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