1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
26 #ifndef SVGA_CONTEXT_H
27 #define SVGA_CONTEXT_H
30 #include "pipe/p_context.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
34 #include "util/os_time.h"
36 #include "util/u_blitter.h"
37 #include "util/list.h"
39 #include "tgsi/tgsi_scan.h"
41 #include "svga_screen.h"
42 #include "svga_state.h"
43 #include "svga_winsys.h"
44 #include "svga_hw_reg.h"
45 #include "svga3d_shaderdefs.h"
46 #include "svga_debug.h"
48 /** Non-GPU queries for gallium HUD */
50 /* per-frame counters */
51 SVGA_QUERY_NUM_DRAW_CALLS
= PIPE_QUERY_DRIVER_SPECIFIC
,
52 SVGA_QUERY_NUM_FALLBACKS
,
53 SVGA_QUERY_NUM_FLUSHES
,
54 SVGA_QUERY_NUM_VALIDATIONS
,
55 SVGA_QUERY_MAP_BUFFER_TIME
,
56 SVGA_QUERY_NUM_BUFFERS_MAPPED
,
57 SVGA_QUERY_NUM_TEXTURES_MAPPED
,
58 SVGA_QUERY_NUM_BYTES_UPLOADED
,
59 SVGA_QUERY_NUM_COMMAND_BUFFERS
,
60 SVGA_QUERY_COMMAND_BUFFER_SIZE
,
61 SVGA_QUERY_FLUSH_TIME
,
62 SVGA_QUERY_SURFACE_WRITE_FLUSHES
,
63 SVGA_QUERY_NUM_READBACKS
,
64 SVGA_QUERY_NUM_RESOURCE_UPDATES
,
65 SVGA_QUERY_NUM_BUFFER_UPLOADS
,
66 SVGA_QUERY_NUM_CONST_BUF_UPDATES
,
67 SVGA_QUERY_NUM_CONST_UPDATES
,
68 SVGA_QUERY_NUM_SHADER_RELOCATIONS
,
69 SVGA_QUERY_NUM_SURFACE_RELOCATIONS
,
71 /* running total counters */
72 SVGA_QUERY_MEMORY_USED
,
73 SVGA_QUERY_NUM_SHADERS
,
74 SVGA_QUERY_NUM_RESOURCES
,
75 SVGA_QUERY_NUM_STATE_OBJECTS
,
76 SVGA_QUERY_NUM_SURFACE_VIEWS
,
77 SVGA_QUERY_NUM_GENERATE_MIPMAP
,
78 SVGA_QUERY_NUM_FAILED_ALLOCATIONS
,
79 SVGA_QUERY_NUM_COMMANDS_PER_DRAW
,
80 SVGA_QUERY_SHADER_MEM_USED
,
82 /*SVGA_QUERY_MAX has to be last because it is size of an array*/
87 * Maximum supported number of constant buffers per shader
89 #define SVGA_MAX_CONST_BUFS 14
92 * Maximum constant buffer size that can be set in the
93 * DXSetSingleConstantBuffer command is
94 * DX10 constant buffer element count * 4 4-bytes components
96 #define SVGA_MAX_CONST_BUF_SIZE (4096 * 4 * sizeof(int))
98 #define CONST0_UPLOAD_ALIGNMENT 256
100 struct draw_vertex_shader
;
101 struct draw_fragment_shader
;
102 struct svga_shader_variant
;
103 struct SVGACmdMemory
;
107 struct svga_cache_context
;
108 struct svga_tracked_state
;
110 struct svga_blend_state
{
111 unsigned need_white_fragments
:1;
112 unsigned independent_blend_enable
:1;
113 unsigned alpha_to_coverage
:1;
114 unsigned alpha_to_one
:1;
115 unsigned blend_color_alpha
:1; /**< set blend color to alpha value */
116 unsigned logicop_enabled
:1;
117 unsigned logicop_mode
:5;
119 /** Per-render target state */
123 boolean blend_enable
;
128 boolean separate_alpha_blend_enable
;
129 uint8_t srcblend_alpha
;
130 uint8_t dstblend_alpha
;
131 uint8_t blendeq_alpha
;
132 } rt
[PIPE_MAX_COLOR_BUFS
];
134 SVGA3dBlendStateId id
; /**< vgpu10 */
137 struct svga_depth_stencil_state
{
140 unsigned zwriteenable
:1;
142 unsigned alphatestenable
:1;
143 unsigned alphafunc
:8;
153 /* SVGA3D has one ref/mask/writemask triple shared between front &
154 * back face stencil. We really need two:
156 unsigned stencil_mask
:8;
157 unsigned stencil_writemask
:8;
161 SVGA3dDepthStencilStateId id
; /**< vgpu10 */
164 #define SVGA_UNFILLED_DISABLE 0
165 #define SVGA_UNFILLED_LINE 1
166 #define SVGA_UNFILLED_POINT 2
168 #define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
169 #define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
170 #define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
172 struct svga_rasterizer_state
{
173 struct pipe_rasterizer_state templ
; /* needed for draw module */
175 unsigned shademode
:8;
177 unsigned scissortestenable
:1;
178 unsigned multisampleantialias
:1;
179 unsigned antialiasedlineenable
:1;
180 unsigned lastpixel
:1;
181 unsigned pointsprite
:1;
183 unsigned linepattern
;
185 float slopescaledepthbias
;
190 unsigned hw_fillmode
:2; /* PIPE_POLYGON_MODE_x */
192 /** Which prims do we need help for? Bitmask of (1 << PIPE_PRIM_x) flags */
193 unsigned need_pipeline
:16;
195 SVGA3dRasterizerStateId id
; /**< vgpu10 */
197 /** For debugging: */
198 const char* need_pipeline_tris_str
;
199 const char* need_pipeline_lines_str
;
200 const char* need_pipeline_points_str
;
203 struct svga_sampler_state
{
207 unsigned aniso_level
;
212 unsigned bordercolor
;
213 unsigned normalized_coords
:1;
214 unsigned compare_mode
:1;
215 unsigned compare_func
:3;
218 unsigned view_min_lod
;
219 unsigned view_max_lod
;
221 SVGA3dSamplerId id
[2];
225 struct svga_pipe_sampler_view
227 struct pipe_sampler_view base
;
229 SVGA3dShaderResourceViewId id
;
233 static inline struct svga_pipe_sampler_view
*
234 svga_pipe_sampler_view(struct pipe_sampler_view
*v
)
236 return (struct svga_pipe_sampler_view
*) v
;
240 struct svga_velems_state
{
242 struct pipe_vertex_element velem
[PIPE_MAX_ATTRIBS
];
243 SVGA3dDeclType decl_type
[PIPE_MAX_ATTRIBS
]; /**< vertex attrib formats */
245 /** Bitmasks indicating which attributes need format conversion */
246 unsigned adjust_attrib_range
; /**< range adjustment */
247 unsigned attrib_is_pure_int
; /**< pure int */
248 unsigned adjust_attrib_w_1
; /**< set w = 1 */
249 unsigned adjust_attrib_itof
; /**< int->float */
250 unsigned adjust_attrib_utof
; /**< uint->float */
251 unsigned attrib_is_bgra
; /**< R / B swizzling */
252 unsigned attrib_puint_to_snorm
; /**< 10_10_10_2 packed uint -> snorm */
253 unsigned attrib_puint_to_uscaled
; /**< 10_10_10_2 packed uint -> uscaled */
254 unsigned attrib_puint_to_sscaled
; /**< 10_10_10_2 packed uint -> sscaled */
256 boolean need_swvfetch
;
258 SVGA3dElementLayoutId id
; /**< VGPU10 */
262 /* Use to calculate differences between state emitted to hardware and
263 * current driver-calculated state.
267 const struct svga_blend_state
*blend
;
268 const struct svga_depth_stencil_state
*depth
;
269 const struct svga_rasterizer_state
*rast
;
270 const struct svga_sampler_state
*sampler
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
271 const struct svga_velems_state
*velems
;
273 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
]; /* or texture ID's? */
274 struct svga_fragment_shader
*fs
;
275 struct svga_vertex_shader
*vs
;
276 struct svga_geometry_shader
*user_gs
; /* user-specified GS */
277 struct svga_geometry_shader
*gs
; /* derived GS */
278 /* derived tessellation control shader */
279 struct svga_tcs_shader
*tcs
;
280 /* derived tessellation evaluation shader */
281 struct svga_tes_shader
*tes
;
282 struct svga_compute_shader
*cs
;
284 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
285 /** Constant buffers for each shader.
286 * The size should probably always match with that of
287 * svga_shader_emitter_v10.num_shader_consts.
289 struct pipe_constant_buffer constbufs
[PIPE_SHADER_TYPES
][SVGA_MAX_CONST_BUFS
];
291 struct pipe_framebuffer_state framebuffer
;
294 /* Hack to limit the number of different render targets between
295 * flushes. Helps avoid blowing out our surface cache in EXA.
299 struct pipe_poly_stipple poly_stipple
;
300 struct pipe_scissor_state scissor
[SVGA3D_DX_MAX_VIEWPORTS
];
301 struct pipe_blend_color blend_color
;
302 struct pipe_stencil_ref stencil_ref
;
303 struct pipe_clip_state clip
;
304 struct pipe_viewport_state viewport
[SVGA3D_DX_MAX_VIEWPORTS
];
306 unsigned num_samplers
[PIPE_SHADER_TYPES
];
307 unsigned num_sampler_views
[PIPE_SHADER_TYPES
];
308 unsigned num_vertex_buffers
;
309 enum pipe_prim_type reduced_prim
;
316 unsigned sample_mask
;
317 unsigned vertices_per_patch
;
318 float default_tesslevels
[6]; /* tessellation (outer[4] + inner[2]) levels */
320 /* Determine the layout of the grid (in block units) to be used. */
322 /* If DispatchIndirect is used, this will has grid size info*/
323 struct pipe_resource
*indirect
;
327 struct svga_prescale
{
333 struct svga_depthrange
{
338 /* Updated by calling svga_update_state( SVGA_STATE_HW_CLEAR )
340 struct svga_hw_clear_state
342 struct pipe_framebuffer_state framebuffer
;
346 struct svga_depthrange depthrange
;
349 SVGA3dViewport viewports
[SVGA3D_DX_MAX_VIEWPORTS
];
350 struct svga_prescale prescale
[SVGA3D_DX_MAX_VIEWPORTS
];
351 struct pipe_scissor_state scissors
[SVGA3D_DX_MAX_VIEWPORTS
];
352 unsigned num_prescale
;
354 unsigned num_rendertargets
;
355 struct pipe_surface
*rtv
[SVGA3D_MAX_RENDER_TARGETS
];
356 struct pipe_surface
*dsv
;
359 struct svga_hw_view_state
361 struct pipe_resource
*texture
;
362 struct svga_sampler_view
*v
;
368 /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
370 struct svga_hw_draw_state
372 /** VGPU9 rasterization state */
373 unsigned rs
[SVGA3D_RS_MAX
];
374 /** VGPU9 texture sampler and bindings state */
375 unsigned ts
[SVGA3D_PIXEL_SAMPLERREG_MAX
][SVGA3D_TS_MAX
];
377 /** VGPU9 texture views */
379 unsigned num_backed_views
; /* views with backing copy of texture */
380 struct svga_hw_view_state views
[PIPE_MAX_SAMPLERS
];
382 /** VGPU9 constant buffer values */
383 float cb
[PIPE_SHADER_TYPES
][SVGA3D_CONSTREG_MAX
][4];
385 /** Currently bound shaders */
386 struct svga_shader_variant
*fs
;
387 struct svga_shader_variant
*vs
;
388 struct svga_shader_variant
*gs
;
389 struct svga_shader_variant
*tcs
;
390 struct svga_shader_variant
*tes
;
391 struct svga_shader_variant
*cs
;
393 /** Currently bound constant buffer, per shader stage */
394 struct pipe_resource
*constbuf
[PIPE_SHADER_TYPES
];
396 /** Bitmask of enabled constant buffers */
397 unsigned enabled_constbufs
[PIPE_SHADER_TYPES
];
400 * These are used to reduce the number of times we call u_upload_unmap()
401 * while updating the zero-th/default VGPU10 constant buffer.
403 struct pipe_resource
*const0_buffer
;
404 struct svga_winsys_surface
*const0_handle
;
406 /** VGPU10 HW state (used to prevent emitting redundant state) */
407 SVGA3dDepthStencilStateId depth_stencil_id
;
408 unsigned stencil_ref
;
409 SVGA3dBlendStateId blend_id
;
410 float blend_factor
[4];
411 unsigned blend_sample_mask
;
412 SVGA3dRasterizerStateId rasterizer_id
;
413 SVGA3dElementLayoutId layout_id
;
414 SVGA3dPrimitiveType topology
;
416 /** Vertex buffer state */
417 SVGA3dVertexBuffer vbuffer_attrs
[PIPE_MAX_ATTRIBS
];
418 struct pipe_resource
*vbuffers
[PIPE_MAX_ATTRIBS
];
419 unsigned num_vbuffers
;
421 struct pipe_resource
*ib
; /**< index buffer for drawing */
422 SVGA3dSurfaceFormat ib_format
;
425 unsigned num_samplers
[PIPE_SHADER_TYPES
];
426 SVGA3dSamplerId samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
428 unsigned num_sampler_views
[PIPE_SHADER_TYPES
];
429 struct pipe_sampler_view
430 *sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
432 /* used for rebinding */
433 unsigned default_constbuf_size
[PIPE_SHADER_TYPES
];
435 boolean rasterizer_discard
; /* set if rasterization is disabled */
436 boolean has_backed_views
; /* set if any of the rtv/dsv is a backed surface view */
440 /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
444 /* which parts we need */
445 boolean need_swvfetch
;
446 boolean need_pipeline
;
449 /* Flag to make sure that need sw is on while
450 * updating state within a swtnl call.
452 boolean in_swtnl_draw
;
456 /* Queue some state updates (like rss) and submit them to hardware in
459 struct svga_hw_queue
;
462 struct svga_qmem_alloc_entry
;
466 struct pipe_context pipe
;
467 struct svga_winsys_context
*swc
;
468 struct blitter_context
*blitter
;
469 struct u_upload_mgr
*const0_upload
;
470 struct u_upload_mgr
*tex_upload
;
475 boolean use_min_mipmap
;
477 /* incremented for each shader */
480 boolean no_line_width
;
481 boolean force_hw_line_stipple
;
483 /** To report perf/conformance/etc issues to the gallium frontend */
484 struct pipe_debug_callback callback
;
488 struct draw_context
*draw
;
489 struct vbuf_render
*backend
;
495 /* Bitmask of blend state objects IDs */
496 struct util_bitmask
*blend_object_id_bm
;
498 /* Bitmask of depth/stencil state objects IDs */
499 struct util_bitmask
*ds_object_id_bm
;
501 /* Bitmaks of input element object IDs */
502 struct util_bitmask
*input_element_object_id_bm
;
504 /* Bitmask of rasterizer object IDs */
505 struct util_bitmask
*rast_object_id_bm
;
507 /* Bitmask of sampler state objects IDs */
508 struct util_bitmask
*sampler_object_id_bm
;
510 /* Bitmask of sampler view IDs */
511 struct util_bitmask
*sampler_view_id_bm
;
513 /* Bitmask of used shader IDs */
514 struct util_bitmask
*shader_id_bm
;
516 /* Bitmask of used surface view IDs */
517 struct util_bitmask
*surface_view_id_bm
;
519 /* Bitmask of used stream output IDs */
520 struct util_bitmask
*stream_output_id_bm
;
522 /* Bitmask of used query IDs */
523 struct util_bitmask
*query_id_bm
;
526 uint64_t dirty
[SVGA_STATE_MAX
];
528 /** bitmasks of which const buffers are changed */
529 unsigned dirty_constbufs
[PIPE_SHADER_TYPES
];
531 unsigned texture_timestamp
;
533 struct svga_sw_state sw
;
534 struct svga_hw_draw_state hw_draw
;
535 struct svga_hw_clear_state hw_clear
;
538 struct svga_state curr
; /* state from the gallium frontend */
539 uint64_t dirty
; /* statechanges since last update_state() */
543 unsigned rendertargets
:1;
544 unsigned texture_samplers
:1;
545 unsigned constbufs
:1;
557 struct svga_hwtnl
*hwtnl
;
559 /** Queries states */
560 struct svga_winsys_gb_query
*gb_query
; /**< gb query object, one per context */
561 unsigned gb_query_len
; /**< gb query object size */
562 struct util_bitmask
*gb_query_alloc_mask
; /**< gb query object allocation mask */
563 struct svga_qmem_alloc_entry
*gb_query_map
[SVGA_QUERY_MAX
];
564 /**< query mem block mapping */
565 struct svga_query
*sq
[SVGA_QUERY_MAX
+12]; /**< queries currently in progress */
566 /* The last 12 entries are for streamout
567 * queries for stream 0..3
570 /** List of buffers with queued transfers */
571 struct list_head dirty_buffers
;
573 /** performance / info queries for HUD */
575 uint64_t num_draw_calls
; /**< SVGA_QUERY_DRAW_CALLS */
576 uint64_t num_fallbacks
; /**< SVGA_QUERY_NUM_FALLBACKS */
577 uint64_t num_flushes
; /**< SVGA_QUERY_NUM_FLUSHES */
578 uint64_t num_validations
; /**< SVGA_QUERY_NUM_VALIDATIONS */
579 uint64_t map_buffer_time
; /**< SVGA_QUERY_MAP_BUFFER_TIME */
580 uint64_t num_buffers_mapped
; /**< SVGA_QUERY_NUM_BUFFERS_MAPPED */
581 uint64_t num_textures_mapped
; /**< SVGA_QUERY_NUM_TEXTURES_MAPPED */
582 uint64_t num_command_buffers
; /**< SVGA_QUERY_NUM_COMMAND_BUFFERS */
583 uint64_t command_buffer_size
; /**< SVGA_QUERY_COMMAND_BUFFER_SIZE */
584 uint64_t flush_time
; /**< SVGA_QUERY_FLUSH_TIME */
585 uint64_t surface_write_flushes
; /**< SVGA_QUERY_SURFACE_WRITE_FLUSHES */
586 uint64_t num_readbacks
; /**< SVGA_QUERY_NUM_READBACKS */
587 uint64_t num_resource_updates
; /**< SVGA_QUERY_NUM_RESOURCE_UPDATES */
588 uint64_t num_buffer_uploads
; /**< SVGA_QUERY_NUM_BUFFER_UPLOADS */
589 uint64_t num_const_buf_updates
; /**< SVGA_QUERY_NUM_CONST_BUF_UPDATES */
590 uint64_t num_const_updates
; /**< SVGA_QUERY_NUM_CONST_UPDATES */
591 uint64_t num_shaders
; /**< SVGA_QUERY_NUM_SHADERS */
593 /** The following are summed for SVGA_QUERY_NUM_STATE_OBJECTS */
594 uint64_t num_blend_objects
;
595 uint64_t num_depthstencil_objects
;
596 uint64_t num_rasterizer_objects
;
597 uint64_t num_sampler_objects
;
598 uint64_t num_samplerview_objects
;
599 uint64_t num_vertexelement_objects
;
601 uint64_t num_surface_views
; /**< SVGA_QUERY_NUM_SURFACE_VIEWS */
602 uint64_t num_bytes_uploaded
; /**< SVGA_QUERY_NUM_BYTES_UPLOADED */
603 uint64_t num_generate_mipmap
; /**< SVGA_QUERY_NUM_GENERATE_MIPMAP */
604 uint64_t shader_mem_used
; /**< SVGA_QUERY_SHADER_MEM_USED */
606 boolean uses_time
; /**< os_time_get() calls needed? */
609 /** The currently bound stream output targets */
610 boolean in_streamout
; /* Set if streamout is active */
611 unsigned num_so_targets
;
612 struct svga_winsys_surface
*so_surfaces
[SVGA3D_DX_MAX_SOTARGETS
];
613 struct pipe_stream_output_target
*so_targets
[SVGA3D_DX_MAX_SOTARGETS
];
614 struct svga_stream_output
*current_so
;
617 * The following states are used in the workaround for auto draw with
621 /* Last bound SO targets that can be used to get vertex count */
622 struct pipe_stream_output_target
*vcount_so_targets
[SVGA3D_DX_MAX_SOTARGETS
];
623 unsigned vcount_buffer_stream
; /* SO buffer to stream index mask */
624 struct pipe_query
*so_queries
[4]; /* SO stat queries for each stream */
626 /** A blend state with blending disabled, for falling back to when blending
627 * is illegal (e.g. an integer texture is bound)
629 struct svga_blend_state
*noop_blend
;
632 struct pipe_resource
*texture
;
633 struct svga_pipe_sampler_view
*sampler_view
;
637 /** Alternate rasterizer states created for point sprite */
638 struct svga_rasterizer_state
*rasterizer_no_cull
[2];
640 /** Depth stencil state created to disable depth stencil test */
641 struct svga_depth_stencil_state
*depthstencil_disable
;
643 /** Current conditional rendering predicate */
645 SVGA3dQueryId query_id
;
649 boolean render_condition
;
650 boolean disable_rasterizer
; /* Set if to disable rasterization */
653 struct svga_tcs_shader
*passthrough_tcs
;
654 struct svga_vertex_shader
*vs
;
655 struct svga_tes_shader
*tes
;
656 unsigned vertices_per_patch
;
662 /* A flag for each frontend state object:
664 #define SVGA_NEW_BLEND ((uint64_t) 0x1)
665 #define SVGA_NEW_DEPTH_STENCIL_ALPHA ((uint64_t) 0x2)
666 #define SVGA_NEW_RAST ((uint64_t) 0x4)
667 #define SVGA_NEW_SAMPLER ((uint64_t) 0x8)
668 #define SVGA_NEW_TEXTURE ((uint64_t) 0x10)
669 #define SVGA_NEW_VBUFFER ((uint64_t) 0x20)
670 #define SVGA_NEW_VELEMENT ((uint64_t) 0x40)
671 #define SVGA_NEW_FS ((uint64_t) 0x80)
672 #define SVGA_NEW_VS ((uint64_t) 0x100)
673 #define SVGA_NEW_FS_CONST_BUFFER ((uint64_t) 0x200)
674 #define SVGA_NEW_VS_CONST_BUFFER ((uint64_t) 0x400)
675 #define SVGA_NEW_FRAME_BUFFER ((uint64_t) 0x800)
676 #define SVGA_NEW_STIPPLE ((uint64_t) 0x1000)
677 #define SVGA_NEW_SCISSOR ((uint64_t) 0x2000)
678 #define SVGA_NEW_BLEND_COLOR ((uint64_t) 0x4000)
679 #define SVGA_NEW_CLIP ((uint64_t) 0x8000)
680 #define SVGA_NEW_VIEWPORT ((uint64_t) 0x10000)
681 #define SVGA_NEW_PRESCALE ((uint64_t) 0x20000)
682 #define SVGA_NEW_REDUCED_PRIMITIVE ((uint64_t) 0x40000)
683 #define SVGA_NEW_TEXTURE_BINDING ((uint64_t) 0x80000)
684 #define SVGA_NEW_NEED_PIPELINE ((uint64_t) 0x100000)
685 #define SVGA_NEW_NEED_SWVFETCH ((uint64_t) 0x200000)
686 #define SVGA_NEW_NEED_SWTNL ((uint64_t) 0x400000)
687 #define SVGA_NEW_FS_VARIANT ((uint64_t) 0x800000)
688 #define SVGA_NEW_VS_VARIANT ((uint64_t) 0x1000000)
689 #define SVGA_NEW_TEXTURE_FLAGS ((uint64_t) 0x4000000)
690 #define SVGA_NEW_STENCIL_REF ((uint64_t) 0x8000000)
691 #define SVGA_NEW_GS ((uint64_t) 0x10000000)
692 #define SVGA_NEW_GS_CONST_BUFFER ((uint64_t) 0x20000000)
693 #define SVGA_NEW_GS_VARIANT ((uint64_t) 0x40000000)
694 #define SVGA_NEW_TEXTURE_CONSTS ((uint64_t) 0x80000000)
695 #define SVGA_NEW_TCS ((uint64_t) 0x100000000)
696 #define SVGA_NEW_TES ((uint64_t) 0x200000000)
697 #define SVGA_NEW_TCS_VARIANT ((uint64_t) 0x400000000)
698 #define SVGA_NEW_TES_VARIANT ((uint64_t) 0x800000000)
699 #define SVGA_NEW_TCS_CONST_BUFFER ((uint64_t) 0x1000000000)
700 #define SVGA_NEW_TES_CONST_BUFFER ((uint64_t) 0x2000000000)
701 #define SVGA_NEW_TCS_PARAM ((uint64_t) 0x4000000000)
702 #define SVGA_NEW_ALL ((uint64_t) 0xFFFFFFFFFFFFFFFF)
705 void svga_init_state_functions( struct svga_context
*svga
);
706 void svga_init_flush_functions( struct svga_context
*svga
);
707 void svga_init_string_functions( struct svga_context
*svga
);
708 void svga_init_blit_functions(struct svga_context
*svga
);
710 void svga_init_blend_functions( struct svga_context
*svga
);
711 void svga_init_depth_stencil_functions( struct svga_context
*svga
);
712 void svga_init_misc_functions( struct svga_context
*svga
);
713 void svga_init_rasterizer_functions( struct svga_context
*svga
);
714 void svga_init_sampler_functions( struct svga_context
*svga
);
715 void svga_init_cs_functions( struct svga_context
*svga
);
716 void svga_init_fs_functions( struct svga_context
*svga
);
717 void svga_init_vs_functions( struct svga_context
*svga
);
718 void svga_init_gs_functions( struct svga_context
*svga
);
719 void svga_init_ts_functions( struct svga_context
*svga
);
720 void svga_init_vertex_functions( struct svga_context
*svga
);
721 void svga_init_constbuffer_functions( struct svga_context
*svga
);
722 void svga_init_draw_functions( struct svga_context
*svga
);
723 void svga_init_query_functions( struct svga_context
*svga
);
724 void svga_init_surface_functions(struct svga_context
*svga
);
725 void svga_init_stream_output_functions( struct svga_context
*svga
);
726 void svga_init_clear_functions( struct svga_context
*svga
);
728 void svga_cleanup_vertex_state( struct svga_context
*svga
);
729 void svga_cleanup_sampler_state( struct svga_context
*svga
);
730 void svga_cleanup_tss_binding( struct svga_context
*svga
);
731 void svga_cleanup_framebuffer( struct svga_context
*svga
);
732 void svga_cleanup_tcs_state( struct svga_context
*svga
);
734 void svga_context_flush( struct svga_context
*svga
,
735 struct pipe_fence_handle
**pfence
);
737 void svga_context_finish(struct svga_context
*svga
);
739 void svga_hwtnl_flush_retry( struct svga_context
*svga
);
740 void svga_hwtnl_flush_buffer( struct svga_context
*svga
,
741 struct pipe_resource
*buffer
);
743 void svga_surfaces_flush(struct svga_context
*svga
);
745 struct pipe_context
*
746 svga_context_create(struct pipe_screen
*screen
,
747 void *priv
, unsigned flags
);
749 void svga_toggle_render_condition(struct svga_context
*svga
,
750 boolean render_condition_enabled
,
753 /***********************************************************************
754 * Inline conversion functions. These are better-typed than the
755 * macros used previously:
757 static inline struct svga_context
*
758 svga_context( struct pipe_context
*pipe
)
760 return (struct svga_context
*)pipe
;
763 static inline struct svga_winsys_screen
*
764 svga_sws(struct svga_context
*svga
)
766 return svga_screen(svga
->pipe
.screen
)->sws
;
769 static inline boolean
770 svga_have_gb_objects(const struct svga_context
*svga
)
772 return svga_screen(svga
->pipe
.screen
)->sws
->have_gb_objects
;
775 static inline boolean
776 svga_have_gb_dma(const struct svga_context
*svga
)
778 return svga_screen(svga
->pipe
.screen
)->sws
->have_gb_dma
;
781 static inline boolean
782 svga_have_vgpu10(const struct svga_context
*svga
)
784 return svga_screen(svga
->pipe
.screen
)->sws
->have_vgpu10
;
787 static inline boolean
788 svga_have_sm4_1(const struct svga_context
*svga
)
790 return svga_screen(svga
->pipe
.screen
)->sws
->have_sm4_1
;
793 static inline boolean
794 svga_have_sm5(const struct svga_context
*svga
)
796 return svga_screen(svga
->pipe
.screen
)->sws
->have_sm5
;
799 static inline boolean
800 svga_need_to_rebind_resources(const struct svga_context
*svga
)
802 return svga_screen(svga
->pipe
.screen
)->sws
->need_to_rebind_resources
;
805 static inline boolean
806 svga_rects_equal(const SVGA3dRect
*r1
, const SVGA3dRect
*r2
)
808 return memcmp(r1
, r2
, sizeof(*r1
)) == 0;
812 * If the Gallium HUD is enabled, this will return the current time.
813 * Otherwise, just return zero.
815 static inline int64_t
816 svga_get_time(struct svga_context
*svga
)
818 return svga
->hud
.uses_time
? os_time_get() : 0;
822 * The SVGA_TRY_XX family of macros can be used to optionally replace a
823 * function call with an error value, the purpose is to trigger and test
824 * retry path handling.
829 * Optionally replace a function call with a PIPE_ERROR_OUT_OF_MEMORY
832 #define SVGA_TRY(_func) \
833 ((SVGA_DEBUG & DEBUG_RETRY) ? PIPE_ERROR_OUT_OF_MEMORY : (_func))
835 /* Optionally replace a function call with a NULL return value */
836 #define SVGA_TRY_PTR(_func) \
837 ((SVGA_DEBUG & DEBUG_RETRY) ? NULL : (_func))
840 * Optionally replace a function call with a NULL return value, and set
841 * the _retry parameter to TRUE.
843 #define SVGA_TRY_MAP(_func, _retry) \
844 ((SVGA_DEBUG & DEBUG_RETRY) ? (_retry) = TRUE, NULL : (_func))
847 #define SVGA_TRY(_func) (_func)
849 #define SVGA_TRY_PTR(_func) (_func)
851 #define SVGA_TRY_MAP(_func, _retry) (_func)
855 * Enter retry processing after hitting out-of-command space
858 svga_retry_enter(struct svga_context
*svga
)
860 /* We shouldn't nest retries, but currently we do. */
861 if ((SVGA_DEBUG
& DEBUG_RETRY
) && svga
->swc
->in_retry
) {
862 debug_printf("WARNING: Recursive retry. Level: %u.\n",
863 svga
->swc
->in_retry
);
865 svga
->swc
->in_retry
++;
869 * Exit retry processing after hitting out-of-command space
872 svga_retry_exit(struct svga_context
*svga
)
874 assert(svga
->swc
->in_retry
> 0);
875 svga
->swc
->in_retry
--;
879 * Perform a function call, and on failure flush the context and retry,
880 * asserting that the retry succeeded. On return, the boolean argument
881 * _retried indicates whether the function call was retried or not.
883 #define SVGA_RETRY_CHECK(_svga, _func, _retried) \
885 enum pipe_error ret; \
887 ret = SVGA_TRY(_func); \
888 (_retried) = (ret != PIPE_OK); \
890 svga_retry_enter(_svga); \
891 svga_context_flush(_svga, NULL); \
893 assert(ret == PIPE_OK); \
894 svga_retry_exit(_svga); \
899 * Perform a function call, and on failure flush the context and retry,
900 * asserting that the retry succeeded.
902 #define SVGA_RETRY(_svga, _func) \
904 UNUSED boolean retried; \
906 SVGA_RETRY_CHECK(_svga, _func, retried); \
910 * Perform a function call, and on out-of-memory, flush the context and
911 * retry. The retry return value is stored in _ret for reuse.
913 #define SVGA_RETRY_OOM(_svga, _ret, _func) \
915 (_ret) = SVGA_TRY(_func); \
916 if ((_ret) == PIPE_ERROR_OUT_OF_MEMORY) { \
917 svga_retry_enter(_svga); \
918 svga_context_flush(_svga, NULL); \
920 svga_retry_exit(_svga); \