Skip to content

Commit

Permalink
Rename stepRate to instanceStepRate (#230)
Browse files Browse the repository at this point in the history
Also actually implements the step rate on the Metal backend.
  • Loading branch information
thatcosmonaut authored and flibitijibibo committed Aug 28, 2024
1 parent 4380e53 commit 29b775e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/SDL3/SDL_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ typedef struct SDL_GpuVertexBinding
Uint32 binding;
Uint32 stride;
SDL_GpuVertexInputRate inputRate;
Uint32 stepRate;
Uint32 instanceStepRate; /* ignored unless inputRate is INSTANCE */
} SDL_GpuVertexBinding;

typedef struct SDL_GpuVertexAttribute
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/d3d11/SDL_gpu_d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ static ID3D11InputLayout *D3D11_INTERNAL_FetchInputLayout(
inputState.vertexBindingCount);
elementDescs[i].InputSlotClass = SDLToD3D11_VertexInputRate[inputState.vertexBindings[bindingIndex].inputRate];
/* The spec requires this to be 0 for per-vertex data */
elementDescs[i].InstanceDataStepRate = (inputState.vertexBindings[bindingIndex].inputRate == SDL_GPU_VERTEXINPUTRATE_INSTANCE ? inputState.vertexBindings[bindingIndex].stepRate : 0);
elementDescs[i].InstanceDataStepRate = (inputState.vertexBindings[bindingIndex].inputRate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? inputState.vertexBindings[bindingIndex].instanceStepRate : 0;

elementDescs[i].SemanticIndex = inputState.vertexAttributes[i].location;
elementDescs[i].SemanticName = "TEXCOORD";
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/d3d12/SDL_gpu_d3d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ static SDL_bool D3D12_INTERNAL_ConvertVertexInputState(SDL_GpuVertexInputState v
desc[i].InputSlot = attribute.binding;
desc[i].AlignedByteOffset = attribute.offset;
desc[i].InputSlotClass = SDLToD3D12_InputRate[vertexInputState.vertexBindings[attribute.binding].inputRate];
desc[i].InstanceDataStepRate = vertexInputState.vertexBindings[attribute.binding].stepRate;
desc[i].InstanceDataStepRate = (vertexInputState.vertexBindings[attribute.binding].inputRate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? vertexInputState.vertexBindings[attribute.binding].instanceStepRate : 0;
}

return SDL_TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/gpu/metal/SDL_gpu_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ static void METAL_ReleaseGraphicsPipeline(
for (Uint32 i = 0; i < pipelineCreateInfo->vertexInputState.vertexBindingCount; i += 1) {
binding = METAL_INTERNAL_GetVertexBufferIndex(pipelineCreateInfo->vertexInputState.vertexBindings[i].binding);
vertexDescriptor.layouts[binding].stepFunction = SDLToMetal_StepFunction[pipelineCreateInfo->vertexInputState.vertexBindings[i].inputRate];
vertexDescriptor.layouts[binding].stepRate = (pipelineCreateInfo->vertexInputState.vertexBindings[i].inputRate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) ? pipelineCreateInfo->vertexInputState.vertexBindings[i].instanceStepRate : 1;
vertexDescriptor.layouts[binding].stride = pipelineCreateInfo->vertexInputState.vertexBindings[i].stride;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6457,7 +6457,7 @@ static SDL_GpuGraphicsPipeline *VULKAN_CreateGraphicsPipeline(
for (i = 0; i < pipelineCreateInfo->vertexInputState.vertexBindingCount; i += 1) {
if (pipelineCreateInfo->vertexInputState.vertexBindings[i].inputRate == SDL_GPU_VERTEXINPUTRATE_INSTANCE) {
divisorDescriptions[divisorDescriptionCount].binding = pipelineCreateInfo->vertexInputState.vertexBindings[i].binding;
divisorDescriptions[divisorDescriptionCount].divisor = pipelineCreateInfo->vertexInputState.vertexBindings[i].stepRate;
divisorDescriptions[divisorDescriptionCount].divisor = pipelineCreateInfo->vertexInputState.vertexBindings[i].instanceStepRate;

divisorDescriptionCount += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/testgpu_spinning_cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ init_render_state(int msaa)

vertex_binding.binding = 0;
vertex_binding.inputRate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
vertex_binding.stepRate = 0;
vertex_binding.instanceStepRate = 0;
vertex_binding.stride = sizeof(VertexData);

vertex_attributes[0].binding = 0;
Expand Down

0 comments on commit 29b775e

Please sign in to comment.