Skip to content

Commit 93d9d45

Browse files
committed
sdlgpu: Update to latest shadercross ABI
1 parent ef665c4 commit 93d9d45

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

mojoshader_sdlgpu.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ typedef enum SDL_ShaderCross_ShaderStage
2323
SDL_SHADERCROSS_SHADERSTAGE_COMPUTE
2424
} SDL_ShaderCross_ShaderStage;
2525

26-
typedef struct SDL_ShaderCross_GraphicsShaderMetadata
27-
{
28-
Uint32 num_samplers; /**< The number of samplers defined in the shader. */
29-
Uint32 num_storage_textures; /**< The number of storage textures defined in the shader. */
30-
Uint32 num_storage_buffers; /**< The number of storage buffers defined in the shader. */
31-
Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
32-
33-
SDL_PropertiesID props; /**< A properties ID for extensions. This is allocated and freed by the caller, and should be 0 if no extensions are needed. */
34-
} SDL_ShaderCross_GraphicsShaderMetadata;
35-
3626
typedef struct SDL_ShaderCross_SPIRV_Info
3727
{
3828
const Uint8 *bytecode; /**< The SPIRV bytecode. */
@@ -45,14 +35,22 @@ typedef struct SDL_ShaderCross_SPIRV_Info
4535
SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
4636
} SDL_ShaderCross_SPIRV_Info;
4737

38+
typedef struct SDL_ShaderCross_GraphicsShaderMetadata SDL_ShaderCross_GraphicsShaderMetadata;
39+
4840
typedef SDL_GPUShaderFormat (SDLCALL *PFN_SDL_ShaderCross_GetSPIRVShaderFormats)(void);
41+
typedef SDL_ShaderCross_GraphicsShaderMetadata *(SDLCALL *PFN_SDL_ShaderCross_ReflectGraphicsSPIRV)(
42+
const Uint8 *bytecode,
43+
size_t bytecode_size,
44+
SDL_PropertiesID props);
4945
typedef SDL_GPUShader *(SDLCALL *PFN_SDL_ShaderCross_CompileGraphicsShaderFromSPIRV)(
5046
SDL_GPUDevice *device,
5147
const SDL_ShaderCross_SPIRV_Info *info,
52-
SDL_ShaderCross_GraphicsShaderMetadata *metadata);
48+
const SDL_ShaderCross_GraphicsShaderMetadata *metadata,
49+
SDL_PropertiesID props);
5350

5451
static SDL_SharedObject *SDL_shadercross_lib = NULL;
5552
static PFN_SDL_ShaderCross_GetSPIRVShaderFormats SDL_ShaderCross_GetSPIRVShaderFormats = NULL;
53+
static PFN_SDL_ShaderCross_ReflectGraphicsSPIRV SDL_ShaderCross_ReflectGraphicsSPIRV = NULL;
5654
static PFN_SDL_ShaderCross_CompileGraphicsShaderFromSPIRV SDL_ShaderCross_CompileGraphicsShaderFromSPIRV = NULL;
5755

5856
#ifdef _WIN32
@@ -352,6 +350,10 @@ MOJOSHADER_sdlContext *MOJOSHADER_sdlCreateContext(
352350
SDL_shadercross_lib,
353351
"SDL_ShaderCross_GetSPIRVShaderFormats"
354352
);
353+
SDL_ShaderCross_ReflectGraphicsSPIRV = (PFN_SDL_ShaderCross_ReflectGraphicsSPIRV) SDL_LoadFunction(
354+
SDL_shadercross_lib,
355+
"SDL_ShaderCross_ReflectGraphicsSPIRV"
356+
);
355357
SDL_ShaderCross_CompileGraphicsShaderFromSPIRV = (PFN_SDL_ShaderCross_CompileGraphicsShaderFromSPIRV) SDL_LoadFunction(
356358
SDL_shadercross_lib,
357359
"SDL_ShaderCross_CompileGraphicsShaderFromSPIRV"
@@ -381,6 +383,7 @@ void MOJOSHADER_sdlDestroyContext(
381383
if (SDL_shadercross_lib != NULL)
382384
{
383385
SDL_ShaderCross_GetSPIRVShaderFormats = NULL;
386+
SDL_ShaderCross_ReflectGraphicsSPIRV = NULL;
384387
SDL_ShaderCross_CompileGraphicsShaderFromSPIRV = NULL;
385388
SDL_UnloadObject(SDL_shadercross_lib);
386389
SDL_shadercross_lib = NULL;
@@ -471,7 +474,7 @@ static MOJOSHADER_sdlProgram *compile_program(
471474
{
472475
SDL_GPUShaderCreateInfo createInfo;
473476
SDL_ShaderCross_SPIRV_Info crossCreateInfo;
474-
SDL_ShaderCross_GraphicsShaderMetadata whoCares;
477+
SDL_ShaderCross_GraphicsShaderMetadata *whoCares;
475478
MOJOSHADER_sdlProgram *program = (MOJOSHADER_sdlProgram*) ctx->malloc_fn(sizeof(MOJOSHADER_sdlProgram),
476479
ctx->malloc_data);
477480
if (program == NULL)
@@ -531,13 +534,21 @@ static MOJOSHADER_sdlProgram *compile_program(
531534
crossCreateInfo.enable_debug = 0;
532535
crossCreateInfo.name = NULL;
533536
crossCreateInfo.props = 0;
534-
whoCares.props = 0;
537+
538+
whoCares = SDL_ShaderCross_ReflectGraphicsSPIRV(
539+
crossCreateInfo.bytecode,
540+
crossCreateInfo.bytecode_size,
541+
0
542+
);
535543

536544
program->vertexShader = SDL_ShaderCross_CompileGraphicsShaderFromSPIRV(
537545
ctx->device,
538546
&crossCreateInfo,
539-
&whoCares
547+
whoCares,
548+
0
540549
);
550+
551+
SDL_free(whoCares);
541552
} // if
542553
else
543554
{
@@ -572,13 +583,21 @@ static MOJOSHADER_sdlProgram *compile_program(
572583
crossCreateInfo.enable_debug = 0;
573584
crossCreateInfo.name = NULL;
574585
crossCreateInfo.props = 0;
575-
whoCares.props = 0;
586+
587+
whoCares = SDL_ShaderCross_ReflectGraphicsSPIRV(
588+
crossCreateInfo.bytecode,
589+
crossCreateInfo.bytecode_size,
590+
0
591+
);
576592

577593
program->pixelShader = SDL_ShaderCross_CompileGraphicsShaderFromSPIRV(
578594
ctx->device,
579595
&crossCreateInfo,
580-
&whoCares
596+
whoCares,
597+
0
581598
);
599+
600+
SDL_free(whoCares);
582601
} // if
583602
else
584603
{

0 commit comments

Comments
 (0)