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_semaphoreobjects.h"
64 #include "st_cb_texture.h"
65 #include "st_cb_xformfb.h"
66 #include "st_cb_flush.h"
67 #include "st_cb_syncobj.h"
68 #include "st_cb_strings.h"
69 #include "st_cb_texturebarrier.h"
70 #include "st_cb_viewport.h"
73 #include "st_extensions.h"
74 #include "st_gen_mipmap.h"
76 #include "st_program.h"
77 #include "st_sampler_view.h"
78 #include "st_shader_cache.h"
80 #include "st_texture.h"
81 #include "pipe/p_context.h"
82 #include "util/u_inlines.h"
83 #include "util/u_upload_mgr.h"
84 #include "util/u_vbuf.h"
85 #include "cso_cache/cso_context.h"
88 DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4
, "MESA_MVP_DP4", FALSE
)
92 * Called via ctx->Driver.Enable()
95 st_Enable(struct gl_context
*ctx
, GLenum cap
, GLboolean state
)
97 struct st_context
*st
= st_context(ctx
);
100 case GL_DEBUG_OUTPUT
:
101 case GL_DEBUG_OUTPUT_SYNCHRONOUS
:
102 st_update_debug_callback(st
);
111 * Called via ctx->Driver.QueryMemoryInfo()
114 st_query_memory_info(struct gl_context
*ctx
, struct gl_memory_info
*out
)
116 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
117 struct pipe_memory_info info
;
119 assert(screen
->query_memory_info
);
120 if (!screen
->query_memory_info
)
123 screen
->query_memory_info(screen
, &info
);
125 out
->total_device_memory
= info
.total_device_memory
;
126 out
->avail_device_memory
= info
.avail_device_memory
;
127 out
->total_staging_memory
= info
.total_staging_memory
;
128 out
->avail_staging_memory
= info
.avail_staging_memory
;
129 out
->device_memory_evicted
= info
.device_memory_evicted
;
130 out
->nr_device_memory_evictions
= info
.nr_device_memory_evictions
;
135 st_get_active_states(struct gl_context
*ctx
)
137 struct st_vertex_program
*vp
=
138 st_vertex_program(ctx
->VertexProgram
._Current
);
139 struct st_common_program
*tcp
=
140 st_common_program(ctx
->TessCtrlProgram
._Current
);
141 struct st_common_program
*tep
=
142 st_common_program(ctx
->TessEvalProgram
._Current
);
143 struct st_common_program
*gp
=
144 st_common_program(ctx
->GeometryProgram
._Current
);
145 struct st_fragment_program
*fp
=
146 st_fragment_program(ctx
->FragmentProgram
._Current
);
147 struct st_compute_program
*cp
=
148 st_compute_program(ctx
->ComputeProgram
._Current
);
149 uint64_t active_shader_states
= 0;
152 active_shader_states
|= vp
->affected_states
;
154 active_shader_states
|= tcp
->affected_states
;
156 active_shader_states
|= tep
->affected_states
;
158 active_shader_states
|= gp
->affected_states
;
160 active_shader_states
|= fp
->affected_states
;
162 active_shader_states
|= cp
->affected_states
;
164 /* Mark non-shader-resource shader states as "always active". */
165 return active_shader_states
| ~ST_ALL_SHADER_RESOURCES
;
170 st_invalidate_buffers(struct st_context
*st
)
172 st
->dirty
|= ST_NEW_BLEND
|
175 ST_NEW_SAMPLE_STATE
|
176 ST_NEW_SAMPLE_SHADING
|
178 ST_NEW_POLY_STIPPLE
|
182 ST_NEW_WINDOW_RECTANGLES
;
187 * Called via ctx->Driver.UpdateState()
190 st_invalidate_state(struct gl_context
*ctx
)
192 GLbitfield new_state
= ctx
->NewState
;
193 struct st_context
*st
= st_context(ctx
);
195 if (new_state
& _NEW_BUFFERS
) {
196 st_invalidate_buffers(st
);
198 /* These set a subset of flags set by _NEW_BUFFERS, so we only have to
199 * check them when _NEW_BUFFERS isn't set.
201 if (new_state
& _NEW_PROGRAM
)
202 st
->dirty
|= ST_NEW_RASTERIZER
;
204 if (new_state
& _NEW_FOG
)
205 st
->dirty
|= ST_NEW_FS_STATE
;
207 if (new_state
& _NEW_FRAG_CLAMP
) {
208 if (st
->clamp_frag_color_in_shader
)
209 st
->dirty
|= ST_NEW_FS_STATE
;
211 st
->dirty
|= ST_NEW_RASTERIZER
;
215 if (new_state
& (_NEW_LIGHT
|
217 st
->dirty
|= ST_NEW_RASTERIZER
;
219 if (new_state
& _NEW_PROJECTION
&&
220 st_user_clip_planes_enabled(ctx
))
221 st
->dirty
|= ST_NEW_CLIP_STATE
;
223 if (new_state
& _NEW_PIXEL
)
224 st
->dirty
|= ST_NEW_PIXEL_TRANSFER
;
226 if (new_state
& _NEW_CURRENT_ATTRIB
)
227 st
->dirty
|= ST_NEW_VERTEX_ARRAYS
;
229 /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
230 if (st
->clamp_vert_color_in_shader
&& (new_state
& _NEW_LIGHT
))
231 st
->dirty
|= ST_NEW_VS_STATE
;
233 /* Which shaders are dirty will be determined manually. */
234 if (new_state
& _NEW_PROGRAM
) {
235 st
->gfx_shaders_may_be_dirty
= true;
236 st
->compute_shader_may_be_dirty
= true;
237 /* This will mask out unused shader resources. */
238 st
->active_states
= st_get_active_states(ctx
);
241 if (new_state
& _NEW_TEXTURE_OBJECT
) {
242 st
->dirty
|= st
->active_states
&
243 (ST_NEW_SAMPLER_VIEWS
|
246 if (ctx
->FragmentProgram
._Current
&&
247 ctx
->FragmentProgram
._Current
->ExternalSamplersUsed
) {
248 st
->dirty
|= ST_NEW_FS_STATE
;
255 st_destroy_context_priv(struct st_context
*st
, bool destroy_pipe
)
259 st_destroy_atoms(st
);
261 st_destroy_clear(st
);
262 st_destroy_bitmap(st
);
263 st_destroy_drawpix(st
);
264 st_destroy_drawtex(st
);
265 st_destroy_perfmon(st
);
266 st_destroy_pbo_helpers(st
);
267 st_destroy_bound_texture_handles(st
);
268 st_destroy_bound_image_handles(st
);
270 for (i
= 0; i
< ARRAY_SIZE(st
->state
.frag_sampler_views
); i
++) {
271 pipe_sampler_view_release(st
->pipe
,
272 &st
->state
.frag_sampler_views
[i
]);
275 /* free glReadPixels cache data */
276 st_invalidate_readpix_cache(st
);
278 cso_destroy_context(st
->cso_context
);
280 if (st
->pipe
&& destroy_pipe
)
281 st
->pipe
->destroy(st
->pipe
);
288 st_init_driver_flags(struct st_context
*st
)
290 struct gl_driver_flags
*f
= &st
->ctx
->DriverFlags
;
292 f
->NewArray
= ST_NEW_VERTEX_ARRAYS
;
293 f
->NewRasterizerDiscard
= ST_NEW_RASTERIZER
;
294 f
->NewTileRasterOrder
= ST_NEW_RASTERIZER
;
295 f
->NewUniformBuffer
= ST_NEW_UNIFORM_BUFFER
;
296 f
->NewDefaultTessLevels
= ST_NEW_TESS_STATE
;
298 /* Shader resources */
299 f
->NewTextureBuffer
= ST_NEW_SAMPLER_VIEWS
;
300 if (st
->has_hw_atomics
)
301 f
->NewAtomicBuffer
= ST_NEW_HW_ATOMICS
| ST_NEW_CS_ATOMICS
;
303 f
->NewAtomicBuffer
= ST_NEW_ATOMIC_BUFFER
;
304 f
->NewShaderStorageBuffer
= ST_NEW_STORAGE_BUFFER
;
305 f
->NewImageUnits
= ST_NEW_IMAGE_UNITS
;
307 f
->NewShaderConstants
[MESA_SHADER_VERTEX
] = ST_NEW_VS_CONSTANTS
;
308 f
->NewShaderConstants
[MESA_SHADER_TESS_CTRL
] = ST_NEW_TCS_CONSTANTS
;
309 f
->NewShaderConstants
[MESA_SHADER_TESS_EVAL
] = ST_NEW_TES_CONSTANTS
;
310 f
->NewShaderConstants
[MESA_SHADER_GEOMETRY
] = ST_NEW_GS_CONSTANTS
;
311 f
->NewShaderConstants
[MESA_SHADER_FRAGMENT
] = ST_NEW_FS_CONSTANTS
;
312 f
->NewShaderConstants
[MESA_SHADER_COMPUTE
] = ST_NEW_CS_CONSTANTS
;
314 f
->NewWindowRectangles
= ST_NEW_WINDOW_RECTANGLES
;
315 f
->NewFramebufferSRGB
= ST_NEW_FB_STATE
;
316 f
->NewScissorRect
= ST_NEW_SCISSOR
;
317 f
->NewScissorTest
= ST_NEW_SCISSOR
| ST_NEW_RASTERIZER
;
318 f
->NewAlphaTest
= ST_NEW_DSA
;
319 f
->NewBlend
= ST_NEW_BLEND
;
320 f
->NewBlendColor
= ST_NEW_BLEND_COLOR
;
321 f
->NewColorMask
= ST_NEW_BLEND
;
322 f
->NewDepth
= ST_NEW_DSA
;
323 f
->NewLogicOp
= ST_NEW_BLEND
;
324 f
->NewStencil
= ST_NEW_DSA
;
325 f
->NewMultisampleEnable
= ST_NEW_BLEND
| ST_NEW_RASTERIZER
|
326 ST_NEW_SAMPLE_STATE
| ST_NEW_SAMPLE_SHADING
;
327 f
->NewSampleAlphaToXEnable
= ST_NEW_BLEND
;
328 f
->NewSampleMask
= ST_NEW_SAMPLE_STATE
;
329 f
->NewSampleLocations
= ST_NEW_SAMPLE_STATE
;
330 f
->NewSampleShading
= ST_NEW_SAMPLE_SHADING
;
332 /* This depends on what the gallium driver wants. */
333 if (st
->force_persample_in_shader
) {
334 f
->NewMultisampleEnable
|= ST_NEW_FS_STATE
;
335 f
->NewSampleShading
|= ST_NEW_FS_STATE
;
337 f
->NewSampleShading
|= ST_NEW_RASTERIZER
;
340 f
->NewClipControl
= ST_NEW_VIEWPORT
| ST_NEW_RASTERIZER
;
341 f
->NewClipPlane
= ST_NEW_CLIP_STATE
;
342 f
->NewClipPlaneEnable
= ST_NEW_RASTERIZER
;
343 f
->NewDepthClamp
= ST_NEW_RASTERIZER
;
344 f
->NewLineState
= ST_NEW_RASTERIZER
;
345 f
->NewPolygonState
= ST_NEW_RASTERIZER
;
346 f
->NewPolygonStipple
= ST_NEW_POLY_STIPPLE
;
347 f
->NewViewport
= ST_NEW_VIEWPORT
;
348 f
->NewNvConservativeRasterization
= ST_NEW_RASTERIZER
;
349 f
->NewNvConservativeRasterizationParams
= ST_NEW_RASTERIZER
;
353 static struct st_context
*
354 st_create_context_priv(struct gl_context
*ctx
, struct pipe_context
*pipe
,
355 const struct st_config_options
*options
, bool no_error
)
357 struct pipe_screen
*screen
= pipe
->screen
;
359 struct st_context
*st
= ST_CALLOC_STRUCT( st_context
);
361 st
->options
= *options
;
368 /* state tracker needs the VBO module */
369 _vbo_CreateContext(ctx
);
371 st
->dirty
= ST_ALL_STATES_MASK
;
373 st
->can_bind_const_buffer_as_vertex
=
374 screen
->get_param(screen
, PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX
);
376 /* st/mesa always uploads zero-stride vertex attribs, and other user
377 * vertex buffers are only possible with a compatibility profile.
378 * So tell the u_vbuf module that user VBOs are not possible with the Core
379 * profile, so that u_vbuf is bypassed completely if there is nothing else
382 unsigned vbuf_flags
=
383 ctx
->API
== API_OPENGL_CORE
? U_VBUF_FLAG_NO_USER_VBOS
: 0;
384 st
->cso_context
= cso_create_context(pipe
, vbuf_flags
);
388 st_init_pbo_helpers(st
);
390 /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */
391 if (pipe
->screen
->get_param(pipe
->screen
, PIPE_CAP_NPOT_TEXTURES
))
392 st
->internal_target
= PIPE_TEXTURE_2D
;
394 st
->internal_target
= PIPE_TEXTURE_RECT
;
396 /* Setup vertex element info for 'struct st_util_vertex'.
399 STATIC_ASSERT(sizeof(struct st_util_vertex
) == 9 * sizeof(float));
401 memset(&st
->util_velems
, 0, sizeof(st
->util_velems
));
402 st
->util_velems
[0].src_offset
= 0;
403 st
->util_velems
[0].vertex_buffer_index
= 0;
404 st
->util_velems
[0].src_format
= PIPE_FORMAT_R32G32B32_FLOAT
;
405 st
->util_velems
[1].src_offset
= 3 * sizeof(float);
406 st
->util_velems
[1].vertex_buffer_index
= 0;
407 st
->util_velems
[1].src_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
408 st
->util_velems
[2].src_offset
= 7 * sizeof(float);
409 st
->util_velems
[2].vertex_buffer_index
= 0;
410 st
->util_velems
[2].src_format
= PIPE_FORMAT_R32G32_FLOAT
;
413 /* we want all vertex data to be placed in buffer objects */
414 vbo_use_buffer_objects(ctx
);
417 /* make sure that no VBOs are left mapped when we're drawing. */
418 vbo_always_unmap_buffers(ctx
);
422 ctx
->FragmentProgram
._MaintainTexEnvProgram
= GL_TRUE
;
424 ctx
->VertexProgram
._MaintainTnlProgram
= GL_TRUE
;
427 ctx
->Const
.ContextFlags
|= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
;
429 ctx
->Const
.PackedDriverUniformStorage
=
430 screen
->get_param(screen
, PIPE_CAP_PACKED_UNIFORMS
);
432 st
->has_stencil_export
=
433 screen
->get_param(screen
, PIPE_CAP_SHADER_STENCIL_EXPORT
);
434 st
->has_shader_model3
= screen
->get_param(screen
, PIPE_CAP_SM3
);
435 st
->has_etc1
= screen
->is_format_supported(screen
, PIPE_FORMAT_ETC1_RGB8
,
436 PIPE_TEXTURE_2D
, 0, 0,
437 PIPE_BIND_SAMPLER_VIEW
);
438 st
->has_etc2
= screen
->is_format_supported(screen
, PIPE_FORMAT_ETC2_RGB8
,
439 PIPE_TEXTURE_2D
, 0, 0,
440 PIPE_BIND_SAMPLER_VIEW
);
441 st
->has_astc_2d_ldr
=
442 screen
->is_format_supported(screen
, PIPE_FORMAT_ASTC_4x4_SRGB
,
443 PIPE_TEXTURE_2D
, 0, 0, PIPE_BIND_SAMPLER_VIEW
);
444 st
->prefer_blit_based_texture_transfer
= screen
->get_param(screen
,
445 PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER
);
446 st
->force_persample_in_shader
=
447 screen
->get_param(screen
, PIPE_CAP_SAMPLE_SHADING
) &&
448 !screen
->get_param(screen
, PIPE_CAP_FORCE_PERSAMPLE_INTERP
);
449 st
->has_shareable_shaders
= screen
->get_param(screen
,
450 PIPE_CAP_SHAREABLE_SHADERS
);
451 st
->needs_texcoord_semantic
=
452 screen
->get_param(screen
, PIPE_CAP_TGSI_TEXCOORD
);
453 st
->apply_texture_swizzle_to_border_color
=
454 !!(screen
->get_param(screen
, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK
) &
455 (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50
|
456 PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600
));
457 st
->has_time_elapsed
=
458 screen
->get_param(screen
, PIPE_CAP_QUERY_TIME_ELAPSED
);
459 st
->has_half_float_packing
=
460 screen
->get_param(screen
, PIPE_CAP_TGSI_PACK_HALF_FLOAT
);
461 st
->has_multi_draw_indirect
=
462 screen
->get_param(screen
, PIPE_CAP_MULTI_DRAW_INDIRECT
);
465 screen
->get_shader_param(screen
, PIPE_SHADER_FRAGMENT
,
466 PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS
)
469 /* GL limits and extensions */
470 st_init_limits(pipe
->screen
, &ctx
->Const
, &ctx
->Extensions
, ctx
->API
);
471 st_init_extensions(pipe
->screen
, &ctx
->Const
,
472 &ctx
->Extensions
, &st
->options
, ctx
->API
);
474 if (st_have_perfmon(st
)) {
475 ctx
->Extensions
.AMD_performance_monitor
= GL_TRUE
;
478 /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */
479 if (screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_UNCLAMPED
)) {
480 if (!screen
->get_param(screen
, PIPE_CAP_VERTEX_COLOR_CLAMPED
)) {
481 st
->clamp_vert_color_in_shader
= GL_TRUE
;
484 if (!screen
->get_param(screen
, PIPE_CAP_FRAGMENT_COLOR_CLAMPED
)) {
485 st
->clamp_frag_color_in_shader
= GL_TRUE
;
488 /* For drivers which cannot do color clamping, it's better to just
489 * disable ARB_color_buffer_float in the core profile, because
490 * the clamping is deprecated there anyway. */
491 if (ctx
->API
== API_OPENGL_CORE
&&
492 (st
->clamp_frag_color_in_shader
|| st
->clamp_vert_color_in_shader
)) {
493 st
->clamp_vert_color_in_shader
= GL_FALSE
;
494 st
->clamp_frag_color_in_shader
= GL_FALSE
;
495 ctx
->Extensions
.ARB_color_buffer_float
= GL_FALSE
;
499 /* called after _mesa_create_context/_mesa_init_point, fix default user
500 * settable max point size up
502 ctx
->Point
.MaxSize
= MAX2(ctx
->Const
.MaxPointSize
,
503 ctx
->Const
.MaxPointSizeAA
);
504 /* For vertex shaders, make sure not to emit saturate when SM 3.0
507 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].EmitNoSat
=
508 !st
->has_shader_model3
;
510 if (!ctx
->Extensions
.ARB_gpu_shader5
) {
511 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
512 ctx
->Const
.ShaderCompilerOptions
[i
].EmitNoIndirectSampler
= true;
515 /* Set which shader types can be compiled at link time. */
516 st
->shader_has_one_variant
[MESA_SHADER_VERTEX
] =
517 st
->has_shareable_shaders
&&
518 !st
->clamp_vert_color_in_shader
;
520 st
->shader_has_one_variant
[MESA_SHADER_FRAGMENT
] =
521 st
->has_shareable_shaders
&&
522 !st
->clamp_frag_color_in_shader
&&
523 !st
->force_persample_in_shader
;
525 st
->shader_has_one_variant
[MESA_SHADER_TESS_CTRL
] = st
->has_shareable_shaders
;
526 st
->shader_has_one_variant
[MESA_SHADER_TESS_EVAL
] = st
->has_shareable_shaders
;
527 st
->shader_has_one_variant
[MESA_SHADER_GEOMETRY
] = st
->has_shareable_shaders
;
528 st
->shader_has_one_variant
[MESA_SHADER_COMPUTE
] = st
->has_shareable_shaders
;
530 st
->bitmap
.cache
.empty
= true;
532 _mesa_override_extensions(ctx
);
533 _mesa_compute_version(ctx
);
535 if (ctx
->Version
== 0) {
536 /* This can happen when a core profile was requested, but the driver
537 * does not support some features of GL 3.1 or later.
539 st_destroy_context_priv(st
, false);
543 _mesa_initialize_dispatch_tables(ctx
);
544 _mesa_initialize_vbo_vtxfmt(ctx
);
545 st_init_driver_flags(st
);
547 /* Initialize context's winsys buffers list */
548 LIST_INITHEAD(&st
->winsys_buffers
);
555 st_create_context(gl_api api
, struct pipe_context
*pipe
,
556 const struct gl_config
*visual
,
557 struct st_context
*share
,
558 const struct st_config_options
*options
,
561 struct gl_context
*ctx
;
562 struct gl_context
*shareCtx
= share
? share
->ctx
: NULL
;
563 struct dd_function_table funcs
;
564 struct st_context
*st
;
566 memset(&funcs
, 0, sizeof(funcs
));
567 st_init_driver_functions(pipe
->screen
, &funcs
);
569 ctx
= calloc(1, sizeof(struct gl_context
));
573 if (!_mesa_initialize_context(ctx
, api
, visual
, shareCtx
, &funcs
)) {
580 if (pipe
->screen
->get_disk_shader_cache
&&
581 !(ST_DEBUG
& DEBUG_TGSI
))
582 ctx
->Cache
= pipe
->screen
->get_disk_shader_cache(pipe
->screen
);
584 /* XXX: need a capability bit in gallium to query if the pipe
585 * driver prefers DP4 or MUL/MAD for vertex transformation.
587 if (debug_get_option_mesa_mvp_dp4())
588 ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].OptimizeForAOS
= GL_TRUE
;
590 st
= st_create_context_priv(ctx
, pipe
, options
, no_error
);
592 _mesa_destroy_context(ctx
);
600 * Callback to release the sampler view attached to a texture object.
601 * Called by _mesa_HashWalk().
604 destroy_tex_sampler_cb(GLuint id
, void *data
, void *userData
)
606 struct gl_texture_object
*texObj
= (struct gl_texture_object
*) data
;
607 struct st_context
*st
= (struct st_context
*) userData
;
609 st_texture_release_sampler_view(st
, st_texture_object(texObj
));
614 st_destroy_context(struct st_context
*st
)
616 struct gl_context
*ctx
= st
->ctx
;
617 struct st_framebuffer
*stfb
, *next
;
619 GET_CURRENT_CONTEXT(curctx
);
621 if (curctx
== NULL
) {
622 /* No current context, but we need one to release
623 * renderbuffer surface when we release framebuffer.
624 * So temporarily bind the context.
626 _mesa_make_current(ctx
, NULL
, NULL
);
629 /* This must be called first so that glthread has a chance to finish */
630 _mesa_glthread_destroy(ctx
);
632 _mesa_HashWalk(ctx
->Shared
->TexObjects
, destroy_tex_sampler_cb
, st
);
634 st_reference_fragprog(st
, &st
->fp
, NULL
);
635 st_reference_prog(st
, &st
->gp
, NULL
);
636 st_reference_vertprog(st
, &st
->vp
, NULL
);
637 st_reference_prog(st
, &st
->tcp
, NULL
);
638 st_reference_prog(st
, &st
->tep
, NULL
);
639 st_reference_compprog(st
, &st
->cp
, NULL
);
641 /* release framebuffer in the winsys buffers list */
642 LIST_FOR_EACH_ENTRY_SAFE_REV(stfb
, next
, &st
->winsys_buffers
, head
) {
643 st_framebuffer_reference(&stfb
, NULL
);
646 pipe_sampler_view_reference(&st
->pixel_xfer
.pixelmap_sampler_view
, NULL
);
647 pipe_resource_reference(&st
->pixel_xfer
.pixelmap_texture
, NULL
);
649 _vbo_DestroyContext(ctx
);
651 st_destroy_program_variants(st
);
653 _mesa_free_context_data(ctx
);
655 /* This will free the st_context too, so 'st' must not be accessed
657 st_destroy_context_priv(st
, true);
665 st_emit_string_marker(struct gl_context
*ctx
, const GLchar
*string
, GLsizei len
)
667 struct st_context
*st
= ctx
->st
;
668 st
->pipe
->emit_string_marker(st
->pipe
, string
, len
);
673 st_set_background_context(struct gl_context
*ctx
,
674 struct util_queue_monitoring
*queue_info
)
676 struct st_context
*st
= ctx
->st
;
677 struct st_manager
*smapi
=
678 (struct st_manager
*) st
->iface
.st_context_private
;
680 assert(smapi
->set_background_context
);
681 smapi
->set_background_context(&st
->iface
, queue_info
);
686 st_get_device_uuid(struct gl_context
*ctx
, char *uuid
)
688 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
690 assert(GL_UUID_SIZE_EXT
>= PIPE_UUID_SIZE
);
691 memset(uuid
, 0, GL_UUID_SIZE_EXT
);
692 screen
->get_device_uuid(screen
, uuid
);
697 st_get_driver_uuid(struct gl_context
*ctx
, char *uuid
)
699 struct pipe_screen
*screen
= st_context(ctx
)->pipe
->screen
;
701 assert(GL_UUID_SIZE_EXT
>= PIPE_UUID_SIZE
);
702 memset(uuid
, 0, GL_UUID_SIZE_EXT
);
703 screen
->get_driver_uuid(screen
, uuid
);
708 st_init_driver_functions(struct pipe_screen
*screen
,
709 struct dd_function_table
*functions
)
711 _mesa_init_sampler_object_functions(functions
);
713 st_init_draw_functions(functions
);
714 st_init_blit_functions(functions
);
715 st_init_bufferobject_functions(screen
, functions
);
716 st_init_clear_functions(functions
);
717 st_init_bitmap_functions(functions
);
718 st_init_copy_image_functions(functions
);
719 st_init_drawpixels_functions(functions
);
720 st_init_rasterpos_functions(functions
);
722 st_init_drawtex_functions(functions
);
724 st_init_eglimage_functions(functions
);
726 st_init_fbo_functions(functions
);
727 st_init_feedback_functions(functions
);
728 st_init_memoryobject_functions(functions
);
729 st_init_msaa_functions(functions
);
730 st_init_perfmon_functions(functions
);
731 st_init_program_functions(functions
);
732 st_init_query_functions(functions
);
733 st_init_cond_render_functions(functions
);
734 st_init_readpixels_functions(functions
);
735 st_init_semaphoreobject_functions(functions
);
736 st_init_texture_functions(functions
);
737 st_init_texture_barrier_functions(functions
);
738 st_init_flush_functions(screen
, functions
);
739 st_init_string_functions(functions
);
740 st_init_viewport_functions(functions
);
741 st_init_compute_functions(functions
);
743 st_init_xformfb_functions(functions
);
744 st_init_syncobj_functions(functions
);
746 st_init_vdpau_functions(functions
);
748 if (screen
->get_param(screen
, PIPE_CAP_STRING_MARKER
))
749 functions
->EmitStringMarker
= st_emit_string_marker
;
751 functions
->Enable
= st_Enable
;
752 functions
->UpdateState
= st_invalidate_state
;
753 functions
->QueryMemoryInfo
= st_query_memory_info
;
754 functions
->SetBackgroundContext
= st_set_background_context
;
755 functions
->GetDriverUuid
= st_get_driver_uuid
;
756 functions
->GetDeviceUuid
= st_get_device_uuid
;
758 /* GL_ARB_get_program_binary */
759 functions
->GetProgramBinaryDriverSHA1
= st_get_program_binary_driver_sha1
;
761 enum pipe_shader_ir preferred_ir
= (enum pipe_shader_ir
)
762 screen
->get_shader_param(screen
, PIPE_SHADER_VERTEX
,
763 PIPE_SHADER_CAP_PREFERRED_IR
);
764 if (preferred_ir
== PIPE_SHADER_IR_NIR
) {
765 functions
->ShaderCacheSerializeDriverBlob
= st_serialise_nir_program
;
766 functions
->ProgramBinarySerializeDriverBlob
=
767 st_serialise_nir_program_binary
;
768 functions
->ProgramBinaryDeserializeDriverBlob
=
769 st_deserialise_nir_program
;
771 functions
->ShaderCacheSerializeDriverBlob
= st_serialise_tgsi_program
;
772 functions
->ProgramBinarySerializeDriverBlob
=
773 st_serialise_tgsi_program_binary
;
774 functions
->ProgramBinaryDeserializeDriverBlob
=
775 st_deserialise_tgsi_program
;