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
(We've talked about this a number of times; just recording it in an issue.)
The depth aspect of depth24plus formats doesn't have a defined memory layout. As such, it's not obvious how they interact with copy commands. Options:
Disallow copies to/from the depth aspect of depth24plus formats
Copies would require sites to use formats with concrete depth format (defined in extensions)
Emulate by inserting format conversions (to D24 and/or D32F) in the implementation
As pointed out by @magcius, the stencil aspect of depth24plus-stencil8, and the hypothetical stencil8 format (#306), may be okay: the stencil format is constant, and Vulkan/D3D12, at least, require copies to be against only one aspect anyway.
update: See also: bjjones's investigation which resulted in the removal of aspect from GPUTextureCopyView.
If the texture’s pixel format is a combined depth/stencil format, then options must be set to either blit the depth attachment portion or blit the stencil attachment portion.
if we allowed copying, I would think we would only allow copying to/from stencil of packed formats.
It would be nice to allow copying the depth component of depth24plus even if it is slower. All APIs allow copying the depth format, so it would be a big limitation of WebGPU couldn't copy at least to other depth24plus[-stencil8] and r32float`.
From (1) to (3) we can conclude that the depth stencil textures that are not guaranteed to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT (including VK_FORMAT_D24_UNORM_S8_UINT and VK_FORMAT_D32_SFLOAT_S8_UINT) are also not guaranteed to support either VK_FORMAT_FEATURE_TRANSFER_SRC_BIT or VK_FORMAT_FEATURE_TRANSFER_DST_BIT.
Although Vulkan 1.0 does not define VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT, according to the experts in Vulkan WG, this part of Vulkan 1.0 SPEC "is poorly defined" and they are suggesting we should still only trust that:
The formats that are required to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT must also support VK_FORMAT_FEATURE_TRANSFER_SRC_BIT or VK_FORMAT_FEATURE_TRANSFER_DST_BIT.
Or we must first check if the format supports VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT before copying with them.
I'd like to know what actual hardware is not able to copy to/from at least one depth and one depth-stencil format that have VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT. I think it's unlikely that it will be a significant portion of the market, but I don't know. gpuinfo.org doesn't seem to have the data.
Especially on mobile, I think a lot of hardware has special-sauce compression for depth and stencil formats which means they might not be transferable. Unfortunately Vulkan gives very low guarantees on when this is available, and @Jiawei-Shao's proposal is the best we can do.
Also if my reading of the GLES spec is correct, (see Table 8.16: Valid CopyTexImage source framebuffer/destination texture base internal format combinations) it doesn't require copies from/to depth stencil formats. Base Vulkan being the same feature level as OpenGL ES 3.1 I think this means it is not possible to expect copies from depth-stencil formats to be available beyond what Vulkan provides. (glBlitFramebuffer is also limited because it asks for the depth-stencil formats of the source and destination to match).
If I'm reading Jiawei's investigations correctly, it sounds like Vulkan requires sampling/src/dst from depth16unorm and depth32float. (But no stencil or depth-stencil formats.)
I guess we'll have to rely on sampling to read from depth24plus formats. Fortunately, from #659, I think we can.
I guess we'll have to rely on sampling to read from depth24plus formats
I don't understand this. If a format is sample-able, Vulkan guarantees it's also copy-able.
I suggest we take a bold stance here and require that we only work with those native formats that support both depth-stencil output and sampling (and therefore, can be copied in/from). This would allow the use of deferred rendering and shadow mapping - two very common cases that are well established and widely used.
Working with those native formats doesn't mean we directly expose them. We'd still expose them as "depth24plus" and such, which we just guarantee to be renderable, sample-able, and copy-able.
I don't understand this. If a format is sample-able, Vulkan guarantees it's also copy-able.
Oh, sorry, I missed that:
formats that are required to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT must also support VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT
phew.
I suggest we take a bold stance here and ...
I'd like to do this too, though this goes beyond what's core in Vulkan, right? So we need to figure out exactly what we can reasonably rely upon from the Vulkan ecosystem.
Original question still stands though: what does a copy look like when the format is unknown (24 or 32f)? Do we convert to a known format? (And if we have to do that conversion, we could read through sampling anyway, meaning we don't need Vulkan support for a copy in that case.)
When copying to or from a depth or stencil aspect, the data in buffer memory uses a layout that is a (mostly) tightly packed representation of the depth or stencil data. (... format appears to be well defined)
Because depth or stencil aspect buffer to image copies may require format conversions on some implementations, they are not supported on queues that do not support graphics.
In KhronosGroup/Vulkan-Docs#1283 the Vulkan WG clarified that the intent is that the depth-stencil format that supports OUTPUT_ATTACHMENT should also support SAMPLED (and most likely) COPY_SRC/COPY_DST. Data extraction from vulkan.gpuinfo.org seems to shows that this is the case for all Vulkan devices. So we should be able to assume that the WebGPU depth and depth-stencil formats are sampleable and copyable (at least for the Vulkan implementability point of view).
We should figure out how between depth/depth-stencil textures and other textures and buffers work. We'll likely need to add a GPUTextureAspect to GPUTextureCopyView.
Guess I should assign this to @grorg@litherum to get a clarification on the buggy documentation / what packing format you get when you copy from the depth or stencil aspect of various depth-stencil formats
Note that @austinEng implemented stencil T <-> B copies in Dawn and it seems that on all configurations we test they are packed. Would be nice to get confirmation from the horse's mouth though.
I think we're reasonably confident that stencil-from-depth-stencil copies on Metal work the same way on as the other APIs. If we don't get clarification on the documentation then we should probably move forward assuming the observed behavior on Mac is Metal's intended behavior.
@litherum has clarified via email that stencil-from-depth-stencil copies from D24S8 will indeed be packed. Thanks Myles!
You noted D24S8 is not available on all devices. I probably should have asked about MTLPixelFormatDepth32Float_Stencil8 as well, but I don't remember whether we already had a conclusive answer on that one. It seems fairly safe to assume it has the same behavior (especially since we would only use it when MTLPixelFormatDepth24Unorm_Stencil8 is not available, and in such cases I believe the D32S8 stencil aspect is stored in a separate tightly packed S8 plane).
Activity
kainino0x commentedon Mar 26, 2020
(issue edited according to Jasper's feedback on chat)
austinEng commentedon Mar 27, 2020
Metal also requires you to specify one aspect.
if we allowed copying, I would think we would only allow copying to/from stencil of packed formats.
Kangz commentedon Mar 27, 2020
It would be nice to allow copying the depth component of
depth24pluseven if it is slower. All APIs allow copying the depth format, so it would be a big limitation of WebGPU couldn't copy at least to otherdepth24plus[-stencil8]and r32float`.Jiawei-Shao commentedon Apr 16, 2020
I'm afraid that we cannot always support copies with
depth24plus[-stencil]formats on all Vulkan backends.(1) Since Vulkan 1.1,
VK_FORMAT_FEATURE_TRANSFER_SRC_BITandVK_FORMAT_FEATURE_TRANSFER_DST_BITare introduced for the formats that don’t support being used in copy commands.(2) In Vulkan SPEC (Chapter 39.3 "Required Format Support"), only the "formats that are required to support
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BITmust also supportVK_FORMAT_FEATURE_TRANSFER_SRC_BITandVK_FORMAT_FEATURE_TRANSFER_DST_BIT".(3) In Vulkan SPEC (Table 65.
"Mandatory format support: depth/stencil with VkImageType VK_IMAGE_TYPE_2D"), there is no column that shows the mandatory support of either
VK_FORMAT_FEATURE_TRANSFER_SRC_BITorVK_FORMAT_FEATURE_TRANSFER_DST_BIT.From (1) to (3) we can conclude that the depth stencil textures that are not guaranteed to support
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT(includingVK_FORMAT_D24_UNORM_S8_UINTandVK_FORMAT_D32_SFLOAT_S8_UINT) are also not guaranteed to support eitherVK_FORMAT_FEATURE_TRANSFER_SRC_BITorVK_FORMAT_FEATURE_TRANSFER_DST_BIT.Although Vulkan 1.0 does not define
VK_FORMAT_FEATURE_TRANSFER_SRC_BITandVK_FORMAT_FEATURE_TRANSFER_DST_BIT, according to the experts in Vulkan WG, this part of Vulkan 1.0 SPEC "is poorly defined" and they are suggesting we should still only trust that:VK_FORMAT_FEATURE_SAMPLED_IMAGE_BITmust also supportVK_FORMAT_FEATURE_TRANSFER_SRC_BITorVK_FORMAT_FEATURE_TRANSFER_DST_BIT.VK_FORMAT_FEATURE_TRANSFER_SRC_BITandVK_FORMAT_FEATURE_TRANSFER_DST_BITbefore copying with them.kainino0x commentedon Apr 16, 2020
I'd like to know what actual hardware is not able to copy to/from at least one depth and one depth-stencil format that have VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT. I think it's unlikely that it will be a significant portion of the market, but I don't know. gpuinfo.org doesn't seem to have the data.
Kangz commentedon Apr 17, 2020
Especially on mobile, I think a lot of hardware has special-sauce compression for depth and stencil formats which means they might not be transferable. Unfortunately Vulkan gives very low guarantees on when this is available, and @Jiawei-Shao's proposal is the best we can do.
Also if my reading of the GLES spec is correct, (see Table 8.16: Valid CopyTexImage source framebuffer/destination texture base internal format combinations) it doesn't require copies from/to depth stencil formats. Base Vulkan being the same feature level as OpenGL ES 3.1 I think this means it is not possible to expect copies from depth-stencil formats to be available beyond what Vulkan provides. (glBlitFramebuffer is also limited because it asks for the depth-stencil formats of the source and destination to match).
kainino0x commentedon Apr 17, 2020
If I'm reading Jiawei's investigations correctly, it sounds like Vulkan requires sampling/src/dst from depth16unorm and depth32float. (But no stencil or depth-stencil formats.)
I guess we'll have to rely on sampling to read from depth24plus formats. Fortunately, from #659, I think we can.
kvark commentedon Apr 27, 2020
@kainino0x
I don't understand this. If a format is sample-able, Vulkan guarantees it's also copy-able.
I suggest we take a bold stance here and require that we only work with those native formats that support both depth-stencil output and sampling (and therefore, can be copied in/from). This would allow the use of deferred rendering and shadow mapping - two very common cases that are well established and widely used.
Working with those native formats doesn't mean we directly expose them. We'd still expose them as "depth24plus" and such, which we just guarantee to be renderable, sample-able, and copy-able.
kainino0x commentedon Apr 27, 2020
Oh, sorry, I missed that:
phew.
I'd like to do this too, though this goes beyond what's core in Vulkan, right? So we need to figure out exactly what we can reasonably rely upon from the Vulkan ecosystem.
kainino0x commentedon Apr 27, 2020
Original question still stands though: what does a copy look like when the format is unknown (24 or 32f)? Do we convert to a known format? (And if we have to do that conversion, we could read through sampling anyway, meaning we don't need Vulkan support for a copy in that case.)
kvark commentedon Apr 27, 2020
Would be nice to a have a mini-investigation showing what native APIs and formats produce on copy.
kainino0x commentedon Apr 27, 2020
Here's a start for Vulkan:
Kangz commentedon Jun 5, 2020
In KhronosGroup/Vulkan-Docs#1283 the Vulkan WG clarified that the intent is that the depth-stencil format that supports
OUTPUT_ATTACHMENTshould also supportSAMPLED(and most likely)COPY_SRC/COPY_DST. Data extraction from vulkan.gpuinfo.org seems to shows that this is the case for all Vulkan devices. So we should be able to assume that the WebGPU depth and depth-stencil formats are sampleable and copyable (at least for the Vulkan implementability point of view).We should figure out how between depth/depth-stencil textures and other textures and buffers work. We'll likely need to add a
GPUTextureAspecttoGPUTextureCopyView.23 remaining items
kainino0x commentedon Jul 24, 2020
Guess I should assign this to @grorg @litherum to get a clarification on the buggy documentation / what packing format you get when you copy from the depth or stencil aspect of various depth-stencil formats
Kangz commentedon Jul 27, 2020
Note that @austinEng implemented stencil T <-> B copies in Dawn and it seems that on all configurations we test they are packed. Would be nice to get confirmation from the horse's mouth though.
austinEng commentedon Aug 17, 2020
Bump @grorg @litherum
kainino0x commentedon Sep 17, 2020
I think we're reasonably confident that stencil-from-depth-stencil copies on Metal work the same way on as the other APIs. If we don't get clarification on the documentation then we should probably move forward assuming the observed behavior on Mac is Metal's intended behavior.
kainino0x commentedon Sep 17, 2020
For meeting prep: This is blocking #873, but the intent is not to discuss that whole PR yet.
kainino0x commentedon Oct 1, 2020
@litherum has clarified via email that stencil-from-depth-stencil copies from D24S8 will indeed be packed. Thanks Myles!
You noted D24S8 is not available on all devices. I probably should have asked about MTLPixelFormatDepth32Float_Stencil8 as well, but I don't remember whether we already had a conclusive answer on that one. It seems fairly safe to assume it has the same behavior (especially since we would only use it when MTLPixelFormatDepth24Unorm_Stencil8 is not available, and in such cases I believe the D32S8 stencil aspect is stored in a separate tightly packed S8 plane).
Add aspect back to GPUTextureCopyView
Add aspect back to GPUTextureCopyView (#873)
Kangz commentedon Sep 2, 2021
@kainino0x are all the resolutions from this issue encoded in the spec?
Describe tight-packing of image-copy ops, including depth/stencil
Describe tight-packing of image-copy ops, including depth/stencil (#2331
Fix expectCompileResult and variable_and_const tests (gpuweb#652)