From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id DD06443D2C for ; Mon, 17 Feb 2025 18:32:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8A3E568C17C; Mon, 17 Feb 2025 20:31:45 +0200 (EET) Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 75F3668C05A for ; Mon, 17 Feb 2025 20:31:38 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1739817098; bh=ve66md5ab5jjySuKnBbgzsd VXKH8VORW8+eJhc70zcc=; b=CmeBirqmOXlXoysYcWYsJiHn3etgVUmVNWl1aRCAPP6Cy/aGoJ AJxj/Jo3bqzIoDlEDhjOyAajkYzpi7cnJtyK+RaydCSLF20cdxbFhLX0+q5k8MbqpRc1P37ADuN Xki3HctThwtMLNmsi+pmZV3a1sGBW9XjVTswfLuk+hGX3CelscJse49H8fk9tn5nHWMyhsfSXZV m9ETJcpNL7eQ8j9LfHeicZjmIgkJhuY65qGDxC88EZtYnCchEAYrOODsp2rCHvWQ8fnIFQRHEFk TwooBKH5uOYAY1pnuz1r5ROZ+FIQfFJ8Ghv5XGZdj1YD0LyMqm9qS1MIHkAtDMrE7Hg==; DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed; h=Message-ID:Date:Subject:To:From; t=1739817098; bh=ve66md5ab5jjySuKnBbgzsd VXKH8VORW8+eJhc70zcc=; b=mZeV62vUGvosZRch/WUFalsAUb2NWGW2V9Ngy4vQOOvsYOcJsC C1LUPS5Uc8DBo2Ar0Tb4KHzr6A6chgTwj0AQ==; From: Lynne To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Feb 2025 19:31:13 +0100 Message-ID: <20250217183125.57656-3-dev@lynne.ee> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250217183125.57656-1-dev@lynne.ee> References: <20250217183125.57656-1-dev@lynne.ee> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/11] nlmeans_vulkan: switch to imageLoad() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Lynne Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavfilter/vf_nlmeans_vulkan.c | 56 ++++++++++++++------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/libavfilter/vf_nlmeans_vulkan.c b/libavfilter/vf_nlmeans_vulkan.c index 67360dc745..22a2a73eae 100644 --- a/libavfilter/vf_nlmeans_vulkan.c +++ b/libavfilter/vf_nlmeans_vulkan.c @@ -37,7 +37,6 @@ typedef struct NLMeansVulkanContext { int initialized; FFVkExecPool e; AVVulkanDeviceQueueFamily *qf; - VkSampler sampler; AVBufferPool *integral_buf_pool; AVBufferPool *ws_buf_pool; @@ -66,16 +65,16 @@ typedef struct NLMeansVulkanContext { static void insert_first(FFVulkanShader *shd, int r, const char *off, int horiz, int plane, int comp) { - GLSLF(4, s1 = texture(input_img[%i], pos + ivec2(%i + %s, %i + %s))[%i]; + GLSLF(4, s1 = imageLoad(input_img[%i], pos + ivec2(%i + %s, %i + %s))[%i]; ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp); - GLSLF(4, s2[0] = texture(input_img[%i], pos + offs[0] + ivec2(%i + %s, %i + %s))[%i]; + GLSLF(4, s2[0] = imageLoad(input_img[%i], pos + offs[0] + ivec2(%i + %s, %i + %s))[%i]; ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp); - GLSLF(4, s2[1] = texture(input_img[%i], pos + offs[1] + ivec2(%i + %s, %i + %s))[%i]; + GLSLF(4, s2[1] = imageLoad(input_img[%i], pos + offs[1] + ivec2(%i + %s, %i + %s))[%i]; ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp); - GLSLF(4, s2[2] = texture(input_img[%i], pos + offs[2] + ivec2(%i + %s, %i + %s))[%i]; + GLSLF(4, s2[2] = imageLoad(input_img[%i], pos + offs[2] + ivec2(%i + %s, %i + %s))[%i]; ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp); - GLSLF(4, s2[3] = texture(input_img[%i], pos + offs[3] + ivec2(%i + %s, %i + %s))[%i]; + GLSLF(4, s2[3] = imageLoad(input_img[%i], pos + offs[3] + ivec2(%i + %s, %i + %s))[%i]; ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp); GLSLC(4, s2 = (s1 - s2) * (s1 - s2); ); @@ -164,10 +163,10 @@ static void insert_weights_pass(FFVulkanShader *shd, int nb_rows, int vert, GLSLC(0, ); GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); ); GLSLC(0, ); - GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp); - GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp); - GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%i]; ,plane, comp); - GLSLF(3, src[3] = texture(input_img[%i], pos + offs[3])[%i]; ,plane, comp); + GLSLF(3, src[0] = imageLoad(input_img[%i], pos + offs[0])[%i]; ,plane, comp); + GLSLF(3, src[1] = imageLoad(input_img[%i], pos + offs[1])[%i]; ,plane, comp); + GLSLF(3, src[2] = imageLoad(input_img[%i], pos + offs[2])[%i]; ,plane, comp); + GLSLF(3, src[3] = imageLoad(input_img[%i], pos + offs[3])[%i]; ,plane, comp); GLSLC(0, ); GLSLC(3, if (lt == false) { ); GLSLC(3, offset = int_stride * uint64_t(pos.y - p); ); @@ -210,7 +209,7 @@ typedef struct HorizontalPushData { static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec, FFVulkanShader *shd, - VkSampler sampler, FFVkSPIRVCompiler *spv, + FFVkSPIRVCompiler *spv, int width, int height, int t, const AVPixFmtDescriptor *desc, int planes, int *nb_rows) @@ -275,11 +274,12 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e desc_set = (FFVulkanDescriptorSetBinding []) { { .name = "input_img", - .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + .mem_layout = ff_vk_shader_rep_fmt(vkctx->input_format, FF_VK_REP_FLOAT), + .mem_quali = "readonly", .dimensions = 2, .elems = planes, .stages = VK_SHADER_STAGE_COMPUTE_BIT, - .samplers = DUP_SAMPLER(sampler), }, { .name = "weights_buffer_0", @@ -418,8 +418,7 @@ typedef struct DenoisePushData { } DenoisePushData; static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec, - FFVulkanShader *shd, - VkSampler sampler, FFVkSPIRVCompiler *spv, + FFVulkanShader *shd, FFVkSPIRVCompiler *spv, const AVPixFmtDescriptor *desc, int planes) { int err; @@ -445,11 +444,12 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e desc_set = (FFVulkanDescriptorSetBinding []) { { .name = "input_img", - .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, + .mem_layout = ff_vk_shader_rep_fmt(vkctx->input_format, FF_VK_REP_FLOAT), + .mem_quali = "readonly", .dimensions = 2, .elems = planes, .stages = VK_SHADER_STAGE_COMPUTE_BIT, - .samplers = DUP_SAMPLER(sampler), }, { .name = "output_img", @@ -539,7 +539,7 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e GLSLC(1, if (!IS_WITHIN(pos, size)) ); GLSLC(2, return; ); GLSLC(0, ); - GLSLC(1, src = texture(input_img[plane], pos); ); + GLSLC(1, src = imageLoad(input_img[plane], pos); ); GLSLC(0, ); for (int c = 0; c < desc->nb_components; c++) { int off = desc->comp[c].offset / (FFALIGN(desc->comp[c].depth, 8)/8); @@ -660,13 +660,12 @@ static av_cold int init_filter(AVFilterContext *ctx) } RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, 1, 0, 0, 0, NULL)); - RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST)); - RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights, s->sampler, + RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights, spv, s->vkctx.output_width, s->vkctx.output_height, s->opts.t, desc, planes, &s->pl_weights_rows)); - RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise, s->sampler, + RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise, spv, desc, planes)); RET(ff_vk_shader_update_desc_buffer(vkctx, &s->e.contexts[0], &s->shd_weights, @@ -865,7 +864,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_GENERAL, VK_QUEUE_FAMILY_IGNORED); /* Output frame prep */ @@ -944,8 +943,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) /* Update weights descriptors */ ff_vk_shader_update_img_array(vkctx, exec, &s->shd_weights, in, in_views, 0, 0, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - s->sampler); + VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE); for (int i = 0; i < desc->nb_components; i++) { RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_weights, 0, 1 + i*2 + 0, 0, ws_vk, weights_offs[i], ws_size[i], @@ -957,10 +955,9 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) /* Update denoise descriptors */ ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, in, in_views, 0, 0, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - s->sampler); + VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE); ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, out, out_views, 0, 1, - VK_IMAGE_LAYOUT_GENERAL, s->sampler); + VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE); for (int i = 0; i < desc->nb_components; i++) { RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_denoise, 1, i*2 + 0, 0, ws_vk, weights_offs[i], ws_size[i], @@ -1052,7 +1049,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) { NLMeansVulkanContext *s = avctx->priv; FFVulkanContext *vkctx = &s->vkctx; - FFVulkanFunctions *vk = &vkctx->vkfn; ff_vk_exec_pool_free(vkctx, &s->e); ff_vk_shader_free(vkctx, &s->shd_weights); @@ -1061,10 +1057,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) av_buffer_pool_uninit(&s->integral_buf_pool); av_buffer_pool_uninit(&s->ws_buf_pool); - if (s->sampler) - vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler, - vkctx->hwctx->alloc); - ff_vk_uninit(&s->vkctx); av_freep(&s->xoffsets); -- 2.47.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".