vc4: Introduce XML-based packet header generation like Intel's.
[mesa.git] / src / mesa / state_tracker / st_context.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 #include "main/imports.h"
29 #include "main/accum.h"
30 #include "main/api_exec.h"
31 #include "main/context.h"
32 #include "main/glthread.h"
33 #include "main/samplerobj.h"
34 #include "main/shaderobj.h"
35 #include "main/version.h"
36 #include "main/vtxfmt.h"
37 #include "main/hash.h"
38 #include "program/prog_cache.h"
39 #include "vbo/vbo.h"
40 #include "glapi/glapi.h"
41 #include "st_context.h"
42 #include "st_debug.h"
43 #include "st_cb_bitmap.h"
44 #include "st_cb_blit.h"
45 #include "st_cb_bufferobjects.h"
46 #include "st_cb_clear.h"
47 #include "st_cb_compute.h"
48 #include "st_cb_condrender.h"
49 #include "st_cb_copyimage.h"
50 #include "st_cb_drawpixels.h"
51 #include "st_cb_rasterpos.h"
52 #include "st_cb_drawtex.h"
53 #include "st_cb_eglimage.h"
54 #include "st_cb_fbo.h"
55 #include "st_cb_feedback.h"
56 #include "st_cb_msaa.h"
57 #include "st_cb_perfmon.h"
58 #include "st_cb_program.h"
59 #include "st_cb_queryobj.h"
60 #include "st_cb_readpixels.h"
61 #include "st_cb_texture.h"
62 #include "st_cb_xformfb.h"
63 #include "st_cb_flush.h"
64 #include "st_cb_syncobj.h"
65 #include "st_cb_strings.h"
66 #include "st_cb_texturebarrier.h"
67 #include "st_cb_viewport.h"
68 #include "st_atom.h"
69 #include "st_draw.h"
70 #include "st_extensions.h"
71 #include "st_gen_mipmap.h"
72 #include "st_pbo.h"
73 #include "st_program.h"
74 #include "st_sampler_view.h"
75 #include "st_vdpau.h"
76 #include "st_texture.h"
77 #include "pipe/p_context.h"
78 #include "util/u_inlines.h"
79 #include "util/u_upload_mgr.h"
80 #include "util/u_vbuf.h"
81 #include "cso_cache/cso_context.h"
82
83
84 DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE)
85
86
87 /**
88 * Called via ctx->Driver.Enable()
89 */
90 static void st_Enable(struct gl_context * ctx, GLenum cap, GLboolean state)
91 {
92 struct st_context *st = st_context(ctx);
93
94 switch (cap) {
95 case GL_DEBUG_OUTPUT:
96 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
97 st_update_debug_callback(st);
98 break;
99 default:
100 break;
101 }
102 }
103
104
105 /**
106 * Called via ctx->Driver.QueryMemoryInfo()
107 */
108 static void
109 st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out)
110 {
111 struct pipe_screen *screen = st_context(ctx)->pipe->screen;
112 struct pipe_memory_info info;
113
114 assert(screen->query_memory_info);
115 if (!screen->query_memory_info)
116 return;
117
118 screen->query_memory_info(screen, &info);
119
120 out->total_device_memory = info.total_device_memory;
121 out->avail_device_memory = info.avail_device_memory;
122 out->total_staging_memory = info.total_staging_memory;
123 out->avail_staging_memory = info.avail_staging_memory;
124 out->device_memory_evicted = info.device_memory_evicted;
125 out->nr_device_memory_evictions = info.nr_device_memory_evictions;
126 }
127
128
129 uint64_t
130 st_get_active_states(struct gl_context *ctx)
131 {
132 struct st_vertex_program *vp =
133 st_vertex_program(ctx->VertexProgram._Current);
134 struct st_common_program *tcp =
135 st_common_program(ctx->TessCtrlProgram._Current);
136 struct st_common_program *tep =
137 st_common_program(ctx->TessEvalProgram._Current);
138 struct st_common_program *gp =
139 st_common_program(ctx->GeometryProgram._Current);
140 struct st_fragment_program *fp =
141 st_fragment_program(ctx->FragmentProgram._Current);
142 struct st_compute_program *cp =
143 st_compute_program(ctx->ComputeProgram._Current);
144 uint64_t active_shader_states = 0;
145
146 if (vp)
147 active_shader_states |= vp->affected_states;
148 if (tcp)
149 active_shader_states |= tcp->affected_states;
150 if (tep)
151 active_shader_states |= tep->affected_states;
152 if (gp)
153 active_shader_states |= gp->affected_states;
154 if (fp)
155 active_shader_states |= fp->affected_states;
156 if (cp)
157 active_shader_states |= cp->affected_states;
158
159 /* Mark non-shader-resource shader states as "always active". */
160 return active_shader_states | ~ST_ALL_SHADER_RESOURCES;
161 }
162
163
164 void
165 st_invalidate_buffers(struct st_context *st)
166 {
167 st->dirty |= ST_NEW_BLEND |
168 ST_NEW_DSA |
169 ST_NEW_FB_STATE |
170 ST_NEW_SAMPLE_MASK |
171 ST_NEW_SAMPLE_SHADING |
172 ST_NEW_FS_STATE |
173 ST_NEW_POLY_STIPPLE |
174 ST_NEW_VIEWPORT |
175 ST_NEW_RASTERIZER |
176 ST_NEW_SCISSOR |
177 ST_NEW_WINDOW_RECTANGLES;
178 }
179
180
181 /**
182 * Called via ctx->Driver.UpdateState()
183 */
184 static void
185 st_invalidate_state(struct gl_context * ctx)
186 {
187 GLbitfield new_state = ctx->NewState;
188 struct st_context *st = st_context(ctx);
189
190 if (new_state & _NEW_BUFFERS) {
191 st_invalidate_buffers(st);
192 } else {
193 /* These set a subset of flags set by _NEW_BUFFERS, so we only have to
194 * check them when _NEW_BUFFERS isn't set.
195 */
196 if (new_state & _NEW_PROGRAM)
197 st->dirty |= ST_NEW_RASTERIZER;
198
199 if (new_state & _NEW_FOG)
200 st->dirty |= ST_NEW_FS_STATE;
201
202 if (new_state & _NEW_FRAG_CLAMP) {
203 if (st->clamp_frag_color_in_shader)
204 st->dirty |= ST_NEW_FS_STATE;
205 else
206 st->dirty |= ST_NEW_RASTERIZER;
207 }
208 }
209
210 if (new_state & (_NEW_LIGHT |
211 _NEW_POINT))
212 st->dirty |= ST_NEW_RASTERIZER;
213
214 if (new_state & _NEW_PROJECTION &&
215 st_user_clip_planes_enabled(ctx))
216 st->dirty |= ST_NEW_CLIP_STATE;
217
218 if (new_state & _NEW_PIXEL)
219 st->dirty |= ST_NEW_PIXEL_TRANSFER;
220
221 if (new_state & _NEW_CURRENT_ATTRIB)
222 st->dirty |= ST_NEW_VERTEX_ARRAYS;
223
224 /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
225 if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT))
226 st->dirty |= ST_NEW_VS_STATE;
227
228 /* Which shaders are dirty will be determined manually. */
229 if (new_state & _NEW_PROGRAM) {
230 st->gfx_shaders_may_be_dirty = true;
231 st->compute_shader_may_be_dirty = true;
232 /* This will mask out unused shader resources. */
233 st->active_states = st_get_active_states(ctx);
234 }
235
236 if (new_state & _NEW_TEXTURE_OBJECT) {
237 st->dirty |= st->active_states &
238 (ST_NEW_SAMPLER_VIEWS |
239 ST_NEW_SAMPLERS |
240 ST_NEW_IMAGE_UNITS);
241 if (ctx->FragmentProgram._Current &&
242 ctx->FragmentProgram._Current->ExternalSamplersUsed) {
243 st->dirty |= ST_NEW_FS_STATE;
244 }
245 }
246 }
247
248
249 static void
250 st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
251 {
252 uint shader, i;
253
254 st_destroy_atoms( st );
255 st_destroy_draw( st );
256 st_destroy_clear(st);
257 st_destroy_bitmap(st);
258 st_destroy_drawpix(st);
259 st_destroy_drawtex(st);
260 st_destroy_perfmon(st);
261 st_destroy_pbo_helpers(st);
262 st_destroy_bound_texture_handles(st);
263 st_destroy_bound_image_handles(st);
264
265 for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) {
266 for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
267 pipe_sampler_view_release(st->pipe,
268 &st->state.sampler_views[shader][i]);
269 }
270 }
271
272 /* free glDrawPixels cache data */
273 free(st->drawpix_cache.image);
274 pipe_resource_reference(&st->drawpix_cache.texture, NULL);
275
276 /* free glReadPixels cache data */
277 st_invalidate_readpix_cache(st);
278
279 cso_destroy_context(st->cso_context);
280
281 if (st->pipe && destroy_pipe)
282 st->pipe->destroy(st->pipe);
283
284 free( st );
285 }
286
287 static void st_init_driver_flags(struct st_context *st);
288
289 static struct st_context *
290 st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
291 const struct st_config_options *options)
292 {
293 struct pipe_screen *screen = pipe->screen;
294 uint i;
295 struct st_context *st = ST_CALLOC_STRUCT( st_context );
296
297 st->options = *options;
298
299 ctx->st = st;
300
301 st->ctx = ctx;
302 st->pipe = pipe;
303
304 /* state tracker needs the VBO module */
305 _vbo_CreateContext(ctx);
306
307 st->dirty = ST_ALL_STATES_MASK;
308
309 st->has_user_constbuf =
310 screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS);
311 st->can_bind_const_buffer_as_vertex =
312 screen->get_param(screen, PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX);
313
314 /* Drivers still have to upload zero-stride vertex attribs manually
315 * with the GL core profile, but they don't have to deal with any complex
316 * user vertex buffer uploads.
317 */
318 unsigned vbuf_flags =
319 ctx->API == API_OPENGL_CORE ? U_VBUF_FLAG_NO_USER_VBOS : 0;
320 st->cso_context = cso_create_context(pipe, vbuf_flags);
321
322 st_init_atoms( st );
323 st_init_clear(st);
324 st_init_draw( st );
325 st_init_pbo_helpers(st);
326
327 /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */
328 if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
329 st->internal_target = PIPE_TEXTURE_2D;
330 else
331 st->internal_target = PIPE_TEXTURE_RECT;
332
333 /* Setup vertex element info for 'struct st_util_vertex'.
334 */
335 {
336 const unsigned slot = cso_get_aux_vertex_buffer_slot(st->cso_context);
337
338 /* If this assertion ever fails all state tracker calls to
339 * cso_get_aux_vertex_buffer_slot() should be audited. This
340 * particular call would have to be moved to just before each
341 * drawing call.
342 */
343 assert(slot == 0);
344
345 STATIC_ASSERT(sizeof(struct st_util_vertex) == 9 * sizeof(float));
346
347 memset(&st->util_velems, 0, sizeof(st->util_velems));
348 st->util_velems[0].src_offset = 0;
349 st->util_velems[0].vertex_buffer_index = slot;
350 st->util_velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT;
351 st->util_velems[1].src_offset = 3 * sizeof(float);
352 st->util_velems[1].vertex_buffer_index = slot;
353 st->util_velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
354 st->util_velems[2].src_offset = 7 * sizeof(float);
355 st->util_velems[2].vertex_buffer_index = slot;
356 st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
357 }
358
359 /* we want all vertex data to be placed in buffer objects */
360 vbo_use_buffer_objects(ctx);
361
362
363 /* make sure that no VBOs are left mapped when we're drawing. */
364 vbo_always_unmap_buffers(ctx);
365
366 /* Need these flags:
367 */
368 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
369
370 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
371
372 st->has_stencil_export =
373 screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT);
374 st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3);
375 st->has_etc1 = screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8,
376 PIPE_TEXTURE_2D, 0,
377 PIPE_BIND_SAMPLER_VIEW);
378 st->has_etc2 = screen->is_format_supported(screen, PIPE_FORMAT_ETC2_RGB8,
379 PIPE_TEXTURE_2D, 0,
380 PIPE_BIND_SAMPLER_VIEW);
381 st->prefer_blit_based_texture_transfer = screen->get_param(screen,
382 PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER);
383 st->force_persample_in_shader =
384 screen->get_param(screen, PIPE_CAP_SAMPLE_SHADING) &&
385 !screen->get_param(screen, PIPE_CAP_FORCE_PERSAMPLE_INTERP);
386 st->has_shareable_shaders = screen->get_param(screen,
387 PIPE_CAP_SHAREABLE_SHADERS);
388 st->needs_texcoord_semantic =
389 screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD);
390 st->apply_texture_swizzle_to_border_color =
391 !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) &
392 (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 |
393 PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600));
394 st->has_time_elapsed =
395 screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED);
396 st->has_half_float_packing =
397 screen->get_param(screen, PIPE_CAP_TGSI_PACK_HALF_FLOAT);
398 st->has_multi_draw_indirect =
399 screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT);
400
401 /* GL limits and extensions */
402 st_init_limits(pipe->screen, &ctx->Const, &ctx->Extensions);
403 st_init_extensions(pipe->screen, &ctx->Const,
404 &ctx->Extensions, &st->options, ctx->Mesa_DXTn);
405
406 if (st_have_perfmon(st)) {
407 ctx->Extensions.AMD_performance_monitor = GL_TRUE;
408 }
409
410 /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */
411 if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
412 if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
413 st->clamp_vert_color_in_shader = GL_TRUE;
414 }
415
416 if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
417 st->clamp_frag_color_in_shader = GL_TRUE;
418 }
419
420 /* For drivers which cannot do color clamping, it's better to just
421 * disable ARB_color_buffer_float in the core profile, because
422 * the clamping is deprecated there anyway. */
423 if (ctx->API == API_OPENGL_CORE &&
424 (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) {
425 st->clamp_vert_color_in_shader = GL_FALSE;
426 st->clamp_frag_color_in_shader = GL_FALSE;
427 ctx->Extensions.ARB_color_buffer_float = GL_FALSE;
428 }
429 }
430
431 /* called after _mesa_create_context/_mesa_init_point, fix default user
432 * settable max point size up
433 */
434 ctx->Point.MaxSize = MAX2(ctx->Const.MaxPointSize,
435 ctx->Const.MaxPointSizeAA);
436 /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */
437 ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !st->has_shader_model3;
438
439 if (!ctx->Extensions.ARB_gpu_shader5) {
440 for (i = 0; i < MESA_SHADER_STAGES; i++)
441 ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true;
442 }
443
444 /* Set which shader types can be compiled at link time. */
445 st->shader_has_one_variant[MESA_SHADER_VERTEX] =
446 st->has_shareable_shaders &&
447 !st->clamp_vert_color_in_shader;
448
449 st->shader_has_one_variant[MESA_SHADER_FRAGMENT] =
450 st->has_shareable_shaders &&
451 !st->clamp_frag_color_in_shader &&
452 !st->force_persample_in_shader;
453
454 st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
455 st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders;
456 st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders;
457 st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders;
458
459 st->bitmap.cache.empty = true;
460
461 _mesa_compute_version(ctx);
462
463 if (ctx->Version == 0) {
464 /* This can happen when a core profile was requested, but the driver
465 * does not support some features of GL 3.1 or later.
466 */
467 st_destroy_context_priv(st, false);
468 return NULL;
469 }
470
471 _mesa_initialize_dispatch_tables(ctx);
472 _mesa_initialize_vbo_vtxfmt(ctx);
473 st_init_driver_flags(st);
474
475 return st;
476 }
477
478 static void st_init_driver_flags(struct st_context *st)
479 {
480 struct gl_driver_flags *f = &st->ctx->DriverFlags;
481
482 f->NewArray = ST_NEW_VERTEX_ARRAYS;
483 f->NewRasterizerDiscard = ST_NEW_RASTERIZER;
484 f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER;
485 f->NewDefaultTessLevels = ST_NEW_TESS_STATE;
486
487 /* Shader resources */
488 f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS;
489 f->NewAtomicBuffer = ST_NEW_ATOMIC_BUFFER;
490 f->NewShaderStorageBuffer = ST_NEW_STORAGE_BUFFER;
491 f->NewImageUnits = ST_NEW_IMAGE_UNITS;
492
493 f->NewShaderConstants[MESA_SHADER_VERTEX] = ST_NEW_VS_CONSTANTS;
494 f->NewShaderConstants[MESA_SHADER_TESS_CTRL] = ST_NEW_TCS_CONSTANTS;
495 f->NewShaderConstants[MESA_SHADER_TESS_EVAL] = ST_NEW_TES_CONSTANTS;
496 f->NewShaderConstants[MESA_SHADER_GEOMETRY] = ST_NEW_GS_CONSTANTS;
497 f->NewShaderConstants[MESA_SHADER_FRAGMENT] = ST_NEW_FS_CONSTANTS;
498 f->NewShaderConstants[MESA_SHADER_COMPUTE] = ST_NEW_CS_CONSTANTS;
499
500 f->NewWindowRectangles = ST_NEW_WINDOW_RECTANGLES;
501 f->NewFramebufferSRGB = ST_NEW_FB_STATE;
502 f->NewScissorRect = ST_NEW_SCISSOR;
503 f->NewScissorTest = ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
504 f->NewAlphaTest = ST_NEW_DSA;
505 f->NewBlend = ST_NEW_BLEND;
506 f->NewBlendColor = ST_NEW_BLEND_COLOR;
507 f->NewColorMask = ST_NEW_BLEND;
508 f->NewDepth = ST_NEW_DSA;
509 f->NewLogicOp = ST_NEW_BLEND;
510 f->NewStencil = ST_NEW_DSA;
511 f->NewMultisampleEnable = ST_NEW_BLEND | ST_NEW_RASTERIZER |
512 ST_NEW_SAMPLE_MASK | ST_NEW_SAMPLE_SHADING;
513 f->NewSampleAlphaToXEnable = ST_NEW_BLEND;
514 f->NewSampleMask = ST_NEW_SAMPLE_MASK;
515 f->NewSampleShading = ST_NEW_SAMPLE_SHADING;
516
517 /* This depends on what the gallium driver wants. */
518 if (st->force_persample_in_shader) {
519 f->NewMultisampleEnable |= ST_NEW_FS_STATE;
520 f->NewSampleShading |= ST_NEW_FS_STATE;
521 } else {
522 f->NewSampleShading |= ST_NEW_RASTERIZER;
523 }
524
525 f->NewClipControl = ST_NEW_VIEWPORT | ST_NEW_RASTERIZER;
526 f->NewClipPlane = ST_NEW_CLIP_STATE;
527 f->NewClipPlaneEnable = ST_NEW_RASTERIZER;
528 f->NewDepthClamp = ST_NEW_RASTERIZER;
529 f->NewLineState = ST_NEW_RASTERIZER;
530 f->NewPolygonState = ST_NEW_RASTERIZER;
531 f->NewPolygonStipple = ST_NEW_POLY_STIPPLE;
532 f->NewViewport = ST_NEW_VIEWPORT;
533 }
534
535 struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
536 const struct gl_config *visual,
537 struct st_context *share,
538 const struct st_config_options *options)
539 {
540 struct gl_context *ctx;
541 struct gl_context *shareCtx = share ? share->ctx : NULL;
542 struct dd_function_table funcs;
543 struct st_context *st;
544
545 memset(&funcs, 0, sizeof(funcs));
546 st_init_driver_functions(pipe->screen, &funcs);
547
548 ctx = calloc(1, sizeof(struct gl_context));
549 if (!ctx)
550 return NULL;
551
552 if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) {
553 free(ctx);
554 return NULL;
555 }
556
557 st_debug_init();
558
559 if (pipe->screen->get_disk_shader_cache &&
560 !(ST_DEBUG & DEBUG_TGSI))
561 ctx->Cache = pipe->screen->get_disk_shader_cache(pipe->screen);
562
563 /* XXX: need a capability bit in gallium to query if the pipe
564 * driver prefers DP4 or MUL/MAD for vertex transformation.
565 */
566 if (debug_get_option_mesa_mvp_dp4())
567 ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE;
568
569 st = st_create_context_priv(ctx, pipe, options);
570 if (!st) {
571 _mesa_destroy_context(ctx);
572 }
573
574 return st;
575 }
576
577
578 /**
579 * Callback to release the sampler view attached to a texture object.
580 * Called by _mesa_HashWalk().
581 */
582 static void
583 destroy_tex_sampler_cb(GLuint id, void *data, void *userData)
584 {
585 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
586 struct st_context *st = (struct st_context *) userData;
587
588 st_texture_release_sampler_view(st, st_texture_object(texObj));
589 }
590
591 void st_destroy_context( struct st_context *st )
592 {
593 struct gl_context *ctx = st->ctx;
594
595 /* This must be called first so that glthread has a chance to finish */
596 _mesa_glthread_destroy(ctx);
597
598 _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st);
599
600 st_reference_fragprog(st, &st->fp, NULL);
601 st_reference_prog(st, &st->gp, NULL);
602 st_reference_vertprog(st, &st->vp, NULL);
603 st_reference_prog(st, &st->tcp, NULL);
604 st_reference_prog(st, &st->tep, NULL);
605 st_reference_compprog(st, &st->cp, NULL);
606
607 pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL);
608 pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL);
609
610 _vbo_DestroyContext(ctx);
611
612 st_destroy_program_variants(st);
613
614 _mesa_free_context_data(ctx);
615
616 /* This will free the st_context too, so 'st' must not be accessed
617 * afterwards. */
618 st_destroy_context_priv(st, true);
619 st = NULL;
620
621 free(ctx);
622 }
623
624 static void
625 st_emit_string_marker(struct gl_context *ctx, const GLchar *string, GLsizei len)
626 {
627 struct st_context *st = ctx->st;
628 st->pipe->emit_string_marker(st->pipe, string, len);
629 }
630
631 static void
632 st_set_background_context(struct gl_context *ctx,
633 struct util_queue_monitoring *queue_info)
634 {
635 struct st_context *st = ctx->st;
636 struct st_manager *smapi =
637 (struct st_manager*)st->iface.st_context_private;
638
639 assert(smapi->set_background_context);
640 smapi->set_background_context(&st->iface, queue_info);
641 }
642
643 void st_init_driver_functions(struct pipe_screen *screen,
644 struct dd_function_table *functions)
645 {
646 _mesa_init_shader_object_functions(functions);
647 _mesa_init_sampler_object_functions(functions);
648
649 st_init_blit_functions(functions);
650 st_init_bufferobject_functions(screen, functions);
651 st_init_clear_functions(functions);
652 st_init_bitmap_functions(functions);
653 st_init_copy_image_functions(functions);
654 st_init_drawpixels_functions(functions);
655 st_init_rasterpos_functions(functions);
656
657 st_init_drawtex_functions(functions);
658
659 st_init_eglimage_functions(functions);
660
661 st_init_fbo_functions(functions);
662 st_init_feedback_functions(functions);
663 st_init_msaa_functions(functions);
664 st_init_perfmon_functions(functions);
665 st_init_program_functions(functions);
666 st_init_query_functions(functions);
667 st_init_cond_render_functions(functions);
668 st_init_readpixels_functions(functions);
669 st_init_texture_functions(functions);
670 st_init_texture_barrier_functions(functions);
671 st_init_flush_functions(screen, functions);
672 st_init_string_functions(functions);
673 st_init_viewport_functions(functions);
674 st_init_compute_functions(functions);
675
676 st_init_xformfb_functions(functions);
677 st_init_syncobj_functions(functions);
678
679 st_init_vdpau_functions(functions);
680
681 if (screen->get_param(screen, PIPE_CAP_STRING_MARKER))
682 functions->EmitStringMarker = st_emit_string_marker;
683
684 functions->Enable = st_Enable;
685 functions->UpdateState = st_invalidate_state;
686 functions->QueryMemoryInfo = st_query_memory_info;
687 functions->SetBackgroundContext = st_set_background_context;
688 }