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