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 "state_tracker/st_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"
48 struct dd_function_table
;
51 struct gen_mipmap_state
;
53 struct st_fragment_program
;
54 struct st_perf_monitor_group
;
58 struct st_bitmap_cache
60 /** Window pos to render the cached image */
62 /** Bounds of region used in window coords */
63 GLint xmin
, ymin
, xmax
, ymax
;
67 /** Bitmap's Z position */
70 struct pipe_resource
*texture
;
71 struct pipe_transfer
*trans
;
75 /** An I8 texture image: */
79 struct st_bound_handles
86 #define NUM_DRAWPIX_CACHE_ENTRIES 4
88 struct drawpix_cache_entry
90 GLsizei width
, height
;
92 const void *user_pointer
; /**< Last user 'pixels' pointer */
93 void *image
; /**< Copy of the glDrawPixels image data */
94 struct pipe_resource
*texture
;
100 * Node for a linked list of dead sampler views.
102 struct st_zombie_sampler_view_node
104 struct pipe_sampler_view
*view
;
105 struct list_head node
;
110 * Node for a linked list of dead shaders.
112 struct st_zombie_shader_node
115 enum pipe_shader_type type
;
116 struct list_head node
;
122 struct st_context_iface iface
;
124 struct gl_context
*ctx
;
126 struct pipe_context
*pipe
;
128 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
129 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
130 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
131 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
132 GLboolean clamp_frag_color_in_shader
;
133 GLboolean clamp_vert_color_in_shader
;
134 boolean clamp_frag_depth_in_shader
;
135 boolean has_stencil_export
; /**< can do shader stencil export? */
136 boolean has_time_elapsed
;
139 boolean has_astc_2d_ldr
;
140 boolean prefer_blit_based_texture_transfer
;
141 boolean force_persample_in_shader
;
142 boolean has_shareable_shaders
;
143 boolean has_half_float_packing
;
144 boolean has_multi_draw_indirect
;
145 boolean has_single_pipe_stat
;
146 boolean has_indep_blend_func
;
147 boolean needs_rgb_dst_alpha_override
;
148 boolean can_bind_const_buffer_as_vertex
;
149 boolean has_signed_vertex_buffer_offset
;
152 * If a shader can be created when we get its source.
153 * This means it has only 1 variant, not counting glBitmap and
156 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
158 boolean needs_texcoord_semantic
;
159 boolean apply_texture_swizzle_to_border_color
;
161 /* On old libGL's for linux we need to invalidate the drawables
162 * on glViewpport calls, this is set via a option.
164 boolean invalidate_on_gl_viewport
;
165 boolean draw_needs_minmax_index
;
166 boolean has_hw_atomics
;
168 /* Some state is contained in constant objects.
169 * Other state is just parameter values.
172 struct pipe_blend_state blend
;
173 struct pipe_depth_stencil_alpha_state depth_stencil
;
174 struct pipe_rasterizer_state rasterizer
;
175 struct pipe_sampler_state frag_samplers
[PIPE_MAX_SAMPLERS
];
176 GLuint num_frag_samplers
;
177 struct pipe_sampler_view
*frag_sampler_views
[PIPE_MAX_SAMPLERS
];
178 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
179 struct pipe_clip_state clip
;
183 } constants
[PIPE_SHADER_TYPES
];
186 unsigned fb_num_samples
;
187 unsigned fb_num_layers
;
189 unsigned num_viewports
;
190 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
191 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
195 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
198 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
200 GLuint fb_orientation
;
202 bool enable_sample_locations
;
203 unsigned sample_locations_samples
;
204 uint8_t sample_locations
[
205 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
*
206 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
* 32];
209 uint64_t dirty
; /**< dirty states */
211 /** This masks out unused shader resources. Only valid in draw calls. */
212 uint64_t active_states
;
214 unsigned pin_thread_counter
; /* for L3 thread pinning on AMD Zen */
216 /* If true, further analysis of states is required to know if something
217 * has changed. Used mainly for shaders.
219 bool gfx_shaders_may_be_dirty
;
220 bool compute_shader_may_be_dirty
;
222 GLboolean vertdata_edgeflags
;
223 GLboolean edgeflag_culls_prims
;
226 * The number of currently active queries (excluding timer queries).
227 * This is used to know if we need to pause any queries for meta ops.
229 unsigned active_queries
;
231 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
232 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
233 struct st_common_program
*gp
; /**< Currently bound geometry program */
234 struct st_common_program
*tcp
; /**< Currently bound tess control program */
235 struct st_common_program
*tep
; /**< Currently bound tess eval program */
236 struct st_compute_program
*cp
; /**< Currently bound compute program */
238 struct st_vp_variant
*vp_variant
;
241 struct pipe_resource
*pixelmap_texture
;
242 struct pipe_sampler_view
*pixelmap_sampler_view
;
247 struct pipe_rasterizer_state rasterizer
;
248 struct pipe_sampler_state sampler
;
249 struct pipe_sampler_state atlas_sampler
;
250 enum pipe_format tex_format
;
251 struct st_bitmap_cache cache
;
254 /** for glDraw/CopyPixels */
259 /** Cache of glDrawPixels images */
261 struct drawpix_cache_entry entries
[NUM_DRAWPIX_CACHE_ENTRIES
];
265 /** for glReadPixels */
267 struct pipe_resource
*src
;
268 struct pipe_resource
*cache
;
269 enum pipe_format dst_format
;
277 struct pipe_rasterizer_state raster
;
278 struct pipe_viewport_state viewport
;
285 /* For gl(Compressed)Tex(Sub)Image */
287 struct pipe_rasterizer_state raster
;
288 struct pipe_blend_state upload_blend
;
292 void *download_fs
[3][PIPE_MAX_TEXTURE_TYPES
];
294 bool download_enabled
;
300 /** for drawing with st_util_vertex */
301 struct pipe_vertex_element util_velems
[3];
303 /** passthrough vertex shader matching the util_velem attributes */
304 void *passthrough_vs
;
306 enum pipe_texture_target internal_target
;
308 struct cso_context
*cso_context
;
310 void *winsys_drawable_handle
;
312 /* The number of vertex buffers from the last call of validate_arrays. */
313 unsigned last_num_vbuffers
;
318 struct st_config_options options
;
320 struct st_perf_monitor_group
*perfmon
;
322 enum pipe_reset_status reset_status
;
324 /* Array of bound texture/image handles which are resident in the context.
326 struct st_bound_handles bound_texture_handles
[PIPE_SHADER_TYPES
];
327 struct st_bound_handles bound_image_handles
[PIPE_SHADER_TYPES
];
330 struct list_head winsys_buffers
;
332 /* Throttling for texture uploads and similar operations to limit memory
333 * usage by limiting the number of in-flight operations based on
334 * the estimated allocated size needed to execute those operations.
336 struct util_throttle throttle
;
339 struct st_zombie_sampler_view_node list
;
341 } zombie_sampler_views
;
344 struct st_zombie_shader_node list
;
352 * Get the state tracker context for the given Mesa context.
354 static inline struct st_context
*
355 st_context(struct gl_context
*ctx
)
361 extern struct st_context
*
362 st_create_context(gl_api api
, struct pipe_context
*pipe
,
363 const struct gl_config
*visual
,
364 struct st_context
*share
,
365 const struct st_config_options
*options
,
369 st_destroy_context(struct st_context
*st
);
373 st_invalidate_buffers(struct st_context
*st
);
377 st_save_zombie_sampler_view(struct st_context
*st
,
378 struct pipe_sampler_view
*view
);
381 st_save_zombie_shader(struct st_context
*st
,
382 enum pipe_shader_type type
,
383 struct pipe_shader_state
*shader
);
387 st_context_free_zombie_objects(struct st_context
*st
);
392 * Wrapper for struct gl_framebuffer.
393 * This is an opaque type to the outside world.
395 struct st_framebuffer
397 struct gl_framebuffer Base
;
399 struct st_framebuffer_iface
*iface
;
400 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
406 /* list of framebuffer objects */
407 struct list_head head
;