c901764668775d1ca2d14b74c1508c2af43f618b
[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 /**
165 * Called via ctx->Driver.UpdateState()
166 */
167 void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
168 {
169 struct st_context *st = st_context(ctx);
170
171 if (new_state & _NEW_BUFFERS) {
172 st->dirty |= ST_NEW_BLEND |
173 ST_NEW_DSA |
174 ST_NEW_FB_STATE |
175 ST_NEW_SAMPLE_MASK |
176 ST_NEW_SAMPLE_SHADING |
177 ST_NEW_FS_STATE |
178 ST_NEW_POLY_STIPPLE |
179 ST_NEW_VIEWPORT |
180 ST_NEW_RASTERIZER |
181 ST_NEW_SCISSOR |
182 ST_NEW_WINDOW_RECTANGLES;
183 } else {
184 /* These set a subset of flags set by _NEW_BUFFERS, so we only have to
185 * check them when _NEW_BUFFERS isn't set.
186 */
187 if (new_state & (_NEW_DEPTH |
188 _NEW_STENCIL))
189 st->dirty |= ST_NEW_DSA;
190
191 if (new_state & _NEW_PROGRAM)
192 st->dirty |= ST_NEW_RASTERIZER;
193
194 if (new_state & _NEW_SCISSOR)
195 st->dirty |= ST_NEW_RASTERIZER |
196 ST_NEW_SCISSOR |
197 ST_NEW_WINDOW_RECTANGLES;
198
199 if (new_state & _NEW_FOG)
200 st->dirty |= ST_NEW_FS_STATE;
201
202 if (new_state & _NEW_POLYGONSTIPPLE)
203 st->dirty |= ST_NEW_POLY_STIPPLE;
204
205 if (new_state & _NEW_VIEWPORT)
206 st->dirty |= ST_NEW_VIEWPORT;
207
208 if (new_state & _NEW_FRAG_CLAMP) {
209 if (st->clamp_frag_color_in_shader)
210 st->dirty |= ST_NEW_FS_STATE;
211 else
212 st->dirty |= ST_NEW_RASTERIZER;
213 }
214 }
215
216 if (new_state & _NEW_MULTISAMPLE) {
217 st->dirty |= ST_NEW_BLEND |
218 ST_NEW_SAMPLE_MASK |
219 ST_NEW_SAMPLE_SHADING |
220 ST_NEW_RASTERIZER |
221 ST_NEW_FS_STATE;
222 } else {
223 /* These set a subset of flags set by _NEW_MULTISAMPLE, so we only
224 * have to check them when _NEW_MULTISAMPLE isn't set.
225 */
226 if (new_state & (_NEW_LIGHT |
227 _NEW_LINE |
228 _NEW_POINT |
229 _NEW_POLYGON |
230 _NEW_TRANSFORM))
231 st->dirty |= ST_NEW_RASTERIZER;
232 }
233
234 if (new_state & (_NEW_PROJECTION |
235 _NEW_TRANSFORM) &&
236 st_user_clip_planes_enabled(ctx))
237 st->dirty |= ST_NEW_CLIP_STATE;
238
239 if (new_state & _NEW_COLOR)
240 st->dirty |= ST_NEW_BLEND |
241 ST_NEW_DSA;
242
243 if (new_state & _NEW_PIXEL)
244 st->dirty |= ST_NEW_PIXEL_TRANSFER;
245
246 if (new_state & _NEW_CURRENT_ATTRIB)
247 st->dirty |= ST_NEW_VERTEX_ARRAYS;
248
249 /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
250 if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT))
251 st->dirty |= ST_NEW_VS_STATE;
252
253 /* Which shaders are dirty will be determined manually. */
254 if (new_state & _NEW_PROGRAM) {
255 st->gfx_shaders_may_be_dirty = true;
256 st->compute_shader_may_be_dirty = true;
257 /* This will mask out unused shader resources. */
258 st->active_states = st_get_active_states(ctx);
259 }
260
261 if (new_state & _NEW_TEXTURE_OBJECT) {
262 st->dirty |= st->active_states &
263 (ST_NEW_SAMPLER_VIEWS |
264 ST_NEW_SAMPLERS |
265 ST_NEW_IMAGE_UNITS);
266 if (ctx->FragmentProgram._Current &&
267 ctx->FragmentProgram._Current->ExternalSamplersUsed) {
268 st->dirty |= ST_NEW_FS_STATE;
269 }
270 }
271
272 if (new_state & _NEW_PROGRAM_CONSTANTS)
273 st->dirty |= st->active_states & ST_NEW_CONSTANTS;
274
275 /* This is the only core Mesa module we depend upon.
276 * No longer use swrast, swsetup, tnl.
277 */
278 _vbo_InvalidateState(ctx, new_state);
279 }
280
281
282 static void
283 st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
284 {
285 uint shader, i;
286
287 st_destroy_atoms( st );
288 st_destroy_draw( st );
289 st_destroy_clear(st);
290 st_destroy_bitmap(st);
291 st_destroy_drawpix(st);
292 st_destroy_drawtex(st);
293 st_destroy_perfmon(st);
294 st_destroy_pbo_helpers(st);
295
296 for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) {
297 for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
298 pipe_sampler_view_release(st->pipe,
299 &st->state.sampler_views[shader][i]);
300 }
301 }
302
303 /* free glDrawPixels cache data */
304 free(st->drawpix_cache.image);
305 pipe_resource_reference(&st->drawpix_cache.texture, NULL);
306
307 /* free glReadPixels cache data */
308 st_invalidate_readpix_cache(st);
309
310 cso_destroy_context(st->cso_context);
311
312 if (st->pipe && destroy_pipe)
313 st->pipe->destroy(st->pipe);
314
315 free( st );
316 }
317
318
319 static struct st_context *
320 st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
321 const struct st_config_options *options)
322 {
323 struct pipe_screen *screen = pipe->screen;
324 uint i;
325 struct st_context *st = ST_CALLOC_STRUCT( st_context );
326
327 st->options = *options;
328
329 ctx->st = st;
330
331 st->ctx = ctx;
332 st->pipe = pipe;
333
334 /* state tracker needs the VBO module */
335 _vbo_CreateContext(ctx);
336
337 st->dirty = ST_ALL_STATES_MASK;
338
339 st->has_user_constbuf =
340 screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS);
341 st->can_bind_const_buffer_as_vertex =
342 screen->get_param(screen, PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX);
343
344 /* Drivers still have to upload zero-stride vertex attribs manually
345 * with the GL core profile, but they don't have to deal with any complex
346 * user vertex buffer uploads.
347 */
348 unsigned vbuf_flags =
349 ctx->API == API_OPENGL_CORE ? U_VBUF_FLAG_NO_USER_VBOS : 0;
350 st->cso_context = cso_create_context(pipe, vbuf_flags);
351
352 st_init_atoms( st );
353 st_init_clear(st);
354 st_init_draw( st );
355 st_init_pbo_helpers(st);
356
357 /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */
358 if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES))
359 st->internal_target = PIPE_TEXTURE_2D;
360 else
361 st->internal_target = PIPE_TEXTURE_RECT;
362
363 /* Setup vertex element info for 'struct st_util_vertex'.
364 */
365 {
366 const unsigned slot = cso_get_aux_vertex_buffer_slot(st->cso_context);
367
368 /* If this assertion ever fails all state tracker calls to
369 * cso_get_aux_vertex_buffer_slot() should be audited. This
370 * particular call would have to be moved to just before each
371 * drawing call.
372 */
373 assert(slot == 0);
374
375 STATIC_ASSERT(sizeof(struct st_util_vertex) == 9 * sizeof(float));
376
377 memset(&st->util_velems, 0, sizeof(st->util_velems));
378 st->util_velems[0].src_offset = 0;
379 st->util_velems[0].vertex_buffer_index = slot;
380 st->util_velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT;
381 st->util_velems[1].src_offset = 3 * sizeof(float);
382 st->util_velems[1].vertex_buffer_index = slot;
383 st->util_velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
384 st->util_velems[2].src_offset = 7 * sizeof(float);
385 st->util_velems[2].vertex_buffer_index = slot;
386 st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
387 }
388
389 /* we want all vertex data to be placed in buffer objects */
390 vbo_use_buffer_objects(ctx);
391
392
393 /* make sure that no VBOs are left mapped when we're drawing. */
394 vbo_always_unmap_buffers(ctx);
395
396 /* Need these flags:
397 */
398 ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
399
400 ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
401
402 st->has_stencil_export =
403 screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT);
404 st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3);
405 st->has_etc1 = screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8,
406 PIPE_TEXTURE_2D, 0,
407 PIPE_BIND_SAMPLER_VIEW);
408 st->has_etc2 = screen->is_format_supported(screen, PIPE_FORMAT_ETC2_RGB8,
409 PIPE_TEXTURE_2D, 0,
410 PIPE_BIND_SAMPLER_VIEW);
411 st->prefer_blit_based_texture_transfer = screen->get_param(screen,
412 PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER);
413 st->force_persample_in_shader =
414 screen->get_param(screen, PIPE_CAP_SAMPLE_SHADING) &&
415 !screen->get_param(screen, PIPE_CAP_FORCE_PERSAMPLE_INTERP);
416 st->has_shareable_shaders = screen->get_param(screen,
417 PIPE_CAP_SHAREABLE_SHADERS);
418 st->needs_texcoord_semantic =
419 screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD);
420 st->apply_texture_swizzle_to_border_color =
421 !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) &
422 (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 |
423 PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600));
424 st->has_time_elapsed =
425 screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED);
426 st->has_half_float_packing =
427 screen->get_param(screen, PIPE_CAP_TGSI_PACK_HALF_FLOAT);
428 st->has_multi_draw_indirect =
429 screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT);
430
431 /* GL limits and extensions */
432 st_init_limits(pipe->screen, &ctx->Const, &ctx->Extensions);
433 st_init_extensions(pipe->screen, &ctx->Const,
434 &ctx->Extensions, &st->options, ctx->Mesa_DXTn);
435
436 if (st_have_perfmon(st)) {
437 ctx->Extensions.AMD_performance_monitor = GL_TRUE;
438 }
439
440 /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */
441 if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
442 if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
443 st->clamp_vert_color_in_shader = GL_TRUE;
444 }
445
446 if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
447 st->clamp_frag_color_in_shader = GL_TRUE;
448 }
449
450 /* For drivers which cannot do color clamping, it's better to just
451 * disable ARB_color_buffer_float in the core profile, because
452 * the clamping is deprecated there anyway. */
453 if (ctx->API == API_OPENGL_CORE &&
454 (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) {
455 st->clamp_vert_color_in_shader = GL_FALSE;
456 st->clamp_frag_color_in_shader = GL_FALSE;
457 ctx->Extensions.ARB_color_buffer_float = GL_FALSE;
458 }
459 }
460
461 /* called after _mesa_create_context/_mesa_init_point, fix default user
462 * settable max point size up
463 */
464 ctx->Point.MaxSize = MAX2(ctx->Const.MaxPointSize,
465 ctx->Const.MaxPointSizeAA);
466 /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */
467 ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !st->has_shader_model3;
468
469 if (!ctx->Extensions.ARB_gpu_shader5) {
470 for (i = 0; i < MESA_SHADER_STAGES; i++)
471 ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true;
472 }
473
474 /* Set which shader types can be compiled at link time. */
475 st->shader_has_one_variant[MESA_SHADER_VERTEX] =
476 st->has_shareable_shaders &&
477 !st->clamp_vert_color_in_shader;
478
479 st->shader_has_one_variant[MESA_SHADER_FRAGMENT] =
480 st->has_shareable_shaders &&
481 !st->clamp_frag_color_in_shader &&
482 !st->force_persample_in_shader;
483
484 st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders;
485 st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders;
486 st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders;
487 st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders;
488
489 st->bitmap.cache.empty = true;
490
491 _mesa_compute_version(ctx);
492
493 if (ctx->Version == 0) {
494 /* This can happen when a core profile was requested, but the driver
495 * does not support some features of GL 3.1 or later.
496 */
497 st_destroy_context_priv(st, false);
498 return NULL;
499 }
500
501 _mesa_initialize_dispatch_tables(ctx);
502 _mesa_initialize_vbo_vtxfmt(ctx);
503
504 return st;
505 }
506
507 static void st_init_driver_flags(struct gl_driver_flags *f)
508 {
509 f->NewArray = ST_NEW_VERTEX_ARRAYS;
510 f->NewRasterizerDiscard = ST_NEW_RASTERIZER;
511 f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER;
512 f->NewDefaultTessLevels = ST_NEW_TESS_STATE;
513 f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS;
514 f->NewAtomicBuffer = ST_NEW_ATOMIC_BUFFER;
515 f->NewShaderStorageBuffer = ST_NEW_STORAGE_BUFFER;
516 f->NewImageUnits = ST_NEW_IMAGE_UNITS;
517 }
518
519 struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
520 const struct gl_config *visual,
521 struct st_context *share,
522 const struct st_config_options *options)
523 {
524 struct gl_context *ctx;
525 struct gl_context *shareCtx = share ? share->ctx : NULL;
526 struct dd_function_table funcs;
527 struct st_context *st;
528
529 memset(&funcs, 0, sizeof(funcs));
530 st_init_driver_functions(pipe->screen, &funcs);
531
532 ctx = calloc(1, sizeof(struct gl_context));
533 if (!ctx)
534 return NULL;
535
536 if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) {
537 free(ctx);
538 return NULL;
539 }
540
541 st_debug_init();
542
543 if (pipe->screen->get_disk_shader_cache &&
544 !(ST_DEBUG & DEBUG_TGSI))
545 ctx->Cache = pipe->screen->get_disk_shader_cache(pipe->screen);
546
547 st_init_driver_flags(&ctx->DriverFlags);
548
549 /* XXX: need a capability bit in gallium to query if the pipe
550 * driver prefers DP4 or MUL/MAD for vertex transformation.
551 */
552 if (debug_get_option_mesa_mvp_dp4())
553 ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE;
554
555 st = st_create_context_priv(ctx, pipe, options);
556 if (!st) {
557 _mesa_destroy_context(ctx);
558 }
559
560 return st;
561 }
562
563
564 /**
565 * Callback to release the sampler view attached to a texture object.
566 * Called by _mesa_HashWalk().
567 */
568 static void
569 destroy_tex_sampler_cb(GLuint id, void *data, void *userData)
570 {
571 struct gl_texture_object *texObj = (struct gl_texture_object *) data;
572 struct st_context *st = (struct st_context *) userData;
573
574 st_texture_release_sampler_view(st, st_texture_object(texObj));
575 }
576
577 void st_destroy_context( struct st_context *st )
578 {
579 struct gl_context *ctx = st->ctx;
580 GLuint i;
581
582 /* This must be called first so that glthread has a chance to finish */
583 _mesa_glthread_destroy(ctx);
584
585 _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st);
586
587 st_reference_fragprog(st, &st->fp, NULL);
588 st_reference_prog(st, &st->gp, NULL);
589 st_reference_vertprog(st, &st->vp, NULL);
590 st_reference_prog(st, &st->tcp, NULL);
591 st_reference_prog(st, &st->tep, NULL);
592 st_reference_compprog(st, &st->cp, NULL);
593
594 /* release framebuffer surfaces */
595 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
596 pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
597 }
598 pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
599 pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL);
600 pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL);
601
602 _vbo_DestroyContext(ctx);
603
604 st_destroy_program_variants(st);
605
606 _mesa_free_context_data(ctx);
607
608 /* This will free the st_context too, so 'st' must not be accessed
609 * afterwards. */
610 st_destroy_context_priv(st, true);
611 st = NULL;
612
613 free(ctx);
614 }
615
616 static void
617 st_emit_string_marker(struct gl_context *ctx, const GLchar *string, GLsizei len)
618 {
619 struct st_context *st = ctx->st;
620 st->pipe->emit_string_marker(st->pipe, string, len);
621 }
622
623 static void
624 st_set_background_context(struct gl_context *ctx)
625 {
626 struct st_context *st = ctx->st;
627 struct st_manager *smapi =
628 (struct st_manager*)st->iface.st_context_private;
629
630 assert(smapi->set_background_context);
631 smapi->set_background_context(&st->iface);
632 }
633
634 void st_init_driver_functions(struct pipe_screen *screen,
635 struct dd_function_table *functions)
636 {
637 _mesa_init_shader_object_functions(functions);
638 _mesa_init_sampler_object_functions(functions);
639
640 st_init_blit_functions(functions);
641 st_init_bufferobject_functions(screen, functions);
642 st_init_clear_functions(functions);
643 st_init_bitmap_functions(functions);
644 st_init_copy_image_functions(functions);
645 st_init_drawpixels_functions(functions);
646 st_init_rasterpos_functions(functions);
647
648 st_init_drawtex_functions(functions);
649
650 st_init_eglimage_functions(functions);
651
652 st_init_fbo_functions(functions);
653 st_init_feedback_functions(functions);
654 st_init_msaa_functions(functions);
655 st_init_perfmon_functions(functions);
656 st_init_program_functions(functions);
657 st_init_query_functions(functions);
658 st_init_cond_render_functions(functions);
659 st_init_readpixels_functions(functions);
660 st_init_texture_functions(functions);
661 st_init_texture_barrier_functions(functions);
662 st_init_flush_functions(screen, functions);
663 st_init_string_functions(functions);
664 st_init_viewport_functions(functions);
665 st_init_compute_functions(functions);
666
667 st_init_xformfb_functions(functions);
668 st_init_syncobj_functions(functions);
669
670 st_init_vdpau_functions(functions);
671
672 if (screen->get_param(screen, PIPE_CAP_STRING_MARKER))
673 functions->EmitStringMarker = st_emit_string_marker;
674
675 functions->Enable = st_Enable;
676 functions->UpdateState = st_invalidate_state;
677 functions->QueryMemoryInfo = st_query_memory_info;
678 functions->SetBackgroundContext = st_set_background_context;
679 }