PR #26180 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26180 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26180.patch
DRM imports can produce a 1920×1080 Vulkan image in a frames context whose height is 1088. Normalizing sampling by the context dimensions stretches luma and loses the bottom picture rows. This regressed in a344f0976c5d. Query the actual luma texture size in the shader, including when converting normalized coordinates back to luma pixels for chroma sampling. Remove the unused CPU-supplied dimensions from the C and shader push-constant declarations. This preserves the existing coordinate arithmetic for Vulkan-decoded images that really include padding. Fixes #26111. Validation on an NVIDIA RTX 5090 with separate plane images: the simulated imported-image mismatch reproduces at the regression commit and passes at its parent. All 22 size, format, crop, chroma-location and interpolation cases pass after the fix; genuinely padded inputs retain unpatched output byte for byte. Real Vulkan H.264 decode matches software decode plus upload at two output sizes with both samplers. Bayer conversion output is unchanged. Build and git diff --check pass. Intel VAAPI/ANV confirmation is requested on the issue. The diagnostic harness, exact revisions, build instructions and results are preserved on fairy/issue26111-tooling at 88d2d1aa6ff6 under tools/issue26111/. From 85755891193d1b6976303e98e149696a34b10385 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 18 Nov 2026 17:23:59 +0000 Subject: [PATCH] avfilter/scale_vulkan: normalize sampling by the actual texture size DRM imports can create a 1920x1080 image in a hardware frames context whose height is 1088. Using the context dimensions for normalized sampling stretches the luma plane and loses the bottom picture rows. Query the luma texture size in the shader instead. Use the same size when converting normalized coordinates back to luma pixels for chroma sampling, and remove the unused input dimensions from the shared push constant declarations. This also preserves sampling for Vulkan-decoded frames whose images really include padding. Verified the dimension mismatch with Vulkan images on NVIDIA, including the introducing commit and its parent. Tested nearest/bilinear sampling, width/height padding, cropping, chroma locations, RGB conversion, and Vulkan H.264 decoding. The original Intel VAAPI path needs a hardware retest. Fixes: a344f0976c5d0fc736715b3a63b0128f90c56377 Fixes: #26111 Assisted-by: Fairy --- libavfilter/vf_scale_vulkan.c | 6 ------ libavfilter/vulkan/debayer.comp.glsl | 1 - libavfilter/vulkan/scale.comp.glsl | 5 +++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c index 1681ad1b506..c71af65b883 100644 --- a/libavfilter/vf_scale_vulkan.c +++ b/libavfilter/vf_scale_vulkan.c @@ -72,7 +72,6 @@ typedef struct ScaleVulkanContext { int crop_y; int crop_w; int crop_h; - float in_dims[2]; float in_chroma_loc[2]; float out_chroma_loc[2]; } opts; @@ -99,7 +98,6 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) int in_planes = av_pix_fmt_count_planes(s->vkctx.input_format); int out_planes = av_pix_fmt_count_planes(s->vkctx.output_format); - const AVHWFramesContext *frames = (AVHWFramesContext *)in->hw_frames_ctx->data; switch (s->scaler) { case F_NEAREST: @@ -178,10 +176,6 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) s->opts.yuv_matrix[3][3] = 1.0; } - /* Normalized texture coordinates include hardware frame padding. */ - s->opts.in_dims[0] = frames->width; - s->opts.in_dims[1] = frames->height; - RET(ff_vk_shader_link(vkctx, shd, ff_scale_comp_spv_data, ff_scale_comp_spv_len, "main")); diff --git a/libavfilter/vulkan/debayer.comp.glsl b/libavfilter/vulkan/debayer.comp.glsl index 90a1516717e..0a4e22de99c 100644 --- a/libavfilter/vulkan/debayer.comp.glsl +++ b/libavfilter/vulkan/debayer.comp.glsl @@ -36,7 +36,6 @@ layout(push_constant, std430) uniform pushConstants { int crop_y; int crop_w; int crop_h; - vec2 in_dims; }; #define LD(xo, yo) \ diff --git a/libavfilter/vulkan/scale.comp.glsl b/libavfilter/vulkan/scale.comp.glsl index 62b11448ec9..0c9a4967a0f 100644 --- a/libavfilter/vulkan/scale.comp.glsl +++ b/libavfilter/vulkan/scale.comp.glsl @@ -48,7 +48,6 @@ layout (push_constant, std430) uniform pushConstants { int crop_y; int crop_w; int crop_h; - vec2 in_dims; vec2 in_chroma_loc; vec2 out_chroma_loc; }; @@ -66,7 +65,7 @@ vec4 scale_chroma(int idx, ivec2 pos, vec2 crop_range, vec2 crop_off) vec2 sub = vec2(1 << log2_chroma_w, 1 << log2_chroma_h); vec2 npos = (vec2(pos) * sub + 0.5f + out_chroma_loc) / imageSize(output_img[0]); npos = npos * crop_range + crop_off; - npos = (npos * in_dims - 0.5f - in_chroma_loc) / sub + 0.5f; + npos = (npos * textureSize(input_img[0], 0) - 0.5f - in_chroma_loc) / sub + 0.5f; return texture(input_img[idx], npos / textureSize(input_img[idx], 0)); } @@ -103,6 +102,8 @@ void write_444(vec4 src, ivec2 pos) void main() { ivec2 pos = ivec2(gl_GlobalInvocationID.xy); + /* Imported images can be smaller than their hardware frames context. */ + vec2 in_dims = textureSize(input_img[0], 0); vec2 c_r = vec2(crop_w, crop_h) / in_dims; vec2 c_o = vec2(crop_x, crop_y) / in_dims; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
