History

nlmeans_vulkan: switch to imageLoad()

Lynne committed 1 year ago

Commit a5356391 parent 9c4a26d1 file · +24 −32Browse files

Unified · Split

libavfilter/vf_nlmeans_vulkan.c+24−32
@@ -37,7 +37,6 @@ typedef struct NLMeansVulkanContext { · 36 unmodified lines
3737 int initialized;
3838 FFVkExecPool e;
3939 AVVulkanDeviceQueueFamily *qf;
40− VkSampler sampler;
4140
4241 AVBufferPool *integral_buf_pool;
4342 AVBufferPool *ws_buf_pool;
@@ -66,16 +65,16 @@ typedef struct NLMeansVulkanContext { · 22 unmodified lines
6665
6766 static void insert_first(FFVulkanShader *shd, int r, const char *off, int horiz, int plane, int comp)
6867 {
69− GLSLF(4, s1 = texture(input_img[%i], pos + ivec2(%i + %s, %i + %s))[%i];
68+ GLSLF(4, s1 = imageLoad(input_img[%i], pos + ivec2(%i + %s, %i + %s))[%i];
7069 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
7170
72− GLSLF(4, s2[0] = texture(input_img[%i], pos + offs[0] + ivec2(%i + %s, %i + %s))[%i];
71+ GLSLF(4, s2[0] = imageLoad(input_img[%i], pos + offs[0] + ivec2(%i + %s, %i + %s))[%i];
7372 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
74− GLSLF(4, s2[1] = texture(input_img[%i], pos + offs[1] + ivec2(%i + %s, %i + %s))[%i];
73+ GLSLF(4, s2[1] = imageLoad(input_img[%i], pos + offs[1] + ivec2(%i + %s, %i + %s))[%i];
7574 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
76− GLSLF(4, s2[2] = texture(input_img[%i], pos + offs[2] + ivec2(%i + %s, %i + %s))[%i];
75+ GLSLF(4, s2[2] = imageLoad(input_img[%i], pos + offs[2] + ivec2(%i + %s, %i + %s))[%i];
7776 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
78− GLSLF(4, s2[3] = texture(input_img[%i], pos + offs[3] + ivec2(%i + %s, %i + %s))[%i];
77+ GLSLF(4, s2[3] = imageLoad(input_img[%i], pos + offs[3] + ivec2(%i + %s, %i + %s))[%i];
7978 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
8079
8180 GLSLC(4, s2 = (s1 - s2) * (s1 - s2); );
@@ -164,10 +163,10 @@ static void insert_weights_pass(FFVulkanShader *shd, int nb_rows, int vert, · 82 unmodified lines
164163 GLSLC(0, );
165164 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );
166165 GLSLC(0, );
167− GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp);
168− GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp);
169− GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%i]; ,plane, comp);
170− GLSLF(3, src[3] = texture(input_img[%i], pos + offs[3])[%i]; ,plane, comp);
166+ GLSLF(3, src[0] = imageLoad(input_img[%i], pos + offs[0])[%i]; ,plane, comp);
167+ GLSLF(3, src[1] = imageLoad(input_img[%i], pos + offs[1])[%i]; ,plane, comp);
168+ GLSLF(3, src[2] = imageLoad(input_img[%i], pos + offs[2])[%i]; ,plane, comp);
169+ GLSLF(3, src[3] = imageLoad(input_img[%i], pos + offs[3])[%i]; ,plane, comp);
171170 GLSLC(0, );
172171 GLSLC(3, if (lt == false) { );
173172 GLSLC(3, offset = int_stride * uint64_t(pos.y - p); );
@@ -210,7 +209,7 @@ typedef struct HorizontalPushData { · 36 unmodified lines
210209
211210 static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,
212211 FFVulkanShader *shd,
213− VkSampler sampler, FFVkSPIRVCompiler *spv,
212+ FFVkSPIRVCompiler *spv,
214213 int width, int height, int t,
215214 const AVPixFmtDescriptor *desc,
216215 int planes, int *nb_rows)
@@ -275,11 +274,12 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 58 unmodified lines
275274 desc_set = (FFVulkanDescriptorSetBinding []) {
276275 {
277276 .name = "input_img",
278− .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
277+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
278+ .mem_layout = ff_vk_shader_rep_fmt(vkctx->input_format, FF_VK_REP_FLOAT),
279+ .mem_quali = "readonly",
279280 .dimensions = 2,
280281 .elems = planes,
281282 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
282− .samplers = DUP_SAMPLER(sampler),
283283 },
284284 {
285285 .name = "weights_buffer_0",
@@ -418,8 +418,7 @@ typedef struct DenoisePushData { · 132 unmodified lines
418418 } DenoisePushData;
419419
420420 static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,
421− FFVulkanShader *shd,
422− VkSampler sampler, FFVkSPIRVCompiler *spv,
421+ FFVulkanShader *shd, FFVkSPIRVCompiler *spv,
423422 const AVPixFmtDescriptor *desc, int planes)
424423 {
425424 int err;
@@ -445,11 +444,12 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 19 unmodified lines
445444 desc_set = (FFVulkanDescriptorSetBinding []) {
446445 {
447446 .name = "input_img",
448− .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
447+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
448+ .mem_layout = ff_vk_shader_rep_fmt(vkctx->input_format, FF_VK_REP_FLOAT),
449+ .mem_quali = "readonly",
449450 .dimensions = 2,
450451 .elems = planes,
451452 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
452− .samplers = DUP_SAMPLER(sampler),
453453 },
454454 {
455455 .name = "output_img",
@@ -539,7 +539,7 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 83 unmodified lines
539539 GLSLC(1, if (!IS_WITHIN(pos, size)) );
540540 GLSLC(2, return; );
541541 GLSLC(0, );
542− GLSLC(1, src = texture(input_img[plane], pos); );
542+ GLSLC(1, src = imageLoad(input_img[plane], pos); );
543543 GLSLC(0, );
544544 for (int c = 0; c < desc->nb_components; c++) {
545545 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) · 114 unmodified lines
660660 }
661661
662662 RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, 1, 0, 0, 0, NULL));
663− RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_NEAREST));
664663
665− RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights, s->sampler,
664+ RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights,
666665 spv, s->vkctx.output_width, s->vkctx.output_height,
667666 s->opts.t, desc, planes, &s->pl_weights_rows));
668667
669− RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise, s->sampler,
668+ RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise,
670669 spv, desc, planes));
671670
672671 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) · 192 unmodified lines
865864 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
866865 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
867866 VK_ACCESS_SHADER_READ_BIT,
868− VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
867+ VK_IMAGE_LAYOUT_GENERAL,
869868 VK_QUEUE_FAMILY_IGNORED);
870869
871870 /* Output frame prep */
@@ -944,8 +943,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 72 unmodified lines
944943
945944 /* Update weights descriptors */
946945 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_weights, in, in_views, 0, 0,
947− VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
948− s->sampler);
946+ VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
949947 for (int i = 0; i < desc->nb_components; i++) {
950948 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_weights, 0, 1 + i*2 + 0, 0,
951949 ws_vk, weights_offs[i], ws_size[i],
@@ -957,10 +955,9 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 5 unmodified lines
957955
958956 /* Update denoise descriptors */
959957 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, in, in_views, 0, 0,
960− VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
961− s->sampler);
958+ VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
962959 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, out, out_views, 0, 1,
963− VK_IMAGE_LAYOUT_GENERAL, s->sampler);
960+ VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
964961 for (int i = 0; i < desc->nb_components; i++) {
965962 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_denoise, 1, i*2 + 0, 0,
966963 ws_vk, weights_offs[i], ws_size[i],
@@ -1052,7 +1049,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) · 85 unmodified lines
10521049 {
10531050 NLMeansVulkanContext *s = avctx->priv;
10541051 FFVulkanContext *vkctx = &s->vkctx;
1055− FFVulkanFunctions *vk = &vkctx->vkfn;
10561052
10571053 ff_vk_exec_pool_free(vkctx, &s->e);
10581054 ff_vk_shader_free(vkctx, &s->shd_weights);
@@ -1061,10 +1057,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) · 2 unmodified lines
10611057 av_buffer_pool_uninit(&s->integral_buf_pool);
10621058 av_buffer_pool_uninit(&s->ws_buf_pool);
10631059
1064− if (s->sampler)
1065− vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
1066− vkctx->hwctx->alloc);
1067−
10681060 ff_vk_uninit(&s->vkctx);
10691061
10701062 av_freep(&s->xoffsets);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t