From d316e5b2f3902634e6637322bd11845bff025563 Mon Sep 17 00:00:00 2001
From: Chicken-Bones <[EMAIL REDACTED]>
Date: Wed, 16 Sep 2026 10:32:09 +1000
Subject: [PATCH] Fix D3D multi-layer texture fallback upload alignment
---
src/gpu/d3d12/SDL_gpu_d3d12.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index 19ebf099928a2..dbccc50ed5e7e 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -6007,7 +6007,11 @@ static void D3D12_UploadToTexture(
needsPlacementCopy = source->offset % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT != 0;
}
- alignedBytesPerSlice = alignedRowPitch * destination->h;
+ alignedBytesPerSlice = alignedRowPitch * blockHeight;
+ if (!renderer->UnrestrictedBufferTextureCopyPitchSupported && destination->d > 1 && alignedBytesPerSlice % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT != 0) {
+ needsRealignment = true;
+ alignedBytesPerSlice = D3D12_INTERNAL_Align(alignedBytesPerSlice, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
+ }
sourceLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
sourceLocation.PlacedFootprint.Footprint.Format = SDLToD3D12_TextureFormat[textureContainer->header.info.format];
@@ -6021,7 +6025,7 @@ static void D3D12_UploadToTexture(
temporaryBuffer = D3D12_INTERNAL_CreateBuffer(
d3d12CommandBuffer->renderer,
0,
- alignedRowPitch * blockHeight * destination->d,
+ alignedBytesPerSlice * destination->d,
D3D12_BUFFER_TYPE_UPLOAD,
NULL);