~wsnipex/+junk/trunk

« back to all changes in this revision

Viewing changes to debian/patches/motion_adaptive_deinterlacer.patch

  • Committer: wsnipex
  • Date: 2013-11-08 13:15:39 UTC
  • Revision ID: wsnipex@a1.net-20131108131539-07sptp1inbwvas8q
update motion_adaptive_deinterlacer to v8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From b6a837d608775fd8609b463a332c1643df763756 Mon Sep 17 00:00:00 2001
 
1
From 08155442aba570a9d2d351795c86fdea466d806d Mon Sep 17 00:00:00 2001
2
2
From: Grigori Goronzy <greg@chown.ath.cx>
3
3
Date: Sat, 2 Nov 2013 21:54:01 +0100
4
4
Subject: [PATCH] WIP: st/vl, st/vdpau: motion adaptive deinterlacer
10
10
v5: cleanup, move dest surface handling into filter
11
11
v6: implement skip_chroma
12
12
v7: tweak motion detection, further cleanup
 
13
v8: fix tgsi code, unbreaks with llvm
13
14
---
14
15
 src/gallium/auxiliary/Makefile.sources           |   3 +-
15
 
 src/gallium/auxiliary/vl/vl_deint_filter.c       | 477 +++++++++++++++++++++++
 
16
 src/gallium/auxiliary/vl/vl_deint_filter.c       | 494 +++++++++++++++++++++++
16
17
 src/gallium/auxiliary/vl/vl_deint_filter.h       |  78 ++++
17
18
 src/gallium/state_trackers/vdpau/mixer.c         |  69 +++-
18
19
 src/gallium/state_trackers/vdpau/query.c         |   1 +
19
20
 src/gallium/state_trackers/vdpau/vdpau_private.h |   7 +
20
 
 6 files changed, 630 insertions(+), 5 deletions(-)
 
21
 6 files changed, 647 insertions(+), 5 deletions(-)
21
22
 create mode 100644 src/gallium/auxiliary/vl/vl_deint_filter.c
22
23
 create mode 100644 src/gallium/auxiliary/vl/vl_deint_filter.h
23
24
 
37
38
        indices/u_indices_gen.c \
38
39
diff --git a/src/gallium/auxiliary/vl/vl_deint_filter.c b/src/gallium/auxiliary/vl/vl_deint_filter.c
39
40
new file mode 100644
40
 
index 0000000..79b87e5
 
41
index 0000000..3b3cc6d
41
42
--- /dev/null
42
43
+++ b/src/gallium/auxiliary/vl/vl_deint_filter.c
43
 
@@ -0,0 +1,477 @@
 
44
@@ -0,0 +1,494 @@
44
45
+/**************************************************************************
45
46
+ *
46
47
+ * Copyright 2013 Grigori Goronzy <greg@chown.ath.cx>.
144
145
+   sampler = ureg_DECL_sampler(shader, 2);
145
146
+   o_fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
146
147
+
 
148
+   ureg_MOV(shader, t_tex, i_vtex);
147
149
+   if (field) {
148
 
+      ureg_ADD(shader, ureg_writemask(ureg_dst(i_vtex), TGSI_WRITEMASK_Z),
149
 
+               i_vtex, ureg_imm1f(shader, 1.0f));
 
150
+      ureg_MOV(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_ZW),
 
151
+               ureg_imm4f(shader, 0, 0, 1.0f, 0));
 
152
+   } else {
 
153
+      ureg_MOV(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_ZW),
 
154
+               ureg_imm1f(shader, 0));
150
155
+   }
151
156
+
152
 
+   ureg_TEX(shader, o_fragment, TGSI_TEXTURE_2D_ARRAY, i_vtex, sampler);
 
157
+   ureg_TEX(shader, o_fragment, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_tex), sampler);
153
158
+
154
159
+   ureg_release_temporary(shader, t_tex);
155
160
+   ureg_END(shader);
168
173
+   struct ureg_src sampler_prev;
169
174
+   struct ureg_src sampler_next;
170
175
+   struct ureg_dst o_fragment;
 
176
+   struct ureg_dst t_tex;
171
177
+   struct ureg_dst t_comp_top, t_comp_bot;
172
178
+   struct ureg_dst t_diff;
173
179
+   struct ureg_dst t_a, t_b;
178
184
+      return NULL;
179
185
+   }
180
186
+
 
187
+   t_tex = ureg_DECL_temporary(shader);
181
188
+   t_comp_top = ureg_DECL_temporary(shader);
182
189
+   t_comp_bot = ureg_DECL_temporary(shader);
183
190
+   t_diff = ureg_DECL_temporary(shader);
193
200
+   sampler_next = ureg_DECL_sampler(shader, 3);
194
201
+   o_fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0);
195
202
+
 
203
+   // we don't care about ZW interpolation (allows better optimization)
 
204
+   ureg_MOV(shader, t_tex, i_vtex);
 
205
+   ureg_MOV(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_ZW),
 
206
+            ureg_imm1f(shader, 0));
 
207
+
196
208
+   // sample between texels for cheap lowpass
197
 
+   ureg_ADD(shader, t_comp_top, i_vtex,
 
209
+   ureg_ADD(shader, t_comp_top, ureg_src(t_tex),
198
210
+            ureg_imm4f(shader, sizes->x * 0.5f, sizes->y * -0.5f, 0, 0));
199
 
+   ureg_ADD(shader, t_comp_bot, i_vtex,
 
211
+   ureg_ADD(shader, t_comp_bot, ureg_src(t_tex),
200
212
+            ureg_imm4f(shader, sizes->x * -0.5f, sizes->y * 0.5f, 1.0f, 0));
201
213
+
202
214
+   if (field == 0) {
223
235
+
224
236
+   // absolute maximum of differences
225
237
+   ureg_MAX(shader, ureg_writemask(t_diff, TGSI_WRITEMASK_X), ureg_abs(ureg_src(t_diff)),
226
 
+         ureg_swizzle(ureg_abs(ureg_src(t_diff)),
227
 
+                      TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Y, TGSI_SWIZZLE_Y));
 
238
+            ureg_scalar(ureg_abs(ureg_src(t_diff)), TGSI_SWIZZLE_Y));
228
239
+
229
240
+   if (field == 0) {
230
241
+      /* weave with prev top field */
231
 
+      ureg_ADD(shader, t_comp_top, i_vtex, ureg_imm4f(shader, 0, 0, 0, 0));
232
 
+      ureg_TEX(shader, t_weave, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_comp_top), sampler_prev);
 
242
+      ureg_TEX(shader, t_weave, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_tex), sampler_prev);
233
243
+      /* get linear interpolation from current bottom field */
234
 
+      ureg_ADD(shader, t_comp_top, i_vtex, ureg_imm4f(shader, 0, sizes->y * -1.0f, 1.0f, 0));
 
244
+      ureg_ADD(shader, t_comp_top, ureg_src(t_tex), ureg_imm4f(shader, 0, sizes->y * -1.0f, 1.0f, 0));
235
245
+      ureg_TEX(shader, t_linear, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_comp_top), sampler_cur);
236
246
+   } else {
237
247
+      /* weave with prev bottom field */
238
 
+      ureg_ADD(shader, t_comp_bot, i_vtex, ureg_imm4f(shader, 0, 0, 1.0f, 0));
 
248
+      ureg_ADD(shader, t_comp_bot, ureg_src(t_tex), ureg_imm4f(shader, 0, 0, 1.0f, 0));
239
249
+      ureg_TEX(shader, t_weave, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_comp_bot), sampler_prev);
240
250
+      /* get linear interpolation from current top field */
241
 
+      ureg_ADD(shader, t_comp_bot, i_vtex, ureg_imm4f(shader, 0, sizes->y * 1.0f, 0, 0));
 
251
+      ureg_ADD(shader, t_comp_bot, ureg_src(t_tex), ureg_imm4f(shader, 0, sizes->y * 1.0f, 0, 0));
242
252
+      ureg_TEX(shader, t_linear, TGSI_TEXTURE_2D_ARRAY, ureg_src(t_comp_bot), sampler_cur);
243
253
+   }
244
254
+
245
255
+   // mix between weave and linear
246
 
+   // fully weave if diff < 7 (0.02745), fully linear if diff > 15 (0.05882)
 
256
+   // fully weave if diff < 6 (0.02353), fully interpolate if diff > 14 (0.05490)
247
257
+   ureg_ADD(shader, ureg_writemask(t_diff, TGSI_WRITEMASK_X), ureg_src(t_diff),
248
 
+            ureg_imm4f(shader, -0.02745f, 0, 0, 0));
 
258
+            ureg_imm4f(shader, -0.02353f, 0, 0, 0));
249
259
+   ureg_MUL(shader, ureg_saturate(ureg_writemask(t_diff, TGSI_WRITEMASK_X)),
250
 
+            ureg_src(t_diff), ureg_imm4f(shader, 31.8775f, 0, 0, 0));
 
260
+            ureg_src(t_diff), ureg_imm4f(shader, 31.8750f, 0, 0, 0));
251
261
+   ureg_LRP(shader, ureg_writemask(o_fragment, TGSI_WRITEMASK_X), ureg_src(t_diff),
252
262
+            ureg_src(t_linear), ureg_src(t_weave));
253
263
+
 
264
+   ureg_release_temporary(shader, t_tex);
254
265
+   ureg_release_temporary(shader, t_comp_top);
255
266
+   ureg_release_temporary(shader, t_comp_bot);
256
267
+   ureg_release_temporary(shader, t_diff);
304
315
+      goto error_rs_state;
305
316
+
306
317
+   memset(&blend, 0, sizeof blend);
307
 
+   blend.rt[0].rgb_func = PIPE_BLEND_ADD;
308
 
+   blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
309
 
+   blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
310
 
+   blend.rt[0].alpha_func = PIPE_BLEND_ADD;
311
 
+   blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
312
 
+   blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
313
 
+   blend.logicop_func = PIPE_LOGICOP_CLEAR;
314
318
+   blend.rt[0].colormask = PIPE_MASK_RGBA;
315
319
+   filter->blend = pipe->create_blend_state(pipe, &blend);
316
320
+   if (!filter->blend)
323
327
+   sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
324
328
+   sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
325
329
+   sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
326
 
+   sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
327
 
+   sampler.compare_func = PIPE_FUNC_ALWAYS;
328
330
+   sampler.normalized_coords = 1;
329
331
+   filter->sampler[0] = pipe->create_sampler_state(pipe, &sampler);
330
332
+   filter->sampler[1] = filter->sampler[2] = filter->sampler[3] = filter->sampler[0];
352
354
+      goto error_vs;
353
355
+
354
356
+   filter->fs_copy_top = create_copy_frag_shader(filter, 0);
 
357
+   if (!filter->fs_copy_top)
 
358
+      goto error_fs_copy_top;
 
359
+
355
360
+   filter->fs_copy_bottom = create_copy_frag_shader(filter, 1);
 
361
+   if (!filter->fs_copy_bottom)
 
362
+      goto error_fs_copy_bottom;
 
363
+
356
364
+   filter->fs_deint_top = create_deint_frag_shader(filter, 0, &sizes, spatial_filter);
 
365
+   if (!filter->fs_deint_top)
 
366
+      goto error_fs_deint_top;
 
367
+
357
368
+   filter->fs_deint_bottom = create_deint_frag_shader(filter, 1, &sizes, spatial_filter);
358
 
+   if (!filter->fs_copy_top || !filter->fs_copy_bottom ||
359
 
+       !filter->fs_deint_top || !filter->fs_deint_bottom)
360
 
+      goto error_fs;
 
369
+   if (!filter->fs_deint_bottom)
 
370
+      goto error_fs_deint_bottom;
361
371
+
362
372
+   return true;
363
373
+
364
 
+error_fs:
 
374
+error_fs_deint_bottom:
 
375
+   pipe->delete_fs_state(pipe, filter->fs_deint_top);
 
376
+
 
377
+error_fs_deint_top:
 
378
+   pipe->delete_fs_state(pipe, filter->fs_copy_bottom);
 
379
+
 
380
+error_fs_copy_bottom:
 
381
+   pipe->delete_fs_state(pipe, filter->fs_copy_top);
 
382
+
 
383
+error_fs_copy_top:
365
384
+   pipe->delete_vs_state(pipe, filter->vs);
366
385
+
367
386
+error_vs:
452
471
+   /* set up destination and source */
453
472
+   dst_surfaces = filter->video_buffer->get_surfaces(filter->video_buffer);
454
473
+   cur_sv = cur->get_sampler_view_components(cur);
455
 
+   prevprev_sv = prev->get_sampler_view_components(prevprev);
 
474
+   prevprev_sv = prevprev->get_sampler_view_components(prevprev);
456
475
+   prev_sv = prev->get_sampler_view_components(prev);
457
476
+   next_sv = next->get_sampler_view_components(next);
458
477
+
459
 
+   /* set up general state */
 
478
+   /* set up pipe state */
460
479
+   filter->pipe->bind_rasterizer_state(filter->pipe, filter->rs_state);
461
480
+   filter->pipe->bind_blend_state(filter->pipe, filter->blend);
462
481
+   filter->pipe->set_vertex_buffers(filter->pipe, 0, 1, &filter->quad);
463
482
+   filter->pipe->bind_vertex_elements_state(filter->pipe, filter->ves);
464
483
+   filter->pipe->bind_vs_state(filter->pipe, filter->vs);
 
484
+   filter->pipe->bind_sampler_states(filter->pipe, PIPE_SHADER_FRAGMENT,
 
485
+                                     0, 4, filter->sampler);
465
486
+
466
 
+   /* set up viewport */
 
487
+   /* prepare viewport */
467
488
+   memset(&viewport, 0, sizeof(viewport));
468
489
+   viewport.scale[2] = 1;
469
490
+   viewport.scale[3] = 1;
470
491
+
471
 
+   /* set up framebuffer */
 
492
+   /* prepare framebuffer */
472
493
+   memset(&fb_state, 0, sizeof(fb_state));
473
494
+   fb_state.nr_cbufs = 1;
474
495
+
475
496
+   /* process each plane separately */
476
497
+   for (j = 0; j < 3; j++) {
477
 
+      /* we always render to YV12 */
 
498
+      /* select correct YV12 surfaces */
478
499
+      int k = j == 1 ? 2 :
479
500
+              j == 2 ? 1 : 0;
480
501
+      struct pipe_surface *blit_surf = dst_surfaces[2 * k + field];
486
507
+      fb_state.width = blit_surf->texture->width0;
487
508
+      fb_state.height = blit_surf->texture->height0;
488
509
+
489
 
+      /* blit current field */
490
 
+      fb_state.cbufs[0] = blit_surf;
 
510
+      /* update sampler view sources  */
491
511
+      sampler_views[0] = prevprev_sv[j];
492
512
+      sampler_views[1] = prev_sv[j];
493
513
+      sampler_views[2] = cur_sv[j];
494
514
+      sampler_views[3] = next_sv[j];
 
515
+      filter->pipe->set_sampler_views(filter->pipe, PIPE_SHADER_FRAGMENT, 0, 4, sampler_views);
495
516
+
496
 
+      filter->pipe->bind_sampler_states(filter->pipe, PIPE_SHADER_FRAGMENT,
497
 
+            0, 4, filter->sampler);
498
 
+      filter->pipe->set_sampler_views(filter->pipe, PIPE_SHADER_FRAGMENT,
499
 
+            0, 4, sampler_views);
 
517
+      /* blit current field */
 
518
+      fb_state.cbufs[0] = blit_surf;
500
519
+      filter->pipe->bind_fs_state(filter->pipe, field ? filter->fs_copy_bottom : filter->fs_copy_top);
501
520
+      filter->pipe->set_framebuffer_state(filter->pipe, &fb_state);
502
521
+      filter->pipe->set_viewport_states(filter->pipe, 0, 1, &viewport);
503
 
+
504
522
+      util_draw_arrays(filter->pipe, PIPE_PRIM_QUADS, 0, 4);
505
523
+
506
524
+      fb_state.cbufs[0] = dst_surf;