vulkan: add profiling debug setting

This simply keeps all shader optimizations, but allows debug
data to be generated.
pull/153/merge
Lynne 6 months ago
parent 832947be02
commit a304cbeb8d
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
  1. 4
      libavfilter/vulkan_glslang.c
  2. 8
      libavfilter/vulkan_shaderc.c
  3. 22
      libavutil/hwcontext_vulkan.c
  4. 3
      libavutil/vulkan.c

@ -184,11 +184,11 @@ static int glslc_shader_compile(FFVulkanContext *s, FFVkSPIRVCompiler *ctx,
#if ((GLSLANG_VERSION_MAJOR) >= 12) #if ((GLSLANG_VERSION_MAJOR) >= 12)
glslang_spv_options_t glslc_opts = { glslang_spv_options_t glslc_opts = {
.generate_debug_info = !!(s->extensions & FF_VK_EXT_DEBUG_UTILS), .generate_debug_info = !!(s->extensions & (FF_VK_EXT_DEBUG_UTILS | FF_VK_EXT_RELAXED_EXTENDED_INSTR)),
.emit_nonsemantic_shader_debug_info = !!(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR), .emit_nonsemantic_shader_debug_info = !!(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR),
.emit_nonsemantic_shader_debug_source = !!(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR), .emit_nonsemantic_shader_debug_source = !!(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR),
.disable_optimizer = !!(s->extensions & FF_VK_EXT_DEBUG_UTILS), .disable_optimizer = !!(s->extensions & FF_VK_EXT_DEBUG_UTILS),
.strip_debug_info = !(s->extensions & FF_VK_EXT_DEBUG_UTILS), .strip_debug_info = !(s->extensions & (FF_VK_EXT_DEBUG_UTILS | FF_VK_EXT_RELAXED_EXTENDED_INSTR)),
.optimize_size = 0, .optimize_size = 0,
.disassemble = 0, .disassemble = 0,
.validate = 1, .validate = 1,

@ -60,14 +60,16 @@ static int shdc_shader_compile(FFVulkanContext *s, FFVkSPIRVCompiler *ctx,
shaderc_env_version_vulkan_1_3); shaderc_env_version_vulkan_1_3);
shaderc_compile_options_set_target_spirv(opts, shaderc_spirv_version_1_6); shaderc_compile_options_set_target_spirv(opts, shaderc_spirv_version_1_6);
if (s->extensions & FF_VK_EXT_DEBUG_UTILS) { /* If either extension is set, turn on debug info */
if (s->extensions & (FF_VK_EXT_DEBUG_UTILS | FF_VK_EXT_RELAXED_EXTENDED_INSTR))
shaderc_compile_options_set_generate_debug_info(opts); shaderc_compile_options_set_generate_debug_info(opts);
if (s->extensions & FF_VK_EXT_DEBUG_UTILS)
shaderc_compile_options_set_optimization_level(opts, shaderc_compile_options_set_optimization_level(opts,
shaderc_optimization_level_zero); shaderc_optimization_level_zero);
} else { else
shaderc_compile_options_set_optimization_level(opts, shaderc_compile_options_set_optimization_level(opts,
shaderc_optimization_level_performance); shaderc_optimization_level_performance);
}
res = shaderc_compile_into_spv((shaderc_compiler_t)ctx->priv, res = shaderc_compile_into_spv((shaderc_compiler_t)ctx->priv,
shd->src.str, strlen(shd->src.str), shd->src.str, strlen(shd->src.str),

@ -642,6 +642,10 @@ enum FFVulkanDebugMode {
FF_VULKAN_DEBUG_PRINTF = 2, FF_VULKAN_DEBUG_PRINTF = 2,
/* Enables extra printouts */ /* Enables extra printouts */
FF_VULKAN_DEBUG_PRACTICES = 3, FF_VULKAN_DEBUG_PRACTICES = 3,
/* Disables validation but keeps shader debug info and optimizations */
FF_VULKAN_DEBUG_PROFILE = 4,
FF_VULKAN_DEBUG_NB,
}; };
static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts, static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
@ -705,7 +709,10 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
tstr = optional_exts[i].name; tstr = optional_exts[i].name;
found = 0; found = 0;
if (dev && debug_mode && if (dev &&
((debug_mode == FF_VULKAN_DEBUG_VALIDATE) ||
(debug_mode == FF_VULKAN_DEBUG_PRINTF) ||
(debug_mode == FF_VULKAN_DEBUG_PRACTICES)) &&
!strcmp(tstr, VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME)) { !strcmp(tstr, VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME)) {
continue; continue;
} }
@ -748,7 +755,8 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
} }
#ifdef VK_KHR_shader_relaxed_extended_instruction #ifdef VK_KHR_shader_relaxed_extended_instruction
if (dev && debug_mode == FF_VULKAN_DEBUG_PRINTF) { if (((debug_mode == FF_VULKAN_DEBUG_PRINTF) ||
(debug_mode == FF_VULKAN_DEBUG_PROFILE)) && dev) {
tstr = VK_KHR_SHADER_RELAXED_EXTENDED_INSTRUCTION_EXTENSION_NAME; tstr = VK_KHR_SHADER_RELAXED_EXTENDED_INSTRUCTION_EXTENSION_NAME;
found = 0; found = 0;
for (int j = 0; j < sup_ext_count; j++) { for (int j = 0; j < sup_ext_count; j++) {
@ -761,7 +769,7 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
av_log(ctx, AV_LOG_VERBOSE, "Using %s extension %s\n", mod, tstr); av_log(ctx, AV_LOG_VERBOSE, "Using %s extension %s\n", mod, tstr);
ADD_VAL_TO_LIST(extension_names, extensions_found, tstr); ADD_VAL_TO_LIST(extension_names, extensions_found, tstr);
} else { } else {
av_log(ctx, AV_LOG_ERROR, "Debug printf enabled, but extension \"%s\" not found!\n", av_log(ctx, AV_LOG_ERROR, "Debug_printf/profile enabled, but extension \"%s\" not found!\n",
tstr); tstr);
err = AVERROR(EINVAL); err = AVERROR(EINVAL);
goto fail; goto fail;
@ -847,7 +855,9 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
/* Check for any properly supported validation layer */ /* Check for any properly supported validation layer */
if (debug_opt) { if (debug_opt) {
if (!strcmp(debug_opt->value, "printf")) { if (!strcmp(debug_opt->value, "profile")) {
mode = FF_VULKAN_DEBUG_PROFILE;
} else if (!strcmp(debug_opt->value, "printf")) {
mode = FF_VULKAN_DEBUG_PRINTF; mode = FF_VULKAN_DEBUG_PRINTF;
} else if (!strcmp(debug_opt->value, "validate")) { } else if (!strcmp(debug_opt->value, "validate")) {
mode = FF_VULKAN_DEBUG_VALIDATE; mode = FF_VULKAN_DEBUG_VALIDATE;
@ -857,7 +867,7 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
char *end_ptr = NULL; char *end_ptr = NULL;
int idx = strtol(debug_opt->value, &end_ptr, 10); int idx = strtol(debug_opt->value, &end_ptr, 10);
if (end_ptr == debug_opt->value || end_ptr[0] != '\0' || if (end_ptr == debug_opt->value || end_ptr[0] != '\0' ||
idx < 0 || idx > FF_VULKAN_DEBUG_PRACTICES) { idx < 0 || idx >= FF_VULKAN_DEBUG_NB) {
av_log(ctx, AV_LOG_ERROR, "Invalid debugging mode \"%s\"\n", av_log(ctx, AV_LOG_ERROR, "Invalid debugging mode \"%s\"\n",
debug_opt->value); debug_opt->value);
err = AVERROR(EINVAL); err = AVERROR(EINVAL);
@ -887,6 +897,8 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
err = AVERROR(ENOTSUP); err = AVERROR(ENOTSUP);
goto end; goto end;
} }
} else if (mode == FF_VULKAN_DEBUG_PROFILE) {
*debug_mode = mode;
} }
/* Process any custom layers enabled */ /* Process any custom layers enabled */

@ -1479,7 +1479,8 @@ int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name,
GLSLC(0, #define IS_WITHIN(v1, v2) ((v1.x < v2.x) && (v1.y < v2.y)) ); GLSLC(0, #define IS_WITHIN(v1, v2) ((v1.x < v2.x) && (v1.y < v2.y)) );
GLSLC(0, ); GLSLC(0, );
GLSLC(0, #extension GL_EXT_scalar_block_layout : require ); GLSLC(0, #extension GL_EXT_scalar_block_layout : require );
if (s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR) if ((s->extensions & FF_VK_EXT_DEBUG_UTILS) &&
(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR))
GLSLC(0, #extension GL_EXT_debug_printf : require ); GLSLC(0, #extension GL_EXT_debug_printf : require );
if (stage == VK_SHADER_STAGE_TASK_BIT_EXT || if (stage == VK_SHADER_STAGE_TASK_BIT_EXT ||

Loading…
Cancel
Save