Skip to content

Rename TextureFormat::is_srgb() to performs_srgb_encoding().#9758

Open
kpreid wants to merge 1 commit into
gfx-rs:trunkfrom
kpreid:is-srgb
Open

Rename TextureFormat::is_srgb() to performs_srgb_encoding().#9758
kpreid wants to merge 1 commit into
gfx-rs:trunkfrom
kpreid:is-srgb

Conversation

@kpreid

@kpreid kpreid commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Renamed TextureFormat::is_srgb() to performs_srgb_encoding().
  • Expanded its documentation.
  • Rewrote the documentation of add_srgb_suffix() and remove_srgb_suffix().

This is intended to clarify the correct use of is_srgb(), and in particular, to communicate that it does not mean “this (surface) texture format stores sRGB data”, which may be true or false independently.

Testing
Ran cargo doc and reviewed the changed documentation.

Squash or Rebase?
Rebase

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

This is intended to clarify the correct use of the method, and in
particular, to communicate that it does *not* mean “this (surface)
texture format stores sRGB data”, which may be true or false
independently.

Also rewrote the documentation of `add_srgb_suffix()` and
`remove_srgb_suffix()`.
@kpreid

kpreid commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator Author

The formatting CI failure appears to be an existing issue. No idea why it hit this PR only.

@sagudev

sagudev commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

The formatting CI failure appears to be an existing issue. No idea why it hit this PR only.

I've also hit this in my personal fork. I guess something changed in last few hours somewhere in the CI stack.

@cwfitzgerald

Copy link
Copy Markdown
Member

Yeah our version of prettier isn't pinned.

@cwfitzgerald

Copy link
Copy Markdown
Member

This is creyD/prettier_action#154


/// Returns `true` for srgb formats.
/// Returns `true` for `*Srgb` formats: those which, when read, automatically apply sRGB
/// decoding, and when written, automatically apply sRGB encoding.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth noting that encoding/decoding only happened in shader read/write, not buffer copies?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that would be a good addition, but I am not sure how to phrase it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Returns `true` for `*Srgb` formats: those which, when read or written to as a sampled texture or a render target, automatically apply the sRGB transfer function.

/// textures, by the [`SurfaceColorSpace`][crate::SurfaceColorSpace]).
#[must_use]
pub fn is_srgb(&self) -> bool {
pub fn performs_srgb_encoding(&self) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I dislike performs_srgb_encoding and prefer is_srgb:

  1. This method returns a bool so is_srgb name is clearer. performs_srgb_encoding sounds like an operation was performed on the texture format, rather than checking it.
  2. I think is_srgb or "sRGB texture formats" is the correct term.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy to call it is_-something given a good suggestion of what that name. However, I strongly disagree that is_srgb() is an adequate name. It has in the past greatly confused me and others about what role it has — resulting in writing incorrect code.

In particular, is_srgb() being true implies that one must not write sRGB encoded values into it (but rather linear values). That’s the opposite of what it sounds like it could mean. The whole API design is kind of confusing, in my opinion, but we should do the best we can to clarify it in the parts we have control over (wgpu-specific functions such as this one, and documentation).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what causes confusion is when you use the *UnormSrgb format its naming does not clearly indicate what it does (though this name is the convention across all backends) - not when you use the is_srgb function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, is_srgb() being true implies that one must not write sRGB encoded values into it (but rather linear values).

Actually this is not accurate. For queue.write_texture, srgb encoded values should be written. Typically srgb textures do store srgb encoded data.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this at the maintainers meeting and we'd prefer something other than is_srgb(). How about applies_srgb_transfer_function or performs_srgb_conversion? We can also have a doc alias for is_srgb so it shows up in searches.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_srgb_suffix if we want the name to be neutral.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_srgb_suffix() seems like an acceptable name to me; it is not very informative, but it matches add_srgb_suffix() and remove_srgb_suffix(), which makes it clear how it is related to the rest.

I will wait for further input before revising this PR.

@cwfitzgerald cwfitzgerald self-assigned this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants