1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
40 #include "glapi/glapi.h"
41 #include "st_manager.h"
42 #include "st_context.h"
44 #include "st_cb_bitmap.h"
45 #include "st_cb_blit.h"
46 #include "st_cb_bufferobjects.h"
47 #include "st_cb_clear.h"
48 #include "st_cb_compute.h"
49 #include "st_cb_condrender.h"
50 #include "st_cb_copyimage.h"
51 #include "st_cb_drawpixels.h"
52 #include "st_cb_rasterpos.h"
53 #include "st_cb_drawtex.h"
54 #include "st_cb_eglimage.h"
55 #include "st_cb_fbo.h"
56 #include "st_cb_feedback.h"
57 #include "st_cb_memoryobjects.h"
58 #include "st_cb_msaa.h"
59 #include "st_cb_perfmon.h"
60 #include "st_cb_program.h"
61 #include "st_cb_queryobj.h"
62 #include "st_cb_readpixels.h"
63 #include "st_cb_texture.h"
64 #include "st_cb_xformfb.h"
65 #include "st_cb_flush.h"
66 #include "st_cb_syncobj.h"
67 #include "st_cb_strings.h"
68 #include "st_cb_texturebarrier.h"
69 #include "st_cb_viewport.h"
72 #include "st_extensions.h"
73 #include "st_gen_mipmap.h"
75 #include "st_program.h"
76 #include "st_sampler_view.h"
78 #include "st_texture.h"
79 #include "pipe/p_context.h"
80 #include "util/u_inlines.h"
81 #include "util/u_upload_mgr.h"
82 #include "util/u_vbuf.h"
83 #include "cso_cache/cso_context.h"
86 DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4
, "MESA_MVP_DP4", FALSE
)
90 * Called via ctx->Driver.Enable()
92 static void st_Enable(struct gl_context
* ctx
, GLenum cap
, GLboolean state
)
94 struct st_context
*st
= st_context(ctx
);
98 case GL_DEBUG_OUTPUT_SYNCHRONOUS
:
99 st_update_debug_callback(st
);
108 * Called via ctx->Driver.QueryMemoryInfo()
111 st_query_memory_info(struct gl_context
*ctx
, struct gl_memory_info
*out
)
113 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
114 struct pipe_memory_info info
;
116 assert(screen
->query_memory_info
);
117 if (!screen
->query_memory_info
)
120 screen
->query_memory_info(screen
, &info
);
122 out
->total_device_memory
= info
.total_device_memory
;
123 out
->avail_device_memory
= info
.avail_device_memory
;
124 out
->total_staging_memory
= info
.total_staging_memory
;
125 out
->avail_staging_memory
= info
.avail_staging_memory
;
126 out
->device_memory_evicted
= info
.device_memory_evicted
;
127 out
->nr_device_memory_evictions
= info
.nr_device_memory_evictions
;
132 st_get_active_states(struct gl_context
*ctx
)
134 struct st_vertex_program
*vp
=
135 st_vertex_program(ctx
->VertexProgram
._Current
);
136 struct st_common_program
*tcp
=
137 st_common_program(ctx
->TessCtrlProgram
._Current
);
138 struct st_common_program
*tep
=
139 st_common_program(ctx
->TessEvalProgram
._Current
);
140 struct st_common_program
*gp
=
141 st_common_program(ctx
->GeometryProgram
._Current
);
142 struct st_fragment_program
*fp
=
143 st_fragment_program(ctx
->FragmentProgram
._Current
);
144 struct st_compute_program
*cp
=
145 st_compute_program(ctx
->ComputeProgram
._Current
);
146 uint64_t active_shader_states
= 0;
149 active_shader_states
|= vp
->affected_states
;
151 active_shader_states
|= tcp
->affected_states
;
153 active_shader_states
|= tep
->affected_states
;
155 active_shader_states
|= gp
->affected_states
;
157 active_shader_states
|= fp
->affected_states
;
159 active_shader_states
|= cp
->affected_states
;
161 /* Mark non-shader-resource shader states as "always active". */
162 return active_shader_states
| ~ST_ALL_SHADER_RESOURCES
;
167 st_invalidate_buffers(struct st_context
*st
)
169 st
->dirty
|= ST_NEW_BLEND
|
173 ST_NEW_SAMPLE_SHADING
|
175 ST_NEW_POLY_STIPPLE
|
179 ST_NEW_WINDOW_RECTANGLES
;
184 * Called via ctx->Driver.UpdateState()
187 st_invalidate_state(struct gl_context
* ctx
)
189 GLbitfield new_state
= ctx
->NewState
;
190 struct st_context
*st
= st_context(ctx
);
192 if (new_state
& _NEW_BUFFERS
) {
193 st_invalidate_buffers(st
);
195 /* These set a subset of flags set by _NEW_BUFFERS, so we only have to
196 * check them when _NEW_BUFFERS isn't set.
198 if (new_state
& _NEW_PROGRAM
)
199 st
->dirty
|= ST_NEW_RASTERIZER
;
201 if (new_state
& _NEW_FOG
)
202 st
->dirty
|= ST_NEW_FS_STATE
;
204 if (new_state
& _NEW_FRAG_CLAMP
) {
205 if (st
->clamp_frag_color_in_shader
)
206 st
->dirty
|= ST_NEW_FS_STATE
;
208 st
->dirty
|= ST_NEW_RASTERIZER
;
212 if (new_state
& (_NEW_LIGHT
|
214 st
->dirty
|= ST_NEW_RASTERIZER
;
216 if (new_state
& _NEW_PROJECTION
&&
217 st_user_clip_planes_enabled(ctx
))
218 st
->dirty
|= ST_NEW_CLIP_STATE
;
220 if (new_state
& _NEW_PIXEL
)
221 st
->dirty
|= ST_NEW_PIXEL_TRANSFER
;
223 if (new_state
& _NEW_CURRENT_ATTRIB
)
224 st
->dirty
|= ST_NEW_VERTEX_ARRAYS
;
226 /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
227 if (st
->clamp_vert_color_in_shader
&& (new_state
& _NEW_LIGHT
))
228 st
->dirty
|= ST_NEW_VS_STATE
;
230 /* Which shaders are dirty will be determined manually. */
231 if (new_state
& _NEW_PROGRAM
) {
232 st
->gfx_shaders_may_be_dirty
= true;
233 st
->compute_shader_may_be_dirty
= true;
234 /* This will mask out unused shader resources. */
235 st
->active_states
= st_get_active_states(ctx
);
238 if (new_state
& _NEW_TEXTURE_OBJECT
) {
239 st
->dirty
|= st
->active_states
&
240 (ST_NEW_SAMPLER_VIEWS
|
243 if (ctx
->FragmentProgram
._Current
&&
244 ctx
->FragmentProgram
._Current
->ExternalSamplersUsed
) {
245 st
->dirty
|= ST_NEW_FS_STATE
;
252 st_destroy_context_priv(struct st_context
*st
, bool destroy_pipe
)
256 st_destroy_atoms( st
);
257 st_destroy_draw( st
);
258 st_destroy_clear(st
);
259 st_destroy_bitmap(st
);
260 st_destroy_drawpix(st
);
261 st_destroy_drawtex(st
);
262 st_destroy_perfmon(st
);
263 st_destroy_pbo_helpers(st
);
264 st_destroy_bound_texture_handles(st
);
265 st_destroy_bound_image_handles(st
);
267 for (shader
= 0; shader
< ARRAY_SIZE(st
->state
.sampler_views
); shader
++) {
268 for (i
= 0; i
< ARRAY_SIZE(st
->state
.sampler_views
[0]); i
++) {
269 pipe_sampler_view_release(st
->pipe
,
270 &st
->state
.sampler_views
[shader
][i
]);
274 /* free glDrawPixels cache data */
275 free(st
->drawpix_cache
.image
);
276 pipe_resource_reference(&st
->drawpix_cache
.texture
, NULL
);
278 /* free glReadPixels cache data */
279 st_invalidate_readpix_cache(st
);
281 cso_destroy_context(st
->cso_context
);
283 if (st
->pipe
&& destroy_pipe
)
284 st
->pipe
->destroy(st
->pipe
);
289 static void st_init_driver_flags(struct st_context
*st
);
291 static struct st_context
*
292 st_create_context_priv( struct gl_context
*ctx
, struct pipe_context
*pipe
,
293 const struct st_config_options
*options
, bool no_error
)
295 struct pipe_screen
*screen
= pipe
->screen
;
297 struct st_context
*st
= ST_CALLOC_STRUCT( st_context
);
299 st
->options
= *options
;
306 /* state tracker needs the VBO module */
307 _vbo_CreateContext(ctx
);
309 st
->dirty
= ST_ALL_STATES_MASK
;
311 st
->has_user_constbuf
=
312 screen
->get_param(screen
, PIPE_CAP_USER_CONSTANT_BUFFERS
);
313 st
->can_bind_const_buffer_as_vertex
=
314 screen
->get_param(screen
, PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX
);
316 /* st/mesa always uploads zero-stride vertex attribs, and other user
317 * vertex buffers are only possible with a compatibility profile.
318 * So tell the u_vbuf module that user VBOs are not possible with the Core
319 * profile, so that u_vbuf is bypassed completely if there is nothing else
322 unsigned vbuf_flags
=
323 ctx
->API
== API_OPENGL_CORE
? U_VBUF_FLAG_NO_USER_VBOS
: 0;
324 st
->cso_context
= cso_create_context(pipe
, vbuf_flags
);
329 st_init_pbo_helpers(st
);
331 /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */
332 if (pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_NPOT_TEXTURES
))
333 st
->internal_target
= PIPE_TEXTURE_2D
;
335 st
->internal_target
= PIPE_TEXTURE_RECT
;
337 /* Setup vertex element info for 'struct st_util_vertex'.
340 const unsigned slot
= cso_get_aux_vertex_buffer_slot(st
->cso_context
);
342 /* If this assertion ever fails all state tracker calls to
343 * cso_get_aux_vertex_buffer_slot() should be audited. This
344 * particular call would have to be moved to just before each
349 STATIC_ASSERT(sizeof(struct st_util_vertex
) == 9 * sizeof(float));
351 memset(&st
->util_velems
, 0, sizeof(st
->util_velems
));
352 st
->util_velems
[0].src_offset
= 0;
353 st
->util_velems
[0].vertex_buffer_index
= slot
;
354 st
->util_velems
[0].src_format
= PIPE_FORMAT_R32G32B32_FLOAT
;
355 st
->util_velems
[1].src_offset
= 3 * sizeof(float);
356 st
->util_velems
[1].vertex_buffer_index
= slot
;
357 st
->util_velems
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
358 st
->util_velems
[2].src_offset
= 7 * sizeof(float);
359 st
->util_velems
[2].vertex_buffer_index
= slot
;
360 st
->util_velems
[2].src_format
= PIPE_FORMAT_R32G32_FLOAT
;
363 /* we want all vertex data to be placed in buffer objects */
364 vbo_use_buffer_objects(ctx
);
367 /* make sure that no VBOs are left mapped when we're drawing. */
368 vbo_always_unmap_buffers(ctx
);
372 ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
374 ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
377 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
379 st
->has_stencil_export
=
380 screen
->get_param(screen
, PIPE_CAP_SHADER_STENCIL_EXPORT
);
381 st
->has_shader_model3
= screen
->get_param(screen
, PIPE_CAP_SM3
);
382 st
->has_etc1
= screen
->is_format_supported(screen
, PIPE_FORMAT_ETC1_RGB8
,
384 PIPE_BIND_SAMPLER_VIEW
);
385 st
->has_etc2
= screen
->is_format_supported(screen
, PIPE_FORMAT_ETC2_RGB8
,
387 PIPE_BIND_SAMPLER_VIEW
);
388 st
->prefer_blit_based_texture_transfer
= screen
->get_param(screen
,
389 PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER
);
390 st
->force_persample_in_shader
=
391 screen
->get_param(screen
, PIPE_CAP_SAMPLE_SHADING
) &&
392 !screen
->get_param(screen
, PIPE_CAP_FORCE_PERSAMPLE_INTERP
);
393 st
->has_shareable_shaders
= screen
->get_param(screen
,
394 PIPE_CAP_SHAREABLE_SHADERS
);
395 st
->needs_texcoord_semantic
=
396 screen
->get_param(screen
, PIPE_CAP_TGSI_TEXCOORD
);
397 st
->apply_texture_swizzle_to_border_color
=
398 !!(screen
->get_param(screen
, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK
) &
399 (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50
|
400 PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600
));
401 st
->has_time_elapsed
=
402 screen
->get_param(screen
, PIPE_CAP_QUERY_TIME_ELAPSED
);
403 st
->has_half_float_packing
=
404 screen
->get_param(screen
, PIPE_CAP_TGSI_PACK_HALF_FLOAT
);
405 st
->has_multi_draw_indirect
=
406 screen
->get_param(screen
, PIPE_CAP_MULTI_DRAW_INDIRECT
);
409 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
410 PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS
) ? true : false;
412 /* GL limits and extensions */
413 st_init_limits(pipe
->screen
, &ctx
->Const
, &ctx
->Extensions
);
414 st_init_extensions(pipe
->screen
, &ctx
->Const
,
415 &ctx
->Extensions
, &st
->options
, ctx
->API
);
417 if (st_have_perfmon(st
)) {
418 ctx
->Extensions
.AMD_performance_monitor
= GL_TRUE
;
421 /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */
422 if (screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_UNCLAMPED
)) {
423 if (!screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_CLAMPED
)) {
424 st
->clamp_vert_color_in_shader
= GL_TRUE
;
427 if (!screen
->get_param(screen
, PIPE_CAP_FRAGMENT_COLOR_CLAMPED
)) {
428 st
->clamp_frag_color_in_shader
= GL_TRUE
;
431 /* For drivers which cannot do color clamping, it's better to just
432 * disable ARB_color_buffer_float in the core profile, because
433 * the clamping is deprecated there anyway. */
434 if (ctx
->API
== API_OPENGL_CORE
&&
435 (st
->clamp_frag_color_in_shader
|| st
->clamp_vert_color_in_shader
)) {
436 st
->clamp_vert_color_in_shader
= GL_FALSE
;
437 st
->clamp_frag_color_in_shader
= GL_FALSE
;
438 ctx
->Extensions
.ARB_color_buffer_float
= GL_FALSE
;
442 /* called after _mesa_create_context/_mesa_init_point, fix default user
443 * settable max point size up
445 ctx
->Point
.MaxSize
= MAX2(ctx
->Const
.MaxPointSize
,
446 ctx
->Const
.MaxPointSizeAA
);
447 /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */
448 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].EmitNoSat
= !st
->has_shader_model3
;
450 if (!ctx
->Extensions
.ARB_gpu_shader5
) {
451 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
452 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectSampler
= true;
455 /* Set which shader types can be compiled at link time. */
456 st
->shader_has_one_variant
[MESA_SHADER_VERTEX
] =
457 st
->has_shareable_shaders
&&
458 !st
->clamp_vert_color_in_shader
;
460 st
->shader_has_one_variant
[MESA_SHADER_FRAGMENT
] =
461 st
->has_shareable_shaders
&&
462 !st
->clamp_frag_color_in_shader
&&
463 !st
->force_persample_in_shader
;
465 st
->shader_has_one_variant
[MESA_SHADER_TESS_CTRL
] = st
->has_shareable_shaders
;
466 st
->shader_has_one_variant
[MESA_SHADER_TESS_EVAL
] = st
->has_shareable_shaders
;
467 st
->shader_has_one_variant
[MESA_SHADER_GEOMETRY
] = st
->has_shareable_shaders
;
468 st
->shader_has_one_variant
[MESA_SHADER_COMPUTE
] = st
->has_shareable_shaders
;
470 st
->bitmap
.cache
.empty
= true;
472 _mesa_compute_version(ctx
);
474 if (ctx
->Version
== 0) {
475 /* This can happen when a core profile was requested, but the driver
476 * does not support some features of GL 3.1 or later.
478 st_destroy_context_priv(st
, false);
482 _mesa_initialize_dispatch_tables(ctx
);
483 _mesa_initialize_vbo_vtxfmt(ctx
);
484 st_init_driver_flags(st
);
486 /* Initialize context's winsys buffers list */
487 LIST_INITHEAD(&st
->winsys_buffers
);
492 static void st_init_driver_flags(struct st_context
*st
)
494 struct gl_driver_flags
*f
= &st
->ctx
->DriverFlags
;
496 f
->NewArray
= ST_NEW_VERTEX_ARRAYS
;
497 f
->NewRasterizerDiscard
= ST_NEW_RASTERIZER
;
498 f
->NewTileRasterOrder
= ST_NEW_RASTERIZER
;
499 f
->NewUniformBuffer
= ST_NEW_UNIFORM_BUFFER
;
500 f
->NewDefaultTessLevels
= ST_NEW_TESS_STATE
;
502 /* Shader resources */
503 f
->NewTextureBuffer
= ST_NEW_SAMPLER_VIEWS
;
504 if (st
->has_hw_atomics
)
505 f
->NewAtomicBuffer
= ST_NEW_HW_ATOMICS
;
507 f
->NewAtomicBuffer
= ST_NEW_ATOMIC_BUFFER
;
508 f
->NewShaderStorageBuffer
= ST_NEW_STORAGE_BUFFER
;
509 f
->NewImageUnits
= ST_NEW_IMAGE_UNITS
;
511 f
->NewShaderConstants
[MESA_SHADER_VERTEX
] = ST_NEW_VS_CONSTANTS
;
512 f
->NewShaderConstants
[MESA_SHADER_TESS_CTRL
] = ST_NEW_TCS_CONSTANTS
;
513 f
->NewShaderConstants
[MESA_SHADER_TESS_EVAL
] = ST_NEW_TES_CONSTANTS
;
514 f
->NewShaderConstants
[MESA_SHADER_GEOMETRY
] = ST_NEW_GS_CONSTANTS
;
515 f
->NewShaderConstants
[MESA_SHADER_FRAGMENT
] = ST_NEW_FS_CONSTANTS
;
516 f
->NewShaderConstants
[MESA_SHADER_COMPUTE
] = ST_NEW_CS_CONSTANTS
;
518 f
->NewWindowRectangles
= ST_NEW_WINDOW_RECTANGLES
;
519 f
->NewFramebufferSRGB
= ST_NEW_FB_STATE
;
520 f
->NewScissorRect
= ST_NEW_SCISSOR
;
521 f
->NewScissorTest
= ST_NEW_SCISSOR
| ST_NEW_RASTERIZER
;
522 f
->NewAlphaTest
= ST_NEW_DSA
;
523 f
->NewBlend
= ST_NEW_BLEND
;
524 f
->NewBlendColor
= ST_NEW_BLEND_COLOR
;
525 f
->NewColorMask
= ST_NEW_BLEND
;
526 f
->NewDepth
= ST_NEW_DSA
;
527 f
->NewLogicOp
= ST_NEW_BLEND
;
528 f
->NewStencil
= ST_NEW_DSA
;
529 f
->NewMultisampleEnable
= ST_NEW_BLEND
| ST_NEW_RASTERIZER
|
530 ST_NEW_SAMPLE_MASK
| ST_NEW_SAMPLE_SHADING
;
531 f
->NewSampleAlphaToXEnable
= ST_NEW_BLEND
;
532 f
->NewSampleMask
= ST_NEW_SAMPLE_MASK
;
533 f
->NewSampleShading
= ST_NEW_SAMPLE_SHADING
;
535 /* This depends on what the gallium driver wants. */
536 if (st
->force_persample_in_shader
) {
537 f
->NewMultisampleEnable
|= ST_NEW_FS_STATE
;
538 f
->NewSampleShading
|= ST_NEW_FS_STATE
;
540 f
->NewSampleShading
|= ST_NEW_RASTERIZER
;
543 f
->NewClipControl
= ST_NEW_VIEWPORT
| ST_NEW_RASTERIZER
;
544 f
->NewClipPlane
= ST_NEW_CLIP_STATE
;
545 f
->NewClipPlaneEnable
= ST_NEW_RASTERIZER
;
546 f
->NewDepthClamp
= ST_NEW_RASTERIZER
;
547 f
->NewLineState
= ST_NEW_RASTERIZER
;
548 f
->NewPolygonState
= ST_NEW_RASTERIZER
;
549 f
->NewPolygonStipple
= ST_NEW_POLY_STIPPLE
;
550 f
->NewViewport
= ST_NEW_VIEWPORT
;
553 struct st_context
*st_create_context(gl_api api
, struct pipe_context
*pipe
,
554 const struct gl_config
*visual
,
555 struct st_context
*share
,
556 const struct st_config_options
*options
,
559 struct gl_context
*ctx
;
560 struct gl_context
*shareCtx
= share
? share
->ctx
: NULL
;
561 struct dd_function_table funcs
;
562 struct st_context
*st
;
564 memset(&funcs
, 0, sizeof(funcs
));
565 st_init_driver_functions(pipe
->screen
, &funcs
);
567 ctx
= calloc(1, sizeof(struct gl_context
));
571 if (!_mesa_initialize_context(ctx
, api
, visual
, shareCtx
, &funcs
)) {
578 if (pipe
->screen
->get_disk_shader_cache
&&
579 !(ST_DEBUG
& DEBUG_TGSI
))
580 ctx
->Cache
= pipe
->screen
->get_disk_shader_cache(pipe
->screen
);
582 /* XXX: need a capability bit in gallium to query if the pipe
583 * driver prefers DP4 or MUL/MAD for vertex transformation.
585 if (debug_get_option_mesa_mvp_dp4())
586 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].OptimizeForAOS
= GL_TRUE
;
588 st
= st_create_context_priv(ctx
, pipe
, options
, no_error
);
590 _mesa_destroy_context(ctx
);
598 * Callback to release the sampler view attached to a texture object.
599 * Called by _mesa_HashWalk().
602 destroy_tex_sampler_cb(GLuint id
, void *data
, void *userData
)
604 struct gl_texture_object
*texObj
= (struct gl_texture_object
*) data
;
605 struct st_context
*st
= (struct st_context
*) userData
;
607 st_texture_release_sampler_view(st
, st_texture_object(texObj
));
610 void st_destroy_context( struct st_context
*st
)
612 struct gl_context
*ctx
= st
->ctx
;
613 struct st_framebuffer
*stfb
, *next
;
615 GET_CURRENT_CONTEXT(curctx
);
616 if (curctx
== NULL
) {
618 /* No current context, but we need one to release
619 * renderbuffer surface when we release framebuffer.
620 * So temporarily bind the context.
622 _mesa_make_current(ctx
, NULL
, NULL
);
625 /* This must be called first so that glthread has a chance to finish */
626 _mesa_glthread_destroy(ctx
);
628 _mesa_HashWalk(ctx
->Shared
->TexObjects
, destroy_tex_sampler_cb
, st
);
630 st_reference_fragprog(st
, &st
->fp
, NULL
);
631 st_reference_prog(st
, &st
->gp
, NULL
);
632 st_reference_vertprog(st
, &st
->vp
, NULL
);
633 st_reference_prog(st
, &st
->tcp
, NULL
);
634 st_reference_prog(st
, &st
->tep
, NULL
);
635 st_reference_compprog(st
, &st
->cp
, NULL
);
637 /* release framebuffer in the winsys buffers list */
638 LIST_FOR_EACH_ENTRY_SAFE_REV(stfb
, next
, &st
->winsys_buffers
, head
) {
639 st_framebuffer_reference(&stfb
, NULL
);
642 pipe_sampler_view_reference(&st
->pixel_xfer
.pixelmap_sampler_view
, NULL
);
643 pipe_resource_reference(&st
->pixel_xfer
.pixelmap_texture
, NULL
);
645 _vbo_DestroyContext(ctx
);
647 st_destroy_program_variants(st
);
649 _mesa_free_context_data(ctx
);
651 /* This will free the st_context too, so 'st' must not be accessed
653 st_destroy_context_priv(st
, true);
660 st_emit_string_marker(struct gl_context
*ctx
, const GLchar
*string
, GLsizei len
)
662 struct st_context
*st
= ctx
->st
;
663 st
->pipe
->emit_string_marker(st
->pipe
, string
, len
);
667 st_set_background_context(struct gl_context
*ctx
,
668 struct util_queue_monitoring
*queue_info
)
670 struct st_context
*st
= ctx
->st
;
671 struct st_manager
*smapi
=
672 (struct st_manager
*)st
->iface
.st_context_private
;
674 assert(smapi
->set_background_context
);
675 smapi
->set_background_context(&st
->iface
, queue_info
);
679 st_get_device_uuid(struct gl_context
*ctx
, char *uuid
)
681 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
683 assert(GL_UUID_SIZE_EXT
>= PIPE_UUID_SIZE
);
684 memset(uuid
, 0, GL_UUID_SIZE_EXT
);
685 screen
->get_device_uuid(screen
, uuid
);
689 st_get_driver_uuid(struct gl_context
*ctx
, char *uuid
)
691 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
693 assert(GL_UUID_SIZE_EXT
>= PIPE_UUID_SIZE
);
694 memset(uuid
, 0, GL_UUID_SIZE_EXT
);
695 screen
->get_driver_uuid(screen
, uuid
);
698 void st_init_driver_functions(struct pipe_screen
*screen
,
699 struct dd_function_table
*functions
)
701 _mesa_init_shader_object_functions(functions
);
702 _mesa_init_sampler_object_functions(functions
);
704 st_init_blit_functions(functions
);
705 st_init_bufferobject_functions(screen
, functions
);
706 st_init_clear_functions(functions
);
707 st_init_bitmap_functions(functions
);
708 st_init_copy_image_functions(functions
);
709 st_init_drawpixels_functions(functions
);
710 st_init_rasterpos_functions(functions
);
712 st_init_drawtex_functions(functions
);
714 st_init_eglimage_functions(functions
);
716 st_init_fbo_functions(functions
);
717 st_init_feedback_functions(functions
);
718 st_init_memoryobject_functions(functions
);
719 st_init_msaa_functions(functions
);
720 st_init_perfmon_functions(functions
);
721 st_init_program_functions(functions
);
722 st_init_query_functions(functions
);
723 st_init_cond_render_functions(functions
);
724 st_init_readpixels_functions(functions
);
725 st_init_texture_functions(functions
);
726 st_init_texture_barrier_functions(functions
);
727 st_init_flush_functions(screen
, functions
);
728 st_init_string_functions(functions
);
729 st_init_viewport_functions(functions
);
730 st_init_compute_functions(functions
);
732 st_init_xformfb_functions(functions
);
733 st_init_syncobj_functions(functions
);
735 st_init_vdpau_functions(functions
);
737 if (screen
->get_param(screen
, PIPE_CAP_STRING_MARKER
))
738 functions
->EmitStringMarker
= st_emit_string_marker
;
740 functions
->Enable
= st_Enable
;
741 functions
->UpdateState
= st_invalidate_state
;
742 functions
->QueryMemoryInfo
= st_query_memory_info
;
743 functions
->SetBackgroundContext
= st_set_background_context
;
744 functions
->GetDriverUuid
= st_get_device_uuid
;
745 functions
->GetDeviceUuid
= st_get_driver_uuid
;