Skip to content

Commit

Permalink
add missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
leanid committed Jan 17, 2025
1 parent a36c197 commit 44bc6b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
33 changes: 27 additions & 6 deletions 02-vulkan/08-vk-framebuffer-cmd-2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ find_package(
#[OPTIONAL_COMPONENTS <libs>...]
# Optional Boost libraries by their canonical name)
) # e.g. "date_time" for "libboost_date_time"
find_program(SLANGC slangc REQUIRED)


om_clang_tidy_enable()
Expand Down Expand Up @@ -57,22 +58,42 @@ PRIVATE
# cmake-format: on

# Find the shader files
file(GLOB_RECURSE shader_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
file(GLOB_RECURSE glsl_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert
${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.frag)

# For each shader file
foreach(shader_file ${shader_files})
set(spirv_file "${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}.spv")
file(GLOB_RECURSE slang_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.slang)

foreach(glsl_file ${glsl_files})
set(spirv_file "${CMAKE_CURRENT_SOURCE_DIR}/${glsl_file}.spv")

# Add custom command to compile shader file to SPIR-V
add_custom_command(
OUTPUT ${spirv_file}
COMMAND
Vulkan::glslangValidator -V --target-env vulkan1.0
${CMAKE_CURRENT_SOURCE_DIR}/${shader_file} -o ${spirv_file}
${CMAKE_CURRENT_SOURCE_DIR}/${glsl_file} -o ${spirv_file}
VERBATIM
DEPENDS ${glsl_file})

list(APPEND spirv_files ${spirv_file})
endforeach()

foreach(slang_file ${slang_files})
set(spirv_file "${CMAKE_CURRENT_SOURCE_DIR}/${slang_file}.spv")

# Add custom command to compile shader file to SPIR-V
add_custom_command(
OUTPUT ${spirv_file}
COMMAND
slangc ${CMAKE_CURRENT_SOURCE_DIR}/${slang_file}
-target spirv -o ${spirv_file}
-profile spirv_1_0
-emit-spirv-directly # only for RenderDoc debuging
-g2 # enable debug info in SPIR-V for RenderDoc
VERBATIM
DEPENDS ${shader_file})
DEPENDS ${slang_file})

list(APPEND spirv_files ${spirv_file})
endforeach()
Expand Down
3 changes: 2 additions & 1 deletion 02-vulkan/08-vk-framebuffer-cmd-2/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ int main(int argc, char** argv)
});

std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window(
SDL_CreateWindow("04-vk-swapchain-1", 800, 600, SDL_WINDOW_VULKAN),
SDL_CreateWindow(
"08-vk-framebuffer-cmd-2", 800, 600, SDL_WINDOW_VULKAN),
SDL_DestroyWindow);
std::experimental::scope_exit destroy_window(
[&log]() { log << "destroy sdl window\n"; });
Expand Down
2 changes: 1 addition & 1 deletion 02-vulkan/08-vk-framebuffer-cmd-2/render.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ void render::create_graphics_pipeline()
auto vertex_shader_code = platform_.get_file_content(
"./02-vulkan/08-vk-framebuffer-cmd-2/shaders/shader.vert.slang.spv");
auto fragment_shader_code = platform_.get_file_content(
"./02-vulkan/08-vk-framebuffer-cmd-2/shaders/shader.frag.spv");
"./02-vulkan/08-vk-framebuffer-cmd-2/shaders/shader.frag.slang.spv");
// compile shaders from spir-v into gpu code
vk::ShaderModule vertex = create_shader(vertex_shader_code.as_span());
std::experimental::scope_exit vertex_cleanup([this, &vertex]()
Expand Down

0 comments on commit 44bc6b9

Please sign in to comment.