~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/gallium/auxiliary/util/u_blit.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#include "util/u_format.h"
46
46
#include "util/u_math.h"
47
47
#include "util/u_memory.h"
 
48
#include "util/u_sampler.h"
48
49
#include "util/u_simple_shaders.h"
49
 
#include "util/u_surface.h"
50
 
#include "util/u_rect.h"
51
50
 
52
51
#include "cso_cache/cso_context.h"
53
52
 
58
57
   struct cso_context *cso;
59
58
 
60
59
   struct pipe_blend_state blend;
61
 
   struct pipe_depth_stencil_alpha_state depthstencil;
 
60
   struct pipe_depth_stencil_alpha_state depthstencil_keep;
 
61
   struct pipe_depth_stencil_alpha_state depthstencil_write;
62
62
   struct pipe_rasterizer_state rasterizer;
63
63
   struct pipe_sampler_state sampler;
64
64
   struct pipe_viewport_state viewport;
65
65
   struct pipe_clip_state clip;
 
66
   struct pipe_vertex_element velem[2];
 
67
   enum pipe_texture_target internal_target;
66
68
 
67
69
   void *vs;
68
70
   void *fs[TGSI_WRITEMASK_XYZW + 1];
 
71
   void *fs_depth;
69
72
 
70
 
   struct pipe_buffer *vbuf;  /**< quad vertices */
 
73
   struct pipe_resource *vbuf;  /**< quad vertices */
71
74
   unsigned vbuf_slot;
72
75
 
73
76
   float vertices[4][2][4];   /**< vertex/texcoords for quad */
96
99
   ctx->blend.rt[0].colormask = PIPE_MASK_RGBA;
97
100
 
98
101
   /* no-op depth/stencil/alpha */
99
 
   memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
 
102
   memset(&ctx->depthstencil_keep, 0, sizeof(ctx->depthstencil_keep));
 
103
   memset(&ctx->depthstencil_write, 0, sizeof(ctx->depthstencil_write));
 
104
   ctx->depthstencil_write.depth.enabled = 1;
 
105
   ctx->depthstencil_write.depth.writemask = 1;
 
106
   ctx->depthstencil_write.depth.func = PIPE_FUNC_ALWAYS;
100
107
 
101
108
   /* rasterizer */
102
109
   memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
103
 
   ctx->rasterizer.front_winding = PIPE_WINDING_CW;
104
 
   ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
 
110
   ctx->rasterizer.cull_face = PIPE_FACE_NONE;
105
111
   ctx->rasterizer.gl_rasterization_rules = 1;
106
112
 
107
113
   /* samplers */
112
118
   ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
113
119
   ctx->sampler.min_img_filter = 0; /* set later */
114
120
   ctx->sampler.mag_img_filter = 0; /* set later */
115
 
   ctx->sampler.normalized_coords = 1;
 
121
 
 
122
   /* vertex elements state */
 
123
   memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2);
 
124
   for (i = 0; i < 2; i++) {
 
125
      ctx->velem[i].src_offset = i * 4 * sizeof(float);
 
126
      ctx->velem[i].instance_divisor = 0;
 
127
      ctx->velem[i].vertex_buffer_index = 0;
 
128
      ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
129
   }
116
130
 
117
131
   /* vertex shader - still required to provide the linkage between
118
132
    * fragment shader input semantics and vertex_element/buffers.
127
141
 
128
142
   /* fragment shader */
129
143
   ctx->fs[TGSI_WRITEMASK_XYZW] =
130
 
      util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
 
144
      util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
 
145
                                    TGSI_INTERPOLATE_LINEAR);
131
146
   ctx->vbuf = NULL;
132
147
 
133
148
   /* init vertex data that doesn't change */
137
152
      ctx->vertices[i][1][3] = 1.0f; /* q */
138
153
   }
139
154
 
 
155
   if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
 
156
      ctx->internal_target = PIPE_TEXTURE_2D;
 
157
   else
 
158
      ctx->internal_target = PIPE_TEXTURE_RECT;
 
159
 
140
160
   return ctx;
141
161
}
142
162
 
156
176
      if (ctx->fs[i])
157
177
         pipe->delete_fs_state(pipe, ctx->fs[i]);
158
178
 
159
 
   pipe_buffer_reference(&ctx->vbuf, NULL);
 
179
   if (ctx->fs_depth)
 
180
      pipe->delete_fs_state(pipe, ctx->fs_depth);
 
181
 
 
182
   pipe_resource_reference(&ctx->vbuf, NULL);
160
183
 
161
184
   FREE(ctx);
162
185
}
175
198
 
176
199
   if (!ctx->vbuf) {
177
200
      ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
178
 
                                     32,
179
 
                                     PIPE_BUFFER_USAGE_VERTEX,
 
201
                                     PIPE_BIND_VERTEX_BUFFER,
180
202
                                     max_slots * sizeof ctx->vertices);
181
203
   }
182
204
   
183
205
   return ctx->vbuf_slot++ * sizeof ctx->vertices;
184
206
}
185
 
                               
186
207
 
187
208
 
188
209
 
225
246
 
226
247
   offset = get_next_slot( ctx );
227
248
 
228
 
   pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
 
249
   pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
229
250
                               offset, sizeof(ctx->vertices), ctx->vertices);
230
251
 
231
252
   return offset;
265
286
 * \param writemask  controls which channels in the dest surface are sourced
266
287
 *                   from the src surface.  Disabled channels are sourced
267
288
 *                   from (0,0,0,1).
268
 
 * XXX need some control over blitting Z and/or stencil.
 
289
 * XXX need some control over blitting stencil.
269
290
 */
270
291
void
271
292
util_blit_pixels_writemask(struct blit_state *ctx,
272
 
                           struct pipe_surface *src,
 
293
                           struct pipe_resource *src_tex,
 
294
                           struct pipe_subresource srcsub,
273
295
                           int srcX0, int srcY0,
274
296
                           int srcX1, int srcY1,
 
297
                           int srcZ0,
275
298
                           struct pipe_surface *dst,
276
299
                           int dstX0, int dstY0,
277
300
                           int dstX1, int dstY1,
280
303
{
281
304
   struct pipe_context *pipe = ctx->pipe;
282
305
   struct pipe_screen *screen = pipe->screen;
283
 
   struct pipe_texture *tex = NULL;
 
306
   struct pipe_sampler_view *sampler_view = NULL;
 
307
   struct pipe_sampler_view sv_templ;
284
308
   struct pipe_framebuffer_state fb;
285
309
   const int srcW = abs(srcX1 - srcX0);
286
310
   const int srcH = abs(srcY1 - srcY0);
287
311
   unsigned offset;
288
 
   boolean overlap;
 
312
   boolean overlap, dst_is_depth;
289
313
   float s0, t0, s1, t1;
 
314
   boolean normalized;
290
315
 
291
316
   assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
292
317
          filter == PIPE_TEX_MIPFILTER_LINEAR);
293
318
 
294
 
   assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
295
 
                                      PIPE_TEXTURE_USAGE_SAMPLER, 0));
296
 
   assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
297
 
                                      PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
 
319
   assert(srcsub.level <= src_tex->last_level);
298
320
 
299
321
   /* do the regions overlap? */
300
 
   overlap = util_same_surface(src, dst) &&
 
322
   overlap = src_tex == dst->texture &&
 
323
             dst->face == srcsub.face &&
 
324
             dst->level == srcsub.level &&
 
325
             dst->zslice == srcZ0 &&
301
326
      regions_overlap(srcX0, srcY0, srcX1, srcY1,
302
327
                      dstX0, dstY0, dstX1, dstY1);
303
328
 
306
331
    * no overlapping.
307
332
    * Filter mode should not matter since there's no stretching.
308
333
    */
309
 
   if (pipe->surface_copy &&
310
 
       dst->format == src->format &&
 
334
   if (dst->format == src_tex->format &&
311
335
       srcX0 < srcX1 &&
312
336
       dstX0 < dstX1 &&
313
337
       srcY0 < srcY1 &&
315
339
       (dstX1 - dstX0) == (srcX1 - srcX0) &&
316
340
       (dstY1 - dstY0) == (srcY1 - srcY0) &&
317
341
       !overlap) {
318
 
      pipe->surface_copy(pipe,
319
 
                         dst, dstX0, dstY0, /* dest */
320
 
                         src, srcX0, srcY0, /* src */
321
 
                         srcW, srcH);       /* size */
 
342
      struct pipe_subresource subdst;
 
343
      subdst.face = dst->face;
 
344
      subdst.level = dst->level;
 
345
      pipe->resource_copy_region(pipe,
 
346
                                 dst->texture, subdst,
 
347
                                 dstX0, dstY0, dst->zslice,/* dest */
 
348
                                 src_tex, srcsub,
 
349
                                 srcX0, srcY0, srcZ0,/* src */
 
350
                                 srcW, srcH);       /* size */
322
351
      return;
323
352
   }
324
 
   
325
 
   assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
326
 
                                      PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
327
353
 
328
354
   /* Create a temporary texture when src and dest alias or when src
329
 
    * is anything other than a single-level 2d texture.
 
355
    * is anything other than a 2d texture.
 
356
    * XXX should just use appropriate shader to access 1d / 3d slice / cube face,
 
357
    * much like the u_blitter code does (should be pretty trivial).
330
358
    * 
331
359
    * This can still be improved upon.
332
360
    */
333
 
   if (util_same_surface(src, dst) ||
334
 
       src->texture->target != PIPE_TEXTURE_2D ||
335
 
       src->texture->last_level != 0)
 
361
   if ((src_tex == dst->texture &&
 
362
       dst->face == srcsub.face &&
 
363
       dst->level == srcsub.level &&
 
364
       dst->zslice == srcZ0) ||
 
365
       (src_tex->target != PIPE_TEXTURE_2D &&
 
366
       src_tex->target != PIPE_TEXTURE_RECT))
336
367
   {
337
 
      struct pipe_texture texTemp;
338
 
      struct pipe_surface *texSurf;
 
368
      struct pipe_resource texTemp;
 
369
      struct pipe_resource *tex;
 
370
      struct pipe_sampler_view sv_templ;
 
371
      struct pipe_subresource texsub;
339
372
      const int srcLeft = MIN2(srcX0, srcX1);
340
373
      const int srcTop = MIN2(srcY0, srcY1);
341
374
 
355
388
 
356
389
      /* create temp texture */
357
390
      memset(&texTemp, 0, sizeof(texTemp));
358
 
      texTemp.target = PIPE_TEXTURE_2D;
359
 
      texTemp.format = src->format;
 
391
      texTemp.target = ctx->internal_target;
 
392
      texTemp.format = src_tex->format;
360
393
      texTemp.last_level = 0;
361
394
      texTemp.width0 = srcW;
362
395
      texTemp.height0 = srcH;
363
396
      texTemp.depth0 = 1;
 
397
      texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
364
398
 
365
 
      tex = screen->texture_create(screen, &texTemp);
 
399
      tex = screen->resource_create(screen, &texTemp);
366
400
      if (!tex)
367
401
         return;
368
402
 
369
 
      texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, 
370
 
                                        PIPE_BUFFER_USAGE_GPU_WRITE);
371
 
 
 
403
      texsub.face = 0;
 
404
      texsub.level = 0;
372
405
      /* load temp texture */
373
 
      if (pipe->surface_copy) {
374
 
         pipe->surface_copy(pipe,
375
 
                            texSurf, 0, 0,   /* dest */
376
 
                            src, srcLeft, srcTop, /* src */
377
 
                            srcW, srcH);     /* size */
378
 
      } else {
379
 
         util_surface_copy(pipe, FALSE,
380
 
                           texSurf, 0, 0,   /* dest */
381
 
                           src, srcLeft, srcTop, /* src */
382
 
                           srcW, srcH);     /* size */
383
 
      }
384
 
 
385
 
      /* free the surface, update the texture if necessary.
386
 
       */
387
 
      pipe_surface_reference(&texSurf, NULL);
388
 
      s0 = 0.0f; 
389
 
      s1 = 1.0f;
390
 
      t0 = 0.0f;
391
 
      t1 = 1.0f;
 
406
      pipe->resource_copy_region(pipe,
 
407
                                 tex, texsub, 0, 0, 0,  /* dest */
 
408
                                 src_tex, srcsub, srcLeft, srcTop, srcZ0, /* src */
 
409
                                 srcW, srcH);     /* size */
 
410
 
 
411
      normalized = tex->target != PIPE_TEXTURE_RECT;
 
412
      if(normalized) {
 
413
         s0 = 0.0f;
 
414
         s1 = 1.0f;
 
415
         t0 = 0.0f;
 
416
         t1 = 1.0f;
 
417
      }
 
418
      else {
 
419
         s0 = 0;
 
420
         s1 = srcW;
 
421
         t0 = 0;
 
422
         t1 = srcH;
 
423
      }
 
424
 
 
425
      u_sampler_view_default_template(&sv_templ, tex, tex->format);
 
426
      sampler_view = pipe->create_sampler_view(pipe, tex, &sv_templ);
 
427
 
 
428
      if (!sampler_view) {
 
429
         pipe_resource_reference(&tex, NULL);
 
430
         return;
 
431
      }
 
432
      pipe_resource_reference(&tex, NULL);
392
433
   }
393
434
   else {
394
 
      pipe_texture_reference(&tex, src->texture);
395
 
      s0 = srcX0 / (float)tex->width0;
396
 
      s1 = srcX1 / (float)tex->width0;
397
 
      t0 = srcY0 / (float)tex->height0;
398
 
      t1 = srcY1 / (float)tex->height0;
 
435
      u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format);
 
436
      sv_templ.first_level = sv_templ.last_level = srcsub.level;
 
437
      sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ);
 
438
 
 
439
      if (!sampler_view) {
 
440
         return;
 
441
      }
 
442
 
 
443
      s0 = srcX0;
 
444
      s1 = srcX1;
 
445
      t0 = srcY0;
 
446
      t1 = srcY1;
 
447
      normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT;
 
448
      if(normalized)
 
449
      {
 
450
         s0 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
 
451
         s1 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
 
452
         t0 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
 
453
         t1 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
 
454
      }
399
455
   }
400
456
 
 
457
   dst_is_depth = util_format_is_depth_or_stencil(dst->format);
401
458
 
 
459
   assert(screen->is_format_supported(screen, sampler_view->format, ctx->internal_target,
 
460
                                      sampler_view->texture->nr_samples,
 
461
                                      PIPE_BIND_SAMPLER_VIEW, 0));
 
462
   assert(screen->is_format_supported(screen, dst->format, ctx->internal_target,
 
463
                                      dst->texture->nr_samples,
 
464
                                      dst_is_depth ? PIPE_BIND_DEPTH_STENCIL :
 
465
                                                     PIPE_BIND_RENDER_TARGET, 0));
402
466
   /* save state (restored below) */
403
467
   cso_save_blend(ctx->cso);
404
468
   cso_save_depth_stencil_alpha(ctx->cso);
405
469
   cso_save_rasterizer(ctx->cso);
406
470
   cso_save_samplers(ctx->cso);
407
 
   cso_save_sampler_textures(ctx->cso);
 
471
   cso_save_fragment_sampler_views(ctx->cso);
408
472
   cso_save_viewport(ctx->cso);
409
473
   cso_save_framebuffer(ctx->cso);
410
474
   cso_save_fragment_shader(ctx->cso);
411
475
   cso_save_vertex_shader(ctx->cso);
412
476
   cso_save_clip(ctx->cso);
 
477
   cso_save_vertex_elements(ctx->cso);
413
478
 
414
479
   /* set misc state we care about */
415
480
   cso_set_blend(ctx->cso, &ctx->blend);
416
 
   cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
 
481
   cso_set_depth_stencil_alpha(ctx->cso,
 
482
                               dst_is_depth ? &ctx->depthstencil_write :
 
483
                                              &ctx->depthstencil_keep);
417
484
   cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
418
485
   cso_set_clip(ctx->cso, &ctx->clip);
 
486
   cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
419
487
 
420
488
   /* sampler */
 
489
   ctx->sampler.normalized_coords = normalized;
421
490
   ctx->sampler.min_img_filter = filter;
422
491
   ctx->sampler.mag_img_filter = filter;
 
492
   /* we've limited this already with the sampler view but you never know... */
 
493
   ctx->sampler.min_lod = srcsub.level;
 
494
   ctx->sampler.max_lod = srcsub.level;
423
495
   cso_single_sampler(ctx->cso, 0, &ctx->sampler);
424
496
   cso_single_sampler_done(ctx->cso);
425
497
 
435
507
   cso_set_viewport(ctx->cso, &ctx->viewport);
436
508
 
437
509
   /* texture */
438
 
   cso_set_sampler_textures(ctx->cso, 1, &tex);
439
 
 
440
 
   if (ctx->fs[writemask] == NULL)
441
 
      ctx->fs[writemask] =
442
 
         util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
443
 
                                                 writemask);
 
510
   cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
444
511
 
445
512
   /* shaders */
446
 
   cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
 
513
   if (dst_is_depth) {
 
514
      if (ctx->fs_depth == NULL)
 
515
         ctx->fs_depth =
 
516
            util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_2D,
 
517
                                                     TGSI_INTERPOLATE_LINEAR);
 
518
 
 
519
      cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth);
 
520
   } else {
 
521
      if (ctx->fs[writemask] == NULL)
 
522
         ctx->fs[writemask] =
 
523
            util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
 
524
                                                    TGSI_INTERPOLATE_LINEAR,
 
525
                                                    writemask);
 
526
 
 
527
      cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
 
528
   }
447
529
   cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
448
530
 
449
531
   /* drawing dest */
450
532
   memset(&fb, 0, sizeof(fb));
451
533
   fb.width = dst->width;
452
534
   fb.height = dst->height;
453
 
   fb.nr_cbufs = 1;
454
 
   fb.cbufs[0] = dst;
 
535
   if (dst_is_depth) {
 
536
      fb.zsbuf = dst;
 
537
   } else {
 
538
      fb.nr_cbufs = 1;
 
539
      fb.cbufs[0] = dst;
 
540
   }
455
541
   cso_set_framebuffer(ctx->cso, &fb);
456
542
 
457
543
   /* draw quad */
474
560
   cso_restore_depth_stencil_alpha(ctx->cso);
475
561
   cso_restore_rasterizer(ctx->cso);
476
562
   cso_restore_samplers(ctx->cso);
477
 
   cso_restore_sampler_textures(ctx->cso);
 
563
   cso_restore_fragment_sampler_views(ctx->cso);
478
564
   cso_restore_viewport(ctx->cso);
479
565
   cso_restore_framebuffer(ctx->cso);
480
566
   cso_restore_fragment_shader(ctx->cso);
481
567
   cso_restore_vertex_shader(ctx->cso);
482
568
   cso_restore_clip(ctx->cso);
 
569
   cso_restore_vertex_elements(ctx->cso);
483
570
 
484
 
   pipe_texture_reference(&tex, NULL);
 
571
   pipe_sampler_view_reference(&sampler_view, NULL);
485
572
}
486
573
 
487
574
 
488
575
void
489
576
util_blit_pixels(struct blit_state *ctx,
490
 
                 struct pipe_surface *src,
 
577
                 struct pipe_resource *src_tex,
 
578
                 struct pipe_subresource srcsub,
491
579
                 int srcX0, int srcY0,
492
580
                 int srcX1, int srcY1,
 
581
                 int srcZ,
493
582
                 struct pipe_surface *dst,
494
583
                 int dstX0, int dstY0,
495
584
                 int dstX1, int dstY1,
496
585
                 float z, uint filter )
497
586
{
498
 
   util_blit_pixels_writemask( ctx, src, 
 
587
   util_blit_pixels_writemask( ctx, src_tex,
 
588
                               srcsub,
499
589
                               srcX0, srcY0,
500
590
                               srcX1, srcY1,
 
591
                               srcZ,
501
592
                               dst,
502
593
                               dstX0, dstY0,
503
594
                               dstX1, dstY1,
511
602
 */
512
603
void util_blit_flush( struct blit_state *ctx )
513
604
{
514
 
   pipe_buffer_reference(&ctx->vbuf, NULL);
 
605
   pipe_resource_reference(&ctx->vbuf, NULL);
515
606
   ctx->vbuf_slot = 0;
516
607
517
608
 
519
610
 
520
611
/**
521
612
 * Copy pixel block from src texture to dst surface.
522
 
 * Overlapping regions are acceptable.
523
613
 *
524
614
 * XXX Should support selection of level.
525
615
 * XXX need some control over blitting Z and/or stencil.
526
616
 */
527
617
void
528
618
util_blit_pixels_tex(struct blit_state *ctx,
529
 
                 struct pipe_texture *tex,
530
 
                 int srcX0, int srcY0,
531
 
                 int srcX1, int srcY1,
532
 
                 struct pipe_surface *dst,
533
 
                 int dstX0, int dstY0,
534
 
                 int dstX1, int dstY1,
535
 
                 float z, uint filter)
 
619
                     struct pipe_sampler_view *src_sampler_view,
 
620
                     int srcX0, int srcY0,
 
621
                     int srcX1, int srcY1,
 
622
                     struct pipe_surface *dst,
 
623
                     int dstX0, int dstY0,
 
624
                     int dstX1, int dstY1,
 
625
                     float z, uint filter)
536
626
{
 
627
   boolean normalized = src_sampler_view->texture->target != PIPE_TEXTURE_RECT;
537
628
   struct pipe_framebuffer_state fb;
538
629
   float s0, t0, s1, t1;
539
630
   unsigned offset;
 
631
   struct pipe_resource *tex = src_sampler_view->texture;
540
632
 
541
633
   assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
542
634
          filter == PIPE_TEX_MIPFILTER_LINEAR);
543
635
 
 
636
   assert(tex);
544
637
   assert(tex->width0 != 0);
545
638
   assert(tex->height0 != 0);
546
639
 
547
 
   s0 = srcX0 / (float)tex->width0;
548
 
   s1 = srcX1 / (float)tex->width0;
549
 
   t0 = srcY0 / (float)tex->height0;
550
 
   t1 = srcY1 / (float)tex->height0;
 
640
   s0 = srcX0;
 
641
   s1 = srcX1;
 
642
   t0 = srcY0;
 
643
   t1 = srcY1;
 
644
 
 
645
   if(normalized)
 
646
   {
 
647
      s0 /= (float)tex->width0;
 
648
      s1 /= (float)tex->width0;
 
649
      t0 /= (float)tex->height0;
 
650
      t1 /= (float)tex->height0;
 
651
   }
551
652
 
552
653
   assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
553
654
                                                 PIPE_TEXTURE_2D,
554
 
                                                 PIPE_TEXTURE_USAGE_RENDER_TARGET,
 
655
                                                 dst->texture->nr_samples,
 
656
                                                 PIPE_BIND_RENDER_TARGET,
555
657
                                                 0));
556
658
 
557
659
   /* save state (restored below) */
559
661
   cso_save_depth_stencil_alpha(ctx->cso);
560
662
   cso_save_rasterizer(ctx->cso);
561
663
   cso_save_samplers(ctx->cso);
562
 
   cso_save_sampler_textures(ctx->cso);
 
664
   cso_save_fragment_sampler_views(ctx->cso);
563
665
   cso_save_framebuffer(ctx->cso);
564
666
   cso_save_fragment_shader(ctx->cso);
565
667
   cso_save_vertex_shader(ctx->cso);
566
668
   cso_save_clip(ctx->cso);
 
669
   cso_save_vertex_elements(ctx->cso);
567
670
 
568
671
   /* set misc state we care about */
569
672
   cso_set_blend(ctx->cso, &ctx->blend);
570
 
   cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
 
673
   cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil_keep);
571
674
   cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
572
675
   cso_set_clip(ctx->cso, &ctx->clip);
 
676
   cso_set_vertex_elements(ctx->cso, 2, ctx->velem);
573
677
 
574
678
   /* sampler */
 
679
   ctx->sampler.normalized_coords = normalized;
575
680
   ctx->sampler.min_img_filter = filter;
576
681
   ctx->sampler.mag_img_filter = filter;
577
682
   cso_single_sampler(ctx->cso, 0, &ctx->sampler);
589
694
   cso_set_viewport(ctx->cso, &ctx->viewport);
590
695
 
591
696
   /* texture */
592
 
   cso_set_sampler_textures(ctx->cso, 1, &tex);
 
697
   cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view);
593
698
 
594
699
   /* shaders */
595
700
   cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]);
623
728
   cso_restore_depth_stencil_alpha(ctx->cso);
624
729
   cso_restore_rasterizer(ctx->cso);
625
730
   cso_restore_samplers(ctx->cso);
626
 
   cso_restore_sampler_textures(ctx->cso);
 
731
   cso_restore_fragment_sampler_views(ctx->cso);
627
732
   cso_restore_framebuffer(ctx->cso);
628
733
   cso_restore_fragment_shader(ctx->cso);
629
734
   cso_restore_vertex_shader(ctx->cso);
630
735
   cso_restore_clip(ctx->cso);
 
736
   cso_restore_vertex_elements(ctx->cso);
631
737
}