From 5771b502f844ac2e7731e0ffcf7cc759dfff2333 Mon Sep 17 00:00:00 2001
From: Caleb Cornett <[EMAIL REDACTED]>
Date: Fri, 13 Sep 2024 09:57:55 -0500
Subject: [PATCH] GPU: Fix D3D11/D3D12 vertex strides for multiple vertex
buffers (#10818)
---
src/gpu/d3d11/SDL_gpu_d3d11.c | 15 ++++-----------
src/gpu/d3d12/SDL_gpu_d3d12.c | 3 ++-
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c
index 7188754a37f3d..dac8a20e4a105 100644
--- a/src/gpu/d3d11/SDL_gpu_d3d11.c
+++ b/src/gpu/d3d11/SDL_gpu_d3d11.c
@@ -509,7 +509,7 @@ typedef struct D3D11GraphicsPipeline
ID3D11PixelShader *fragmentShader;
ID3D11InputLayout *inputLayout;
- Uint32 *vertexStrides;
+ Uint32 vertexStrides[MAX_VERTEX_BUFFERS];
Uint32 vertexSamplerCount;
Uint32 vertexUniformBufferCount;
@@ -1258,9 +1258,6 @@ static void D3D11_ReleaseGraphicsPipeline(
if (d3d11GraphicsPipeline->inputLayout) {
ID3D11InputLayout_Release(d3d11GraphicsPipeline->inputLayout);
}
- if (d3d11GraphicsPipeline->vertexStrides) {
- SDL_free(d3d11GraphicsPipeline->vertexStrides);
- }
ID3D11VertexShader_Release(d3d11GraphicsPipeline->vertexShader);
ID3D11PixelShader_Release(d3d11GraphicsPipeline->fragmentShader);
@@ -1611,16 +1608,12 @@ static SDL_GPUGraphicsPipeline *D3D11_CreateGraphicsPipeline(
vertShader->bytecode,
vertShader->bytecodeSize);
+ SDL_zeroa(pipeline->vertexStrides);
if (createinfo->vertex_input_state.num_vertex_buffers > 0) {
- pipeline->vertexStrides = SDL_malloc(
- sizeof(Uint32) *
- createinfo->vertex_input_state.num_vertex_buffers);
-
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
- pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
+ pipeline->vertexStrides[createinfo->vertex_input_state.vertex_buffer_descriptions[i].slot] =
+ createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
}
- } else {
- pipeline->vertexStrides = NULL;
}
// Resource layout
diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index e01cda26da3f5..2f71bac227e9f 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -2663,7 +2663,8 @@ static SDL_GPUGraphicsPipeline *D3D12_CreateGraphicsPipeline(
pipeline->pipelineState = pipelineState;
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
- pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
+ pipeline->vertexStrides[createinfo->vertex_input_state.vertex_buffer_descriptions[i].slot] =
+ createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
}
pipeline->primitiveType = createinfo->primitive_type;