From fee8c94b5c7211dd04349470a6ff333f07ac0d99 Mon Sep 17 00:00:00 2001
From: Evan Hemsley <[EMAIL REDACTED]>
Date: Tue, 5 May 2026 12:55:16 -0700
Subject: [PATCH] GPU: D3D12 stencil plane transition (#15519)
---
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 75a4c99a76db4..3a1d651fddf64 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -1838,6 +1838,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,
@@ -1894,6 +1904,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(