这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@toji
Copy link
Member

@toji toji commented Jul 11, 2024

Fixes #4426

Adds usage to texture views, defaulting them to the full set of usages from the texture. Validates that they must be a subset of the texture usage and validates that the view format is storage compatible if the STORAGE_BINDING usage is specified.

CC @teoxoy and @austinEng

@toji toji requested review from jimblandy and kainino0x July 11, 2024 17:02
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2024

Previews, as seen when this build job started (799d217):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

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

I think we also need to update bind group creation validation and the "renderable texture view" validation to refer to the view's usages instead of the texture's.

@toji
Copy link
Member Author

toji commented Jul 11, 2024

Good catch, thanks! Updated those two algorithms.

@greggman
Copy link
Contributor

I feel like it would be nice to include a note about what this is trying to solve.

It's still not clear to me what problem this is solving from #4426

You create rgba8unorm texture with STORAGE_BINDING usage and then try to bind it with a view of rgba8unorm-srgb as storage texture. This could already fail without requiring usage on the view, just updating the validation rules.

You create rgba8unorm-srgb texture with STORAGE_BINDING usage and then try to bind it with a view of rgba8unorm as storage texture. This will already fail when trying to create the texture.

@greggman
Copy link
Contributor

greggman commented Jul 12, 2024

So Kai explained to me (which I didn't know). "views" can be actual native API objects and are created by createView.

With the change above, creating rgba8unorm texture with storage usage and then creating an rgbaunorm-srgb view of it will fail. You're required to remove the storage usage flag. It would be nice to mention that example in the spec.

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Mostly LGTM

@kainino0x kainino0x added needs-cts-issue This change requires tests (or would need tests if accepted), but may not have a CTS issue filed yet api resolved Resolved - waiting for a change to the API specification api WebGPU API labels Jul 25, 2024
Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

IIUC after the last discussion on this topic this PR is still the way we decided to go. I'm not sure what Kelsey was going to write up, but I think we have it here already (once comments are addressed).

spec/index.bs Outdated
::
The allowed {{GPUTextureUsage|usage(s)}} for the texture view. Must be a subset of the
{{GPUTexture/usage}} flags of the texture. Defaults to the full set of {{GPUTexture/usage}}
flags of the texture.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, should we error if you request some viewFormat that has zero overlap with the usage of the texture?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I understand this?

Copy link
Contributor

@kainino0x kainino0x Aug 30, 2024

Choose a reason for hiding this comment

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

Example GPUTextureDescriptor:
{ format: 'rgba8unorm', viewFormats: ['rgba8unorm-srgb'], usage: GPUTextureUsage.STORAGE_BINDING }
This makes it impossible to actually use that viewFormat so should it be an error to create this texture?

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to how we disallow usage from being 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, got it. So something like (obvious psuedocode) usage & viewFormat.allowedUsages != 0. Makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm not sure that this is needed, it seems to add preemptive validation just because it might be an interesting warning for developers. Maybe it should just be a warning in this case. IIRC there are other cases where we don't error even if the operation makes things that cannot be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a note to the texture validation algorithm encouraging implementations to warn in this scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

After discussion in the WG this needs to be changed to a TODO.

@kainino0x kainino0x added this to the Milestone 0 milestone Aug 30, 2024
spec/index.bs Outdated
: GPUObjectDescriptorBase {
GPUTextureFormat format;
GPUTextureViewDimension dimension;
GPUTextureUsageFlags usage;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: I imagine for webgpu.h we'll want usage == None to mean inheriting the usages, so we might need something special to say that the usages are exactly 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given that creating a view with no usages won't be useful (there's validation to ensure the texture usages aren't 0) is that a scenario we need to support? If you are asking explicitly for a usage of 0 we can pretty confidently say you are doing it wrong, and thus don't need to allow it when 0 can have a reasonable and useful alternative interpretation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, would this be a type error or something still surfaced as a validation error on the GPUDevice? (in both cases it is fairly implementable)

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I misunderstood, but I thought None would be given the value of 0? In which case the default behavior is to inherit, but you can also specify any combination of other usages (which will be validated against the view format and the texture usages.) The only thing you can't do is specify a view usage of 0, which is OK because that's useless anyway. No new validation needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cleared up the confusion offline. I thought the concern was primarily for native interfaces but it's actually about the JS interface where undefined and 0 are distinct.

My proposal to handle that is to have the dictionary default to 0 and define that a view usage of 0 means the usage is inherited. That way the native and JS interfaces function more similarly and the JS interface still ends up interpreting undefined as "inherit".

The alternative is that we only treat undefined as "inherit", throw a validation error if 0 is passed (which matches the texture validation) and native will either differ and treat 0 as inherit or introduce a new, explicit inherit enum. Given that this route involves more opportunity for errors with no real upside AND makes native and JS differ I'm not in favor of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

WG approved of defaulting to 0 and having that mean inherit.

@toji
Copy link
Member Author

toji commented Sep 4, 2024

Changed non-normative note to a TODO comment pointing at #4852. PR should match the WG's decisions now.

toji and others added 8 commits September 5, 2024 09:33
Fixes #4426

Adds usage to texture views, defaulting them to the full set of usages
from the texture. Validates that they must be a subset of the texture
usage and validates that the view format is storage compatible if the
`STORAGE_BINDING` usage is specified.
Co-authored-by: Kai Ninomiya <kainino@chromium.org>
@toji toji enabled auto-merge (squash) September 5, 2024 16:47
@toji toji merged commit b39d86d into main Sep 5, 2024
@kainino0x kainino0x deleted the view-usage branch September 5, 2024 17:17
juj added a commit to juj/wasm_webgpu that referenced this pull request Sep 6, 2024
@Kangz
Copy link
Contributor

Kangz commented Sep 10, 2024

GPU Web WG 2024-09-04 Atlantic-time
  • Need to decide pattern for specifying that the view usage is inherited from the texture usage.
  • BJ: generally this is you don't define a specific view. How does this translate down to native API? If I say 0 in view usages, is that analogous to inheriting definition from texture, or is it an error, like on the texture side? On native side, NONE is like inheriting the texture's usage. But on JS side, funneling both "undefined" and 0 down separately is difficult.
  • BJ: my proposal: in dictionary for TextureViewDescriptor: default for usage is 0, and that's treated as INHERIT. You don't have a way to say I want zero usages, but that's useless anyway and we'd need a separate error for it anyway.
  • BJ: alternative is "undefined" and 0 are separate on the JS side; need more validation rules then. No perceived benefit.
  • KG: sure (sounds fine)
    • Don't think there's a real argument that the native behavior of "no usages" is compelling
  • MW: thumbs up
  • Consensus: default to 0, make it mean inherited!
  • KN: there was another thread on the PR
  • BJ: if you only specify STORAGE usage and specify a view format that can't do STORAGE, that view format can't be used. Validate at texture creation?
  • KG: think the consensus was that that was an error.
  • BJ: not sure we talked about that and got consensus on it.
  • KG: if there's something more to discuss here can we write it down in the bug
  • BJ: behavior in the PR (which doesn't address this) is fine, you can use it as-is and you won't get into an invalid state. Just can't make texture with a view that won't be used down the road. If we want to tighten it up, can discuss that as a separate topic to this one.
  • CW: problem was that it wasn't clear what to look at in the PR. Let's try to do better at that. Here there's agreement on everything except this one issue. Let's try to land something in the spec.
  • BJ: the reason this didn't come up in the agenda, this was basically resolved with a non-normative note for warnings. We talked about it on the pull request, came to some resolution.
  • CW: procedurally it's a validation error; we can add TODOs to the spec that have to be resolved before CR, and let's tightly scope agenda items for the next meeting.

@Maungmaunglwin096062286

This comment was marked as spam.

@kainino0x kainino0x removed the needs-cts-issue This change requires tests (or would need tests if accepted), but may not have a CTS issue filed yet label Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api resolved Resolved - waiting for a change to the API specification api WebGPU API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createTexture does not validate viewFormats against usage

7 participants