Skip to content

Reading from MSAA depth textures #1924

Description

@kvark

(I think we discussed this a bit, but I'm not able to find, where)
Related to #1198

How does the API allow to read from MSAA-enabled depth textures?

If I understand correctly, in #1198 we decided that all depth textures can only be seen by the shaders as "texture_depth*" types.
Therefore, we can't bind an MSAA depth texture as "texture_multisampled_2d" (non-depth). And if we decided to turn back on this, we'd have to take special care of the swizzling, since on Metal accessing G,B,A components is undefined.

The only other choice is adding a separate type like texture_depth_multisampled_2d. Then when we have 2D array MSAA textures, we'd have to add texture_depth_multisampled_2d_array as well...

Activity

  1. Kangz commented on Jul 15, 2021

    @Kangz
    Contributor

    My understanding is that the reason why we have texture_depth* is so that WGSL can guarantee with its type system that these textures are only used with the sampler_comparison type. You can also use texture_*<f32> for regular, non-comparison sampling of depth textures though.

    However you can't sample MSAA textures, just load them, so there is no issue if comparison vs. non-comparison sampling, and it seems we should be able to use texture_multisampled_2d<f32> for multisampled depth textures. If Metal provides undefined values (it is not general undefined behavior), then I think that similarly to stencil textures, it is fine to have either 0, 0, 1 or a copy of the R component for loads.

    Actually I think we should add "float" and "unfilterable-float" to capabilities for the depth aspects of depth-stencil textures. AFAIK (@austinEng can correct me) we have a bunch of tests in Dawn that do this and pass on all backends.

  2. kvark commented on Jul 15, 2021

    @kvark
    ContributorAuthor

    You can also use texture_* for regular, non-comparison sampling of depth textures though.

    My understanding is that we designed the spec in a way that depth-format textures are required to be represented as depth textures on shader side, partly because that's what Metal requires. It can be worked around by re-interpretation of the format in Metal, but this is a whole other story, and unclear if there are costs associated to enabling this on depth textures.

    So currently you can't do texture_*<f32> on depth textures at all.

  3. austinEng commented on Jul 15, 2021

    @austinEng
    Contributor

    Metal is a bit different from other APIs in that you don't need to do texture format reinterpretation (or anything to indicate you want that aspect) to sample depth. You only need to reinterpret the format to sample stencil for a combined depth-stencil texture. i.e. MTLPixelFormatDepth32Float_Stencil8 can be bound directly to texture_2d<f32> and it works - you get the depth channel when sampling it. Still have the (r, 0, 0, 1) or (r, r, r, r) issue though.

    Regarding "float" and "unfilterable-float" on depth textures, I don't think we have thorough testing of using BOTH filtering and non-filtering samplers. We test using textureSample but we could do better testing to see if the filtering aspect of it actually works. IIRC there was an investigation about this in the various APIs though (maybe just Vulkan?). I don't remember the results right now.

  4. litherum commented on Jul 19, 2021

    @litherum
    Contributor

    MTLPixelFormatDepth32Float_Stencil8 can be bound directly to texture_2d and it works - you get the depth channel when sampling it.

    It may work on particular drivers on particular machines, but the spec says that you can't rely on it.

    #1198 (comment)

  5. kainino0x commented on Jul 19, 2021

    @kainino0x
    Contributor

    [API meeting] resolution: No API change. Add corresponding type to WGSL.

  6. self-assigned this
    on Jul 19, 2021
  7. kvark commented on Jul 19, 2021

    @kvark
    ContributorAuthor

    PR has already been open for the last 7 weeks - #1793

  8. kdashg commented on Jul 20, 2021

    @kdashg
    Contributor
    WGSL meeting minutes 2021-07-20
    • JG: Request from API group was that we need to have a MS depth texture type.
    • AB: I don’t like that we have a section on multi-sampled textures, and a section on depth textures, and it’s not clear where it ends up. The spec organization isn’t clear
    • JG: You could make ‘multisampled depth’ be a third category
    • DM: Is redundancy bad? Why not list it in both places?
    • MM: There should be one source of truth - duplicated information risks divergence
    • DM: We can refactor the spec later, I just want the type
    • MM: +1 on the new type
    • AB: I think the PR is fine
    • Resolved: PR needs review, then can land
  9. kainino0x commented on Jun 17, 2022

    @kainino0x
    Contributor

    Reopening as I think actually an API change is needed here, right now it seems our validation rules prevent use of this type (found in #2094)

  10. added
    tacit resolution candidate
    on Jun 17, 2022
  11. kainino0x commented on Jun 17, 2022

    @kainino0x
    Contributor

    I think this may have just been a typo in #1793, so I'm trying to figure out what was intended.

  12. added this to the V1.0 milestone on Jun 20, 2022
  13. removed
    tacit resolution candidate
    on Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions