Skip to content

Commit

Permalink
sdlgpu: Only load ShaderCross when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Jan 5, 2025
1 parent ba3ab52 commit fef8d2f
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions mojoshader_sdlgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,35 +411,37 @@ MOJOSHADER_sdlContext *MOJOSHADER_sdlCreateContext(

SDL_memset(resultCtx, '\0', sizeof(MOJOSHADER_sdlContext));
resultCtx->device = device;
resultCtx->malloc_fn = m;
resultCtx->free_fn = f;
resultCtx->malloc_data = malloc_d;

if (load_precompiled_blob(resultCtx))
{
/* Just validate the bytecode, calculate a hash to find in blobCache */
resultCtx->profile = "bytecode";
resultCtx->blob.format = SDL_GetGPUShaderFormats(device);
}
} // if
else
{
resultCtx->profile = (shader_format == SDL_GPU_SHADERFORMAT_SPIRV) ? "spirv" : "metal";
}

resultCtx->malloc_fn = m;
resultCtx->free_fn = f;
resultCtx->malloc_data = malloc_d;

// We only care about this on Windows, hardcode the DLL name :shrug:
SDL_shadercross_lib = SDL_LoadObject(SDL_SHADERCROSS_LIB_NAME);
if (SDL_shadercross_lib != NULL)
{
SDL_ShaderCross_GetSPIRVShaderFormats = (PFN_SDL_ShaderCross_GetSPIRVShaderFormats) SDL_LoadFunction(
SDL_shadercross_lib,
"SDL_ShaderCross_GetSPIRVShaderFormats"
);
SDL_ShaderCross_CompileGraphicsShaderFromSPIRV = (PFN_SDL_ShaderCross_CompileGraphicsShaderFromSPIRV) SDL_LoadFunction(
SDL_shadercross_lib,
"SDL_ShaderCross_CompileGraphicsShaderFromSPIRV"
);
} // if
// We only care about ShaderCross if the device doesn't natively support SPIR-V
if (!(SDL_GetGPUShaderFormats(device) & SDL_GPU_SHADERFORMAT_SPIRV))
{
SDL_shadercross_lib = SDL_LoadObject(SDL_SHADERCROSS_LIB_NAME);
if (SDL_shadercross_lib != NULL)
{
SDL_ShaderCross_GetSPIRVShaderFormats = (PFN_SDL_ShaderCross_GetSPIRVShaderFormats) SDL_LoadFunction(
SDL_shadercross_lib,
"SDL_ShaderCross_GetSPIRVShaderFormats"
);
SDL_ShaderCross_CompileGraphicsShaderFromSPIRV = (PFN_SDL_ShaderCross_CompileGraphicsShaderFromSPIRV) SDL_LoadFunction(
SDL_shadercross_lib,
"SDL_ShaderCross_CompileGraphicsShaderFromSPIRV"
);
} // if
} // if
} // else

return resultCtx;

Expand Down

0 comments on commit fef8d2f

Please sign in to comment.