History

nlmeans_vulkan: switch to imageLoad()

Lynne committed 1 year ago

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

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_nlmeans_vulkan.c+24−32
@@ -37,7 +37,6 @@ typedef struct NLMeansVulkanContext { · 36 unmodified lines
37 int initialized;37 int initialized;
38 FFVkExecPool e;38 FFVkExecPool e;
39 AVVulkanDeviceQueueFamily *qf;39 AVVulkanDeviceQueueFamily *qf;
40 VkSampler sampler;
41 40
42 AVBufferPool *integral_buf_pool;41 AVBufferPool *integral_buf_pool;
43 AVBufferPool *ws_buf_pool;42 AVBufferPool *ws_buf_pool;
@@ -66,16 +65,16 @@ typedef struct NLMeansVulkanContext { · 22 unmodified lines
66 65
67static void insert_first(FFVulkanShader *shd, int r, const char *off, int horiz, int plane, int comp)66static void insert_first(FFVulkanShader *shd, int r, const char *off, int horiz, int plane, int comp)
68{67{
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];
70 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);69 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
71 70
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];
73 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);72 ,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];
75 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);74 ,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];
77 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);76 ,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];
79 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);78 ,plane, horiz ? r : 0, horiz ? off : "0", !horiz ? r : 0, !horiz ? off : "0", comp);
80 79
81 GLSLC(4, s2 = (s1 - s2) * (s1 - s2); );80 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
164 GLSLC(0, );163 GLSLC(0, );
165 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );164 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );
166 GLSLC(0, );165 GLSLC(0, );
167 GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp);166 GLSLF(3, src[0] = imageLoad(input_img[%i], pos + offs[0])[%i]; ,plane, comp);
168 GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp);167 GLSLF(3, src[1] = imageLoad(input_img[%i], pos + offs[1])[%i]; ,plane, comp);
169 GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%i]; ,plane, comp);168 GLSLF(3, src[2] = imageLoad(input_img[%i], pos + offs[2])[%i]; ,plane, comp);
170 GLSLF(3, src[3] = texture(input_img[%i], pos + offs[3])[%i]; ,plane, comp);169 GLSLF(3, src[3] = imageLoad(input_img[%i], pos + offs[3])[%i]; ,plane, comp);
171 GLSLC(0, );170 GLSLC(0, );
172 GLSLC(3, if (lt == false) { );171 GLSLC(3, if (lt == false) { );
173 GLSLC(3, offset = int_stride * uint64_t(pos.y - p); );172 GLSLC(3, offset = int_stride * uint64_t(pos.y - p); );
@@ -210,7 +209,7 @@ typedef struct HorizontalPushData { · 36 unmodified lines
210 209
211static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,210static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,
212 FFVulkanShader *shd,211 FFVulkanShader *shd,
213 VkSampler sampler, FFVkSPIRVCompiler *spv,212 FFVkSPIRVCompiler *spv,
214 int width, int height, int t,213 int width, int height, int t,
215 const AVPixFmtDescriptor *desc,214 const AVPixFmtDescriptor *desc,
216 int planes, int *nb_rows)215 int planes, int *nb_rows)
@@ -275,11 +274,12 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 58 unmodified lines
275 desc_set = (FFVulkanDescriptorSetBinding []) {274 desc_set = (FFVulkanDescriptorSetBinding []) {
276 {275 {
277 .name = "input_img",276 .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",
279 .dimensions = 2,280 .dimensions = 2,
280 .elems = planes,281 .elems = planes,
281 .stages = VK_SHADER_STAGE_COMPUTE_BIT,282 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
282 .samplers = DUP_SAMPLER(sampler),
283 },283 },
284 {284 {
285 .name = "weights_buffer_0",285 .name = "weights_buffer_0",
@@ -418,8 +418,7 @@ typedef struct DenoisePushData { · 132 unmodified lines
418} DenoisePushData;418} DenoisePushData;
419 419
420static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,420static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *exec,
421 FFVulkanShader *shd,421 FFVulkanShader *shd, FFVkSPIRVCompiler *spv,
422 VkSampler sampler, FFVkSPIRVCompiler *spv,
423 const AVPixFmtDescriptor *desc, int planes)422 const AVPixFmtDescriptor *desc, int planes)
424{423{
425 int err;424 int err;
@@ -445,11 +444,12 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 19 unmodified lines
445 desc_set = (FFVulkanDescriptorSetBinding []) {444 desc_set = (FFVulkanDescriptorSetBinding []) {
446 {445 {
447 .name = "input_img",446 .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",
449 .dimensions = 2,450 .dimensions = 2,
450 .elems = planes,451 .elems = planes,
451 .stages = VK_SHADER_STAGE_COMPUTE_BIT,452 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
452 .samplers = DUP_SAMPLER(sampler),
453 },453 },
454 {454 {
455 .name = "output_img",455 .name = "output_img",
@@ -539,7 +539,7 @@ static av_cold int init_denoise_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 83 unmodified lines
539 GLSLC(1, if (!IS_WITHIN(pos, size)) );539 GLSLC(1, if (!IS_WITHIN(pos, size)) );
540 GLSLC(2, return; );540 GLSLC(2, return; );
541 GLSLC(0, );541 GLSLC(0, );
542 GLSLC(1, src = texture(input_img[plane], pos); );542 GLSLC(1, src = imageLoad(input_img[plane], pos); );
543 GLSLC(0, );543 GLSLC(0, );
544 for (int c = 0; c < desc->nb_components; c++) {544 for (int c = 0; c < desc->nb_components; c++) {
545 int off = desc->comp[c].offset / (FFALIGN(desc->comp[c].depth, 8)/8);545 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
660 }660 }
661 661
662 RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, 1, 0, 0, 0, NULL));662 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));
664 663
665 RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights, s->sampler,664 RET(init_weights_pipeline(vkctx, &s->e, &s->shd_weights,
666 spv, s->vkctx.output_width, s->vkctx.output_height,665 spv, s->vkctx.output_width, s->vkctx.output_height,
667 s->opts.t, desc, planes, &s->pl_weights_rows));666 s->opts.t, desc, planes, &s->pl_weights_rows));
668 667
669 RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise, s->sampler,668 RET(init_denoise_pipeline(vkctx, &s->e, &s->shd_denoise,
670 spv, desc, planes));669 spv, desc, planes));
671 670
672 RET(ff_vk_shader_update_desc_buffer(vkctx, &s->e.contexts[0], &s->shd_weights,671 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
865 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,864 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
866 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,865 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
867 VK_ACCESS_SHADER_READ_BIT,866 VK_ACCESS_SHADER_READ_BIT,
868 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,867 VK_IMAGE_LAYOUT_GENERAL,
869 VK_QUEUE_FAMILY_IGNORED);868 VK_QUEUE_FAMILY_IGNORED);
870 869
871 /* Output frame prep */870 /* Output frame prep */
@@ -944,8 +943,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 72 unmodified lines
944 943
945 /* Update weights descriptors */944 /* Update weights descriptors */
946 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_weights, in, in_views, 0, 0,945 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_weights, in, in_views, 0, 0,
947 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,946 VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
948 s->sampler);
949 for (int i = 0; i < desc->nb_components; i++) {947 for (int i = 0; i < desc->nb_components; i++) {
950 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_weights, 0, 1 + i*2 + 0, 0,948 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_weights, 0, 1 + i*2 + 0, 0,
951 ws_vk, weights_offs[i], ws_size[i],949 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
957 955
958 /* Update denoise descriptors */956 /* Update denoise descriptors */
959 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, in, in_views, 0, 0,957 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, in, in_views, 0, 0,
960 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,958 VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
961 s->sampler);
962 ff_vk_shader_update_img_array(vkctx, exec, &s->shd_denoise, out, out_views, 0, 1,959 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);
964 for (int i = 0; i < desc->nb_components; i++) {961 for (int i = 0; i < desc->nb_components; i++) {
965 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_denoise, 1, i*2 + 0, 0,962 RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd_denoise, 1, i*2 + 0, 0,
966 ws_vk, weights_offs[i], ws_size[i],963 ws_vk, weights_offs[i], ws_size[i],
@@ -1052,7 +1049,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) · 85 unmodified lines
1052{1049{
1053 NLMeansVulkanContext *s = avctx->priv;1050 NLMeansVulkanContext *s = avctx->priv;
1054 FFVulkanContext *vkctx = &s->vkctx;1051 FFVulkanContext *vkctx = &s->vkctx;
1055 FFVulkanFunctions *vk = &vkctx->vkfn;
1056 1052
1057 ff_vk_exec_pool_free(vkctx, &s->e);1053 ff_vk_exec_pool_free(vkctx, &s->e);
1058 ff_vk_shader_free(vkctx, &s->shd_weights);1054 ff_vk_shader_free(vkctx, &s->shd_weights);
@@ -1061,10 +1057,6 @@ static void nlmeans_vulkan_uninit(AVFilterContext *avctx) · 2 unmodified lines
1061 av_buffer_pool_uninit(&s->integral_buf_pool);1057 av_buffer_pool_uninit(&s->integral_buf_pool);
1062 av_buffer_pool_uninit(&s->ws_buf_pool);1058 av_buffer_pool_uninit(&s->ws_buf_pool);
1063 1059
1064 if (s->sampler)
1065 vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
1066 vkctx->hwctx->alloc);
1067
1068 ff_vk_uninit(&s->vkctx);1060 ff_vk_uninit(&s->vkctx);
1069 1061
1070 av_freep(&s->xoffsets);1062 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