Skip to content

Copying of depth24plus formats #652

Closed

Description

@kainino0x

(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.

cc #305 #69

Activity

  1. kainino0x commented on Mar 26, 2020

    @kainino0x
    ContributorAuthor

    (issue edited according to Jasper's feedback on chat)

  2. austinEng commented on Mar 27, 2020

    @austinEng
    Contributor

    Metal also requires you to specify one aspect.

    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.

  3. Kangz commented on Mar 27, 2020

    @Kangz
    Contributor

    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`.

  4. Jiawei-Shao commented on Apr 16, 2020

    @Jiawei-Shao
    Contributor

    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_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT are 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_BIT must also support VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_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_BIT or VK_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 (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.
  5. kainino0x commented on Apr 16, 2020

    @kainino0x
    ContributorAuthor

    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.

  6. Kangz commented on Apr 17, 2020

    @Kangz
    Contributor

    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).

  7. kainino0x commented on Apr 17, 2020

    @kainino0x
    ContributorAuthor

    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.

  8. kvark commented on Apr 27, 2020

    @kvark
    Contributor

    @kainino0x

    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.

  9. kainino0x commented on Apr 27, 2020

    @kainino0x
    ContributorAuthor

    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.

  10. kainino0x commented on Apr 27, 2020

    @kainino0x
    ContributorAuthor

    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.)

  11. kvark commented on Apr 27, 2020

    @kvark
    Contributor

    Would be nice to a have a mini-investigation showing what native APIs and formats produce on copy.

  12. kainino0x commented on Apr 27, 2020

    @kainino0x
    ContributorAuthor

    Here's a start for Vulkan:

    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.

  13. Kangz commented on Jun 5, 2020

    @Kangz
    Contributor

    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.

  14. 23 remaining items

  15. kainino0x commented on Jul 24, 2020

    @kainino0x
    ContributorAuthor

    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

  16. Kangz commented on Jul 27, 2020

    @Kangz
    Contributor

    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.

  17. austinEng commented on Aug 17, 2020

    @austinEng
    Contributor
  18. kainino0x commented on Sep 17, 2020

    @kainino0x
    ContributorAuthor

    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.

  19. kainino0x commented on Sep 17, 2020

    @kainino0x
    ContributorAuthor

    For meeting prep: This is blocking #873, but the intent is not to discuss that whole PR yet.

  20. kainino0x commented on Oct 1, 2020

    @kainino0x
    ContributorAuthor

    @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).

  21. Kangz commented on Sep 2, 2021

    @Kangz
    Contributor

    @kainino0x are all the resolutions from this issue encoded in the spec?

  22. added this to the V1.0 milestone on Sep 2, 2021
  23. added a commit that references this issue on Nov 20, 2021
    189c73a
  24. added a commit that references this issue on Nov 24, 2021
    03c2345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions