GPU: Rename struct members and parameters for SDL3 naming conventions (#10730)

---------

Co-authored-by: Evan Hemsley <2342303+thatcosmonaut@users.noreply.github.com>
This commit is contained in:
Caleb Cornett
2024-09-06 18:38:23 -05:00
committed by GitHub
parent e21f70c593
commit 9730f62e8c
13 changed files with 2963 additions and 2972 deletions

View File

@@ -97,34 +97,34 @@ void GPU_DestroyPipelineCache(GPU_PipelineCache *cache)
static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders *shaders, const GPU_PipelineParameters *params)
{
SDL_GPUColorAttachmentDescription ad;
SDL_GPUColorTargetDescription ad;
SDL_zero(ad);
ad.format = params->attachment_format;
SDL_BlendMode blend = params->blend_mode;
ad.blendState.blendEnable = blend != 0;
ad.blendState.colorWriteMask = 0xF;
ad.blendState.alphaBlendOp = GPU_ConvertBlendOperation(SDL_GetBlendModeAlphaOperation(blend));
ad.blendState.dstAlphaBlendFactor = GPU_ConvertBlendFactor(SDL_GetBlendModeDstAlphaFactor(blend));
ad.blendState.srcAlphaBlendFactor = GPU_ConvertBlendFactor(SDL_GetBlendModeSrcAlphaFactor(blend));
ad.blendState.colorBlendOp = GPU_ConvertBlendOperation(SDL_GetBlendModeColorOperation(blend));
ad.blendState.dstColorBlendFactor = GPU_ConvertBlendFactor(SDL_GetBlendModeDstColorFactor(blend));
ad.blendState.srcColorBlendFactor = GPU_ConvertBlendFactor(SDL_GetBlendModeSrcColorFactor(blend));
ad.blend_state.enable_blend = blend != 0;
ad.blend_state.color_write_mask = 0xF;
ad.blend_state.alpha_blend_op = GPU_ConvertBlendOperation(SDL_GetBlendModeAlphaOperation(blend));
ad.blend_state.dst_alpha_blendfactor = GPU_ConvertBlendFactor(SDL_GetBlendModeDstAlphaFactor(blend));
ad.blend_state.src_alpha_blendfactor = GPU_ConvertBlendFactor(SDL_GetBlendModeSrcAlphaFactor(blend));
ad.blend_state.color_blend_op = GPU_ConvertBlendOperation(SDL_GetBlendModeColorOperation(blend));
ad.blend_state.dst_color_blendfactor = GPU_ConvertBlendFactor(SDL_GetBlendModeDstColorFactor(blend));
ad.blend_state.src_color_blendfactor = GPU_ConvertBlendFactor(SDL_GetBlendModeSrcColorFactor(blend));
SDL_GPUGraphicsPipelineCreateInfo pci;
SDL_zero(pci);
pci.attachmentInfo.hasDepthStencilAttachment = false;
pci.attachmentInfo.colorAttachmentCount = 1;
pci.attachmentInfo.colorAttachmentDescriptions = &ad;
pci.vertexShader = GPU_GetVertexShader(shaders, params->vert_shader);
pci.fragmentShader = GPU_GetFragmentShader(shaders, params->frag_shader);
pci.multisampleState.sampleCount = SDL_GPU_SAMPLECOUNT_1;
pci.multisampleState.sampleMask = 0xFFFF;
pci.primitiveType = params->primitive_type;
pci.target_info.has_depth_stencil_target = false;
pci.target_info.num_color_targets = 1;
pci.target_info.color_target_descriptions = &ad;
pci.vertex_shader = GPU_GetVertexShader(shaders, params->vert_shader);
pci.fragment_shader = GPU_GetFragmentShader(shaders, params->frag_shader);
pci.multisample_state.sample_count = SDL_GPU_SAMPLECOUNT_1;
pci.multisample_state.sample_mask = 0xFFFF;
pci.primitive_type = params->primitive_type;
pci.rasterizerState.cullMode = SDL_GPU_CULLMODE_NONE;
pci.rasterizerState.fillMode = SDL_GPU_FILLMODE_FILL;
pci.rasterizerState.frontFace = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
pci.rasterizer_state.cull_mode = SDL_GPU_CULLMODE_NONE;
pci.rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL;
pci.rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
SDL_GPUVertexBinding bind;
SDL_zero(bind);
@@ -150,16 +150,16 @@ static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders
// Position
attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
attribs[num_attribs].offset = bind.stride;
bind.stride += 2 * sizeof(float);
attribs[num_attribs].offset = bind.pitch;
bind.pitch += 2 * sizeof(float);
num_attribs++;
if (have_attr_color) {
// Color
attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4;
attribs[num_attribs].offset = bind.stride;
bind.stride += 4 * sizeof(float);
attribs[num_attribs].offset = bind.pitch;
bind.pitch += 4 * sizeof(float);
num_attribs++;
}
@@ -167,15 +167,15 @@ static SDL_GPUGraphicsPipeline *MakePipeline(SDL_GPUDevice *device, GPU_Shaders
// UVs
attribs[num_attribs].location = num_attribs;
attribs[num_attribs].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
attribs[num_attribs].offset = bind.stride;
bind.stride += 2 * sizeof(float);
attribs[num_attribs].offset = bind.pitch;
bind.pitch += 2 * sizeof(float);
num_attribs++;
}
pci.vertexInputState.vertexAttributeCount = num_attribs;
pci.vertexInputState.vertexAttributes = attribs;
pci.vertexInputState.vertexBindingCount = 1;
pci.vertexInputState.vertexBindings = &bind;
pci.vertex_input_state.num_vertex_attributes = num_attribs;
pci.vertex_input_state.vertex_attributes = attribs;
pci.vertex_input_state.num_vertex_bindings = 1;
pci.vertex_input_state.vertex_bindings = &bind;
return SDL_CreateGPUGraphicsPipeline(device, &pci);
}

View File

@@ -69,7 +69,7 @@ typedef struct GPU_RenderData
SDL_GPURenderPass *render_pass;
SDL_Texture *render_target;
SDL_GPUCommandBuffer *command_buffer;
SDL_GPUColorAttachmentInfo color_attachment;
SDL_GPUColorTargetInfo color_attachment;
SDL_GPUViewport viewport;
SDL_Rect scissor;
SDL_FColor draw_color;
@@ -219,12 +219,12 @@ static bool GPU_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
SDL_GPUTextureCreateInfo tci;
SDL_zero(tci);
tci.format = format;
tci.layerCountOrDepth = 1;
tci.levelCount = 1;
tci.usageFlags = usage;
tci.layer_count_or_depth = 1;
tci.num_levels = 1;
tci.usage = usage;
tci.width = texture->w;
tci.height = texture->h;
tci.sampleCount = SDL_GPU_SAMPLECOUNT_1;
tci.sample_count = SDL_GPU_SAMPLECOUNT_1;
data->format = format;
data->texture = SDL_CreateGPUTexture(renderdata->device, &tci);
@@ -258,7 +258,7 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
SDL_GPUTransferBufferCreateInfo tbci;
SDL_zero(tbci);
tbci.sizeInBytes = (Uint32)data_size;
tbci.size = (Uint32)data_size;
tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
SDL_GPUTransferBuffer *tbuf = SDL_CreateGPUTransferBuffer(renderdata->device, &tbci);
@@ -273,7 +273,7 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
memcpy(output, pixels, data_size);
} else {
// FIXME is negative pitch supposed to work?
// If not, maybe use SDL_GPUTextureTransferInfo::imagePitch instead of this
// If not, maybe use SDL_GPUTextureTransferInfo::pixels_per_row instead of this
const Uint8 *input = pixels;
for (int i = 0; i < rect->h; ++i) {
@@ -290,9 +290,9 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
SDL_GPUTextureTransferInfo tex_src;
SDL_zero(tex_src);
tex_src.transferBuffer = tbuf;
tex_src.imageHeight = rect->h;
tex_src.imagePitch = rect->w;
tex_src.transfer_buffer = tbuf;
tex_src.rows_per_layer = rect->h;
tex_src.pixels_per_row = rect->w;
SDL_GPUTextureRegion tex_dst;
SDL_zero(tex_dst);
@@ -467,7 +467,7 @@ static SDL_GPURenderPass *RestartRenderPass(GPU_RenderData *data)
// This is busted. We should be able to know which load op to use.
// LOAD is incorrect behavior most of the time, unless we had to break a render pass.
// -cosmonaut
data->state.color_attachment.loadOp = SDL_GPU_LOADOP_LOAD;
data->state.color_attachment.load_op = SDL_GPU_LOADOP_LOAD;
data->state.scissor_was_enabled = false;
return data->state.render_pass;
@@ -524,7 +524,7 @@ static void Draw(
Uint32 offset,
SDL_GPUPrimitiveType prim)
{
if (!data->state.render_pass || data->state.color_attachment.loadOp == SDL_GPU_LOADOP_CLEAR) {
if (!data->state.render_pass || data->state.color_attachment.load_op == SDL_GPU_LOADOP_CLEAR) {
RestartRenderPass(data);
}
@@ -607,8 +607,8 @@ static bool InitVertexBuffer(GPU_RenderData *data, Uint32 size)
{
SDL_GPUBufferCreateInfo bci;
SDL_zero(bci);
bci.sizeInBytes = size;
bci.usageFlags = SDL_GPU_BUFFERUSAGE_VERTEX;
bci.size = size;
bci.usage = SDL_GPU_BUFFERUSAGE_VERTEX;
data->vertices.buffer = SDL_CreateGPUBuffer(data->device, &bci);
@@ -618,7 +618,7 @@ static bool InitVertexBuffer(GPU_RenderData *data, Uint32 size)
SDL_GPUTransferBufferCreateInfo tbci;
SDL_zero(tbci);
tbci.sizeInBytes = size;
tbci.size = size;
tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
data->vertices.transfer_buf = SDL_CreateGPUTransferBuffer(data->device, &tbci);
@@ -655,7 +655,7 @@ static bool UploadVertices(GPU_RenderData *data, void *vertices, size_t vertsize
SDL_GPUTransferBufferLocation src;
SDL_zero(src);
src.transferBuffer = data->vertices.transfer_buf;
src.transfer_buffer = data->vertices.transfer_buf;
SDL_GPUBufferRegion dst;
SDL_zero(dst);
@@ -685,7 +685,7 @@ static bool GPU_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
return false;
}
data->state.color_attachment.loadOp = SDL_GPU_LOADOP_LOAD;
data->state.color_attachment.load_op = SDL_GPU_LOADOP_LOAD;
if (renderer->target) {
GPU_TextureData *tdata = renderer->target->internal;
@@ -729,8 +729,8 @@ static bool GPU_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
case SDL_RENDERCMD_CLEAR:
{
data->state.color_attachment.clearColor = GetDrawCmdColor(renderer, cmd);
data->state.color_attachment.loadOp = SDL_GPU_LOADOP_CLEAR;
data->state.color_attachment.clear_color = GetDrawCmdColor(renderer, cmd);
data->state.color_attachment.load_op = SDL_GPU_LOADOP_CLEAR;
break;
}
@@ -823,7 +823,7 @@ static bool GPU_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
cmd = cmd->next;
}
if (data->state.color_attachment.loadOp == SDL_GPU_LOADOP_CLEAR) {
if (data->state.color_attachment.load_op == SDL_GPU_LOADOP_CLEAR) {
RestartRenderPass(data);
}
@@ -873,7 +873,7 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
SDL_GPUTransferBufferCreateInfo tbci;
SDL_zero(tbci);
tbci.sizeInBytes = (Uint32)image_size;
tbci.size = (Uint32)image_size;
tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD;
SDL_GPUTransferBuffer *tbuf = SDL_CreateGPUTransferBuffer(data->device, &tbci);
@@ -895,9 +895,9 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
SDL_GPUTextureTransferInfo dst;
SDL_zero(dst);
dst.transferBuffer = tbuf;
dst.imageHeight = rect->h;
dst.imagePitch = rect->w;
dst.transfer_buffer = tbuf;
dst.rows_per_layer = rect->h;
dst.pixels_per_row = rect->w;
SDL_DownloadFromGPUTexture(pass, &src, &dst);
SDL_EndGPUCopyPass(pass);
@@ -935,10 +935,10 @@ static bool CreateBackbuffer(GPU_RenderData *data, Uint32 w, Uint32 h, SDL_GPUTe
tci.width = w;
tci.height = h;
tci.format = fmt;
tci.layerCountOrDepth = 1;
tci.levelCount = 1;
tci.sampleCount = SDL_GPU_SAMPLECOUNT_1;
tci.usageFlags = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER;
tci.layer_count_or_depth = 1;
tci.num_levels = 1;
tci.sample_count = SDL_GPU_SAMPLECOUNT_1;
tci.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER;
data->backbuffer.texture = SDL_CreateGPUTexture(data->device, &tci);
data->backbuffer.width = w;
@@ -1167,11 +1167,11 @@ static bool InitSamplers(GPU_RenderData *data)
for (Uint32 i = 0; i < SDL_arraysize(configs); ++i) {
SDL_GPUSamplerCreateInfo sci;
SDL_zero(sci);
sci.maxAnisotropy = configs[i].gpu.anisotropy;
sci.anisotropyEnable = configs[i].gpu.anisotropy > 0;
sci.addressModeU = sci.addressModeV = sci.addressModeW = configs[i].gpu.address_mode;
sci.minFilter = sci.magFilter = configs[i].gpu.filter;
sci.mipmapMode = configs[i].gpu.mipmap_mode;
sci.max_anisotropy = configs[i].gpu.anisotropy;
sci.enable_anisotropy = configs[i].gpu.anisotropy > 0;
sci.address_mode_u = sci.address_mode_v = sci.address_mode_w = configs[i].gpu.address_mode;
sci.min_filter = sci.mag_filter = configs[i].gpu.filter;
sci.mipmap_mode = configs[i].gpu.mipmap_mode;
SDL_GPUSampler *sampler = SDL_CreateGPUSampler(data->device, &sci);
@@ -1286,8 +1286,8 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
data->state.draw_color.g = 1.0f;
data->state.draw_color.b = 1.0f;
data->state.draw_color.a = 1.0f;
data->state.viewport.minDepth = 0;
data->state.viewport.maxDepth = 1;
data->state.viewport.min_depth = 0;
data->state.viewport.max_depth = 1;
data->state.command_buffer = SDL_AcquireGPUCommandBuffer(data->device);
int w, h;

View File

@@ -167,12 +167,12 @@ static SDL_GPUShader *CompileShader(const GPU_ShaderSources *sources, SDL_GPUDev
SDL_GPUShaderCreateInfo sci = { 0 };
sci.code = sms->code;
sci.codeSize = sms->code_len;
sci.code_size = sms->code_len;
sci.format = sms->format;
// FIXME not sure if this is correct
sci.entryPointName = driver == SDL_GPU_DRIVER_METAL ? "main0" : "main";
sci.samplerCount = sources->num_samplers;
sci.uniformBufferCount = sources->num_uniform_buffers;
sci.entrypoint = driver == SDL_GPU_DRIVER_METAL ? "main0" : "main";
sci.num_samplers = sources->num_samplers;
sci.num_uniform_buffers = sources->num_uniform_buffers;
sci.stage = stage;
return SDL_CreateGPUShader(device, &sci);