1cdc920a0Smrg/************************************************************************** 2cdc920a0Smrg * 3cdc920a0Smrg * Copyright 2009 Marek Olšák <maraeo@gmail.com> 4cdc920a0Smrg * 5cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6cdc920a0Smrg * copy of this software and associated documentation files (the 7cdc920a0Smrg * "Software"), to deal in the Software without restriction, including 8cdc920a0Smrg * without limitation the rights to use, copy, modify, merge, publish, 9cdc920a0Smrg * distribute, sub license, and/or sell copies of the Software, and to 10cdc920a0Smrg * permit persons to whom the Software is furnished to do so, subject to 11cdc920a0Smrg * the following conditions: 12cdc920a0Smrg * 13cdc920a0Smrg * The above copyright notice and this permission notice (including the 14cdc920a0Smrg * next paragraph) shall be included in all copies or substantial portions 15cdc920a0Smrg * of the Software. 16cdc920a0Smrg * 17cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18cdc920a0Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19cdc920a0Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 21cdc920a0Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22cdc920a0Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23cdc920a0Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24cdc920a0Smrg * 25cdc920a0Smrg **************************************************************************/ 26cdc920a0Smrg 27cdc920a0Smrg#ifndef U_BLITTER_H 28cdc920a0Smrg#define U_BLITTER_H 29cdc920a0Smrg 303464ebd5Sriastradh#include "util/u_framebuffer.h" 313464ebd5Sriastradh#include "util/u_inlines.h" 32cdc920a0Smrg 33cdc920a0Smrg#include "pipe/p_state.h" 34cdc920a0Smrg 35cdc920a0Smrg#ifdef __cplusplus 36cdc920a0Smrgextern "C" { 37cdc920a0Smrg#endif 38cdc920a0Smrg 39cdc920a0Smrgstruct pipe_context; 40cdc920a0Smrg 413464ebd5Sriastradhenum blitter_attrib_type { 423464ebd5Sriastradh UTIL_BLITTER_ATTRIB_NONE, 433464ebd5Sriastradh UTIL_BLITTER_ATTRIB_COLOR, 4401e04c3fSmrg UTIL_BLITTER_ATTRIB_TEXCOORD_XY, 4501e04c3fSmrg UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW, 4601e04c3fSmrg}; 4701e04c3fSmrg 4801e04c3fSmrgunion blitter_attrib { 4901e04c3fSmrg float color[4]; 5001e04c3fSmrg 5101e04c3fSmrg struct { 5201e04c3fSmrg float x1, y1, x2, y2, z, w; 5301e04c3fSmrg } texcoord; 543464ebd5Sriastradh}; 553464ebd5Sriastradh 5601e04c3fSmrgstruct blitter_context; 5701e04c3fSmrg 5801e04c3fSmrgtypedef void *(*blitter_get_vs_func)(struct blitter_context *blitter); 5901e04c3fSmrg 60cdc920a0Smrgstruct blitter_context 61cdc920a0Smrg{ 623464ebd5Sriastradh /** 633464ebd5Sriastradh * Draw a rectangle. 643464ebd5Sriastradh * 6501e04c3fSmrg * \param get_vs Callback for obtaining the vertex shader for the draw call. 6601e04c3fSmrg * It might invoke the shader compiler. The driver is 6701e04c3fSmrg * responsible for setting the vertex shader, and the callback 6801e04c3fSmrg * allows the driver to query the vertex shader CSO if it 6901e04c3fSmrg * wants to use the default one. 703464ebd5Sriastradh * \param x1 An X coordinate of the top-left corner. 713464ebd5Sriastradh * \param y1 A Y coordinate of the top-left corner. 723464ebd5Sriastradh * \param x2 An X coordinate of the bottom-right corner. 733464ebd5Sriastradh * \param y2 A Y coordinate of the bottom-right corner. 743464ebd5Sriastradh * \param depth A depth which the rectangle is rendered at. 753464ebd5Sriastradh * 763464ebd5Sriastradh * \param type Semantics of the attributes "attrib". 773464ebd5Sriastradh * If type is UTIL_BLITTER_ATTRIB_NONE, ignore them. 783464ebd5Sriastradh * If type is UTIL_BLITTER_ATTRIB_COLOR, the attributes 793464ebd5Sriastradh * make up a constant RGBA color, and should go 803464ebd5Sriastradh * to the GENERIC0 varying slot of a fragment shader. 813464ebd5Sriastradh * If type is UTIL_BLITTER_ATTRIB_TEXCOORD, {a1, a2} and 823464ebd5Sriastradh * {a3, a4} specify top-left and bottom-right texture 833464ebd5Sriastradh * coordinates of the rectangle, respectively, and should go 843464ebd5Sriastradh * to the GENERIC0 varying slot of a fragment shader. 853464ebd5Sriastradh * 863464ebd5Sriastradh * \param attrib See type. 873464ebd5Sriastradh * 883464ebd5Sriastradh * \note A driver may optionally override this callback to implement 893464ebd5Sriastradh * a specialized hardware path for drawing a rectangle, e.g. using 903464ebd5Sriastradh * a rectangular point sprite. 913464ebd5Sriastradh */ 923464ebd5Sriastradh void (*draw_rectangle)(struct blitter_context *blitter, 9301e04c3fSmrg void *vertex_elements_cso, 9401e04c3fSmrg blitter_get_vs_func get_vs, 95af69d88dSmrg int x1, int y1, int x2, int y2, 9601e04c3fSmrg float depth, unsigned num_instances, 973464ebd5Sriastradh enum blitter_attrib_type type, 9801e04c3fSmrg const union blitter_attrib *attrib); 993464ebd5Sriastradh 1003464ebd5Sriastradh /* Whether the blitter is running. */ 10101e04c3fSmrg bool running; 10201e04c3fSmrg 10301e04c3fSmrg bool use_index_buffer; 1043464ebd5Sriastradh 105cdc920a0Smrg /* Private members, really. */ 1063464ebd5Sriastradh struct pipe_context *pipe; /**< pipe context */ 1073464ebd5Sriastradh 108cdc920a0Smrg void *saved_blend_state; /**< blend state */ 109cdc920a0Smrg void *saved_dsa_state; /**< depth stencil alpha state */ 1103464ebd5Sriastradh void *saved_velem_state; /**< vertex elements state */ 111cdc920a0Smrg void *saved_rs_state; /**< rasterizer state */ 11201e04c3fSmrg void *saved_fs, *saved_vs, *saved_gs, *saved_tcs, *saved_tes; /**< shaders */ 113cdc920a0Smrg 114cdc920a0Smrg struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */ 115cdc920a0Smrg struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */ 116cdc920a0Smrg struct pipe_viewport_state saved_viewport; 117af69d88dSmrg struct pipe_scissor_state saved_scissor; 11801e04c3fSmrg bool skip_viewport_restore; 11901e04c3fSmrg bool is_sample_mask_saved; 120af69d88dSmrg unsigned saved_sample_mask; 121cdc920a0Smrg 122af69d88dSmrg unsigned saved_num_sampler_states; 1233464ebd5Sriastradh void *saved_sampler_states[PIPE_MAX_SAMPLERS]; 124cdc920a0Smrg 125af69d88dSmrg unsigned saved_num_sampler_views; 1263464ebd5Sriastradh struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS]; 1273464ebd5Sriastradh 12801e04c3fSmrg unsigned cb_slot; 12901e04c3fSmrg struct pipe_constant_buffer saved_fs_constant_buffer; 13001e04c3fSmrg 131af69d88dSmrg unsigned vb_slot; 132af69d88dSmrg struct pipe_vertex_buffer saved_vertex_buffer; 133af69d88dSmrg 134af69d88dSmrg unsigned saved_num_so_targets; 135af69d88dSmrg struct pipe_stream_output_target *saved_so_targets[PIPE_MAX_SO_BUFFERS]; 136af69d88dSmrg 137af69d88dSmrg struct pipe_query *saved_render_cond_query; 138af69d88dSmrg uint saved_render_cond_mode; 13901e04c3fSmrg bool saved_render_cond_cond; 14001e04c3fSmrg 14101e04c3fSmrg boolean saved_window_rectangles_include; 14201e04c3fSmrg unsigned saved_num_window_rectangles; 14301e04c3fSmrg struct pipe_scissor_state saved_window_rectangles[PIPE_MAX_WINDOW_RECTANGLES]; 144cdc920a0Smrg}; 145cdc920a0Smrg 146cdc920a0Smrg/** 147cdc920a0Smrg * Create a blitter context. 148cdc920a0Smrg */ 149cdc920a0Smrgstruct blitter_context *util_blitter_create(struct pipe_context *pipe); 150cdc920a0Smrg 151cdc920a0Smrg/** 152cdc920a0Smrg * Destroy a blitter context. 153cdc920a0Smrg */ 154cdc920a0Smrgvoid util_blitter_destroy(struct blitter_context *blitter); 155cdc920a0Smrg 156af69d88dSmrgvoid util_blitter_cache_all_shaders(struct blitter_context *blitter); 1577ec681f3Smrgvoid *util_blitter_get_noop_blend_state(struct blitter_context *blitter); 1587ec681f3Smrgvoid *util_blitter_get_noop_dsa_state(struct blitter_context *blitter); 1597ec681f3Smrgvoid *util_blitter_get_discard_rasterizer_state(struct blitter_context *blitter); 1607ec681f3Smrg 161af69d88dSmrg 1623464ebd5Sriastradh/** 1633464ebd5Sriastradh * Return the pipe context associated with a blitter context. 1643464ebd5Sriastradh */ 16501e04c3fSmrgstatic inline 1663464ebd5Sriastradhstruct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter) 1673464ebd5Sriastradh{ 1683464ebd5Sriastradh return blitter->pipe; 1693464ebd5Sriastradh} 1703464ebd5Sriastradh 171af69d88dSmrg/** 172af69d88dSmrg * Override PIPE_CAP_TEXTURE_MULTISAMPLE as reported by the driver. 173af69d88dSmrg */ 174af69d88dSmrgvoid util_blitter_set_texture_multisample(struct blitter_context *blitter, 17501e04c3fSmrg bool supported); 176af69d88dSmrg 177af69d88dSmrg/* The default function to draw a rectangle. This can only be used 178af69d88dSmrg * inside of the draw_rectangle callback if the driver overrides it. */ 179af69d88dSmrgvoid util_blitter_draw_rectangle(struct blitter_context *blitter, 18001e04c3fSmrg void *vertex_elements_cso, 18101e04c3fSmrg blitter_get_vs_func get_vs, 18201e04c3fSmrg int x1, int y1, int x2, int y2, 18301e04c3fSmrg float depth, unsigned num_instances, 184af69d88dSmrg enum blitter_attrib_type type, 18501e04c3fSmrg const union blitter_attrib *attrib); 186af69d88dSmrg 187af69d88dSmrg 188cdc920a0Smrg/* 189af69d88dSmrg * These states must be saved before any of the following functions are called: 190af69d88dSmrg * - vertex buffers 191af69d88dSmrg * - vertex elements 192cdc920a0Smrg * - vertex shader 193af69d88dSmrg * - geometry shader (if supported) 194af69d88dSmrg * - stream output targets (if supported) 195af69d88dSmrg * - rasterizer state 196cdc920a0Smrg */ 197cdc920a0Smrg 198cdc920a0Smrg/** 199cdc920a0Smrg * Clear a specified set of currently bound buffers to specified values. 200af69d88dSmrg * 201af69d88dSmrg * These states must be saved in the blitter in addition to the state objects 202af69d88dSmrg * already required to be saved: 203af69d88dSmrg * - fragment shader 204af69d88dSmrg * - depth stencil alpha state 205af69d88dSmrg * - blend state 206cdc920a0Smrg */ 207cdc920a0Smrgvoid util_blitter_clear(struct blitter_context *blitter, 208af69d88dSmrg unsigned width, unsigned height, unsigned num_layers, 209cdc920a0Smrg unsigned clear_buffers, 210af69d88dSmrg const union pipe_color_union *color, 2117ec681f3Smrg double depth, unsigned stencil, 2127ec681f3Smrg bool msaa); 213cdc920a0Smrg 214af69d88dSmrg/** 215af69d88dSmrg * Check if the blitter (with the help of the driver) can blit between 216af69d88dSmrg * the two resources. 217af69d88dSmrg */ 21801e04c3fSmrgbool util_blitter_is_copy_supported(struct blitter_context *blitter, 21901e04c3fSmrg const struct pipe_resource *dst, 22001e04c3fSmrg const struct pipe_resource *src); 221af69d88dSmrg 22201e04c3fSmrgbool util_blitter_is_blit_supported(struct blitter_context *blitter, 22301e04c3fSmrg const struct pipe_blit_info *info); 2243464ebd5Sriastradh 225cdc920a0Smrg/** 226cdc920a0Smrg * Copy a block of pixels from one surface to another. 227cdc920a0Smrg * 228cdc920a0Smrg * These states must be saved in the blitter in addition to the state objects 229cdc920a0Smrg * already required to be saved: 230af69d88dSmrg * - fragment shader 231af69d88dSmrg * - depth stencil alpha state 232af69d88dSmrg * - blend state 233cdc920a0Smrg * - fragment sampler states 234cdc920a0Smrg * - fragment sampler textures 235af69d88dSmrg * - framebuffer state 236af69d88dSmrg * - sample mask 237af69d88dSmrg */ 238af69d88dSmrgvoid util_blitter_copy_texture(struct blitter_context *blitter, 239af69d88dSmrg struct pipe_resource *dst, 240af69d88dSmrg unsigned dst_level, 241af69d88dSmrg unsigned dstx, unsigned dsty, unsigned dstz, 242af69d88dSmrg struct pipe_resource *src, 243af69d88dSmrg unsigned src_level, 244af69d88dSmrg const struct pipe_box *srcbox); 245af69d88dSmrg 246af69d88dSmrg/** 247af69d88dSmrg * This is a generic implementation of pipe->blit, which accepts 248af69d88dSmrg * sampler/surface views instead of resources. 249af69d88dSmrg * 250af69d88dSmrg * The layer and mipmap level are specified by the views. 251af69d88dSmrg * 252af69d88dSmrg * Drivers can use this to change resource properties (like format, width, 253af69d88dSmrg * height) by changing how the views interpret them, instead of changing 254af69d88dSmrg * pipe_resource directly. This is used to blit resources of formats which 255af69d88dSmrg * are not renderable. 256af69d88dSmrg * 257af69d88dSmrg * src_width0 and src_height0 are sampler_view-private properties that 258af69d88dSmrg * override pipe_resource. The blitter uses them for computation of texture 259af69d88dSmrg * coordinates. The dst dimensions are supplied through pipe_surface::width 260af69d88dSmrg * and height. 261af69d88dSmrg * 262af69d88dSmrg * The mask is a combination of the PIPE_MASK_* flags. 263af69d88dSmrg * Set to PIPE_MASK_RGBAZS if unsure. 264af69d88dSmrg */ 265af69d88dSmrgvoid util_blitter_blit_generic(struct blitter_context *blitter, 266af69d88dSmrg struct pipe_surface *dst, 267af69d88dSmrg const struct pipe_box *dstbox, 268af69d88dSmrg struct pipe_sampler_view *src, 269af69d88dSmrg const struct pipe_box *srcbox, 270af69d88dSmrg unsigned src_width0, unsigned src_height0, 271af69d88dSmrg unsigned mask, unsigned filter, 27201e04c3fSmrg const struct pipe_scissor_state *scissor, 2737ec681f3Smrg bool alpha_blend, bool sample0_only); 274af69d88dSmrg 275af69d88dSmrgvoid util_blitter_blit(struct blitter_context *blitter, 276af69d88dSmrg const struct pipe_blit_info *info); 277af69d88dSmrg 27801e04c3fSmrgvoid util_blitter_generate_mipmap(struct blitter_context *blitter, 27901e04c3fSmrg struct pipe_resource *tex, 28001e04c3fSmrg enum pipe_format format, 28101e04c3fSmrg unsigned base_level, unsigned last_level, 28201e04c3fSmrg unsigned first_layer, unsigned last_layer); 28301e04c3fSmrg 284af69d88dSmrg/** 285af69d88dSmrg * Helper function to initialize a view for copy_texture_view. 286af69d88dSmrg * The parameters must match copy_texture_view. 287cdc920a0Smrg */ 288af69d88dSmrgvoid util_blitter_default_dst_texture(struct pipe_surface *dst_templ, 289af69d88dSmrg struct pipe_resource *dst, 290af69d88dSmrg unsigned dstlevel, 291af69d88dSmrg unsigned dstz); 292af69d88dSmrg 293af69d88dSmrg/** 294af69d88dSmrg * Helper function to initialize a view for copy_texture_view. 295af69d88dSmrg * The parameters must match copy_texture_view. 296af69d88dSmrg */ 29701e04c3fSmrgvoid util_blitter_default_src_texture(struct blitter_context *blitter, 29801e04c3fSmrg struct pipe_sampler_view *src_templ, 299af69d88dSmrg struct pipe_resource *src, 300af69d88dSmrg unsigned srclevel); 301af69d88dSmrg 302af69d88dSmrg/** 303af69d88dSmrg * Copy data from one buffer to another using the Stream Output functionality. 304af69d88dSmrg * 4-byte alignment is required, otherwise software fallback is used. 305af69d88dSmrg */ 306af69d88dSmrgvoid util_blitter_copy_buffer(struct blitter_context *blitter, 3073464ebd5Sriastradh struct pipe_resource *dst, 308af69d88dSmrg unsigned dstx, 3093464ebd5Sriastradh struct pipe_resource *src, 310af69d88dSmrg unsigned srcx, 311af69d88dSmrg unsigned size); 312af69d88dSmrg 313af69d88dSmrg/** 314af69d88dSmrg * Clear the contents of a buffer using the Stream Output functionality. 315af69d88dSmrg * 4-byte alignment is required. 316af69d88dSmrg * 317af69d88dSmrg * "num_channels" can be 1, 2, 3, or 4, and specifies if the clear value is 318af69d88dSmrg * R, RG, RGB, or RGBA. 319af69d88dSmrg * 320af69d88dSmrg * For each element, only "num_channels" components of "clear_value" are 321af69d88dSmrg * copied to the buffer, then the offset is incremented by num_channels*4. 322af69d88dSmrg */ 323af69d88dSmrgvoid util_blitter_clear_buffer(struct blitter_context *blitter, 324af69d88dSmrg struct pipe_resource *dst, 325af69d88dSmrg unsigned offset, unsigned size, 326af69d88dSmrg unsigned num_channels, 327af69d88dSmrg const union pipe_color_union *clear_value); 328cdc920a0Smrg 329cdc920a0Smrg/** 3303464ebd5Sriastradh * Clear a region of a (color) surface to a constant value. 331cdc920a0Smrg * 332cdc920a0Smrg * These states must be saved in the blitter in addition to the state objects 333cdc920a0Smrg * already required to be saved: 334af69d88dSmrg * - fragment shader 335af69d88dSmrg * - depth stencil alpha state 336af69d88dSmrg * - blend state 337cdc920a0Smrg * - framebuffer state 338cdc920a0Smrg */ 3393464ebd5Sriastradhvoid util_blitter_clear_render_target(struct blitter_context *blitter, 3403464ebd5Sriastradh struct pipe_surface *dst, 341af69d88dSmrg const union pipe_color_union *color, 3423464ebd5Sriastradh unsigned dstx, unsigned dsty, 3433464ebd5Sriastradh unsigned width, unsigned height); 344cdc920a0Smrg 345cdc920a0Smrg/** 3463464ebd5Sriastradh * Clear a region of a depth-stencil surface, both stencil and depth 3473464ebd5Sriastradh * or only one of them if this is a combined depth-stencil surface. 348cdc920a0Smrg * 3493464ebd5Sriastradh * These states must be saved in the blitter in addition to the state objects 3503464ebd5Sriastradh * already required to be saved: 351af69d88dSmrg * - fragment shader 352af69d88dSmrg * - depth stencil alpha state 353af69d88dSmrg * - blend state 3543464ebd5Sriastradh * - framebuffer state 355cdc920a0Smrg */ 3563464ebd5Sriastradhvoid util_blitter_clear_depth_stencil(struct blitter_context *blitter, 3573464ebd5Sriastradh struct pipe_surface *dst, 3583464ebd5Sriastradh unsigned clear_flags, 3593464ebd5Sriastradh double depth, 3603464ebd5Sriastradh unsigned stencil, 3613464ebd5Sriastradh unsigned dstx, unsigned dsty, 3623464ebd5Sriastradh unsigned width, unsigned height); 3633464ebd5Sriastradh 364af69d88dSmrg/* The following functions are customized variants of the clear functions. 365af69d88dSmrg * Some drivers use them internally to do things like MSAA resolve 366af69d88dSmrg * and resource decompression. It usually consists of rendering a full-screen 367af69d88dSmrg * quad with a special blend or DSA state. 368af69d88dSmrg */ 369af69d88dSmrg 370af69d88dSmrg/* Used by r300g for depth decompression. */ 371af69d88dSmrgvoid util_blitter_custom_clear_depth(struct blitter_context *blitter, 372af69d88dSmrg unsigned width, unsigned height, 373af69d88dSmrg double depth, void *custom_dsa); 374af69d88dSmrg 375af69d88dSmrg/* Used by r600g for depth decompression. */ 3763464ebd5Sriastradhvoid util_blitter_custom_depth_stencil(struct blitter_context *blitter, 3773464ebd5Sriastradh struct pipe_surface *zsurf, 3783464ebd5Sriastradh struct pipe_surface *cbsurf, 379af69d88dSmrg unsigned sample_mask, 3803464ebd5Sriastradh void *dsa_stage, float depth); 381cdc920a0Smrg 382af69d88dSmrg/* Used by r600g for color decompression. */ 383af69d88dSmrgvoid util_blitter_custom_color(struct blitter_context *blitter, 384af69d88dSmrg struct pipe_surface *dstsurf, 385af69d88dSmrg void *custom_blend); 386af69d88dSmrg 387af69d88dSmrg/* Used by r600g for MSAA color resolve. */ 388af69d88dSmrgvoid util_blitter_custom_resolve_color(struct blitter_context *blitter, 389af69d88dSmrg struct pipe_resource *dst, 390af69d88dSmrg unsigned dst_level, 391af69d88dSmrg unsigned dst_layer, 392af69d88dSmrg struct pipe_resource *src, 393af69d88dSmrg unsigned src_layer, 394af69d88dSmrg unsigned sampled_mask, 395af69d88dSmrg void *custom_blend, 396af69d88dSmrg enum pipe_format format); 397af69d88dSmrg 39801e04c3fSmrg/* Used by vc4 for 8/16-bit linear-to-tiled blits */ 39901e04c3fSmrgvoid util_blitter_custom_shader(struct blitter_context *blitter, 40001e04c3fSmrg struct pipe_surface *dstsurf, 40101e04c3fSmrg void *custom_vs, void *custom_fs); 40201e04c3fSmrg 4037ec681f3Smrg/* Used by D3D12 for non-MSAA -> MSAA stencil blits */ 4047ec681f3Smrgvoid util_blitter_stencil_fallback(struct blitter_context *blitter, 4057ec681f3Smrg struct pipe_resource *dst, 4067ec681f3Smrg unsigned dst_level, 4077ec681f3Smrg const struct pipe_box *dstbox, 4087ec681f3Smrg struct pipe_resource *src, 4097ec681f3Smrg unsigned src_level, 4107ec681f3Smrg const struct pipe_box *srcbox, 4117ec681f3Smrg const struct pipe_scissor_state *scissor); 4127ec681f3Smrg 413cdc920a0Smrg/* The functions below should be used to save currently bound constant state 414cdc920a0Smrg * objects inside a driver. The objects are automatically restored at the end 4153464ebd5Sriastradh * of the util_blitter_{clear, copy_region, fill_region} functions and then 416cdc920a0Smrg * forgotten. 417cdc920a0Smrg * 418af69d88dSmrg * States not listed here are not affected by util_blitter. */ 419cdc920a0Smrg 42001e04c3fSmrgstatic inline void 42101e04c3fSmrgutil_blitter_save_blend(struct blitter_context *blitter, void *state) 422cdc920a0Smrg{ 423cdc920a0Smrg blitter->saved_blend_state = state; 424cdc920a0Smrg} 425cdc920a0Smrg 42601e04c3fSmrgstatic inline void 42701e04c3fSmrgutil_blitter_save_depth_stencil_alpha(struct blitter_context *blitter, 42801e04c3fSmrg void *state) 429cdc920a0Smrg{ 430cdc920a0Smrg blitter->saved_dsa_state = state; 431cdc920a0Smrg} 432cdc920a0Smrg 43301e04c3fSmrgstatic inline void 43401e04c3fSmrgutil_blitter_save_vertex_elements(struct blitter_context *blitter, void *state) 4353464ebd5Sriastradh{ 4363464ebd5Sriastradh blitter->saved_velem_state = state; 4373464ebd5Sriastradh} 4383464ebd5Sriastradh 43901e04c3fSmrgstatic inline void 44001e04c3fSmrgutil_blitter_save_stencil_ref(struct blitter_context *blitter, 44101e04c3fSmrg const struct pipe_stencil_ref *state) 442cdc920a0Smrg{ 443cdc920a0Smrg blitter->saved_stencil_ref = *state; 444cdc920a0Smrg} 445cdc920a0Smrg 44601e04c3fSmrgstatic inline void 44701e04c3fSmrgutil_blitter_save_rasterizer(struct blitter_context *blitter, void *state) 448cdc920a0Smrg{ 449cdc920a0Smrg blitter->saved_rs_state = state; 450cdc920a0Smrg} 451cdc920a0Smrg 45201e04c3fSmrgstatic inline void 45301e04c3fSmrgutil_blitter_save_fragment_shader(struct blitter_context *blitter, void *fs) 454cdc920a0Smrg{ 455cdc920a0Smrg blitter->saved_fs = fs; 456cdc920a0Smrg} 457cdc920a0Smrg 45801e04c3fSmrgstatic inline void 45901e04c3fSmrgutil_blitter_save_vertex_shader(struct blitter_context *blitter, void *vs) 460cdc920a0Smrg{ 461cdc920a0Smrg blitter->saved_vs = vs; 462cdc920a0Smrg} 463cdc920a0Smrg 46401e04c3fSmrgstatic inline void 46501e04c3fSmrgutil_blitter_save_geometry_shader(struct blitter_context *blitter, void *gs) 466af69d88dSmrg{ 467af69d88dSmrg blitter->saved_gs = gs; 468af69d88dSmrg} 469af69d88dSmrg 47001e04c3fSmrgstatic inline void 47101e04c3fSmrgutil_blitter_save_tessctrl_shader(struct blitter_context *blitter, 47201e04c3fSmrg void *sh) 47301e04c3fSmrg{ 47401e04c3fSmrg blitter->saved_tcs = sh; 47501e04c3fSmrg} 47601e04c3fSmrg 47701e04c3fSmrgstatic inline void 47801e04c3fSmrgutil_blitter_save_tesseval_shader(struct blitter_context *blitter, 47901e04c3fSmrg void *sh) 48001e04c3fSmrg{ 48101e04c3fSmrg blitter->saved_tes = sh; 48201e04c3fSmrg} 48301e04c3fSmrg 48401e04c3fSmrgstatic inline void 48501e04c3fSmrgutil_blitter_save_framebuffer(struct blitter_context *blitter, 48601e04c3fSmrg const struct pipe_framebuffer_state *state) 487cdc920a0Smrg{ 4883464ebd5Sriastradh blitter->saved_fb_state.nr_cbufs = 0; /* It's ~0 now, meaning it's unsaved. */ 4893464ebd5Sriastradh util_copy_framebuffer_state(&blitter->saved_fb_state, state); 490cdc920a0Smrg} 491cdc920a0Smrg 49201e04c3fSmrgstatic inline void 49301e04c3fSmrgutil_blitter_save_viewport(struct blitter_context *blitter, 49401e04c3fSmrg struct pipe_viewport_state *state) 495cdc920a0Smrg{ 496cdc920a0Smrg blitter->saved_viewport = *state; 497cdc920a0Smrg} 498cdc920a0Smrg 49901e04c3fSmrgstatic inline void 50001e04c3fSmrgutil_blitter_save_scissor(struct blitter_context *blitter, 50101e04c3fSmrg struct pipe_scissor_state *state) 502cdc920a0Smrg{ 503af69d88dSmrg blitter->saved_scissor = *state; 504cdc920a0Smrg} 505cdc920a0Smrg 50601e04c3fSmrgstatic inline void 50701e04c3fSmrgutil_blitter_save_fragment_sampler_states( 508cdc920a0Smrg struct blitter_context *blitter, 509af69d88dSmrg unsigned num_sampler_states, 510cdc920a0Smrg void **sampler_states) 511cdc920a0Smrg{ 51201e04c3fSmrg assert(num_sampler_states <= ARRAY_SIZE(blitter->saved_sampler_states)); 513cdc920a0Smrg 514cdc920a0Smrg blitter->saved_num_sampler_states = num_sampler_states; 515cdc920a0Smrg memcpy(blitter->saved_sampler_states, sampler_states, 516cdc920a0Smrg num_sampler_states * sizeof(void *)); 517cdc920a0Smrg} 518cdc920a0Smrg 51901e04c3fSmrgstatic inline void 5203464ebd5Sriastradhutil_blitter_save_fragment_sampler_views(struct blitter_context *blitter, 521af69d88dSmrg unsigned num_views, 5223464ebd5Sriastradh struct pipe_sampler_view **views) 5233464ebd5Sriastradh{ 5243464ebd5Sriastradh unsigned i; 52501e04c3fSmrg assert(num_views <= ARRAY_SIZE(blitter->saved_sampler_views)); 5263464ebd5Sriastradh 5273464ebd5Sriastradh blitter->saved_num_sampler_views = num_views; 5283464ebd5Sriastradh for (i = 0; i < num_views; i++) 5293464ebd5Sriastradh pipe_sampler_view_reference(&blitter->saved_sampler_views[i], 5303464ebd5Sriastradh views[i]); 5313464ebd5Sriastradh} 5323464ebd5Sriastradh 53301e04c3fSmrgstatic inline void 53401e04c3fSmrgutil_blitter_save_fragment_constant_buffer_slot( 53501e04c3fSmrg struct blitter_context *blitter, 53601e04c3fSmrg struct pipe_constant_buffer *constant_buffers) 53701e04c3fSmrg{ 53801e04c3fSmrg pipe_resource_reference(&blitter->saved_fs_constant_buffer.buffer, 53901e04c3fSmrg constant_buffers[blitter->cb_slot].buffer); 54001e04c3fSmrg memcpy(&blitter->saved_fs_constant_buffer, &constant_buffers[blitter->cb_slot], 54101e04c3fSmrg sizeof(struct pipe_constant_buffer)); 54201e04c3fSmrg} 54301e04c3fSmrg 54401e04c3fSmrgstatic inline void 545af69d88dSmrgutil_blitter_save_vertex_buffer_slot(struct blitter_context *blitter, 546af69d88dSmrg struct pipe_vertex_buffer *vertex_buffers) 547af69d88dSmrg{ 54801e04c3fSmrg pipe_vertex_buffer_reference(&blitter->saved_vertex_buffer, 54901e04c3fSmrg &vertex_buffers[blitter->vb_slot]); 550af69d88dSmrg} 551af69d88dSmrg 55201e04c3fSmrgstatic inline void 553af69d88dSmrgutil_blitter_save_so_targets(struct blitter_context *blitter, 554af69d88dSmrg unsigned num_targets, 555af69d88dSmrg struct pipe_stream_output_target **targets) 556cdc920a0Smrg{ 557af69d88dSmrg unsigned i; 55801e04c3fSmrg assert(num_targets <= ARRAY_SIZE(blitter->saved_so_targets)); 559cdc920a0Smrg 560af69d88dSmrg blitter->saved_num_so_targets = num_targets; 561af69d88dSmrg for (i = 0; i < num_targets; i++) 562af69d88dSmrg pipe_so_target_reference(&blitter->saved_so_targets[i], 563af69d88dSmrg targets[i]); 564af69d88dSmrg} 565af69d88dSmrg 56601e04c3fSmrgstatic inline void 567af69d88dSmrgutil_blitter_save_sample_mask(struct blitter_context *blitter, 568af69d88dSmrg unsigned sample_mask) 569af69d88dSmrg{ 57001e04c3fSmrg blitter->is_sample_mask_saved = true; 571af69d88dSmrg blitter->saved_sample_mask = sample_mask; 572af69d88dSmrg} 573af69d88dSmrg 57401e04c3fSmrgstatic inline void 575af69d88dSmrgutil_blitter_save_render_condition(struct blitter_context *blitter, 576af69d88dSmrg struct pipe_query *query, 57701e04c3fSmrg bool condition, 57801e04c3fSmrg enum pipe_render_cond_flag mode) 579af69d88dSmrg{ 580af69d88dSmrg blitter->saved_render_cond_query = query; 581af69d88dSmrg blitter->saved_render_cond_mode = mode; 582af69d88dSmrg blitter->saved_render_cond_cond = condition; 583cdc920a0Smrg} 584cdc920a0Smrg 58501e04c3fSmrgstatic inline void 58601e04c3fSmrgutil_blitter_save_window_rectangles(struct blitter_context *blitter, 58701e04c3fSmrg boolean include, 58801e04c3fSmrg unsigned num_rectangles, 58901e04c3fSmrg const struct pipe_scissor_state *rects) 59001e04c3fSmrg{ 59101e04c3fSmrg blitter->saved_window_rectangles_include = include; 59201e04c3fSmrg blitter->saved_num_window_rectangles = num_rectangles; 59301e04c3fSmrg if (num_rectangles > 0) { 59401e04c3fSmrg assert(num_rectangles < ARRAY_SIZE(blitter->saved_window_rectangles)); 59501e04c3fSmrg memcpy(blitter->saved_window_rectangles, rects, 59601e04c3fSmrg sizeof(*rects) * num_rectangles); 59701e04c3fSmrg } 59801e04c3fSmrg} 59901e04c3fSmrg 60001e04c3fSmrgvoid util_blitter_common_clear_setup(struct blitter_context *blitter, 60101e04c3fSmrg unsigned width, unsigned height, 60201e04c3fSmrg unsigned clear_buffers, 60301e04c3fSmrg void *custom_blend, void *custom_dsa); 60401e04c3fSmrg 60501e04c3fSmrgvoid util_blitter_set_running_flag(struct blitter_context *blitter); 60601e04c3fSmrgvoid util_blitter_unset_running_flag(struct blitter_context *blitter); 60701e04c3fSmrg 60801e04c3fSmrgvoid util_blitter_restore_vertex_states(struct blitter_context *blitter); 60901e04c3fSmrgvoid util_blitter_restore_fragment_states(struct blitter_context *blitter); 61001e04c3fSmrgvoid util_blitter_restore_render_cond(struct blitter_context *blitter); 61101e04c3fSmrgvoid util_blitter_restore_fb_state(struct blitter_context *blitter); 61201e04c3fSmrgvoid util_blitter_restore_textures(struct blitter_context *blitter); 61301e04c3fSmrgvoid util_blitter_restore_constant_buffer_state(struct blitter_context *blitter); 61401e04c3fSmrg 6157ec681f3Smrg/* These are supported combinations of blits from ZS to color and vice versa. 6167ec681f3Smrg * The blitter will do the packing/unpacking of depth and stencil 6177ec681f3Smrg * in the fragment shader. 6187ec681f3Smrg */ 6197ec681f3Smrgstatic inline enum pipe_format 6207ec681f3Smrgutil_blitter_get_color_format_for_zs(enum pipe_format format) 6217ec681f3Smrg{ 6227ec681f3Smrg switch (format) { 6237ec681f3Smrg case PIPE_FORMAT_Z16_UNORM: 6247ec681f3Smrg return PIPE_FORMAT_R16_UNORM; 6257ec681f3Smrg 6267ec681f3Smrg case PIPE_FORMAT_Z32_FLOAT: 6277ec681f3Smrg return PIPE_FORMAT_R32_FLOAT; 6287ec681f3Smrg 6297ec681f3Smrg case PIPE_FORMAT_Z24_UNORM_S8_UINT: 6307ec681f3Smrg case PIPE_FORMAT_Z24X8_UNORM: 6317ec681f3Smrg case PIPE_FORMAT_S8_UINT_Z24_UNORM: 6327ec681f3Smrg case PIPE_FORMAT_X8Z24_UNORM: 6337ec681f3Smrg return PIPE_FORMAT_R32_UINT; 6347ec681f3Smrg 6357ec681f3Smrg case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: 6367ec681f3Smrg return PIPE_FORMAT_R32G32_UINT; 6377ec681f3Smrg 6387ec681f3Smrg case PIPE_FORMAT_Z32_UNORM: 6397ec681f3Smrg default: 6407ec681f3Smrg assert(0); 6417ec681f3Smrg } 6427ec681f3Smrg return PIPE_FORMAT_NONE; 6437ec681f3Smrg} 6447ec681f3Smrg 645cdc920a0Smrg#ifdef __cplusplus 646cdc920a0Smrg} 647cdc920a0Smrg#endif 648cdc920a0Smrg 649cdc920a0Smrg#endif 650