GPU: Rename VertexBinding to VertexBufferDescription (#10811)

This commit is contained in:
Caleb Cornett 2024-09-12 18:02:39 -05:00 committed by GitHub
parent 446ee3e7c5
commit a45a2caf49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 130 additions and 103 deletions

View file

@ -1179,42 +1179,46 @@ typedef struct SDL_GPUSamplerCreateInfo
} SDL_GPUSamplerCreateInfo; } SDL_GPUSamplerCreateInfo;
/** /**
* A structure specifying a vertex binding. * A structure specifying the parameters of vertex buffers used in a graphics
* pipeline.
* *
* When you call SDL_BindGPUVertexBuffers, you specify the binding indices of * When you call SDL_BindGPUVertexBuffers, you specify the binding slots of
* the vertex buffers. For example if you called SDL_BindGPUVertexBuffers with * the vertex buffers. For example if you called SDL_BindGPUVertexBuffers with
* a first_binding of 2 and num_bindings of 3, the binding indices 2, 3, 4 * a first_slot of 2 and num_bindings of 3, the binding slots 2, 3, 4 would be
* would be used by the vertex buffers you pass in. * used by the vertex buffers you pass in.
* *
* Vertex attributes are linked to bindings via the index. The binding_index * Vertex attributes are linked to buffers via the buffer_slot field of
* field of SDL_GPUVertexAttribute specifies the vertex buffer binding index * SDL_GPUVertexAttribute. For example, if an attribute has a buffer_slot of 0,
* that the attribute will be read from. * then that attribute belongs to the vertex buffer bound at slot 0.
* *
* \since This struct is available since SDL 3.0.0 * \since This struct is available since SDL 3.0.0
* *
* \sa SDL_GPUVertexAttribute * \sa SDL_GPUVertexAttribute
* \sa SDL_GPUVertexInputState * \sa SDL_GPUVertexInputState
*/ */
typedef struct SDL_GPUVertexBinding typedef struct SDL_GPUVertexBufferDescription
{ {
Uint32 index; /**< The binding index. */ Uint32 slot; /**< The binding slot of the vertex buffer. */
Uint32 pitch; /**< The byte pitch between consecutive elements of the vertex buffer. */ Uint32 pitch; /**< The byte pitch between consecutive elements of the vertex buffer. */
SDL_GPUVertexInputRate input_rate; /**< Whether attribute addressing is a function of the vertex index or instance index. */ SDL_GPUVertexInputRate input_rate; /**< Whether attribute addressing is a function of the vertex index or instance index. */
Uint32 instance_step_rate; /**< The number of instances to draw using the same per-instance data before advancing in the instance buffer by one element. Ignored unless input_rate is SDL_GPU_VERTEXINPUTRATE_INSTANCE */ Uint32 instance_step_rate; /**< The number of instances to draw using the same per-instance data before advancing in the instance buffer by one element. Ignored unless input_rate is SDL_GPU_VERTEXINPUTRATE_INSTANCE */
} SDL_GPUVertexBinding; } SDL_GPUVertexBufferDescription;
/** /**
* A structure specifying a vertex attribute. * A structure specifying a vertex attribute.
* *
* All vertex attribute locations provided to an SDL_GPUVertexInputState
* must be unique.
*
* \since This struct is available since SDL 3.0.0 * \since This struct is available since SDL 3.0.0
* *
* \sa SDL_GPUVertexBinding * \sa SDL_GPUVertexBufferDescription
* \sa SDL_GPUVertexInputState * \sa SDL_GPUVertexInputState
*/ */
typedef struct SDL_GPUVertexAttribute typedef struct SDL_GPUVertexAttribute
{ {
Uint32 location; /**< The shader input location index. */ Uint32 location; /**< The shader input location index. */
Uint32 binding_index; /**< The binding index. */ Uint32 buffer_slot; /**< The binding slot of the associated vertex buffer. */
SDL_GPUVertexElementFormat format; /**< The size and type of the attribute data. */ SDL_GPUVertexElementFormat format; /**< The size and type of the attribute data. */
Uint32 offset; /**< The byte offset of this attribute relative to the start of the vertex element. */ Uint32 offset; /**< The byte offset of this attribute relative to the start of the vertex element. */
} SDL_GPUVertexAttribute; } SDL_GPUVertexAttribute;
@ -1229,10 +1233,10 @@ typedef struct SDL_GPUVertexAttribute
*/ */
typedef struct SDL_GPUVertexInputState typedef struct SDL_GPUVertexInputState
{ {
const SDL_GPUVertexBinding *vertex_bindings; /**< A pointer to an array of vertex binding descriptions. */ const SDL_GPUVertexBufferDescription *vertex_buffer_descriptions; /**< A pointer to an array of vertex buffer descriptions. */
Uint32 num_vertex_bindings; /**< The number of vertex binding descriptions in the above array. */ Uint32 num_vertex_buffers; /**< The number of vertex buffer descriptions in the above array. */
const SDL_GPUVertexAttribute *vertex_attributes; /**< A pointer to an array of vertex attribute descriptions. */ const SDL_GPUVertexAttribute *vertex_attributes; /**< A pointer to an array of vertex attribute descriptions. */
Uint32 num_vertex_attributes; /**< The number of vertex attribute descriptions in the above array. */ Uint32 num_vertex_attributes; /**< The number of vertex attribute descriptions in the above array. */
} SDL_GPUVertexInputState; } SDL_GPUVertexInputState;
/** /**
@ -2447,7 +2451,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGPUStencilReference(
* calls. * calls.
* *
* \param render_pass a render pass handle. * \param render_pass a render pass handle.
* \param first_binding the starting bind point for the vertex buffers. * \param first_slot the vertex buffer slot to begin binding from.
* \param bindings an array of SDL_GPUBufferBinding structs containing vertex * \param bindings an array of SDL_GPUBufferBinding structs containing vertex
* buffers and offset values. * buffers and offset values.
* \param num_bindings the number of bindings in the bindings array. * \param num_bindings the number of bindings in the bindings array.
@ -2456,7 +2460,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGPUStencilReference(
*/ */
extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexBuffers( extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexBuffers(
SDL_GPURenderPass *render_pass, SDL_GPURenderPass *render_pass,
Uint32 first_binding, Uint32 first_slot,
const SDL_GPUBufferBinding *bindings, const SDL_GPUBufferBinding *bindings,
Uint32 num_bindings); Uint32 num_bindings);

View file

@ -692,16 +692,32 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
return NULL; return NULL;
} }
} }
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_bindings > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_bindings == NULL) { if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_buffers > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_buffer_descriptions == NULL) {
SDL_assert_release(!"Vertex bindings array pointer cannot be NULL!"); SDL_assert_release(!"Vertex buffer descriptions array pointer cannot be NULL!");
return NULL;
}
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_buffers > MAX_VERTEX_BUFFERS) {
SDL_assert_release(!"The number of vertex buffer descriptions in a vertex input state must not exceed 16!");
return NULL; return NULL;
} }
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes == NULL) { if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes == NULL) {
SDL_assert_release(!"Vertex attributes array pointer cannot be NULL!"); SDL_assert_release(!"Vertex attributes array pointer cannot be NULL!");
return NULL; return NULL;
} }
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes > MAX_VERTEX_ATTRIBUTES) {
SDL_assert_release(!"The number of vertex attributes in a vertex input state must not exceed 16!");
return NULL;
}
Uint32 locations[MAX_VERTEX_ATTRIBUTES];
for (Uint32 i = 0; i < graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes; i += 1) { for (Uint32 i = 0; i < graphicsPipelineCreateInfo->vertex_input_state.num_vertex_attributes; i += 1) {
CHECK_VERTEXELEMENTFORMAT_ENUM_INVALID(graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes[i].format, NULL); CHECK_VERTEXELEMENTFORMAT_ENUM_INVALID(graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes[i].format, NULL);
locations[i] = graphicsPipelineCreateInfo->vertex_input_state.vertex_attributes[i].location;
for (Uint32 j = 0; j < i; j += 1) {
if (locations[j] == locations[i]) {
SDL_assert_release(!"Each vertex attribute location in a vertex input state must be unique!");
}
}
} }
if (graphicsPipelineCreateInfo->depth_stencil_state.enable_depth_test) { if (graphicsPipelineCreateInfo->depth_stencil_state.enable_depth_test) {
CHECK_COMPAREOP_ENUM_INVALID(graphicsPipelineCreateInfo->depth_stencil_state.compare_op, NULL) CHECK_COMPAREOP_ENUM_INVALID(graphicsPipelineCreateInfo->depth_stencil_state.compare_op, NULL)

View file

@ -232,7 +232,8 @@ static inline Sint32 BytesPerImage(
#define MAX_COMPUTE_WRITE_TEXTURES 8 #define MAX_COMPUTE_WRITE_TEXTURES 8
#define MAX_COMPUTE_WRITE_BUFFERS 8 #define MAX_COMPUTE_WRITE_BUFFERS 8
#define UNIFORM_BUFFER_SIZE 32768 #define UNIFORM_BUFFER_SIZE 32768
#define MAX_BUFFER_BINDINGS 16 #define MAX_VERTEX_BUFFERS 16
#define MAX_VERTEX_ATTRIBUTES 16
#define MAX_COLOR_TARGET_BINDINGS 4 #define MAX_COLOR_TARGET_BINDINGS 4
#define MAX_PRESENT_COUNT 16 #define MAX_PRESENT_COUNT 16
#define MAX_FRAMES_IN_FLIGHT 3 #define MAX_FRAMES_IN_FLIGHT 3
@ -411,7 +412,7 @@ struct SDL_GPUDevice
void (*BindVertexBuffers)( void (*BindVertexBuffers)(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
Uint32 firstBinding, Uint32 firstSlot,
const SDL_GPUBufferBinding *bindings, const SDL_GPUBufferBinding *bindings,
Uint32 numBindings); Uint32 numBindings);

View file

@ -672,8 +672,8 @@ typedef struct D3D11CommandBuffer
// defer OMSetBlendState because it combines three different states // defer OMSetBlendState because it combines three different states
bool needBlendStateSet; bool needBlendStateSet;
ID3D11Buffer *vertexBuffers[MAX_BUFFER_BINDINGS]; ID3D11Buffer *vertexBuffers[MAX_VERTEX_BUFFERS];
Uint32 vertexBufferOffsets[MAX_BUFFER_BINDINGS]; Uint32 vertexBufferOffsets[MAX_VERTEX_BUFFERS];
Uint32 vertexBufferCount; Uint32 vertexBufferCount;
D3D11Texture *vertexSamplerTextures[MAX_TEXTURE_SAMPLERS_PER_STAGE]; D3D11Texture *vertexSamplerTextures[MAX_TEXTURE_SAMPLERS_PER_STAGE];
@ -1380,18 +1380,18 @@ static ID3D11RasterizerState *D3D11_INTERNAL_FetchRasterizerState(
return result; return result;
} }
static Uint32 D3D11_INTERNAL_FindIndexOfVertexBinding( static Uint32 D3D11_INTERNAL_FindIndexOfVertexSlot(
Uint32 targetBinding, Uint32 targetSlot,
const SDL_GPUVertexBinding *bindings, const SDL_GPUVertexBufferDescription *bufferDescriptions,
Uint32 numBindings) Uint32 numDescriptions)
{ {
for (Uint32 i = 0; i < numBindings; i += 1) { for (Uint32 i = 0; i < numDescriptions; i += 1) {
if (bindings[i].index == targetBinding) { if (bufferDescriptions[i].slot == targetSlot) {
return i; return i;
} }
} }
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Could not find vertex binding %u!", targetBinding); SDL_LogError(SDL_LOG_CATEGORY_GPU, "Could not find vertex buffer slot %u!", targetSlot);
return 0; return 0;
} }
@ -1420,15 +1420,17 @@ static ID3D11InputLayout *D3D11_INTERNAL_FetchInputLayout(
for (Uint32 i = 0; i < inputState.num_vertex_attributes; i += 1) { for (Uint32 i = 0; i < inputState.num_vertex_attributes; i += 1) {
elementDescs[i].AlignedByteOffset = inputState.vertex_attributes[i].offset; elementDescs[i].AlignedByteOffset = inputState.vertex_attributes[i].offset;
elementDescs[i].Format = SDLToD3D11_VertexFormat[inputState.vertex_attributes[i].format]; elementDescs[i].Format = SDLToD3D11_VertexFormat[inputState.vertex_attributes[i].format];
elementDescs[i].InputSlot = inputState.vertex_attributes[i].binding_index; elementDescs[i].InputSlot = inputState.vertex_attributes[i].buffer_slot;
bindingIndex = D3D11_INTERNAL_FindIndexOfVertexBinding( bindingIndex = D3D11_INTERNAL_FindIndexOfVertexSlot(
elementDescs[i].InputSlot, elementDescs[i].InputSlot,
inputState.vertex_bindings, inputState.vertex_buffer_descriptions,
inputState.num_vertex_bindings); inputState.num_vertex_buffers);
elementDescs[i].InputSlotClass = SDLToD3D11_VertexInputRate[inputState.vertex_bindings[bindingIndex].input_rate]; elementDescs[i].InputSlotClass = SDLToD3D11_VertexInputRate[inputState.vertex_buffer_descriptions[bindingIndex].input_rate];
// The spec requires this to be 0 for per-vertex data // The spec requires this to be 0 for per-vertex data
elementDescs[i].InstanceDataStepRate = (inputState.vertex_bindings[bindingIndex].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? inputState.vertex_bindings[bindingIndex].instance_step_rate : 0; elementDescs[i].InstanceDataStepRate = (inputState.vertex_buffer_descriptions[bindingIndex].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE)
? inputState.vertex_buffer_descriptions[bindingIndex].instance_step_rate
: 0;
elementDescs[i].SemanticIndex = inputState.vertex_attributes[i].location; elementDescs[i].SemanticIndex = inputState.vertex_attributes[i].location;
elementDescs[i].SemanticName = "TEXCOORD"; elementDescs[i].SemanticName = "TEXCOORD";
@ -1609,13 +1611,13 @@ static SDL_GPUGraphicsPipeline *D3D11_CreateGraphicsPipeline(
vertShader->bytecode, vertShader->bytecode,
vertShader->bytecodeSize); vertShader->bytecodeSize);
if (createinfo->vertex_input_state.num_vertex_bindings > 0) { if (createinfo->vertex_input_state.num_vertex_buffers > 0) {
pipeline->vertexStrides = SDL_malloc( pipeline->vertexStrides = SDL_malloc(
sizeof(Uint32) * sizeof(Uint32) *
createinfo->vertex_input_state.num_vertex_bindings); createinfo->vertex_input_state.num_vertex_buffers);
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_bindings; i += 1) { for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_bindings[i].pitch; pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
} }
} else { } else {
pipeline->vertexStrides = NULL; pipeline->vertexStrides = NULL;
@ -3732,7 +3734,7 @@ static void D3D11_BindGraphicsPipeline(
static void D3D11_BindVertexBuffers( static void D3D11_BindVertexBuffers(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
Uint32 firstBinding, Uint32 firstSlot,
const SDL_GPUBufferBinding *bindings, const SDL_GPUBufferBinding *bindings,
Uint32 numBindings) Uint32 numBindings)
{ {
@ -3740,13 +3742,13 @@ static void D3D11_BindVertexBuffers(
for (Uint32 i = 0; i < numBindings; i += 1) { for (Uint32 i = 0; i < numBindings; i += 1) {
D3D11Buffer *currentBuffer = ((D3D11BufferContainer *)bindings[i].buffer)->activeBuffer; D3D11Buffer *currentBuffer = ((D3D11BufferContainer *)bindings[i].buffer)->activeBuffer;
d3d11CommandBuffer->vertexBuffers[firstBinding + i] = currentBuffer->handle; d3d11CommandBuffer->vertexBuffers[firstSlot + i] = currentBuffer->handle;
d3d11CommandBuffer->vertexBufferOffsets[firstBinding + i] = bindings[i].offset; d3d11CommandBuffer->vertexBufferOffsets[firstSlot + i] = bindings[i].offset;
D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, currentBuffer); D3D11_INTERNAL_TrackBuffer(d3d11CommandBuffer, currentBuffer);
} }
d3d11CommandBuffer->vertexBufferCount = d3d11CommandBuffer->vertexBufferCount =
SDL_max(d3d11CommandBuffer->vertexBufferCount, firstBinding + numBindings); SDL_max(d3d11CommandBuffer->vertexBufferCount, firstSlot + numBindings);
d3d11CommandBuffer->needVertexBufferBind = true; d3d11CommandBuffer->needVertexBufferBind = true;
} }

View file

@ -702,8 +702,8 @@ struct D3D12CommandBuffer
bool needComputeReadOnlyStorageBufferBind; bool needComputeReadOnlyStorageBufferBind;
bool needComputeUniformBufferBind[MAX_UNIFORM_BUFFERS_PER_STAGE]; bool needComputeUniformBufferBind[MAX_UNIFORM_BUFFERS_PER_STAGE];
D3D12Buffer *vertexBuffers[MAX_BUFFER_BINDINGS]; D3D12Buffer *vertexBuffers[MAX_VERTEX_BUFFERS];
Uint32 vertexBufferOffsets[MAX_BUFFER_BINDINGS]; Uint32 vertexBufferOffsets[MAX_VERTEX_BUFFERS];
Uint32 vertexBufferCount; Uint32 vertexBufferCount;
D3D12Texture *vertexSamplerTextures[MAX_TEXTURE_SAMPLERS_PER_STAGE]; D3D12Texture *vertexSamplerTextures[MAX_TEXTURE_SAMPLERS_PER_STAGE];
@ -792,7 +792,7 @@ struct D3D12GraphicsPipeline
D3D12GraphicsRootSignature *rootSignature; D3D12GraphicsRootSignature *rootSignature;
SDL_GPUPrimitiveType primitiveType; SDL_GPUPrimitiveType primitiveType;
Uint32 vertexStrides[MAX_BUFFER_BINDINGS]; Uint32 vertexStrides[MAX_VERTEX_BUFFERS];
Uint32 vertexSamplerCount; Uint32 vertexSamplerCount;
Uint32 vertexUniformBufferCount; Uint32 vertexUniformBufferCount;
@ -2531,10 +2531,12 @@ static bool D3D12_INTERNAL_ConvertVertexInputState(SDL_GPUVertexInputState verte
desc[i].SemanticName = semantic; desc[i].SemanticName = semantic;
desc[i].SemanticIndex = attribute.location; desc[i].SemanticIndex = attribute.location;
desc[i].Format = SDLToD3D12_VertexFormat[attribute.format]; desc[i].Format = SDLToD3D12_VertexFormat[attribute.format];
desc[i].InputSlot = attribute.binding_index; desc[i].InputSlot = attribute.buffer_slot;
desc[i].AlignedByteOffset = attribute.offset; desc[i].AlignedByteOffset = attribute.offset;
desc[i].InputSlotClass = SDLToD3D12_InputRate[vertexInputState.vertex_bindings[attribute.binding_index].input_rate]; desc[i].InputSlotClass = SDLToD3D12_InputRate[vertexInputState.vertex_buffer_descriptions[attribute.buffer_slot].input_rate];
desc[i].InstanceDataStepRate = (vertexInputState.vertex_bindings[attribute.binding_index].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? vertexInputState.vertex_bindings[attribute.binding_index].instance_step_rate : 0; desc[i].InstanceDataStepRate = (vertexInputState.vertex_buffer_descriptions[attribute.buffer_slot].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE)
? vertexInputState.vertex_buffer_descriptions[attribute.buffer_slot].instance_step_rate
: 0;
} }
return true; return true;
@ -2660,8 +2662,8 @@ static SDL_GPUGraphicsPipeline *D3D12_CreateGraphicsPipeline(
pipeline->pipelineState = pipelineState; pipeline->pipelineState = pipelineState;
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_bindings; i += 1) { for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_bindings[i].pitch; pipeline->vertexStrides[i] = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
} }
pipeline->primitiveType = createinfo->primitive_type; pipeline->primitiveType = createinfo->primitive_type;
@ -4250,7 +4252,7 @@ static void D3D12_BindGraphicsPipeline(
static void D3D12_BindVertexBuffers( static void D3D12_BindVertexBuffers(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
Uint32 firstBinding, Uint32 firstSlot,
const SDL_GPUBufferBinding *bindings, const SDL_GPUBufferBinding *bindings,
Uint32 numBindings) Uint32 numBindings)
{ {
@ -4258,13 +4260,13 @@ static void D3D12_BindVertexBuffers(
for (Uint32 i = 0; i < numBindings; i += 1) { for (Uint32 i = 0; i < numBindings; i += 1) {
D3D12Buffer *currentBuffer = ((D3D12BufferContainer *)bindings[i].buffer)->activeBuffer; D3D12Buffer *currentBuffer = ((D3D12BufferContainer *)bindings[i].buffer)->activeBuffer;
d3d12CommandBuffer->vertexBuffers[firstBinding + i] = currentBuffer; d3d12CommandBuffer->vertexBuffers[firstSlot + i] = currentBuffer;
d3d12CommandBuffer->vertexBufferOffsets[firstBinding + i] = bindings[i].offset; d3d12CommandBuffer->vertexBufferOffsets[firstSlot + i] = bindings[i].offset;
D3D12_INTERNAL_TrackBuffer(d3d12CommandBuffer, currentBuffer); D3D12_INTERNAL_TrackBuffer(d3d12CommandBuffer, currentBuffer);
} }
d3d12CommandBuffer->vertexBufferCount = d3d12CommandBuffer->vertexBufferCount =
SDL_max(d3d12CommandBuffer->vertexBufferCount, firstBinding + numBindings); SDL_max(d3d12CommandBuffer->vertexBufferCount, firstSlot + numBindings);
d3d12CommandBuffer->needVertexBufferBind = true; d3d12CommandBuffer->needVertexBufferBind = true;
} }
@ -4492,7 +4494,7 @@ static void D3D12_INTERNAL_BindGraphicsResources(
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandles[MAX_TEXTURE_SAMPLERS_PER_STAGE]; D3D12_CPU_DESCRIPTOR_HANDLE cpuHandles[MAX_TEXTURE_SAMPLERS_PER_STAGE];
D3D12_GPU_DESCRIPTOR_HANDLE gpuDescriptorHandle; D3D12_GPU_DESCRIPTOR_HANDLE gpuDescriptorHandle;
D3D12_VERTEX_BUFFER_VIEW vertexBufferViews[MAX_BUFFER_BINDINGS]; D3D12_VERTEX_BUFFER_VIEW vertexBufferViews[MAX_VERTEX_BUFFERS];
if (commandBuffer->needVertexBufferBind) { if (commandBuffer->needVertexBufferBind) {
for (Uint32 i = 0; i < commandBuffer->vertexBufferCount; i += 1) { for (Uint32 i = 0; i < commandBuffer->vertexBufferCount; i += 1) {

View file

@ -1090,21 +1090,23 @@ static SDL_GPUGraphicsPipeline *METAL_CreateGraphicsPipeline(
// Vertex Descriptor // Vertex Descriptor
if (createinfo->vertex_input_state.num_vertex_bindings > 0) { if (createinfo->vertex_input_state.num_vertex_buffers > 0) {
vertexDescriptor = [MTLVertexDescriptor vertexDescriptor]; vertexDescriptor = [MTLVertexDescriptor vertexDescriptor];
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_attributes; i += 1) { for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_attributes; i += 1) {
Uint32 loc = createinfo->vertex_input_state.vertex_attributes[i].location; Uint32 loc = createinfo->vertex_input_state.vertex_attributes[i].location;
vertexDescriptor.attributes[loc].format = SDLToMetal_VertexFormat[createinfo->vertex_input_state.vertex_attributes[i].format]; vertexDescriptor.attributes[loc].format = SDLToMetal_VertexFormat[createinfo->vertex_input_state.vertex_attributes[i].format];
vertexDescriptor.attributes[loc].offset = createinfo->vertex_input_state.vertex_attributes[i].offset; vertexDescriptor.attributes[loc].offset = createinfo->vertex_input_state.vertex_attributes[i].offset;
vertexDescriptor.attributes[loc].bufferIndex = METAL_INTERNAL_GetVertexBufferIndex(createinfo->vertex_input_state.vertex_attributes[i].binding_index); vertexDescriptor.attributes[loc].bufferIndex = METAL_INTERNAL_GetVertexBufferIndex(createinfo->vertex_input_state.vertex_attributes[i].buffer_slot);
} }
for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_bindings; i += 1) { for (Uint32 i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
binding = METAL_INTERNAL_GetVertexBufferIndex(createinfo->vertex_input_state.vertex_bindings[i].index); binding = METAL_INTERNAL_GetVertexBufferIndex(createinfo->vertex_input_state.vertex_buffer_descriptions[i].slot);
vertexDescriptor.layouts[binding].stepFunction = SDLToMetal_StepFunction[createinfo->vertex_input_state.vertex_bindings[i].input_rate]; vertexDescriptor.layouts[binding].stepFunction = SDLToMetal_StepFunction[createinfo->vertex_input_state.vertex_buffer_descriptions[i].input_rate];
vertexDescriptor.layouts[binding].stepRate = (createinfo->vertex_input_state.vertex_bindings[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? createinfo->vertex_input_state.vertex_bindings[i].instance_step_rate : 1; vertexDescriptor.layouts[binding].stepRate = (createinfo->vertex_input_state.vertex_buffer_descriptions[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE)
vertexDescriptor.layouts[binding].stride = createinfo->vertex_input_state.vertex_bindings[i].pitch; ? createinfo->vertex_input_state.vertex_buffer_descriptions[i].instance_step_rate
: 1;
vertexDescriptor.layouts[binding].stride = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
} }
pipelineDescriptor.vertexDescriptor = vertexDescriptor; pipelineDescriptor.vertexDescriptor = vertexDescriptor;
@ -2367,8 +2369,8 @@ static void METAL_BindVertexBuffers(
{ {
@autoreleasepool { @autoreleasepool {
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer; MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
id<MTLBuffer> metalBuffers[MAX_BUFFER_BINDINGS]; id<MTLBuffer> metalBuffers[MAX_VERTEX_BUFFERS];
NSUInteger bufferOffsets[MAX_BUFFER_BINDINGS]; NSUInteger bufferOffsets[MAX_VERTEX_BUFFERS];
NSRange range = NSMakeRange(METAL_INTERNAL_GetVertexBufferIndex(firstBinding), numBindings); NSRange range = NSMakeRange(METAL_INTERNAL_GetVertexBufferIndex(firstBinding), numBindings);
if (range.length == 0) { if (range.length == 0) {

View file

@ -6366,9 +6366,9 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
VkPipelineVertexInputStateCreateInfo vertexInputStateCreateInfo; VkPipelineVertexInputStateCreateInfo vertexInputStateCreateInfo;
VkPipelineVertexInputDivisorStateCreateInfoEXT divisorStateCreateInfo; VkPipelineVertexInputDivisorStateCreateInfoEXT divisorStateCreateInfo;
VkVertexInputBindingDescription *vertexInputBindingDescriptions = SDL_stack_alloc(VkVertexInputBindingDescription, createinfo->vertex_input_state.num_vertex_bindings); VkVertexInputBindingDescription *vertexInputBindingDescriptions = SDL_stack_alloc(VkVertexInputBindingDescription, createinfo->vertex_input_state.num_vertex_buffers);
VkVertexInputAttributeDescription *vertexInputAttributeDescriptions = SDL_stack_alloc(VkVertexInputAttributeDescription, createinfo->vertex_input_state.num_vertex_attributes); VkVertexInputAttributeDescription *vertexInputAttributeDescriptions = SDL_stack_alloc(VkVertexInputAttributeDescription, createinfo->vertex_input_state.num_vertex_attributes);
VkVertexInputBindingDivisorDescriptionEXT *divisorDescriptions = SDL_stack_alloc(VkVertexInputBindingDivisorDescriptionEXT, createinfo->vertex_input_state.num_vertex_bindings); VkVertexInputBindingDivisorDescriptionEXT *divisorDescriptions = SDL_stack_alloc(VkVertexInputBindingDivisorDescriptionEXT, createinfo->vertex_input_state.num_vertex_buffers);
Uint32 divisorDescriptionCount = 0; Uint32 divisorDescriptionCount = 0;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo; VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo;
@ -6445,18 +6445,18 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
// Vertex input // Vertex input
for (i = 0; i < createinfo->vertex_input_state.num_vertex_bindings; i += 1) { for (i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
vertexInputBindingDescriptions[i].binding = createinfo->vertex_input_state.vertex_bindings[i].index; vertexInputBindingDescriptions[i].binding = createinfo->vertex_input_state.vertex_buffer_descriptions[i].slot;
vertexInputBindingDescriptions[i].inputRate = SDLToVK_VertexInputRate[createinfo->vertex_input_state.vertex_bindings[i].input_rate]; vertexInputBindingDescriptions[i].inputRate = SDLToVK_VertexInputRate[createinfo->vertex_input_state.vertex_buffer_descriptions[i].input_rate];
vertexInputBindingDescriptions[i].stride = createinfo->vertex_input_state.vertex_bindings[i].pitch; vertexInputBindingDescriptions[i].stride = createinfo->vertex_input_state.vertex_buffer_descriptions[i].pitch;
if (createinfo->vertex_input_state.vertex_bindings[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) { if (createinfo->vertex_input_state.vertex_buffer_descriptions[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) {
divisorDescriptionCount += 1; divisorDescriptionCount += 1;
} }
} }
for (i = 0; i < createinfo->vertex_input_state.num_vertex_attributes; i += 1) { for (i = 0; i < createinfo->vertex_input_state.num_vertex_attributes; i += 1) {
vertexInputAttributeDescriptions[i].binding = createinfo->vertex_input_state.vertex_attributes[i].binding_index; vertexInputAttributeDescriptions[i].binding = createinfo->vertex_input_state.vertex_attributes[i].buffer_slot;
vertexInputAttributeDescriptions[i].format = SDLToVK_VertexFormat[createinfo->vertex_input_state.vertex_attributes[i].format]; vertexInputAttributeDescriptions[i].format = SDLToVK_VertexFormat[createinfo->vertex_input_state.vertex_attributes[i].format];
vertexInputAttributeDescriptions[i].location = createinfo->vertex_input_state.vertex_attributes[i].location; vertexInputAttributeDescriptions[i].location = createinfo->vertex_input_state.vertex_attributes[i].location;
vertexInputAttributeDescriptions[i].offset = createinfo->vertex_input_state.vertex_attributes[i].offset; vertexInputAttributeDescriptions[i].offset = createinfo->vertex_input_state.vertex_attributes[i].offset;
@ -6465,7 +6465,7 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
vertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputStateCreateInfo.pNext = NULL; vertexInputStateCreateInfo.pNext = NULL;
vertexInputStateCreateInfo.flags = 0; vertexInputStateCreateInfo.flags = 0;
vertexInputStateCreateInfo.vertexBindingDescriptionCount = createinfo->vertex_input_state.num_vertex_bindings; vertexInputStateCreateInfo.vertexBindingDescriptionCount = createinfo->vertex_input_state.num_vertex_buffers;
vertexInputStateCreateInfo.pVertexBindingDescriptions = vertexInputBindingDescriptions; vertexInputStateCreateInfo.pVertexBindingDescriptions = vertexInputBindingDescriptions;
vertexInputStateCreateInfo.vertexAttributeDescriptionCount = createinfo->vertex_input_state.num_vertex_attributes; vertexInputStateCreateInfo.vertexAttributeDescriptionCount = createinfo->vertex_input_state.num_vertex_attributes;
vertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions; vertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions;
@ -6473,10 +6473,10 @@ static SDL_GPUGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
if (divisorDescriptionCount > 0) { if (divisorDescriptionCount > 0) {
divisorDescriptionCount = 0; divisorDescriptionCount = 0;
for (i = 0; i < createinfo->vertex_input_state.num_vertex_bindings; i += 1) { for (i = 0; i < createinfo->vertex_input_state.num_vertex_buffers; i += 1) {
if (createinfo->vertex_input_state.vertex_bindings[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) { if (createinfo->vertex_input_state.vertex_buffer_descriptions[i].input_rate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) {
divisorDescriptions[divisorDescriptionCount].binding = createinfo->vertex_input_state.vertex_bindings[i].index; divisorDescriptions[divisorDescriptionCount].binding = createinfo->vertex_input_state.vertex_buffer_descriptions[i].slot;
divisorDescriptions[divisorDescriptionCount].divisor = createinfo->vertex_input_state.vertex_bindings[i].instance_step_rate; divisorDescriptions[divisorDescriptionCount].divisor = createinfo->vertex_input_state.vertex_buffer_descriptions[i].instance_step_rate;
divisorDescriptionCount += 1; divisorDescriptionCount += 1;
} }
@ -8087,7 +8087,7 @@ static void VULKAN_BindGraphicsPipeline(
static void VULKAN_BindVertexBuffers( static void VULKAN_BindVertexBuffers(
SDL_GPUCommandBuffer *commandBuffer, SDL_GPUCommandBuffer *commandBuffer,
Uint32 firstBinding, Uint32 firstSlot,
const SDL_GPUBufferBinding *bindings, const SDL_GPUBufferBinding *bindings,
Uint32 numBindings) Uint32 numBindings)
{ {
@ -8107,7 +8107,7 @@ static void VULKAN_BindVertexBuffers(
renderer->vkCmdBindVertexBuffers( renderer->vkCmdBindVertexBuffers(
vulkanCommandBuffer->commandBuffer, vulkanCommandBuffer->commandBuffer,
firstBinding, firstSlot,
numBindings, numBindings,
buffers, buffers,
offsets); offsets);

View file

@ -126,8 +126,8 @@ static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders
pci.rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL; pci.rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL;
pci.rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE; pci.rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
SDL_GPUVertexBinding bind; SDL_GPUVertexBufferDescription vertex_buffer_desc;
SDL_zero(bind); SDL_zero(vertex_buffer_desc);
Uint32 num_attribs = 0; Uint32 num_attribs = 0;
SDL_GPUVertexAttribute attribs[4]; SDL_GPUVertexAttribute attribs[4];
@ -150,16 +150,16 @@ static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders
// Position // Position
attribs[num_attribs].location = num_attribs; attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2; attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
attribs[num_attribs].offset = bind.pitch; attribs[num_attribs].offset = vertex_buffer_desc.pitch;
bind.pitch += 2 * sizeof(float); vertex_buffer_desc.pitch += 2 * sizeof(float);
num_attribs++; num_attribs++;
if (have_attr_color) { if (have_attr_color) {
// Color // Color
attribs[num_attribs].location = num_attribs; attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4; attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4;
attribs[num_attribs].offset = bind.pitch; attribs[num_attribs].offset = vertex_buffer_desc.pitch;
bind.pitch += 4 * sizeof(float); vertex_buffer_desc.pitch += 4 * sizeof(float);
num_attribs++; num_attribs++;
} }
@ -167,15 +167,15 @@ static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders
// UVs // UVs
attribs[num_attribs].location = num_attribs; attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2; attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
attribs[num_attribs].offset = bind.pitch; attribs[num_attribs].offset = vertex_buffer_desc.pitch;
bind.pitch += 2 * sizeof(float); vertex_buffer_desc.pitch += 2 * sizeof(float);
num_attribs++; num_attribs++;
} }
pci.vertex_input_state.num_vertex_attributes = num_attribs; pci.vertex_input_state.num_vertex_attributes = num_attribs;
pci.vertex_input_state.vertex_attributes = attribs; pci.vertex_input_state.vertex_attributes = attribs;
pci.vertex_input_state.num_vertex_bindings = 1; pci.vertex_input_state.num_vertex_buffers = 1;
pci.vertex_input_state.vertex_bindings = &bind; pci.vertex_input_state.vertex_buffer_descriptions = &vertex_buffer_desc;
return SDL_CreateGPUGraphicsPipeline(device, &pci); return SDL_CreateGPUGraphicsPipeline(device, &pci);
} }

View file

@ -465,7 +465,7 @@ init_render_state(int msaa)
SDL_GPUColorTargetDescription color_target_desc; SDL_GPUColorTargetDescription color_target_desc;
Uint32 drawablew, drawableh; Uint32 drawablew, drawableh;
SDL_GPUVertexAttribute vertex_attributes[2]; SDL_GPUVertexAttribute vertex_attributes[2];
SDL_GPUVertexBinding vertex_binding; SDL_GPUVertexBufferDescription vertex_buffer_desc;
SDL_GPUShader *vertex_shader; SDL_GPUShader *vertex_shader;
SDL_GPUShader *fragment_shader; SDL_GPUShader *fragment_shader;
int i; int i;
@ -554,8 +554,8 @@ init_render_state(int msaa)
pipelinedesc.target_info.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_D16_UNORM; pipelinedesc.target_info.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_D16_UNORM;
pipelinedesc.target_info.has_depth_stencil_target = SDL_TRUE; pipelinedesc.target_info.has_depth_stencil_target = SDL_TRUE;
pipelinedesc.depth_stencil_state.enable_depth_test = 1; pipelinedesc.depth_stencil_state.enable_depth_test = SDL_TRUE;
pipelinedesc.depth_stencil_state.enable_depth_write = 1; pipelinedesc.depth_stencil_state.enable_depth_write = SDL_TRUE;
pipelinedesc.depth_stencil_state.compare_op = SDL_GPU_COMPAREOP_LESS_OR_EQUAL; pipelinedesc.depth_stencil_state.compare_op = SDL_GPU_COMPAREOP_LESS_OR_EQUAL;
pipelinedesc.multisample_state.sample_count = render_state.sample_count; pipelinedesc.multisample_state.sample_count = render_state.sample_count;
@ -565,23 +565,23 @@ init_render_state(int msaa)
pipelinedesc.vertex_shader = vertex_shader; pipelinedesc.vertex_shader = vertex_shader;
pipelinedesc.fragment_shader = fragment_shader; pipelinedesc.fragment_shader = fragment_shader;
vertex_binding.index = 0; vertex_buffer_desc.slot = 0;
vertex_binding.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX; vertex_buffer_desc.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
vertex_binding.instance_step_rate = 0; vertex_buffer_desc.instance_step_rate = 0;
vertex_binding.pitch = sizeof(VertexData); vertex_buffer_desc.pitch = sizeof(VertexData);
vertex_attributes[0].binding_index = 0; vertex_attributes[0].buffer_slot = 0;
vertex_attributes[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3; vertex_attributes[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
vertex_attributes[0].location = 0; vertex_attributes[0].location = 0;
vertex_attributes[0].offset = 0; vertex_attributes[0].offset = 0;
vertex_attributes[1].binding_index = 0; vertex_attributes[1].buffer_slot = 0;
vertex_attributes[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3; vertex_attributes[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
vertex_attributes[1].location = 1; vertex_attributes[1].location = 1;
vertex_attributes[1].offset = sizeof(float) * 3; vertex_attributes[1].offset = sizeof(float) * 3;
pipelinedesc.vertex_input_state.num_vertex_bindings = 1; pipelinedesc.vertex_input_state.num_vertex_buffers = 1;
pipelinedesc.vertex_input_state.vertex_bindings = &vertex_binding; pipelinedesc.vertex_input_state.vertex_buffer_descriptions = &vertex_buffer_desc;
pipelinedesc.vertex_input_state.num_vertex_attributes = 2; pipelinedesc.vertex_input_state.num_vertex_attributes = 2;
pipelinedesc.vertex_input_state.vertex_attributes = (SDL_GPUVertexAttribute*) &vertex_attributes; pipelinedesc.vertex_input_state.vertex_attributes = (SDL_GPUVertexAttribute*) &vertex_attributes;