1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "main/arrayobj.h"
32 #include "main/mtypes.h"
33 #include "frontend/api.h"
34 #include "main/fbobject.h"
35 #include "state_tracker/st_atom.h"
36 #include "util/u_helpers.h"
37 #include "util/u_inlines.h"
38 #include "util/list.h"
40 #include "util/list.h"
41 #include "cso_cache/cso_context.h"
49 struct dd_function_table
;
52 struct gen_mipmap_state
;
55 struct st_perf_monitor_group
;
59 struct st_bitmap_cache
61 /** Window pos to render the cached image */
63 /** Bounds of region used in window coords */
64 GLint xmin
, ymin
, xmax
, ymax
;
68 /** Bitmap's Z position */
71 struct pipe_resource
*texture
;
72 struct pipe_transfer
*trans
;
76 /** An I8 texture image: */
80 struct st_bound_handles
87 #define NUM_DRAWPIX_CACHE_ENTRIES 4
89 struct drawpix_cache_entry
91 GLsizei width
, height
;
93 const void *user_pointer
; /**< Last user 'pixels' pointer */
94 void *image
; /**< Copy of the glDrawPixels image data */
95 struct pipe_resource
*texture
;
101 * Node for a linked list of dead sampler views.
103 struct st_zombie_sampler_view_node
105 struct pipe_sampler_view
*view
;
106 struct list_head node
;
111 * Node for a linked list of dead shaders.
113 struct st_zombie_shader_node
116 enum pipe_shader_type type
;
117 struct list_head node
;
123 struct st_context_iface iface
;
125 struct gl_context
*ctx
;
127 struct pipe_context
*pipe
;
129 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
130 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
131 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
132 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
133 GLboolean clamp_frag_color_in_shader
;
134 GLboolean clamp_vert_color_in_shader
;
135 boolean clamp_frag_depth_in_shader
;
136 boolean has_stencil_export
; /**< can do shader stencil export? */
137 boolean has_time_elapsed
;
140 boolean has_astc_2d_ldr
;
141 boolean has_astc_5x5_ldr
;
142 boolean prefer_blit_based_texture_transfer
;
143 boolean force_persample_in_shader
;
144 boolean has_shareable_shaders
;
145 boolean has_half_float_packing
;
146 boolean has_multi_draw_indirect
;
147 boolean has_single_pipe_stat
;
148 boolean has_indep_blend_func
;
149 boolean needs_rgb_dst_alpha_override
;
150 boolean can_bind_const_buffer_as_vertex
;
151 boolean lower_flatshade
;
152 boolean lower_alpha_test
;
153 boolean lower_point_size
;
154 boolean lower_two_sided_color
;
157 /* There are consequences for drivers wanting to call st_finalize_nir
158 * twice, once before shader caching and once after lowering for shader
159 * variants. If shader variants use lowering passes that are not ready
160 * for that, things can blow up.
162 * If this is true, st_finalize_nir and pipe_screen::finalize_nir will be
163 * called before the result is stored in the shader cache. If lowering for
164 * shader variants is invoked, the functions will be called again.
166 boolean allow_st_finalize_nir_twice
;
169 * If a shader can be created when we get its source.
170 * This means it has only 1 variant, not counting glBitmap and
173 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
175 boolean needs_texcoord_semantic
;
176 boolean apply_texture_swizzle_to_border_color
;
178 /* On old libGL's for linux we need to invalidate the drawables
179 * on glViewpport calls, this is set via a option.
181 boolean invalidate_on_gl_viewport
;
182 boolean draw_needs_minmax_index
;
183 boolean has_hw_atomics
;
186 /* driver supports scissored clears */
187 boolean can_scissor_clear
;
189 /* Some state is contained in constant objects.
190 * Other state is just parameter values.
193 struct pipe_blend_state blend
;
194 struct pipe_depth_stencil_alpha_state depth_stencil
;
195 struct pipe_rasterizer_state rasterizer
;
196 struct pipe_sampler_state vert_samplers
[PIPE_MAX_SAMPLERS
];
197 struct pipe_sampler_state frag_samplers
[PIPE_MAX_SAMPLERS
];
198 GLuint num_vert_samplers
;
199 GLuint num_frag_samplers
;
200 struct pipe_sampler_view
*vert_sampler_views
[PIPE_MAX_SAMPLERS
];
201 struct pipe_sampler_view
*frag_sampler_views
[PIPE_MAX_SAMPLERS
];
202 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
203 struct pipe_clip_state clip
;
207 } constants
[PIPE_SHADER_TYPES
];
210 unsigned fb_num_samples
;
211 unsigned fb_num_layers
;
213 unsigned num_viewports
;
214 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
215 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
219 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
222 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
224 GLuint fb_orientation
;
226 bool enable_sample_locations
;
227 unsigned sample_locations_samples
;
228 uint8_t sample_locations
[
229 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
*
230 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
* 32];
233 uint64_t dirty
; /**< dirty states */
235 /** This masks out unused shader resources. Only valid in draw calls. */
236 uint64_t active_states
;
238 unsigned pin_thread_counter
; /* for L3 thread pinning on AMD Zen */
240 /* If true, further analysis of states is required to know if something
241 * has changed. Used mainly for shaders.
243 bool gfx_shaders_may_be_dirty
;
244 bool compute_shader_may_be_dirty
;
246 GLboolean vertdata_edgeflags
;
247 GLboolean edgeflag_culls_prims
;
250 * The number of currently active queries (excluding timer queries).
251 * This is used to know if we need to pause any queries for meta ops.
253 unsigned active_queries
;
257 struct st_program
*vp
; /**< Currently bound vertex program */
258 struct st_program
*tcp
; /**< Currently bound tess control program */
259 struct st_program
*tep
; /**< Currently bound tess eval program */
260 struct st_program
*gp
; /**< Currently bound geometry program */
261 struct st_program
*fp
; /**< Currently bound fragment program */
262 struct st_program
*cp
; /**< Currently bound compute program */
264 struct gl_program
*current_program
[MESA_SHADER_STAGES
];
267 struct st_common_variant
*vp_variant
;
270 struct pipe_resource
*pixelmap_texture
;
271 struct pipe_sampler_view
*pixelmap_sampler_view
;
276 struct pipe_rasterizer_state rasterizer
;
277 struct pipe_sampler_state sampler
;
278 struct pipe_sampler_state atlas_sampler
;
279 enum pipe_format tex_format
;
280 struct st_bitmap_cache cache
;
283 /** for glDraw/CopyPixels */
288 /** Cache of glDrawPixels images */
290 struct drawpix_cache_entry entries
[NUM_DRAWPIX_CACHE_ENTRIES
];
294 /** for glReadPixels */
296 struct pipe_resource
*src
;
297 struct pipe_resource
*cache
;
298 enum pipe_format dst_format
;
306 struct pipe_rasterizer_state raster
;
307 struct pipe_viewport_state viewport
;
314 /* For gl(Compressed)Tex(Sub)Image */
316 struct pipe_rasterizer_state raster
;
317 struct pipe_blend_state upload_blend
;
321 void *download_fs
[3][PIPE_MAX_TEXTURE_TYPES
];
323 bool download_enabled
;
329 /** for drawing with st_util_vertex */
330 struct cso_velems_state util_velems
;
332 /** passthrough vertex shader matching the util_velem attributes */
333 void *passthrough_vs
;
335 enum pipe_texture_target internal_target
;
337 struct cso_context
*cso_context
;
339 void *winsys_drawable_handle
;
341 /* The number of vertex buffers from the last call of validate_arrays. */
342 unsigned last_num_vbuffers
;
344 unsigned last_used_atomic_bindings
[PIPE_SHADER_TYPES
];
345 unsigned last_num_ssbos
[PIPE_SHADER_TYPES
];
350 struct st_config_options options
;
352 struct st_perf_monitor_group
*perfmon
;
354 enum pipe_reset_status reset_status
;
356 /* Array of bound texture/image handles which are resident in the context.
358 struct st_bound_handles bound_texture_handles
[PIPE_SHADER_TYPES
];
359 struct st_bound_handles bound_image_handles
[PIPE_SHADER_TYPES
];
362 struct list_head winsys_buffers
;
364 /* Throttling for texture uploads and similar operations to limit memory
365 * usage by limiting the number of in-flight operations based on
366 * the estimated allocated size needed to execute those operations.
368 struct util_throttle throttle
;
371 struct st_zombie_sampler_view_node list
;
373 } zombie_sampler_views
;
376 struct st_zombie_shader_node list
;
384 * Get the state tracker context for the given Mesa context.
386 static inline struct st_context
*
387 st_context(struct gl_context
*ctx
)
393 extern struct st_context
*
394 st_create_context(gl_api api
, struct pipe_context
*pipe
,
395 const struct gl_config
*visual
,
396 struct st_context
*share
,
397 const struct st_config_options
*options
,
401 st_destroy_context(struct st_context
*st
);
405 st_invalidate_buffers(struct st_context
*st
);
409 st_save_zombie_sampler_view(struct st_context
*st
,
410 struct pipe_sampler_view
*view
);
413 st_save_zombie_shader(struct st_context
*st
,
414 enum pipe_shader_type type
,
415 struct pipe_shader_state
*shader
);
419 st_context_free_zombie_objects(struct st_context
*st
);
424 * Wrapper for struct gl_framebuffer.
425 * This is an opaque type to the outside world.
427 struct st_framebuffer
429 struct gl_framebuffer Base
;
431 struct st_framebuffer_iface
*iface
;
432 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
438 /* list of framebuffer objects */
439 struct list_head head
;