• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2009 Marek Olšák <maraeo@gmail.com>
4  *
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:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
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.
24  *
25  **************************************************************************/
26 
27 #ifndef U_BLITTER_H
28 #define U_BLITTER_H
29 
30 #include "util/u_framebuffer.h"
31 #include "util/u_inlines.h"
32 
33 #include "pipe/p_state.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 struct pipe_context;
40 
41 enum blitter_attrib_type {
42    UTIL_BLITTER_ATTRIB_NONE,
43    UTIL_BLITTER_ATTRIB_COLOR,
44    UTIL_BLITTER_ATTRIB_TEXCOORD_XY,
45    UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW,
46 };
47 
48 union blitter_attrib {
49    float color[4];
50 
51    struct {
52       float x1, y1, x2, y2, z, w;
53    } texcoord;
54 };
55 
56 struct blitter_context;
57 
58 typedef void *(*blitter_get_vs_func)(struct blitter_context *blitter);
59 
60 struct blitter_context
61 {
62    /**
63     * Draw a rectangle.
64     *
65     * \param get_vs  Callback for obtaining the vertex shader for the draw call.
66     *                It might invoke the shader compiler. The driver is
67     *                responsible for setting the vertex shader, and the callback
68     *                allows the driver to query the vertex shader CSO if it
69     *                wants to use the default one.
70     * \param x1      An X coordinate of the top-left corner.
71     * \param y1      A Y coordinate of the top-left corner.
72     * \param x2      An X coordinate of the bottom-right corner.
73     * \param y2      A Y coordinate of the bottom-right corner.
74     * \param depth   A depth which the rectangle is rendered at.
75     *
76     * \param type   Semantics of the attributes "attrib".
77     *               If type is UTIL_BLITTER_ATTRIB_NONE, ignore them.
78     *               If type is UTIL_BLITTER_ATTRIB_COLOR, the attributes
79     *               make up a constant RGBA color, and should go
80     *               to the GENERIC0 varying slot of a fragment shader.
81     *               If type is UTIL_BLITTER_ATTRIB_TEXCOORD, {a1, a2} and
82     *               {a3, a4} specify top-left and bottom-right texture
83     *               coordinates of the rectangle, respectively, and should go
84     *               to the GENERIC0 varying slot of a fragment shader.
85     *
86     * \param attrib See type.
87     *
88     * \note A driver may optionally override this callback to implement
89     *       a specialized hardware path for drawing a rectangle, e.g. using
90     *       a rectangular point sprite.
91     */
92    void (*draw_rectangle)(struct blitter_context *blitter,
93                           void *vertex_elements_cso,
94                           blitter_get_vs_func get_vs,
95                           int x1, int y1, int x2, int y2,
96                           float depth, unsigned num_instances,
97                           enum blitter_attrib_type type,
98                           const union blitter_attrib *attrib);
99 
100    /* Whether the blitter is running. */
101    bool running;
102 
103    bool use_index_buffer;
104 
105    /* Private members, really. */
106    struct pipe_context *pipe; /**< pipe context */
107 
108    void *saved_blend_state;   /**< blend state */
109    void *saved_dsa_state;     /**< depth stencil alpha state */
110    void *saved_velem_state;   /**< vertex elements state */
111    void *saved_rs_state;      /**< rasterizer state */
112    void *saved_fs, *saved_vs, *saved_gs, *saved_tcs, *saved_tes; /**< shaders */
113 
114    struct pipe_framebuffer_state saved_fb_state;  /**< framebuffer state */
115    struct pipe_stencil_ref saved_stencil_ref;     /**< stencil ref */
116    struct pipe_viewport_state saved_viewport;
117    struct pipe_scissor_state saved_scissor;
118    bool skip_viewport_restore;
119    bool is_sample_mask_saved;
120    unsigned saved_sample_mask;
121    unsigned saved_min_samples;
122 
123    unsigned saved_num_sampler_states;
124    void *saved_sampler_states[PIPE_MAX_SAMPLERS];
125 
126    unsigned saved_num_sampler_views;
127    struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
128 
129    unsigned cb_slot;
130    struct pipe_constant_buffer saved_fs_constant_buffer;
131 
132    unsigned vb_slot;
133    struct pipe_vertex_buffer saved_vertex_buffer;
134 
135    unsigned saved_num_so_targets;
136    struct pipe_stream_output_target *saved_so_targets[PIPE_MAX_SO_BUFFERS];
137 
138    struct pipe_query *saved_render_cond_query;
139    uint saved_render_cond_mode;
140    bool saved_render_cond_cond;
141 
142    boolean saved_window_rectangles_include;
143    unsigned saved_num_window_rectangles;
144    struct pipe_scissor_state saved_window_rectangles[PIPE_MAX_WINDOW_RECTANGLES];
145 };
146 
147 /**
148  * Create a blitter context.
149  */
150 struct blitter_context *util_blitter_create(struct pipe_context *pipe);
151 
152 /**
153  * Destroy a blitter context.
154  */
155 void util_blitter_destroy(struct blitter_context *blitter);
156 
157 void util_blitter_cache_all_shaders(struct blitter_context *blitter);
158 void *util_blitter_get_noop_blend_state(struct blitter_context *blitter);
159 void *util_blitter_get_noop_dsa_state(struct blitter_context *blitter);
160 void *util_blitter_get_discard_rasterizer_state(struct blitter_context *blitter);
161 
162 
163 /**
164  * Return the pipe context associated with a blitter context.
165  */
166 static inline
util_blitter_get_pipe(struct blitter_context * blitter)167 struct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter)
168 {
169    return blitter->pipe;
170 }
171 
172 /**
173  * Override PIPE_CAP_TEXTURE_MULTISAMPLE as reported by the driver.
174  */
175 void util_blitter_set_texture_multisample(struct blitter_context *blitter,
176                                           bool supported);
177 
178 /* The default function to draw a rectangle. This can only be used
179  * inside of the draw_rectangle callback if the driver overrides it. */
180 void util_blitter_draw_rectangle(struct blitter_context *blitter,
181                                  void *vertex_elements_cso,
182                                  blitter_get_vs_func get_vs,
183                                  int x1, int y1, int x2, int y2,
184                                  float depth, unsigned num_instances,
185                                  enum blitter_attrib_type type,
186                                  const union blitter_attrib *attrib);
187 
188 
189 /*
190  * These states must be saved before any of the following functions are called:
191  * - vertex buffers
192  * - vertex elements
193  * - vertex shader
194  * - geometry shader (if supported)
195  * - stream output targets (if supported)
196  * - rasterizer state
197  */
198 
199 /**
200  * Clear a specified set of currently bound buffers to specified values.
201  *
202  * These states must be saved in the blitter in addition to the state objects
203  * already required to be saved:
204  * - fragment shader
205  * - depth stencil alpha state
206  * - blend state
207  */
208 void util_blitter_clear(struct blitter_context *blitter,
209                         unsigned width, unsigned height, unsigned num_layers,
210                         unsigned clear_buffers,
211                         const union pipe_color_union *color,
212                         double depth, unsigned stencil,
213                         bool msaa);
214 
215 /**
216  * Check if the blitter (with the help of the driver) can blit between
217  * the two resources.
218  */
219 bool util_blitter_is_copy_supported(struct blitter_context *blitter,
220                                     const struct pipe_resource *dst,
221                                     const struct pipe_resource *src);
222 
223 bool util_blitter_is_blit_supported(struct blitter_context *blitter,
224 				    const struct pipe_blit_info *info);
225 
226 /**
227  * Copy a block of pixels from one surface to another.
228  *
229  * These states must be saved in the blitter in addition to the state objects
230  * already required to be saved:
231  * - fragment shader
232  * - depth stencil alpha state
233  * - blend state
234  * - fragment sampler states
235  * - fragment sampler textures
236  * - framebuffer state
237  * - sample mask
238  */
239 void util_blitter_copy_texture(struct blitter_context *blitter,
240                                struct pipe_resource *dst,
241                                unsigned dst_level,
242                                unsigned dstx, unsigned dsty, unsigned dstz,
243                                struct pipe_resource *src,
244                                unsigned src_level,
245                                const struct pipe_box *srcbox);
246 
247 /**
248  * This is a generic implementation of pipe->blit, which accepts
249  * sampler/surface views instead of resources.
250  *
251  * The layer and mipmap level are specified by the views.
252  *
253  * Drivers can use this to change resource properties (like format, width,
254  * height) by changing how the views interpret them, instead of changing
255  * pipe_resource directly. This is used to blit resources of formats which
256  * are not renderable.
257  *
258  * src_width0 and src_height0 are sampler_view-private properties that
259  * override pipe_resource. The blitter uses them for computation of texture
260  * coordinates. The dst dimensions are supplied through pipe_surface::width
261  * and height.
262  *
263  * The mask is a combination of the PIPE_MASK_* flags.
264  * Set to PIPE_MASK_RGBAZS if unsure.
265  */
266 void util_blitter_blit_generic(struct blitter_context *blitter,
267                                struct pipe_surface *dst,
268                                const struct pipe_box *dstbox,
269                                struct pipe_sampler_view *src,
270                                const struct pipe_box *srcbox,
271                                unsigned src_width0, unsigned src_height0,
272                                unsigned mask, unsigned filter,
273                                const struct pipe_scissor_state *scissor,
274                                bool alpha_blend, bool sample0_only,
275                                unsigned dst_sample);
276 
277 void util_blitter_blit(struct blitter_context *blitter,
278 		       const struct pipe_blit_info *info);
279 
280 void util_blitter_generate_mipmap(struct blitter_context *blitter,
281                                   struct pipe_resource *tex,
282                                   enum pipe_format format,
283                                   unsigned base_level, unsigned last_level,
284                                   unsigned first_layer, unsigned last_layer);
285 
286 /**
287  * Helper function to initialize a view for copy_texture_view.
288  * The parameters must match copy_texture_view.
289  */
290 void util_blitter_default_dst_texture(struct pipe_surface *dst_templ,
291                                       struct pipe_resource *dst,
292                                       unsigned dstlevel,
293                                       unsigned dstz);
294 
295 /**
296  * Helper function to initialize a view for copy_texture_view.
297  * The parameters must match copy_texture_view.
298  */
299 void util_blitter_default_src_texture(struct blitter_context *blitter,
300                                       struct pipe_sampler_view *src_templ,
301                                       struct pipe_resource *src,
302                                       unsigned srclevel);
303 
304 /**
305  * Clear the contents of a buffer using the Stream Output functionality.
306  * 4-byte alignment is required.
307  *
308  * "num_channels" can be 1, 2, 3, or 4, and specifies if the clear value is
309  * R, RG, RGB, or RGBA.
310  *
311  * For each element, only "num_channels" components of "clear_value" are
312  * copied to the buffer, then the offset is incremented by num_channels*4.
313  */
314 void util_blitter_clear_buffer(struct blitter_context *blitter,
315                                struct pipe_resource *dst,
316                                unsigned offset, unsigned size,
317                                unsigned num_channels,
318                                const union pipe_color_union *clear_value);
319 
320 /**
321  * Clear a region of a (color) surface to a constant value.
322  *
323  * These states must be saved in the blitter in addition to the state objects
324  * already required to be saved:
325  * - fragment shader
326  * - depth stencil alpha state
327  * - blend state
328  * - framebuffer state
329  */
330 void util_blitter_clear_render_target(struct blitter_context *blitter,
331                                       struct pipe_surface *dst,
332                                       const union pipe_color_union *color,
333                                       unsigned dstx, unsigned dsty,
334                                       unsigned width, unsigned height);
335 
336 /**
337  * Clear a region of a depth-stencil surface, both stencil and depth
338  * or only one of them if this is a combined depth-stencil surface.
339  *
340  * These states must be saved in the blitter in addition to the state objects
341  * already required to be saved:
342  * - fragment shader
343  * - depth stencil alpha state
344  * - blend state
345  * - framebuffer state
346  */
347 void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
348                                       struct pipe_surface *dst,
349                                       unsigned clear_flags,
350                                       double depth,
351                                       unsigned stencil,
352                                       unsigned dstx, unsigned dsty,
353                                       unsigned width, unsigned height);
354 
355 /* The following functions are customized variants of the clear functions.
356  * Some drivers use them internally to do things like MSAA resolve
357  * and resource decompression. It usually consists of rendering a full-screen
358  * quad with a special blend or DSA state.
359  */
360 
361 /* Used by r300g for depth decompression. */
362 void util_blitter_custom_clear_depth(struct blitter_context *blitter,
363                                      unsigned width, unsigned height,
364                                      double depth, void *custom_dsa);
365 
366 /* Used by r600g for depth decompression. */
367 void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
368 				       struct pipe_surface *zsurf,
369 				       struct pipe_surface *cbsurf,
370 				       unsigned sample_mask,
371 				       void *dsa_stage, float depth);
372 
373 /* Used by r600g for color decompression. */
374 void util_blitter_custom_color(struct blitter_context *blitter,
375                                struct pipe_surface *dstsurf,
376                                void *custom_blend);
377 
378 /* Used by r600g for MSAA color resolve. */
379 void util_blitter_custom_resolve_color(struct blitter_context *blitter,
380                                        struct pipe_resource *dst,
381                                        unsigned dst_level,
382                                        unsigned dst_layer,
383                                        struct pipe_resource *src,
384                                        unsigned src_layer,
385 				       unsigned sampled_mask,
386                                        void *custom_blend,
387                                        enum pipe_format format);
388 
389 /* Used by vc4 for 8/16-bit linear-to-tiled blits */
390 void util_blitter_custom_shader(struct blitter_context *blitter,
391                                 struct pipe_surface *dstsurf,
392                                 void *custom_vs, void *custom_fs);
393 
394 /* Used by D3D12 for non-MSAA -> MSAA stencil blits */
395 void util_blitter_stencil_fallback(struct blitter_context *blitter,
396                                    struct pipe_resource *dst,
397                                    unsigned dst_level,
398                                    const struct pipe_box *dstbox,
399                                    struct pipe_resource *src,
400                                    unsigned src_level,
401                                    const struct pipe_box *srcbox,
402                                    const struct pipe_scissor_state *scissor);
403 
404 /* The functions below should be used to save currently bound constant state
405  * objects inside a driver. The objects are automatically restored at the end
406  * of the util_blitter_{clear, copy_region, fill_region} functions and then
407  * forgotten.
408  *
409  * States not listed here are not affected by util_blitter. */
410 
411 static inline void
util_blitter_save_blend(struct blitter_context * blitter,void * state)412 util_blitter_save_blend(struct blitter_context *blitter, void *state)
413 {
414    blitter->saved_blend_state = state;
415 }
416 
417 static inline void
util_blitter_save_depth_stencil_alpha(struct blitter_context * blitter,void * state)418 util_blitter_save_depth_stencil_alpha(struct blitter_context *blitter,
419                                       void *state)
420 {
421    blitter->saved_dsa_state = state;
422 }
423 
424 static inline void
util_blitter_save_vertex_elements(struct blitter_context * blitter,void * state)425 util_blitter_save_vertex_elements(struct blitter_context *blitter, void *state)
426 {
427    blitter->saved_velem_state = state;
428 }
429 
430 static inline void
util_blitter_save_stencil_ref(struct blitter_context * blitter,const struct pipe_stencil_ref * state)431 util_blitter_save_stencil_ref(struct blitter_context *blitter,
432                               const struct pipe_stencil_ref *state)
433 {
434    blitter->saved_stencil_ref = *state;
435 }
436 
437 static inline void
util_blitter_save_rasterizer(struct blitter_context * blitter,void * state)438 util_blitter_save_rasterizer(struct blitter_context *blitter, void *state)
439 {
440    blitter->saved_rs_state = state;
441 }
442 
443 static inline void
util_blitter_save_fragment_shader(struct blitter_context * blitter,void * fs)444 util_blitter_save_fragment_shader(struct blitter_context *blitter, void *fs)
445 {
446    blitter->saved_fs = fs;
447 }
448 
449 static inline void
util_blitter_save_vertex_shader(struct blitter_context * blitter,void * vs)450 util_blitter_save_vertex_shader(struct blitter_context *blitter, void *vs)
451 {
452    blitter->saved_vs = vs;
453 }
454 
455 static inline void
util_blitter_save_geometry_shader(struct blitter_context * blitter,void * gs)456 util_blitter_save_geometry_shader(struct blitter_context *blitter, void *gs)
457 {
458    blitter->saved_gs = gs;
459 }
460 
461 static inline void
util_blitter_save_tessctrl_shader(struct blitter_context * blitter,void * sh)462 util_blitter_save_tessctrl_shader(struct blitter_context *blitter,
463                                   void *sh)
464 {
465    blitter->saved_tcs = sh;
466 }
467 
468 static inline void
util_blitter_save_tesseval_shader(struct blitter_context * blitter,void * sh)469 util_blitter_save_tesseval_shader(struct blitter_context *blitter,
470                                   void *sh)
471 {
472    blitter->saved_tes = sh;
473 }
474 
475 static inline void
util_blitter_save_framebuffer(struct blitter_context * blitter,const struct pipe_framebuffer_state * state)476 util_blitter_save_framebuffer(struct blitter_context *blitter,
477                               const struct pipe_framebuffer_state *state)
478 {
479    blitter->saved_fb_state.nr_cbufs = 0; /* It's ~0 now, meaning it's unsaved. */
480    util_copy_framebuffer_state(&blitter->saved_fb_state, state);
481 }
482 
483 static inline void
util_blitter_save_viewport(struct blitter_context * blitter,struct pipe_viewport_state * state)484 util_blitter_save_viewport(struct blitter_context *blitter,
485                            struct pipe_viewport_state *state)
486 {
487    blitter->saved_viewport = *state;
488 }
489 
490 static inline void
util_blitter_save_scissor(struct blitter_context * blitter,struct pipe_scissor_state * state)491 util_blitter_save_scissor(struct blitter_context *blitter,
492                           struct pipe_scissor_state *state)
493 {
494    blitter->saved_scissor = *state;
495 }
496 
497 static inline void
util_blitter_save_fragment_sampler_states(struct blitter_context * blitter,unsigned num_sampler_states,void ** sampler_states)498 util_blitter_save_fragment_sampler_states(
499                   struct blitter_context *blitter,
500                   unsigned num_sampler_states,
501                   void **sampler_states)
502 {
503    assert(num_sampler_states <= ARRAY_SIZE(blitter->saved_sampler_states));
504 
505    blitter->saved_num_sampler_states = num_sampler_states;
506    memcpy(blitter->saved_sampler_states, sampler_states,
507           num_sampler_states * sizeof(void *));
508 }
509 
510 static inline void
util_blitter_save_fragment_sampler_views(struct blitter_context * blitter,unsigned num_views,struct pipe_sampler_view ** views)511 util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
512                                          unsigned num_views,
513                                          struct pipe_sampler_view **views)
514 {
515    unsigned i;
516    assert(num_views <= ARRAY_SIZE(blitter->saved_sampler_views));
517 
518    blitter->saved_num_sampler_views = num_views;
519    for (i = 0; i < num_views; i++)
520       pipe_sampler_view_reference(&blitter->saved_sampler_views[i],
521                                   views[i]);
522 }
523 
524 static inline void
util_blitter_save_fragment_constant_buffer_slot(struct blitter_context * blitter,struct pipe_constant_buffer * constant_buffers)525 util_blitter_save_fragment_constant_buffer_slot(
526                   struct blitter_context *blitter,
527                   struct pipe_constant_buffer *constant_buffers)
528 {
529    pipe_resource_reference(&blitter->saved_fs_constant_buffer.buffer,
530                            constant_buffers[blitter->cb_slot].buffer);
531    memcpy(&blitter->saved_fs_constant_buffer, &constant_buffers[blitter->cb_slot],
532           sizeof(struct pipe_constant_buffer));
533 }
534 
535 static inline void
util_blitter_save_vertex_buffer_slot(struct blitter_context * blitter,struct pipe_vertex_buffer * vertex_buffers)536 util_blitter_save_vertex_buffer_slot(struct blitter_context *blitter,
537                                      struct pipe_vertex_buffer *vertex_buffers)
538 {
539    pipe_vertex_buffer_reference(&blitter->saved_vertex_buffer,
540                                 &vertex_buffers[blitter->vb_slot]);
541 }
542 
543 static inline void
util_blitter_save_so_targets(struct blitter_context * blitter,unsigned num_targets,struct pipe_stream_output_target ** targets)544 util_blitter_save_so_targets(struct blitter_context *blitter,
545                              unsigned num_targets,
546                              struct pipe_stream_output_target **targets)
547 {
548    unsigned i;
549    assert(num_targets <= ARRAY_SIZE(blitter->saved_so_targets));
550 
551    blitter->saved_num_so_targets = num_targets;
552    for (i = 0; i < num_targets; i++)
553       pipe_so_target_reference(&blitter->saved_so_targets[i],
554                                targets[i]);
555 }
556 
557 static inline void
util_blitter_save_sample_mask(struct blitter_context * blitter,unsigned sample_mask,unsigned min_samples)558 util_blitter_save_sample_mask(struct blitter_context *blitter,
559                               unsigned sample_mask, unsigned min_samples)
560 {
561    blitter->is_sample_mask_saved = true;
562    blitter->saved_sample_mask = sample_mask;
563    blitter->saved_min_samples = min_samples;
564 }
565 
566 static inline void
util_blitter_save_render_condition(struct blitter_context * blitter,struct pipe_query * query,bool condition,enum pipe_render_cond_flag mode)567 util_blitter_save_render_condition(struct blitter_context *blitter,
568                                    struct pipe_query *query,
569                                    bool condition,
570                                    enum pipe_render_cond_flag mode)
571 {
572    blitter->saved_render_cond_query = query;
573    blitter->saved_render_cond_mode = mode;
574    blitter->saved_render_cond_cond = condition;
575 }
576 
577 static inline void
util_blitter_save_window_rectangles(struct blitter_context * blitter,boolean include,unsigned num_rectangles,const struct pipe_scissor_state * rects)578 util_blitter_save_window_rectangles(struct blitter_context *blitter,
579                                     boolean include,
580                                     unsigned num_rectangles,
581                                     const struct pipe_scissor_state *rects)
582 {
583    blitter->saved_window_rectangles_include = include;
584    blitter->saved_num_window_rectangles = num_rectangles;
585    if (num_rectangles > 0) {
586       assert(num_rectangles < ARRAY_SIZE(blitter->saved_window_rectangles));
587       memcpy(blitter->saved_window_rectangles, rects,
588              sizeof(*rects) * num_rectangles);
589    }
590 }
591 
592 void util_blitter_common_clear_setup(struct blitter_context *blitter,
593                                      unsigned width, unsigned height,
594                                      unsigned clear_buffers,
595                                      void *custom_blend, void *custom_dsa);
596 
597 void util_blitter_set_running_flag(struct blitter_context *blitter);
598 void util_blitter_unset_running_flag(struct blitter_context *blitter);
599 
600 void util_blitter_restore_vertex_states(struct blitter_context *blitter);
601 void util_blitter_restore_fragment_states(struct blitter_context *blitter);
602 void util_blitter_restore_render_cond(struct blitter_context *blitter);
603 void util_blitter_restore_fb_state(struct blitter_context *blitter);
604 void util_blitter_restore_textures(struct blitter_context *blitter);
605 void util_blitter_restore_constant_buffer_state(struct blitter_context *blitter);
606 
607 /* These are supported combinations of blits from ZS to color and vice versa.
608  * The blitter will do the packing/unpacking of depth and stencil
609  * in the fragment shader.
610  */
611 static inline enum pipe_format
util_blitter_get_color_format_for_zs(enum pipe_format format)612 util_blitter_get_color_format_for_zs(enum pipe_format format)
613 {
614    switch (format) {
615    case PIPE_FORMAT_Z16_UNORM:
616       return PIPE_FORMAT_R16_UNORM;
617 
618    case PIPE_FORMAT_Z32_FLOAT:
619       return PIPE_FORMAT_R32_FLOAT;
620 
621    case PIPE_FORMAT_Z24_UNORM_S8_UINT:
622    case PIPE_FORMAT_Z24X8_UNORM:
623    case PIPE_FORMAT_S8_UINT_Z24_UNORM:
624    case PIPE_FORMAT_X8Z24_UNORM:
625       return PIPE_FORMAT_R32_UINT;
626 
627    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
628       return PIPE_FORMAT_R32G32_UINT;
629 
630    case PIPE_FORMAT_Z32_UNORM:
631    default:
632       assert(0);
633    }
634    return PIPE_FORMAT_NONE;
635 }
636 
637 #ifdef __cplusplus
638 }
639 #endif
640 
641 #endif
642