1bf215546Sopenharmony_ci/**********************************************************
2bf215546Sopenharmony_ci * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person
5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation
6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without
7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy,
8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies
9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is
10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be
13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22bf215546Sopenharmony_ci * SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci **********************************************************/
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef SVGA_CONTEXT_H
27bf215546Sopenharmony_ci#define SVGA_CONTEXT_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "pipe/p_context.h"
31bf215546Sopenharmony_ci#include "pipe/p_defines.h"
32bf215546Sopenharmony_ci#include "pipe/p_state.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "util/os_time.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "util/u_blitter.h"
37bf215546Sopenharmony_ci#include "util/list.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "tgsi/tgsi_scan.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#include "svga_screen.h"
42bf215546Sopenharmony_ci#include "svga_state.h"
43bf215546Sopenharmony_ci#include "svga_winsys.h"
44bf215546Sopenharmony_ci#include "svga_hw_reg.h"
45bf215546Sopenharmony_ci#include "svga3d_shaderdefs.h"
46bf215546Sopenharmony_ci#include "svga_image_view.h"
47bf215546Sopenharmony_ci#include "svga_shader_buffer.h"
48bf215546Sopenharmony_ci#include "svga_debug.h"
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/** Non-GPU queries for gallium HUD */
51bf215546Sopenharmony_cienum svga_hud {
52bf215546Sopenharmony_ci/* per-frame counters */
53bf215546Sopenharmony_ci   SVGA_QUERY_NUM_DRAW_CALLS = PIPE_QUERY_DRIVER_SPECIFIC,
54bf215546Sopenharmony_ci   SVGA_QUERY_NUM_FALLBACKS,
55bf215546Sopenharmony_ci   SVGA_QUERY_NUM_FLUSHES,
56bf215546Sopenharmony_ci   SVGA_QUERY_NUM_VALIDATIONS,
57bf215546Sopenharmony_ci   SVGA_QUERY_MAP_BUFFER_TIME,
58bf215546Sopenharmony_ci   SVGA_QUERY_NUM_BUFFERS_MAPPED,
59bf215546Sopenharmony_ci   SVGA_QUERY_NUM_TEXTURES_MAPPED,
60bf215546Sopenharmony_ci   SVGA_QUERY_NUM_BYTES_UPLOADED,
61bf215546Sopenharmony_ci   SVGA_QUERY_NUM_COMMAND_BUFFERS,
62bf215546Sopenharmony_ci   SVGA_QUERY_COMMAND_BUFFER_SIZE,
63bf215546Sopenharmony_ci   SVGA_QUERY_FLUSH_TIME,
64bf215546Sopenharmony_ci   SVGA_QUERY_SURFACE_WRITE_FLUSHES,
65bf215546Sopenharmony_ci   SVGA_QUERY_NUM_READBACKS,
66bf215546Sopenharmony_ci   SVGA_QUERY_NUM_RESOURCE_UPDATES,
67bf215546Sopenharmony_ci   SVGA_QUERY_NUM_BUFFER_UPLOADS,
68bf215546Sopenharmony_ci   SVGA_QUERY_NUM_CONST_BUF_UPDATES,
69bf215546Sopenharmony_ci   SVGA_QUERY_NUM_CONST_UPDATES,
70bf215546Sopenharmony_ci   SVGA_QUERY_NUM_SHADER_RELOCATIONS,
71bf215546Sopenharmony_ci   SVGA_QUERY_NUM_SURFACE_RELOCATIONS,
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci/* running total counters */
74bf215546Sopenharmony_ci   SVGA_QUERY_MEMORY_USED,
75bf215546Sopenharmony_ci   SVGA_QUERY_NUM_SHADERS,
76bf215546Sopenharmony_ci   SVGA_QUERY_NUM_RESOURCES,
77bf215546Sopenharmony_ci   SVGA_QUERY_NUM_STATE_OBJECTS,
78bf215546Sopenharmony_ci   SVGA_QUERY_NUM_SURFACE_VIEWS,
79bf215546Sopenharmony_ci   SVGA_QUERY_NUM_GENERATE_MIPMAP,
80bf215546Sopenharmony_ci   SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
81bf215546Sopenharmony_ci   SVGA_QUERY_NUM_COMMANDS_PER_DRAW,
82bf215546Sopenharmony_ci   SVGA_QUERY_SHADER_MEM_USED,
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci/*SVGA_QUERY_MAX has to be last because it is size of an array*/
85bf215546Sopenharmony_ci   SVGA_QUERY_MAX
86bf215546Sopenharmony_ci};
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci/**
90bf215546Sopenharmony_ci * Maximum supported number of constant buffers per shader
91bf215546Sopenharmony_ci * including the zero slot for the default constant buffer.
92bf215546Sopenharmony_ci */
93bf215546Sopenharmony_ci#define SVGA_MAX_CONST_BUFS 15
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci/**
96bf215546Sopenharmony_ci * Maximum constant buffer size that can be set in the
97bf215546Sopenharmony_ci * DXSetSingleConstantBuffer command is
98bf215546Sopenharmony_ci * DX10 constant buffer element count * 4 4-bytes components
99bf215546Sopenharmony_ci */
100bf215546Sopenharmony_ci#define SVGA_MAX_CONST_BUF_SIZE (4096 * 4 * sizeof(int))
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci#define CONST0_UPLOAD_ALIGNMENT 256
103bf215546Sopenharmony_ci#define SVGA_MAX_IMAGES         SVGA3D_MAX_UAVIEWS
104bf215546Sopenharmony_ci#define SVGA_MAX_SHADER_BUFFERS	SVGA3D_MAX_UAVIEWS
105bf215546Sopenharmony_ci#define SVGA_MAX_ATOMIC_BUFFERS	SVGA3D_MAX_UAVIEWS
106bf215546Sopenharmony_ci#define SVGA_MAX_UAVIEWS        SVGA3D_DX11_1_MAX_UAVIEWS
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_cienum svga_surface_state
109bf215546Sopenharmony_ci{
110bf215546Sopenharmony_ci   SVGA_SURFACE_STATE_CREATED,
111bf215546Sopenharmony_ci   SVGA_SURFACE_STATE_INVALIDATED,
112bf215546Sopenharmony_ci   SVGA_SURFACE_STATE_UPDATED,
113bf215546Sopenharmony_ci   SVGA_SURFACE_STATE_RENDERED,
114bf215546Sopenharmony_ci};
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_cistruct draw_vertex_shader;
117bf215546Sopenharmony_cistruct draw_fragment_shader;
118bf215546Sopenharmony_cistruct svga_shader_variant;
119bf215546Sopenharmony_cistruct SVGACmdMemory;
120bf215546Sopenharmony_cistruct util_bitmask;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct svga_cache_context;
124bf215546Sopenharmony_cistruct svga_tracked_state;
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_cistruct svga_blend_state {
127bf215546Sopenharmony_ci   unsigned need_white_fragments:1;
128bf215546Sopenharmony_ci   unsigned independent_blend_enable:1;
129bf215546Sopenharmony_ci   unsigned alpha_to_coverage:1;
130bf215546Sopenharmony_ci   unsigned alpha_to_one:1;
131bf215546Sopenharmony_ci   unsigned blend_color_alpha:1;  /**< set blend color to alpha value */
132bf215546Sopenharmony_ci   unsigned logicop_enabled:1;
133bf215546Sopenharmony_ci   unsigned logicop_mode:5;
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci   /** Per-render target state */
136bf215546Sopenharmony_ci   struct {
137bf215546Sopenharmony_ci      uint8_t writemask;
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci      boolean blend_enable;
140bf215546Sopenharmony_ci      uint8_t srcblend;
141bf215546Sopenharmony_ci      uint8_t dstblend;
142bf215546Sopenharmony_ci      uint8_t blendeq;
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci      boolean separate_alpha_blend_enable;
145bf215546Sopenharmony_ci      uint8_t srcblend_alpha;
146bf215546Sopenharmony_ci      uint8_t dstblend_alpha;
147bf215546Sopenharmony_ci      uint8_t blendeq_alpha;
148bf215546Sopenharmony_ci   } rt[PIPE_MAX_COLOR_BUFS];
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   SVGA3dBlendStateId id;  /**< vgpu10 */
151bf215546Sopenharmony_ci};
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_cistruct svga_depth_stencil_state {
154bf215546Sopenharmony_ci   unsigned zfunc:8;
155bf215546Sopenharmony_ci   unsigned zenable:1;
156bf215546Sopenharmony_ci   unsigned zwriteenable:1;
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   unsigned alphatestenable:1;
159bf215546Sopenharmony_ci   unsigned alphafunc:8;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci   struct {
162bf215546Sopenharmony_ci      unsigned enabled:1;
163bf215546Sopenharmony_ci      unsigned func:8;
164bf215546Sopenharmony_ci      unsigned fail:8;
165bf215546Sopenharmony_ci      unsigned zfail:8;
166bf215546Sopenharmony_ci      unsigned pass:8;
167bf215546Sopenharmony_ci   } stencil[2];
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci   /* SVGA3D has one ref/mask/writemask triple shared between front &
170bf215546Sopenharmony_ci    * back face stencil.  We really need two:
171bf215546Sopenharmony_ci    */
172bf215546Sopenharmony_ci   unsigned stencil_mask:8;
173bf215546Sopenharmony_ci   unsigned stencil_writemask:8;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   float    alpharef;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   SVGA3dDepthStencilStateId id;  /**< vgpu10 */
178bf215546Sopenharmony_ci};
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci#define SVGA_UNFILLED_DISABLE 0
181bf215546Sopenharmony_ci#define SVGA_UNFILLED_LINE    1
182bf215546Sopenharmony_ci#define SVGA_UNFILLED_POINT   2
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci#define SVGA_PIPELINE_FLAG_POINTS   (1<<PIPE_PRIM_POINTS)
185bf215546Sopenharmony_ci#define SVGA_PIPELINE_FLAG_LINES    (1<<PIPE_PRIM_LINES)
186bf215546Sopenharmony_ci#define SVGA_PIPELINE_FLAG_TRIS     (1<<PIPE_PRIM_TRIANGLES)
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci#define SVGA_MAX_FRAMEBUFFER_DEFAULT_SAMPLES 4
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_cistruct svga_rasterizer_state {
191bf215546Sopenharmony_ci   struct pipe_rasterizer_state templ; /* needed for draw module */
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci   unsigned shademode:8;
194bf215546Sopenharmony_ci   unsigned cullmode:8;
195bf215546Sopenharmony_ci   unsigned scissortestenable:1;
196bf215546Sopenharmony_ci   unsigned multisampleantialias:1;
197bf215546Sopenharmony_ci   unsigned antialiasedlineenable:1;
198bf215546Sopenharmony_ci   unsigned lastpixel:1;
199bf215546Sopenharmony_ci   unsigned pointsprite:1;
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci   unsigned linepattern;
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   float slopescaledepthbias;
204bf215546Sopenharmony_ci   float depthbias;
205bf215546Sopenharmony_ci   float pointsize;
206bf215546Sopenharmony_ci   float linewidth;
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ci   unsigned hw_fillmode:2;         /* PIPE_POLYGON_MODE_x */
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci   /** Which prims do we need help for?  Bitmask of (1 << PIPE_PRIM_x) flags */
211bf215546Sopenharmony_ci   unsigned need_pipeline:16;
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   SVGA3dRasterizerStateId id;    /**< vgpu10 */
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   /* Alternate SVGA rasterizer state object with forcedSampleCount */
216bf215546Sopenharmony_ci   int altRastIds[SVGA_MAX_FRAMEBUFFER_DEFAULT_SAMPLES+1];
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_ci   struct svga_rasterizer_state *no_cull_rasterizer;
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci   /** For debugging: */
221bf215546Sopenharmony_ci   const char* need_pipeline_tris_str;
222bf215546Sopenharmony_ci   const char* need_pipeline_lines_str;
223bf215546Sopenharmony_ci   const char* need_pipeline_points_str;
224bf215546Sopenharmony_ci};
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_cistruct svga_sampler_state {
227bf215546Sopenharmony_ci   unsigned mipfilter;
228bf215546Sopenharmony_ci   unsigned magfilter;
229bf215546Sopenharmony_ci   unsigned minfilter;
230bf215546Sopenharmony_ci   unsigned aniso_level;
231bf215546Sopenharmony_ci   float lod_bias;
232bf215546Sopenharmony_ci   unsigned addressu;
233bf215546Sopenharmony_ci   unsigned addressv;
234bf215546Sopenharmony_ci   unsigned addressw;
235bf215546Sopenharmony_ci   unsigned bordercolor;
236bf215546Sopenharmony_ci   unsigned normalized_coords:1;
237bf215546Sopenharmony_ci   unsigned compare_mode:1;
238bf215546Sopenharmony_ci   unsigned compare_func:3;
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci   unsigned min_lod;
241bf215546Sopenharmony_ci   unsigned view_min_lod;
242bf215546Sopenharmony_ci   unsigned view_max_lod;
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci   SVGA3dSamplerId id[2];
245bf215546Sopenharmony_ci};
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_cistruct svga_pipe_sampler_view
249bf215546Sopenharmony_ci{
250bf215546Sopenharmony_ci   struct pipe_sampler_view base;
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci   SVGA3dShaderResourceViewId id;
253bf215546Sopenharmony_ci};
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_cistatic inline struct svga_pipe_sampler_view *
257bf215546Sopenharmony_cisvga_pipe_sampler_view(struct pipe_sampler_view *v)
258bf215546Sopenharmony_ci{
259bf215546Sopenharmony_ci   return (struct svga_pipe_sampler_view *) v;
260bf215546Sopenharmony_ci}
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_cistruct svga_velems_state {
264bf215546Sopenharmony_ci   unsigned count;
265bf215546Sopenharmony_ci   struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
266bf215546Sopenharmony_ci   SVGA3dDeclType decl_type[PIPE_MAX_ATTRIBS]; /**< vertex attrib formats */
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_ci   /** Bitmasks indicating which attributes need format conversion */
269bf215546Sopenharmony_ci   unsigned adjust_attrib_range;     /**< range adjustment */
270bf215546Sopenharmony_ci   unsigned attrib_is_pure_int;      /**< pure int */
271bf215546Sopenharmony_ci   unsigned adjust_attrib_w_1;       /**< set w = 1 */
272bf215546Sopenharmony_ci   unsigned adjust_attrib_itof;      /**< int->float */
273bf215546Sopenharmony_ci   unsigned adjust_attrib_utof;      /**< uint->float */
274bf215546Sopenharmony_ci   unsigned attrib_is_bgra;          /**< R / B swizzling */
275bf215546Sopenharmony_ci   unsigned attrib_puint_to_snorm;   /**< 10_10_10_2 packed uint -> snorm */
276bf215546Sopenharmony_ci   unsigned attrib_puint_to_uscaled; /**< 10_10_10_2 packed uint -> uscaled */
277bf215546Sopenharmony_ci   unsigned attrib_puint_to_sscaled; /**< 10_10_10_2 packed uint -> sscaled */
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci   boolean need_swvfetch;
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   SVGA3dElementLayoutId id; /**< VGPU10 */
282bf215546Sopenharmony_ci};
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_cistruct svga_constant_buffer {
285bf215546Sopenharmony_ci   struct svga_winsys_surface *handle;
286bf215546Sopenharmony_ci   unsigned size;
287bf215546Sopenharmony_ci};
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_cistruct svga_raw_buffer {
290bf215546Sopenharmony_ci   struct svga_winsys_surface *handle;
291bf215546Sopenharmony_ci   unsigned buffer_offset;
292bf215546Sopenharmony_ci   unsigned buffer_size;
293bf215546Sopenharmony_ci   struct pipe_resource *buffer;
294bf215546Sopenharmony_ci   int32 srvid;
295bf215546Sopenharmony_ci};
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_ci/* Use to calculate differences between state emitted to hardware and
298bf215546Sopenharmony_ci * current driver-calculated state.
299bf215546Sopenharmony_ci */
300bf215546Sopenharmony_cistruct svga_state
301bf215546Sopenharmony_ci{
302bf215546Sopenharmony_ci   const struct svga_blend_state *blend;
303bf215546Sopenharmony_ci   const struct svga_depth_stencil_state *depth;
304bf215546Sopenharmony_ci   const struct svga_sampler_state *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
305bf215546Sopenharmony_ci   const struct svga_velems_state *velems;
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci   struct svga_rasterizer_state *rast;
308bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; /* or texture ID's? */
309bf215546Sopenharmony_ci   struct svga_fragment_shader *fs;
310bf215546Sopenharmony_ci   struct svga_vertex_shader *vs;
311bf215546Sopenharmony_ci   struct svga_geometry_shader *user_gs; /* user-specified GS */
312bf215546Sopenharmony_ci   struct svga_geometry_shader *gs;      /* derived GS */
313bf215546Sopenharmony_ci   /* derived tessellation control shader */
314bf215546Sopenharmony_ci   struct svga_tcs_shader *tcs;
315bf215546Sopenharmony_ci   /* derived tessellation evaluation shader */
316bf215546Sopenharmony_ci   struct svga_tes_shader *tes;
317bf215546Sopenharmony_ci   struct svga_compute_shader *cs;
318bf215546Sopenharmony_ci
319bf215546Sopenharmony_ci   struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
320bf215546Sopenharmony_ci   /** Constant buffers for each shader.
321bf215546Sopenharmony_ci    * The size should probably always match with that of
322bf215546Sopenharmony_ci    * svga_shader_emitter_v10.num_shader_consts.
323bf215546Sopenharmony_ci    */
324bf215546Sopenharmony_ci   struct pipe_constant_buffer constbufs[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
325bf215546Sopenharmony_ci   struct svga_raw_buffer rawbufs[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ci   struct pipe_framebuffer_state framebuffer;
328bf215546Sopenharmony_ci   float depthscale;
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci   /* Hack to limit the number of different render targets between
331bf215546Sopenharmony_ci    * flushes.  Helps avoid blowing out our surface cache in EXA.
332bf215546Sopenharmony_ci    */
333bf215546Sopenharmony_ci   int nr_fbs;
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_ci   struct pipe_poly_stipple poly_stipple;
336bf215546Sopenharmony_ci   struct pipe_scissor_state scissor[SVGA3D_DX_MAX_VIEWPORTS];
337bf215546Sopenharmony_ci   struct pipe_blend_color blend_color;
338bf215546Sopenharmony_ci   struct pipe_stencil_ref stencil_ref;
339bf215546Sopenharmony_ci   struct pipe_clip_state clip;
340bf215546Sopenharmony_ci   struct pipe_viewport_state viewport[SVGA3D_DX_MAX_VIEWPORTS];
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci   unsigned num_samplers[PIPE_SHADER_TYPES];
343bf215546Sopenharmony_ci   unsigned num_sampler_views[PIPE_SHADER_TYPES];
344bf215546Sopenharmony_ci   unsigned num_vertex_buffers;
345bf215546Sopenharmony_ci   enum pipe_prim_type reduced_prim;
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ci   unsigned vertex_id_bias;
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   struct {
350bf215546Sopenharmony_ci      unsigned flag_1d;
351bf215546Sopenharmony_ci      unsigned flag_srgb;
352bf215546Sopenharmony_ci   } tex_flags;
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   unsigned sample_mask;
355bf215546Sopenharmony_ci   unsigned vertices_per_patch;
356bf215546Sopenharmony_ci   float default_tesslevels[6]; /* tessellation (outer[4] + inner[2]) levels */
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci   /* Image views */
359bf215546Sopenharmony_ci   unsigned num_image_views[PIPE_SHADER_TYPES];
360bf215546Sopenharmony_ci   struct svga_image_view image_views[PIPE_SHADER_TYPES][SVGA_MAX_IMAGES];
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci   /* Shader buffers */
363bf215546Sopenharmony_ci   unsigned num_shader_buffers[PIPE_SHADER_TYPES];
364bf215546Sopenharmony_ci   struct svga_shader_buffer shader_buffers[PIPE_SHADER_TYPES][SVGA_MAX_SHADER_BUFFERS];
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci   /* HW atomic buffers */
367bf215546Sopenharmony_ci   unsigned num_atomic_buffers;
368bf215546Sopenharmony_ci   struct svga_shader_buffer atomic_buffers[SVGA_MAX_SHADER_BUFFERS];
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_ci   struct {
371bf215546Sopenharmony_ci      /* Determine the layout of the grid (in block units) to be used. */
372bf215546Sopenharmony_ci      unsigned size[3];
373bf215546Sopenharmony_ci      /* If DispatchIndirect is used, this will has grid size info*/
374bf215546Sopenharmony_ci      struct pipe_resource *indirect;
375bf215546Sopenharmony_ci   } grid_info;
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci};
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_cistruct svga_prescale {
380bf215546Sopenharmony_ci   float translate[4];
381bf215546Sopenharmony_ci   float scale[4];
382bf215546Sopenharmony_ci   boolean enabled;
383bf215546Sopenharmony_ci};
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_cistruct svga_depthrange {
386bf215546Sopenharmony_ci   float zmin;
387bf215546Sopenharmony_ci   float zmax;
388bf215546Sopenharmony_ci};
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci/* Updated by calling svga_update_state( SVGA_STATE_HW_CLEAR )
391bf215546Sopenharmony_ci */
392bf215546Sopenharmony_cistruct svga_hw_clear_state
393bf215546Sopenharmony_ci{
394bf215546Sopenharmony_ci   struct pipe_framebuffer_state framebuffer;
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci   /* VGPU9 only */
397bf215546Sopenharmony_ci   SVGA3dRect viewport;
398bf215546Sopenharmony_ci   struct svga_depthrange depthrange;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_ci   /* VGPU10 state */
401bf215546Sopenharmony_ci   SVGA3dViewport viewports[SVGA3D_DX_MAX_VIEWPORTS];
402bf215546Sopenharmony_ci   struct svga_prescale prescale[SVGA3D_DX_MAX_VIEWPORTS];
403bf215546Sopenharmony_ci   struct pipe_scissor_state scissors[SVGA3D_DX_MAX_VIEWPORTS];
404bf215546Sopenharmony_ci   unsigned num_prescale;
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ci   unsigned num_rendertargets;
407bf215546Sopenharmony_ci   struct pipe_surface *rtv[SVGA3D_MAX_RENDER_TARGETS];
408bf215546Sopenharmony_ci   struct pipe_surface *dsv;
409bf215546Sopenharmony_ci};
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_cistruct svga_hw_view_state
412bf215546Sopenharmony_ci{
413bf215546Sopenharmony_ci   struct pipe_resource *texture;
414bf215546Sopenharmony_ci   struct svga_sampler_view *v;
415bf215546Sopenharmony_ci   unsigned min_lod;
416bf215546Sopenharmony_ci   unsigned max_lod;
417bf215546Sopenharmony_ci   boolean dirty;
418bf215546Sopenharmony_ci};
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ci/* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
421bf215546Sopenharmony_ci */
422bf215546Sopenharmony_cistruct svga_hw_draw_state
423bf215546Sopenharmony_ci{
424bf215546Sopenharmony_ci   /** VGPU9 rasterization state */
425bf215546Sopenharmony_ci   unsigned rs[SVGA3D_RS_MAX];
426bf215546Sopenharmony_ci   /** VGPU9 texture sampler and bindings state */
427bf215546Sopenharmony_ci   unsigned ts[SVGA3D_PIXEL_SAMPLERREG_MAX][SVGA3D_TS_MAX];
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci   /** VGPU9 texture views */
430bf215546Sopenharmony_ci   unsigned num_views;
431bf215546Sopenharmony_ci   unsigned num_backed_views; /* views with backing copy of texture */
432bf215546Sopenharmony_ci   struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci   /** VGPU9 constant buffer values */
435bf215546Sopenharmony_ci   float cb[PIPE_SHADER_TYPES][SVGA3D_CONSTREG_MAX][4];
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci   /** Currently bound shaders */
438bf215546Sopenharmony_ci   struct svga_shader_variant *fs;
439bf215546Sopenharmony_ci   struct svga_shader_variant *vs;
440bf215546Sopenharmony_ci   struct svga_shader_variant *gs;
441bf215546Sopenharmony_ci   struct svga_shader_variant *tcs;
442bf215546Sopenharmony_ci   struct svga_shader_variant *tes;
443bf215546Sopenharmony_ci   struct svga_shader_variant *cs;
444bf215546Sopenharmony_ci
445bf215546Sopenharmony_ci   /** Currently bound constant buffer, per shader stage */
446bf215546Sopenharmony_ci   struct pipe_resource *constbuf[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
447bf215546Sopenharmony_ci   struct svga_constant_buffer constbufoffsets[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
448bf215546Sopenharmony_ci   struct svga_raw_buffer rawbufs[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
449bf215546Sopenharmony_ci   unsigned enabled_rawbufs[PIPE_SHADER_TYPES];
450bf215546Sopenharmony_ci
451bf215546Sopenharmony_ci   /** Bitmask of enabled constant buffers */
452bf215546Sopenharmony_ci   unsigned enabled_constbufs[PIPE_SHADER_TYPES];
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_ci   /**
455bf215546Sopenharmony_ci    * These are used to reduce the number of times we call u_upload_unmap()
456bf215546Sopenharmony_ci    * while updating the zero-th/default VGPU10 constant buffer.
457bf215546Sopenharmony_ci    */
458bf215546Sopenharmony_ci   struct pipe_resource *const0_buffer;
459bf215546Sopenharmony_ci   struct svga_winsys_surface *const0_handle;
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ci   /** VGPU10 HW state (used to prevent emitting redundant state) */
462bf215546Sopenharmony_ci   SVGA3dDepthStencilStateId depth_stencil_id;
463bf215546Sopenharmony_ci   unsigned stencil_ref;
464bf215546Sopenharmony_ci   SVGA3dBlendStateId blend_id;
465bf215546Sopenharmony_ci   float blend_factor[4];
466bf215546Sopenharmony_ci   unsigned blend_sample_mask;
467bf215546Sopenharmony_ci   SVGA3dRasterizerStateId rasterizer_id;
468bf215546Sopenharmony_ci   SVGA3dElementLayoutId layout_id;
469bf215546Sopenharmony_ci   SVGA3dPrimitiveType topology;
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci   /** Vertex buffer state */
472bf215546Sopenharmony_ci   SVGA3dVertexBuffer_v2 vbuffer_attrs[PIPE_MAX_ATTRIBS];
473bf215546Sopenharmony_ci   struct pipe_resource *vbuffers[PIPE_MAX_ATTRIBS];
474bf215546Sopenharmony_ci   unsigned num_vbuffers;
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci   struct pipe_resource *ib;  /**< index buffer for drawing */
477bf215546Sopenharmony_ci   SVGA3dSurfaceFormat ib_format;
478bf215546Sopenharmony_ci   unsigned ib_offset;
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci   unsigned num_samplers[PIPE_SHADER_TYPES];
481bf215546Sopenharmony_ci   SVGA3dSamplerId samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_ci   unsigned num_sampler_views[PIPE_SHADER_TYPES];
484bf215546Sopenharmony_ci   struct pipe_sampler_view
485bf215546Sopenharmony_ci      *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
486bf215546Sopenharmony_ci
487bf215546Sopenharmony_ci   /* used for rebinding */
488bf215546Sopenharmony_ci   unsigned default_constbuf_size[PIPE_SHADER_TYPES];
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci   boolean rasterizer_discard; /* set if rasterization is disabled */
491bf215546Sopenharmony_ci   boolean has_backed_views;   /* set if any of the rtv/dsv is a backed surface view */
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci   /* Image Views */
494bf215546Sopenharmony_ci   int uavSpliceIndex;
495bf215546Sopenharmony_ci   unsigned num_image_views[PIPE_SHADER_TYPES];
496bf215546Sopenharmony_ci   struct svga_image_view image_views[PIPE_SHADER_TYPES][SVGA_MAX_IMAGES];
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci   /* Shader Buffers */
499bf215546Sopenharmony_ci   unsigned num_shader_buffers[PIPE_SHADER_TYPES];
500bf215546Sopenharmony_ci   struct svga_shader_buffer shader_buffers[PIPE_SHADER_TYPES][SVGA_MAX_SHADER_BUFFERS];
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci   /* HW Atomic Buffers */
503bf215546Sopenharmony_ci   unsigned num_atomic_buffers;
504bf215546Sopenharmony_ci   struct svga_shader_buffer atomic_buffers[SVGA_MAX_SHADER_BUFFERS];
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci   /* UAV state */
507bf215546Sopenharmony_ci   unsigned num_uavs;
508bf215546Sopenharmony_ci   SVGA3dUAViewId uaViewIds[SVGA_MAX_UAVIEWS];
509bf215546Sopenharmony_ci   struct svga_winsys_surface *uaViews[SVGA_MAX_UAVIEWS];
510bf215546Sopenharmony_ci
511bf215546Sopenharmony_ci   /* Compute UAV state */
512bf215546Sopenharmony_ci   unsigned num_cs_uavs;
513bf215546Sopenharmony_ci   SVGA3dUAViewId csUAViewIds[SVGA_MAX_UAVIEWS];
514bf215546Sopenharmony_ci   struct svga_winsys_surface *csUAViews[SVGA_MAX_UAVIEWS];
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci   /* starting uav index for each shader */
517bf215546Sopenharmony_ci   unsigned uav_start_index[PIPE_SHADER_TYPES];
518bf215546Sopenharmony_ci
519bf215546Sopenharmony_ci   /* starting uav index for HW atomic buffers */
520bf215546Sopenharmony_ci   unsigned uav_atomic_buf_index;
521bf215546Sopenharmony_ci};
522bf215546Sopenharmony_ci
523bf215546Sopenharmony_ci
524bf215546Sopenharmony_ci/* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
525bf215546Sopenharmony_ci */
526bf215546Sopenharmony_cistruct svga_sw_state
527bf215546Sopenharmony_ci{
528bf215546Sopenharmony_ci   /* which parts we need */
529bf215546Sopenharmony_ci   boolean need_swvfetch;
530bf215546Sopenharmony_ci   boolean need_pipeline;
531bf215546Sopenharmony_ci   boolean need_swtnl;
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_ci   /* Flag to make sure that need sw is on while
534bf215546Sopenharmony_ci    * updating state within a swtnl call.
535bf215546Sopenharmony_ci    */
536bf215546Sopenharmony_ci   boolean in_swtnl_draw;
537bf215546Sopenharmony_ci};
538bf215546Sopenharmony_ci
539bf215546Sopenharmony_ci
540bf215546Sopenharmony_ci/* Queue some state updates (like rss) and submit them to hardware in
541bf215546Sopenharmony_ci * a single packet.
542bf215546Sopenharmony_ci */
543bf215546Sopenharmony_cistruct svga_hw_queue;
544bf215546Sopenharmony_ci
545bf215546Sopenharmony_cistruct svga_query;
546bf215546Sopenharmony_cistruct svga_qmem_alloc_entry;
547bf215546Sopenharmony_ci
548bf215546Sopenharmony_cienum svga_uav_type
549bf215546Sopenharmony_ci{
550bf215546Sopenharmony_ci   SVGA_IMAGE_VIEW = 0,
551bf215546Sopenharmony_ci   SVGA_SHADER_BUFFER
552bf215546Sopenharmony_ci};
553bf215546Sopenharmony_ci
554bf215546Sopenharmony_cistruct svga_uav
555bf215546Sopenharmony_ci{
556bf215546Sopenharmony_ci   enum svga_uav_type type;
557bf215546Sopenharmony_ci   union {
558bf215546Sopenharmony_ci      struct svga_image_view image_view;
559bf215546Sopenharmony_ci      struct svga_shader_buffer shader_buffer;
560bf215546Sopenharmony_ci   } desc;
561bf215546Sopenharmony_ci   struct pipe_resource *resource;
562bf215546Sopenharmony_ci   unsigned next_uaView;
563bf215546Sopenharmony_ci   SVGA3dUAViewId uaViewId;
564bf215546Sopenharmony_ci   unsigned timestamp[2];
565bf215546Sopenharmony_ci};
566bf215546Sopenharmony_ci
567bf215546Sopenharmony_cistruct svga_cache_uav
568bf215546Sopenharmony_ci{
569bf215546Sopenharmony_ci   unsigned num_uaViews;
570bf215546Sopenharmony_ci   unsigned next_uaView;
571bf215546Sopenharmony_ci   struct svga_uav uaViews[SVGA3D_DX11_1_MAX_UAVIEWS];
572bf215546Sopenharmony_ci};
573bf215546Sopenharmony_ci
574bf215546Sopenharmony_cistruct svga_context
575bf215546Sopenharmony_ci{
576bf215546Sopenharmony_ci   struct pipe_context pipe;
577bf215546Sopenharmony_ci   struct svga_winsys_context *swc;
578bf215546Sopenharmony_ci   struct blitter_context *blitter;
579bf215546Sopenharmony_ci   struct u_upload_mgr *const0_upload;
580bf215546Sopenharmony_ci   struct u_upload_mgr *tex_upload;
581bf215546Sopenharmony_ci
582bf215546Sopenharmony_ci   struct {
583bf215546Sopenharmony_ci      boolean no_swtnl;
584bf215546Sopenharmony_ci      boolean force_swtnl;
585bf215546Sopenharmony_ci      boolean use_min_mipmap;
586bf215546Sopenharmony_ci
587bf215546Sopenharmony_ci      /* incremented for each shader */
588bf215546Sopenharmony_ci      unsigned shader_id;
589bf215546Sopenharmony_ci
590bf215546Sopenharmony_ci      boolean no_line_width;
591bf215546Sopenharmony_ci      boolean force_hw_line_stipple;
592bf215546Sopenharmony_ci
593bf215546Sopenharmony_ci      /** To report perf/conformance/etc issues to the gallium frontend */
594bf215546Sopenharmony_ci      struct util_debug_callback callback;
595bf215546Sopenharmony_ci   } debug;
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci   struct {
598bf215546Sopenharmony_ci      struct draw_context *draw;
599bf215546Sopenharmony_ci      struct vbuf_render *backend;
600bf215546Sopenharmony_ci      unsigned hw_prim;
601bf215546Sopenharmony_ci      boolean new_vbuf;
602bf215546Sopenharmony_ci      boolean new_vdecl;
603bf215546Sopenharmony_ci   } swtnl;
604bf215546Sopenharmony_ci
605bf215546Sopenharmony_ci   /* Bitmask of blend state objects IDs */
606bf215546Sopenharmony_ci   struct util_bitmask *blend_object_id_bm;
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_ci   /* Bitmask of depth/stencil state objects IDs */
609bf215546Sopenharmony_ci   struct util_bitmask *ds_object_id_bm;
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_ci   /* Bitmask of input element object IDs */
612bf215546Sopenharmony_ci   struct util_bitmask *input_element_object_id_bm;
613bf215546Sopenharmony_ci
614bf215546Sopenharmony_ci   /* Bitmask of rasterizer object IDs */
615bf215546Sopenharmony_ci   struct util_bitmask *rast_object_id_bm;
616bf215546Sopenharmony_ci
617bf215546Sopenharmony_ci   /* Bitmask of sampler state objects IDs */
618bf215546Sopenharmony_ci   struct util_bitmask *sampler_object_id_bm;
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci   /* Bitmask of sampler view IDs */
621bf215546Sopenharmony_ci   struct util_bitmask *sampler_view_id_bm;
622bf215546Sopenharmony_ci
623bf215546Sopenharmony_ci   /* Bitmask of to-free sampler view IDs created for raw buffer srv */
624bf215546Sopenharmony_ci   struct util_bitmask *sampler_view_to_free_id_bm;
625bf215546Sopenharmony_ci
626bf215546Sopenharmony_ci   /* Bitmask of used shader IDs */
627bf215546Sopenharmony_ci   struct util_bitmask *shader_id_bm;
628bf215546Sopenharmony_ci
629bf215546Sopenharmony_ci   /* Bitmask of used surface view IDs */
630bf215546Sopenharmony_ci   struct util_bitmask *surface_view_id_bm;
631bf215546Sopenharmony_ci
632bf215546Sopenharmony_ci   /* Bitmask of used stream output IDs */
633bf215546Sopenharmony_ci   struct util_bitmask *stream_output_id_bm;
634bf215546Sopenharmony_ci
635bf215546Sopenharmony_ci   /* Bitmask of used query IDs */
636bf215546Sopenharmony_ci   struct util_bitmask *query_id_bm;
637bf215546Sopenharmony_ci
638bf215546Sopenharmony_ci   /* Bitmask of used uav IDs */
639bf215546Sopenharmony_ci   struct util_bitmask *uav_id_bm;
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci   /* Bitmask of to-free uav IDs */
642bf215546Sopenharmony_ci   struct util_bitmask *uav_to_free_id_bm;
643bf215546Sopenharmony_ci
644bf215546Sopenharmony_ci   struct {
645bf215546Sopenharmony_ci      uint64_t dirty[SVGA_STATE_MAX];
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci      /** bitmasks of which const buffers are changed */
648bf215546Sopenharmony_ci      unsigned dirty_constbufs[PIPE_SHADER_TYPES];
649bf215546Sopenharmony_ci
650bf215546Sopenharmony_ci      /** bitmasks of which const buffers to be bound as raw buffers */
651bf215546Sopenharmony_ci      unsigned raw_constbufs[PIPE_SHADER_TYPES];
652bf215546Sopenharmony_ci
653bf215546Sopenharmony_ci      unsigned texture_timestamp;
654bf215546Sopenharmony_ci      unsigned uav_timestamp[2];
655bf215546Sopenharmony_ci
656bf215546Sopenharmony_ci      struct svga_sw_state          sw;
657bf215546Sopenharmony_ci      struct svga_hw_draw_state     hw_draw;
658bf215546Sopenharmony_ci      struct svga_hw_clear_state    hw_clear;
659bf215546Sopenharmony_ci   } state;
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_ci   struct svga_state curr;      /* state from the gallium frontend */
662bf215546Sopenharmony_ci   uint64_t dirty;              /* statechanges since last update_state() */
663bf215546Sopenharmony_ci
664bf215546Sopenharmony_ci   union {
665bf215546Sopenharmony_ci      struct {
666bf215546Sopenharmony_ci         unsigned rendertargets:1;
667bf215546Sopenharmony_ci         unsigned texture_samplers:1;
668bf215546Sopenharmony_ci         unsigned constbufs:1;
669bf215546Sopenharmony_ci         unsigned vs:1;
670bf215546Sopenharmony_ci         unsigned fs:1;
671bf215546Sopenharmony_ci         unsigned gs:1;
672bf215546Sopenharmony_ci         unsigned tcs:1;
673bf215546Sopenharmony_ci         unsigned tes:1;
674bf215546Sopenharmony_ci         unsigned cs:1;
675bf215546Sopenharmony_ci         unsigned query:1;
676bf215546Sopenharmony_ci         unsigned images:1;
677bf215546Sopenharmony_ci         unsigned shaderbufs:1;
678bf215546Sopenharmony_ci         unsigned atomicbufs:1;
679bf215546Sopenharmony_ci         unsigned uav:1;
680bf215546Sopenharmony_ci         unsigned indexbuf:1;
681bf215546Sopenharmony_ci         unsigned vertexbufs:1;
682bf215546Sopenharmony_ci      } flags;
683bf215546Sopenharmony_ci      unsigned val;
684bf215546Sopenharmony_ci   } rebind;
685bf215546Sopenharmony_ci
686bf215546Sopenharmony_ci   struct svga_hwtnl *hwtnl;
687bf215546Sopenharmony_ci
688bf215546Sopenharmony_ci   /** Queries states */
689bf215546Sopenharmony_ci   struct svga_winsys_gb_query *gb_query;     /**< gb query object, one per context */
690bf215546Sopenharmony_ci   unsigned gb_query_len;                     /**< gb query object size */
691bf215546Sopenharmony_ci   struct util_bitmask *gb_query_alloc_mask;  /**< gb query object allocation mask */
692bf215546Sopenharmony_ci   struct svga_qmem_alloc_entry *gb_query_map[SVGA_QUERY_MAX];
693bf215546Sopenharmony_ci                                              /**< query mem block mapping */
694bf215546Sopenharmony_ci   struct svga_query *sq[SVGA_QUERY_MAX+12];  /**< queries currently in progress */
695bf215546Sopenharmony_ci                                              /* The last 12 entries are for streamout
696bf215546Sopenharmony_ci                                               * queries for stream 0..3
697bf215546Sopenharmony_ci                                               */
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_ci   /** List of buffers with queued transfers */
700bf215546Sopenharmony_ci   struct list_head dirty_buffers;
701bf215546Sopenharmony_ci
702bf215546Sopenharmony_ci   /** performance / info queries for HUD */
703bf215546Sopenharmony_ci   struct {
704bf215546Sopenharmony_ci      uint64_t num_draw_calls;          /**< SVGA_QUERY_DRAW_CALLS */
705bf215546Sopenharmony_ci      uint64_t num_fallbacks;           /**< SVGA_QUERY_NUM_FALLBACKS */
706bf215546Sopenharmony_ci      uint64_t num_flushes;             /**< SVGA_QUERY_NUM_FLUSHES */
707bf215546Sopenharmony_ci      uint64_t num_validations;         /**< SVGA_QUERY_NUM_VALIDATIONS */
708bf215546Sopenharmony_ci      uint64_t map_buffer_time;         /**< SVGA_QUERY_MAP_BUFFER_TIME */
709bf215546Sopenharmony_ci      uint64_t num_buffers_mapped;      /**< SVGA_QUERY_NUM_BUFFERS_MAPPED */
710bf215546Sopenharmony_ci      uint64_t num_textures_mapped;     /**< SVGA_QUERY_NUM_TEXTURES_MAPPED */
711bf215546Sopenharmony_ci      uint64_t num_command_buffers;     /**< SVGA_QUERY_NUM_COMMAND_BUFFERS */
712bf215546Sopenharmony_ci      uint64_t command_buffer_size;     /**< SVGA_QUERY_COMMAND_BUFFER_SIZE */
713bf215546Sopenharmony_ci      uint64_t flush_time;              /**< SVGA_QUERY_FLUSH_TIME */
714bf215546Sopenharmony_ci      uint64_t surface_write_flushes;   /**< SVGA_QUERY_SURFACE_WRITE_FLUSHES */
715bf215546Sopenharmony_ci      uint64_t num_readbacks;           /**< SVGA_QUERY_NUM_READBACKS */
716bf215546Sopenharmony_ci      uint64_t num_resource_updates;    /**< SVGA_QUERY_NUM_RESOURCE_UPDATES */
717bf215546Sopenharmony_ci      uint64_t num_buffer_uploads;      /**< SVGA_QUERY_NUM_BUFFER_UPLOADS */
718bf215546Sopenharmony_ci      uint64_t num_const_buf_updates;   /**< SVGA_QUERY_NUM_CONST_BUF_UPDATES */
719bf215546Sopenharmony_ci      uint64_t num_const_updates;       /**< SVGA_QUERY_NUM_CONST_UPDATES */
720bf215546Sopenharmony_ci      uint64_t num_shaders;             /**< SVGA_QUERY_NUM_SHADERS */
721bf215546Sopenharmony_ci
722bf215546Sopenharmony_ci      /** The following are summed for SVGA_QUERY_NUM_STATE_OBJECTS */
723bf215546Sopenharmony_ci      uint64_t num_blend_objects;
724bf215546Sopenharmony_ci      uint64_t num_depthstencil_objects;
725bf215546Sopenharmony_ci      uint64_t num_rasterizer_objects;
726bf215546Sopenharmony_ci      uint64_t num_sampler_objects;
727bf215546Sopenharmony_ci      uint64_t num_samplerview_objects;
728bf215546Sopenharmony_ci      uint64_t num_vertexelement_objects;
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_ci      uint64_t num_surface_views;       /**< SVGA_QUERY_NUM_SURFACE_VIEWS */
731bf215546Sopenharmony_ci      uint64_t num_bytes_uploaded;      /**< SVGA_QUERY_NUM_BYTES_UPLOADED */
732bf215546Sopenharmony_ci      uint64_t num_generate_mipmap;     /**< SVGA_QUERY_NUM_GENERATE_MIPMAP */
733bf215546Sopenharmony_ci      uint64_t shader_mem_used;         /**< SVGA_QUERY_SHADER_MEM_USED */
734bf215546Sopenharmony_ci
735bf215546Sopenharmony_ci      boolean uses_time;                /**< os_time_get() calls needed? */
736bf215546Sopenharmony_ci   } hud;
737bf215546Sopenharmony_ci
738bf215546Sopenharmony_ci   /** The currently bound stream output targets */
739bf215546Sopenharmony_ci   boolean in_streamout;                /* Set if streamout is active */
740bf215546Sopenharmony_ci   unsigned num_so_targets;
741bf215546Sopenharmony_ci   struct svga_winsys_surface *so_surfaces[SVGA3D_DX_MAX_SOTARGETS];
742bf215546Sopenharmony_ci   struct pipe_stream_output_target *so_targets[SVGA3D_DX_MAX_SOTARGETS];
743bf215546Sopenharmony_ci   struct svga_stream_output *current_so;
744bf215546Sopenharmony_ci
745bf215546Sopenharmony_ci   /**
746bf215546Sopenharmony_ci    * The following states are used in the workaround for auto draw with
747bf215546Sopenharmony_ci    * stream instancing.
748bf215546Sopenharmony_ci    */
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci   /* Last bound SO targets that can be used to get vertex count */
751bf215546Sopenharmony_ci   struct pipe_stream_output_target *vcount_so_targets[SVGA3D_DX_MAX_SOTARGETS];
752bf215546Sopenharmony_ci   unsigned vcount_buffer_stream;       /* SO buffer to stream index mask */
753bf215546Sopenharmony_ci   struct pipe_query *so_queries[4];    /* SO stat queries for each stream */
754bf215546Sopenharmony_ci
755bf215546Sopenharmony_ci   /** A blend state with blending disabled, for falling back to when blending
756bf215546Sopenharmony_ci    * is illegal (e.g. an integer texture is bound)
757bf215546Sopenharmony_ci    */
758bf215546Sopenharmony_ci   struct svga_blend_state *noop_blend;
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_ci   struct {
761bf215546Sopenharmony_ci      struct pipe_resource *texture;
762bf215546Sopenharmony_ci      struct svga_pipe_sampler_view *sampler_view;
763bf215546Sopenharmony_ci      void *sampler;
764bf215546Sopenharmony_ci   } polygon_stipple;
765bf215546Sopenharmony_ci
766bf215546Sopenharmony_ci   /** Depth stencil state created to disable depth stencil test */
767bf215546Sopenharmony_ci   struct svga_depth_stencil_state *depthstencil_disable;
768bf215546Sopenharmony_ci
769bf215546Sopenharmony_ci   /** Current conditional rendering predicate */
770bf215546Sopenharmony_ci   struct {
771bf215546Sopenharmony_ci      SVGA3dQueryId query_id;
772bf215546Sopenharmony_ci      boolean cond;
773bf215546Sopenharmony_ci   } pred;
774bf215546Sopenharmony_ci
775bf215546Sopenharmony_ci   boolean render_condition;
776bf215546Sopenharmony_ci   boolean disable_rasterizer; /* Set if to disable rasterization */
777bf215546Sopenharmony_ci   uint8_t patch_vertices;
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_ci   struct {
780bf215546Sopenharmony_ci      struct svga_tcs_shader *passthrough_tcs;
781bf215546Sopenharmony_ci      struct svga_vertex_shader *vs;
782bf215546Sopenharmony_ci      struct svga_tes_shader *tes;
783bf215546Sopenharmony_ci      unsigned vertices_per_patch;
784bf215546Sopenharmony_ci      boolean passthrough;
785bf215546Sopenharmony_ci   } tcs;
786bf215546Sopenharmony_ci
787bf215546Sopenharmony_ci   struct svga_cache_uav cache_uav;
788bf215546Sopenharmony_ci   struct pipe_resource *dummy_resource;
789bf215546Sopenharmony_ci};
790bf215546Sopenharmony_ci
791bf215546Sopenharmony_ci/* A flag for each frontend state object:
792bf215546Sopenharmony_ci */
793bf215546Sopenharmony_ci#define SVGA_NEW_BLEND               ((uint64_t) 0x1)
794bf215546Sopenharmony_ci#define SVGA_NEW_DEPTH_STENCIL_ALPHA ((uint64_t) 0x2)
795bf215546Sopenharmony_ci#define SVGA_NEW_RAST                ((uint64_t) 0x4)
796bf215546Sopenharmony_ci#define SVGA_NEW_SAMPLER             ((uint64_t) 0x8)
797bf215546Sopenharmony_ci#define SVGA_NEW_TEXTURE             ((uint64_t) 0x10)
798bf215546Sopenharmony_ci#define SVGA_NEW_VBUFFER             ((uint64_t) 0x20)
799bf215546Sopenharmony_ci#define SVGA_NEW_VELEMENT            ((uint64_t) 0x40)
800bf215546Sopenharmony_ci#define SVGA_NEW_FS                  ((uint64_t) 0x80)
801bf215546Sopenharmony_ci#define SVGA_NEW_VS                  ((uint64_t) 0x100)
802bf215546Sopenharmony_ci#define SVGA_NEW_FS_CONST_BUFFER     ((uint64_t) 0x200)
803bf215546Sopenharmony_ci#define SVGA_NEW_VS_CONST_BUFFER     ((uint64_t) 0x400)
804bf215546Sopenharmony_ci#define SVGA_NEW_FRAME_BUFFER        ((uint64_t) 0x800)
805bf215546Sopenharmony_ci#define SVGA_NEW_STIPPLE             ((uint64_t) 0x1000)
806bf215546Sopenharmony_ci#define SVGA_NEW_SCISSOR             ((uint64_t) 0x2000)
807bf215546Sopenharmony_ci#define SVGA_NEW_BLEND_COLOR         ((uint64_t) 0x4000)
808bf215546Sopenharmony_ci#define SVGA_NEW_CLIP                ((uint64_t) 0x8000)
809bf215546Sopenharmony_ci#define SVGA_NEW_VIEWPORT            ((uint64_t) 0x10000)
810bf215546Sopenharmony_ci#define SVGA_NEW_PRESCALE            ((uint64_t) 0x20000)
811bf215546Sopenharmony_ci#define SVGA_NEW_REDUCED_PRIMITIVE   ((uint64_t) 0x40000)
812bf215546Sopenharmony_ci#define SVGA_NEW_TEXTURE_BINDING     ((uint64_t) 0x80000)
813bf215546Sopenharmony_ci#define SVGA_NEW_NEED_PIPELINE       ((uint64_t) 0x100000)
814bf215546Sopenharmony_ci#define SVGA_NEW_NEED_SWVFETCH       ((uint64_t) 0x200000)
815bf215546Sopenharmony_ci#define SVGA_NEW_NEED_SWTNL          ((uint64_t) 0x400000)
816bf215546Sopenharmony_ci#define SVGA_NEW_FS_VARIANT          ((uint64_t) 0x800000)
817bf215546Sopenharmony_ci#define SVGA_NEW_VS_VARIANT          ((uint64_t) 0x1000000)
818bf215546Sopenharmony_ci#define SVGA_NEW_TEXTURE_FLAGS       ((uint64_t) 0x4000000)
819bf215546Sopenharmony_ci#define SVGA_NEW_STENCIL_REF         ((uint64_t) 0x8000000)
820bf215546Sopenharmony_ci#define SVGA_NEW_GS                  ((uint64_t) 0x10000000)
821bf215546Sopenharmony_ci#define SVGA_NEW_GS_CONST_BUFFER     ((uint64_t) 0x20000000)
822bf215546Sopenharmony_ci#define SVGA_NEW_GS_VARIANT          ((uint64_t) 0x40000000)
823bf215546Sopenharmony_ci#define SVGA_NEW_TEXTURE_CONSTS      ((uint64_t) 0x80000000)
824bf215546Sopenharmony_ci#define SVGA_NEW_TCS                 ((uint64_t) 0x100000000)
825bf215546Sopenharmony_ci#define SVGA_NEW_TES                 ((uint64_t) 0x200000000)
826bf215546Sopenharmony_ci#define SVGA_NEW_TCS_VARIANT         ((uint64_t) 0x400000000)
827bf215546Sopenharmony_ci#define SVGA_NEW_TES_VARIANT         ((uint64_t) 0x800000000)
828bf215546Sopenharmony_ci#define SVGA_NEW_TCS_CONST_BUFFER    ((uint64_t) 0x1000000000)
829bf215546Sopenharmony_ci#define SVGA_NEW_TES_CONST_BUFFER    ((uint64_t) 0x2000000000)
830bf215546Sopenharmony_ci#define SVGA_NEW_TCS_PARAM           ((uint64_t) 0x4000000000)
831bf215546Sopenharmony_ci#define SVGA_NEW_IMAGE_VIEW          ((uint64_t) 0x8000000000)
832bf215546Sopenharmony_ci#define SVGA_NEW_SHADER_BUFFER       ((uint64_t) 0x10000000000)
833bf215546Sopenharmony_ci#define SVGA_NEW_CS                  ((uint64_t) 0x20000000000)
834bf215546Sopenharmony_ci#define SVGA_NEW_CS_VARIANT          ((uint64_t) 0x40000000000)
835bf215546Sopenharmony_ci#define SVGA_NEW_CS_CONST_BUFFER     ((uint64_t) 0x80000000000)
836bf215546Sopenharmony_ci#define SVGA_NEW_FS_CONSTS           ((uint64_t) 0x100000000000)
837bf215546Sopenharmony_ci#define SVGA_NEW_VS_CONSTS           ((uint64_t) 0x200000000000)
838bf215546Sopenharmony_ci#define SVGA_NEW_GS_CONSTS           ((uint64_t) 0x400000000000)
839bf215546Sopenharmony_ci#define SVGA_NEW_TCS_CONSTS          ((uint64_t) 0x800000000000)
840bf215546Sopenharmony_ci#define SVGA_NEW_TES_CONSTS          ((uint64_t) 0x1000000000000)
841bf215546Sopenharmony_ci#define SVGA_NEW_CS_CONSTS           ((uint64_t) 0x2000000000000)
842bf215546Sopenharmony_ci#define SVGA_NEW_FS_RAW_BUFFER       ((uint64_t) 0x4000000000000)
843bf215546Sopenharmony_ci#define SVGA_NEW_VS_RAW_BUFFER       ((uint64_t) 0x8000000000000)
844bf215546Sopenharmony_ci#define SVGA_NEW_GS_RAW_BUFFER       ((uint64_t) 0x10000000000000)
845bf215546Sopenharmony_ci#define SVGA_NEW_TCS_RAW_BUFFER      ((uint64_t) 0x20000000000000)
846bf215546Sopenharmony_ci#define SVGA_NEW_TES_RAW_BUFFER      ((uint64_t) 0x40000000000000)
847bf215546Sopenharmony_ci#define SVGA_NEW_CS_RAW_BUFFER       ((uint64_t) 0x80000000000000)
848bf215546Sopenharmony_ci#define SVGA_NEW_ALL                 ((uint64_t) 0xFFFFFFFFFFFFFFFF)
849bf215546Sopenharmony_ci
850bf215546Sopenharmony_ci#define SVGA_NEW_CONST_BUFFER \
851bf215546Sopenharmony_ci   (SVGA_NEW_FS_CONST_BUFFER | SVGA_NEW_VS_CONST_BUFFER | \
852bf215546Sopenharmony_ci    SVGA_NEW_GS_CONST_BUFFER | SVGA_NEW_CS_CONST_BUFFER | \
853bf215546Sopenharmony_ci    SVGA_NEW_TCS_CONST_BUFFER | SVGA_NEW_TES_CONST_BUFFER)
854bf215546Sopenharmony_ci
855bf215546Sopenharmony_ci
856bf215546Sopenharmony_ci/** Program pipelines */
857bf215546Sopenharmony_cienum svga_pipe_type
858bf215546Sopenharmony_ci{
859bf215546Sopenharmony_ci   SVGA_PIPE_GRAPHICS = 0,
860bf215546Sopenharmony_ci   SVGA_PIPE_COMPUTE  = 1
861bf215546Sopenharmony_ci};
862bf215546Sopenharmony_ci
863bf215546Sopenharmony_civoid svga_init_state_functions( struct svga_context *svga );
864bf215546Sopenharmony_civoid svga_init_flush_functions( struct svga_context *svga );
865bf215546Sopenharmony_civoid svga_init_string_functions( struct svga_context *svga );
866bf215546Sopenharmony_civoid svga_init_blit_functions(struct svga_context *svga);
867bf215546Sopenharmony_ci
868bf215546Sopenharmony_civoid svga_init_blend_functions( struct svga_context *svga );
869bf215546Sopenharmony_civoid svga_init_depth_stencil_functions( struct svga_context *svga );
870bf215546Sopenharmony_civoid svga_init_misc_functions( struct svga_context *svga );
871bf215546Sopenharmony_civoid svga_init_rasterizer_functions( struct svga_context *svga );
872bf215546Sopenharmony_civoid svga_init_sampler_functions( struct svga_context *svga );
873bf215546Sopenharmony_civoid svga_init_cs_functions( struct svga_context *svga );
874bf215546Sopenharmony_civoid svga_init_fs_functions( struct svga_context *svga );
875bf215546Sopenharmony_civoid svga_init_vs_functions( struct svga_context *svga );
876bf215546Sopenharmony_civoid svga_init_gs_functions( struct svga_context *svga );
877bf215546Sopenharmony_civoid svga_init_ts_functions( struct svga_context *svga );
878bf215546Sopenharmony_civoid svga_init_vertex_functions( struct svga_context *svga );
879bf215546Sopenharmony_civoid svga_init_constbuffer_functions( struct svga_context *svga );
880bf215546Sopenharmony_civoid svga_init_draw_functions( struct svga_context *svga );
881bf215546Sopenharmony_civoid svga_init_query_functions( struct svga_context *svga );
882bf215546Sopenharmony_civoid svga_init_surface_functions(struct svga_context *svga);
883bf215546Sopenharmony_civoid svga_init_stream_output_functions( struct svga_context *svga );
884bf215546Sopenharmony_civoid svga_init_clear_functions( struct svga_context *svga );
885bf215546Sopenharmony_civoid svga_init_shader_image_functions( struct svga_context *svga );
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_civoid svga_cleanup_vertex_state( struct svga_context *svga );
888bf215546Sopenharmony_civoid svga_cleanup_sampler_state( struct svga_context *svga );
889bf215546Sopenharmony_civoid svga_cleanup_tss_binding( struct svga_context *svga );
890bf215546Sopenharmony_civoid svga_cleanup_framebuffer( struct svga_context *svga );
891bf215546Sopenharmony_civoid svga_cleanup_tcs_state( struct svga_context *svga );
892bf215546Sopenharmony_ci
893bf215546Sopenharmony_civoid svga_context_flush( struct svga_context *svga,
894bf215546Sopenharmony_ci                         struct pipe_fence_handle **pfence );
895bf215546Sopenharmony_ci
896bf215546Sopenharmony_civoid svga_context_finish(struct svga_context *svga);
897bf215546Sopenharmony_ci
898bf215546Sopenharmony_civoid svga_hwtnl_flush_retry( struct svga_context *svga );
899bf215546Sopenharmony_civoid svga_hwtnl_flush_buffer( struct svga_context *svga,
900bf215546Sopenharmony_ci                              struct pipe_resource *buffer );
901bf215546Sopenharmony_ciboolean svga_hwtnl_has_pending_prim(struct svga_hwtnl *);
902bf215546Sopenharmony_ci
903bf215546Sopenharmony_civoid svga_surfaces_flush(struct svga_context *svga);
904bf215546Sopenharmony_ci
905bf215546Sopenharmony_cistruct pipe_context *
906bf215546Sopenharmony_cisvga_context_create(struct pipe_screen *screen,
907bf215546Sopenharmony_ci                    void *priv, unsigned flags);
908bf215546Sopenharmony_ci
909bf215546Sopenharmony_civoid svga_toggle_render_condition(struct svga_context *svga,
910bf215546Sopenharmony_ci                                  boolean render_condition_enabled,
911bf215546Sopenharmony_ci                                  boolean on);
912bf215546Sopenharmony_ci
913bf215546Sopenharmony_ciint svga_define_rasterizer_object(struct svga_context *svga,
914bf215546Sopenharmony_ci                                  struct svga_rasterizer_state *,
915bf215546Sopenharmony_ci                                  unsigned samples);
916bf215546Sopenharmony_ci
917bf215546Sopenharmony_cienum pipe_error
918bf215546Sopenharmony_cisvga_validate_sampler_resources(struct svga_context *svga,
919bf215546Sopenharmony_ci                                enum svga_pipe_type);
920bf215546Sopenharmony_ci
921bf215546Sopenharmony_cienum pipe_error
922bf215546Sopenharmony_cisvga_validate_constant_buffers(struct svga_context *svga,
923bf215546Sopenharmony_ci                               enum svga_pipe_type);
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_cienum pipe_error
926bf215546Sopenharmony_cisvga_validate_image_views(struct svga_context *svga,
927bf215546Sopenharmony_ci                          enum svga_pipe_type);
928bf215546Sopenharmony_ci
929bf215546Sopenharmony_cienum pipe_error
930bf215546Sopenharmony_cisvga_validate_shader_buffers(struct svga_context *svga,
931bf215546Sopenharmony_ci                             enum svga_pipe_type);
932bf215546Sopenharmony_ci
933bf215546Sopenharmony_civoid
934bf215546Sopenharmony_cisvga_destroy_rawbuf_srv(struct svga_context *svga);
935bf215546Sopenharmony_ci
936bf215546Sopenharmony_civoid
937bf215546Sopenharmony_cisvga_uav_cache_init(struct svga_context *svga);
938bf215546Sopenharmony_ci
939bf215546Sopenharmony_civoid
940bf215546Sopenharmony_cisvga_destroy_rawbuf_srv(struct svga_context *svga);
941bf215546Sopenharmony_ci
942bf215546Sopenharmony_ci
943bf215546Sopenharmony_ci/***********************************************************************
944bf215546Sopenharmony_ci * Inline conversion functions.  These are better-typed than the
945bf215546Sopenharmony_ci * macros used previously:
946bf215546Sopenharmony_ci */
947bf215546Sopenharmony_cistatic inline struct svga_context *
948bf215546Sopenharmony_cisvga_context( struct pipe_context *pipe )
949bf215546Sopenharmony_ci{
950bf215546Sopenharmony_ci   return (struct svga_context *)pipe;
951bf215546Sopenharmony_ci}
952bf215546Sopenharmony_ci
953bf215546Sopenharmony_cistatic inline struct svga_winsys_screen *
954bf215546Sopenharmony_cisvga_sws(struct svga_context *svga)
955bf215546Sopenharmony_ci{
956bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws;
957bf215546Sopenharmony_ci}
958bf215546Sopenharmony_ci
959bf215546Sopenharmony_cistatic inline boolean
960bf215546Sopenharmony_cisvga_have_gb_objects(const struct svga_context *svga)
961bf215546Sopenharmony_ci{
962bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_gb_objects;
963bf215546Sopenharmony_ci}
964bf215546Sopenharmony_ci
965bf215546Sopenharmony_cistatic inline boolean
966bf215546Sopenharmony_cisvga_have_gb_dma(const struct svga_context *svga)
967bf215546Sopenharmony_ci{
968bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_gb_dma;
969bf215546Sopenharmony_ci}
970bf215546Sopenharmony_ci
971bf215546Sopenharmony_cistatic inline boolean
972bf215546Sopenharmony_cisvga_have_vgpu10(const struct svga_context *svga)
973bf215546Sopenharmony_ci{
974bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_vgpu10;
975bf215546Sopenharmony_ci}
976bf215546Sopenharmony_ci
977bf215546Sopenharmony_cistatic inline boolean
978bf215546Sopenharmony_cisvga_have_sm4_1(const struct svga_context *svga)
979bf215546Sopenharmony_ci{
980bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_sm4_1;
981bf215546Sopenharmony_ci}
982bf215546Sopenharmony_ci
983bf215546Sopenharmony_cistatic inline boolean
984bf215546Sopenharmony_cisvga_have_sm5(const struct svga_context *svga)
985bf215546Sopenharmony_ci{
986bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_sm5;
987bf215546Sopenharmony_ci}
988bf215546Sopenharmony_ci
989bf215546Sopenharmony_cistatic inline boolean
990bf215546Sopenharmony_cisvga_have_gl43(const struct svga_context *svga)
991bf215546Sopenharmony_ci{
992bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->have_gl43;
993bf215546Sopenharmony_ci}
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_cistatic inline boolean
996bf215546Sopenharmony_cisvga_need_to_rebind_resources(const struct svga_context *svga)
997bf215546Sopenharmony_ci{
998bf215546Sopenharmony_ci   return svga_screen(svga->pipe.screen)->sws->need_to_rebind_resources;
999bf215546Sopenharmony_ci}
1000bf215546Sopenharmony_ci
1001bf215546Sopenharmony_cistatic inline boolean
1002bf215546Sopenharmony_cisvga_rects_equal(const SVGA3dRect *r1, const SVGA3dRect *r2)
1003bf215546Sopenharmony_ci{
1004bf215546Sopenharmony_ci   return memcmp(r1, r2, sizeof(*r1)) == 0;
1005bf215546Sopenharmony_ci}
1006bf215546Sopenharmony_ci
1007bf215546Sopenharmony_ci
1008bf215546Sopenharmony_ci/* A helper function to return TRUE if sampler state mapping is
1009bf215546Sopenharmony_ci * to be used. Sampler state mapping is used in GL43 context
1010bf215546Sopenharmony_ci * if the number of sampler states exceeds the SVGA device limit or
1011bf215546Sopenharmony_ci * the sampler state mapping environment variable is set.
1012bf215546Sopenharmony_ci */
1013bf215546Sopenharmony_cistatic inline boolean
1014bf215546Sopenharmony_cisvga_use_sampler_state_mapping(const struct svga_context *svga,
1015bf215546Sopenharmony_ci                               unsigned num_sampler_states)
1016bf215546Sopenharmony_ci{
1017bf215546Sopenharmony_ci   return svga_have_gl43(svga) &&
1018bf215546Sopenharmony_ci          (svga_screen(svga->pipe.screen)->debug.sampler_state_mapping ||
1019bf215546Sopenharmony_ci           num_sampler_states > SVGA3D_DX_MAX_SAMPLERS);
1020bf215546Sopenharmony_ci}
1021bf215546Sopenharmony_ci
1022bf215546Sopenharmony_ci/**
1023bf215546Sopenharmony_ci * If the Gallium HUD is enabled, this will return the current time.
1024bf215546Sopenharmony_ci * Otherwise, just return zero.
1025bf215546Sopenharmony_ci */
1026bf215546Sopenharmony_cistatic inline int64_t
1027bf215546Sopenharmony_cisvga_get_time(struct svga_context *svga)
1028bf215546Sopenharmony_ci{
1029bf215546Sopenharmony_ci   return svga->hud.uses_time ? os_time_get() : 0;
1030bf215546Sopenharmony_ci}
1031bf215546Sopenharmony_ci
1032bf215546Sopenharmony_ci/*
1033bf215546Sopenharmony_ci * The SVGA_TRY_XX family of macros can be used to optionally replace a
1034bf215546Sopenharmony_ci * function call with an error value, the purpose is to trigger and test
1035bf215546Sopenharmony_ci * retry path handling.
1036bf215546Sopenharmony_ci */
1037bf215546Sopenharmony_ci#ifdef DEBUG
1038bf215546Sopenharmony_ci
1039bf215546Sopenharmony_ci/*
1040bf215546Sopenharmony_ci * Optionally replace a function call with a PIPE_ERROR_OUT_OF_MEMORY
1041bf215546Sopenharmony_ci * return value
1042bf215546Sopenharmony_ci */
1043bf215546Sopenharmony_ci#define SVGA_TRY(_func) \
1044bf215546Sopenharmony_ci   ((SVGA_DEBUG & DEBUG_RETRY) ? PIPE_ERROR_OUT_OF_MEMORY : (_func))
1045bf215546Sopenharmony_ci
1046bf215546Sopenharmony_ci/* Optionally replace a function call with a NULL return value */
1047bf215546Sopenharmony_ci#define SVGA_TRY_PTR(_func) \
1048bf215546Sopenharmony_ci   ((SVGA_DEBUG & DEBUG_RETRY) ? NULL : (_func))
1049bf215546Sopenharmony_ci
1050bf215546Sopenharmony_ci/*
1051bf215546Sopenharmony_ci * Optionally replace a function call with a NULL return value, and set
1052bf215546Sopenharmony_ci * the _retry parameter to TRUE.
1053bf215546Sopenharmony_ci */
1054bf215546Sopenharmony_ci#define SVGA_TRY_MAP(_func, _retry) \
1055bf215546Sopenharmony_ci   ((SVGA_DEBUG & DEBUG_RETRY) ? (_retry) = TRUE, NULL : (_func))
1056bf215546Sopenharmony_ci#else
1057bf215546Sopenharmony_ci
1058bf215546Sopenharmony_ci#define SVGA_TRY(_func) (_func)
1059bf215546Sopenharmony_ci
1060bf215546Sopenharmony_ci#define SVGA_TRY_PTR(_func) (_func)
1061bf215546Sopenharmony_ci
1062bf215546Sopenharmony_ci#define SVGA_TRY_MAP(_func, _retry) (_func)
1063bf215546Sopenharmony_ci#endif
1064bf215546Sopenharmony_ci
1065bf215546Sopenharmony_ci/**
1066bf215546Sopenharmony_ci * Enter retry processing after hitting out-of-command space
1067bf215546Sopenharmony_ci */
1068bf215546Sopenharmony_cistatic inline void
1069bf215546Sopenharmony_cisvga_retry_enter(struct svga_context *svga)
1070bf215546Sopenharmony_ci{
1071bf215546Sopenharmony_ci   /* We shouldn't nest retries, but currently we do. */
1072bf215546Sopenharmony_ci   if ((SVGA_DEBUG & DEBUG_RETRY) && svga->swc->in_retry) {
1073bf215546Sopenharmony_ci      debug_printf("WARNING: Recursive retry. Level: %u.\n",
1074bf215546Sopenharmony_ci                   svga->swc->in_retry);
1075bf215546Sopenharmony_ci   }
1076bf215546Sopenharmony_ci   svga->swc->in_retry++;
1077bf215546Sopenharmony_ci}
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_ci/**
1080bf215546Sopenharmony_ci * Exit retry processing after hitting out-of-command space
1081bf215546Sopenharmony_ci */
1082bf215546Sopenharmony_cistatic inline void
1083bf215546Sopenharmony_cisvga_retry_exit(struct svga_context *svga)
1084bf215546Sopenharmony_ci{
1085bf215546Sopenharmony_ci   assert(svga->swc->in_retry > 0);
1086bf215546Sopenharmony_ci   svga->swc->in_retry--;
1087bf215546Sopenharmony_ci}
1088bf215546Sopenharmony_ci
1089bf215546Sopenharmony_ci/**
1090bf215546Sopenharmony_ci * Perform a function call, and on failure flush the context and retry,
1091bf215546Sopenharmony_ci * asserting that the retry succeeded. On return, the boolean argument
1092bf215546Sopenharmony_ci * _retried indicates whether the function call was retried or not.
1093bf215546Sopenharmony_ci */
1094bf215546Sopenharmony_ci#define SVGA_RETRY_CHECK(_svga, _func, _retried)       \
1095bf215546Sopenharmony_ci   do {                                                \
1096bf215546Sopenharmony_ci      enum pipe_error ret;                             \
1097bf215546Sopenharmony_ci                                                       \
1098bf215546Sopenharmony_ci      ret = SVGA_TRY(_func);                           \
1099bf215546Sopenharmony_ci      (_retried) = (ret != PIPE_OK);                   \
1100bf215546Sopenharmony_ci      if (_retried) {                                  \
1101bf215546Sopenharmony_ci         svga_retry_enter(_svga);                      \
1102bf215546Sopenharmony_ci         svga_context_flush(_svga, NULL);              \
1103bf215546Sopenharmony_ci         ret = (_func);                                \
1104bf215546Sopenharmony_ci         assert(ret == PIPE_OK);                       \
1105bf215546Sopenharmony_ci         svga_retry_exit(_svga);                       \
1106bf215546Sopenharmony_ci      }                                                \
1107bf215546Sopenharmony_ci   } while(0)
1108bf215546Sopenharmony_ci
1109bf215546Sopenharmony_ci/**
1110bf215546Sopenharmony_ci * Perform a function call, and on failure flush the context and retry,
1111bf215546Sopenharmony_ci * asserting that the retry succeeded.
1112bf215546Sopenharmony_ci */
1113bf215546Sopenharmony_ci#define SVGA_RETRY(_svga, _func)                \
1114bf215546Sopenharmony_ci   do {                                         \
1115bf215546Sopenharmony_ci      UNUSED boolean retried;                   \
1116bf215546Sopenharmony_ci                                                \
1117bf215546Sopenharmony_ci      SVGA_RETRY_CHECK(_svga, _func, retried);  \
1118bf215546Sopenharmony_ci   } while(0)
1119bf215546Sopenharmony_ci
1120bf215546Sopenharmony_ci/**
1121bf215546Sopenharmony_ci * Perform a function call, and on out-of-memory, flush the context and
1122bf215546Sopenharmony_ci * retry. The retry return value is stored in _ret for reuse.
1123bf215546Sopenharmony_ci */
1124bf215546Sopenharmony_ci#define SVGA_RETRY_OOM(_svga, _ret, _func)              \
1125bf215546Sopenharmony_ci   do {                                                 \
1126bf215546Sopenharmony_ci      (_ret) = SVGA_TRY(_func);                         \
1127bf215546Sopenharmony_ci      if ((_ret) == PIPE_ERROR_OUT_OF_MEMORY) {         \
1128bf215546Sopenharmony_ci         svga_retry_enter(_svga);                       \
1129bf215546Sopenharmony_ci         svga_context_flush(_svga, NULL);               \
1130bf215546Sopenharmony_ci         (_ret) = (_func);                              \
1131bf215546Sopenharmony_ci         svga_retry_exit(_svga);                        \
1132bf215546Sopenharmony_ci      }                                                 \
1133bf215546Sopenharmony_ci   } while (0);
1134bf215546Sopenharmony_ci
1135bf215546Sopenharmony_ci#endif
1136