xorg_renderer.c revision 8b0c217f2bc123bffd25cc4977d6abb1b3fa8186
1#include "xorg_exa.h"
2#include "xorg_renderer.h"
3
4#include "xorg_exa_tgsi.h"
5
6#include "cso_cache/cso_context.h"
7#include "util/u_draw_quad.h"
8#include "util/u_math.h"
9#include "util/u_memory.h"
10#include "util/u_rect.h"
11#include "util/u_sampler.h"
12#include "util/u_surface.h"
13
14#include "util/u_inlines.h"
15
16#include <math.h>
17
18#define floatsEqual(x, y) (fabs(x - y) <= 0.00001f * MIN2(fabs(x), fabs(y)))
19#define floatIsZero(x) (floatsEqual((x) + 1, 1))
20
21#define NUM_COMPONENTS 4
22
23static INLINE boolean is_affine(float *matrix)
24{
25   return floatIsZero(matrix[2]) && floatIsZero(matrix[5])
26      && floatsEqual(matrix[8], 1);
27}
28static INLINE void map_point(float *mat, float x, float y,
29                             float *out_x, float *out_y)
30{
31   if (!mat) {
32      *out_x = x;
33      *out_y = y;
34      return;
35   }
36
37   *out_x = mat[0]*x + mat[3]*y + mat[6];
38   *out_y = mat[1]*x + mat[4]*y + mat[7];
39   if (!is_affine(mat)) {
40      float w = 1/(mat[2]*x + mat[5]*y + mat[8]);
41      *out_x *= w;
42      *out_y *= w;
43   }
44}
45
46static INLINE struct pipe_resource *
47renderer_buffer_create(struct xorg_renderer *r)
48{
49   struct pipe_resource *buf =
50      pipe_user_buffer_create(r->pipe->screen,
51                              r->buffer,
52                              sizeof(float)*
53                              r->buffer_size,
54/* XXX was: PIPE_BUFFER_USAGE_PIXEL/PIPE_BUFFER_USAGE_GPU_WRITE even though this is a vertex buffer??? */
55			      PIPE_BIND_VERTEX_BUFFER);
56   r->buffer_size = 0;
57
58   return buf;
59}
60
61static INLINE void
62renderer_draw(struct xorg_renderer *r)
63{
64   struct pipe_context *pipe = r->pipe;
65   struct pipe_resource *buf = 0;
66   int num_verts = r->buffer_size/(r->attrs_per_vertex * NUM_COMPONENTS);
67
68   if (!r->buffer_size)
69      return;
70
71   buf = renderer_buffer_create(r);
72
73
74   if (buf) {
75      cso_set_vertex_elements(r->cso, r->attrs_per_vertex, r->velems);
76
77      util_draw_vertex_buffer(pipe, buf, 0,
78                              PIPE_PRIM_QUADS,
79                              num_verts,  /* verts */
80                              r->attrs_per_vertex); /* attribs/vert */
81
82      pipe_resource_reference(&buf, NULL);
83   }
84}
85
86static INLINE void
87renderer_draw_conditional(struct xorg_renderer *r,
88                          int next_batch)
89{
90   if (r->buffer_size + next_batch >= BUF_SIZE ||
91       (next_batch == 0 && r->buffer_size)) {
92      renderer_draw(r);
93   }
94}
95
96static void
97renderer_init_state(struct xorg_renderer *r)
98{
99   struct pipe_depth_stencil_alpha_state dsa;
100   struct pipe_rasterizer_state raster;
101   unsigned i;
102
103   /* set common initial clip state */
104   memset(&dsa, 0, sizeof(struct pipe_depth_stencil_alpha_state));
105   cso_set_depth_stencil_alpha(r->cso, &dsa);
106
107
108   /* XXX: move to renderer_init_state? */
109   memset(&raster, 0, sizeof(struct pipe_rasterizer_state));
110   raster.gl_rasterization_rules = 1;
111   cso_set_rasterizer(r->cso, &raster);
112
113   /* vertex elements state */
114   memset(&r->velems[0], 0, sizeof(r->velems[0]) * 3);
115   for (i = 0; i < 3; i++) {
116      r->velems[i].src_offset = i * 4 * sizeof(float);
117      r->velems[i].instance_divisor = 0;
118      r->velems[i].vertex_buffer_index = 0;
119      r->velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
120   }
121}
122
123
124static INLINE void
125add_vertex_color(struct xorg_renderer *r,
126                 float x, float y,
127                 float color[4])
128{
129   float *vertex = r->buffer + r->buffer_size;
130
131   vertex[0] = x;
132   vertex[1] = y;
133   vertex[2] = 0.f; /*z*/
134   vertex[3] = 1.f; /*w*/
135
136   vertex[4] = color[0]; /*r*/
137   vertex[5] = color[1]; /*g*/
138   vertex[6] = color[2]; /*b*/
139   vertex[7] = color[3]; /*a*/
140
141   r->buffer_size += 8;
142}
143
144static INLINE void
145add_vertex_1tex(struct xorg_renderer *r,
146                float x, float y, float s, float t)
147{
148   float *vertex = r->buffer + r->buffer_size;
149
150   vertex[0] = x;
151   vertex[1] = y;
152   vertex[2] = 0.f; /*z*/
153   vertex[3] = 1.f; /*w*/
154
155   vertex[4] = s;   /*s*/
156   vertex[5] = t;   /*t*/
157   vertex[6] = 0.f; /*r*/
158   vertex[7] = 1.f; /*q*/
159
160   r->buffer_size += 8;
161}
162
163static void
164add_vertex_data1(struct xorg_renderer *r,
165                 float srcX, float srcY,  float dstX, float dstY,
166                 float width, float height,
167                 struct pipe_resource *src, float *src_matrix)
168{
169   float s0, t0, s1, t1, s2, t2, s3, t3;
170   float pt0[2], pt1[2], pt2[2], pt3[2];
171
172   pt0[0] = srcX;
173   pt0[1] = srcY;
174   pt1[0] = (srcX + width);
175   pt1[1] = srcY;
176   pt2[0] = (srcX + width);
177   pt2[1] = (srcY + height);
178   pt3[0] = srcX;
179   pt3[1] = (srcY + height);
180
181   if (src_matrix) {
182      map_point(src_matrix, pt0[0], pt0[1], &pt0[0], &pt0[1]);
183      map_point(src_matrix, pt1[0], pt1[1], &pt1[0], &pt1[1]);
184      map_point(src_matrix, pt2[0], pt2[1], &pt2[0], &pt2[1]);
185      map_point(src_matrix, pt3[0], pt3[1], &pt3[0], &pt3[1]);
186   }
187
188   s0 =  pt0[0] / src->width0;
189   s1 =  pt1[0] / src->width0;
190   s2 =  pt2[0] / src->width0;
191   s3 =  pt3[0] / src->width0;
192   t0 =  pt0[1] / src->height0;
193   t1 =  pt1[1] / src->height0;
194   t2 =  pt2[1] / src->height0;
195   t3 =  pt3[1] / src->height0;
196
197   /* 1st vertex */
198   add_vertex_1tex(r, dstX, dstY, s0, t0);
199   /* 2nd vertex */
200   add_vertex_1tex(r, dstX + width, dstY, s1, t1);
201   /* 3rd vertex */
202   add_vertex_1tex(r, dstX + width, dstY + height, s2, t2);
203   /* 4th vertex */
204   add_vertex_1tex(r, dstX, dstY + height, s3, t3);
205}
206
207
208static INLINE void
209add_vertex_2tex(struct xorg_renderer *r,
210                float x, float y,
211                float s0, float t0, float s1, float t1)
212{
213   float *vertex = r->buffer + r->buffer_size;
214
215   vertex[0] = x;
216   vertex[1] = y;
217   vertex[2] = 0.f; /*z*/
218   vertex[3] = 1.f; /*w*/
219
220   vertex[4] = s0;  /*s*/
221   vertex[5] = t0;  /*t*/
222   vertex[6] = 0.f; /*r*/
223   vertex[7] = 1.f; /*q*/
224
225   vertex[8] = s1;  /*s*/
226   vertex[9] = t1;  /*t*/
227   vertex[10] = 0.f; /*r*/
228   vertex[11] = 1.f; /*q*/
229
230   r->buffer_size += 12;
231}
232
233static void
234add_vertex_data2(struct xorg_renderer *r,
235                 float srcX, float srcY, float maskX, float maskY,
236                 float dstX, float dstY, float width, float height,
237                 struct pipe_resource *src,
238                 struct pipe_resource *mask,
239                 float *src_matrix, float *mask_matrix)
240{
241   float src_s0, src_t0, src_s1, src_t1;
242   float mask_s0, mask_t0, mask_s1, mask_t1;
243   float spt0[2], spt1[2];
244   float mpt0[2], mpt1[2];
245
246   spt0[0] = srcX;
247   spt0[1] = srcY;
248   spt1[0] = srcX + width;
249   spt1[1] = srcY + height;
250
251   mpt0[0] = maskX;
252   mpt0[1] = maskY;
253   mpt1[0] = maskX + width;
254   mpt1[1] = maskY + height;
255
256   if (src_matrix) {
257      map_point(src_matrix, spt0[0], spt0[1], &spt0[0], &spt0[1]);
258      map_point(src_matrix, spt1[0], spt1[1], &spt1[0], &spt1[1]);
259   }
260
261   if (mask_matrix) {
262      map_point(mask_matrix, mpt0[0], mpt0[1], &mpt0[0], &mpt0[1]);
263      map_point(mask_matrix, mpt1[0], mpt1[1], &mpt1[0], &mpt1[1]);
264   }
265
266   src_s0 = spt0[0] / src->width0;
267   src_t0 = spt0[1] / src->height0;
268   src_s1 = spt1[0] / src->width0;
269   src_t1 = spt1[1] / src->height0;
270
271   mask_s0 = mpt0[0] / mask->width0;
272   mask_t0 = mpt0[1] / mask->height0;
273   mask_s1 = mpt1[0] / mask->width0;
274   mask_t1 = mpt1[1] / mask->height0;
275
276   /* 1st vertex */
277   add_vertex_2tex(r, dstX, dstY,
278                   src_s0, src_t0, mask_s0, mask_t0);
279   /* 2nd vertex */
280   add_vertex_2tex(r, dstX + width, dstY,
281                   src_s1, src_t0, mask_s1, mask_t0);
282   /* 3rd vertex */
283   add_vertex_2tex(r, dstX + width, dstY + height,
284                   src_s1, src_t1, mask_s1, mask_t1);
285   /* 4th vertex */
286   add_vertex_2tex(r, dstX, dstY + height,
287                   src_s0, src_t1, mask_s0, mask_t1);
288}
289
290static struct pipe_resource *
291setup_vertex_data_yuv(struct xorg_renderer *r,
292                      float srcX, float srcY, float srcW, float srcH,
293                      float dstX, float dstY, float dstW, float dstH,
294                      struct pipe_resource **tex)
295{
296   float s0, t0, s1, t1;
297   float spt0[2], spt1[2];
298
299   spt0[0] = srcX;
300   spt0[1] = srcY;
301   spt1[0] = srcX + srcW;
302   spt1[1] = srcY + srcH;
303
304   s0 = spt0[0] / tex[0]->width0;
305   t0 = spt0[1] / tex[0]->height0;
306   s1 = spt1[0] / tex[0]->width0;
307   t1 = spt1[1] / tex[0]->height0;
308
309   /* 1st vertex */
310   add_vertex_1tex(r, dstX, dstY, s0, t0);
311   /* 2nd vertex */
312   add_vertex_1tex(r, dstX + dstW, dstY,
313                   s1, t0);
314   /* 3rd vertex */
315   add_vertex_1tex(r, dstX + dstW, dstY + dstH,
316                   s1, t1);
317   /* 4th vertex */
318   add_vertex_1tex(r, dstX, dstY + dstH,
319                   s0, t1);
320
321   return renderer_buffer_create(r);
322}
323
324
325
326/* Set up framebuffer, viewport and vertex shader constant buffer
327 * state for a particular destinaton surface.  In all our rendering,
328 * these concepts are linked.
329 */
330void renderer_bind_destination(struct xorg_renderer *r,
331                               struct pipe_surface *surface,
332                               int width,
333                               int height )
334{
335
336   struct pipe_framebuffer_state fb;
337   struct pipe_viewport_state viewport;
338
339   /* Framebuffer uses actual surface width/height
340    */
341   memset(&fb, 0, sizeof fb);
342   fb.width  = surface->width;
343   fb.height = surface->height;
344   fb.nr_cbufs = 1;
345   fb.cbufs[0] = surface;
346   fb.zsbuf = 0;
347
348   /* Viewport just touches the bit we're interested in:
349    */
350   viewport.scale[0] =  width / 2.f;
351   viewport.scale[1] =  height / 2.f;
352   viewport.scale[2] =  1.0;
353   viewport.scale[3] =  1.0;
354   viewport.translate[0] = width / 2.f;
355   viewport.translate[1] = height / 2.f;
356   viewport.translate[2] = 0.0;
357   viewport.translate[3] = 0.0;
358
359   /* Constant buffer set up to match viewport dimensions:
360    */
361   if (r->fb_width != width ||
362       r->fb_height != height)
363   {
364      float vs_consts[8] = {
365         2.f/width, 2.f/height, 1, 1,
366         -1, -1, 0, 0
367      };
368
369      r->fb_width = width;
370      r->fb_height = height;
371
372      renderer_set_constants(r, PIPE_SHADER_VERTEX,
373                             vs_consts, sizeof vs_consts);
374   }
375
376   cso_set_framebuffer(r->cso, &fb);
377   cso_set_viewport(r->cso, &viewport);
378}
379
380
381struct xorg_renderer * renderer_create(struct pipe_context *pipe)
382{
383   struct xorg_renderer *renderer = CALLOC_STRUCT(xorg_renderer);
384
385   renderer->pipe = pipe;
386   renderer->cso = cso_create_context(pipe);
387   renderer->shaders = xorg_shaders_create(renderer);
388
389   renderer_init_state(renderer);
390
391   return renderer;
392}
393
394void renderer_destroy(struct xorg_renderer *r)
395{
396   struct pipe_resource **vsbuf = &r->vs_const_buffer;
397   struct pipe_resource **fsbuf = &r->fs_const_buffer;
398
399   if (*vsbuf)
400      pipe_resource_reference(vsbuf, NULL);
401
402   if (*fsbuf)
403      pipe_resource_reference(fsbuf, NULL);
404
405   if (r->shaders) {
406      xorg_shaders_destroy(r->shaders);
407      r->shaders = NULL;
408   }
409
410   if (r->cso) {
411      cso_release_all(r->cso);
412      cso_destroy_context(r->cso);
413      r->cso = NULL;
414   }
415}
416
417
418
419
420
421void renderer_set_constants(struct xorg_renderer *r,
422                            int shader_type,
423                            const float *params,
424                            int param_bytes)
425{
426   struct pipe_resource **cbuf =
427      (shader_type == PIPE_SHADER_VERTEX) ? &r->vs_const_buffer :
428      &r->fs_const_buffer;
429
430   pipe_resource_reference(cbuf, NULL);
431   *cbuf = pipe_buffer_create(r->pipe->screen,
432                              PIPE_BIND_CONSTANT_BUFFER,
433                              param_bytes);
434
435   if (*cbuf) {
436      pipe_buffer_write(r->pipe, *cbuf,
437                        0, param_bytes, params);
438   }
439   r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
440}
441
442
443void renderer_copy_prepare(struct xorg_renderer *r,
444                           struct pipe_surface *dst_surface,
445                           struct pipe_resource *src_texture)
446{
447   struct pipe_context *pipe = r->pipe;
448   struct pipe_screen *screen = pipe->screen;
449   struct xorg_shader shader;
450
451   assert(screen->is_format_supported(screen, dst_surface->format,
452                                      PIPE_TEXTURE_2D,
453                                      PIPE_BIND_RENDER_TARGET,
454                                      0));
455   (void) screen;
456
457
458   /* set misc state we care about */
459   {
460      struct pipe_blend_state blend;
461      memset(&blend, 0, sizeof(blend));
462      blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
463      blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
464      blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
465      blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
466      blend.rt[0].colormask = PIPE_MASK_RGBA;
467      cso_set_blend(r->cso, &blend);
468   }
469
470   /* sampler */
471   {
472      struct pipe_sampler_state sampler;
473      memset(&sampler, 0, sizeof(sampler));
474      sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
475      sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
476      sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
477      sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
478      sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
479      sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
480      sampler.normalized_coords = 1;
481      cso_single_sampler(r->cso, 0, &sampler);
482      cso_single_sampler_done(r->cso);
483   }
484
485   renderer_bind_destination(r, dst_surface,
486                             dst_surface->width,
487                             dst_surface->height);
488
489   /* texture/sampler view */
490   {
491      struct pipe_sampler_view templ;
492      struct pipe_sampler_view *src_view;
493      u_sampler_view_default_template(&templ,
494                                      src_texture,
495                                      src_texture->format);
496      src_view = pipe->create_sampler_view(pipe, src_texture, &templ);
497      cso_set_fragment_sampler_views(r->cso, 1, &src_view);
498      pipe_sampler_view_reference(&src_view, NULL);
499   }
500
501   /* shaders */
502   shader = xorg_shaders_get(r->shaders,
503                             VS_COMPOSITE,
504                             FS_COMPOSITE);
505   cso_set_vertex_shader_handle(r->cso, shader.vs);
506   cso_set_fragment_shader_handle(r->cso, shader.fs);
507
508   r->buffer_size = 0;
509   r->attrs_per_vertex = 2;
510}
511
512struct pipe_resource *
513renderer_clone_texture(struct xorg_renderer *r,
514                       struct pipe_resource *src)
515{
516   enum pipe_format format;
517   struct pipe_context *pipe = r->pipe;
518   struct pipe_screen *screen = pipe->screen;
519   struct pipe_resource *pt;
520   struct pipe_resource templ;
521
522   if (pipe->is_resource_referenced(pipe, src, 0, 0) &
523       PIPE_REFERENCED_FOR_WRITE)
524      pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
525
526   /* the coming in texture should already have that invariance */
527   debug_assert(screen->is_format_supported(screen, src->format,
528                                            PIPE_TEXTURE_2D,
529                                            PIPE_BIND_SAMPLER_VIEW, 0));
530
531   format = src->format;
532
533   memset(&templ, 0, sizeof(templ));
534   templ.target = PIPE_TEXTURE_2D;
535   templ.format = format;
536   templ.last_level = 0;
537   templ.width0 = src->width0;
538   templ.height0 = src->height0;
539   templ.depth0 = 1;
540   templ.bind = PIPE_BIND_SAMPLER_VIEW;
541
542   pt = screen->resource_create(screen, &templ);
543
544   debug_assert(!pt || pipe_is_referenced(&pt->reference));
545
546   if (!pt)
547      return NULL;
548
549   {
550      /* copy source framebuffer surface into texture */
551      struct pipe_surface *ps_read = screen->get_tex_surface(
552         screen, src, 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
553      struct pipe_surface *ps_tex = screen->get_tex_surface(
554         screen, pt, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION );
555      if (pipe->surface_copy) {
556         pipe->surface_copy(pipe,
557                ps_tex, /* dest */
558                0, 0, /* destx/y */
559                ps_read,
560                0, 0, src->width0, src->height0);
561      } else {
562          util_surface_copy(pipe, FALSE,
563                ps_tex, /* dest */
564                0, 0, /* destx/y */
565                ps_read,
566                0, 0, src->width0, src->height0);
567      }
568      pipe_surface_reference(&ps_read, NULL);
569      pipe_surface_reference(&ps_tex, NULL);
570   }
571
572   return pt;
573}
574
575
576void renderer_copy_pixmap(struct xorg_renderer *r,
577                          int dx, int dy,
578                          int sx, int sy,
579                          int width, int height,
580                          float src_width,
581                          float src_height)
582{
583   float s0, t0, s1, t1;
584   float x0, y0, x1, y1;
585
586
587   /* XXX: could put the texcoord scaling calculation into the vertex
588    * shader.
589    */
590   s0 = sx            / src_width;
591   s1 = (sx + width)  / src_width;
592   t0 = sy            / src_height;
593   t1 = (sy + height) / src_height;
594
595   x0 = dx;
596   x1 = dx + width;
597   y0 = dy;
598   y1 = dy + height;
599
600   /* draw quad */
601   renderer_draw_conditional(r, 4*8);
602   add_vertex_1tex(r, x0, y0, s0, t0);
603   add_vertex_1tex(r, x1, y0, s1, t0);
604   add_vertex_1tex(r, x1, y1, s1, t1);
605   add_vertex_1tex(r, x0, y1, s0, t1);
606}
607
608
609
610
611void renderer_draw_yuv(struct xorg_renderer *r,
612                       int src_x, int src_y, int src_w, int src_h,
613                       int dst_x, int dst_y, int dst_w, int dst_h,
614                       struct pipe_resource **textures)
615{
616   struct pipe_context *pipe = r->pipe;
617   struct pipe_resource *buf = 0;
618
619   buf = setup_vertex_data_yuv(r,
620                               src_x, src_y, src_w, src_h,
621                               dst_x, dst_y, dst_w, dst_h,
622                               textures);
623
624   if (buf) {
625      const int num_attribs = 2; /*pos + tex coord*/
626
627      cso_set_vertex_elements(r->cso, num_attribs, r->velems);
628
629      util_draw_vertex_buffer(pipe, buf, 0,
630                              PIPE_PRIM_QUADS,
631                              4,  /* verts */
632                              num_attribs); /* attribs/vert */
633
634      pipe_resource_reference(&buf, NULL);
635   }
636}
637
638void renderer_begin_solid(struct xorg_renderer *r)
639{
640   r->buffer_size = 0;
641   r->attrs_per_vertex = 2;
642}
643
644void renderer_solid(struct xorg_renderer *r,
645                    int x0, int y0,
646                    int x1, int y1,
647                    float *color)
648{
649   /*
650   debug_printf("solid rect[(%d, %d), (%d, %d)], rgba[%f, %f, %f, %f]\n",
651   x0, y0, x1, y1, color[0], color[1], color[2], color[3]);*/
652
653   renderer_draw_conditional(r, 4 * 8);
654
655   /* 1st vertex */
656   add_vertex_color(r, x0, y0, color);
657   /* 2nd vertex */
658   add_vertex_color(r, x1, y0, color);
659   /* 3rd vertex */
660   add_vertex_color(r, x1, y1, color);
661   /* 4th vertex */
662   add_vertex_color(r, x0, y1, color);
663}
664
665void renderer_draw_flush(struct xorg_renderer *r)
666{
667   renderer_draw_conditional(r, 0);
668}
669
670void renderer_begin_textures(struct xorg_renderer *r,
671                             int num_textures)
672{
673   r->attrs_per_vertex = 1 + num_textures;
674   r->buffer_size = 0;
675}
676
677void renderer_texture(struct xorg_renderer *r,
678                      int *pos,
679                      int width, int height,
680                      struct pipe_sampler_view **sampler_view,
681                      int num_textures,
682                      float *src_matrix,
683                      float *mask_matrix)
684{
685
686#if 0
687   if (src_matrix) {
688      debug_printf("src_matrix = \n");
689      debug_printf("%f, %f, %f\n", src_matrix[0], src_matrix[1], src_matrix[2]);
690      debug_printf("%f, %f, %f\n", src_matrix[3], src_matrix[4], src_matrix[5]);
691      debug_printf("%f, %f, %f\n", src_matrix[6], src_matrix[7], src_matrix[8]);
692   }
693   if (mask_matrix) {
694      debug_printf("mask_matrix = \n");
695      debug_printf("%f, %f, %f\n", mask_matrix[0], mask_matrix[1], mask_matrix[2]);
696      debug_printf("%f, %f, %f\n", mask_matrix[3], mask_matrix[4], mask_matrix[5]);
697      debug_printf("%f, %f, %f\n", mask_matrix[6], mask_matrix[7], mask_matrix[8]);
698   }
699#endif
700
701   switch(r->attrs_per_vertex) {
702   case 2:
703      renderer_draw_conditional(r, 4 * 8);
704      add_vertex_data1(r,
705                       pos[0], pos[1], /* src */
706                       pos[4], pos[5], /* dst */
707                       width, height,
708                       sampler_view[0]->texture, src_matrix);
709      break;
710   case 3:
711      renderer_draw_conditional(r, 4 * 12);
712      add_vertex_data2(r,
713                       pos[0], pos[1], /* src */
714                       pos[2], pos[3], /* mask */
715                       pos[4], pos[5], /* dst */
716                       width, height,
717                       sampler_view[0]->texture, sampler_view[1]->texture,
718                       src_matrix, mask_matrix);
719      break;
720   default:
721      debug_assert(!"Unsupported number of textures");
722      break;
723   }
724}
725