1
1
#include <SDL_gpu_examples.h>
2
2
3
+ #define SDL_GPU_SPIRVCROSS_IMPLEMENTATION
4
+ #include <SDL_gpu_spirvcross.h>
5
+
3
6
#define STB_IMAGE_IMPLEMENTATION
4
7
#define STBI_MALLOC SDL_malloc
5
8
#define STBI_REALLOC SDL_realloc
@@ -82,7 +85,8 @@ SDL_GpuShader* LoadShader(
82
85
return NULL ;
83
86
}
84
87
85
- SDL_GpuShader * shader = SDL_GpuCreateShader (device , & (SDL_GpuShaderCreateInfo ){
88
+ SDL_GpuShader * shader ;
89
+ SDL_GpuShaderCreateInfo shaderInfo = {
86
90
.code = code ,
87
91
.codeSize = codeSize ,
88
92
.entryPointName = "main" ,
@@ -92,7 +96,15 @@ SDL_GpuShader* LoadShader(
92
96
.uniformBufferCount = uniformBufferCount ,
93
97
.storageBufferCount = storageBufferCount ,
94
98
.storageTextureCount = storageTextureCount
95
- });
99
+ };
100
+ if (SDL_GpuGetBackend (device ) == SDL_GPU_BACKEND_VULKAN )
101
+ {
102
+ shader = SDL_GpuCreateShader (device , & shaderInfo );
103
+ }
104
+ else
105
+ {
106
+ shader = SDL_CompileFromSPIRV (device , & shaderInfo , SDL_FALSE );
107
+ }
96
108
if (shader == NULL )
97
109
{
98
110
SDL_Log ("Failed to create shader!" );
@@ -127,7 +139,15 @@ SDL_GpuComputePipeline* CreateComputePipelineFromShader(
127
139
newCreateInfo .entryPointName = "main" ;
128
140
newCreateInfo .format = SDL_GPU_SHADERFORMAT_SPIRV ;
129
141
130
- SDL_GpuComputePipeline * pipeline = SDL_GpuCreateComputePipeline (device , & newCreateInfo );
142
+ SDL_GpuComputePipeline * pipeline ;
143
+ if (SDL_GpuGetBackend (device ) == SDL_GPU_BACKEND_VULKAN )
144
+ {
145
+ pipeline = SDL_GpuCreateComputePipeline (device , & newCreateInfo );
146
+ }
147
+ else
148
+ {
149
+ pipeline = SDL_CompileFromSPIRV (device , & newCreateInfo , SDL_TRUE );
150
+ }
131
151
if (pipeline == NULL )
132
152
{
133
153
SDL_Log ("Failed to create compute pipeline!" );
@@ -349,4 +369,4 @@ Vector3 Vector3_Cross(Vector3 vecA, Vector3 vecB)
349
369
- (vecA .x * vecB .z - vecB .x * vecA .z ),
350
370
vecA .x * vecB .y - vecB .x * vecA .y
351
371
};
352
- }
372
+ }
0 commit comments