d5839c581991b7e0aa0e8bb119bc1a7b50860b57
2 * Copyright © 2015 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "util/u_format.h"
25 #include "util/u_surface.h"
26 #include "util/u_blitter.h"
27 #include "vc4_context.h"
29 static struct pipe_surface
*
30 vc4_get_blit_surface(struct pipe_context
*pctx
,
31 struct pipe_resource
*prsc
, unsigned level
)
33 struct pipe_surface tmpl
;
35 memset(&tmpl
, 0, sizeof(tmpl
));
36 tmpl
.format
= prsc
->format
;
37 tmpl
.u
.tex
.level
= level
;
38 tmpl
.u
.tex
.first_layer
= 0;
39 tmpl
.u
.tex
.last_layer
= 0;
41 return pctx
->create_surface(pctx
, prsc
, &tmpl
);
45 is_tile_unaligned(unsigned size
, unsigned tile_size
)
47 return size
& (tile_size
- 1);
51 vc4_tile_blit(struct pipe_context
*pctx
, const struct pipe_blit_info
*info
)
53 struct vc4_context
*vc4
= vc4_context(pctx
);
57 if (util_format_is_depth_or_stencil(info
->dst
.resource
->format
))
60 if ((info
->mask
& PIPE_MASK_RGBA
) == 0)
63 if (info
->dst
.box
.x
!= info
->src
.box
.x
||
64 info
->src
.box
.y
!= info
->src
.box
.y
||
65 info
->dst
.box
.width
!= info
->src
.box
.width
||
66 info
->dst
.box
.height
!= info
->src
.box
.height
) {
70 if (is_tile_unaligned(info
->dst
.box
.x
, tile_width
) ||
71 is_tile_unaligned(info
->dst
.box
.y
, tile_height
) ||
72 is_tile_unaligned(info
->dst
.box
.width
, tile_width
) ||
73 is_tile_unaligned(info
->dst
.box
.height
, tile_height
)) {
77 if (info
->dst
.resource
->format
!= info
->src
.resource
->format
)
82 struct pipe_surface
*dst_surf
=
83 vc4_get_blit_surface(pctx
, info
->dst
.resource
, info
->dst
.level
);
84 struct pipe_surface
*src_surf
=
85 vc4_get_blit_surface(pctx
, info
->src
.resource
, info
->src
.level
);
87 pipe_surface_reference(&vc4
->color_read
, src_surf
);
88 pipe_surface_reference(&vc4
->color_write
, dst_surf
);
89 pipe_surface_reference(&vc4
->zs_read
, NULL
);
90 pipe_surface_reference(&vc4
->zs_write
, NULL
);
91 vc4
->draw_min_x
= info
->dst
.box
.x
;
92 vc4
->draw_min_y
= info
->dst
.box
.y
;
93 vc4
->draw_max_x
= info
->dst
.box
.x
+ info
->dst
.box
.width
;
94 vc4
->draw_max_y
= info
->dst
.box
.y
+ info
->dst
.box
.height
;
95 vc4
->draw_width
= dst_surf
->width
;
96 vc4
->draw_height
= dst_surf
->height
;
98 vc4
->needs_flush
= true;
101 pipe_surface_reference(&dst_surf
, NULL
);
102 pipe_surface_reference(&src_surf
, NULL
);
108 vc4_render_blit(struct pipe_context
*ctx
, struct pipe_blit_info
*info
)
110 struct vc4_context
*vc4
= vc4_context(ctx
);
112 if (!util_blitter_is_blit_supported(vc4
->blitter
, info
)) {
113 fprintf(stderr
, "blit unsupported %s -> %s\n",
114 util_format_short_name(info
->src
.resource
->format
),
115 util_format_short_name(info
->dst
.resource
->format
));
119 util_blitter_save_vertex_buffer_slot(vc4
->blitter
, vc4
->vertexbuf
.vb
);
120 util_blitter_save_vertex_elements(vc4
->blitter
, vc4
->vtx
);
121 util_blitter_save_vertex_shader(vc4
->blitter
, vc4
->prog
.bind_vs
);
122 util_blitter_save_rasterizer(vc4
->blitter
, vc4
->rasterizer
);
123 util_blitter_save_viewport(vc4
->blitter
, &vc4
->viewport
);
124 util_blitter_save_scissor(vc4
->blitter
, &vc4
->scissor
);
125 util_blitter_save_fragment_shader(vc4
->blitter
, vc4
->prog
.bind_fs
);
126 util_blitter_save_blend(vc4
->blitter
, vc4
->blend
);
127 util_blitter_save_depth_stencil_alpha(vc4
->blitter
, vc4
->zsa
);
128 util_blitter_save_stencil_ref(vc4
->blitter
, &vc4
->stencil_ref
);
129 util_blitter_save_sample_mask(vc4
->blitter
, vc4
->sample_mask
);
130 util_blitter_save_framebuffer(vc4
->blitter
, &vc4
->framebuffer
);
131 util_blitter_save_fragment_sampler_states(vc4
->blitter
,
132 vc4
->fragtex
.num_samplers
,
133 (void **)vc4
->fragtex
.samplers
);
134 util_blitter_save_fragment_sampler_views(vc4
->blitter
,
135 vc4
->fragtex
.num_textures
, vc4
->fragtex
.textures
);
137 util_blitter_blit(vc4
->blitter
, info
);
142 /* Optimal hardware path for blitting pixels.
143 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
146 vc4_blit(struct pipe_context
*pctx
, const struct pipe_blit_info
*blit_info
)
148 struct pipe_blit_info info
= *blit_info
;
150 if (info
.src
.resource
->nr_samples
> 1 &&
151 info
.dst
.resource
->nr_samples
<= 1 &&
152 !util_format_is_depth_or_stencil(info
.src
.resource
->format
) &&
153 !util_format_is_pure_integer(info
.src
.resource
->format
)) {
154 fprintf(stderr
, "color resolve unimplemented\n");
158 if (vc4_tile_blit(pctx
, blit_info
))
161 if (util_try_blit_via_copy_region(pctx
, &info
)) {
165 if (info
.mask
& PIPE_MASK_S
) {
166 fprintf(stderr
, "cannot blit stencil, skipping\n");
167 info
.mask
&= ~PIPE_MASK_S
;
170 vc4_render_blit(pctx
, &info
);