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,