Skip to content

PrepareUploadEx for Direct3D 12 planar depth/stencil formats - #753

Closed
João Vilaça (jpggvilaca) wants to merge 2 commits into
microsoft:mainfrom
jpggvilaca:planar-depth-stencil
Closed

João Vilaça (jpggvilaca) wants to merge 2 commits into
microsoft:mainfrom
jpggvilaca:planar-depth-stencil

Conversation

@jpggvilaca

Copy link
Copy Markdown

Related to microsoft/DirectXTK12#283. As suggested there, this adds the depth/stencil support to DirectXTex first; DDSTextureLoader12 and DirectXTK12 will follow.

Problem

PrepareUpload returns HRESULT_E_NOT_SUPPORTED for the D24 and D32 depth/stencil families, because Direct3D 12 treats them as two planes, while DDS files (like Direct3D 11) store depth and stencil interleaved per pixel.

Change

Adds a new function:

HRESULT PrepareUploadEx(ID3D12Device* pDevice, const Image* srcImages, size_t nimages,
    const TexMetadata& metadata, std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
    Blob& planarData);
  • For the D24 family (D24_UNORM_S8_UINT, R24G8_TYPELESS, R24_UNORM_X8_TYPELESS, X24_TYPELESS_G8_UINT) and the D32 family (D32_FLOAT_S8X24_UINT, R32G8X24_TYPELESS, R32_FLOAT_X8X24_TYPELESS, X32_TYPELESS_G8X24_UINT), the data is rearranged byte by byte into planarData: plane 0 holds 4 bytes per pixel (depth, with the X8 bits zeroed as the planar depth/stencil spec requires) and plane 1 holds 1 byte per pixel (stencil). subresources points into planarData, so it must outlive UpdateSubresources.
  • All other formats are forwarded to PrepareUpload, and planarData is left empty. PrepareUpload itself is unchanged.
  • Volume textures and XBOX_DXGI_FORMAT_D16_UNORM_S8_UINT (which DirectXTex already stores planar) still return HRESULT_E_NOT_SUPPORTED.
  • Images whose rowPitch is smaller than width * bytesPerPixel are rejected, and the buffer size is computed in 64 bits with an overflow check.

The scanline helpers follow the style of CopyScanline24bpp in DirectXTexDDS.cpp.

Testing

xtd3d12 from directxtextest, with depthimageD16.dds, depthimageD24.dds and depthimageD32.dds added (test PR to follow): all tests pass with the D3D12 debug layer enabled; the only debug-layer error is the existing invalid-dimension check in the CreateTexture test. depthimageD24.dds is created, prepared, uploaded and rendered; D16/D32 are skipped only in the render test, since those formats can't be used for shader resource views.

Documentation

Suggested wiki text for the CreateTexture page, next to PrepareUpload:

PrepareUploadEx: Like PrepareUpload, but also supports the depth/stencil formats that Direct3D 12 treats as planar (the D24_UNORM_S8_UINT and D32_FLOAT_S8X24_UINT families, including their typeless variants). For those formats, the image data is rearranged into a depth plane and a stencil plane stored in planarData, and the subresources entries point into it, so planarData must remain valid until the data has been copied (for example, until UpdateSubresources returns). For all other formats it behaves exactly like PrepareUpload, and planarData is left empty.

Note: I developed this with help from Claude. I've built, tested and reviewed every change myself.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@walbourn

Copy link
Copy Markdown
Collaborator

Please explain why you are closing the PR.

@jpggvilaca

Copy link
Copy Markdown
Author

Please explain why you are closing the PR.

Apologies for all this confusion. I thought I could work on this but it might not be allowed by my company (Intel), so, in case of doubt, I decided to close just to avoid any issues. I apologize for wasting your time and appreciate the opportunity to contribute/learn.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loading or capture depth/stencil formats is unsupported for DirectX 12

2 participants