From 7d3ace8cb21dfbb7a2b1fdb7246bef73ec629a5d Mon Sep 17 00:00:00 2001 From: Lynne Date: Sun, 20 Sep 2026 17:30:24 +0900 Subject: [PATCH] vulkan_prores: pick the bitstream prefetch depth per device Same situation as ProRes RAW: with the packet host-mapped, the VLD is bound by fetch latency over the bus. Make GET_BITS_SMEM a specialization constant: 32 lines per invocation on discrete GPUs reading host-mapped packets, 4 otherwise. The 8x8 workgroup makes that 32 KB of shared memory; 64 does not fit, and 40 or 48 measured slower. An integrated GPU loses a third of its speed at 32, so it keeps 4. The depth is clamped to maxComputeSharedMemorySize for 32 KB devices such as MoltenVK. 5.7K ProRes HQ on an RX 6900 XT: 85 -> 120 fps, bit-identical output. --- libavcodec/vulkan/prores_vld.comp.glsl | 4 +++- libavcodec/vulkan_prores.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libavcodec/vulkan/prores_vld.comp.glsl b/libavcodec/vulkan/prores_vld.comp.glsl index b0b17264a4..cdf1fe9ef9 100644 --- a/libavcodec/vulkan/prores_vld.comp.glsl +++ b/libavcodec/vulkan/prores_vld.comp.glsl @@ -19,7 +19,9 @@ #pragma shader_stage(compute) #extension GL_GOOGLE_include_directive : require -#define GET_BITS_SMEM 4 +/* Bitstream prefetch depth in 16-byte lines, set by the host */ +layout (constant_id = 1) const uint smem_lines = 4; +#define GET_BITS_SMEM smem_lines #include "common.glsl" layout (constant_id = 0) const bool interlaced = false; diff --git a/libavcodec/vulkan_prores.c b/libavcodec/vulkan_prores.c index d8d7808ef8..1ccbb5288b 100644 --- a/libavcodec/vulkan_prores.c +++ b/libavcodec/vulkan_prores.c @@ -374,8 +374,19 @@ static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s, AVHWFramesContext *dec_frames_ctx; dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; - SPEC_LIST_CREATE(sl, 1, 1*sizeof(uint32_t)) + /* Discrete GPUs read host-mapped packets over the bus; prefetch more + * to hide the latency. 32 lines (32 KB for the 8x8 workgroup) measured + * best; integrated GPUs get slower with every extra line. Clamp to the + * shared memory limit, leaving 1 KB for the tables. */ + int smem_lines = 4; + if (s->props.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && + (s->extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)) { + uint32_t max_smem = s->props.properties.limits.maxComputeSharedMemorySize; + smem_lines = FFMIN(32, (max_smem - 1024) / (8*8*16)); + } + SPEC_LIST_CREATE(sl, 2, 2*sizeof(uint32_t)) SPEC_LIST_ADD(sl, 0, 32, interlaced); + SPEC_LIST_ADD(sl, 1, 32, smem_lines); ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,