From 6b28e6870e5a0b0c3e630264915b367d1d4a6f8a Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+thatcosmonaut@users.noreply.github.com> Date: Tue, 5 May 2026 12:55:16 -0700 Subject: [PATCH] GPU: D3D12 stencil plane transition (#15519) (cherry picked from commit fee8c94b5c7211dd04349470a6ff333f07ac0d99) --- src/gpu/d3d12/SDL_gpu_d3d12.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c index 21050f39f1..b5a6e50f1e 100644 --- a/src/gpu/d3d12/SDL_gpu_d3d12.c +++ b/src/gpu/d3d12/SDL_gpu_d3d12.c @@ -1792,6 +1792,16 @@ static inline Uint32 D3D12_INTERNAL_CalcSubresource( return mipLevel + (layer * numLevels); } +static inline Uint32 D3D12_INTERNAL_CalcSubresourceWithPlane( + Uint32 mipLevel, + Uint32 layer, + Uint32 planeSlice, + Uint32 numLevels, + Uint32 arraySize) +{ + return mipLevel + (layer * numLevels) + (planeSlice * numLevels * arraySize); +} + static void D3D12_INTERNAL_ResourceBarrier( D3D12CommandBuffer *commandBuffer, D3D12_RESOURCE_STATES sourceState, @@ -1848,6 +1858,27 @@ static void D3D12_INTERNAL_TextureSubresourceBarrier( textureSubresource->parent->resource, textureSubresource->index, needsUAVBarrier); + + // D3D12 stores planar values on a separate subresource. + // Since depth-stencil is our only supported planar format, + // just force an extra transition if we're using a stencil format. + if (IsStencilFormat(textureSubresource->parent->container->header.info.format)) { + Uint32 planeSubresourceIndex = D3D12_INTERNAL_CalcSubresourceWithPlane( + textureSubresource->level, + textureSubresource->layer, + 1, + textureSubresource->parent->container->header.info.num_levels, + textureSubresource->parent->container->header.info.layer_count_or_depth + ); + + D3D12_INTERNAL_ResourceBarrier( + commandBuffer, + sourceState, + destinationState, + textureSubresource->parent->resource, + planeSubresourceIndex, + needsUAVBarrier); + } } static D3D12_RESOURCE_STATES D3D12_INTERNAL_DefaultTextureResourceState(