Skip to content

Case for optional GPUBindGroupLayoutEntry entries #851

Open

Description

@kvark

The decision on minimumBufferBindingSize of #678 has opened a can of questions on how do we decide whether the validation happens at the initialization time versus the draw time. There is a class of GPUBindGroupLayoutEntry properties that aren't actually needed by the native APIs, and we only have them for the purpose of early validation:

  • textureComponentType GPUTextureBindingLayout.sampleType
  • storageTextureFormat GPUStorageTextureBindingLayout.format
  • minimumBufferBindingSize GPUBufferBindingLayout.minBindingSize

Currently, the first two are mandatory, while the last one is optional. Technically, we could validate all 3 at the draw time, so it's important to understand where and why we draw this line.

For example, there could be an application that wants to compute mipmaps in the shader. They would have separate shader variants for int/uint/float textures, but in all of the native APIs these shaders would be linked to pipelines of the same layout. In WebGPU today, that would require separate GPUBindGroupLayout objects (since textureComponentType is different), and separate GPUPipelineLayout.

Another example is a shader that zeroes out a storage texture. It could have different entry points for different formats of the texture. But all of them would use the same layout in the native APIs. In WebGPU today, that would require a separate bind group layout for every format/shader variation.


Personally, I see great value in surfacing the errors as early as possible, making them more explicit. I think it would be great just making all of these properties required, and then listening to ISV feedback to see if this needs to be relaxed.
Raising this issue for the awareness of the group.


EDIT(2023-09-01 @kainino0x): some related things:

  • Texture filterability / sampler filtering validation. Currently baked into a pipeline layout (and therefore pipeline) but could be validated at draw/dispatch time. Somewhat expensive because it requires iterating over all of the texture-sampler pairs and checking them. discussion
  • (this one is not for bind group layouts, but I'll note it here anyway.) Usage scope validation on sub-ranges of storage buffers. Somewhat expensive because we have to look at all of the currently-bound ranges (which may be dynamic with hasDynamicOffset), find overlaps, and check them for usage scope violations. See also Proposal: BufferSubRanges to solve buffer-tracking, streaming and descriptor set explosion. #156

Activity

  1. kainino0x commented on Jun 8, 2020

    @kainino0x
    Contributor

    If we wanted to open things up for cases that want draw-time validation, we could expose them not as optional, but as "required" (if the type uses it) fields of type (null or T) (or (undefined or T) or required ("dynamic" or T)?) so that the user has to explicitly specify that they want that behavior.

  2. Kangz commented on Jun 9, 2020

    @Kangz
    Contributor

    I don't think we should make textureComponentType or storageTextureFormat optional. Like @kvark described, the declaration of the bindings in the shader has to be different anyways and there is a clear mapping between the declaration and what goes in the GPUBindGroupLayoutDescriptor. The examples provided are also simpler if the application takes advantage of pipeline layout defaulting and getBindGroupLayout.

    The reason why minBufferSize can have a default that validates at draw-time is that the size of uniform / storage interface varies much more often than the component type of textures (and most of them are "float" anyway), or the format of storage textures. It is would be the BGL compatibility check they most often run into (because they forgot to update the BGL that's used to compile the pipeline) and a small affordance can be made for it.

  3. kvark commented on Jun 24, 2020

    @kvark
    ContributorAuthor

    Action item from the virtual F2F: reach out to ISVs like BabylonJS asking if they are ok with minBufferBindingSize being a strong requirement on BGLs.

  4. kainino0x commented on Aug 12, 2020

    @kainino0x
    Contributor

    Actually, I think this action item is obsolete since we made it optional?

  5. kainino0x commented on Aug 12, 2020

    @kainino0x
    Contributor

    Unless we were still considering changing it to be required (I thought we weren't).

  6. kvark commented on Aug 12, 2020

    @kvark
    ContributorAuthor

    @kainino0x the change to optional doesn't affect the semantics. The issue is still there: if the binding type depends on, say, texture component type, do we require it to be set, or should we allow the user to not care, in which case the validation is done at the draw time?

  7. kainino0x commented on Aug 12, 2020

    @kainino0x
    Contributor

    The action item was specifically about minBufferBindingSize, but you're right we need to determine this for other fields.

  8. kvark commented on Aug 12, 2020

    @kvark
    ContributorAuthor

    Yes, the AI was for minBufferBindingSize because if the answer is "we can make it a requirement", then we can align this with the other fields, and no further action is needed.

  9. Kangz commented on Aug 14, 2020

    @Kangz
    Contributor

    It isn't super clear what needs to be discussed with the group now. We need to gather data from ISVs no?

  10. kvark commented on Aug 14, 2020

    @kvark
    ContributorAuthor

    Well, not all issues can be helped by an immediate discussion :)
    The point of this issue is to highlight and track the inconsistency in the specification, so that we keep it on our radar and think about it. Input from ISVs would help, too.

  11. Kangz commented on Nov 20, 2020

    @Kangz
    Contributor

    I think this will be mostly fixed by #1223.

  12. Kangz commented on Dec 7, 2020

    @Kangz
    Contributor

    @kvark are you satisfied with #1223 and can we close this?

  13. kvark commented on Dec 7, 2020

    @kvark
    ContributorAuthor

    I don't think #1223 resolves this issue. The matter here is that some checks are delayed at draw time, while others are not.
    This is still the case, the only thing #1223 changes is what default values are in the BGL.

  14. 2 remaining items

  15. removed this from the post-MVP milestone on Aug 23, 2021
  16. added this to the V1.0 milestone on Sep 2, 2021
  17. Kangz commented on Nov 10, 2021

    @Kangz
    Contributor

    @kvark, are you ok closing this or moving post-V1? We might not need the classification's rational for V1.

  18. kainino0x commented on Nov 10, 2021

    @kainino0x
    Contributor

    Basically do we want to actually make any API changes here? Or are we happy with the API as it is and just need to write down rationale for why it is the way it is?

  19. kvark commented on Nov 23, 2021

    @kvark
    ContributorAuthor

    Let's write it down and not block V1

  20. modified the milestones: V1.0, post-V1 on Nov 24, 2021
  21. kainino0x commented on Sep 1, 2023

    @kainino0x
    Contributor

    Two new ideas for possible opt-ins to runtime validation came up today (I'll add them to the summary above too for easier discoverability):

    • Texture filterability / sampler filtering validation. Currently baked into a pipeline layout (and therefore pipeline) but could be validated at draw/dispatch time. Somewhat expensive because it requires iterating over all of the texture-sampler pairs and checking them. discussion
    • (this one is not for bind group layouts, but I'll note it here anyway.) Usage scope validation on sub-ranges of storage buffers. Somewhat expensive because we have to look at all of the currently-bound ranges (which may be dynamic with hasDynamicOffset), find overlaps, and check them for usage scope violations. See also Proposal: BufferSubRanges to solve buffer-tracking, streaming and descriptor set explosion. #156
  22. floooh commented on Sep 2, 2023

    @floooh

    I wonder if the "lazy" texture/sampler validation could be solved in a compatible way by adding two new enum items: GPUTextureSampleType.unknown and GPUSamplerBindingType.unknown. Specifying those in a BindGroupLayout would delay the texture-vs-sampler validation from CreateRenderPipeline to SetBindGroup.

    Assuming that the internal shader compilation returns a list of all actually used texture/sampler pairs in the shader, this list could be stored internally at the render-pipeline object as an index-pair of texture and sampler bind slots into the BindGroupLayout (actually: only texture/sampler pairs which involve a texture or sampler that's declared as "unknown" in the BindGroupLayout, the others are validated immediately, just as it happens now).

    At SetBindGroup time, this list of "unknown" texture/sampler-index pairs of the currently set render-pipeline is iterated and texture and associated sampler objects in the bind group are checked for compatibility.

    Even if there are dozens of texture/sampler pairs to check, such a simple O(n) loop really shouldn't matter much in terms of runtime overhead? (and for BindGroupLayouts that don't involve unknown texture/sampler types, runtime behaviour would be the same as is now)

  23. MikhailGorobets commented on Jun 19, 2024

    @MikhailGorobets

    Any updates?

  24. kainino0x commented on Jun 20, 2024

    @kainino0x
    Contributor

    No, and we're not expecting to talk about it anytime soon (it's in "Milestone 3+"). If you could describe why this is useful to you, it could help us prioritize it!

  25. MikhailGorobets commented on Sep 12, 2024

    @MikhailGorobets

    No, and we're not expecting to talk about it anytime soon (it's in "Milestone 3+"). If you could describe why this is useful to you, it could help us prioritize it!

    For example, in this case
    https://github.com/DiligentGraphics/DiligentCore/blob/14f7cd0d421af7b96ad20b0b40c80c878947f294/Graphics/GraphicsEngineWebGPU/src/GenerateMipsHelperWebGPU.cpp#L96, we are computing mip levels for a texture using a compute shader. Since WebGPU requires a resource for each binding, we have to use a 1x1 placeholder texture with a different format from the source texture. If we try to pre-create all PSOs, each PSO will have a unique PipelineLayout, even though this wouldn’t be necessary in all native APIs. Also, specifying the texture format directly in WGSL forces shader recompilation every time, adding additional overhead. I understand this limitation was introduced due to the lack of shaderStorageImageReadWithoutFormat / shaderStorageImageWriteWithoutFormat on mobile platforms in Vulkan, but it might be worth considering an extension that allows omitting the format inside WGSL where possible.

  26. brendan-duncan commented on Oct 1, 2025

    @brendan-duncan

    I just ran into this being an issue for Unity's WebGPU implementation. While implementing PSO caching and warmup, pipeline descriptors were not recording information about unfilterable-float textures or non-filtering samplers because none of the other APIs require this information. There is nothing from the reflection information for the shader that would indicate this information, it's only known at runtime based on the bound resources. I had to add a complicated work-around to implement it for WebGPU and justify the changes as "webgpu is special". It adds technical debt to our code,

    If texture samplerType and sampler type were optional, validated at the draw call, that would greatly simplify our code and unify it with the other APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions