Set a default shader entry point

The default should be the entrypoint generated by SDL_shadercross. That way it doesn't need to be hand-specified in the common workflow.
This commit is contained in:
Sam Lantinga 2025-03-14 10:27:50 -07:00
parent 1a2fccc56a
commit dcb97a5f49
5 changed files with 11 additions and 14 deletions

View file

@ -8056,7 +8056,6 @@ static void D3D12_INTERNAL_InitBlitResources(
shaderCreateInfo.code_size = sizeof(D3D12_FullscreenVert);
shaderCreateInfo.stage = SDL_GPU_SHADERSTAGE_VERTEX;
shaderCreateInfo.format = SDL_GPU_SHADERFORMAT_DXBC;
shaderCreateInfo.entrypoint = "main";
renderer->blitVertexShader = D3D12_CreateShader(
(SDL_GPURenderer *)renderer,

View file

@ -840,6 +840,10 @@ static MetalLibraryFunction METAL_INTERNAL_CompileShader(
dispatch_data_t data;
id<MTLFunction> function;
if (!entrypoint) {
entrypoint = "main0";
}
if (format == SDL_GPU_SHADERFORMAT_MSL) {
NSString *codeString = [[NSString alloc]
initWithBytes:code

View file

@ -577,7 +577,7 @@ typedef struct VulkanSampler
typedef struct VulkanShader
{
VkShaderModule shaderModule;
const char *entrypointName;
char *entrypointName;
SDL_GPUShaderStage stage;
Uint32 numSamplers;
Uint32 numStorageTextures;
@ -3115,7 +3115,7 @@ static void VULKAN_INTERNAL_DestroyShader(
vulkanShader->shaderModule,
NULL);
SDL_free((void *)vulkanShader->entrypointName);
SDL_free(vulkanShader->entrypointName);
SDL_free(vulkanShader);
}
@ -6620,7 +6620,6 @@ static SDL_GPUShader *VULKAN_CreateShader(
VkResult vulkanResult;
VkShaderModuleCreateInfo vkShaderModuleCreateInfo;
VulkanRenderer *renderer = (VulkanRenderer *)driverData;
size_t entryPointNameLength;
vulkanShader = SDL_malloc(sizeof(VulkanShader));
vkShaderModuleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
@ -6640,10 +6639,11 @@ static SDL_GPUShader *VULKAN_CreateShader(
CHECK_VULKAN_ERROR_AND_RETURN(vulkanResult, vkCreateShaderModule, NULL);
}
entryPointNameLength = SDL_strlen(createinfo->entrypoint) + 1;
vulkanShader->entrypointName = SDL_malloc(entryPointNameLength);
SDL_utf8strlcpy((char *)vulkanShader->entrypointName, createinfo->entrypoint, entryPointNameLength);
const char *entrypoint = createinfo->entrypoint;
if (!entrypoint) {
entrypoint = "main";
}
vulkanShader->entrypointName = SDL_strdup(entrypoint);
vulkanShader->stage = createinfo->stage;
vulkanShader->numSamplers = createinfo->num_samplers;
vulkanShader->numStorageTextures = createinfo->num_storage_textures;

View file

@ -172,17 +172,14 @@ static bool InitGPURenderState(void)
info.format = SDL_GPU_SHADERFORMAT_SPIRV;
info.code = data->spirv_shader_source;
info.code_size = data->spirv_shader_source_len;
info.entrypoint = "main";
} else if (formats & SDL_GPU_SHADERFORMAT_DXIL) {
info.format = SDL_GPU_SHADERFORMAT_DXIL;
info.code = data->dxil_shader_source;
info.code_size = data->dxil_shader_source_len;
info.entrypoint = "main";
} else if (formats & SDL_GPU_SHADERFORMAT_MSL) {
info.format = SDL_GPU_SHADERFORMAT_MSL;
info.code = data->msl_shader_source;
info.code_size = data->msl_shader_source_len;
info.entrypoint = "main0";
} else {
SDL_Log("No supported shader format found");
return false;

View file

@ -184,17 +184,14 @@ static bool InitGPURenderState(void)
info.format = SDL_GPU_SHADERFORMAT_SPIRV;
info.code = testgpurender_msdf_frag_spv;
info.code_size = testgpurender_msdf_frag_spv_len;
info.entrypoint = "main";
} else if (formats & SDL_GPU_SHADERFORMAT_DXIL) {
info.format = SDL_GPU_SHADERFORMAT_DXIL;
info.code = testgpurender_msdf_frag_dxil;
info.code_size = testgpurender_msdf_frag_dxil_len;
info.entrypoint = "main";
} else if (formats & SDL_GPU_SHADERFORMAT_MSL) {
info.format = SDL_GPU_SHADERFORMAT_MSL;
info.code = testgpurender_msdf_frag_msl;
info.code_size = testgpurender_msdf_frag_msl_len;
info.entrypoint = "main0";
} else {
SDL_Log("No supported shader format found");
return false;