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"
43 struct dd_function_table
;
46 struct gen_mipmap_state
;
48 struct st_fragment_program
;
49 struct st_perf_monitor_group
;
53 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
61 struct st_bitmap_cache
63 /** Window pos to render the cached image */
65 /** Bounds of region used in window coords */
66 GLint xmin
, ymin
, xmax
, ymax
;
70 /** Bitmap's Z position */
73 struct pipe_resource
*texture
;
74 struct pipe_transfer
*trans
;
78 /** An I8 texture image: */
84 struct st_context_iface iface
;
86 struct gl_context
*ctx
;
88 struct pipe_context
*pipe
;
90 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
91 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
92 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
93 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
94 GLboolean clamp_frag_color_in_shader
;
95 GLboolean clamp_vert_color_in_shader
;
96 boolean has_stencil_export
; /**< can do shader stencil export? */
97 boolean has_time_elapsed
;
98 boolean has_shader_model3
;
101 boolean prefer_blit_based_texture_transfer
;
102 boolean force_persample_in_shader
;
103 boolean has_shareable_shaders
;
104 boolean has_half_float_packing
;
105 boolean has_multi_draw_indirect
;
106 boolean has_user_constbuf
;
107 boolean can_bind_const_buffer_as_vertex
;
110 * If a shader can be created when we get its source.
111 * This means it has only 1 variant, not counting glBitmap and
114 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
116 boolean needs_texcoord_semantic
;
117 boolean apply_texture_swizzle_to_border_color
;
119 /* On old libGL's for linux we need to invalidate the drawables
120 * on glViewpport calls, this is set via a option.
122 boolean invalidate_on_gl_viewport
;
124 boolean vertex_array_out_of_memory
;
126 /* Some state is contained in constant objects.
127 * Other state is just parameter values.
130 struct pipe_blend_state blend
;
131 struct pipe_depth_stencil_alpha_state depth_stencil
;
132 struct pipe_rasterizer_state rasterizer
;
133 struct pipe_sampler_state samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
134 GLuint num_samplers
[PIPE_SHADER_TYPES
];
135 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
136 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
137 struct pipe_clip_state clip
;
141 } constants
[PIPE_SHADER_TYPES
];
142 struct pipe_framebuffer_state framebuffer
;
143 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
144 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
148 struct pipe_scissor_state rects
[PIPE_MAX_WINDOW_RECTANGLES
];
150 unsigned sample_mask
;
152 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
154 GLuint fb_orientation
;
160 uint64_t dirty
; /**< dirty states */
162 /** This masks out unused shader resources. Only valid in draw calls. */
163 uint64_t active_states
;
165 /* If true, further analysis of states is required to know if something
166 * has changed. Used mainly for shaders.
168 bool gfx_shaders_may_be_dirty
;
169 bool compute_shader_may_be_dirty
;
171 GLboolean vertdata_edgeflags
;
172 GLboolean edgeflag_culls_prims
;
174 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
175 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
176 struct st_common_program
*gp
; /**< Currently bound geometry program */
177 struct st_common_program
*tcp
; /**< Currently bound tess control program */
178 struct st_common_program
*tep
; /**< Currently bound tess eval program */
179 struct st_compute_program
*cp
; /**< Currently bound compute program */
181 struct st_vp_variant
*vp_variant
;
182 struct st_fp_variant
*fp_variant
;
183 struct st_basic_variant
*gp_variant
;
184 struct st_basic_variant
*tcp_variant
;
185 struct st_basic_variant
*tep_variant
;
186 struct st_basic_variant
*cp_variant
;
189 struct pipe_resource
*pixelmap_texture
;
190 struct pipe_sampler_view
*pixelmap_sampler_view
;
195 struct pipe_rasterizer_state rasterizer
;
196 struct pipe_sampler_state sampler
;
197 struct pipe_sampler_state atlas_sampler
;
198 enum pipe_format tex_format
;
200 struct st_bitmap_cache cache
;
203 /** for glDraw/CopyPixels */
206 void *vert_shaders
[2]; /**< ureg shaders */
210 GLsizei width
, height
;
212 const void *user_pointer
; /**< Last user 'pixels' pointer */
213 void *image
; /**< Copy of the glDrawPixels image data */
214 struct pipe_resource
*texture
;
217 /** for glReadPixels */
219 struct pipe_resource
*src
;
220 struct pipe_resource
*cache
;
221 enum pipe_format dst_format
;
229 struct pipe_rasterizer_state raster
;
230 struct pipe_viewport_state viewport
;
237 /* For gl(Compressed)Tex(Sub)Image */
239 struct pipe_rasterizer_state raster
;
240 struct pipe_blend_state upload_blend
;
244 void *download_fs
[3][PIPE_MAX_TEXTURE_TYPES
];
246 bool download_enabled
;
252 /** for drawing with st_util_vertex */
253 struct pipe_vertex_element util_velems
[3];
255 void *passthrough_fs
; /**< simple pass-through frag shader */
257 enum pipe_texture_target internal_target
;
259 struct cso_context
*cso_context
;
261 void *winsys_drawable_handle
;
263 /* The number of vertex buffers from the last call of validate_arrays. */
264 unsigned last_num_vbuffers
;
269 struct st_config_options options
;
271 struct st_perf_monitor_group
*perfmon
;
273 enum pipe_reset_status reset_status
;
277 /* Need this so that we can implement Mesa callbacks in this module.
279 static inline struct st_context
*st_context(struct gl_context
*ctx
)
286 * Wrapper for struct gl_framebuffer.
287 * This is an opaque type to the outside world.
289 struct st_framebuffer
291 struct gl_framebuffer Base
;
294 struct st_framebuffer_iface
*iface
;
295 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
302 extern void st_init_driver_functions(struct pipe_screen
*screen
,
303 struct dd_function_table
*functions
);
305 void st_invalidate_state(struct gl_context
* ctx
, GLbitfield new_state
);
307 /* Invalidate the readpixels cache to ensure we don't read stale data.
310 st_invalidate_readpix_cache(struct st_context
*st
)
312 if (unlikely(st
->readpix_cache
.src
)) {
313 pipe_resource_reference(&st
->readpix_cache
.src
, NULL
);
314 pipe_resource_reference(&st
->readpix_cache
.cache
, NULL
);
323 st_fb_orientation(const struct gl_framebuffer
*fb
)
325 if (fb
&& _mesa_is_winsys_fbo(fb
)) {
326 /* Drawing into a window (on-screen buffer).
328 * Negate Y scale to flip image vertically.
329 * The NDC Y coords prior to viewport transformation are in the range
330 * [y=-1=bottom, y=1=top]
331 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
332 * H is the window height.
333 * Use the viewport transformation to invert Y.
338 /* Drawing into user-created FBO (very likely a texture).
340 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
347 static inline enum pipe_shader_type
348 st_shader_stage_to_ptarget(gl_shader_stage stage
)
351 case MESA_SHADER_VERTEX
:
352 return PIPE_SHADER_VERTEX
;
353 case MESA_SHADER_FRAGMENT
:
354 return PIPE_SHADER_FRAGMENT
;
355 case MESA_SHADER_GEOMETRY
:
356 return PIPE_SHADER_GEOMETRY
;
357 case MESA_SHADER_TESS_CTRL
:
358 return PIPE_SHADER_TESS_CTRL
;
359 case MESA_SHADER_TESS_EVAL
:
360 return PIPE_SHADER_TESS_EVAL
;
361 case MESA_SHADER_COMPUTE
:
362 return PIPE_SHADER_COMPUTE
;
365 assert(!"should not be reached");
366 return PIPE_SHADER_VERTEX
;
370 st_user_clip_planes_enabled(struct gl_context
*ctx
)
372 return (ctx
->API
== API_OPENGL_COMPAT
||
373 ctx
->API
== API_OPENGLES
) && /* only ES 1.x */
374 ctx
->Transform
.ClipPlanesEnabled
;
377 /** clear-alloc a struct-sized object, with casting */
378 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
381 extern struct st_context
*
382 st_create_context(gl_api api
, struct pipe_context
*pipe
,
383 const struct gl_config
*visual
,
384 struct st_context
*share
,
385 const struct st_config_options
*options
);
388 st_destroy_context(struct st_context
*st
);
391 st_get_active_states(struct gl_context
*ctx
);