Skip to content

Commit

Permalink
Add shader debug info when t.graphics.debug is set;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Apr 20, 2023
1 parent edb65a7 commit 6a030ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ typedef struct {
bool depthResolve;
bool indirectDrawFirstInstance;
bool shaderTally;
bool shaderDebug;
bool float64;
bool int64;
bool int16;
Expand Down
5 changes: 4 additions & 1 deletion src/core/gpu_vk.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ typedef struct {
bool portability;
bool validation;
bool debug;
bool shaderDebug;
bool colorspace;
bool depthResolve;
} gpu_extensions;
Expand Down Expand Up @@ -2143,7 +2144,8 @@ bool gpu_init(gpu_config* config) {
{ "VK_KHR_create_renderpass2", true, NULL },
{ "VK_KHR_swapchain", state.config.vk.surface, NULL },
{ "VK_KHR_portability_subset", true, &state.extensions.portability },
{ "VK_KHR_depth_stencil_resolve", true, &state.extensions.depthResolve }
{ "VK_KHR_depth_stencil_resolve", true, &state.extensions.depthResolve },
{ "VK_KHR_shader_non_semantic_info", state.config.debug, &state.extensions.shaderDebug }
};

VkExtensionProperties extensionInfo[512];
Expand All @@ -2165,6 +2167,7 @@ bool gpu_init(gpu_config* config) {

if (config->features) {
config->features->depthResolve = state.extensions.depthResolve;
config->features->shaderDebug = state.extensions.shaderDebug;
}

VkDeviceCreateInfo deviceInfo = {
Expand Down
11 changes: 10 additions & 1 deletion src/modules/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,16 @@ ShaderSource lovrGraphicsCompileShader(ShaderStage stage, ShaderSource* source)

glslang_program_map_io(program);

glslang_program_SPIRV_generate(program, stages[stage]);
glslang_spv_options_t spvOptions = { 0 };

if (state.config.debug && state.features.shaderDebug) {
spvOptions.generate_debug_info = true;
spvOptions.emit_nonsemantic_shader_debug_info = true;
spvOptions.emit_nonsemantic_shader_debug_source = true;
glslang_program_add_source_text(program, stages[stage], source->code, source->size);
}

glslang_program_SPIRV_generate_with_options(program, stages[stage], &spvOptions);

void* words = glslang_program_SPIRV_get_ptr(program);
size_t size = glslang_program_SPIRV_get_size(program) * 4;
Expand Down

0 comments on commit 6a030ef

Please sign in to comment.