Skip to content

Commit

Permalink
merian: shader compiler: generate debug info in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Dec 6, 2024
1 parent 9ca83d7 commit 5254ce5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/merian/vk/shader/shader_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ class ShaderCompiler {
shader_kind);
}

void set_generate_debug_info(const bool enable) {
generate_debug_info = enable;
}

// ------------------------------------------------

void add_include_path(const std::string& include_path) {
Expand All @@ -167,6 +171,10 @@ class ShaderCompiler {

virtual bool available() const = 0;

bool generate_debug_info_enabled() const {
return generate_debug_info;
}

private:
static vk::ShaderStageFlagBits guess_kind(const std::filesystem::path& path) {
std::string extension;
Expand All @@ -188,6 +196,7 @@ class ShaderCompiler {

std::vector<std::string> include_paths;
std::map<std::string, std::string> macro_definitions;
bool generate_debug_info;
};

} // namespace merian
1 change: 1 addition & 0 deletions src/merian/vk/shader/shader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ShaderCompiler::ShaderCompiler(const ContextHandle& context,
insert_all(include_paths, context->get_default_shader_include_paths());
macro_definitions.insert(context->get_default_shader_macro_definitions().begin(),
context->get_default_shader_macro_definitions().end());
generate_debug_info = Context::IS_DEBUG_BUILD;
}

ShaderCompiler::~ShaderCompiler(){};
Expand Down
2 changes: 2 additions & 0 deletions src/merian/vk/shader/shader_compiler_shaderc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ std::vector<uint32_t> ShadercCompiler::compile_glsl(
const shaderc_shader_kind kind = shaderc_shader_kind_for_stage_flag_bit(shader_kind);

shaderc::CompileOptions compile_options;
if (generate_debug_info_enabled())
compile_options.SetGenerateDebugInfo();

for (const auto& [key, value] : get_macro_definitions()) {
compile_options.AddMacroDefinition(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ std::vector<uint32_t> SystemGlslangValidatorCompiler::compile_glsl(
command.emplace_back(fmt::format("-D{}={}", key, value));
}

if (generate_debug_info_enabled()) {
command.emplace_back("-g");
}

const std::string output_file = temporary_file();
command.emplace_back("-o");
command.emplace_back(output_file);
Expand Down
4 changes: 4 additions & 0 deletions src/merian/vk/shader/shader_compiler_system_glslc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ std::vector<uint32_t> SystemGlslcCompiler::compile_glsl(
command.emplace_back(fmt::format("-D{}={}", key, value));
}

if (generate_debug_info_enabled()) {
command.emplace_back("-g");
}

// turn on optimization
command.emplace_back("-O");

Expand Down

0 comments on commit 5254ce5

Please sign in to comment.