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