Skip to content

Commit 1f0b948

Browse files
committed
allow more than one shader
1 parent 373f44a commit 1f0b948

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ endforeach(GLSL_FILE)
9595
# create a command to generate the source file that depends on the shader headers
9696
set(SPVRC_SRC "${CMAKE_CURRENT_BINARY_DIR}/spvrc.cpp")
9797
add_custom_command(
98-
COMMAND ${CMAKE_COMMAND}
99-
-DSPVRC_SRC=${SPVRC_SRC}
100-
-DSPVRC_SPIRV_HEADERS=${SPVRC_SPIRV_HEADERS}
101-
-DSPVRC_SPIRV_FILES=${SPVRC_SPIRV_FILES}
102-
-DSPVRC_SPIRV_SYMBOLS=${SPVRC_SPIRV_SYMBOLS}
98+
COMMAND_EXPAND_LISTS
99+
COMMAND ${CMAKE_COMMAND}
100+
-DSPVRC_SRC=${SPVRC_SRC}
101+
-DSPVRC_SPIRV_HEADERS="${SPVRC_SPIRV_HEADERS}"
102+
-DSPVRC_SPIRV_FILES="${SPVRC_SPIRV_FILES}"
103+
-DSPVRC_SPIRV_SYMBOLS="${SPVRC_SPIRV_SYMBOLS}"
103104
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_spvrc_source.cmake"
104105
DEPENDS ${SPVRC_SPIRV_HEADERS}
105106
OUTPUT ${SPVRC_SRC}

cmake/generate_spvrc_source.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
string(REPLACE " " ";" SPVRC_SPIRV_HEADERS ${SPVRC_SPIRV_HEADERS})
2+
string(REPLACE " " ";" SPVRC_SPIRV_FILES ${SPVRC_SPIRV_FILES})
3+
string(REPLACE " " ";" SPVRC_SPIRV_SYMBOLS ${SPVRC_SPIRV_SYMBOLS})
4+
15
file(WRITE "${SPVRC_SRC}"
26
"#include <string_view>
37
#include <cstdint>
8+
#include <cassert>
49
#include <vector>
510
#include \"spvrc/spvrc.hpp\"
611
")
@@ -22,17 +27,17 @@ constexpr uint32_t hash(std::string_view data) noexcept {
2227
namespace spvrc {
2328
auto load(std::string_view path) -> std::vector<uint32_t> {
2429
std::vector<uint32_t> data;
25-
switch (hash(path)) {
26-
")
30+
switch (hash(path)) {"
31+
)
2732
# insert shader data
2833
foreach(SPIRV_FILE SPIRV_SYMBOL IN ZIP_LISTS SPVRC_SPIRV_FILES SPVRC_SPIRV_SYMBOLS)
29-
file(APPEND "${SPVRC_SRC}"
30-
" case hash(\"${SPIRV_FILE}\"): data = { ${SPIRV_SYMBOL}, ${SPIRV_SYMBOL} + std::size(${SPIRV_SYMBOL})}; break;\n"
34+
file(APPEND "${SPVRC_SRC}" "
35+
case hash(\"${SPIRV_FILE}\"): data = { ${SPIRV_SYMBOL}, ${SPIRV_SYMBOL} + std::size(${SPIRV_SYMBOL})}; break;"
3136
)
3237
endforeach(SPIRV_FILE SPIRV_SYMBOL)
3338
# end namespace
3439
file(APPEND "${SPVRC_SRC}" "
35-
default: break;
40+
default: assert(false && \"Shader not found\");
3641
}
3742
return data;
3843
}

shaders/shader2.comp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#version 460
2+
3+
layout(set = 0, binding = 0, rgba16f) uniform image2D image;
4+
layout(constant_id = 0) const uint image_size_x = 1280;
5+
layout(constant_id = 1) const uint image_size_y = 720;
6+
const uvec2 image_size = uvec2(image_size_x, image_size_y);
7+
8+
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
9+
void main() {
10+
uvec2 texelCoord = gl_GlobalInvocationID.xy;
11+
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
12+
if(gl_LocalInvocationID.x != 0 && gl_LocalInvocationID.y != 0) {
13+
color.x = float(texelCoord.x)/float(image_size.x);
14+
color.y = float(texelCoord.y)/float(image_size.y);
15+
}
16+
imageStore(image, ivec2(texelCoord), color);
17+
}

0 commit comments

Comments
 (0)