Skip to content

Commit 33cdf2a

Browse files
committed
Integrate SDL_gpu_spirvcross
1 parent 121fe47 commit 33cdf2a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "spirv"]
2+
path = spirv
3+
url = https://github.com/flibitijibibo/SDL_gpu_spirvcross

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ add_executable(SDL_gpu_examples
3030
Examples/WindowResize.c
3131
)
3232

33-
target_include_directories(SDL_gpu_examples PRIVATE .)
33+
target_include_directories(SDL_gpu_examples PRIVATE . spirv)
3434

3535
target_link_libraries(SDL_gpu_examples
3636
SDL3::SDL3

Examples/Common.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <SDL_gpu_examples.h>
22

3+
#define SDL_GPU_SPIRVCROSS_IMPLEMENTATION
4+
#include <SDL_gpu_spirvcross.h>
5+
36
#define STB_IMAGE_IMPLEMENTATION
47
#define STBI_MALLOC SDL_malloc
58
#define STBI_REALLOC SDL_realloc
@@ -82,7 +85,8 @@ SDL_GpuShader* LoadShader(
8285
return NULL;
8386
}
8487

85-
SDL_GpuShader* shader = SDL_GpuCreateShader(device, &(SDL_GpuShaderCreateInfo){
88+
SDL_GpuShader* shader;
89+
SDL_GpuShaderCreateInfo shaderInfo = {
8690
.code = code,
8791
.codeSize = codeSize,
8892
.entryPointName = "main",
@@ -92,7 +96,15 @@ SDL_GpuShader* LoadShader(
9296
.uniformBufferCount = uniformBufferCount,
9397
.storageBufferCount = storageBufferCount,
9498
.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+
}
96108
if (shader == NULL)
97109
{
98110
SDL_Log("Failed to create shader!");
@@ -127,7 +139,15 @@ SDL_GpuComputePipeline* CreateComputePipelineFromShader(
127139
newCreateInfo.entryPointName = "main";
128140
newCreateInfo.format = SDL_GPU_SHADERFORMAT_SPIRV;
129141

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+
}
131151
if (pipeline == NULL)
132152
{
133153
SDL_Log("Failed to create compute pipeline!");
@@ -349,4 +369,4 @@ Vector3 Vector3_Cross(Vector3 vecA, Vector3 vecB)
349369
-(vecA.x * vecB.z - vecB.x * vecA.z),
350370
vecA.x * vecB.y - vecB.x * vecA.y
351371
};
352-
}
372+
}

spirv

Submodule spirv added at 1ff3891

0 commit comments

Comments
 (0)