meson: fix missing dependencies
[mesa.git] / src / mesa / state_tracker / st_context.h
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef ST_CONTEXT_H
29 #define ST_CONTEXT_H
30
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"
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 struct dd_function_table;
45 struct draw_context;
46 struct draw_stage;
47 struct gen_mipmap_state;
48 struct st_context;
49 struct st_fragment_program;
50 struct st_perf_monitor_group;
51 struct u_upload_mgr;
52
53
54 /** For drawing quads for glClear, glDraw/CopyPixels, glBitmap, etc. */
55 struct st_util_vertex
56 {
57 float x, y, z;
58 float r, g, b, a;
59 float s, t;
60 };
61
62 struct st_bitmap_cache
63 {
64 /** Window pos to render the cached image */
65 GLint xpos, ypos;
66 /** Bounds of region used in window coords */
67 GLint xmin, ymin, xmax, ymax;
68
69 GLfloat color[4];
70
71 /** Bitmap's Z position */
72 GLfloat zpos;
73
74 struct pipe_resource *texture;
75 struct pipe_transfer *trans;
76
77 GLboolean empty;
78
79 /** An I8 texture image: */
80 ubyte *buffer;
81 };
82
83 struct st_bound_handles
84 {
85 unsigned num_handles;
86 uint64_t *handles;
87 };
88
89 struct st_context
90 {
91 struct st_context_iface iface;
92
93 struct gl_context *ctx;
94
95 struct pipe_context *pipe;
96
97 struct draw_context *draw; /**< For selection/feedback/rastpos only */
98 struct draw_stage *feedback_stage; /**< For GL_FEEDBACK rendermode */
99 struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */
100 struct draw_stage *rastpos_stage; /**< For glRasterPos */
101 GLboolean clamp_frag_color_in_shader;
102 GLboolean clamp_vert_color_in_shader;
103 boolean has_stencil_export; /**< can do shader stencil export? */
104 boolean has_time_elapsed;
105 boolean has_shader_model3;
106 boolean has_etc1;
107 boolean has_etc2;
108 boolean prefer_blit_based_texture_transfer;
109 boolean force_persample_in_shader;
110 boolean has_shareable_shaders;
111 boolean has_half_float_packing;
112 boolean has_multi_draw_indirect;
113 boolean can_bind_const_buffer_as_vertex;
114
115 /**
116 * If a shader can be created when we get its source.
117 * This means it has only 1 variant, not counting glBitmap and
118 * glDrawPixels.
119 */
120 boolean shader_has_one_variant[MESA_SHADER_STAGES];
121
122 boolean needs_texcoord_semantic;
123 boolean apply_texture_swizzle_to_border_color;
124
125 /* On old libGL's for linux we need to invalidate the drawables
126 * on glViewpport calls, this is set via a option.
127 */
128 boolean invalidate_on_gl_viewport;
129 boolean draw_needs_minmax_index;
130 boolean vertex_array_out_of_memory;
131 boolean has_hw_atomics;
132
133 /* Some state is contained in constant objects.
134 * Other state is just parameter values.
135 */
136 struct {
137 struct pipe_blend_state blend;
138 struct pipe_depth_stencil_alpha_state depth_stencil;
139 struct pipe_rasterizer_state rasterizer;
140 struct pipe_sampler_state samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
141 GLuint num_samplers[PIPE_SHADER_TYPES];
142 struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
143 GLuint num_sampler_views[PIPE_SHADER_TYPES];
144 struct pipe_clip_state clip;
145 struct {
146 void *ptr;
147 unsigned size;
148 } constants[PIPE_SHADER_TYPES];
149 unsigned fb_width;
150 unsigned fb_height;
151 unsigned fb_num_samples;
152 unsigned fb_num_layers;
153 unsigned num_viewports;
154 struct pipe_scissor_state scissor[PIPE_MAX_VIEWPORTS];
155 struct pipe_viewport_state viewport[PIPE_MAX_VIEWPORTS];
156 struct {
157 unsigned num;
158 boolean include;
159 struct pipe_scissor_state rects[PIPE_MAX_WINDOW_RECTANGLES];
160 } window_rects;
161
162 GLuint poly_stipple[32]; /**< In OpenGL's bottom-to-top order */
163
164 GLuint fb_orientation;
165 } state;
166
167 uint64_t dirty; /**< dirty states */
168
169 /** This masks out unused shader resources. Only valid in draw calls. */
170 uint64_t active_states;
171
172 /* If true, further analysis of states is required to know if something
173 * has changed. Used mainly for shaders.
174 */
175 bool gfx_shaders_may_be_dirty;
176 bool compute_shader_may_be_dirty;
177
178 GLboolean vertdata_edgeflags;
179 GLboolean edgeflag_culls_prims;
180
181 struct st_vertex_program *vp; /**< Currently bound vertex program */
182 struct st_fragment_program *fp; /**< Currently bound fragment program */
183 struct st_common_program *gp; /**< Currently bound geometry program */
184 struct st_common_program *tcp; /**< Currently bound tess control program */
185 struct st_common_program *tep; /**< Currently bound tess eval program */
186 struct st_compute_program *cp; /**< Currently bound compute program */
187
188 struct st_vp_variant *vp_variant;
189
190 struct {
191 struct pipe_resource *pixelmap_texture;
192 struct pipe_sampler_view *pixelmap_sampler_view;
193 } pixel_xfer;
194
195 /** for glBitmap */
196 struct {
197 struct pipe_rasterizer_state rasterizer;
198 struct pipe_sampler_state sampler;
199 struct pipe_sampler_state atlas_sampler;
200 enum pipe_format tex_format;
201 void *vs;
202 struct st_bitmap_cache cache;
203 } bitmap;
204
205 /** for glDraw/CopyPixels */
206 struct {
207 void *zs_shaders[4];
208 void *vert_shaders[2]; /**< ureg shaders */
209 } drawpix;
210
211 struct {
212 GLsizei width, height;
213 GLenum format, type;
214 const void *user_pointer; /**< Last user 'pixels' pointer */
215 void *image; /**< Copy of the glDrawPixels image data */
216 struct pipe_resource *texture;
217 } drawpix_cache;
218
219 /** for glReadPixels */
220 struct {
221 struct pipe_resource *src;
222 struct pipe_resource *cache;
223 enum pipe_format dst_format;
224 unsigned level;
225 unsigned layer;
226 unsigned hits;
227 } readpix_cache;
228
229 /** for glClear */
230 struct {
231 struct pipe_rasterizer_state raster;
232 struct pipe_viewport_state viewport;
233 void *vs;
234 void *fs;
235 void *vs_layered;
236 void *gs_layered;
237 } clear;
238
239 /* For gl(Compressed)Tex(Sub)Image */
240 struct {
241 struct pipe_rasterizer_state raster;
242 struct pipe_blend_state upload_blend;
243 void *vs;
244 void *gs;
245 void *upload_fs[3];
246 void *download_fs[3][PIPE_MAX_TEXTURE_TYPES];
247 bool upload_enabled;
248 bool download_enabled;
249 bool rgba_only;
250 bool layers;
251 bool use_gs;
252 } pbo;
253
254 /** for drawing with st_util_vertex */
255 struct pipe_vertex_element util_velems[3];
256
257 void *passthrough_fs; /**< simple pass-through frag shader */
258
259 enum pipe_texture_target internal_target;
260
261 struct cso_context *cso_context;
262
263 void *winsys_drawable_handle;
264
265 /* The number of vertex buffers from the last call of validate_arrays. */
266 unsigned last_num_vbuffers;
267
268 int32_t draw_stamp;
269 int32_t read_stamp;
270
271 struct st_config_options options;
272
273 struct st_perf_monitor_group *perfmon;
274
275 enum pipe_reset_status reset_status;
276
277 /* Array of bound texture/image handles which are resident in the context.
278 */
279 struct st_bound_handles bound_texture_handles[PIPE_SHADER_TYPES];
280 struct st_bound_handles bound_image_handles[PIPE_SHADER_TYPES];
281
282 /* Winsys buffers */
283 struct list_head winsys_buffers;
284 };
285
286
287 /* Need this so that we can implement Mesa callbacks in this module.
288 */
289 static inline struct st_context *st_context(struct gl_context *ctx)
290 {
291 return ctx->st;
292 }
293
294
295 /**
296 * Wrapper for struct gl_framebuffer.
297 * This is an opaque type to the outside world.
298 */
299 struct st_framebuffer
300 {
301 struct gl_framebuffer Base;
302
303 struct st_framebuffer_iface *iface;
304 enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
305 unsigned num_statts;
306 int32_t stamp;
307 int32_t iface_stamp;
308 uint32_t iface_ID;
309
310 /* list of framebuffer objects */
311 struct list_head head;
312 };
313
314
315 extern void st_init_driver_functions(struct pipe_screen *screen,
316 struct dd_function_table *functions);
317
318 void
319 st_invalidate_buffers(struct st_context *st);
320
321 /* Invalidate the readpixels cache to ensure we don't read stale data.
322 */
323 static inline void
324 st_invalidate_readpix_cache(struct st_context *st)
325 {
326 if (unlikely(st->readpix_cache.src)) {
327 pipe_resource_reference(&st->readpix_cache.src, NULL);
328 pipe_resource_reference(&st->readpix_cache.cache, NULL);
329 }
330 }
331
332
333 #define Y_0_TOP 1
334 #define Y_0_BOTTOM 2
335
336 static inline GLuint
337 st_fb_orientation(const struct gl_framebuffer *fb)
338 {
339 if (fb && _mesa_is_winsys_fbo(fb)) {
340 /* Drawing into a window (on-screen buffer).
341 *
342 * Negate Y scale to flip image vertically.
343 * The NDC Y coords prior to viewport transformation are in the range
344 * [y=-1=bottom, y=1=top]
345 * Hardware window coords are in the range [y=0=top, y=H-1=bottom] where
346 * H is the window height.
347 * Use the viewport transformation to invert Y.
348 */
349 return Y_0_TOP;
350 }
351 else {
352 /* Drawing into user-created FBO (very likely a texture).
353 *
354 * For textures, T=0=Bottom, so by extension Y=0=Bottom for rendering.
355 */
356 return Y_0_BOTTOM;
357 }
358 }
359
360
361 static inline bool
362 st_user_clip_planes_enabled(struct gl_context *ctx)
363 {
364 return (ctx->API == API_OPENGL_COMPAT ||
365 ctx->API == API_OPENGLES) && /* only ES 1.x */
366 ctx->Transform.ClipPlanesEnabled;
367 }
368
369 /** clear-alloc a struct-sized object, with casting */
370 #define ST_CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
371
372
373 extern struct st_context *
374 st_create_context(gl_api api, struct pipe_context *pipe,
375 const struct gl_config *visual,
376 struct st_context *share,
377 const struct st_config_options *options,
378 bool no_error);
379
380 extern void
381 st_destroy_context(struct st_context *st);
382
383 uint64_t
384 st_get_active_states(struct gl_context *ctx);
385
386
387 #ifdef __cplusplus
388 }
389 #endif
390
391 #endif