GPU: Remove pitch parameters from indirect draw calls (#10803)

This commit is contained in:
Caleb Cornett 2024-09-12 01:30:14 -05:00 committed by GitHub
parent 3d7e8c9bb7
commit ddd5723e2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 47 additions and 99 deletions

View file

@ -2651,7 +2651,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitives(
* Draws data using bound graphics state and with draw parameters set from a * Draws data using bound graphics state and with draw parameters set from a
* buffer. * buffer.
* *
* The buffer layout should match the layout of SDL_GPUIndirectDrawCommand. * The buffer must consist of tightly-packed draw parameter sets that
* each match the the layout of SDL_GPUIndirectDrawCommand.
* You must not call this function before binding a graphics pipeline. * You must not call this function before binding a graphics pipeline.
* *
* \param render_pass a render pass handle. * \param render_pass a render pass handle.
@ -2659,7 +2660,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitives(
* \param offset the offset to start reading from the draw buffer. * \param offset the offset to start reading from the draw buffer.
* \param draw_count the number of draw parameter sets that should be read * \param draw_count the number of draw parameter sets that should be read
* from the draw buffer. * from the draw buffer.
* \param pitch the byte pitch between sets of draw parameters.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.
*/ */
@ -2667,23 +2667,21 @@ extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitivesIndirect(
SDL_GPURenderPass *render_pass, SDL_GPURenderPass *render_pass,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 draw_count, Uint32 draw_count);
Uint32 pitch);
/** /**
* Draws data using bound graphics state with an index buffer enabled and with * Draws data using bound graphics state with an index buffer enabled and with
* draw parameters set from a buffer. * draw parameters set from a buffer.
* *
* The buffer layout should match the layout of * The buffer must consist of tightly-packed draw parameter sets that
* SDL_GPUIndexedIndirectDrawCommand. You must not call this function before * each match the the layout of SDL_GPUIndexedIndirectDrawCommand.
* binding a graphics pipeline. * You must not call this function before binding a graphics pipeline.
* *
* \param render_pass a render pass handle. * \param render_pass a render pass handle.
* \param buffer a buffer containing draw parameters. * \param buffer a buffer containing draw parameters.
* \param offset the offset to start reading from the draw buffer. * \param offset the offset to start reading from the draw buffer.
* \param draw_count the number of draw parameter sets that should be read * \param draw_count the number of draw parameter sets that should be read
* from the draw buffer. * from the draw buffer.
* \param pitch the byte pitch between sets of draw parameters.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.
*/ */
@ -2691,8 +2689,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUIndexedPrimitivesIndirect(
SDL_GPURenderPass *render_pass, SDL_GPURenderPass *render_pass,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 draw_count, Uint32 draw_count);
Uint32 pitch);
/** /**
* Ends the given render pass. * Ends the given render pass.
@ -2846,9 +2843,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DispatchGPUCompute(
/** /**
* Dispatches compute work with parameters set from a buffer. * Dispatches compute work with parameters set from a buffer.
* *
* The buffer layout should match the layout of * The buffer layout should match the layout of SDL_GPUIndirectDispatchCommand.
* SDL_GPUIndirectDispatchCommand. You must not call this function before * You must not call this function before binding a compute pipeline.
* binding a compute pipeline.
* *
* A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and * A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and
* the dispatches write to the same resource region as each other, there is no * the dispatches write to the same resource region as each other, there is no

View file

@ -188,9 +188,9 @@ SDL_DYNAPI_PROC(void,SDL_DispatchGPUComputeIndirect,(SDL_GPUComputePass *a, SDL_
SDL_DYNAPI_PROC(void,SDL_DownloadFromGPUBuffer,(SDL_GPUCopyPass *a, const SDL_GPUBufferRegion *b, const SDL_GPUTransferBufferLocation *c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_DownloadFromGPUBuffer,(SDL_GPUCopyPass *a, const SDL_GPUBufferRegion *b, const SDL_GPUTransferBufferLocation *c),(a,b,c),)
SDL_DYNAPI_PROC(void,SDL_DownloadFromGPUTexture,(SDL_GPUCopyPass *a, const SDL_GPUTextureRegion *b, const SDL_GPUTextureTransferInfo *c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_DownloadFromGPUTexture,(SDL_GPUCopyPass *a, const SDL_GPUTextureRegion *b, const SDL_GPUTextureTransferInfo *c),(a,b,c),)
SDL_DYNAPI_PROC(void,SDL_DrawGPUIndexedPrimitives,(SDL_GPURenderPass *a, Uint32 b, Uint32 c, Uint32 d, Sint32 e, Uint32 f),(a,b,c,d,e,f),) SDL_DYNAPI_PROC(void,SDL_DrawGPUIndexedPrimitives,(SDL_GPURenderPass *a, Uint32 b, Uint32 c, Uint32 d, Sint32 e, Uint32 f),(a,b,c,d,e,f),)
SDL_DYNAPI_PROC(void,SDL_DrawGPUIndexedPrimitivesIndirect,(SDL_GPURenderPass *a, SDL_GPUBuffer *b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),) SDL_DYNAPI_PROC(void,SDL_DrawGPUIndexedPrimitivesIndirect,(SDL_GPURenderPass *a, SDL_GPUBuffer *b, Uint32 c, Uint32 d),(a,b,c,d),)
SDL_DYNAPI_PROC(void,SDL_DrawGPUPrimitives,(SDL_GPURenderPass *a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),) SDL_DYNAPI_PROC(void,SDL_DrawGPUPrimitives,(SDL_GPURenderPass *a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),)
SDL_DYNAPI_PROC(void,SDL_DrawGPUPrimitivesIndirect,(SDL_GPURenderPass *a, SDL_GPUBuffer *b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),) SDL_DYNAPI_PROC(void,SDL_DrawGPUPrimitivesIndirect,(SDL_GPURenderPass *a, SDL_GPUBuffer *b, Uint32 c, Uint32 d),(a,b,c,d),)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentConfig,(void),(),return) SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentConfig,(void),(),return)
SDL_DYNAPI_PROC(SDL_EGLDisplay,SDL_EGL_GetCurrentDisplay,(void),(),return) SDL_DYNAPI_PROC(SDL_EGLDisplay,SDL_EGL_GetCurrentDisplay,(void),(),return)

View file

@ -1631,8 +1631,7 @@ void SDL_DrawGPUPrimitivesIndirect(
SDL_GPURenderPass *render_pass, SDL_GPURenderPass *render_pass,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 draw_count, Uint32 draw_count)
Uint32 pitch)
{ {
if (render_pass == NULL) { if (render_pass == NULL) {
SDL_InvalidParamError("render_pass"); SDL_InvalidParamError("render_pass");
@ -1652,16 +1651,14 @@ void SDL_DrawGPUPrimitivesIndirect(
RENDERPASS_COMMAND_BUFFER, RENDERPASS_COMMAND_BUFFER,
buffer, buffer,
offset, offset,
draw_count, draw_count);
pitch);
} }
void SDL_DrawGPUIndexedPrimitivesIndirect( void SDL_DrawGPUIndexedPrimitivesIndirect(
SDL_GPURenderPass *render_pass, SDL_GPURenderPass *render_pass,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 draw_count, Uint32 draw_count)
Uint32 pitch)
{ {
if (render_pass == NULL) { if (render_pass == NULL) {
SDL_InvalidParamError("render_pass"); SDL_InvalidParamError("render_pass");
@ -1681,8 +1678,7 @@ void SDL_DrawGPUIndexedPrimitivesIndirect(
RENDERPASS_COMMAND_BUFFER, RENDERPASS_COMMAND_BUFFER,
buffer, buffer,
offset, offset,
draw_count, draw_count);
pitch);
} }
void SDL_EndGPURenderPass( void SDL_EndGPURenderPass(

View file

@ -485,15 +485,13 @@ struct SDL_GPUDevice
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount);
Uint32 pitch);
void (*DrawIndexedPrimitivesIndirect)( void (*DrawIndexedPrimitivesIndirect)(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount);
Uint32 pitch);
void (*EndRenderPass)( void (*EndRenderPass)(
SDL_GPUCommandBuffer *commandBuffer); SDL_GPUCommandBuffer *commandBuffer);

View file

@ -4156,8 +4156,7 @@ static void D3D11_DrawPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
D3D11_INTERNAL_BindGraphicsResources(d3d11CommandBuffer); D3D11_INTERNAL_BindGraphicsResources(d3d11CommandBuffer);
@ -4171,7 +4170,7 @@ static void D3D11_DrawPrimitivesIndirect(
ID3D11DeviceContext_DrawInstancedIndirect( ID3D11DeviceContext_DrawInstancedIndirect(
d3d11CommandBuffer->context, d3d11CommandBuffer->context,
d3d11Buffer->handle, d3d11Buffer->handle,
offset + (pitch * i)); offset + (sizeof(SDL_GPUIndirectDrawCommand) * i));
} }
D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, d3d11Buffer); D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, d3d11Buffer);
@ -4181,8 +4180,7 @@ static void D3D11_DrawIndexedPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer; D3D11CommandBuffer *d3d11CommandBuffer = (D3D11CommandBuffer *)commandBuffer;
D3D11_INTERNAL_BindGraphicsResources(d3d11CommandBuffer); D3D11_INTERNAL_BindGraphicsResources(d3d11CommandBuffer);
@ -4196,7 +4194,7 @@ static void D3D11_DrawIndexedPrimitivesIndirect(
ID3D11DeviceContext_DrawIndexedInstancedIndirect( ID3D11DeviceContext_DrawIndexedInstancedIndirect(
d3d11CommandBuffer->context, d3d11CommandBuffer->context,
d3d11Buffer->handle, d3d11Buffer->handle,
offset + (pitch * i)); offset + (sizeof(SDL_GPUIndexedIndirectDrawCommand) * i));
} }
D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, d3d11Buffer); D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, d3d11Buffer);

View file

@ -4722,16 +4722,13 @@ static void D3D12_DrawPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer; D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer; D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer;
D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer); D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer);
if (pitch == sizeof(SDL_GPUIndirectDrawCommand)) {
// Real multi-draw!
ID3D12GraphicsCommandList_ExecuteIndirect( ID3D12GraphicsCommandList_ExecuteIndirect(
d3d12CommandBuffer->graphicsCommandList, d3d12CommandBuffer->graphicsCommandList,
d3d12CommandBuffer->renderer->indirectDrawCommandSignature, d3d12CommandBuffer->renderer->indirectDrawCommandSignature,
@ -4740,38 +4737,19 @@ static void D3D12_DrawPrimitivesIndirect(
offset, offset,
NULL, NULL,
0); 0);
} else {
/* Fake multi-draw...
* FIXME: we could make this real multi-draw
* if we have a lookup to get command signature per pitch value
*/
for (Uint32 i = 0; i < drawCount; i += 1) {
ID3D12GraphicsCommandList_ExecuteIndirect(
d3d12CommandBuffer->graphicsCommandList,
d3d12CommandBuffer->renderer->indirectDrawCommandSignature,
1,
d3d12Buffer->handle,
offset + (pitch * i),
NULL,
0);
}
}
} }
static void D3D12_DrawIndexedPrimitivesIndirect( static void D3D12_DrawIndexedPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer; D3D12CommandBuffer *d3d12CommandBuffer = (D3D12CommandBuffer *)commandBuffer;
D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer; D3D12Buffer *d3d12Buffer = ((D3D12BufferContainer *)buffer)->activeBuffer;
D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer); D3D12_INTERNAL_BindGraphicsResources(d3d12CommandBuffer);
if (pitch == sizeof(SDL_GPUIndexedIndirectDrawCommand)) {
// Real multi-draw!
ID3D12GraphicsCommandList_ExecuteIndirect( ID3D12GraphicsCommandList_ExecuteIndirect(
d3d12CommandBuffer->graphicsCommandList, d3d12CommandBuffer->graphicsCommandList,
d3d12CommandBuffer->renderer->indirectIndexedDrawCommandSignature, d3d12CommandBuffer->renderer->indirectIndexedDrawCommandSignature,
@ -4780,22 +4758,6 @@ static void D3D12_DrawIndexedPrimitivesIndirect(
offset, offset,
NULL, NULL,
0); 0);
} else {
/* Fake multi-draw...
* FIXME: we could make this real multi-draw
* if we have a lookup to get command signature per pitch value
*/
for (Uint32 i = 0; i < drawCount; i += 1) {
ID3D12GraphicsCommandList_ExecuteIndirect(
d3d12CommandBuffer->graphicsCommandList,
d3d12CommandBuffer->renderer->indirectIndexedDrawCommandSignature,
1,
d3d12Buffer->handle,
offset + (pitch * i),
NULL,
0);
}
}
} }
static void D3D12_EndRenderPass( static void D3D12_EndRenderPass(

View file

@ -2750,8 +2750,7 @@ static void METAL_DrawPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
@autoreleasepool { @autoreleasepool {
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
@ -2767,7 +2766,7 @@ static void METAL_DrawPrimitivesIndirect(
[metalCommandBuffer->renderEncoder [metalCommandBuffer->renderEncoder
drawPrimitives:SDLToMetal_PrimitiveType[primitiveType] drawPrimitives:SDLToMetal_PrimitiveType[primitiveType]
indirectBuffer:metalBuffer->handle indirectBuffer:metalBuffer->handle
indirectBufferOffset:offset + (pitch * i)]; indirectBufferOffset:offset + (sizeof(SDL_GPUIndirectDrawCommand) * i)];
} }
METAL_INTERNAL_TrackBuffer(metalCommandBuffer, metalBuffer); METAL_INTERNAL_TrackBuffer(metalCommandBuffer, metalBuffer);
@ -2778,8 +2777,7 @@ static void METAL_DrawIndexedPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
@autoreleasepool { @autoreleasepool {
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
@ -2795,7 +2793,7 @@ static void METAL_DrawIndexedPrimitivesIndirect(
indexBuffer:metalCommandBuffer->indexBuffer->handle indexBuffer:metalCommandBuffer->indexBuffer->handle
indexBufferOffset:metalCommandBuffer->indexBufferOffset indexBufferOffset:metalCommandBuffer->indexBufferOffset
indirectBuffer:metalBuffer->handle indirectBuffer:metalBuffer->handle
indirectBufferOffset:offset + (pitch * i)]; indirectBufferOffset:offset + (sizeof(SDL_GPUIndexedIndirectDrawCommand) * i)];
} }
METAL_INTERNAL_TrackBuffer(metalCommandBuffer, metalBuffer); METAL_INTERNAL_TrackBuffer(metalCommandBuffer, metalBuffer);

View file

@ -5357,12 +5357,12 @@ static void VULKAN_DrawPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer;
VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer;
VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer *)buffer)->activeBufferHandle->vulkanBuffer; VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer *)buffer)->activeBufferHandle->vulkanBuffer;
Uint32 pitch = sizeof(SDL_GPUIndirectDrawCommand);
Uint32 i; Uint32 i;
VULKAN_INTERNAL_BindGraphicsDescriptorSets(renderer, vulkanCommandBuffer); VULKAN_INTERNAL_BindGraphicsDescriptorSets(renderer, vulkanCommandBuffer);
@ -5394,12 +5394,12 @@ static void VULKAN_DrawIndexedPrimitivesIndirect(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
SDL_GPUBuffer *buffer, SDL_GPUBuffer *buffer,
Uint32 offset, Uint32 offset,
Uint32 drawCount, Uint32 drawCount)
Uint32 pitch)
{ {
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer; VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer *)commandBuffer;
VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer; VulkanRenderer *renderer = (VulkanRenderer *)vulkanCommandBuffer->renderer;
VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer *)buffer)->activeBufferHandle->vulkanBuffer; VulkanBuffer *vulkanBuffer = ((VulkanBufferContainer *)buffer)->activeBufferHandle->vulkanBuffer;
Uint32 pitch = sizeof(SDL_GPUIndexedIndirectDrawCommand);
Uint32 i; Uint32 i;
VULKAN_INTERNAL_BindGraphicsDescriptorSets(renderer, vulkanCommandBuffer); VULKAN_INTERNAL_BindGraphicsDescriptorSets(renderer, vulkanCommandBuffer);