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 "pipe/p_state.h"
33 #include "state_tracker/st_api.h"
34 #include "main/fbobject.h"
43 struct dd_function_table
;
46 struct gen_mipmap_state
;
48 struct st_fragment_program
;
49 struct st_perf_monitor_group
;
53 #define ST_NEW_MESA (1 << 0) /* Mesa state has changed */
54 #define ST_NEW_FRAGMENT_PROGRAM (1 << 1)
55 #define ST_NEW_VERTEX_PROGRAM (1 << 2)
56 #define ST_NEW_FRAMEBUFFER (1 << 3)
57 #define ST_NEW_TESS_STATE (1 << 4)
58 #define ST_NEW_GEOMETRY_PROGRAM (1 << 5)
59 #define ST_NEW_VERTEX_ARRAYS (1 << 6)
60 #define ST_NEW_RASTERIZER (1 << 7)
61 #define ST_NEW_UNIFORM_BUFFER (1 << 8)
62 #define ST_NEW_TESSCTRL_PROGRAM (1 << 9)
63 #define ST_NEW_TESSEVAL_PROGRAM (1 << 10)
64 #define ST_NEW_SAMPLER_VIEWS (1 << 11)
65 #define ST_NEW_ATOMIC_BUFFER (1 << 12)
66 #define ST_NEW_STORAGE_BUFFER (1 << 13)
67 #define ST_NEW_COMPUTE_PROGRAM (1 << 14)
68 #define ST_NEW_IMAGE_UNITS (1 << 15)
71 struct st_state_flags
{
72 GLbitfield mesa
; /**< Mask of _NEW_x flags */
73 uint64_t st
; /**< Mask of ST_NEW_x flags */
76 struct st_tracked_state
{
78 struct st_state_flags dirty
;
79 void (*update
)( struct st_context
*st
);
84 * Enumeration of state tracker pipelines.
92 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
103 struct st_context_iface iface
;
105 struct gl_context
*ctx
;
107 struct pipe_context
*pipe
;
109 struct u_upload_mgr
*uploader
, *indexbuf_uploader
, *constbuf_uploader
;
111 struct draw_context
*draw
; /**< For selection/feedback/rastpos only */
112 struct draw_stage
*feedback_stage
; /**< For GL_FEEDBACK rendermode */
113 struct draw_stage
*selection_stage
; /**< For GL_SELECT rendermode */
114 struct draw_stage
*rastpos_stage
; /**< For glRasterPos */
115 GLboolean clamp_frag_color_in_shader
;
116 GLboolean clamp_vert_color_in_shader
;
117 boolean has_stencil_export
; /**< can do shader stencil export? */
118 boolean has_time_elapsed
;
119 boolean has_shader_model3
;
122 boolean prefer_blit_based_texture_transfer
;
123 boolean force_persample_in_shader
;
124 boolean has_shareable_shaders
;
125 boolean has_half_float_packing
;
126 boolean has_multi_draw_indirect
;
129 * If a shader can be created when we get its source.
130 * This means it has only 1 variant, not counting glBitmap and
133 boolean shader_has_one_variant
[MESA_SHADER_STAGES
];
135 boolean needs_texcoord_semantic
;
136 boolean apply_texture_swizzle_to_border_color
;
138 /* On old libGL's for linux we need to invalidate the drawables
139 * on glViewpport calls, this is set via a option.
141 boolean invalidate_on_gl_viewport
;
143 boolean vertex_array_out_of_memory
;
145 /* Some state is contained in constant objects.
146 * Other state is just parameter values.
149 struct pipe_blend_state blend
;
150 struct pipe_depth_stencil_alpha_state depth_stencil
;
151 struct pipe_rasterizer_state rasterizer
;
152 struct pipe_sampler_state samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
153 GLuint num_samplers
[PIPE_SHADER_TYPES
];
154 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
155 GLuint num_sampler_views
[PIPE_SHADER_TYPES
];
156 struct pipe_clip_state clip
;
160 } constants
[PIPE_SHADER_TYPES
];
161 struct pipe_framebuffer_state framebuffer
;
162 struct pipe_scissor_state scissor
[PIPE_MAX_VIEWPORTS
];
163 struct pipe_viewport_state viewport
[PIPE_MAX_VIEWPORTS
];
164 unsigned sample_mask
;
166 GLuint poly_stipple
[32]; /**< In OpenGL's bottom-to-top order */
168 GLuint fb_orientation
;
174 struct st_state_flags dirty
;
175 struct st_state_flags dirty_cp
;
177 GLboolean vertdata_edgeflags
;
178 GLboolean edgeflag_culls_prims
;
180 /** Mapping from VARYING_SLOT_x to post-transformed vertex slot */
181 const GLuint
*vertex_result_to_slot
;
183 struct st_vertex_program
*vp
; /**< Currently bound vertex program */
184 struct st_fragment_program
*fp
; /**< Currently bound fragment program */
185 struct st_geometry_program
*gp
; /**< Currently bound geometry program */
186 struct st_tessctrl_program
*tcp
; /**< Currently bound tess control program */
187 struct st_tesseval_program
*tep
; /**< Currently bound tess eval program */
188 struct st_compute_program
*cp
; /**< Currently bound compute program */
190 struct st_vp_variant
*vp_variant
;
191 struct st_fp_variant
*fp_variant
;
192 struct st_basic_variant
*gp_variant
;
193 struct st_basic_variant
*tcp_variant
;
194 struct st_basic_variant
*tep_variant
;
195 struct st_basic_variant
*cp_variant
;
197 struct gl_texture_object
*default_texture
;
200 struct pipe_resource
*pixelmap_texture
;
201 struct pipe_sampler_view
*pixelmap_sampler_view
;
206 struct pipe_rasterizer_state rasterizer
;
207 struct pipe_sampler_state sampler
;
208 enum pipe_format tex_format
;
210 struct bitmap_cache
*cache
;
213 /** for glDraw/CopyPixels */
216 void *vert_shaders
[2]; /**< ureg shaders */
221 struct pipe_rasterizer_state raster
;
222 struct pipe_viewport_state viewport
;
229 /* For gl(Compressed)Tex(Sub)Image */
231 struct pipe_rasterizer_state raster
;
232 struct pipe_blend_state blend
;
242 /** for drawing with st_util_vertex */
243 struct pipe_vertex_element util_velems
[3];
245 void *passthrough_fs
; /**< simple pass-through frag shader */
247 enum pipe_texture_target internal_target
;
249 struct cso_context
*cso_context
;
251 void *winsys_drawable_handle
;
253 /* The number of vertex buffers from the last call of validate_arrays. */
254 unsigned last_num_vbuffers
;
259 struct st_config_options options
;
261 struct st_perf_monitor_group
*perfmon
;
265 /* Need this so that we can implement Mesa callbacks in this module.
267 static inline struct st_context
*st_context(struct gl_context
*ctx
)
274 * Wrapper for struct gl_framebuffer.
275 * This is an opaque type to the outside world.
277 struct st_framebuffer
279 struct gl_framebuffer Base
;
282 struct st_framebuffer_iface
*iface
;
283 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
290 extern void st_init_driver_functions(struct pipe_screen
*screen
,
291 struct dd_function_table
*functions
);
293 void st_invalidate_state(struct gl_context
* ctx
, GLbitfield new_state
);
301 st_fb_orientation(const struct gl_framebuffer
*fb
)
303 if (fb
&& _mesa_is_winsys_fbo(fb
)) {
304 /* Drawing into a window (on-screen buffer).
306 * Negate Y scale to flip image vertically.
307 * The NDC Y coords prior to viewport transformation are in the range
308 * [y=-1=bottom, y=1=top]
309 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
310 * H is the window height.
311 * Use the viewport transformation to invert Y.
316 /* Drawing into user-created FBO (very likely a texture).
318 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
325 static inline unsigned
326 st_shader_stage_to_ptarget(gl_shader_stage stage
)
329 case MESA_SHADER_VERTEX
:
330 return PIPE_SHADER_VERTEX
;
331 case MESA_SHADER_FRAGMENT
:
332 return PIPE_SHADER_FRAGMENT
;
333 case MESA_SHADER_GEOMETRY
:
334 return PIPE_SHADER_GEOMETRY
;
335 case MESA_SHADER_TESS_CTRL
:
336 return PIPE_SHADER_TESS_CTRL
;
337 case MESA_SHADER_TESS_EVAL
:
338 return PIPE_SHADER_TESS_EVAL
;
339 case MESA_SHADER_COMPUTE
:
340 return PIPE_SHADER_COMPUTE
;
343 assert(!"should not be reached");
344 return PIPE_SHADER_VERTEX
;
348 /** clear-alloc a struct-sized object, with casting */
349 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
352 extern struct st_context
*
353 st_create_context(gl_api api
, struct pipe_context
*pipe
,
354 const struct gl_config
*visual
,
355 struct st_context
*share
,
356 const struct st_config_options
*options
);
359 st_destroy_context(struct st_context
*st
);