From 244435832d4580cab23aaf3351566990a333bfc8 Mon Sep 17 00:00:00 2001 From: Bart van der Werf Date: Mon, 5 Aug 2024 15:03:43 +0200 Subject: [PATCH 1/4] Addresses https://github.com/thatcosmonaut/SDL/issues/135 --- src/gpu/SDL_gpu.c | 8 ++++---- src/gpu/SDL_sysgpu.h | 25 ++----------------------- src/gpu/d3d11/SDL_gpu_d3d11.c | 8 ++++---- src/gpu/d3d12/SDL_gpu_d3d12.c | 8 ++++---- src/gpu/vulkan/SDL_gpu_vulkan.c | 12 ++++-------- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/gpu/SDL_gpu.c b/src/gpu/SDL_gpu.c index 84d108b0faabe..dad4e33eb9e6d 100644 --- a/src/gpu/SDL_gpu.c +++ b/src/gpu/SDL_gpu.c @@ -1112,7 +1112,7 @@ void SDL_GpuDrawIndexedPrimitives( SDL_GpuRenderPass *renderPass, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount) { if (renderPass == NULL) { @@ -1129,14 +1129,14 @@ void SDL_GpuDrawIndexedPrimitives( RENDERPASS_COMMAND_BUFFER, baseVertex, startIndex, - primitiveCount, + vertexCount, instanceCount); } void SDL_GpuDrawPrimitives( SDL_GpuRenderPass *renderPass, Uint32 vertexStart, - Uint32 primitiveCount) + Uint32 vertexCount) { if (renderPass == NULL) { SDL_InvalidParamError("renderPass"); @@ -1151,7 +1151,7 @@ void SDL_GpuDrawPrimitives( RENDERPASS_DEVICE->DrawPrimitives( RENDERPASS_COMMAND_BUFFER, vertexStart, - primitiveCount); + vertexCount); } void SDL_GpuDrawPrimitivesIndirect( diff --git a/src/gpu/SDL_sysgpu.h b/src/gpu/SDL_sysgpu.h index 6d5e99e142ba2..889702c7c9f4c 100644 --- a/src/gpu/SDL_sysgpu.h +++ b/src/gpu/SDL_sysgpu.h @@ -118,27 +118,6 @@ static inline SDL_bool IsStencilFormat( } } -static inline Uint32 PrimitiveVerts( - SDL_GpuPrimitiveType primitiveType, - Uint32 primitiveCount) -{ - switch (primitiveType) { - case SDL_GPU_PRIMITIVETYPE_TRIANGLELIST: - return primitiveCount * 3; - case SDL_GPU_PRIMITIVETYPE_TRIANGLESTRIP: - return primitiveCount + 2; - case SDL_GPU_PRIMITIVETYPE_LINELIST: - return primitiveCount * 2; - case SDL_GPU_PRIMITIVETYPE_LINESTRIP: - return primitiveCount + 1; - case SDL_GPU_PRIMITIVETYPE_POINTLIST: - return primitiveCount; - default: - SDL_assert_release(!"Unrecognized primitive type!"); - return 0; - } -} - static inline Uint32 IndexSize(SDL_GpuIndexElementSize size) { return (size == SDL_GPU_INDEXELEMENTSIZE_16BIT) ? 2 : 4; @@ -369,13 +348,13 @@ struct SDL_GpuDevice SDL_GpuCommandBuffer *commandBuffer, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount); void (*DrawPrimitives)( SDL_GpuCommandBuffer *commandBuffer, Uint32 vertexStart, - Uint32 primitiveCount); + Uint32 vertexCount); void (*DrawPrimitivesIndirect)( SDL_GpuCommandBuffer *commandBuffer, diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c index 674f89ab41d55..1bf1e40ad0bca 100644 --- a/src/gpu/d3d11/SDL_gpu_d3d11.c +++ b/src/gpu/d3d11/SDL_gpu_d3d11.c @@ -4098,7 +4098,7 @@ static void D3D11_DrawIndexedPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; @@ -4106,7 +4106,7 @@ static void D3D11_DrawIndexedPrimitives( ID3D11DeviceContext_DrawIndexedInstanced( d3d11CommandBuffer->context, - PrimitiveVerts(d3d11CommandBuffer->graphicsPipeline->primitiveType, primitiveCount), + vertexCount, instanceCount, startIndex, baseVertex, @@ -4116,14 +4116,14 @@ static void D3D11_DrawIndexedPrimitives( static void D3D11_DrawPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 vertexStart, - Uint32 primitiveCount) + Uint32 vertexCount) { D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11_INTERNAL_BindGraphicsResources(d3d11CommandBuffer); ID3D11DeviceContext_Draw( d3d11CommandBuffer->context, - PrimitiveVerts(d3d11CommandBuffer->graphicsPipeline->primitiveType, primitiveCount), + vertexCount, vertexStart); } diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c index 67241c48ef726..e50c56824ec65 100644 --- a/src/gpu/d3d12/SDL_gpu_d3d12.c +++ b/src/gpu/d3d12/SDL_gpu_d3d12.c @@ -4083,7 +4083,7 @@ static void D3D12_DrawIndexedPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount) { D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer; @@ -4091,7 +4091,7 @@ static void D3D12_DrawIndexedPrimitives( ID3D12GraphicsCommandList_DrawIndexedInstanced( d3d12CommandBuffer->graphicsCommandList, - PrimitiveVerts(d3d12CommandBuffer->currentGraphicsPipeline->primitiveType, primitiveCount), + vertexCount, instanceCount, startIndex, baseVertex, @@ -4101,14 +4101,14 @@ static void D3D12_DrawIndexedPrimitives( static void D3D12_DrawPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 vertexStart, - Uint32 primitiveCount) + Uint32 vertexCount) { D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer; D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer); ID3D12GraphicsCommandList_DrawInstanced( d3d12CommandBuffer->graphicsCommandList, - PrimitiveVerts(d3d12CommandBuffer->currentGraphicsPipeline->primitiveType, primitiveCount), + vertexCount, 1, /* Instance count */ vertexStart, 0 /* Start instance location */ diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c index 56cf0e832ede8..d1f05fa33492d 100644 --- a/src/gpu/vulkan/SDL_gpu_vulkan.c +++ b/src/gpu/vulkan/SDL_gpu_vulkan.c @@ -5290,7 +5290,7 @@ static void VULKAN_DrawIndexedPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; @@ -5300,9 +5300,7 @@ static void VULKAN_DrawIndexedPrimitives( renderer->vkCmdDrawIndexed( vulkanCommandBuffer->commandBuffer, - PrimitiveVerts( - vulkanCommandBuffer->currentGraphicsPipeline->primitiveType, - primitiveCount), + vertexCount, instanceCount, startIndex, baseVertex, @@ -5312,7 +5310,7 @@ static void VULKAN_DrawIndexedPrimitives( static void VULKAN_DrawPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 vertexStart, - Uint32 primitiveCount) + Uint32 vertexCount) { VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; @@ -5321,9 +5319,7 @@ static void VULKAN_DrawPrimitives( renderer->vkCmdDraw( vulkanCommandBuffer->commandBuffer, - PrimitiveVerts( - vulkanCommandBuffer->currentGraphicsPipeline->primitiveType, - primitiveCount), + vertexCount, 1, vertexStart, 0); From 49716b96c575ab6bf765d9e0b1d090f82cd2fd93 Mon Sep 17 00:00:00 2001 From: Bart van der Werf Date: Mon, 5 Aug 2024 15:26:47 +0200 Subject: [PATCH 2/4] Update comments, fix missing metal changes --- include/SDL3/SDL_gpu.h | 6 +++--- src/gpu/metal/SDL_gpu_metal.m | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/SDL3/SDL_gpu.h b/include/SDL3/SDL_gpu.h index 9efe0ddb419c9..0b4c7acf491f7 100644 --- a/include/SDL3/SDL_gpu.h +++ b/include/SDL3/SDL_gpu.h @@ -1544,7 +1544,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuBindFragmentStorageBuffers( * \param renderPass a render pass handle * \param baseVertex the starting offset to read from the vertex buffer * \param startIndex the starting offset to read from the index buffer - * \param primitiveCount the number of primitives to draw + * \param vertexCount the number of vertices to draw * \param instanceCount the number of instances that will be drawn * * \since This function is available since SDL 3.x.x @@ -1562,14 +1562,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuDrawIndexedPrimitives( * * \param renderPass a render pass handle * \param vertexStart The starting offset to read from the vertex buffer - * \param primitiveCount The number of primitives to draw + * \param vertexCount The number of vertices to draw * * \since This function is available since SDL 3.x.x */ extern SDL_DECLSPEC void SDLCALL SDL_GpuDrawPrimitives( SDL_GpuRenderPass *renderPass, Uint32 vertexStart, - Uint32 primitiveCount); + Uint32 vertexCount); /** * Draws data using bound graphics state and with draw parameters set from a buffer. diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m index d936aae25d1f9..1513517cd7e6b 100644 --- a/src/gpu/metal/SDL_gpu_metal.m +++ b/src/gpu/metal/SDL_gpu_metal.m @@ -2691,7 +2691,7 @@ static void METAL_DrawIndexedPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount) { @autoreleasepool { @@ -2703,7 +2703,7 @@ static void METAL_DrawIndexedPrimitives( [metalCommandBuffer->renderEncoder drawIndexedPrimitives:SDLToMetal_PrimitiveType[primitiveType] - indexCount:PrimitiveVerts(primitiveType, primitiveCount) + indexCount:vertexCount indexType:SDLToMetal_IndexType[metalCommandBuffer->indexElementSize] indexBuffer:metalCommandBuffer->indexBuffer->handle indexBufferOffset:metalCommandBuffer->indexBufferOffset + (startIndex * indexSize) @@ -2716,7 +2716,7 @@ static void METAL_DrawIndexedPrimitives( static void METAL_DrawPrimitives( SDL_GpuCommandBuffer *commandBuffer, Uint32 vertexStart, - Uint32 primitiveCount) + Uint32 vertexCount) { @autoreleasepool { MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; @@ -2727,7 +2727,7 @@ static void METAL_DrawPrimitives( [metalCommandBuffer->renderEncoder drawPrimitives:SDLToMetal_PrimitiveType[primitiveType] vertexStart:vertexStart - vertexCount:PrimitiveVerts(primitiveType, primitiveCount)]; + vertexCount:vertexCount; } } From a5e5220b16b530cbebb4d5b09552b96ac2395933 Mon Sep 17 00:00:00 2001 From: Bart van der Werf Date: Mon, 5 Aug 2024 15:34:46 +0200 Subject: [PATCH 3/4] missed argument name. (visual studio refuses to find it in FindAll...) --- include/SDL3/SDL_gpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SDL3/SDL_gpu.h b/include/SDL3/SDL_gpu.h index 0b4c7acf491f7..f0807664f2d74 100644 --- a/include/SDL3/SDL_gpu.h +++ b/include/SDL3/SDL_gpu.h @@ -1553,7 +1553,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GpuDrawIndexedPrimitives( SDL_GpuRenderPass *renderPass, Uint32 baseVertex, Uint32 startIndex, - Uint32 primitiveCount, + Uint32 vertexCount, Uint32 instanceCount); /** From 688f2b24d59ca8329dfca1af243caefbcd421f54 Mon Sep 17 00:00:00 2001 From: Bart van der Werf Date: Mon, 5 Aug 2024 15:41:15 +0200 Subject: [PATCH 4/4] typo --- src/gpu/metal/SDL_gpu_metal.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m index 1513517cd7e6b..596db17e8aa85 100644 --- a/src/gpu/metal/SDL_gpu_metal.m +++ b/src/gpu/metal/SDL_gpu_metal.m @@ -2727,7 +2727,7 @@ static void METAL_DrawPrimitives( [metalCommandBuffer->renderEncoder drawPrimitives:SDLToMetal_PrimitiveType[primitiveType] vertexStart:vertexStart - vertexCount:vertexCount; + vertexCount:vertexCount]; } }