Use shader compilation from command line
This avoid dependency compilation and linking
This commit is contained in:
parent
b76e9d7ff3
commit
ed3c76c0b0
@ -16,6 +16,7 @@ cmake_print_variables("CXX flags Release: ${CMAKE_CXX_FLAGS_RELEASE}")
|
|||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CMAKE_C_STANDARD 23)
|
set(CMAKE_C_STANDARD 23)
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(SHADER_COMPILATION_USE_SOURCE OFF CACHE BOOL "Variable to control if to invoke command line for shader compilation or not")
|
||||||
|
|
||||||
set(LIBRARY_NAME "std")
|
set(LIBRARY_NAME "std")
|
||||||
set(RUNNER_NAME "runner")
|
set(RUNNER_NAME "runner")
|
||||||
@ -34,6 +35,11 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set (USE_LLVM ${BB_IS_CI} CACHE BOOL "Variable that determines if LLVM should be linked to the target")
|
set (USE_LLVM ${BB_IS_CI} CACHE BOOL "Variable that determines if LLVM should be linked to the target")
|
||||||
|
if (SHADER_COMPILATION_USE_SOURCE)
|
||||||
|
set(SHADER_COMPILATION_USE_SOURCE_C_FLAG "-DSHADER_COMPILATION_USE_SOURCE=1")
|
||||||
|
else()
|
||||||
|
set(SHADER_COMPILATION_USE_SOURCE_C_FLAG "-DSHADER_COMPILATION_USE_SOURCE=0")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
-pedantic
|
-pedantic
|
||||||
@ -44,7 +50,7 @@ add_compile_options(
|
|||||||
-fansi-escape-codes
|
-fansi-escape-codes
|
||||||
-ferror-limit=1
|
-ferror-limit=1
|
||||||
-march=native
|
-march=native
|
||||||
${BB_IS_CI_C_FLAG} -DCOMPILER_NAME=\"${COMPILER_NAME}\" -DBUILD_DIR=\"${CMAKE_BINARY_DIR}\" -DBB_DIR=\"${BB_DIR}\"
|
${BB_IS_CI_C_FLAG} -DCOMPILER_NAME=\"${COMPILER_NAME}\" -DBUILD_DIR=\"${CMAKE_BINARY_DIR}\" -DBB_DIR=\"${BB_DIR}\" ${SHADER_COMPILATION_USE_SOURCE_C_FLAG}
|
||||||
)
|
)
|
||||||
include_directories("bootstrap/include")
|
include_directories("bootstrap/include")
|
||||||
|
|
||||||
@ -185,10 +191,12 @@ if (USE_LLVM)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT BB_IS_CI)
|
if (NOT BB_IS_CI)
|
||||||
add_subdirectory(dependencies/SPIRV-Headers-vulkan-sdk-1.3.296.0)
|
if (SHADER_COMPILATION_USE_SOURCE)
|
||||||
add_subdirectory(dependencies/SPIRV-Tools-vulkan-sdk-1.3.296.0)
|
add_subdirectory(dependencies/SPIRV-Headers-vulkan-sdk-1.3.296.0)
|
||||||
add_subdirectory(dependencies/glslang-15.0.0)
|
add_subdirectory(dependencies/SPIRV-Tools-vulkan-sdk-1.3.296.0)
|
||||||
target_link_libraries(${COMPILER_NAME} PRIVATE glslang::glslang glslang::SPIRV glslang::glslang-default-resource-limits)
|
add_subdirectory(dependencies/glslang-15.0.0)
|
||||||
|
target_link_libraries(${COMPILER_NAME} PRIVATE glslang::glslang glslang::SPIRV glslang::glslang-default-resource-limits)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||||
|
1
bootstrap/shaders/.gitignore
vendored
Normal file
1
bootstrap/shaders/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.spv
|
@ -1,7 +1,7 @@
|
|||||||
#include <std/shader_compilation.h>
|
#include <std/shader_compilation.h>
|
||||||
|
#if SHADER_COMPILATION_USE_SOURCE
|
||||||
#include <glslang/Include/glslang_c_interface.h>
|
#include <glslang/Include/glslang_c_interface.h>
|
||||||
|
|
||||||
|
|
||||||
// Required for use of glslang_default_resource
|
// Required for use of glslang_default_resource
|
||||||
#include <glslang/Public/resource_limits_c.h>
|
#include <glslang/Public/resource_limits_c.h>
|
||||||
|
|
||||||
@ -85,9 +85,11 @@ fn SpirVBinary compileShaderToSPIRV_Vulkan(Arena* arena, glslang_stage_t stage,
|
|||||||
|
|
||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
String compile_shader(Arena* arena, String path, ShaderStage shader_stage)
|
String compile_shader(Arena* arena, String path, ShaderStage shader_stage)
|
||||||
{
|
{
|
||||||
|
#if SHADER_COMPILATION_USE_SOURCE
|
||||||
auto file = file_read(arena, path);
|
auto file = file_read(arena, path);
|
||||||
|
|
||||||
glslang_stage_t stage;
|
glslang_stage_t stage;
|
||||||
@ -107,4 +109,22 @@ String compile_shader(Arena* arena, String path, ShaderStage shader_stage)
|
|||||||
.pointer = (u8*)result.words,
|
.pointer = (u8*)result.words,
|
||||||
.length = result.size * sizeof(*result.words),
|
.length = result.size * sizeof(*result.words),
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
unused(shader_stage);
|
||||||
|
auto output_path = arena_join_string(arena, (Slice(String))array_to_slice(((String[]) {
|
||||||
|
path,
|
||||||
|
strlit(".spv"),
|
||||||
|
})));
|
||||||
|
char* arguments[] = {
|
||||||
|
"/usr/bin/glslangValidator",
|
||||||
|
"-V",
|
||||||
|
string_to_c(path),
|
||||||
|
"-o",
|
||||||
|
string_to_c(output_path),
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
run_command(arena, (CStringSlice)array_to_slice(arguments), 0);
|
||||||
|
auto file = file_read(arena, output_path);
|
||||||
|
return file;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ case $BIRTH_OS in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
SHADER_DIR=$
|
||||||
BUILD_DIR=$ORIGINAL_DIR/build/$CMAKE_BUILD_TYPE
|
BUILD_DIR=$ORIGINAL_DIR/build/$CMAKE_BUILD_TYPE
|
||||||
mkdir -p $BUILD_DIR
|
mkdir -p $BUILD_DIR
|
||||||
cmake . \
|
cmake . \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user