1 /**************************************************************************
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
29 * Blitter utility to facilitate acceleration of the clear, clear_render_target,
30 * clear_depth_stencil, resource_copy_region, and blit functions.
35 #include "pipe/p_context.h"
36 #include "pipe/p_defines.h"
37 #include "util/u_inlines.h"
38 #include "pipe/p_shader_tokens.h"
39 #include "pipe/p_state.h"
41 #include "util/u_format.h"
42 #include "util/u_memory.h"
43 #include "util/u_math.h"
44 #include "util/u_blitter.h"
45 #include "util/u_draw_quad.h"
46 #include "util/u_sampler.h"
47 #include "util/u_simple_shaders.h"
48 #include "util/u_surface.h"
49 #include "util/u_texture.h"
50 #include "util/u_upload_mgr.h"
52 #define INVALID_PTR ((void*)~0)
54 #define GET_CLEAR_BLEND_STATE_IDX(clear_buffers) \
55 ((clear_buffers) / PIPE_CLEAR_COLOR0)
57 #define NUM_RESOLVE_FRAG_SHADERS 5 /* MSAA 2x, 4x, 8x, 16x, 32x */
58 #define GET_MSAA_RESOLVE_FS_IDX(nr_samples) (util_logbase2(nr_samples)-1)
60 struct blitter_context_priv
62 struct blitter_context base
;
64 float vertices
[4][2][4]; /**< {pos, color} or {pos, texcoord} */
66 /* Templates for various state objects. */
68 /* Constant state objects. */
70 void *vs
; /**< Vertex shader which passes {pos, generic} to the output.*/
71 void *vs_pos_only
[4]; /**< Vertex shader which passes pos to the output.*/
72 void *vs_layered
; /**< Vertex shader which sets LAYER = INSTANCEID. */
74 /* Fragment shaders. */
76 void *fs_write_one_cbuf
;
77 void *fs_write_all_cbufs
;
79 /* FS which outputs a color from a texture.
80 * The first index indicates the texture type / destination type,
81 * the second index is the PIPE_TEXTURE_* to be sampled. */
82 void *fs_texfetch_col
[5][PIPE_MAX_TEXTURE_TYPES
];
84 /* FS which outputs a depth from a texture,
85 where the index is PIPE_TEXTURE_* to be sampled. */
86 void *fs_texfetch_depth
[PIPE_MAX_TEXTURE_TYPES
];
87 void *fs_texfetch_depthstencil
[PIPE_MAX_TEXTURE_TYPES
];
88 void *fs_texfetch_stencil
[PIPE_MAX_TEXTURE_TYPES
];
90 /* FS which outputs one sample from a multisample texture. */
91 void *fs_texfetch_col_msaa
[5][PIPE_MAX_TEXTURE_TYPES
];
92 void *fs_texfetch_depth_msaa
[PIPE_MAX_TEXTURE_TYPES
];
93 void *fs_texfetch_depthstencil_msaa
[PIPE_MAX_TEXTURE_TYPES
];
94 void *fs_texfetch_stencil_msaa
[PIPE_MAX_TEXTURE_TYPES
];
96 /* FS which outputs an average of all samples. */
97 void *fs_resolve
[PIPE_MAX_TEXTURE_TYPES
][NUM_RESOLVE_FRAG_SHADERS
][2];
100 void *blend
[PIPE_MASK_RGBA
+1][2]; /**< blend state with writemask */
101 void *blend_clear
[GET_CLEAR_BLEND_STATE_IDX(PIPE_CLEAR_COLOR
)+1];
103 /* Depth stencil alpha state. */
104 void *dsa_write_depth_stencil
;
105 void *dsa_write_depth_keep_stencil
;
106 void *dsa_keep_depth_stencil
;
107 void *dsa_keep_depth_write_stencil
;
109 /* Vertex elements states. */
111 void *velem_state_readbuf
[4]; /**< X, XY, XYZ, XYZW */
115 void *sampler_state_linear
;
116 void *sampler_state_rect
;
117 void *sampler_state_rect_linear
;
119 /* Rasterizer state. */
120 void *rs_state
, *rs_state_scissor
, *rs_discard_state
;
122 /* Viewport state. */
123 struct pipe_viewport_state viewport
;
125 /* Destination surface dimensions. */
129 boolean has_geometry_shader
;
130 boolean has_tessellation
;
132 boolean has_stream_out
;
133 boolean has_stencil_export
;
134 boolean has_texture_multisample
;
135 boolean cached_all_shaders
;
137 /* The Draw module overrides these functions.
138 * Always create the blitter before Draw. */
139 void (*bind_fs_state
)(struct pipe_context
*, void *);
140 void (*delete_fs_state
)(struct pipe_context
*, void *);
143 static struct pipe_surface
*
144 util_blitter_get_next_surface_layer(struct pipe_context
*pipe
,
145 struct pipe_surface
*surf
);
147 struct blitter_context
*util_blitter_create(struct pipe_context
*pipe
)
149 struct blitter_context_priv
*ctx
;
150 struct pipe_blend_state blend
;
151 struct pipe_depth_stencil_alpha_state dsa
;
152 struct pipe_rasterizer_state rs_state
;
153 struct pipe_sampler_state sampler_state
;
154 struct pipe_vertex_element velem
[2];
157 ctx
= CALLOC_STRUCT(blitter_context_priv
);
161 ctx
->base
.pipe
= pipe
;
162 ctx
->base
.draw_rectangle
= util_blitter_draw_rectangle
;
163 ctx
->base
.get_next_surface_layer
= util_blitter_get_next_surface_layer
;
165 ctx
->bind_fs_state
= pipe
->bind_fs_state
;
166 ctx
->delete_fs_state
= pipe
->delete_fs_state
;
168 /* init state objects for them to be considered invalid */
169 ctx
->base
.saved_blend_state
= INVALID_PTR
;
170 ctx
->base
.saved_dsa_state
= INVALID_PTR
;
171 ctx
->base
.saved_rs_state
= INVALID_PTR
;
172 ctx
->base
.saved_fs
= INVALID_PTR
;
173 ctx
->base
.saved_vs
= INVALID_PTR
;
174 ctx
->base
.saved_gs
= INVALID_PTR
;
175 ctx
->base
.saved_velem_state
= INVALID_PTR
;
176 ctx
->base
.saved_fb_state
.nr_cbufs
= ~0;
177 ctx
->base
.saved_num_sampler_views
= ~0;
178 ctx
->base
.saved_num_sampler_states
= ~0;
179 ctx
->base
.saved_num_so_targets
= ~0;
181 ctx
->has_geometry_shader
=
182 pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_GEOMETRY
,
183 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0;
185 ctx
->has_tessellation
=
186 pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_TESS_CTRL
,
187 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0;
189 ctx
->has_stream_out
=
190 pipe
->screen
->get_param(pipe
->screen
,
191 PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
) != 0;
193 ctx
->has_stencil_export
=
194 pipe
->screen
->get_param(pipe
->screen
,
195 PIPE_CAP_SHADER_STENCIL_EXPORT
);
197 ctx
->has_texture_multisample
=
198 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_TEXTURE_MULTISAMPLE
);
200 /* blend state objects */
201 memset(&blend
, 0, sizeof(blend
));
203 for (i
= 0; i
<= PIPE_MASK_RGBA
; i
++) {
204 for (j
= 0; j
< 2; j
++) {
205 memset(&blend
.rt
[0], 0, sizeof(blend
.rt
[0]));
206 blend
.rt
[0].colormask
= i
;
208 blend
.rt
[0].blend_enable
= 1;
209 blend
.rt
[0].rgb_func
= PIPE_BLEND_ADD
;
210 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_SRC_ALPHA
;
211 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
212 blend
.rt
[0].alpha_func
= PIPE_BLEND_ADD
;
213 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_SRC_ALPHA
;
214 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
216 ctx
->blend
[i
][j
] = pipe
->create_blend_state(pipe
, &blend
);
220 /* depth stencil alpha state objects */
221 memset(&dsa
, 0, sizeof(dsa
));
222 ctx
->dsa_keep_depth_stencil
=
223 pipe
->create_depth_stencil_alpha_state(pipe
, &dsa
);
225 dsa
.depth
.enabled
= 1;
226 dsa
.depth
.writemask
= 1;
227 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
228 ctx
->dsa_write_depth_keep_stencil
=
229 pipe
->create_depth_stencil_alpha_state(pipe
, &dsa
);
231 dsa
.stencil
[0].enabled
= 1;
232 dsa
.stencil
[0].func
= PIPE_FUNC_ALWAYS
;
233 dsa
.stencil
[0].fail_op
= PIPE_STENCIL_OP_REPLACE
;
234 dsa
.stencil
[0].zpass_op
= PIPE_STENCIL_OP_REPLACE
;
235 dsa
.stencil
[0].zfail_op
= PIPE_STENCIL_OP_REPLACE
;
236 dsa
.stencil
[0].valuemask
= 0xff;
237 dsa
.stencil
[0].writemask
= 0xff;
238 ctx
->dsa_write_depth_stencil
=
239 pipe
->create_depth_stencil_alpha_state(pipe
, &dsa
);
241 dsa
.depth
.enabled
= 0;
242 dsa
.depth
.writemask
= 0;
243 ctx
->dsa_keep_depth_write_stencil
=
244 pipe
->create_depth_stencil_alpha_state(pipe
, &dsa
);
247 memset(&sampler_state
, 0, sizeof(sampler_state
));
248 sampler_state
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
249 sampler_state
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
250 sampler_state
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
251 sampler_state
.normalized_coords
= 1;
252 ctx
->sampler_state
= pipe
->create_sampler_state(pipe
, &sampler_state
);
253 sampler_state
.normalized_coords
= 0;
254 ctx
->sampler_state_rect
= pipe
->create_sampler_state(pipe
, &sampler_state
);
256 sampler_state
.min_img_filter
= PIPE_TEX_FILTER_LINEAR
;
257 sampler_state
.mag_img_filter
= PIPE_TEX_FILTER_LINEAR
;
258 sampler_state
.normalized_coords
= 1;
259 ctx
->sampler_state_linear
= pipe
->create_sampler_state(pipe
, &sampler_state
);
260 sampler_state
.normalized_coords
= 0;
261 ctx
->sampler_state_rect_linear
= pipe
->create_sampler_state(pipe
, &sampler_state
);
263 /* rasterizer state */
264 memset(&rs_state
, 0, sizeof(rs_state
));
265 rs_state
.cull_face
= PIPE_FACE_NONE
;
266 rs_state
.half_pixel_center
= 1;
267 rs_state
.bottom_edge_rule
= 1;
268 rs_state
.flatshade
= 1;
269 rs_state
.depth_clip
= 1;
270 ctx
->rs_state
= pipe
->create_rasterizer_state(pipe
, &rs_state
);
272 rs_state
.scissor
= 1;
273 ctx
->rs_state_scissor
= pipe
->create_rasterizer_state(pipe
, &rs_state
);
275 if (ctx
->has_stream_out
) {
276 rs_state
.scissor
= 0;
277 rs_state
.rasterizer_discard
= 1;
278 ctx
->rs_discard_state
= pipe
->create_rasterizer_state(pipe
, &rs_state
);
281 ctx
->base
.cb_slot
= 0; /* 0 for now */
282 ctx
->base
.vb_slot
= 0; /* 0 for now */
284 /* vertex elements states */
285 memset(&velem
[0], 0, sizeof(velem
[0]) * 2);
286 for (i
= 0; i
< 2; i
++) {
287 velem
[i
].src_offset
= i
* 4 * sizeof(float);
288 velem
[i
].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
289 velem
[i
].vertex_buffer_index
= ctx
->base
.vb_slot
;
291 ctx
->velem_state
= pipe
->create_vertex_elements_state(pipe
, 2, &velem
[0]);
293 if (ctx
->has_stream_out
) {
294 static enum pipe_format formats
[4] = {
295 PIPE_FORMAT_R32_UINT
,
296 PIPE_FORMAT_R32G32_UINT
,
297 PIPE_FORMAT_R32G32B32_UINT
,
298 PIPE_FORMAT_R32G32B32A32_UINT
301 for (i
= 0; i
< 4; i
++) {
302 velem
[0].src_format
= formats
[i
];
303 velem
[0].vertex_buffer_index
= ctx
->base
.vb_slot
;
304 ctx
->velem_state_readbuf
[i
] =
305 pipe
->create_vertex_elements_state(pipe
, 1, &velem
[0]);
310 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_TGSI_INSTANCEID
) &&
311 pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_TGSI_VS_LAYER_VIEWPORT
);
313 /* set invariant vertex coordinates */
314 for (i
= 0; i
< 4; i
++)
315 ctx
->vertices
[i
][0][3] = 1; /*v.w*/
320 static void bind_vs_pos_only(struct blitter_context_priv
*ctx
,
321 unsigned num_so_channels
)
323 struct pipe_context
*pipe
= ctx
->base
.pipe
;
324 int index
= num_so_channels
? num_so_channels
- 1 : 0;
326 if (!ctx
->vs_pos_only
[index
]) {
327 struct pipe_stream_output_info so
;
328 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
};
329 const uint semantic_indices
[] = { 0 };
331 memset(&so
, 0, sizeof(so
));
333 so
.output
[0].num_components
= num_so_channels
;
334 so
.stride
[0] = num_so_channels
;
336 ctx
->vs_pos_only
[index
] =
337 util_make_vertex_passthrough_shader_with_so(pipe
, 1, semantic_names
,
338 semantic_indices
, FALSE
,
342 pipe
->bind_vs_state(pipe
, ctx
->vs_pos_only
[index
]);
345 static void bind_vs_passthrough(struct blitter_context_priv
*ctx
)
347 struct pipe_context
*pipe
= ctx
->base
.pipe
;
350 const uint semantic_names
[] = { TGSI_SEMANTIC_POSITION
,
351 TGSI_SEMANTIC_GENERIC
};
352 const uint semantic_indices
[] = { 0, 0 };
354 util_make_vertex_passthrough_shader(pipe
, 2, semantic_names
,
355 semantic_indices
, FALSE
);
358 pipe
->bind_vs_state(pipe
, ctx
->vs
);
361 static void bind_vs_layered(struct blitter_context_priv
*ctx
)
363 struct pipe_context
*pipe
= ctx
->base
.pipe
;
365 if (!ctx
->vs_layered
) {
366 ctx
->vs_layered
= util_make_layered_clear_vertex_shader(pipe
);
369 pipe
->bind_vs_state(pipe
, ctx
->vs_layered
);
372 static void bind_fs_empty(struct blitter_context_priv
*ctx
)
374 struct pipe_context
*pipe
= ctx
->base
.pipe
;
376 if (!ctx
->fs_empty
) {
377 assert(!ctx
->cached_all_shaders
);
378 ctx
->fs_empty
= util_make_empty_fragment_shader(pipe
);
381 ctx
->bind_fs_state(pipe
, ctx
->fs_empty
);
384 static void bind_fs_write_one_cbuf(struct blitter_context_priv
*ctx
)
386 struct pipe_context
*pipe
= ctx
->base
.pipe
;
388 if (!ctx
->fs_write_one_cbuf
) {
389 assert(!ctx
->cached_all_shaders
);
390 ctx
->fs_write_one_cbuf
=
391 util_make_fragment_passthrough_shader(pipe
, TGSI_SEMANTIC_GENERIC
,
392 TGSI_INTERPOLATE_CONSTANT
, FALSE
);
395 ctx
->bind_fs_state(pipe
, ctx
->fs_write_one_cbuf
);
398 static void bind_fs_write_all_cbufs(struct blitter_context_priv
*ctx
)
400 struct pipe_context
*pipe
= ctx
->base
.pipe
;
402 if (!ctx
->fs_write_all_cbufs
) {
403 assert(!ctx
->cached_all_shaders
);
404 ctx
->fs_write_all_cbufs
=
405 util_make_fragment_passthrough_shader(pipe
, TGSI_SEMANTIC_GENERIC
,
406 TGSI_INTERPOLATE_CONSTANT
, TRUE
);
409 ctx
->bind_fs_state(pipe
, ctx
->fs_write_all_cbufs
);
412 void util_blitter_destroy(struct blitter_context
*blitter
)
414 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
415 struct pipe_context
*pipe
= blitter
->pipe
;
418 for (i
= 0; i
<= PIPE_MASK_RGBA
; i
++)
419 for (j
= 0; j
< 2; j
++)
420 pipe
->delete_blend_state(pipe
, ctx
->blend
[i
][j
]);
422 for (i
= 0; i
< ARRAY_SIZE(ctx
->blend_clear
); i
++) {
423 if (ctx
->blend_clear
[i
])
424 pipe
->delete_blend_state(pipe
, ctx
->blend_clear
[i
]);
426 pipe
->delete_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
427 pipe
->delete_depth_stencil_alpha_state(pipe
,
428 ctx
->dsa_write_depth_keep_stencil
);
429 pipe
->delete_depth_stencil_alpha_state(pipe
, ctx
->dsa_write_depth_stencil
);
430 pipe
->delete_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_write_stencil
);
432 pipe
->delete_rasterizer_state(pipe
, ctx
->rs_state
);
433 pipe
->delete_rasterizer_state(pipe
, ctx
->rs_state_scissor
);
434 if (ctx
->rs_discard_state
)
435 pipe
->delete_rasterizer_state(pipe
, ctx
->rs_discard_state
);
437 pipe
->delete_vs_state(pipe
, ctx
->vs
);
438 for (i
= 0; i
< 4; i
++)
439 if (ctx
->vs_pos_only
[i
])
440 pipe
->delete_vs_state(pipe
, ctx
->vs_pos_only
[i
]);
442 pipe
->delete_vs_state(pipe
, ctx
->vs_layered
);
443 pipe
->delete_vertex_elements_state(pipe
, ctx
->velem_state
);
444 for (i
= 0; i
< 4; i
++) {
445 if (ctx
->velem_state_readbuf
[i
]) {
446 pipe
->delete_vertex_elements_state(pipe
, ctx
->velem_state_readbuf
[i
]);
450 for (i
= 0; i
< PIPE_MAX_TEXTURE_TYPES
; i
++) {
451 for (unsigned type
= 0; type
< ARRAY_SIZE(ctx
->fs_texfetch_col
); ++type
) {
452 if (ctx
->fs_texfetch_col
[type
][i
])
453 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_col
[type
][i
]);
454 if (ctx
->fs_texfetch_col_msaa
[type
][i
])
455 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_col_msaa
[type
][i
]);
458 if (ctx
->fs_texfetch_depth
[i
])
459 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_depth
[i
]);
460 if (ctx
->fs_texfetch_depthstencil
[i
])
461 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_depthstencil
[i
]);
462 if (ctx
->fs_texfetch_stencil
[i
])
463 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_stencil
[i
]);
465 if (ctx
->fs_texfetch_depth_msaa
[i
])
466 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_depth_msaa
[i
]);
467 if (ctx
->fs_texfetch_depthstencil_msaa
[i
])
468 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_depthstencil_msaa
[i
]);
469 if (ctx
->fs_texfetch_stencil_msaa
[i
])
470 ctx
->delete_fs_state(pipe
, ctx
->fs_texfetch_stencil_msaa
[i
]);
472 for (j
= 0; j
< ARRAY_SIZE(ctx
->fs_resolve
[i
]); j
++)
473 for (f
= 0; f
< 2; f
++)
474 if (ctx
->fs_resolve
[i
][j
][f
])
475 ctx
->delete_fs_state(pipe
, ctx
->fs_resolve
[i
][j
][f
]);
479 ctx
->delete_fs_state(pipe
, ctx
->fs_empty
);
480 if (ctx
->fs_write_one_cbuf
)
481 ctx
->delete_fs_state(pipe
, ctx
->fs_write_one_cbuf
);
482 if (ctx
->fs_write_all_cbufs
)
483 ctx
->delete_fs_state(pipe
, ctx
->fs_write_all_cbufs
);
485 pipe
->delete_sampler_state(pipe
, ctx
->sampler_state_rect_linear
);
486 pipe
->delete_sampler_state(pipe
, ctx
->sampler_state_rect
);
487 pipe
->delete_sampler_state(pipe
, ctx
->sampler_state_linear
);
488 pipe
->delete_sampler_state(pipe
, ctx
->sampler_state
);
492 void util_blitter_set_texture_multisample(struct blitter_context
*blitter
,
495 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
497 ctx
->has_texture_multisample
= supported
;
500 void util_blitter_set_running_flag(struct blitter_context
*blitter
)
502 if (blitter
->running
) {
503 _debug_printf("u_blitter:%i: Caught recursion. This is a driver bug.\n",
506 blitter
->running
= TRUE
;
508 blitter
->pipe
->set_active_query_state(blitter
->pipe
, false);
511 void util_blitter_unset_running_flag(struct blitter_context
*blitter
)
513 if (!blitter
->running
) {
514 _debug_printf("u_blitter:%i: Caught recursion. This is a driver bug.\n",
517 blitter
->running
= FALSE
;
519 blitter
->pipe
->set_active_query_state(blitter
->pipe
, true);
522 static void blitter_check_saved_vertex_states(struct blitter_context_priv
*ctx
)
524 assert(ctx
->base
.saved_velem_state
!= INVALID_PTR
);
525 assert(ctx
->base
.saved_vs
!= INVALID_PTR
);
526 assert(!ctx
->has_geometry_shader
|| ctx
->base
.saved_gs
!= INVALID_PTR
);
527 assert(!ctx
->has_tessellation
|| ctx
->base
.saved_tcs
!= INVALID_PTR
);
528 assert(!ctx
->has_tessellation
|| ctx
->base
.saved_tes
!= INVALID_PTR
);
529 assert(!ctx
->has_stream_out
|| ctx
->base
.saved_num_so_targets
!= ~0u);
530 assert(ctx
->base
.saved_rs_state
!= INVALID_PTR
);
533 void util_blitter_restore_vertex_states(struct blitter_context
*blitter
)
535 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
536 struct pipe_context
*pipe
= ctx
->base
.pipe
;
540 pipe
->set_vertex_buffers(pipe
, ctx
->base
.vb_slot
, 1,
541 &ctx
->base
.saved_vertex_buffer
);
542 pipe_vertex_buffer_unreference(&ctx
->base
.saved_vertex_buffer
);
544 /* Vertex elements. */
545 pipe
->bind_vertex_elements_state(pipe
, ctx
->base
.saved_velem_state
);
546 ctx
->base
.saved_velem_state
= INVALID_PTR
;
549 pipe
->bind_vs_state(pipe
, ctx
->base
.saved_vs
);
550 ctx
->base
.saved_vs
= INVALID_PTR
;
552 /* Geometry shader. */
553 if (ctx
->has_geometry_shader
) {
554 pipe
->bind_gs_state(pipe
, ctx
->base
.saved_gs
);
555 ctx
->base
.saved_gs
= INVALID_PTR
;
558 if (ctx
->has_tessellation
) {
559 pipe
->bind_tcs_state(pipe
, ctx
->base
.saved_tcs
);
560 pipe
->bind_tes_state(pipe
, ctx
->base
.saved_tes
);
561 ctx
->base
.saved_tcs
= INVALID_PTR
;
562 ctx
->base
.saved_tes
= INVALID_PTR
;
565 /* Stream outputs. */
566 if (ctx
->has_stream_out
) {
567 unsigned offsets
[PIPE_MAX_SO_BUFFERS
];
568 for (i
= 0; i
< ctx
->base
.saved_num_so_targets
; i
++)
569 offsets
[i
] = (unsigned)-1;
570 pipe
->set_stream_output_targets(pipe
,
571 ctx
->base
.saved_num_so_targets
,
572 ctx
->base
.saved_so_targets
, offsets
);
574 for (i
= 0; i
< ctx
->base
.saved_num_so_targets
; i
++)
575 pipe_so_target_reference(&ctx
->base
.saved_so_targets
[i
], NULL
);
577 ctx
->base
.saved_num_so_targets
= ~0;
581 pipe
->bind_rasterizer_state(pipe
, ctx
->base
.saved_rs_state
);
582 ctx
->base
.saved_rs_state
= INVALID_PTR
;
585 static void blitter_check_saved_fragment_states(struct blitter_context_priv
*ctx
)
587 assert(ctx
->base
.saved_fs
!= INVALID_PTR
);
588 assert(ctx
->base
.saved_dsa_state
!= INVALID_PTR
);
589 assert(ctx
->base
.saved_blend_state
!= INVALID_PTR
);
592 void util_blitter_restore_fragment_states(struct blitter_context
*blitter
)
594 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
595 struct pipe_context
*pipe
= ctx
->base
.pipe
;
597 /* Fragment shader. */
598 ctx
->bind_fs_state(pipe
, ctx
->base
.saved_fs
);
599 ctx
->base
.saved_fs
= INVALID_PTR
;
601 /* Depth, stencil, alpha. */
602 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->base
.saved_dsa_state
);
603 ctx
->base
.saved_dsa_state
= INVALID_PTR
;
606 pipe
->bind_blend_state(pipe
, ctx
->base
.saved_blend_state
);
607 ctx
->base
.saved_blend_state
= INVALID_PTR
;
610 if (ctx
->base
.is_sample_mask_saved
) {
611 pipe
->set_sample_mask(pipe
, ctx
->base
.saved_sample_mask
);
612 ctx
->base
.is_sample_mask_saved
= FALSE
;
615 /* Miscellaneous states. */
616 /* XXX check whether these are saved and whether they need to be restored
617 * (depending on the operation) */
618 pipe
->set_stencil_ref(pipe
, &ctx
->base
.saved_stencil_ref
);
619 pipe
->set_viewport_states(pipe
, 0, 1, &ctx
->base
.saved_viewport
);
622 static void blitter_check_saved_fb_state(struct blitter_context_priv
*ctx
)
624 assert(ctx
->base
.saved_fb_state
.nr_cbufs
!= ~0u);
627 static void blitter_disable_render_cond(struct blitter_context_priv
*ctx
)
629 struct pipe_context
*pipe
= ctx
->base
.pipe
;
631 if (ctx
->base
.saved_render_cond_query
) {
632 pipe
->render_condition(pipe
, NULL
, FALSE
, 0);
636 void util_blitter_restore_render_cond(struct blitter_context
*blitter
)
638 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
639 struct pipe_context
*pipe
= ctx
->base
.pipe
;
641 if (ctx
->base
.saved_render_cond_query
) {
642 pipe
->render_condition(pipe
, ctx
->base
.saved_render_cond_query
,
643 ctx
->base
.saved_render_cond_cond
,
644 ctx
->base
.saved_render_cond_mode
);
645 ctx
->base
.saved_render_cond_query
= NULL
;
649 void util_blitter_restore_fb_state(struct blitter_context
*blitter
)
651 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
652 struct pipe_context
*pipe
= ctx
->base
.pipe
;
654 pipe
->set_framebuffer_state(pipe
, &ctx
->base
.saved_fb_state
);
655 util_unreference_framebuffer_state(&ctx
->base
.saved_fb_state
);
658 static void blitter_check_saved_textures(struct blitter_context_priv
*ctx
)
660 assert(ctx
->base
.saved_num_sampler_states
!= ~0u);
661 assert(ctx
->base
.saved_num_sampler_views
!= ~0u);
664 void util_blitter_restore_textures(struct blitter_context
*blitter
)
666 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
667 struct pipe_context
*pipe
= ctx
->base
.pipe
;
670 /* Fragment sampler states. */
671 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_FRAGMENT
, 0,
672 ctx
->base
.saved_num_sampler_states
,
673 ctx
->base
.saved_sampler_states
);
675 ctx
->base
.saved_num_sampler_states
= ~0;
677 /* Fragment sampler views. */
678 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0,
679 ctx
->base
.saved_num_sampler_views
,
680 ctx
->base
.saved_sampler_views
);
682 for (i
= 0; i
< ctx
->base
.saved_num_sampler_views
; i
++)
683 pipe_sampler_view_reference(&ctx
->base
.saved_sampler_views
[i
], NULL
);
685 ctx
->base
.saved_num_sampler_views
= ~0;
688 void util_blitter_restore_constant_buffer_state(struct blitter_context
*blitter
)
690 struct pipe_context
*pipe
= blitter
->pipe
;
692 pipe
->set_constant_buffer(pipe
, PIPE_SHADER_FRAGMENT
, blitter
->cb_slot
,
693 &blitter
->saved_fs_constant_buffer
);
694 pipe_resource_reference(&blitter
->saved_fs_constant_buffer
.buffer
, NULL
);
697 static void blitter_set_rectangle(struct blitter_context_priv
*ctx
,
698 int x1
, int y1
, int x2
, int y2
,
703 /* set vertex positions */
704 ctx
->vertices
[0][0][0] = (float)x1
/ ctx
->dst_width
* 2.0f
- 1.0f
; /*v0.x*/
705 ctx
->vertices
[0][0][1] = (float)y1
/ ctx
->dst_height
* 2.0f
- 1.0f
; /*v0.y*/
707 ctx
->vertices
[1][0][0] = (float)x2
/ ctx
->dst_width
* 2.0f
- 1.0f
; /*v1.x*/
708 ctx
->vertices
[1][0][1] = (float)y1
/ ctx
->dst_height
* 2.0f
- 1.0f
; /*v1.y*/
710 ctx
->vertices
[2][0][0] = (float)x2
/ ctx
->dst_width
* 2.0f
- 1.0f
; /*v2.x*/
711 ctx
->vertices
[2][0][1] = (float)y2
/ ctx
->dst_height
* 2.0f
- 1.0f
; /*v2.y*/
713 ctx
->vertices
[3][0][0] = (float)x1
/ ctx
->dst_width
* 2.0f
- 1.0f
; /*v3.x*/
714 ctx
->vertices
[3][0][1] = (float)y2
/ ctx
->dst_height
* 2.0f
- 1.0f
; /*v3.y*/
716 for (i
= 0; i
< 4; i
++)
717 ctx
->vertices
[i
][0][2] = depth
; /*z*/
720 ctx
->viewport
.scale
[0] = 0.5f
* ctx
->dst_width
;
721 ctx
->viewport
.scale
[1] = 0.5f
* ctx
->dst_height
;
722 ctx
->viewport
.scale
[2] = 1.0f
;
723 ctx
->viewport
.translate
[0] = 0.5f
* ctx
->dst_width
;
724 ctx
->viewport
.translate
[1] = 0.5f
* ctx
->dst_height
;
725 ctx
->viewport
.translate
[2] = 0.0f
;
726 ctx
->base
.pipe
->set_viewport_states(ctx
->base
.pipe
, 0, 1, &ctx
->viewport
);
729 static void blitter_set_clear_color(struct blitter_context_priv
*ctx
,
730 const union pipe_color_union
*color
)
735 for (i
= 0; i
< 4; i
++) {
736 uint32_t *uiverts
= (uint32_t *)ctx
->vertices
[i
][1];
737 uiverts
[0] = color
->ui
[0];
738 uiverts
[1] = color
->ui
[1];
739 uiverts
[2] = color
->ui
[2];
740 uiverts
[3] = color
->ui
[3];
743 for (i
= 0; i
< 4; i
++) {
744 ctx
->vertices
[i
][1][0] = 0;
745 ctx
->vertices
[i
][1][1] = 0;
746 ctx
->vertices
[i
][1][2] = 0;
747 ctx
->vertices
[i
][1][3] = 0;
752 static void get_texcoords(struct pipe_sampler_view
*src
,
753 unsigned src_width0
, unsigned src_height0
,
754 int x1
, int y1
, int x2
, int y2
,
757 struct pipe_resource
*tex
= src
->texture
;
758 unsigned level
= src
->u
.tex
.first_level
;
759 boolean normalized
= tex
->target
!= PIPE_TEXTURE_RECT
&&
760 tex
->nr_samples
<= 1;
763 out
[0] = x1
/ (float)u_minify(src_width0
, level
);
764 out
[1] = y1
/ (float)u_minify(src_height0
, level
);
765 out
[2] = x2
/ (float)u_minify(src_width0
, level
);
766 out
[3] = y2
/ (float)u_minify(src_height0
, level
);
775 static void set_texcoords_in_vertices(const float coord
[4],
776 float *out
, unsigned stride
)
778 out
[0] = coord
[0]; /*t0.s*/
779 out
[1] = coord
[1]; /*t0.t*/
781 out
[0] = coord
[2]; /*t1.s*/
782 out
[1] = coord
[1]; /*t1.t*/
784 out
[0] = coord
[2]; /*t2.s*/
785 out
[1] = coord
[3]; /*t2.t*/
787 out
[0] = coord
[0]; /*t3.s*/
788 out
[1] = coord
[3]; /*t3.t*/
791 static void blitter_set_texcoords(struct blitter_context_priv
*ctx
,
792 struct pipe_sampler_view
*src
,
793 unsigned src_width0
, unsigned src_height0
,
794 float layer
, unsigned sample
,
795 int x1
, int y1
, int x2
, int y2
)
799 float face_coord
[4][2];
801 get_texcoords(src
, src_width0
, src_height0
, x1
, y1
, x2
, y2
, coord
);
803 if (src
->texture
->target
== PIPE_TEXTURE_CUBE
||
804 src
->texture
->target
== PIPE_TEXTURE_CUBE_ARRAY
) {
805 set_texcoords_in_vertices(coord
, &face_coord
[0][0], 2);
806 util_map_texcoords2d_onto_cubemap((unsigned)layer
% 6,
807 /* pointer, stride in floats */
808 &face_coord
[0][0], 2,
809 &ctx
->vertices
[0][1][0], 8,
812 set_texcoords_in_vertices(coord
, &ctx
->vertices
[0][1][0], 8);
816 switch (src
->texture
->target
) {
817 case PIPE_TEXTURE_3D
:
819 float r
= layer
/ (float)u_minify(src
->texture
->depth0
,
820 src
->u
.tex
.first_level
);
821 for (i
= 0; i
< 4; i
++)
822 ctx
->vertices
[i
][1][2] = r
; /*r*/
826 case PIPE_TEXTURE_1D_ARRAY
:
827 for (i
= 0; i
< 4; i
++)
828 ctx
->vertices
[i
][1][1] = (float) layer
; /*t*/
831 case PIPE_TEXTURE_2D_ARRAY
:
832 for (i
= 0; i
< 4; i
++) {
833 ctx
->vertices
[i
][1][2] = (float) layer
; /*r*/
834 ctx
->vertices
[i
][1][3] = (float) sample
; /*q*/
838 case PIPE_TEXTURE_CUBE_ARRAY
:
839 for (i
= 0; i
< 4; i
++)
840 ctx
->vertices
[i
][1][3] = (float) ((unsigned)layer
/ 6); /*w*/
843 case PIPE_TEXTURE_2D
:
844 for (i
= 0; i
< 4; i
++) {
845 ctx
->vertices
[i
][1][3] = (float) sample
; /*r*/
853 static void blitter_set_dst_dimensions(struct blitter_context_priv
*ctx
,
854 unsigned width
, unsigned height
)
856 ctx
->dst_width
= width
;
857 ctx
->dst_height
= height
;
860 static void *blitter_get_fs_texfetch_col(struct blitter_context_priv
*ctx
,
861 enum pipe_format src_format
,
862 enum pipe_format dst_format
,
863 enum pipe_texture_target target
,
864 unsigned src_nr_samples
,
865 unsigned dst_nr_samples
,
868 struct pipe_context
*pipe
= ctx
->base
.pipe
;
869 unsigned tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, src_nr_samples
);
870 enum tgsi_return_type stype
;
871 enum tgsi_return_type dtype
;
874 assert(target
< PIPE_MAX_TEXTURE_TYPES
);
876 if (util_format_is_pure_uint(src_format
)) {
877 stype
= TGSI_RETURN_TYPE_UINT
;
878 if (util_format_is_pure_uint(dst_format
)) {
879 dtype
= TGSI_RETURN_TYPE_UINT
;
882 assert(util_format_is_pure_sint(dst_format
));
883 dtype
= TGSI_RETURN_TYPE_SINT
;
886 } else if (util_format_is_pure_sint(src_format
)) {
887 stype
= TGSI_RETURN_TYPE_SINT
;
888 if (util_format_is_pure_sint(dst_format
)) {
889 dtype
= TGSI_RETURN_TYPE_SINT
;
892 assert(util_format_is_pure_uint(dst_format
));
893 dtype
= TGSI_RETURN_TYPE_UINT
;
897 assert(!util_format_is_pure_uint(dst_format
) &&
898 !util_format_is_pure_sint(dst_format
));
899 dtype
= stype
= TGSI_RETURN_TYPE_FLOAT
;
903 if (src_nr_samples
> 1) {
906 /* OpenGL requires that integer textures just copy 1 sample instead
909 if (dst_nr_samples
<= 1 &&
910 stype
!= TGSI_RETURN_TYPE_UINT
&&
911 stype
!= TGSI_RETURN_TYPE_SINT
) {
912 /* The destination has one sample, so we'll do color resolve. */
913 unsigned index
= GET_MSAA_RESOLVE_FS_IDX(src_nr_samples
);
917 shader
= &ctx
->fs_resolve
[target
][index
][filter
];
920 assert(!ctx
->cached_all_shaders
);
921 if (filter
== PIPE_TEX_FILTER_LINEAR
) {
922 *shader
= util_make_fs_msaa_resolve_bilinear(pipe
, tgsi_tex
,
927 *shader
= util_make_fs_msaa_resolve(pipe
, tgsi_tex
,
934 /* The destination has multiple samples, we'll do
935 * an MSAA->MSAA copy.
937 shader
= &ctx
->fs_texfetch_col_msaa
[type
][target
];
939 /* Create the fragment shader on-demand. */
941 assert(!ctx
->cached_all_shaders
);
942 *shader
= util_make_fs_blit_msaa_color(pipe
, tgsi_tex
, stype
, dtype
);
948 void **shader
= &ctx
->fs_texfetch_col
[type
][target
];
950 /* Create the fragment shader on-demand. */
952 assert(!ctx
->cached_all_shaders
);
953 *shader
= util_make_fragment_tex_shader(pipe
, tgsi_tex
,
954 TGSI_INTERPOLATE_LINEAR
,
964 void *blitter_get_fs_texfetch_depth(struct blitter_context_priv
*ctx
,
965 enum pipe_texture_target target
,
968 struct pipe_context
*pipe
= ctx
->base
.pipe
;
970 assert(target
< PIPE_MAX_TEXTURE_TYPES
);
972 if (nr_samples
> 1) {
973 void **shader
= &ctx
->fs_texfetch_depth_msaa
[target
];
975 /* Create the fragment shader on-demand. */
978 assert(!ctx
->cached_all_shaders
);
979 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, nr_samples
);
980 *shader
= util_make_fs_blit_msaa_depth(pipe
, tgsi_tex
);
985 void **shader
= &ctx
->fs_texfetch_depth
[target
];
987 /* Create the fragment shader on-demand. */
990 assert(!ctx
->cached_all_shaders
);
991 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, 0);
993 util_make_fragment_tex_shader_writedepth(pipe
, tgsi_tex
,
994 TGSI_INTERPOLATE_LINEAR
,
1003 void *blitter_get_fs_texfetch_depthstencil(struct blitter_context_priv
*ctx
,
1004 enum pipe_texture_target target
,
1005 unsigned nr_samples
)
1007 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1009 assert(target
< PIPE_MAX_TEXTURE_TYPES
);
1011 if (nr_samples
> 1) {
1012 void **shader
= &ctx
->fs_texfetch_depthstencil_msaa
[target
];
1014 /* Create the fragment shader on-demand. */
1017 assert(!ctx
->cached_all_shaders
);
1018 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, nr_samples
);
1019 *shader
= util_make_fs_blit_msaa_depthstencil(pipe
, tgsi_tex
);
1024 void **shader
= &ctx
->fs_texfetch_depthstencil
[target
];
1026 /* Create the fragment shader on-demand. */
1029 assert(!ctx
->cached_all_shaders
);
1030 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, 0);
1032 util_make_fragment_tex_shader_writedepthstencil(pipe
, tgsi_tex
,
1033 TGSI_INTERPOLATE_LINEAR
,
1043 void *blitter_get_fs_texfetch_stencil(struct blitter_context_priv
*ctx
,
1044 enum pipe_texture_target target
,
1045 unsigned nr_samples
)
1047 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1049 assert(target
< PIPE_MAX_TEXTURE_TYPES
);
1051 if (nr_samples
> 1) {
1052 void **shader
= &ctx
->fs_texfetch_stencil_msaa
[target
];
1054 /* Create the fragment shader on-demand. */
1057 assert(!ctx
->cached_all_shaders
);
1058 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, nr_samples
);
1059 *shader
= util_make_fs_blit_msaa_stencil(pipe
, tgsi_tex
);
1064 void **shader
= &ctx
->fs_texfetch_stencil
[target
];
1066 /* Create the fragment shader on-demand. */
1069 assert(!ctx
->cached_all_shaders
);
1070 tgsi_tex
= util_pipe_tex_to_tgsi_tex(target
, 0);
1072 util_make_fragment_tex_shader_writestencil(pipe
, tgsi_tex
,
1073 TGSI_INTERPOLATE_LINEAR
,
1083 * Generate and save all fragment shaders that we will ever need for
1084 * blitting. Drivers which use the 'draw' fallbacks will typically use
1085 * this to make sure we generate/use shaders that don't go through the
1086 * draw module's wrapper functions.
1088 void util_blitter_cache_all_shaders(struct blitter_context
*blitter
)
1090 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1091 struct pipe_context
*pipe
= blitter
->pipe
;
1092 struct pipe_screen
*screen
= pipe
->screen
;
1093 unsigned samples
, j
, f
, target
, max_samples
;
1094 boolean has_arraytex
, has_cubearraytex
;
1096 max_samples
= ctx
->has_texture_multisample
? 2 : 1;
1097 has_arraytex
= screen
->get_param(screen
,
1098 PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS
) != 0;
1099 has_cubearraytex
= screen
->get_param(screen
,
1100 PIPE_CAP_CUBE_MAP_ARRAY
) != 0;
1102 /* It only matters if i <= 1 or > 1. */
1103 for (samples
= 1; samples
<= max_samples
; samples
++) {
1104 for (target
= PIPE_TEXTURE_1D
; target
< PIPE_MAX_TEXTURE_TYPES
; target
++) {
1105 if (!has_arraytex
&&
1106 (target
== PIPE_TEXTURE_1D_ARRAY
||
1107 target
== PIPE_TEXTURE_2D_ARRAY
)) {
1110 if (!has_cubearraytex
&&
1111 (target
== PIPE_TEXTURE_CUBE_ARRAY
))
1115 (target
!= PIPE_TEXTURE_2D
&&
1116 target
!= PIPE_TEXTURE_2D_ARRAY
))
1119 /* If samples == 1, the shaders read one texel. If samples >= 1,
1120 * they read one sample.
1122 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_FLOAT
,
1123 PIPE_FORMAT_R32_FLOAT
, target
,
1124 samples
, samples
, 0);
1125 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_UINT
,
1126 PIPE_FORMAT_R32_UINT
, target
,
1127 samples
, samples
, 0);
1128 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_UINT
,
1129 PIPE_FORMAT_R32_SINT
, target
,
1130 samples
, samples
, 0);
1131 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_SINT
,
1132 PIPE_FORMAT_R32_SINT
, target
,
1133 samples
, samples
, 0);
1134 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_SINT
,
1135 PIPE_FORMAT_R32_UINT
, target
,
1136 samples
, samples
, 0);
1137 blitter_get_fs_texfetch_depth(ctx
, target
, samples
);
1138 if (ctx
->has_stencil_export
) {
1139 blitter_get_fs_texfetch_depthstencil(ctx
, target
, samples
);
1140 blitter_get_fs_texfetch_stencil(ctx
, target
, samples
);
1146 /* MSAA resolve shaders. */
1147 for (j
= 2; j
< 32; j
++) {
1148 if (!screen
->is_format_supported(screen
, PIPE_FORMAT_R32_FLOAT
,
1150 PIPE_BIND_SAMPLER_VIEW
)) {
1154 for (f
= 0; f
< 2; f
++) {
1155 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_FLOAT
,
1156 PIPE_FORMAT_R32_FLOAT
, target
,
1158 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_UINT
,
1159 PIPE_FORMAT_R32_UINT
, target
,
1161 blitter_get_fs_texfetch_col(ctx
, PIPE_FORMAT_R32_SINT
,
1162 PIPE_FORMAT_R32_SINT
, target
,
1169 ctx
->fs_empty
= util_make_empty_fragment_shader(pipe
);
1171 ctx
->fs_write_one_cbuf
=
1172 util_make_fragment_passthrough_shader(pipe
, TGSI_SEMANTIC_GENERIC
,
1173 TGSI_INTERPOLATE_CONSTANT
, FALSE
);
1175 ctx
->fs_write_all_cbufs
=
1176 util_make_fragment_passthrough_shader(pipe
, TGSI_SEMANTIC_GENERIC
,
1177 TGSI_INTERPOLATE_CONSTANT
, TRUE
);
1179 ctx
->cached_all_shaders
= TRUE
;
1182 static void blitter_set_common_draw_rect_state(struct blitter_context_priv
*ctx
,
1186 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1188 pipe
->bind_rasterizer_state(pipe
, scissor
? ctx
->rs_state_scissor
1191 bind_vs_layered(ctx
);
1193 bind_vs_passthrough(ctx
);
1195 if (ctx
->has_geometry_shader
)
1196 pipe
->bind_gs_state(pipe
, NULL
);
1197 if (ctx
->has_tessellation
) {
1198 pipe
->bind_tcs_state(pipe
, NULL
);
1199 pipe
->bind_tes_state(pipe
, NULL
);
1201 if (ctx
->has_stream_out
)
1202 pipe
->set_stream_output_targets(pipe
, 0, NULL
, NULL
);
1205 static void blitter_draw(struct blitter_context_priv
*ctx
,
1206 int x1
, int y1
, int x2
, int y2
, float depth
,
1207 unsigned num_instances
)
1209 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1210 struct pipe_vertex_buffer vb
= {0};
1212 blitter_set_rectangle(ctx
, x1
, y1
, x2
, y2
, depth
);
1214 vb
.stride
= 8 * sizeof(float);
1216 u_upload_data(pipe
->stream_uploader
, 0, sizeof(ctx
->vertices
), 4, ctx
->vertices
,
1217 &vb
.buffer_offset
, &vb
.buffer
.resource
);
1218 if (!vb
.buffer
.resource
)
1220 u_upload_unmap(pipe
->stream_uploader
);
1222 pipe
->set_vertex_buffers(pipe
, ctx
->base
.vb_slot
, 1, &vb
);
1223 util_draw_arrays_instanced(pipe
, PIPE_PRIM_TRIANGLE_FAN
, 0, 4,
1225 pipe_resource_reference(&vb
.buffer
.resource
, NULL
);
1228 void util_blitter_draw_rectangle(struct blitter_context
*blitter
,
1229 int x1
, int y1
, int x2
, int y2
, float depth
,
1230 enum blitter_attrib_type type
,
1231 const union pipe_color_union
*attrib
)
1233 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1236 case UTIL_BLITTER_ATTRIB_COLOR
:
1237 blitter_set_clear_color(ctx
, attrib
);
1240 case UTIL_BLITTER_ATTRIB_TEXCOORD
:
1241 set_texcoords_in_vertices(attrib
->f
, &ctx
->vertices
[0][1][0], 8);
1247 blitter_draw(ctx
, x1
, y1
, x2
, y2
, depth
, 1);
1250 static void *get_clear_blend_state(struct blitter_context_priv
*ctx
,
1251 unsigned clear_buffers
)
1253 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1256 clear_buffers
&= PIPE_CLEAR_COLOR
;
1258 /* Return an existing blend state. */
1260 return ctx
->blend
[0][0];
1262 index
= GET_CLEAR_BLEND_STATE_IDX(clear_buffers
);
1264 if (ctx
->blend_clear
[index
])
1265 return ctx
->blend_clear
[index
];
1267 /* Create a new one. */
1269 struct pipe_blend_state blend
= {0};
1272 blend
.independent_blend_enable
= 1;
1274 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
1275 if (clear_buffers
& (PIPE_CLEAR_COLOR0
<< i
)) {
1276 blend
.rt
[i
].colormask
= PIPE_MASK_RGBA
;
1280 ctx
->blend_clear
[index
] = pipe
->create_blend_state(pipe
, &blend
);
1282 return ctx
->blend_clear
[index
];
1285 void util_blitter_common_clear_setup(struct blitter_context
*blitter
,
1286 unsigned width
, unsigned height
,
1287 unsigned clear_buffers
,
1288 void *custom_blend
, void *custom_dsa
)
1290 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1291 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1293 util_blitter_set_running_flag(blitter
);
1294 blitter_check_saved_vertex_states(ctx
);
1295 blitter_check_saved_fragment_states(ctx
);
1296 blitter_disable_render_cond(ctx
);
1300 pipe
->bind_blend_state(pipe
, custom_blend
);
1302 pipe
->bind_blend_state(pipe
, get_clear_blend_state(ctx
, clear_buffers
));
1306 pipe
->bind_depth_stencil_alpha_state(pipe
, custom_dsa
);
1307 } else if ((clear_buffers
& PIPE_CLEAR_DEPTHSTENCIL
) == PIPE_CLEAR_DEPTHSTENCIL
) {
1308 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_write_depth_stencil
);
1309 } else if (clear_buffers
& PIPE_CLEAR_DEPTH
) {
1310 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_write_depth_keep_stencil
);
1311 } else if (clear_buffers
& PIPE_CLEAR_STENCIL
) {
1312 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_write_stencil
);
1314 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
1317 pipe
->set_sample_mask(pipe
, ~0);
1318 blitter_set_dst_dimensions(ctx
, width
, height
);
1321 static void util_blitter_clear_custom(struct blitter_context
*blitter
,
1322 unsigned width
, unsigned height
,
1323 unsigned num_layers
,
1324 unsigned clear_buffers
,
1325 const union pipe_color_union
*color
,
1326 double depth
, unsigned stencil
,
1327 void *custom_blend
, void *custom_dsa
)
1329 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1330 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1331 struct pipe_stencil_ref sr
= { { 0 } };
1333 assert(ctx
->has_layered
|| num_layers
<= 1);
1335 util_blitter_common_clear_setup(blitter
, width
, height
, clear_buffers
,
1336 custom_blend
, custom_dsa
);
1338 sr
.ref_value
[0] = stencil
& 0xff;
1339 pipe
->set_stencil_ref(pipe
, &sr
);
1341 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
1342 bind_fs_write_all_cbufs(ctx
);
1344 if (num_layers
> 1 && ctx
->has_layered
) {
1345 blitter_set_common_draw_rect_state(ctx
, FALSE
, TRUE
);
1346 blitter_set_clear_color(ctx
, color
);
1347 blitter_draw(ctx
, 0, 0, width
, height
, depth
, num_layers
);
1350 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
1351 blitter
->draw_rectangle(blitter
, 0, 0, width
, height
, (float) depth
,
1352 UTIL_BLITTER_ATTRIB_COLOR
, color
);
1355 util_blitter_restore_vertex_states(blitter
);
1356 util_blitter_restore_fragment_states(blitter
);
1357 util_blitter_restore_render_cond(blitter
);
1358 util_blitter_unset_running_flag(blitter
);
1361 void util_blitter_clear(struct blitter_context
*blitter
,
1362 unsigned width
, unsigned height
, unsigned num_layers
,
1363 unsigned clear_buffers
,
1364 const union pipe_color_union
*color
,
1365 double depth
, unsigned stencil
)
1367 util_blitter_clear_custom(blitter
, width
, height
, num_layers
,
1368 clear_buffers
, color
, depth
, stencil
,
1372 void util_blitter_custom_clear_depth(struct blitter_context
*blitter
,
1373 unsigned width
, unsigned height
,
1374 double depth
, void *custom_dsa
)
1376 static const union pipe_color_union color
;
1377 util_blitter_clear_custom(blitter
, width
, height
, 0, 0, &color
, depth
, 0,
1381 void util_blitter_default_dst_texture(struct pipe_surface
*dst_templ
,
1382 struct pipe_resource
*dst
,
1386 memset(dst_templ
, 0, sizeof(*dst_templ
));
1387 dst_templ
->format
= util_format_linear(dst
->format
);
1388 dst_templ
->u
.tex
.level
= dstlevel
;
1389 dst_templ
->u
.tex
.first_layer
= dstz
;
1390 dst_templ
->u
.tex
.last_layer
= dstz
;
1393 static struct pipe_surface
*
1394 util_blitter_get_next_surface_layer(struct pipe_context
*pipe
,
1395 struct pipe_surface
*surf
)
1397 struct pipe_surface dst_templ
;
1399 memset(&dst_templ
, 0, sizeof(dst_templ
));
1400 dst_templ
.format
= surf
->format
;
1401 dst_templ
.u
.tex
.level
= surf
->u
.tex
.level
;
1402 dst_templ
.u
.tex
.first_layer
= surf
->u
.tex
.first_layer
+ 1;
1403 dst_templ
.u
.tex
.last_layer
= surf
->u
.tex
.last_layer
+ 1;
1405 return pipe
->create_surface(pipe
, surf
->texture
, &dst_templ
);
1408 void util_blitter_default_src_texture(struct pipe_sampler_view
*src_templ
,
1409 struct pipe_resource
*src
,
1412 memset(src_templ
, 0, sizeof(*src_templ
));
1413 src_templ
->target
= src
->target
;
1414 src_templ
->format
= util_format_linear(src
->format
);
1415 src_templ
->u
.tex
.first_level
= srclevel
;
1416 src_templ
->u
.tex
.last_level
= srclevel
;
1417 src_templ
->u
.tex
.first_layer
= 0;
1418 src_templ
->u
.tex
.last_layer
=
1419 src
->target
== PIPE_TEXTURE_3D
? u_minify(src
->depth0
, srclevel
) - 1
1420 : src
->array_size
- 1;
1421 src_templ
->swizzle_r
= PIPE_SWIZZLE_X
;
1422 src_templ
->swizzle_g
= PIPE_SWIZZLE_Y
;
1423 src_templ
->swizzle_b
= PIPE_SWIZZLE_Z
;
1424 src_templ
->swizzle_a
= PIPE_SWIZZLE_W
;
1427 static boolean
is_blit_generic_supported(struct blitter_context
*blitter
,
1428 const struct pipe_resource
*dst
,
1429 enum pipe_format dst_format
,
1430 const struct pipe_resource
*src
,
1431 enum pipe_format src_format
,
1434 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1435 struct pipe_screen
*screen
= ctx
->base
.pipe
->screen
;
1439 const struct util_format_description
*desc
=
1440 util_format_description(dst_format
);
1441 boolean dst_has_stencil
= util_format_has_stencil(desc
);
1443 /* Stencil export must be supported for stencil copy. */
1444 if ((mask
& PIPE_MASK_S
) && dst_has_stencil
&&
1445 !ctx
->has_stencil_export
) {
1449 if (dst_has_stencil
|| util_format_has_depth(desc
))
1450 bind
= PIPE_BIND_DEPTH_STENCIL
;
1452 bind
= PIPE_BIND_RENDER_TARGET
;
1454 if (!screen
->is_format_supported(screen
, dst_format
, dst
->target
,
1455 dst
->nr_samples
, bind
)) {
1461 if (src
->nr_samples
> 1 && !ctx
->has_texture_multisample
) {
1465 if (!screen
->is_format_supported(screen
, src_format
, src
->target
,
1466 src
->nr_samples
, PIPE_BIND_SAMPLER_VIEW
)) {
1470 /* Check stencil sampler support for stencil copy. */
1471 if (mask
& PIPE_MASK_S
) {
1472 if (util_format_has_stencil(util_format_description(src_format
))) {
1473 enum pipe_format stencil_format
=
1474 util_format_stencil_only(src_format
);
1475 assert(stencil_format
!= PIPE_FORMAT_NONE
);
1477 if (stencil_format
!= src_format
&&
1478 !screen
->is_format_supported(screen
, stencil_format
,
1479 src
->target
, src
->nr_samples
,
1480 PIPE_BIND_SAMPLER_VIEW
)) {
1490 boolean
util_blitter_is_copy_supported(struct blitter_context
*blitter
,
1491 const struct pipe_resource
*dst
,
1492 const struct pipe_resource
*src
)
1494 return is_blit_generic_supported(blitter
, dst
, dst
->format
,
1495 src
, src
->format
, PIPE_MASK_RGBAZS
);
1498 boolean
util_blitter_is_blit_supported(struct blitter_context
*blitter
,
1499 const struct pipe_blit_info
*info
)
1501 return is_blit_generic_supported(blitter
,
1502 info
->dst
.resource
, info
->dst
.format
,
1503 info
->src
.resource
, info
->src
.format
,
1507 void util_blitter_copy_texture(struct blitter_context
*blitter
,
1508 struct pipe_resource
*dst
,
1510 unsigned dstx
, unsigned dsty
, unsigned dstz
,
1511 struct pipe_resource
*src
,
1513 const struct pipe_box
*srcbox
)
1515 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1516 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1517 struct pipe_surface
*dst_view
, dst_templ
;
1518 struct pipe_sampler_view src_templ
, *src_view
;
1519 struct pipe_box dstbox
;
1522 assert(src
->target
< PIPE_MAX_TEXTURE_TYPES
);
1524 u_box_3d(dstx
, dsty
, dstz
, abs(srcbox
->width
), abs(srcbox
->height
),
1525 abs(srcbox
->depth
), &dstbox
);
1527 /* Initialize the surface. */
1528 util_blitter_default_dst_texture(&dst_templ
, dst
, dst_level
, dstz
);
1529 dst_view
= pipe
->create_surface(pipe
, dst
, &dst_templ
);
1531 /* Initialize the sampler view. */
1532 util_blitter_default_src_texture(&src_templ
, src
, src_level
);
1533 src_view
= pipe
->create_sampler_view(pipe
, src
, &src_templ
);
1536 util_blitter_blit_generic(blitter
, dst_view
, &dstbox
,
1537 src_view
, srcbox
, src
->width0
, src
->height0
,
1538 PIPE_MASK_RGBAZS
, PIPE_TEX_FILTER_NEAREST
, NULL
,
1541 pipe_surface_reference(&dst_view
, NULL
);
1542 pipe_sampler_view_reference(&src_view
, NULL
);
1545 static void do_blits(struct blitter_context_priv
*ctx
,
1546 struct pipe_surface
*dst
,
1547 const struct pipe_box
*dstbox
,
1548 struct pipe_sampler_view
*src
,
1549 unsigned src_width0
,
1550 unsigned src_height0
,
1551 const struct pipe_box
*srcbox
,
1554 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1555 unsigned src_samples
= src
->texture
->nr_samples
;
1556 unsigned dst_samples
= dst
->texture
->nr_samples
;
1557 enum pipe_texture_target src_target
= src
->texture
->target
;
1558 struct pipe_framebuffer_state fb_state
= {0};
1560 /* Initialize framebuffer state. */
1561 fb_state
.width
= dst
->width
;
1562 fb_state
.height
= dst
->height
;
1563 fb_state
.nr_cbufs
= is_zsbuf
? 0 : 1;
1565 blitter_set_dst_dimensions(ctx
, fb_state
.width
, fb_state
.height
);
1567 if ((src_target
== PIPE_TEXTURE_1D
||
1568 src_target
== PIPE_TEXTURE_2D
||
1569 src_target
== PIPE_TEXTURE_RECT
) &&
1571 /* Draw the quad with the draw_rectangle callback. */
1573 /* Set texture coordinates. - use a pipe color union
1574 * for interface purposes.
1575 * XXX pipe_color_union is a wrong name since we use that to set
1576 * texture coordinates too.
1578 union pipe_color_union coord
;
1579 get_texcoords(src
, src_width0
, src_height0
, srcbox
->x
, srcbox
->y
,
1580 srcbox
->x
+srcbox
->width
, srcbox
->y
+srcbox
->height
, coord
.f
);
1582 /* Set framebuffer state. */
1584 fb_state
.zsbuf
= dst
;
1586 fb_state
.cbufs
[0] = dst
;
1588 pipe
->set_framebuffer_state(pipe
, &fb_state
);
1591 pipe
->set_sample_mask(pipe
, ~0);
1592 ctx
->base
.draw_rectangle(&ctx
->base
, dstbox
->x
, dstbox
->y
,
1593 dstbox
->x
+ dstbox
->width
,
1594 dstbox
->y
+ dstbox
->height
, 0,
1595 UTIL_BLITTER_ATTRIB_TEXCOORD
, &coord
);
1597 /* Draw the quad with the generic codepath. */
1599 for (dst_z
= 0; dst_z
< dstbox
->depth
; dst_z
++) {
1600 struct pipe_surface
*old
;
1601 float dst2src_scale
= srcbox
->depth
/ (float)dstbox
->depth
;
1603 /* Scale Z properly if the blit is scaled.
1605 * When downscaling, we want the coordinates centered, so that
1606 * mipmapping works for 3D textures. For example, when generating
1607 * a 4x4x4 level, this wouldn't average the pixels:
1609 * src Z: 0 1 2 3 4 5 6 7
1612 * Because the pixels are not centered below the pixels of the higher
1613 * level. Therefore, we want this:
1614 * src Z: 0 1 2 3 4 5 6 7
1617 * dst_offset defines the offset needed for centering the pixels and
1618 * it works with any scaling (not just 2x).
1620 float dst_offset
= ((srcbox
->depth
- 1) -
1621 (dstbox
->depth
- 1) * dst2src_scale
) * 0.5;
1622 float src_z
= (dst_z
+ dst_offset
) * dst2src_scale
;
1624 /* Set framebuffer state. */
1626 fb_state
.zsbuf
= dst
;
1628 fb_state
.cbufs
[0] = dst
;
1630 pipe
->set_framebuffer_state(pipe
, &fb_state
);
1632 /* See if we need to blit a multisample or singlesample buffer. */
1633 if (src_samples
== dst_samples
&& dst_samples
> 1) {
1635 unsigned i
, max_sample
= dst_samples
- 1;
1637 for (i
= 0; i
<= max_sample
; i
++) {
1638 pipe
->set_sample_mask(pipe
, 1 << i
);
1639 blitter_set_texcoords(ctx
, src
, src_width0
, src_height0
,
1641 i
, srcbox
->x
, srcbox
->y
,
1642 srcbox
->x
+ srcbox
->width
,
1643 srcbox
->y
+ srcbox
->height
);
1644 blitter_draw(ctx
, dstbox
->x
, dstbox
->y
,
1645 dstbox
->x
+ dstbox
->width
,
1646 dstbox
->y
+ dstbox
->height
, 0, 1);
1649 /* Normal copy, MSAA upsampling, or MSAA resolve. */
1650 pipe
->set_sample_mask(pipe
, ~0);
1651 blitter_set_texcoords(ctx
, src
, src_width0
, src_height0
,
1652 srcbox
->z
+ src_z
, 0,
1653 srcbox
->x
, srcbox
->y
,
1654 srcbox
->x
+ srcbox
->width
,
1655 srcbox
->y
+ srcbox
->height
);
1656 blitter_draw(ctx
, dstbox
->x
, dstbox
->y
,
1657 dstbox
->x
+ dstbox
->width
,
1658 dstbox
->y
+ dstbox
->height
, 0, 1);
1661 /* Get the next surface or (if this is the last iteration)
1662 * just unreference the last one. */
1664 if (dst_z
< dstbox
->depth
-1) {
1665 dst
= ctx
->base
.get_next_surface_layer(ctx
->base
.pipe
, dst
);
1668 pipe_surface_reference(&old
, NULL
);
1674 void util_blitter_blit_generic(struct blitter_context
*blitter
,
1675 struct pipe_surface
*dst
,
1676 const struct pipe_box
*dstbox
,
1677 struct pipe_sampler_view
*src
,
1678 const struct pipe_box
*srcbox
,
1679 unsigned src_width0
, unsigned src_height0
,
1680 unsigned mask
, unsigned filter
,
1681 const struct pipe_scissor_state
*scissor
,
1682 boolean alpha_blend
)
1684 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1685 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1686 enum pipe_texture_target src_target
= src
->texture
->target
;
1687 unsigned src_samples
= src
->texture
->nr_samples
;
1688 unsigned dst_samples
= dst
->texture
->nr_samples
;
1689 boolean has_depth
, has_stencil
, has_color
;
1690 boolean blit_stencil
, blit_depth
, blit_color
;
1691 void *sampler_state
;
1692 const struct util_format_description
*src_desc
=
1693 util_format_description(src
->format
);
1694 const struct util_format_description
*dst_desc
=
1695 util_format_description(dst
->format
);
1697 has_color
= src_desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
&&
1698 dst_desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
;
1699 has_depth
= util_format_has_depth(src_desc
) &&
1700 util_format_has_depth(dst_desc
);
1701 has_stencil
= util_format_has_stencil(src_desc
) &&
1702 util_format_has_stencil(dst_desc
);
1704 blit_color
= has_color
&& (mask
& PIPE_MASK_RGBA
);
1705 blit_depth
= has_depth
&& (mask
& PIPE_MASK_Z
);
1706 blit_stencil
= has_stencil
&& (mask
& PIPE_MASK_S
) &&
1707 ctx
->has_stencil_export
;
1709 if (!blit_stencil
&& !blit_depth
&& !blit_color
) {
1714 (dstbox
->width
== abs(srcbox
->width
) &&
1715 dstbox
->height
== abs(srcbox
->height
))) {
1716 filter
= PIPE_TEX_FILTER_NEAREST
;
1719 /* Check whether the states are properly saved. */
1720 util_blitter_set_running_flag(blitter
);
1721 blitter_check_saved_vertex_states(ctx
);
1722 blitter_check_saved_fragment_states(ctx
);
1723 blitter_check_saved_textures(ctx
);
1724 blitter_check_saved_fb_state(ctx
);
1725 blitter_disable_render_cond(ctx
);
1727 if (blit_depth
|| blit_stencil
) {
1728 pipe
->bind_blend_state(pipe
, ctx
->blend
[0][0]);
1730 if (blit_depth
&& blit_stencil
) {
1731 pipe
->bind_depth_stencil_alpha_state(pipe
,
1732 ctx
->dsa_write_depth_stencil
);
1733 ctx
->bind_fs_state(pipe
,
1734 blitter_get_fs_texfetch_depthstencil(ctx
, src_target
,
1736 } else if (blit_depth
) {
1737 pipe
->bind_depth_stencil_alpha_state(pipe
,
1738 ctx
->dsa_write_depth_keep_stencil
);
1739 ctx
->bind_fs_state(pipe
,
1740 blitter_get_fs_texfetch_depth(ctx
, src_target
,
1742 } else { /* is_stencil */
1743 pipe
->bind_depth_stencil_alpha_state(pipe
,
1744 ctx
->dsa_keep_depth_write_stencil
);
1745 ctx
->bind_fs_state(pipe
,
1746 blitter_get_fs_texfetch_stencil(ctx
, src_target
,
1751 unsigned colormask
= mask
& PIPE_MASK_RGBA
;
1753 pipe
->bind_blend_state(pipe
, ctx
->blend
[colormask
][alpha_blend
]);
1754 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
1755 ctx
->bind_fs_state(pipe
,
1756 blitter_get_fs_texfetch_col(ctx
, src
->format
, dst
->format
, src_target
,
1757 src_samples
, dst_samples
, filter
));
1760 /* Set the linear filter only for scaled color non-MSAA blits. */
1761 if (filter
== PIPE_TEX_FILTER_LINEAR
) {
1762 if (src_target
== PIPE_TEXTURE_RECT
) {
1763 sampler_state
= ctx
->sampler_state_rect_linear
;
1765 sampler_state
= ctx
->sampler_state_linear
;
1768 if (src_target
== PIPE_TEXTURE_RECT
) {
1769 sampler_state
= ctx
->sampler_state_rect
;
1771 sampler_state
= ctx
->sampler_state
;
1776 if (blit_depth
&& blit_stencil
) {
1777 /* Setup two samplers, one for depth and the other one for stencil. */
1778 struct pipe_sampler_view templ
;
1779 struct pipe_sampler_view
*views
[2];
1780 void *samplers
[2] = {sampler_state
, sampler_state
};
1783 templ
.format
= util_format_stencil_only(templ
.format
);
1784 assert(templ
.format
!= PIPE_FORMAT_NONE
);
1787 views
[1] = pipe
->create_sampler_view(pipe
, src
->texture
, &templ
);
1789 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0, 2, views
);
1790 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_FRAGMENT
, 0, 2, samplers
);
1792 pipe_sampler_view_reference(&views
[1], NULL
);
1793 } else if (blit_stencil
) {
1794 /* Set a stencil-only sampler view for it not to sample depth instead. */
1795 struct pipe_sampler_view templ
;
1796 struct pipe_sampler_view
*view
;
1799 templ
.format
= util_format_stencil_only(templ
.format
);
1800 assert(templ
.format
!= PIPE_FORMAT_NONE
);
1802 view
= pipe
->create_sampler_view(pipe
, src
->texture
, &templ
);
1804 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0, 1, &view
);
1805 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_FRAGMENT
,
1806 0, 1, &sampler_state
);
1808 pipe_sampler_view_reference(&view
, NULL
);
1810 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0, 1, &src
);
1811 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_FRAGMENT
,
1812 0, 1, &sampler_state
);
1815 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
1817 pipe
->set_scissor_states(pipe
, 0, 1, scissor
);
1820 blitter_set_common_draw_rect_state(ctx
, scissor
!= NULL
, FALSE
);
1822 do_blits(ctx
, dst
, dstbox
, src
, src_width0
, src_height0
,
1823 srcbox
, blit_depth
|| blit_stencil
);
1825 util_blitter_restore_vertex_states(blitter
);
1826 util_blitter_restore_fragment_states(blitter
);
1827 util_blitter_restore_textures(blitter
);
1828 util_blitter_restore_fb_state(blitter
);
1830 pipe
->set_scissor_states(pipe
, 0, 1, &ctx
->base
.saved_scissor
);
1832 util_blitter_restore_render_cond(blitter
);
1833 util_blitter_unset_running_flag(blitter
);
1837 util_blitter_blit(struct blitter_context
*blitter
,
1838 const struct pipe_blit_info
*info
)
1840 struct pipe_resource
*dst
= info
->dst
.resource
;
1841 struct pipe_resource
*src
= info
->src
.resource
;
1842 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1843 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1844 struct pipe_surface
*dst_view
, dst_templ
;
1845 struct pipe_sampler_view src_templ
, *src_view
;
1847 /* Initialize the surface. */
1848 util_blitter_default_dst_texture(&dst_templ
, dst
, info
->dst
.level
,
1850 dst_templ
.format
= info
->dst
.format
;
1851 dst_view
= pipe
->create_surface(pipe
, dst
, &dst_templ
);
1853 /* Initialize the sampler view. */
1854 util_blitter_default_src_texture(&src_templ
, src
, info
->src
.level
);
1855 src_templ
.format
= info
->src
.format
;
1856 src_view
= pipe
->create_sampler_view(pipe
, src
, &src_templ
);
1859 util_blitter_blit_generic(blitter
, dst_view
, &info
->dst
.box
,
1860 src_view
, &info
->src
.box
, src
->width0
, src
->height0
,
1861 info
->mask
, info
->filter
,
1862 info
->scissor_enable
? &info
->scissor
: NULL
,
1865 pipe_surface_reference(&dst_view
, NULL
);
1866 pipe_sampler_view_reference(&src_view
, NULL
);
1869 void util_blitter_generate_mipmap(struct blitter_context
*blitter
,
1870 struct pipe_resource
*tex
,
1871 enum pipe_format format
,
1872 unsigned base_level
, unsigned last_level
,
1873 unsigned first_layer
, unsigned last_layer
)
1875 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1876 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1877 struct pipe_surface dst_templ
, *dst_view
;
1878 struct pipe_sampler_view src_templ
, *src_view
;
1880 void *sampler_state
;
1881 const struct util_format_description
*desc
=
1882 util_format_description(format
);
1885 assert(tex
->nr_samples
<= 1);
1886 assert(!util_format_has_stencil(desc
));
1888 is_depth
= desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
;
1890 /* Check whether the states are properly saved. */
1891 util_blitter_set_running_flag(blitter
);
1892 blitter_check_saved_vertex_states(ctx
);
1893 blitter_check_saved_fragment_states(ctx
);
1894 blitter_check_saved_textures(ctx
);
1895 blitter_check_saved_fb_state(ctx
);
1896 blitter_disable_render_cond(ctx
);
1900 pipe
->bind_blend_state(pipe
, ctx
->blend
[0][0]);
1901 pipe
->bind_depth_stencil_alpha_state(pipe
,
1902 ctx
->dsa_write_depth_keep_stencil
);
1903 ctx
->bind_fs_state(pipe
,
1904 blitter_get_fs_texfetch_depth(ctx
, tex
->target
, 1));
1906 pipe
->bind_blend_state(pipe
, ctx
->blend
[PIPE_MASK_RGBA
][0]);
1907 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
1908 ctx
->bind_fs_state(pipe
,
1909 blitter_get_fs_texfetch_col(ctx
, tex
->format
, tex
->format
, tex
->target
,
1910 1, 1, PIPE_TEX_FILTER_LINEAR
));
1913 if (tex
->target
== PIPE_TEXTURE_RECT
) {
1914 sampler_state
= ctx
->sampler_state_rect_linear
;
1916 sampler_state
= ctx
->sampler_state_linear
;
1918 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_FRAGMENT
,
1919 0, 1, &sampler_state
);
1921 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
1922 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
1924 for (src_level
= base_level
; src_level
< last_level
; src_level
++) {
1925 struct pipe_box dstbox
= {0}, srcbox
= {0};
1926 unsigned dst_level
= src_level
+ 1;
1928 dstbox
.width
= u_minify(tex
->width0
, dst_level
);
1929 dstbox
.height
= u_minify(tex
->height0
, dst_level
);
1931 srcbox
.width
= u_minify(tex
->width0
, src_level
);
1932 srcbox
.height
= u_minify(tex
->height0
, src_level
);
1934 if (tex
->target
== PIPE_TEXTURE_3D
) {
1935 dstbox
.depth
= util_max_layer(tex
, dst_level
) + 1;
1936 srcbox
.depth
= util_max_layer(tex
, src_level
) + 1;
1938 dstbox
.z
= srcbox
.z
= first_layer
;
1939 dstbox
.depth
= srcbox
.depth
= last_layer
- first_layer
+ 1;
1942 /* Initialize the surface. */
1943 util_blitter_default_dst_texture(&dst_templ
, tex
, dst_level
,
1945 dst_templ
.format
= format
;
1946 dst_view
= pipe
->create_surface(pipe
, tex
, &dst_templ
);
1948 /* Initialize the sampler view. */
1949 util_blitter_default_src_texture(&src_templ
, tex
, src_level
);
1950 src_templ
.format
= format
;
1951 src_view
= pipe
->create_sampler_view(pipe
, tex
, &src_templ
);
1953 pipe
->set_sampler_views(pipe
, PIPE_SHADER_FRAGMENT
, 0, 1, &src_view
);
1955 do_blits(ctx
, dst_view
, &dstbox
, src_view
, tex
->width0
, tex
->height0
,
1958 pipe_surface_reference(&dst_view
, NULL
);
1959 pipe_sampler_view_reference(&src_view
, NULL
);
1962 util_blitter_restore_vertex_states(blitter
);
1963 util_blitter_restore_fragment_states(blitter
);
1964 util_blitter_restore_textures(blitter
);
1965 util_blitter_restore_fb_state(blitter
);
1966 util_blitter_restore_render_cond(blitter
);
1967 util_blitter_unset_running_flag(blitter
);
1970 /* Clear a region of a color surface to a constant value. */
1971 void util_blitter_clear_render_target(struct blitter_context
*blitter
,
1972 struct pipe_surface
*dstsurf
,
1973 const union pipe_color_union
*color
,
1974 unsigned dstx
, unsigned dsty
,
1975 unsigned width
, unsigned height
)
1977 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
1978 struct pipe_context
*pipe
= ctx
->base
.pipe
;
1979 struct pipe_framebuffer_state fb_state
;
1980 unsigned num_layers
;
1982 assert(dstsurf
->texture
);
1983 if (!dstsurf
->texture
)
1986 /* check the saved state */
1987 util_blitter_set_running_flag(blitter
);
1988 blitter_check_saved_vertex_states(ctx
);
1989 blitter_check_saved_fragment_states(ctx
);
1990 blitter_check_saved_fb_state(ctx
);
1991 blitter_disable_render_cond(ctx
);
1994 pipe
->bind_blend_state(pipe
, ctx
->blend
[PIPE_MASK_RGBA
][0]);
1995 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
1996 bind_fs_write_one_cbuf(ctx
);
1997 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
1999 /* set a framebuffer state */
2000 fb_state
.width
= dstsurf
->width
;
2001 fb_state
.height
= dstsurf
->height
;
2002 fb_state
.nr_cbufs
= 1;
2003 fb_state
.cbufs
[0] = dstsurf
;
2005 pipe
->set_framebuffer_state(pipe
, &fb_state
);
2006 pipe
->set_sample_mask(pipe
, ~0);
2008 blitter_set_dst_dimensions(ctx
, dstsurf
->width
, dstsurf
->height
);
2010 num_layers
= dstsurf
->u
.tex
.last_layer
- dstsurf
->u
.tex
.first_layer
+ 1;
2011 if (num_layers
> 1 && ctx
->has_layered
) {
2012 blitter_set_common_draw_rect_state(ctx
, FALSE
, TRUE
);
2013 blitter_set_clear_color(ctx
, color
);
2014 blitter_draw(ctx
, dstx
, dsty
, dstx
+width
, dsty
+height
, 0, num_layers
);
2017 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
2018 blitter
->draw_rectangle(blitter
, dstx
, dsty
, dstx
+width
, dsty
+height
, 0,
2019 UTIL_BLITTER_ATTRIB_COLOR
, color
);
2022 util_blitter_restore_vertex_states(blitter
);
2023 util_blitter_restore_fragment_states(blitter
);
2024 util_blitter_restore_fb_state(blitter
);
2025 util_blitter_restore_render_cond(blitter
);
2026 util_blitter_unset_running_flag(blitter
);
2029 /* Clear a region of a depth stencil surface. */
2030 void util_blitter_clear_depth_stencil(struct blitter_context
*blitter
,
2031 struct pipe_surface
*dstsurf
,
2032 unsigned clear_flags
,
2035 unsigned dstx
, unsigned dsty
,
2036 unsigned width
, unsigned height
)
2038 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2039 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2040 struct pipe_framebuffer_state fb_state
;
2041 struct pipe_stencil_ref sr
= { { 0 } };
2042 unsigned num_layers
;
2044 assert(dstsurf
->texture
);
2045 if (!dstsurf
->texture
)
2048 /* check the saved state */
2049 util_blitter_set_running_flag(blitter
);
2050 blitter_check_saved_vertex_states(ctx
);
2051 blitter_check_saved_fragment_states(ctx
);
2052 blitter_check_saved_fb_state(ctx
);
2053 blitter_disable_render_cond(ctx
);
2056 pipe
->bind_blend_state(pipe
, ctx
->blend
[0][0]);
2057 if ((clear_flags
& PIPE_CLEAR_DEPTHSTENCIL
) == PIPE_CLEAR_DEPTHSTENCIL
) {
2058 sr
.ref_value
[0] = stencil
& 0xff;
2059 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_write_depth_stencil
);
2060 pipe
->set_stencil_ref(pipe
, &sr
);
2062 else if (clear_flags
& PIPE_CLEAR_DEPTH
) {
2063 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_write_depth_keep_stencil
);
2065 else if (clear_flags
& PIPE_CLEAR_STENCIL
) {
2066 sr
.ref_value
[0] = stencil
& 0xff;
2067 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_write_stencil
);
2068 pipe
->set_stencil_ref(pipe
, &sr
);
2071 /* hmm that should be illegal probably, or make it a no-op somewhere */
2072 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
2075 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
2077 /* set a framebuffer state */
2078 fb_state
.width
= dstsurf
->width
;
2079 fb_state
.height
= dstsurf
->height
;
2080 fb_state
.nr_cbufs
= 0;
2081 fb_state
.cbufs
[0] = 0;
2082 fb_state
.zsbuf
= dstsurf
;
2083 pipe
->set_framebuffer_state(pipe
, &fb_state
);
2084 pipe
->set_sample_mask(pipe
, ~0);
2086 blitter_set_dst_dimensions(ctx
, dstsurf
->width
, dstsurf
->height
);
2088 num_layers
= dstsurf
->u
.tex
.last_layer
- dstsurf
->u
.tex
.first_layer
+ 1;
2089 if (num_layers
> 1 && ctx
->has_layered
) {
2090 blitter_set_common_draw_rect_state(ctx
, FALSE
, TRUE
);
2091 blitter_draw(ctx
, dstx
, dsty
, dstx
+width
, dsty
+height
, (float) depth
, num_layers
);
2094 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
2095 blitter
->draw_rectangle(blitter
, dstx
, dsty
, dstx
+width
, dsty
+height
,
2097 UTIL_BLITTER_ATTRIB_NONE
, NULL
);
2100 util_blitter_restore_vertex_states(blitter
);
2101 util_blitter_restore_fragment_states(blitter
);
2102 util_blitter_restore_fb_state(blitter
);
2103 util_blitter_restore_render_cond(blitter
);
2104 util_blitter_unset_running_flag(blitter
);
2107 /* draw a rectangle across a region using a custom dsa stage - for r600g */
2108 void util_blitter_custom_depth_stencil(struct blitter_context
*blitter
,
2109 struct pipe_surface
*zsurf
,
2110 struct pipe_surface
*cbsurf
,
2111 unsigned sample_mask
,
2112 void *dsa_stage
, float depth
)
2114 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2115 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2116 struct pipe_framebuffer_state fb_state
;
2118 assert(zsurf
->texture
);
2119 if (!zsurf
->texture
)
2122 /* check the saved state */
2123 util_blitter_set_running_flag(blitter
);
2124 blitter_check_saved_vertex_states(ctx
);
2125 blitter_check_saved_fragment_states(ctx
);
2126 blitter_check_saved_fb_state(ctx
);
2127 blitter_disable_render_cond(ctx
);
2130 pipe
->bind_blend_state(pipe
, cbsurf
? ctx
->blend
[PIPE_MASK_RGBA
][0] :
2132 pipe
->bind_depth_stencil_alpha_state(pipe
, dsa_stage
);
2134 bind_fs_write_one_cbuf(ctx
);
2137 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
2139 /* set a framebuffer state */
2140 fb_state
.width
= zsurf
->width
;
2141 fb_state
.height
= zsurf
->height
;
2142 fb_state
.nr_cbufs
= 1;
2144 fb_state
.cbufs
[0] = cbsurf
;
2145 fb_state
.nr_cbufs
= 1;
2147 fb_state
.cbufs
[0] = NULL
;
2148 fb_state
.nr_cbufs
= 0;
2150 fb_state
.zsbuf
= zsurf
;
2151 pipe
->set_framebuffer_state(pipe
, &fb_state
);
2152 pipe
->set_sample_mask(pipe
, sample_mask
);
2154 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
2155 blitter_set_dst_dimensions(ctx
, zsurf
->width
, zsurf
->height
);
2156 blitter
->draw_rectangle(blitter
, 0, 0, zsurf
->width
, zsurf
->height
, depth
,
2157 UTIL_BLITTER_ATTRIB_NONE
, NULL
);
2159 util_blitter_restore_vertex_states(blitter
);
2160 util_blitter_restore_fragment_states(blitter
);
2161 util_blitter_restore_fb_state(blitter
);
2162 util_blitter_restore_render_cond(blitter
);
2163 util_blitter_unset_running_flag(blitter
);
2166 void util_blitter_copy_buffer(struct blitter_context
*blitter
,
2167 struct pipe_resource
*dst
,
2169 struct pipe_resource
*src
,
2173 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2174 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2175 struct pipe_vertex_buffer vb
;
2176 struct pipe_stream_output_target
*so_target
;
2177 unsigned offsets
[PIPE_MAX_SO_BUFFERS
] = {0};
2179 if (srcx
>= src
->width0
||
2180 dstx
>= dst
->width0
) {
2183 if (srcx
+ size
> src
->width0
) {
2184 size
= src
->width0
- srcx
;
2186 if (dstx
+ size
> dst
->width0
) {
2187 size
= dst
->width0
- dstx
;
2190 /* Drivers not capable of Stream Out should not call this function
2191 * in the first place. */
2192 assert(ctx
->has_stream_out
);
2194 /* Some alignment is required. */
2195 if (srcx
% 4 != 0 || dstx
% 4 != 0 || size
% 4 != 0 ||
2196 !ctx
->has_stream_out
) {
2197 struct pipe_box box
;
2198 u_box_1d(srcx
, size
, &box
);
2199 util_resource_copy_region(pipe
, dst
, 0, dstx
, 0, 0, src
, 0, &box
);
2203 util_blitter_set_running_flag(blitter
);
2204 blitter_check_saved_vertex_states(ctx
);
2205 blitter_disable_render_cond(ctx
);
2207 vb
.is_user_buffer
= false;
2208 vb
.buffer
.resource
= src
;
2209 vb
.buffer_offset
= srcx
;
2212 pipe
->set_vertex_buffers(pipe
, ctx
->base
.vb_slot
, 1, &vb
);
2213 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state_readbuf
[0]);
2214 bind_vs_pos_only(ctx
, 1);
2215 if (ctx
->has_geometry_shader
)
2216 pipe
->bind_gs_state(pipe
, NULL
);
2217 if (ctx
->has_tessellation
) {
2218 pipe
->bind_tcs_state(pipe
, NULL
);
2219 pipe
->bind_tes_state(pipe
, NULL
);
2221 pipe
->bind_rasterizer_state(pipe
, ctx
->rs_discard_state
);
2223 so_target
= pipe
->create_stream_output_target(pipe
, dst
, dstx
, size
);
2224 pipe
->set_stream_output_targets(pipe
, 1, &so_target
, offsets
);
2226 util_draw_arrays(pipe
, PIPE_PRIM_POINTS
, 0, size
/ 4);
2228 util_blitter_restore_vertex_states(blitter
);
2229 util_blitter_restore_render_cond(blitter
);
2230 util_blitter_unset_running_flag(blitter
);
2231 pipe_so_target_reference(&so_target
, NULL
);
2234 void util_blitter_clear_buffer(struct blitter_context
*blitter
,
2235 struct pipe_resource
*dst
,
2236 unsigned offset
, unsigned size
,
2237 unsigned num_channels
,
2238 const union pipe_color_union
*clear_value
)
2240 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2241 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2242 struct pipe_vertex_buffer vb
= {0};
2243 struct pipe_stream_output_target
*so_target
= NULL
;
2244 unsigned offsets
[PIPE_MAX_SO_BUFFERS
] = {0};
2246 assert(num_channels
>= 1);
2247 assert(num_channels
<= 4);
2249 /* IMPORTANT: DON'T DO ANY BOUNDS CHECKING HERE!
2251 * R600 uses this to initialize texture resources, so width0 might not be
2252 * what you think it is.
2255 /* Streamout is required. */
2256 if (!ctx
->has_stream_out
) {
2257 assert(!"Streamout unsupported in util_blitter_clear_buffer()");
2261 /* Some alignment is required. */
2262 if (offset
% 4 != 0 || size
% 4 != 0) {
2263 assert(!"Bad alignment in util_blitter_clear_buffer()");
2267 u_upload_data(pipe
->stream_uploader
, 0, num_channels
*4, 4, clear_value
,
2268 &vb
.buffer_offset
, &vb
.buffer
.resource
);
2269 if (!vb
.buffer
.resource
)
2274 util_blitter_set_running_flag(blitter
);
2275 blitter_check_saved_vertex_states(ctx
);
2276 blitter_disable_render_cond(ctx
);
2278 pipe
->set_vertex_buffers(pipe
, ctx
->base
.vb_slot
, 1, &vb
);
2279 pipe
->bind_vertex_elements_state(pipe
,
2280 ctx
->velem_state_readbuf
[num_channels
-1]);
2281 bind_vs_pos_only(ctx
, num_channels
);
2282 if (ctx
->has_geometry_shader
)
2283 pipe
->bind_gs_state(pipe
, NULL
);
2284 if (ctx
->has_tessellation
) {
2285 pipe
->bind_tcs_state(pipe
, NULL
);
2286 pipe
->bind_tes_state(pipe
, NULL
);
2288 pipe
->bind_rasterizer_state(pipe
, ctx
->rs_discard_state
);
2290 so_target
= pipe
->create_stream_output_target(pipe
, dst
, offset
, size
);
2291 pipe
->set_stream_output_targets(pipe
, 1, &so_target
, offsets
);
2293 util_draw_arrays(pipe
, PIPE_PRIM_POINTS
, 0, size
/ 4);
2296 util_blitter_restore_vertex_states(blitter
);
2297 util_blitter_restore_render_cond(blitter
);
2298 util_blitter_unset_running_flag(blitter
);
2299 pipe_so_target_reference(&so_target
, NULL
);
2300 pipe_resource_reference(&vb
.buffer
.resource
, NULL
);
2303 /* probably radeon specific */
2304 void util_blitter_custom_resolve_color(struct blitter_context
*blitter
,
2305 struct pipe_resource
*dst
,
2308 struct pipe_resource
*src
,
2310 unsigned sample_mask
,
2312 enum pipe_format format
)
2314 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2315 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2316 struct pipe_framebuffer_state fb_state
;
2317 struct pipe_surface
*srcsurf
, *dstsurf
, surf_tmpl
;
2319 util_blitter_set_running_flag(blitter
);
2320 blitter_check_saved_vertex_states(ctx
);
2321 blitter_check_saved_fragment_states(ctx
);
2322 blitter_disable_render_cond(ctx
);
2325 pipe
->bind_blend_state(pipe
, custom_blend
);
2326 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
2327 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
2328 bind_fs_write_one_cbuf(ctx
);
2329 pipe
->set_sample_mask(pipe
, sample_mask
);
2331 memset(&surf_tmpl
, 0, sizeof(surf_tmpl
));
2332 surf_tmpl
.format
= format
;
2333 surf_tmpl
.u
.tex
.level
= dst_level
;
2334 surf_tmpl
.u
.tex
.first_layer
= dst_layer
;
2335 surf_tmpl
.u
.tex
.last_layer
= dst_layer
;
2337 dstsurf
= pipe
->create_surface(pipe
, dst
, &surf_tmpl
);
2339 surf_tmpl
.u
.tex
.level
= 0;
2340 surf_tmpl
.u
.tex
.first_layer
= src_layer
;
2341 surf_tmpl
.u
.tex
.last_layer
= src_layer
;
2343 srcsurf
= pipe
->create_surface(pipe
, src
, &surf_tmpl
);
2345 /* set a framebuffer state */
2346 fb_state
.width
= src
->width0
;
2347 fb_state
.height
= src
->height0
;
2348 fb_state
.nr_cbufs
= 2;
2349 fb_state
.cbufs
[0] = srcsurf
;
2350 fb_state
.cbufs
[1] = dstsurf
;
2351 fb_state
.zsbuf
= NULL
;
2352 pipe
->set_framebuffer_state(pipe
, &fb_state
);
2354 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
2355 blitter_set_dst_dimensions(ctx
, src
->width0
, src
->height0
);
2356 blitter
->draw_rectangle(blitter
, 0, 0, src
->width0
, src
->height0
,
2358 util_blitter_restore_fb_state(blitter
);
2359 util_blitter_restore_vertex_states(blitter
);
2360 util_blitter_restore_fragment_states(blitter
);
2361 util_blitter_restore_render_cond(blitter
);
2362 util_blitter_unset_running_flag(blitter
);
2364 pipe_surface_reference(&srcsurf
, NULL
);
2365 pipe_surface_reference(&dstsurf
, NULL
);
2368 void util_blitter_custom_color(struct blitter_context
*blitter
,
2369 struct pipe_surface
*dstsurf
,
2372 struct blitter_context_priv
*ctx
= (struct blitter_context_priv
*)blitter
;
2373 struct pipe_context
*pipe
= ctx
->base
.pipe
;
2374 struct pipe_framebuffer_state fb_state
;
2376 assert(dstsurf
->texture
);
2377 if (!dstsurf
->texture
)
2380 /* check the saved state */
2381 util_blitter_set_running_flag(blitter
);
2382 blitter_check_saved_vertex_states(ctx
);
2383 blitter_check_saved_fragment_states(ctx
);
2384 blitter_check_saved_fb_state(ctx
);
2385 blitter_disable_render_cond(ctx
);
2388 pipe
->bind_blend_state(pipe
, custom_blend
? custom_blend
2389 : ctx
->blend
[PIPE_MASK_RGBA
][0]);
2390 pipe
->bind_depth_stencil_alpha_state(pipe
, ctx
->dsa_keep_depth_stencil
);
2391 bind_fs_write_one_cbuf(ctx
);
2392 pipe
->bind_vertex_elements_state(pipe
, ctx
->velem_state
);
2393 pipe
->set_sample_mask(pipe
, (1ull << MAX2(1, dstsurf
->texture
->nr_samples
)) - 1);
2395 /* set a framebuffer state */
2396 fb_state
.width
= dstsurf
->width
;
2397 fb_state
.height
= dstsurf
->height
;
2398 fb_state
.nr_cbufs
= 1;
2399 fb_state
.cbufs
[0] = dstsurf
;
2401 pipe
->set_framebuffer_state(pipe
, &fb_state
);
2402 pipe
->set_sample_mask(pipe
, ~0);
2404 blitter_set_common_draw_rect_state(ctx
, FALSE
, FALSE
);
2405 blitter_set_dst_dimensions(ctx
, dstsurf
->width
, dstsurf
->height
);
2406 blitter
->draw_rectangle(blitter
, 0, 0, dstsurf
->width
, dstsurf
->height
,
2409 util_blitter_restore_vertex_states(blitter
);
2410 util_blitter_restore_fragment_states(blitter
);
2411 util_blitter_restore_fb_state(blitter
);
2412 util_blitter_restore_render_cond(blitter
);
2413 util_blitter_unset_running_flag(blitter
);