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);
312
boolean overlap, dst_is_depth;
289
313
float s0, t0, s1, t1;
291
316
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
292
317
filter == PIPE_TEX_MIPFILTER_LINEAR);
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);
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);
315
339
(dstX1 - dstX0) == (srcX1 - srcX0) &&
316
340
(dstY1 - dstY0) == (srcY1 - srcY0) &&
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 */
349
srcX0, srcY0, srcZ0,/* src */
350
srcW, srcH); /* size */
325
assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
326
PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
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).
331
359
* This can still be improved upon.
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))
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);
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;
365
tex = screen->texture_create(screen, &texTemp);
399
tex = screen->resource_create(screen, &texTemp);
369
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
370
PIPE_BUFFER_USAGE_GPU_WRITE);
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 */
379
util_surface_copy(pipe, FALSE,
380
texSurf, 0, 0, /* dest */
381
src, srcLeft, srcTop, /* src */
382
srcW, srcH); /* size */
385
/* free the surface, update the texture if necessary.
387
pipe_surface_reference(&texSurf, NULL);
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 */
411
normalized = tex->target != PIPE_TEXTURE_RECT;
425
u_sampler_view_default_template(&sv_templ, tex, tex->format);
426
sampler_view = pipe->create_sampler_view(pipe, tex, &sv_templ);
429
pipe_resource_reference(&tex, NULL);
432
pipe_resource_reference(&tex, NULL);
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);
447
normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT;
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));
457
dst_is_depth = util_format_is_depth_or_stencil(dst->format);
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);
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);
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);
435
507
cso_set_viewport(ctx->cso, &ctx->viewport);
438
cso_set_sampler_textures(ctx->cso, 1, &tex);
440
if (ctx->fs[writemask] == NULL)
442
util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
510
cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view);
446
cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
514
if (ctx->fs_depth == NULL)
516
util_make_fragment_tex_shader_writedepth(pipe, TGSI_TEXTURE_2D,
517
TGSI_INTERPOLATE_LINEAR);
519
cso_set_fragment_shader_handle(ctx->cso, ctx->fs_depth);
521
if (ctx->fs[writemask] == NULL)
523
util_make_fragment_tex_shader_writemask(pipe, TGSI_TEXTURE_2D,
524
TGSI_INTERPOLATE_LINEAR,
527
cso_set_fragment_shader_handle(ctx->cso, ctx->fs[writemask]);
447
529
cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
449
531
/* drawing dest */
450
532
memset(&fb, 0, sizeof(fb));
451
533
fb.width = dst->width;
452
534
fb.height = dst->height;
455
541
cso_set_framebuffer(ctx->cso, &fb);
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);
484
pipe_texture_reference(&tex, NULL);
571
pipe_sampler_view_reference(&sampler_view, NULL);
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,
493
582
struct pipe_surface *dst,
494
583
int dstX0, int dstY0,
495
584
int dstX1, int dstY1,
496
585
float z, uint filter )
498
util_blit_pixels_writemask( ctx, src,
587
util_blit_pixels_writemask( ctx, src_tex,
521
612
* Copy pixel block from src texture to dst surface.
522
* Overlapping regions are acceptable.
524
614
* XXX Should support selection of level.
525
615
* XXX need some control over blitting Z and/or stencil.
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)
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;
631
struct pipe_resource *tex = src_sampler_view->texture;
541
633
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
542
634
filter == PIPE_TEX_MIPFILTER_LINEAR);
544
637
assert(tex->width0 != 0);
545
638
assert(tex->height0 != 0);
547
s0 = srcX0 / (float)tex->width0;
548
s1 = srcX1 / (float)tex->width0;
549
t0 = srcY0 / (float)tex->height0;
550
t1 = srcY1 / (float)tex->height0;
647
s0 /= (float)tex->width0;
648
s1 /= (float)tex->width0;
649
t0 /= (float)tex->height0;
650
t1 /= (float)tex->height0;
552
653
assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
554
PIPE_TEXTURE_USAGE_RENDER_TARGET,
655
dst->texture->nr_samples,
656
PIPE_BIND_RENDER_TARGET,
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);
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);
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);