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/mtypes.h"
32 #include "state_tracker/st_api.h"
33 #include "main/fbobject.h"
34 #include "state_tracker/st_atom.h"
35 #include "util/u_inlines.h"
36 #include "util/list.h"
45 struct dd_function_table
;
48 struct gen_mipmap_state
;
50 struct st_fragment_program
;
51 struct st_perf_monitor_group
;
55 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
63 struct st_bitmap_cache
65 /** Window pos to render the cached image */
67 /** Bounds of region used in window coords */
68 GLint xmin
, ymin
, xmax
, ymax
;
72 /** Bitmap's Z position */
75 struct pipe_resource
*texture
;
76 struct pipe_transfer
*trans
;
80 /** An I8 texture image: */
84 struct st_bound_handles
91 #define NUM_DRAWPIX_CACHE_ENTRIES 4
93 struct drawpix_cache_entry
95 GLsizei width
, height
;
97 const void *user_pointer
; /**< Last user 'pixels' pointer */
98 void *image
; /**< Copy of the glDrawPixels image data */
99 struct pipe_resource
*texture
;
106 struct st_context_iface iface
;
108 struct gl_context
*ctx
;
110 struct pipe_context
*pipe
;
112 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
113 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
114 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
115 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
116 GLboolean clamp_frag_color_in_shader
;
117 GLboolean clamp_vert_color_in_shader
;
118 boolean has_stencil_export
; /**< can do shader stencil export? */
119 boolean has_time_elapsed
;
120 boolean has_shader_model3
;
123 boolean has_astc_2d_ldr
;
124 boolean prefer_blit_based_texture_transfer
;
125 boolean force_persample_in_shader
;
126 boolean has_shareable_shaders
;
127 boolean has_half_float_packing
;
128 boolean has_multi_draw_indirect
;
129 boolean can_bind_const_buffer_as_vertex
;
132 * If a shader can be created when we get its source.
133 * This means it has only 1 variant, not counting glBitmap and
136 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
138 boolean needs_texcoord_semantic
;
139 boolean apply_texture_swizzle_to_border_color
;
141 /* On old libGL's for linux we need to invalidate the drawables
142 * on glViewpport calls, this is set via a option.
144 boolean invalidate_on_gl_viewport
;
145 boolean draw_needs_minmax_index
;
146 boolean vertex_array_out_of_memory
;
147 boolean has_hw_atomics
;
149 /* Some state is contained in constant objects.
150 * Other state is just parameter values.
153 struct pipe_blend_state blend
;
154 struct pipe_depth_stencil_alpha_state depth_stencil
;
155 struct pipe_rasterizer_state rasterizer
;
156 struct pipe_sampler_state frag_samplers
[PIPE_MAX_SAMPLERS
];
157 GLuint num_frag_samplers
;
158 struct pipe_sampler_view
*frag_sampler_views
[PIPE_MAX_SAMPLERS
];
159 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
160 struct pipe_clip_state clip
;
164 } constants
[PIPE_SHADER_TYPES
];
167 unsigned fb_num_samples
;
168 unsigned fb_num_layers
;
170 unsigned num_viewports
;
171 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
172 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
176 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
179 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
181 GLuint fb_orientation
;
183 bool enable_sample_locations
;
184 unsigned sample_locations_samples
;
185 uint8_t sample_locations
[
186 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
*
187 PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE
* 32];
190 uint64_t dirty
; /**< dirty states */
192 /** This masks out unused shader resources. Only valid in draw calls. */
193 uint64_t active_states
;
195 /* If true, further analysis of states is required to know if something
196 * has changed. Used mainly for shaders.
198 bool gfx_shaders_may_be_dirty
;
199 bool compute_shader_may_be_dirty
;
201 GLboolean vertdata_edgeflags
;
202 GLboolean edgeflag_culls_prims
;
204 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
205 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
206 struct st_common_program
*gp
; /**< Currently bound geometry program */
207 struct st_common_program
*tcp
; /**< Currently bound tess control program */
208 struct st_common_program
*tep
; /**< Currently bound tess eval program */
209 struct st_compute_program
*cp
; /**< Currently bound compute program */
211 struct st_vp_variant
*vp_variant
;
214 struct pipe_resource
*pixelmap_texture
;
215 struct pipe_sampler_view
*pixelmap_sampler_view
;
220 struct pipe_rasterizer_state rasterizer
;
221 struct pipe_sampler_state sampler
;
222 struct pipe_sampler_state atlas_sampler
;
223 enum pipe_format tex_format
;
225 struct st_bitmap_cache cache
;
228 /** for glDraw/CopyPixels */
231 void *vert_shaders
[2]; /**< ureg shaders */
234 /** Cache of glDrawPixels images */
236 struct drawpix_cache_entry entries
[NUM_DRAWPIX_CACHE_ENTRIES
];
240 /** for glReadPixels */
242 struct pipe_resource
*src
;
243 struct pipe_resource
*cache
;
244 enum pipe_format dst_format
;
252 struct pipe_rasterizer_state raster
;
253 struct pipe_viewport_state viewport
;
260 /* For gl(Compressed)Tex(Sub)Image */
262 struct pipe_rasterizer_state raster
;
263 struct pipe_blend_state upload_blend
;
267 void *download_fs
[3][PIPE_MAX_TEXTURE_TYPES
];
269 bool download_enabled
;
275 /** for drawing with st_util_vertex */
276 struct pipe_vertex_element util_velems
[3];
278 void *passthrough_fs
; /**< simple pass-through frag shader */
280 enum pipe_texture_target internal_target
;
282 struct cso_context
*cso_context
;
284 void *winsys_drawable_handle
;
286 /* The number of vertex buffers from the last call of validate_arrays. */
287 unsigned last_num_vbuffers
;
292 struct st_config_options options
;
294 struct st_perf_monitor_group
*perfmon
;
296 enum pipe_reset_status reset_status
;
298 /* Array of bound texture/image handles which are resident in the context.
300 struct st_bound_handles bound_texture_handles
[PIPE_SHADER_TYPES
];
301 struct st_bound_handles bound_image_handles
[PIPE_SHADER_TYPES
];
304 struct list_head winsys_buffers
;
308 /* Need this so that we can implement Mesa callbacks in this module.
310 static inline struct st_context
*st_context(struct gl_context
*ctx
)
317 * Wrapper for struct gl_framebuffer.
318 * This is an opaque type to the outside world.
320 struct st_framebuffer
322 struct gl_framebuffer Base
;
324 struct st_framebuffer_iface
*iface
;
325 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
331 /* list of framebuffer objects */
332 struct list_head head
;
336 extern void st_init_driver_functions(struct pipe_screen
*screen
,
337 struct dd_function_table
*functions
);
340 st_invalidate_buffers(struct st_context
*st
);
342 /* Invalidate the readpixels cache to ensure we don't read stale data.
345 st_invalidate_readpix_cache(struct st_context
*st
)
347 if (unlikely(st
->readpix_cache
.src
)) {
348 pipe_resource_reference(&st
->readpix_cache
.src
, NULL
);
349 pipe_resource_reference(&st
->readpix_cache
.cache
, NULL
);
358 st_fb_orientation(const struct gl_framebuffer
*fb
)
360 if (fb
&& _mesa_is_winsys_fbo(fb
)) {
361 /* Drawing into a window (on-screen buffer).
363 * Negate Y scale to flip image vertically.
364 * The NDC Y coords prior to viewport transformation are in the range
365 * [y=-1=bottom, y=1=top]
366 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
367 * H is the window height.
368 * Use the viewport transformation to invert Y.
373 /* Drawing into user-created FBO (very likely a texture).
375 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
383 st_user_clip_planes_enabled(struct gl_context
*ctx
)
385 return (ctx
->API
== API_OPENGL_COMPAT
||
386 ctx
->API
== API_OPENGLES
) && /* only ES 1.x */
387 ctx
->Transform
.ClipPlanesEnabled
;
390 /** clear-alloc a struct-sized object, with casting */
391 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
394 extern struct st_context
*
395 st_create_context(gl_api api
, struct pipe_context
*pipe
,
396 const struct gl_config
*visual
,
397 struct st_context
*share
,
398 const struct st_config_options
*options
,
402 st_destroy_context(struct st_context
*st
);
405 st_get_active_states(struct gl_context
*ctx
);