I’m trying to upload a triangle (3 vertices with x, y and z coords) to a GPU vertex buffer for rendering using SDL_gpu. I have the following code:
// Create the GPU pipeline
SDL_GPUGraphicsPipelineCreateInfo pipelineCreateInfo = {
.target_info = {
.num_color_targets = 1,
.color_target_descriptions = (SDL_GPUColorTargetDescription[]){{
.format = SDL_GetGPUSwapchainTextureFormat(device, window),
}},
},
// This is set up to match the vertex shader layout!
.vertex_input_state = (SDL_GPUVertexInputState){
.num_vertex_buffers = 1,
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){{
.slot = 0,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
.pitch = sizeof(Vec3_t),
}},
.num_vertex_attributes = 1,
.vertex_attributes = (SDL_GPUVertexAttribute[]){{
.buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
.location = 0,
.offset = 0,
}}
},
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
.vertex_shader = vertexShader,
.fragment_shader = fragmentShader,
};
SDL_GPUGraphicsPipeline* pipeline = SDL_CreateGPUGraphicsPipeline(device, &pipelineCreateInfo);
if (pipeline == NULL) {
SDL_Log("Unable to create graphics pipeline: %s", SDL_GetError());
return 1;
}
Here are my (very simple) shaders in HLSL:
// vert.hlsl
struct VertexInput
{
float3 position : POSITION;
};
struct VertexOutput
{
float4 position : SV_Position;
};
VertexOutput MainVS(VertexInput input)
{
VertexOutput output;
output.position = float4(input.position, 1.0);
return output;
}
// frag.hlsl
float4 MainPS() : SV_Target
{
return float4(1.0f, 0.0f, 0.0f, 1.0f);
}
And I get the following error:
Unable to create graphics pipeline: Could not create graphics pipeline state! Error Code: The parameter is incorrect. (0x80070057)
Do you know what this error is about? Tried to search the source code for this error code, but found nothing. Also, I already checked the shaders and both are not NULL after creation. Same for device and window. I’m on version 3.1.6 of SDL.