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

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
9494 GLSLC(2, #pragma unroll(1) );
9595 GLSLF(2, for (r = 0; r < %i; r++) { ,nb_rows);
9696 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); );
9898 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
9999 GLSLC(0, );
100100 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
122122 GLSLC(0, );
123123 GLSLF(1, if (pos.x < width[%i]) { ,plane);
124124 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); );
126126 GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
127127 GLSLC(0, );
128128 GLSLC(3, #pragma unroll(1) );
@@ -167,40 +167,26 @@ static void insert_weights_pass(FFVkSPIRVShader *shd, int nb_rows, int vert, · 38 unmodified lines
167167 GLSLC(0, );
168168 GLSLC(3, lt = ((pos.x - p) < 0) || ((pos.y - p) < 0); );
169169 GLSLC(0, );
170− if (TYPE_ELEMS == 4) {
171− GLSLF(3, src[0] = texture(input_img[%i], pos + offs[0])[%i]; ,plane, comp);
172− GLSLF(3, src[1] = texture(input_img[%i], pos + offs[1])[%i]; ,plane, comp);
173− GLSLF(3, src[2] = texture(input_img[%i], pos + offs[2])[%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− }
170+ 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[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);
181174 GLSLC(0, );
182175 GLSLC(3, if (lt == false) { );
183− GLSLC(4, a = integral_data.v[(pos.y - p)*int_stride + pos.x - p]; );
184− GLSLC(4, c = integral_data.v[(pos.y - p)*int_stride + pos.x + p]; );
185− GLSLC(4, b = integral_data.v[(pos.y + p)*int_stride + pos.x - p]; );
186− GLSLC(4, d = integral_data.v[(pos.y + p)*int_stride + pos.x + p]; );
176+ GLSLC(3, offset = int_stride * uint64_t(pos.y - p); );
177+ GLSLC(3, dst = DataBuffer(uint64_t(integral_data) + offset); );
178+ GLSLC(4, a = dst.v[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]; );
187184 GLSLC(3, } );
188185 GLSLC(0, );
189186 GLSLC(3, patch_diff = d + a - b - c; );
190− if (TYPE_ELEMS == 4) {
191− GLSLF(3, w = exp(patch_diff * strength[%i]); ,dst_comp);
192− GLSLC(3, w_sum = w[0] + w[1] + w[2] + w[3]; );
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− }
187+ GLSLF(3, w = exp(patch_diff * strength[%i]); ,dst_comp);
188+ GLSLC(3, w_sum = w[0] + w[1] + w[2] + w[3]; );
189+ GLSLC(3, sum = dot(w, src*255); );
204190 GLSLC(0, );
205191 if (t > 1) {
206192 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
220206 int32_t patch_size[4];
221207 float strength[4];
222208 VkDeviceAddress integral_base;
223− uint32_t integral_size;
224− uint32_t int_stride;
209+ uint64_t integral_size;
210+ uint64_t int_stride;
225211 uint32_t xyoffs_start;
226212 } HorizontalPushData;
227213
@@ -275,8 +261,8 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 47 unmodified lines
275261 GLSLC(1, ivec4 patch_size; );
276262 GLSLC(1, vec4 strength; );
277263 GLSLC(1, DataBuffer integral_base; );
278− GLSLC(1, uint integral_size; );
279− GLSLC(1, uint int_stride; );
264+ GLSLC(1, uint64_t integral_size; );
265+ GLSLC(1, uint64_t int_stride; );
280266 GLSLC(1, uint xyoffs_start; );
281267 GLSLC(0, }; );
282268 GLSLC(0, );
@@ -371,13 +357,11 @@ static av_cold int init_weights_pipeline(FFVulkanContext *vkctx, FFVkExecPool *e · 88 unmodified lines
371357 GLSLF(1, ivec2 offs[%i]; ,TYPE_ELEMS);
372358 GLSLC(0, );
373359 GLSLC(1, int invoc_idx = int(gl_WorkGroupID.z); );
374−
375− GLSLC(1, offset = uint64_t(integral_size)*invoc_idx; );
376− GLSLC(1, dst = DataBuffer(uint64_t(integral_data) + offset); );
377−
360+ GLSLC(0, );
361+ GLSLC(1, offset = integral_size * invoc_idx; );
378362 GLSLC(1, integral_data = DataBuffer(uint64_t(integral_base) + offset); );
379− for (int i = 0; i < TYPE_ELEMS*2; i += 2)
380− GLSLF(1, offs[%i] = xyoffsets[xyoffs_start + 2*%i*invoc_idx + %i]; ,i/2,TYPE_ELEMS,i);
363+ for (int i = 0; i < TYPE_ELEMS; i++)
364+ GLSLF(1, offs[%i] = xyoffsets[xyoffs_start + %i*invoc_idx + %i]; ,i,TYPE_ELEMS,i);
381365 GLSLC(0, );
382366 GLSLC(1, DTYPE a; );
383367 GLSLC(1, DTYPE b; );
@@ -759,7 +743,7 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 375 unmodified lines
759743 /* Integral */
760744 AVBufferRef *integral_buf = NULL;
761745 FFVkBuffer *integral_vk;
762− uint32_t int_stride;
746+ size_t int_stride;
763747 size_t int_size;
764748
765749 /* Weights/sums */
@@ -787,8 +771,8 @@ static int nlmeans_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 21 unmodified lines
787771 return AVERROR(EINVAL);
788772
789773 /* Integral image */
790− int_stride = s->pl_weights.wg_size[0]*s->pl_weights_rows;
791− int_size = int_stride * int_stride * TYPE_SIZE;
774+ int_stride = s->pl_weights.wg_size[0]*s->pl_weights_rows*TYPE_SIZE;
775+ int_size = s->pl_weights.wg_size[0]*s->pl_weights_rows*int_stride;
792776
793777 /* Plane dimensions */
794778 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
982966 { s->patch[0], s->patch[1], s->patch[2], s->patch[3] },
983967 { s->strength[0], s->strength[1], s->strength[2], s->strength[2], },
984968 integral_vk->address,
985− int_size,
986− int_stride,
987− offsets_dispatched * 2,
969+ (uint64_t)int_size,
970+ (uint64_t)int_stride,
971+ offsets_dispatched,
988972 };
989973
990974 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