~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/gallium/drivers/nv50/nv50_surface.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include "nv50_defs.xml.h"
36
36
 
 
37
#define NV50_ENG2D_SUPPORTED_FORMATS 0xff0843e080608409ULL
 
38
 
37
39
/* return TRUE for formats that can be converted among each other by NV50_2D */
38
40
static INLINE boolean
39
41
nv50_2d_format_faithful(enum pipe_format format)
40
42
{
41
 
   switch (format) {
42
 
   case PIPE_FORMAT_B8G8R8A8_UNORM:
43
 
   case PIPE_FORMAT_B8G8R8X8_UNORM:
44
 
   case PIPE_FORMAT_B8G8R8A8_SRGB:
45
 
   case PIPE_FORMAT_B8G8R8X8_SRGB:
46
 
   case PIPE_FORMAT_B5G6R5_UNORM:
47
 
   case PIPE_FORMAT_B5G5R5A1_UNORM:
48
 
   case PIPE_FORMAT_B10G10R10A2_UNORM:
49
 
   case PIPE_FORMAT_R8_UNORM:
50
 
   case PIPE_FORMAT_R32G32B32A32_FLOAT:
51
 
   case PIPE_FORMAT_R32G32B32_FLOAT:
52
 
      return TRUE;
53
 
   default:
54
 
      return FALSE;
55
 
   }
 
43
   uint8_t id = nv50_format_table[format].rt;
 
44
 
 
45
   return (id >= 0xc0) &&
 
46
      (NV50_ENG2D_SUPPORTED_FORMATS & (1ULL << (id - 0xc0)));
56
47
}
57
48
 
58
49
static INLINE uint8_t
63
54
   /* Hardware values for color formats range from 0xc0 to 0xff,
64
55
    * but the 2D engine doesn't support all of them.
65
56
    */
66
 
   if ((id >= 0xc0) && (0xff0843e080608409ULL & (1ULL << (id - 0xc0))))
 
57
   if ((id >= 0xc0) && (NV50_ENG2D_SUPPORTED_FORMATS & (1ULL << (id - 0xc0))))
67
58
      return id;
68
59
 
69
60
   switch (util_format_get_blocksize(format)) {
72
63
   case 2:
73
64
      return NV50_SURFACE_FORMAT_R16_UNORM;
74
65
   case 4:
75
 
      return NV50_SURFACE_FORMAT_A8R8G8B8_UNORM;
 
66
      return NV50_SURFACE_FORMAT_BGRA8_UNORM;
76
67
   default:
77
68
      return 0;
78
69
   }
96
87
      return 1;
97
88
   }
98
89
 
99
 
   width = u_minify(mt->base.base.width0, level);
100
 
   height = u_minify(mt->base.base.height0, level);
 
90
   width = u_minify(mt->base.base.width0, level) << mt->ms_x;
 
91
   height = u_minify(mt->base.base.height0, level) << mt->ms_y;
101
92
 
102
93
   offset = mt->level[level].offset;
103
94
   if (!mt->layout_3d) {
152
143
                        unsigned sx, unsigned sy, unsigned sz,
153
144
                        unsigned w, unsigned h)
154
145
{
 
146
   static const uint32_t duvdxy[5] =
 
147
   {
 
148
      0x40000000, 0x80000000, 0x00000001, 0x00000002, 0x00000004
 
149
   };
 
150
 
155
151
   int ret;
 
152
   uint32_t ctrl;
156
153
 
157
154
   ret = MARK_RING(chan, 2 * 16 + 32, 4);
158
155
   if (ret)
166
163
   if (ret)
167
164
      return ret;
168
165
 
169
 
   /* 0/1 = CENTER/CORNER, 10/00 = POINT/BILINEAR */
 
166
   /* NOTE: 2D engine doesn't work for MS8 */
 
167
   if (src->ms_x)
 
168
      ctrl = 0x11;
 
169
 
 
170
   /* 0/1 = CENTER/CORNER, 00/10 = POINT/BILINEAR */
170
171
   BEGIN_RING(chan, RING_2D(BLIT_CONTROL), 1);
171
 
   OUT_RING  (chan, 0);
 
172
   OUT_RING  (chan, ctrl);
172
173
   BEGIN_RING(chan, RING_2D(BLIT_DST_X), 4);
173
 
   OUT_RING  (chan, dx);
174
 
   OUT_RING  (chan, dy);
175
 
   OUT_RING  (chan, w);
176
 
   OUT_RING  (chan, h);
 
174
   OUT_RING  (chan, dx << dst->ms_x);
 
175
   OUT_RING  (chan, dy << dst->ms_y);
 
176
   OUT_RING  (chan, w << dst->ms_x);
 
177
   OUT_RING  (chan, h << dst->ms_y);
177
178
   BEGIN_RING(chan, RING_2D(BLIT_DU_DX_FRACT), 4);
178
 
   OUT_RING  (chan, 0);
179
 
   OUT_RING  (chan, 1);
180
 
   OUT_RING  (chan, 0);
181
 
   OUT_RING  (chan, 1);
 
179
   OUT_RING  (chan, duvdxy[2 + ((int)src->ms_x - (int)dst->ms_x)] & 0xf0000000);
 
180
   OUT_RING  (chan, duvdxy[2 + ((int)src->ms_x - (int)dst->ms_x)] & 0x0000000f);
 
181
   OUT_RING  (chan, duvdxy[2 + ((int)src->ms_y - (int)dst->ms_y)] & 0xf0000000);
 
182
   OUT_RING  (chan, duvdxy[2 + ((int)src->ms_y - (int)dst->ms_y)] & 0x0000000f);
182
183
   BEGIN_RING(chan, RING_2D(BLIT_SRC_X_FRACT), 4);
183
184
   OUT_RING  (chan, 0);
184
 
   OUT_RING  (chan, sx);
 
185
   OUT_RING  (chan, sx << src->ms_x);
185
186
   OUT_RING  (chan, 0);
186
 
   OUT_RING  (chan, sy);
 
187
   OUT_RING  (chan, sy << src->ms_y);
187
188
 
188
189
   return 0;
189
190
}
197
198
{
198
199
   struct nv50_screen *screen = nv50_context(pipe)->screen;
199
200
   int ret;
 
201
   boolean m2mf;
200
202
   unsigned dst_layer = dstz, src_layer = src_box->z;
201
203
 
202
204
   /* Fallback for buffers. */
206
208
      return;
207
209
   }
208
210
 
 
211
   assert(src->nr_samples == dst->nr_samples);
 
212
 
 
213
   m2mf = (src->format == dst->format) ||
 
214
      (util_format_get_blocksizebits(src->format) ==
 
215
       util_format_get_blocksizebits(dst->format));
 
216
 
 
217
   nv04_resource(dst)->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
 
218
 
 
219
   if (m2mf) {
 
220
      struct nv50_m2mf_rect drect, srect;
 
221
      unsigned i;
 
222
      unsigned nx = util_format_get_nblocksx(src->format, src_box->width);
 
223
      unsigned ny = util_format_get_nblocksy(src->format, src_box->height);
 
224
 
 
225
      nv50_m2mf_rect_setup(&drect, dst, dst_level, dstx, dsty, dstz);
 
226
      nv50_m2mf_rect_setup(&srect, src, src_level,
 
227
                           src_box->x, src_box->y, src_box->z);
 
228
 
 
229
      for (i = 0; i < src_box->depth; ++i) {
 
230
         nv50_m2mf_transfer_rect(&screen->base.base, &drect, &srect, nx, ny);
 
231
 
 
232
         if (nv50_miptree(dst)->layout_3d)
 
233
            drect.z++;
 
234
         else
 
235
            drect.base += nv50_miptree(dst)->layer_stride;
 
236
 
 
237
         if (nv50_miptree(src)->layout_3d)
 
238
            srect.z++;
 
239
         else
 
240
            srect.base += nv50_miptree(src)->layer_stride;
 
241
      }
 
242
      return;
 
243
   }
 
244
 
209
245
   assert((src->format == dst->format) ||
210
246
          (nv50_2d_format_faithful(src->format) &&
211
247
           nv50_2d_format_faithful(dst->format)));
225
261
static void
226
262
nv50_clear_render_target(struct pipe_context *pipe,
227
263
                         struct pipe_surface *dst,
228
 
                         const float *rgba,
 
264
                         const union pipe_color_union *color,
229
265
                         unsigned dstx, unsigned dsty,
230
266
                         unsigned width, unsigned height)
231
267
{
237
273
   struct nouveau_bo *bo = mt->base.bo;
238
274
 
239
275
   BEGIN_RING(chan, RING_3D(CLEAR_COLOR(0)), 4);
240
 
   OUT_RINGf (chan, rgba[0]);
241
 
   OUT_RINGf (chan, rgba[1]);
242
 
   OUT_RINGf (chan, rgba[2]);
243
 
   OUT_RINGf (chan, rgba[3]);
 
276
   OUT_RINGf (chan, color->f[0]);
 
277
   OUT_RINGf (chan, color->f[1]);
 
278
   OUT_RINGf (chan, color->f[2]);
 
279
   OUT_RINGf (chan, color->f[3]);
244
280
 
245
281
   if (MARK_RING(chan, 18, 2))
246
282
      return;
254
290
   OUT_RING  (chan, mt->level[sf->base.u.tex.level].tile_mode << 4);
255
291
   OUT_RING  (chan, 0);
256
292
   BEGIN_RING(chan, RING_3D(RT_HORIZ(0)), 2);
257
 
   OUT_RING  (chan, sf->width);
 
293
   if (nouveau_bo_tile_layout(bo))
 
294
      OUT_RING(chan, sf->width);
 
295
   else
 
296
      OUT_RING(chan, NV50_3D_RT_HORIZ_LINEAR | mt->level[0].pitch);
258
297
   OUT_RING  (chan, sf->height);
259
298
   BEGIN_RING(chan, RING_3D(RT_ARRAY_MODE), 1);
260
299
   OUT_RING  (chan, 1);
261
300
 
 
301
   if (!nouveau_bo_tile_layout(bo)) {
 
302
      BEGIN_RING(chan, RING_3D(ZETA_ENABLE), 1);
 
303
      OUT_RING  (chan, 0);
 
304
   }
 
305
 
262
306
   /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */
263
307
 
264
308
   BEGIN_RING(chan, RING_3D(VIEWPORT_HORIZ(0)), 2);
288
332
   struct nouveau_bo *bo = mt->base.bo;
289
333
   uint32_t mode = 0;
290
334
 
 
335
   assert(nouveau_bo_tile_layout(bo)); /* ZETA cannot be linear */
 
336
 
291
337
   if (clear_flags & PIPE_CLEAR_DEPTH) {
292
338
      BEGIN_RING(chan, RING_3D(CLEAR_DEPTH), 1);
293
339
      OUT_RINGf (chan, depth);
328
374
 
329
375
void
330
376
nv50_clear(struct pipe_context *pipe, unsigned buffers,
331
 
           const float *rgba, double depth, unsigned stencil)
 
377
           const union pipe_color_union *color,
 
378
           double depth, unsigned stencil)
332
379
{
333
380
   struct nv50_context *nv50 = nv50_context(pipe);
334
381
   struct nouveau_channel *chan = nv50->screen->base.channel;
335
382
   struct pipe_framebuffer_state *fb = &nv50->framebuffer;
336
383
   unsigned i;
337
 
   const unsigned dirty = nv50->dirty;
338
384
   uint32_t mode = 0;
339
385
 
340
386
   /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
341
 
   nv50->dirty &= NV50_NEW_FRAMEBUFFER;
342
 
   if (!nv50_state_validate(nv50))
 
387
   if (!nv50_state_validate(nv50, NV50_NEW_FRAMEBUFFER, 9 + (fb->nr_cbufs * 2)))
343
388
      return;
344
389
 
345
390
   if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
346
391
      BEGIN_RING(chan, RING_3D(CLEAR_COLOR(0)), 4);
347
 
      OUT_RINGf (chan, rgba[0]);
348
 
      OUT_RINGf (chan, rgba[1]);
349
 
      OUT_RINGf (chan, rgba[2]);
350
 
      OUT_RINGf (chan, rgba[3]);
 
392
      OUT_RINGf (chan, color->f[0]);
 
393
      OUT_RINGf (chan, color->f[1]);
 
394
      OUT_RINGf (chan, color->f[2]);
 
395
      OUT_RINGf (chan, color->f[3]);
351
396
      mode =
352
397
         NV50_3D_CLEAR_BUFFERS_R | NV50_3D_CLEAR_BUFFERS_G |
353
398
         NV50_3D_CLEAR_BUFFERS_B | NV50_3D_CLEAR_BUFFERS_A;
372
417
      BEGIN_RING(chan, RING_3D(CLEAR_BUFFERS), 1);
373
418
      OUT_RING  (chan, (i << 6) | 0x3c);
374
419
   }
375
 
 
376
 
   nv50->dirty = dirty & ~NV50_NEW_FRAMEBUFFER;
 
420
}
 
421
 
 
422
 
 
423
struct nv50_blitctx
 
424
{
 
425
   struct nv50_screen *screen;
 
426
   struct {
 
427
      struct pipe_framebuffer_state fb;
 
428
      struct nv50_program *vp;
 
429
      struct nv50_program *gp;
 
430
      struct nv50_program *fp;
 
431
      unsigned num_textures[3];
 
432
      unsigned num_samplers[3];
 
433
      struct pipe_sampler_view *texture;
 
434
      struct nv50_tsc_entry *sampler;
 
435
      unsigned dirty;
 
436
   } saved;
 
437
   struct nv50_program vp;
 
438
   struct nv50_program fp;
 
439
   struct nv50_tsc_entry sampler[2]; /* nearest, bilinear */
 
440
   uint32_t fp_offset;
 
441
   uint16_t color_mask;
 
442
   uint8_t filter;
 
443
};
 
444
 
 
445
static void
 
446
nv50_blitctx_make_vp(struct nv50_blitctx *blit)
 
447
{
 
448
   static const uint32_t code[] =
 
449
   {
 
450
      0x10000001, /* mov b32 o[0x00] s[0x00] */ /* HPOS.x */
 
451
      0x0423c788,
 
452
      0x10000205, /* mov b32 o[0x04] s[0x04] */ /* HPOS.y */
 
453
      0x0423c788,
 
454
      0x10000409, /* mov b32 o[0x08] s[0x08] */ /* TEXC.x */
 
455
      0x0423c788,
 
456
      0x1000060d, /* mov b32 o[0x0c] s[0x0c] */ /* TEXC.y */
 
457
      0x0423c788,
 
458
      0x10000811, /* exit mov b32 o[0x10] s[0x10] */ /* TEXC.z */
 
459
      0x0423c789,
 
460
   };
 
461
 
 
462
   blit->vp.type = PIPE_SHADER_VERTEX;
 
463
   blit->vp.translated = TRUE;
 
464
   blit->vp.code = (uint32_t *)code; /* const_cast */
 
465
   blit->vp.code_size = sizeof(code);
 
466
   blit->vp.max_gpr = 4;
 
467
   blit->vp.max_out = 5;
 
468
   blit->vp.out_nr = 2;
 
469
   blit->vp.out[0].mask = 0x3;
 
470
   blit->vp.out[0].sn = TGSI_SEMANTIC_POSITION;
 
471
   blit->vp.out[1].hw = 2;
 
472
   blit->vp.out[1].mask = 0x7;
 
473
   blit->vp.out[1].sn = TGSI_SEMANTIC_GENERIC;
 
474
   blit->vp.vp.attrs[0] = 0x73;
 
475
   blit->vp.vp.psiz = 0x40;
 
476
   blit->vp.vp.edgeflag = 0x40;
 
477
}
 
478
 
 
479
static void
 
480
nv50_blitctx_make_fp(struct nv50_blitctx *blit)
 
481
{
 
482
   static const uint32_t code[] =
 
483
   {
 
484
      /* 3 coords RGBA in, RGBA out, also for Z32_FLOAT(_S8X24_UINT) */
 
485
      0x80000000, /* interp $r0 v[0x0] */
 
486
      0x80010004, /* interp $r1 v[0x4] */
 
487
      0x80020009, /* interp $r2 flat v[0x8] */
 
488
      0x00040780,
 
489
      0xf6800001, /* texauto live { $r0,1,2,3 } $t0 $s0 { $r0,1,2 } */
 
490
      0x0000c785, /* exit */
 
491
 
 
492
      /* 3 coords ZS in, S encoded in R, Z encoded in GBA (8_UNORM) */
 
493
      0x80000000, /* interp $r0 v[0x00] */
 
494
      0x80010004, /* interp $r1 v[0x04] */
 
495
      0x80020009, /* interp $r2 flat v[0x8] */
 
496
      0x00040780,
 
497
      0xf6800001, /* texauto live { $r0,1,#,# } $t0 $s0 { $r0,1,2 } */
 
498
      0x00000784,
 
499
      0xc03f0009, /* mul f32 $r2 $r0 (2^24 - 1) */
 
500
      0x04b7ffff,
 
501
      0xa0000201, /* cvt f32 $r0 s32 $r1 */
 
502
      0x44014780,
 
503
      0xa0000409, /* cvt rni s32 $r2 f32 $r2 */
 
504
      0x8c004780,
 
505
      0xc0010001, /* mul f32 $r0 $r0 1/0xff */
 
506
      0x03b8080b,
 
507
      0xd03f0405, /* and b32 $r1 $r2 0x0000ff */
 
508
      0x0000000f,
 
509
      0xd000040d, /* and b32 $r3 $r2 0xff0000 */
 
510
      0x000ff003,
 
511
      0xd0000409, /* and b32 $r2 $r2 0x00ff00 */
 
512
      0x00000ff3,
 
513
      0xa0000205, /* cvt f32 $r1 s32 $r1 */
 
514
      0x44014780,
 
515
      0xa000060d, /* cvt f32 $r3 s32 $r3 */
 
516
      0x44014780,
 
517
      0xa0000409, /* cvt f32 $r2 s32 $r2 */
 
518
      0x44014780,
 
519
      0xc0010205, /* mul f32 $r1 $r1 1/0x0000ff */
 
520
      0x03b8080b,
 
521
      0xc001060d, /* mul f32 $r3 $r3 1/0x00ff00 */
 
522
      0x0338080b,
 
523
      0xc0010409, /* mul f32 $r2 $r2 1/0xff0000 */
 
524
      0x0378080b,
 
525
      0xf0000001, /* exit never nop */
 
526
      0xe0000001,
 
527
 
 
528
      /* 3 coords ZS in, Z encoded in RGB, S encoded in A (U8_UNORM) */
 
529
      0x80000000, /* interp $r0 v[0x00] */
 
530
      0x80010004, /* interp $r1 v[0x04] */
 
531
      0x80020009, /* interp $r2 flat v[0x8] */
 
532
      0x00040780,
 
533
      0xf6800001, /* texauto live { $r0,1,#,# } $t0 $s0 { $r0,1,2 } */
 
534
      0x00000784,
 
535
      0xc03f0009, /* mul f32 $r2 $r0 (2^24 - 1) */
 
536
      0x04b7ffff,
 
537
      0xa0000281, /* cvt f32 $r3 s32 $r1 */
 
538
      0x44014780,
 
539
      0xa0000409, /* cvt rni s32 $r2 f32 $r2 */
 
540
      0x8c004780,
 
541
      0xc001060d, /* mul f32 $r3 $r3 1/0xff */
 
542
      0x03b8080b,
 
543
      0xd03f0401, /* and b32 $r0 $r2 0x0000ff */
 
544
      0x0000000f,
 
545
      0xd0000405, /* and b32 $r1 $r2 0x00ff00 */
 
546
      0x00000ff3,
 
547
      0xd0000409, /* and b32 $r2 $r2 0xff0000 */
 
548
      0x000ff003,
 
549
      0xa0000001, /* cvt f32 $r0 s32 $r0 */
 
550
      0x44014780,
 
551
      0xa0000205, /* cvt f32 $r1 s32 $r1 */
 
552
      0x44014780,
 
553
      0xa0000409, /* cvt f32 $r2 s32 $r2 */
 
554
      0x44014780,
 
555
      0xc0010001, /* mul f32 $r0 $r0 1/0x0000ff */
 
556
      0x03b8080b,
 
557
      0xc0010205, /* mul f32 $r1 $r1 1/0x00ff00 */
 
558
      0x0378080b,
 
559
      0xc0010409, /* mul f32 $r2 $r2 1/0xff0000 */
 
560
      0x0338080b,
 
561
      0xf0000001, /* exit never nop */
 
562
      0xe0000001
 
563
   };
 
564
 
 
565
   blit->fp.type = PIPE_SHADER_FRAGMENT;
 
566
   blit->fp.translated = TRUE;
 
567
   blit->fp.code = (uint32_t *)code; /* const_cast */
 
568
   blit->fp.code_size = sizeof(code);
 
569
   blit->fp.max_gpr = 4;
 
570
   blit->fp.max_out = 4;
 
571
   blit->fp.in_nr = 1;
 
572
   blit->fp.in[0].mask = 0x7; /* last component flat */
 
573
   blit->fp.in[0].linear = 1;
 
574
   blit->fp.in[0].sn = TGSI_SEMANTIC_GENERIC;
 
575
   blit->fp.out_nr = 1;
 
576
   blit->fp.out[0].mask = 0xf;
 
577
   blit->fp.out[0].sn = TGSI_SEMANTIC_COLOR;
 
578
   blit->fp.fp.interp = 0x00020403;
 
579
   blit->fp.gp.primid = 0x80;
 
580
}
 
581
 
 
582
static void
 
583
nv50_blitctx_make_sampler(struct nv50_blitctx *blit)
 
584
{
 
585
   /* clamp to edge, min/max lod = 0, nearest filtering */
 
586
 
 
587
   blit->sampler[0].id = -1;
 
588
 
 
589
   blit->sampler[0].tsc[0] = 0x00000092;
 
590
   blit->sampler[0].tsc[1] = 0x00000051;
 
591
 
 
592
   /* clamp to edge, min/max lod = 0, bilinear filtering */
 
593
 
 
594
   blit->sampler[1].id = -1;
 
595
 
 
596
   blit->sampler[1].tsc[0] = 0x00000092;
 
597
   blit->sampler[1].tsc[1] = 0x00000062;
 
598
}
 
599
 
 
600
/* Since shaders cannot export stencil, we cannot copy stencil values when
 
601
 * rendering to ZETA, so we attach the ZS surface to a colour render target.
 
602
 */
 
603
static INLINE enum pipe_format
 
604
nv50_blit_zeta_to_colour_format(enum pipe_format format)
 
605
{
 
606
   switch (format) {
 
607
   case PIPE_FORMAT_Z16_UNORM:               return PIPE_FORMAT_R16_UNORM;
 
608
   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
 
609
   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
 
610
   case PIPE_FORMAT_Z24X8_UNORM:             return PIPE_FORMAT_R8G8B8A8_UNORM;
 
611
   case PIPE_FORMAT_Z32_FLOAT:               return PIPE_FORMAT_R32_FLOAT;
 
612
   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: return PIPE_FORMAT_R32G32_FLOAT;
 
613
   default:
 
614
      assert(0);
 
615
      return PIPE_FORMAT_NONE;
 
616
   }
 
617
}
 
618
 
 
619
static void
 
620
nv50_blitctx_get_color_mask_and_fp(struct nv50_blitctx *blit,
 
621
                                   enum pipe_format format, uint8_t mask)
 
622
{
 
623
   blit->color_mask = 0;
 
624
 
 
625
   switch (format) {
 
626
   case PIPE_FORMAT_Z24X8_UNORM:
 
627
   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
 
628
      blit->fp_offset = 160;
 
629
      if (mask & PIPE_MASK_Z)
 
630
         blit->color_mask |= 0x0111;
 
631
      if (mask & PIPE_MASK_S)
 
632
         blit->color_mask |= 0x1000;
 
633
      break;
 
634
   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
 
635
      blit->fp_offset = 24;
 
636
      if (mask & PIPE_MASK_Z)
 
637
         blit->color_mask |= 0x1110;
 
638
      if (mask & PIPE_MASK_S)
 
639
         blit->color_mask |= 0x0001;
 
640
      break;
 
641
   default:
 
642
      blit->fp_offset = 0;
 
643
      if (mask & (PIPE_MASK_R | PIPE_MASK_Z)) blit->color_mask |= 0x0001;
 
644
      if (mask & (PIPE_MASK_G | PIPE_MASK_S)) blit->color_mask |= 0x0010;
 
645
      if (mask & PIPE_MASK_B) blit->color_mask |= 0x0100;
 
646
      if (mask & PIPE_MASK_A) blit->color_mask |= 0x1000;
 
647
      break;
 
648
   }
 
649
}
 
650
 
 
651
static void
 
652
nv50_blit_set_dst(struct nv50_context *nv50,
 
653
                  struct pipe_resource *res, unsigned level, unsigned layer)
 
654
{
 
655
   struct pipe_context *pipe = &nv50->base.pipe;
 
656
   struct pipe_surface templ;
 
657
 
 
658
   if (util_format_is_depth_or_stencil(res->format))
 
659
      templ.format = nv50_blit_zeta_to_colour_format(res->format);
 
660
   else
 
661
      templ.format = res->format;
 
662
 
 
663
   templ.usage = PIPE_USAGE_STREAM;
 
664
   templ.u.tex.level = level;
 
665
   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
 
666
 
 
667
   nv50->framebuffer.cbufs[0] = nv50_miptree_surface_new(pipe, res, &templ);
 
668
   nv50->framebuffer.nr_cbufs = 1;
 
669
   nv50->framebuffer.zsbuf = NULL;
 
670
   nv50->framebuffer.width = nv50->framebuffer.cbufs[0]->width;
 
671
   nv50->framebuffer.height = nv50->framebuffer.cbufs[0]->height;
 
672
}
 
673
 
 
674
static INLINE void
 
675
nv50_blit_fixup_tic_entry(struct pipe_sampler_view *view)
 
676
{
 
677
   struct nv50_tic_entry *ent = nv50_tic_entry(view);
 
678
 
 
679
   ent->tic[2] &= ~(1 << 31); /* scaled coordinates, ok with 3d textures ? */
 
680
 
 
681
   /* magic: */
 
682
 
 
683
   ent->tic[3] = 0x20000000; /* affects quality of near vertical edges in MS8 */
 
684
}
 
685
 
 
686
static void
 
687
nv50_blit_set_src(struct nv50_context *nv50,
 
688
                  struct pipe_resource *res, unsigned level, unsigned layer)
 
689
{
 
690
   struct pipe_context *pipe = &nv50->base.pipe;
 
691
   struct pipe_sampler_view templ;
 
692
 
 
693
   templ.format = res->format;
 
694
   templ.u.tex.first_layer = templ.u.tex.last_layer = layer;
 
695
   templ.u.tex.first_level = templ.u.tex.last_level = level;
 
696
   templ.swizzle_r = PIPE_SWIZZLE_RED;
 
697
   templ.swizzle_g = PIPE_SWIZZLE_GREEN;
 
698
   templ.swizzle_b = PIPE_SWIZZLE_BLUE;
 
699
   templ.swizzle_a = PIPE_SWIZZLE_ALPHA;
 
700
 
 
701
   nv50->textures[2][0] = nv50_create_sampler_view(pipe, res, &templ);
 
702
 
 
703
   nv50_blit_fixup_tic_entry(nv50->textures[2][0]);
 
704
 
 
705
   nv50->num_textures[0] = nv50->num_textures[1] = 0;
 
706
   nv50->num_textures[2] = 1;
 
707
}
 
708
 
 
709
static void
 
710
nv50_blitctx_prepare_state(struct nv50_blitctx *blit)
 
711
{
 
712
   struct nouveau_channel *chan = blit->screen->base.channel;
 
713
 
 
714
   /* blend state */
 
715
   BEGIN_RING(chan, RING_3D(COLOR_MASK(0)), 1);
 
716
   OUT_RING  (chan, blit->color_mask);
 
717
   BEGIN_RING(chan, RING_3D(BLEND_ENABLE(0)), 1);
 
718
   OUT_RING  (chan, 0);
 
719
   BEGIN_RING(chan, RING_3D(LOGIC_OP_ENABLE), 1);
 
720
   OUT_RING  (chan, 0);
 
721
 
 
722
   /* rasterizer state */
 
723
#ifndef NV50_SCISSORS_CLIPPING
 
724
   BEGIN_RING(chan, RING_3D(SCISSOR_ENABLE(0)), 1);
 
725
   OUT_RING  (chan, 1);
 
726
#endif
 
727
   BEGIN_RING(chan, RING_3D(VERTEX_TWO_SIDE_ENABLE), 1);
 
728
   OUT_RING  (chan, 0);
 
729
   BEGIN_RING(chan, RING_3D(FRAG_COLOR_CLAMP_EN), 1);
 
730
   OUT_RING  (chan, 0);
 
731
   BEGIN_RING(chan, RING_3D(MULTISAMPLE_ENABLE), 1);
 
732
   OUT_RING  (chan, 0);
 
733
   BEGIN_RING(chan, RING_3D(MSAA_MASK(0)), 4);
 
734
   OUT_RING  (chan, 0xffff);
 
735
   OUT_RING  (chan, 0xffff);
 
736
   OUT_RING  (chan, 0xffff);
 
737
   OUT_RING  (chan, 0xffff);
 
738
   BEGIN_RING(chan, RING_3D(POLYGON_MODE_FRONT), 3);
 
739
   OUT_RING  (chan, NV50_3D_POLYGON_MODE_FRONT_FILL);
 
740
   OUT_RING  (chan, NV50_3D_POLYGON_MODE_BACK_FILL);
 
741
   OUT_RING  (chan, 0);
 
742
   BEGIN_RING(chan, RING_3D(CULL_FACE_ENABLE), 1);
 
743
   OUT_RING  (chan, 0);
 
744
   BEGIN_RING(chan, RING_3D(POLYGON_STIPPLE_ENABLE), 1);
 
745
   OUT_RING  (chan, 0);
 
746
   BEGIN_RING(chan, RING_3D(POLYGON_OFFSET_FILL_ENABLE), 1);
 
747
   OUT_RING  (chan, 0);
 
748
 
 
749
   /* zsa state */
 
750
   BEGIN_RING(chan, RING_3D(DEPTH_TEST_ENABLE), 1);
 
751
   OUT_RING  (chan, 0);
 
752
   BEGIN_RING(chan, RING_3D(STENCIL_ENABLE), 1);
 
753
   OUT_RING  (chan, 0);
 
754
   BEGIN_RING(chan, RING_3D(ALPHA_TEST_ENABLE), 1);
 
755
   OUT_RING  (chan, 0);
 
756
}
 
757
 
 
758
static void
 
759
nv50_blitctx_pre_blit(struct nv50_blitctx *blit, struct nv50_context *nv50)
 
760
{
 
761
   int s;
 
762
 
 
763
   blit->saved.fb.width = nv50->framebuffer.width;
 
764
   blit->saved.fb.height = nv50->framebuffer.height;
 
765
   blit->saved.fb.nr_cbufs = nv50->framebuffer.nr_cbufs;
 
766
   blit->saved.fb.cbufs[0] = nv50->framebuffer.cbufs[0];
 
767
   blit->saved.fb.zsbuf = nv50->framebuffer.zsbuf;
 
768
 
 
769
   blit->saved.vp = nv50->vertprog;
 
770
   blit->saved.gp = nv50->gmtyprog;
 
771
   blit->saved.fp = nv50->fragprog;
 
772
 
 
773
   nv50->vertprog = &blit->vp;
 
774
   nv50->gmtyprog = NULL;
 
775
   nv50->fragprog = &blit->fp;
 
776
 
 
777
   for (s = 0; s < 3; ++s) {
 
778
      blit->saved.num_textures[s] = nv50->num_textures[s];
 
779
      blit->saved.num_samplers[s] = nv50->num_samplers[s];
 
780
   }
 
781
   blit->saved.texture = nv50->textures[2][0];
 
782
   blit->saved.sampler = nv50->samplers[2][0];
 
783
 
 
784
   nv50->samplers[2][0] = &blit->sampler[blit->filter];
 
785
 
 
786
   nv50->num_samplers[0] = nv50->num_samplers[1] = 0;
 
787
   nv50->num_samplers[2] = 1;
 
788
 
 
789
   blit->saved.dirty = nv50->dirty;
 
790
 
 
791
   nv50->dirty =
 
792
      NV50_NEW_FRAMEBUFFER |
 
793
      NV50_NEW_VERTPROG | NV50_NEW_FRAGPROG | NV50_NEW_GMTYPROG |
 
794
      NV50_NEW_TEXTURES | NV50_NEW_SAMPLERS;
 
795
}
 
796
 
 
797
static void
 
798
nv50_blitctx_post_blit(struct nv50_context *nv50, struct nv50_blitctx *blit)
 
799
{
 
800
   int s;
 
801
 
 
802
   pipe_surface_reference(&nv50->framebuffer.cbufs[0], NULL);
 
803
 
 
804
   nv50->framebuffer.width = blit->saved.fb.width;
 
805
   nv50->framebuffer.height = blit->saved.fb.height;
 
806
   nv50->framebuffer.nr_cbufs = blit->saved.fb.nr_cbufs;
 
807
   nv50->framebuffer.cbufs[0] = blit->saved.fb.cbufs[0];
 
808
   nv50->framebuffer.zsbuf = blit->saved.fb.zsbuf;
 
809
 
 
810
   nv50->vertprog = blit->saved.vp;
 
811
   nv50->gmtyprog = blit->saved.gp;
 
812
   nv50->fragprog = blit->saved.fp;
 
813
 
 
814
   pipe_sampler_view_reference(&nv50->textures[2][0], NULL);
 
815
 
 
816
   for (s = 0; s < 3; ++s) {
 
817
      nv50->num_textures[s] = blit->saved.num_textures[s];
 
818
      nv50->num_samplers[s] = blit->saved.num_samplers[s];
 
819
   }
 
820
   nv50->textures[2][0] = blit->saved.texture;
 
821
   nv50->samplers[2][0] = blit->saved.sampler;
 
822
 
 
823
   nv50->dirty = blit->saved.dirty |
 
824
      (NV50_NEW_FRAMEBUFFER | NV50_NEW_SCISSOR | NV50_NEW_SAMPLE_MASK |
 
825
       NV50_NEW_RASTERIZER | NV50_NEW_ZSA | NV50_NEW_BLEND |
 
826
       NV50_NEW_TEXTURES | NV50_NEW_SAMPLERS |
 
827
       NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG | NV50_NEW_FRAGPROG);
 
828
}
 
829
 
 
830
static void
 
831
nv50_resource_resolve(struct pipe_context *pipe,
 
832
                      const struct pipe_resolve_info *info)
 
833
{
 
834
   struct nv50_context *nv50 = nv50_context(pipe);
 
835
   struct nv50_screen *screen = nv50->screen;
 
836
   struct nv50_blitctx *blit = screen->blitctx;
 
837
   struct nouveau_channel *chan = screen->base.channel;
 
838
   struct pipe_resource *src = info->src.res;
 
839
   struct pipe_resource *dst = info->dst.res;
 
840
   float x0, x1, y0, y1, z;
 
841
   float x_range, y_range;
 
842
 
 
843
   nv50_blitctx_get_color_mask_and_fp(blit, dst->format, info->mask);
 
844
 
 
845
   blit->filter = util_format_is_depth_or_stencil(dst->format) ? 0 : 1;
 
846
 
 
847
   nv50_blitctx_pre_blit(blit, nv50);
 
848
 
 
849
   nv50_blit_set_dst(nv50, dst, info->dst.level, info->dst.layer);
 
850
   nv50_blit_set_src(nv50, src, 0,               info->src.layer);
 
851
 
 
852
   nv50_blitctx_prepare_state(blit);
 
853
 
 
854
   nv50_state_validate(nv50, ~0, 36);
 
855
 
 
856
   x_range =
 
857
      (float)(info->src.x1 - info->src.x0) /
 
858
      (float)(info->dst.x1 - info->dst.x0);
 
859
   y_range =
 
860
      (float)(info->src.y1 - info->src.y0) /
 
861
      (float)(info->dst.y1 - info->dst.y0);
 
862
 
 
863
   x0 = (float)info->src.x0 - x_range * (float)info->dst.x0;
 
864
   y0 = (float)info->src.y0 - y_range * (float)info->dst.y0;
 
865
 
 
866
   x1 = x0 + 16384.0f * x_range;
 
867
   y1 = y0 + 16384.0f * y_range;
 
868
 
 
869
   x0 *= (float)(1 << nv50_miptree(src)->ms_x);
 
870
   x1 *= (float)(1 << nv50_miptree(src)->ms_x);
 
871
   y0 *= (float)(1 << nv50_miptree(src)->ms_y);
 
872
   y1 *= (float)(1 << nv50_miptree(src)->ms_y);
 
873
 
 
874
   z = (float)info->src.layer;
 
875
 
 
876
   BEGIN_RING(chan, RING_3D(FP_START_ID), 1);
 
877
   OUT_RING  (chan,
 
878
              blit->fp.code_base + blit->fp_offset);
 
879
 
 
880
   BEGIN_RING(chan, RING_3D(VIEWPORT_TRANSFORM_EN), 1);
 
881
   OUT_RING  (chan, 0);
 
882
 
 
883
   /* Draw a large triangle in screen coordinates covering the whole
 
884
    * render target, with scissors defining the destination region.
 
885
    * The vertex is supplied with non-normalized texture coordinates
 
886
    * arranged in a way to yield the desired offset and scale.
 
887
    */
 
888
 
 
889
   BEGIN_RING(chan, RING_3D(SCISSOR_HORIZ(0)), 2);
 
890
   OUT_RING  (chan, (info->dst.x1 << 16) | info->dst.x0);
 
891
   OUT_RING  (chan, (info->dst.y1 << 16) | info->dst.y0);
 
892
 
 
893
   BEGIN_RING(chan, RING_3D(VERTEX_BEGIN_GL), 1);
 
894
   OUT_RING  (chan, NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_TRIANGLES);
 
895
   BEGIN_RING(chan, RING_3D(VTX_ATTR_3F_X(1)), 3);
 
896
   OUT_RINGf (chan, x0);
 
897
   OUT_RINGf (chan, y0);
 
898
   OUT_RINGf (chan, z);
 
899
   BEGIN_RING(chan, RING_3D(VTX_ATTR_2F_X(0)), 2);
 
900
   OUT_RINGf (chan, 0.0f);
 
901
   OUT_RINGf (chan, 0.0f);
 
902
   BEGIN_RING(chan, RING_3D(VTX_ATTR_3F_X(1)), 3);
 
903
   OUT_RINGf (chan, x1);
 
904
   OUT_RINGf (chan, y0);
 
905
   OUT_RINGf (chan, z);
 
906
   BEGIN_RING(chan, RING_3D(VTX_ATTR_2F_X(0)), 2);
 
907
   OUT_RINGf (chan, 16384 << nv50_miptree(dst)->ms_x);
 
908
   OUT_RINGf (chan, 0.0f);
 
909
   BEGIN_RING(chan, RING_3D(VTX_ATTR_3F_X(1)), 3);
 
910
   OUT_RINGf (chan, x0);
 
911
   OUT_RINGf (chan, y1);
 
912
   OUT_RINGf (chan, z);
 
913
   BEGIN_RING(chan, RING_3D(VTX_ATTR_2F_X(0)), 2);
 
914
   OUT_RINGf (chan, 0.0f);
 
915
   OUT_RINGf (chan, 16384 << nv50_miptree(dst)->ms_y);
 
916
   BEGIN_RING(chan, RING_3D(VERTEX_END_GL), 1);
 
917
   OUT_RING  (chan, 0);
 
918
 
 
919
   /* re-enable normally constant state */
 
920
 
 
921
   BEGIN_RING(chan, RING_3D(VIEWPORT_TRANSFORM_EN), 1);
 
922
   OUT_RING  (chan, 1);
 
923
 
 
924
   nv50_blitctx_post_blit(nv50, blit);
 
925
}
 
926
 
 
927
boolean
 
928
nv50_blitctx_create(struct nv50_screen *screen)
 
929
{
 
930
   screen->blitctx = CALLOC_STRUCT(nv50_blitctx);
 
931
   if (!screen->blitctx) {
 
932
      NOUVEAU_ERR("failed to allocate blit context\n");
 
933
      return FALSE;
 
934
   }
 
935
 
 
936
   screen->blitctx->screen = screen;
 
937
 
 
938
   nv50_blitctx_make_vp(screen->blitctx);
 
939
   nv50_blitctx_make_fp(screen->blitctx);
 
940
 
 
941
   nv50_blitctx_make_sampler(screen->blitctx);
 
942
 
 
943
   screen->blitctx->color_mask = 0x1111;
 
944
 
 
945
   return TRUE;
377
946
}
378
947
 
379
948
void
382
951
   struct pipe_context *pipe = &nv50->base.pipe;
383
952
 
384
953
   pipe->resource_copy_region = nv50_resource_copy_region;
 
954
   pipe->resource_resolve = nv50_resource_resolve;
385
955
   pipe->clear_render_target = nv50_clear_render_target;
386
956
   pipe->clear_depth_stencil = nv50_clear_depth_stencil;
387
957
}