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