You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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...
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.
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.
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.
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
Activity
Kangz commentedon Jul 15, 2021
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 thesampler_comparisontype. You can also usetexture_*<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.kvark commentedon Jul 15, 2021
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.austinEng commentedon Jul 15, 2021
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
textureSamplebut 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.litherum commentedon Jul 19, 2021
It may work on particular drivers on particular machines, but the spec says that you can't rely on it.
#1198 (comment)
kainino0x commentedon Jul 19, 2021
[API meeting] resolution: No API change. Add corresponding type to WGSL.
kvark commentedon Jul 19, 2021
PR has already been open for the last 7 weeks - #1793
kdashg commentedon Jul 20, 2021
WGSL meeting minutes 2021-07-20
kainino0x commentedon Jun 17, 2022
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)
kainino0x commentedon Jun 17, 2022
I think this may have just been a typo in #1793, so I'm trying to figure out what was intended.