[FFmpeg-cvslog] vulkan: add profiling debug setting
Lynne
git at videolan.org
Fri Oct 4 11:28:45 EEST 2024
ffmpeg | branch: master | Lynne <dev at lynne.ee> | Fri Oct 4 04:24:20 2024 +0200| [a304cbeb8d48d97acc48e526b24e2db9189fa848] | committer: Lynne
vulkan: add profiling debug setting
This simply keeps all shader optimizations, but allows debug
data to be generated.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a304cbeb8d48d97acc48e526b24e2db9189fa848
---
libavfilter/vulkan_glslang.c | 4 ++--
libavfilter/vulkan_shaderc.c | 8 +++++---
libavutil/hwcontext_vulkan.c | 22 +++++++++++++++++-----
libavutil/vulkan.c | 3 ++-
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/libavfilter/vulkan_glslang.c b/libavfilter/vulkan_glslang.c
index 68c0fcbe53..9e1b8f4d8d 100644
--- a/libavfilter/vulkan_glslang.c
+++ b/libavfilter/vulkan_glslang.c
@@ -184,11 +184,11 @@ static int glslc_shader_compile(FFVulkanContext *s, FFVkSPIRVCompiler *ctx,
#if ((GLSLANG_VERSION_MAJOR) >= 12)
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_source = !!(s->extensions & FF_VK_EXT_RELAXED_EXTENDED_INSTR),
.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,
.disassemble = 0,
.validate = 1,
diff --git a/libavfilter/vulkan_shaderc.c b/libavfilter/vulkan_shaderc.c
index 7144f04f21..6e7475c49f 100644
--- a/libavfilter/vulkan_shaderc.c
+++ b/libavfilter/vulkan_shaderc.c
@@ -60,14 +60,16 @@ static int shdc_shader_compile(FFVulkanContext *s, FFVkSPIRVCompiler *ctx,
shaderc_env_version_vulkan_1_3);
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);
+
+ if (s->extensions & FF_VK_EXT_DEBUG_UTILS)
shaderc_compile_options_set_optimization_level(opts,
shaderc_optimization_level_zero);
- } else {
+ else
shaderc_compile_options_set_optimization_level(opts,
shaderc_optimization_level_performance);
- }
res = shaderc_compile_into_spv((shaderc_compiler_t)ctx->priv,
shd->src.str, strlen(shd->src.str),
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 033077178c..af187d6840 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -642,6 +642,10 @@ enum FFVulkanDebugMode {
FF_VULKAN_DEBUG_PRINTF = 2,
/* Enables extra printouts */
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,
@@ -705,7 +709,10 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
tstr = optional_exts[i].name;
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)) {
continue;
}
@@ -748,7 +755,8 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
}
#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;
found = 0;
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);
ADD_VAL_TO_LIST(extension_names, extensions_found, tstr);
} 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);
err = AVERROR(EINVAL);
goto fail;
@@ -847,7 +855,9 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
/* Check for any properly supported validation layer */
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;
} else if (!strcmp(debug_opt->value, "validate")) {
mode = FF_VULKAN_DEBUG_VALIDATE;
@@ -857,7 +867,7 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
char *end_ptr = NULL;
int idx = strtol(debug_opt->value, &end_ptr, 10);
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",
debug_opt->value);
err = AVERROR(EINVAL);
@@ -887,6 +897,8 @@ static int check_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
err = AVERROR(ENOTSUP);
goto end;
}
+ } else if (mode == FF_VULKAN_DEBUG_PROFILE) {
+ *debug_mode = mode;
}
/* Process any custom layers enabled */
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index fe69bf4698..44552e97b8 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -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, );
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 );
if (stage == VK_SHADER_STAGE_TASK_BIT_EXT ||
More information about the ffmpeg-cvslog
mailing list