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