GPU: Add flag for shader debug info generation
This PR proposes to add a new flag `--shader-debug-info` that enables the generation of shader debug information. I created this PR as WIP due to the following reasons: - Currently it only works for the Vulkan backend. I do not know if it makes sense for other backends. For example, OpenGL directly receives the GLSL code, so there no need for this might exist. - So far `--debug-gpu-renderdoc` already turns on the following changes for GLSL shader compilation with shaderc: ``` options.SetOptimizationLevel(shaderc_optimization_level_zero); options.SetGenerateDebugInfo(); ``` - While combining optimization level zero with debug info is a sensible choice for frame debuggers like RenderDoc, my use case for creating this PR is shader profiling. In this case, one does not want compiler optimizations to be turned off. At the current point in time, the only information my profiler uses (which is unfortunately not public at this point in time) is the name of the shader. When turning on debug information, shaderc/glslang store this information in the generated SPIR-V data. Otherwise, it would be impossible for the profiler to tell the user what the name of the shader it is that is profiled. - An alternative solution would be to rename the entry point `main` of a shader to the name of the shader. But this might be an even uglier hack, as it requires editing the source code (and the name of the shader then needs to be a valid GLSL function name). - We should first clarify if there is interest in the Blender side in upstreaming an option like this. While I could just keep this in my local fork of Blender, there is merit in having the possibility to profile arbitrary Blender builds. Pull Request: https://projects.blender.org/blender/blender/pulls/142986
This commit is contained in:
committed by
Nikita Sirgienko
parent
02879c2d85
commit
1384bad2d2
@@ -258,11 +258,12 @@ enum {
|
||||
G_DEBUG_GPU_FORCE_VULKAN_LOCAL_READ = (1 << 19), /* Force GPU dynamic rendering local read. */
|
||||
G_DEBUG_GPU_COMPILE_SHADERS = (1 << 20), /* Compile all statically defined shaders. . */
|
||||
G_DEBUG_GPU_RENDERDOC = (1 << 21), /* Enable RenderDoc integration. */
|
||||
G_DEBUG_XR = (1 << 22), /* XR/OpenXR messages */
|
||||
G_DEBUG_XR_TIME = (1 << 23), /* XR/OpenXR timing messages */
|
||||
G_DEBUG_GPU_SHADER_DEBUG_INFO = (1 << 22), /* Enable the generation of shader debug info. */
|
||||
G_DEBUG_XR = (1 << 23), /* XR/OpenXR messages */
|
||||
G_DEBUG_XR_TIME = (1 << 24), /* XR/OpenXR timing messages */
|
||||
|
||||
G_DEBUG_GHOST = (1 << 24), /* Debug GHOST module. */
|
||||
G_DEBUG_WINTAB = (1 << 25), /* Debug Wintab. */
|
||||
G_DEBUG_GHOST = (1 << 25), /* Debug GHOST module. */
|
||||
G_DEBUG_WINTAB = (1 << 26), /* Debug Wintab. */
|
||||
};
|
||||
|
||||
#define G_DEBUG_ALL \
|
||||
|
||||
@@ -176,6 +176,8 @@ static bool compile_ex(shaderc::Compiler &compiler,
|
||||
options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_2);
|
||||
if (G.debug & G_DEBUG_GPU_RENDERDOC) {
|
||||
options.SetOptimizationLevel(shaderc_optimization_level_zero);
|
||||
}
|
||||
if (G.debug & G_DEBUG_GPU_SHADER_DEBUG_INFO) {
|
||||
options.SetGenerateDebugInfo();
|
||||
}
|
||||
|
||||
|
||||
@@ -1529,13 +1529,24 @@ static int arg_handle_debug_gpu_renderdoc_set(int /*argc*/,
|
||||
void * /*data*/)
|
||||
{
|
||||
# ifdef WITH_RENDERDOC
|
||||
G.debug |= G_DEBUG_GPU_RENDERDOC | G_DEBUG_GPU;
|
||||
G.debug |= G_DEBUG_GPU_RENDERDOC | G_DEBUG_GPU | G_DEBUG_GPU_SHADER_DEBUG_INFO;
|
||||
# else
|
||||
BLI_assert_unreachable();
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char arg_handle_debug_gpu_shader_debug_info_set_doc[] =
|
||||
"\n"
|
||||
"\tEnable shader debug info generation (Vulkan only).";
|
||||
static int arg_handle_debug_gpu_shader_debug_info_set(int /*argc*/,
|
||||
const char ** /*argv*/,
|
||||
void * /*data*/)
|
||||
{
|
||||
G.debug |= G_DEBUG_GPU_SHADER_DEBUG_INFO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char arg_handle_gpu_backend_set_doc_all[] =
|
||||
"\n"
|
||||
"\tForce to use a specific GPU backend. Valid options: "
|
||||
@@ -2886,6 +2897,11 @@ void main_args_setup(bContext *C, bArgs *ba, bool all)
|
||||
BLI_args_add(
|
||||
ba, nullptr, "--debug-gpu-renderdoc", CB(arg_handle_debug_gpu_renderdoc_set), nullptr);
|
||||
}
|
||||
BLI_args_add(ba,
|
||||
nullptr,
|
||||
"--debug-gpu-shader-debug-info",
|
||||
CB(arg_handle_debug_gpu_shader_debug_info_set),
|
||||
nullptr);
|
||||
|
||||
BLI_args_add(ba,
|
||||
nullptr,
|
||||
|
||||
Reference in New Issue
Block a user