History

nlmeans_vulkan: fix offsets calculation and various stride issues

We calculated offsets as pairs, but addressed them in the shader as single float values, while reading them as ivec2s. Also removes unused code (was provisionally added if cooperative matrices could be used, but that turned out to be impossible).

Lynne committed 3 years ago

Commit 99fcdee1 parent 854012e1 file · +31 −47Browse files

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

Unified · Split

libavfilter/vf_nlmeans_vulkan.c+31−47
@@ -94,7 +94,7 @@ static void insert_horizontal_pass(FFVkSPIRVShader *shd, int nb_rows, int first, · 93 unmodified lines
94 GLSLC(2, #pragma unroll(1) );94 GLSLC(2, #pragma unroll(1) );
95 GLSLF(2, for (r = 0; r < %i; r++) { ,nb_rows);95 GLSLF(2, for (r = 0; r < %i; r++) { ,nb_rows);
96 GLSLC(3, prefix_sum = DTYPE(0); );96 GLSLC(3, prefix_sum = DTYPE(0); );
97 GLSLC(3, offset = uint64_t(int_stride)*(pos.y + r)*T_ALIGN; );97 GLSLC(3, offset = int_stride * uint64_t(pos.y + r); );
98 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );98 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
99 GLSLC(0, );99 GLSLC(0, );
100 GLSLF(3, for (pos.x = 0; pos.x < width[%i]; pos.x++) { ,plane);100 GLSLF(3, for (pos.x = 0; pos.x < width[%i]; pos.x++) { ,plane);
@@ -122,7 +122,7 @@ static void insert_vertical_pass(FFVkSPIRVShader *shd, int nb_rows, int first, i · 21 unmodified lines
122 GLSLC(0, );122 GLSLC(0, );
123 GLSLF(1, if (pos.x < width[%i]) { ,plane);123 GLSLF(1, if (pos.x < width[%i]) { ,plane);
124 GLSLF(2, for (pos.y = 0; pos.y < height[%i]; pos.y++) { ,plane);124 GLSLF(2, for (pos.y = 0; pos.y < height[%i]; pos.y++) { ,plane);
125 GLSLC(3, offset = uint64_t(int_stride)*pos.y*T_ALIGN; );125 GLSLC(3, offset = int_stride * uint64_t(pos.y); );
126 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );126 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
127 GLSLC(0, );127 GLSLC(0, );
128 GLSLC(3, #pragma unroll(1) );128 GLSLC(3, #pragma unroll(1) );
@@ -167,40 +167,26 @@ static void insert_weights_pass(FFVkSPIRVShader *shd, int nb_rows, int vert, · 38 unmodified lines
167 GLSLC(0, );167 GLSLC(0, );
168 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );168 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );
169 GLSLC(0, );169 GLSLC(0, );
170 if (TYPE_ELEMS == 4) {170 GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp);
171 GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp);171 GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp);
172 GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp);172 GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%i]; ,plane, comp);
173 GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%i]; ,plane, comp);173 GLSLF(3, src[3] = texture(input_img[%i], pos + offs[3])[%i]; ,plane, comp);
174 GLSLF(3, src[3] = texture(input_img[%i], pos + offs[3])[%i]; ,plane, comp);
175 } else {
176 for (int i = 0; i < 16; i++)
177 GLSLF(3, src[%i][%i] = texture(input_img[%i], pos + offs[%i])[%i];
178 ,i / 4, i % 4, plane, i, comp);
179
180 }
181 GLSLC(0, );174 GLSLC(0, );
182 GLSLC(3, if (lt == false) { );175 GLSLC(3, if (lt == false) { );
183 GLSLC(4, a = integral_data.v[(pos.y - p)*int_stride + pos.x - p]; );176 GLSLC(3, offset = int_stride * uint64_t(pos.y - p); );
184 GLSLC(4, c = integral_data.v[(pos.y - p)*int_stride + pos.x + p]; );177 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
185 GLSLC(4, b = integral_data.v[(pos.y + p)*int_stride + pos.x - p]; );178 GLSLC(4, a = dst.v[pos.x - p]; );
186 GLSLC(4, d = integral_data.v[(pos.y + p)*int_stride + pos.x + p]; );179 GLSLC(4, c = dst.v[pos.x + p]; );
180 GLSLC(3, offset = int_stride * uint64_t(pos.y + p); );
181 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
182 GLSLC(4, b = dst.v[pos.x - p]; );
183 GLSLC(4, d = dst.v[pos.x + p]; );
187 GLSLC(3, } );184 GLSLC(3, } );
188 GLSLC(0, );185 GLSLC(0, );
189 GLSLC(3, patch_diff = d + a - b - c; );186 GLSLC(3, patch_diff = d + a - b - c; );
190 if (TYPE_ELEMS == 4) {187 GLSLF(3, w = exp(patch_diff * strength[%i]); ,dst_comp);
191 GLSLF(3, w = exp(patch_diff * strength[%i]); ,dst_comp);188 GLSLC(3, w_sum = w[0] + w[1] + w[2] + w[3]; );
192 GLSLC(3, w_sum = w[0] + w[1] + w[2] + w[3]; );189 GLSLC(3, sum = dot(w, src*255); );
193 GLSLC(3, sum = dot(w, src*255); );
194 } else {
195 for (int i = 0; i < 4; i++)
196 GLSLF(3, w[%i] = exp(patch_diff[%i] * strength[%i]); ,i,i,dst_comp);
197 for (int i = 0; i < 4; i++)
198 GLSLF(3, w_sum %s w[%i][0] + w[%i][1] + w[%i][2] + w[%i][3];
199 ,!i ? "=" : "+=", i, i, i, i);
200 for (int i = 0; i < 4; i++)
201 GLSLF(3, sum %s dot(w[%i], src[%i]*255);
202 ,!i ? "=" : "+=", i, i);
203 }
204 GLSLC(0, );190 GLSLC(0, );
205 if (t > 1) {191 if (t > 1) {
206 GLSLF(3, atomicAdd(weights_%i[pos.y*ws_stride[%i] + pos.x], w_sum); ,dst_comp, dst_comp);192 GLSLF(3, atomicAdd(weights_%i[pos.y*ws_stride[%i] + pos.x], w_sum); ,dst_comp, dst_comp);
@@ -220,8 +206,8 @@ typedef struct HorizontalPushData { · 13 unmodified lines
220 int32_t patch_size[4];206 int32_t patch_size[4];
221 float strength[4];207 float strength[4];
222 VkDeviceAddress integral_base;208 VkDeviceAddress integral_base;
223 uint32_t integral_size;209 uint64_t integral_size;
224 uint32_t int_stride;210 uint64_t int_stride;
225 uint32_t xyoffs_start;211 uint32_t xyoffs_start;
226} HorizontalPushData;212} HorizontalPushData;
227 213
@@ -275,8 +261,8 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 47 unmodified lines
275 GLSLC(1, ivec4 patch_size; );261 GLSLC(1, ivec4 patch_size; );
276 GLSLC(1, vec4 strength; );262 GLSLC(1, vec4 strength; );
277 GLSLC(1, DataBuffer integral_base; );263 GLSLC(1, DataBuffer integral_base; );
278 GLSLC(1, uint integral_size; );264 GLSLC(1, uint64_t integral_size; );
279 GLSLC(1, uint int_stride; );265 GLSLC(1, uint64_t int_stride; );
280 GLSLC(1, uint xyoffs_start; );266 GLSLC(1, uint xyoffs_start; );
281 GLSLC(0, }; );267 GLSLC(0, }; );
282 GLSLC(0, );268 GLSLC(0, );
@@ -371,13 +357,11 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 88 unmodified lines
371 GLSLF(1, ivec2 offs[%i]; ,TYPE_ELEMS);357 GLSLF(1, ivec2 offs[%i]; ,TYPE_ELEMS);
372 GLSLC(0, );358 GLSLC(0, );
373 GLSLC(1, int invoc_idx = int(gl_WorkGroupID.z); );359 GLSLC(1, int invoc_idx = int(gl_WorkGroupID.z); );
374 360 GLSLC(0, );
375 GLSLC(1, offset = uint64_t(integral_size)*invoc_idx; );361 GLSLC(1, offset = integral_size * invoc_idx; );
376 GLSLC(1, dst = DataBuffer(uint64_t(integral_data) + offset); );
377
378 GLSLC(1, integral_data = DataBuffer(uint64_t(integral_base) + offset); );362 GLSLC(1, integral_data = DataBuffer(uint64_t(integral_base) + offset); );
379 for (int i = 0; i < TYPE_ELEMS*2; i += 2)363 for (int i = 0; i < TYPE_ELEMS; i++)
380 GLSLF(1, offs[%i] = xyoffsets[xyoffs_start + 2*%i*invoc_idx + %i]; ,i/2,TYPE_ELEMS,i);364 GLSLF(1, offs[%i] = xyoffsets[xyoffs_start + %i*invoc_idx + %i]; ,i,TYPE_ELEMS,i);
381 GLSLC(0, );365 GLSLC(0, );
382 GLSLC(1, DTYPE a; );366 GLSLC(1, DTYPE a; );
383 GLSLC(1, DTYPE b; );367 GLSLC(1, DTYPE b; );
@@ -759,7 +743,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 375 unmodified lines
759 /* Integral */743 /* Integral */
760 AVBufferRef *integral_buf = NULL;744 AVBufferRef *integral_buf = NULL;
761 FFVkBuffer *integral_vk;745 FFVkBuffer *integral_vk;
762 uint32_t int_stride;746 size_t int_stride;
763 size_t int_size;747 size_t int_size;
764 748
765 /* Weights/sums */749 /* Weights/sums */
@@ -787,8 +771,8 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 21 unmodified lines
787 return AVERROR(EINVAL);771 return AVERROR(EINVAL);
788 772
789 /* Integral image */773 /* Integral image */
790 int_stride = s->pl_weights.wg_size[0]*s->pl_weights_rows;774 int_stride = s->pl_weights.wg_size[0]*s->pl_weights_rows*TYPE_SIZE;
791 int_size = int_stride * int_stride * TYPE_SIZE;775 int_size = s->pl_weights.wg_size[0]*s->pl_weights_rows*int_stride;
792 776
793 /* Plane dimensions */777 /* Plane dimensions */
794 for (int i = 0; i < desc->nb_components; i++) {778 for (int i = 0; i < desc->nb_components; i++) {
@@ -982,9 +966,9 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 187 unmodified lines
982 { s->patch[0], s->patch[1], s->patch[2], s->patch[3] },966 { s->patch[0], s->patch[1], s->patch[2], s->patch[3] },
983 { s->strength[0], s->strength[1], s->strength[2], s->strength[2], },967 { s->strength[0], s->strength[1], s->strength[2], s->strength[2], },
984 integral_vk->address,968 integral_vk->address,
985 int_size,969 (uint64_t)int_size,
986 int_stride,970 (uint64_t)int_stride,
987 offsets_dispatched * 2,971 offsets_dispatched,
988 };972 };
989 973
990 if (offsets_dispatched) {974 if (offsets_dispatched) {

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