Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2007 VMware, Inc. |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 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. |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 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 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 28 | #include "main/imports.h" |
Brian Paul | 122c676 | 2011-12-03 10:04:18 -0700 | [diff] [blame] | 29 | #include "main/accum.h" |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 30 | #include "main/api_exec.h" |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 31 | #include "main/context.h" |
Brian Paul | 34a5d3b | 2011-04-10 12:48:28 -0600 | [diff] [blame] | 32 | #include "main/samplerobj.h" |
Brian Paul | a37b221 | 2010-06-10 20:23:03 -0600 | [diff] [blame] | 33 | #include "main/shaderobj.h" |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 34 | #include "main/version.h" |
| 35 | #include "main/vtxfmt.h" |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 36 | #include "main/hash.h" |
Vinson Lee | 9c98e9e | 2010-08-04 21:17:13 -0700 | [diff] [blame] | 37 | #include "program/prog_cache.h" |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 38 | #include "vbo/vbo.h" |
Brian Paul | 5ebd849 | 2008-06-17 14:27:36 -0600 | [diff] [blame] | 39 | #include "glapi/glapi.h" |
Chia-I Wu | de8a879 | 2010-02-07 19:20:52 +0800 | [diff] [blame] | 40 | #include "st_context.h" |
Keith Whitwell | b02ef74 | 2009-10-05 15:50:11 +0100 | [diff] [blame] | 41 | #include "st_debug.h" |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 42 | #include "st_cb_bitmap.h" |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 43 | #include "st_cb_blit.h" |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 44 | #include "st_cb_bufferobjects.h" |
Brian | 51b300c | 2007-08-02 10:29:50 -0600 | [diff] [blame] | 45 | #include "st_cb_clear.h" |
Brian Paul | c9b5583 | 2009-12-31 14:47:21 -0700 | [diff] [blame] | 46 | #include "st_cb_condrender.h" |
Marek Olšák | f04f136 | 2015-08-24 02:55:20 +0200 | [diff] [blame] | 47 | #include "st_cb_copyimage.h" |
Brian | 184b6a1 | 2007-08-02 14:21:16 -0600 | [diff] [blame] | 48 | #include "st_cb_drawpixels.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 49 | #include "st_cb_rasterpos.h" |
Brian Paul | 4424c66 | 2008-08-12 18:02:44 -0600 | [diff] [blame] | 50 | #include "st_cb_drawtex.h" |
Chia-I Wu | a1aa53b | 2010-02-25 23:10:47 +0800 | [diff] [blame] | 51 | #include "st_cb_eglimage.h" |
Brian | 64da751 | 2007-08-09 12:27:44 -0600 | [diff] [blame] | 52 | #include "st_cb_fbo.h" |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 53 | #include "st_cb_feedback.h" |
Dave Airlie | 1d90ee5 | 2013-03-04 06:14:18 +1000 | [diff] [blame] | 54 | #include "st_cb_msaa.h" |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 55 | #include "st_cb_perfmon.h" |
Brian Paul | 22a3d02 | 2008-03-24 11:55:29 -0600 | [diff] [blame] | 56 | #include "st_cb_program.h" |
Brian | 2486474 | 2007-08-11 19:57:37 +0100 | [diff] [blame] | 57 | #include "st_cb_queryobj.h" |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 58 | #include "st_cb_readpixels.h" |
Brian | 4435bae | 2007-08-06 15:49:11 -0600 | [diff] [blame] | 59 | #include "st_cb_texture.h" |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 60 | #include "st_cb_xformfb.h" |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 61 | #include "st_cb_flush.h" |
Marek Olšák | 5257a6d | 2011-03-05 20:32:28 +0100 | [diff] [blame] | 62 | #include "st_cb_syncobj.h" |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 63 | #include "st_cb_strings.h" |
Marek Olšák | aea4ed4 | 2011-03-08 11:32:35 +0100 | [diff] [blame] | 64 | #include "st_cb_texturebarrier.h" |
Jakob Bornecrantz | a93f9f3 | 2010-05-21 20:37:23 +0100 | [diff] [blame] | 65 | #include "st_cb_viewport.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 66 | #include "st_atom.h" |
| 67 | #include "st_draw.h" |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 68 | #include "st_extensions.h" |
Brian | 62abcb9 | 2008-02-08 14:54:18 -0700 | [diff] [blame] | 69 | #include "st_gen_mipmap.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 70 | #include "st_program.h" |
Christian König | 8096422 | 2013-05-15 15:10:11 +0200 | [diff] [blame] | 71 | #include "st_vdpau.h" |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 72 | #include "st_texture.h" |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 73 | #include "pipe/p_context.h" |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 74 | #include "util/u_inlines.h" |
Marek Olšák | 76d9a99 | 2012-04-13 19:27:45 +0200 | [diff] [blame] | 75 | #include "util/u_upload_mgr.h" |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 76 | #include "cso_cache/cso_context.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 77 | |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 78 | |
Brian Paul | 6b97fe5 | 2010-08-06 15:09:51 -0600 | [diff] [blame] | 79 | DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE) |
Jakob Bornecrantz | 99611f0 | 2010-08-05 17:13:41 -0700 | [diff] [blame] | 80 | |
| 81 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 82 | /** |
| 83 | * Called via ctx->Driver.UpdateState() |
| 84 | */ |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 85 | void st_invalidate_state(struct gl_context * ctx, GLuint new_state) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 86 | { |
| 87 | struct st_context *st = st_context(ctx); |
| 88 | |
Marek Olšák | bc1c836 | 2012-01-23 03:11:17 +0100 | [diff] [blame] | 89 | /* Replace _NEW_FRAG_CLAMP with ST_NEW_FRAGMENT_PROGRAM for the fallback. */ |
| 90 | if (st->clamp_frag_color_in_shader && (new_state & _NEW_FRAG_CLAMP)) { |
| 91 | new_state &= ~_NEW_FRAG_CLAMP; |
| 92 | st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; |
| 93 | } |
| 94 | |
| 95 | /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */ |
| 96 | if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT)) { |
| 97 | st->dirty.st |= ST_NEW_VERTEX_PROGRAM; |
| 98 | } |
| 99 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 100 | st->dirty.mesa |= new_state; |
| 101 | st->dirty.st |= ST_NEW_MESA; |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 102 | |
| 103 | /* This is the only core Mesa module we depend upon. |
| 104 | * No longer use swrast, swsetup, tnl. |
| 105 | */ |
| 106 | _vbo_InvalidateState(ctx, new_state); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 109 | |
| 110 | static void |
| 111 | st_destroy_context_priv(struct st_context *st) |
| 112 | { |
| 113 | uint shader, i; |
| 114 | |
| 115 | st_destroy_atoms( st ); |
| 116 | st_destroy_draw( st ); |
| 117 | st_destroy_clear(st); |
| 118 | st_destroy_bitmap(st); |
| 119 | st_destroy_drawpix(st); |
| 120 | st_destroy_drawtex(st); |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 121 | st_destroy_perfmon(st); |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 122 | |
Brian Paul | 2f0143c | 2015-02-28 09:01:33 -0700 | [diff] [blame] | 123 | for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) { |
| 124 | for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) { |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 125 | pipe_sampler_view_release(st->pipe, |
| 126 | &st->state.sampler_views[shader][i]); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (st->default_texture) { |
| 131 | st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture); |
| 132 | st->default_texture = NULL; |
| 133 | } |
| 134 | |
| 135 | u_upload_destroy(st->uploader); |
| 136 | if (st->indexbuf_uploader) { |
| 137 | u_upload_destroy(st->indexbuf_uploader); |
| 138 | } |
| 139 | if (st->constbuf_uploader) { |
| 140 | u_upload_destroy(st->constbuf_uploader); |
| 141 | } |
Marek Olšák | 0a60ebe | 2014-12-07 14:21:41 +0100 | [diff] [blame] | 142 | |
| 143 | cso_destroy_context(st->cso_context); |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 144 | free( st ); |
| 145 | } |
| 146 | |
| 147 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 148 | static struct st_context * |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 149 | st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, |
| 150 | const struct st_config_options *options) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 151 | { |
Marek Olšák | 8c655f4 | 2012-04-24 17:04:18 +0200 | [diff] [blame] | 152 | struct pipe_screen *screen = pipe->screen; |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 153 | uint i; |
Brian Paul | f1a59a6 | 2009-02-12 10:14:36 -0700 | [diff] [blame] | 154 | struct st_context *st = ST_CALLOC_STRUCT( st_context ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 155 | |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 156 | st->options = *options; |
| 157 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 158 | ctx->st = st; |
| 159 | |
| 160 | st->ctx = ctx; |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 161 | st->pipe = pipe; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 162 | |
Keith Whitwell | b02ef74 | 2009-10-05 15:50:11 +0100 | [diff] [blame] | 163 | /* XXX: this is one-off, per-screen init: */ |
| 164 | st_debug_init(); |
| 165 | |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 166 | /* state tracker needs the VBO module */ |
| 167 | _vbo_CreateContext(ctx); |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 168 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 169 | st->dirty.mesa = ~0; |
| 170 | st->dirty.st = ~0; |
| 171 | |
Brian Paul | 282bb87 | 2013-10-17 09:28:17 -0600 | [diff] [blame] | 172 | /* Create upload manager for vertex data for glBitmap, glDrawPixels, |
| 173 | * glClear, etc. |
| 174 | */ |
Marek Olšák | 76d9a99 | 2012-04-13 19:27:45 +0200 | [diff] [blame] | 175 | st->uploader = u_upload_create(st->pipe, 65536, 4, PIPE_BIND_VERTEX_BUFFER); |
Marek Olšák | 8c655f4 | 2012-04-24 17:04:18 +0200 | [diff] [blame] | 176 | |
| 177 | if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { |
| 178 | st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, 4, |
| 179 | PIPE_BIND_INDEX_BUFFER); |
| 180 | } |
| 181 | |
Marek Olšák | 7a05459 | 2012-04-24 20:16:50 +0200 | [diff] [blame] | 182 | if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) { |
| 183 | unsigned alignment = |
| 184 | screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT); |
| 185 | |
| 186 | st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, alignment, |
| 187 | PIPE_BIND_CONSTANT_BUFFER); |
| 188 | } |
| 189 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 190 | st->cso_context = cso_create_context(pipe); |
Zack Rusin | 9780327 | 2007-09-14 04:08:58 -0400 | [diff] [blame] | 191 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 192 | st_init_atoms( st ); |
Brian | c62b197 | 2008-03-28 14:53:47 -0600 | [diff] [blame] | 193 | st_init_bitmap(st); |
Brian Paul | ce5c867 | 2008-04-03 12:54:32 -0600 | [diff] [blame] | 194 | st_init_clear(st); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 195 | st_init_draw( st ); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 196 | |
Brian Paul | 282bb87 | 2013-10-17 09:28:17 -0600 | [diff] [blame] | 197 | /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */ |
| 198 | if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) |
Luca Barbieri | 3070e0e | 2010-08-06 07:39:21 +0200 | [diff] [blame] | 199 | st->internal_target = PIPE_TEXTURE_2D; |
| 200 | else |
| 201 | st->internal_target = PIPE_TEXTURE_RECT; |
| 202 | |
Brian Paul | 84e5cb3 | 2012-08-17 14:33:31 -0600 | [diff] [blame] | 203 | /* Vertex element objects used for drawing rectangles for glBitmap, |
| 204 | * glDrawPixels, glClear, etc. |
| 205 | */ |
Brian Paul | 2f0143c | 2015-02-28 09:01:33 -0700 | [diff] [blame] | 206 | for (i = 0; i < ARRAY_SIZE(st->velems_util_draw); i++) { |
Roland Scheidegger | ae7b7bf | 2010-03-09 15:09:01 +0100 | [diff] [blame] | 207 | memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); |
| 208 | st->velems_util_draw[i].src_offset = i * 4 * sizeof(float); |
| 209 | st->velems_util_draw[i].instance_divisor = 0; |
Marek Olšák | e73bf3b | 2012-03-29 17:51:50 +0200 | [diff] [blame] | 210 | st->velems_util_draw[i].vertex_buffer_index = |
| 211 | cso_get_aux_vertex_buffer_slot(st->cso_context); |
Roland Scheidegger | ae7b7bf | 2010-03-09 15:09:01 +0100 | [diff] [blame] | 212 | st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; |
| 213 | } |
| 214 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 215 | /* we want all vertex data to be placed in buffer objects */ |
| 216 | vbo_use_buffer_objects(ctx); |
| 217 | |
Brian Paul | 2997b45 | 2011-10-25 17:41:12 -0600 | [diff] [blame] | 218 | |
| 219 | /* make sure that no VBOs are left mapped when we're drawing. */ |
| 220 | vbo_always_unmap_buffers(ctx); |
| 221 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 222 | /* Need these flags: |
| 223 | */ |
| 224 | st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 225 | |
Brian | e3bdd66 | 2007-08-16 17:33:49 -0600 | [diff] [blame] | 226 | st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; |
| 227 | |
Marek Olšák | 5ba15d8 | 2012-07-09 05:08:36 +0200 | [diff] [blame] | 228 | st->has_stencil_export = |
| 229 | screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT); |
Marek Olšák | 4362bda | 2013-01-31 22:30:44 +0100 | [diff] [blame] | 230 | st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3); |
Marek Olšák | 0127d26 | 2014-08-02 21:38:25 +0200 | [diff] [blame] | 231 | st->has_etc1 = screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8, |
| 232 | PIPE_TEXTURE_2D, 0, |
| 233 | PIPE_BIND_SAMPLER_VIEW); |
Ilia Mirkin | 33edda7 | 2015-02-16 02:27:37 -0500 | [diff] [blame] | 234 | st->has_etc2 = screen->is_format_supported(screen, PIPE_FORMAT_ETC2_RGB8, |
| 235 | PIPE_TEXTURE_2D, 0, |
| 236 | PIPE_BIND_SAMPLER_VIEW); |
Marek Olšák | 3e10ab6 | 2013-03-14 17:18:43 +0100 | [diff] [blame] | 237 | st->prefer_blit_based_texture_transfer = screen->get_param(screen, |
| 238 | PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); |
Marek Olšák | b99645f | 2015-10-20 00:12:53 +0200 | [diff] [blame] | 239 | st->force_persample_in_shader = |
| 240 | screen->get_param(screen, PIPE_CAP_SAMPLE_SHADING) && |
| 241 | !screen->get_param(screen, PIPE_CAP_FORCE_PERSAMPLE_INTERP); |
Marek Olšák | f4e938e | 2015-09-27 23:36:59 +0200 | [diff] [blame] | 242 | st->has_shareable_shaders = screen->get_param(screen, |
| 243 | PIPE_CAP_SHAREABLE_SHADERS); |
Christoph Bumiller | 8acaf86 | 2013-03-15 22:11:31 +0100 | [diff] [blame] | 244 | st->needs_texcoord_semantic = |
| 245 | screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD); |
Christoph Bumiller | 729abfd | 2013-04-12 13:42:01 +0200 | [diff] [blame] | 246 | st->apply_texture_swizzle_to_border_color = |
| 247 | !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & |
| 248 | (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 | |
| 249 | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600)); |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 250 | st->has_time_elapsed = |
| 251 | screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED); |
Christoph Bumiller | 8acaf86 | 2013-03-15 22:11:31 +0100 | [diff] [blame] | 252 | |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 253 | /* GL limits and extensions */ |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 254 | st_init_limits(st->pipe->screen, &ctx->Const, &ctx->Extensions); |
Marek Olšák | 4155d1c | 2014-09-12 16:41:19 +0200 | [diff] [blame] | 255 | st_init_extensions(st->pipe->screen, &ctx->Const, |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 256 | &ctx->Extensions, &st->options, ctx->Mesa_DXTn); |
| 257 | |
Nicolai Hähnle | babf655 | 2015-11-25 12:19:03 +0100 | [diff] [blame^] | 258 | if (st_have_perfmon(st)) { |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 259 | /* GL_AMD_performance_monitor is only enabled when the underlying |
| 260 | * driver expose GPU hardware performance counters. */ |
| 261 | ctx->Extensions.AMD_performance_monitor = GL_TRUE; |
| 262 | } |
| 263 | |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 264 | /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */ |
| 265 | if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) { |
| 266 | if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) { |
| 267 | st->clamp_vert_color_in_shader = GL_TRUE; |
| 268 | } |
| 269 | |
| 270 | if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) { |
| 271 | st->clamp_frag_color_in_shader = GL_TRUE; |
| 272 | } |
| 273 | |
| 274 | /* For drivers which cannot do color clamping, it's better to just |
| 275 | * disable ARB_color_buffer_float in the core profile, because |
| 276 | * the clamping is deprecated there anyway. */ |
| 277 | if (ctx->API == API_OPENGL_CORE && |
| 278 | (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) { |
| 279 | st->clamp_vert_color_in_shader = GL_FALSE; |
| 280 | st->clamp_frag_color_in_shader = GL_FALSE; |
| 281 | ctx->Extensions.ARB_color_buffer_float = GL_FALSE; |
| 282 | } |
| 283 | } |
Brian | af3d6c8 | 2007-08-21 20:15:00 -0600 | [diff] [blame] | 284 | |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 285 | /* called after _mesa_create_context/_mesa_init_point, fix default user |
| 286 | * settable max point size up |
| 287 | */ |
| 288 | st->ctx->Point.MaxSize = MAX2(ctx->Const.MaxPointSize, |
| 289 | ctx->Const.MaxPointSizeAA); |
Abdiel Janulgue | 49e0431 | 2014-12-01 14:59:08 +0200 | [diff] [blame] | 290 | /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */ |
| 291 | ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !st->has_shader_model3; |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 292 | |
Tapani Pälli | f17c8c2 | 2015-06-29 09:48:52 +0300 | [diff] [blame] | 293 | if (!ctx->Extensions.ARB_gpu_shader5) { |
| 294 | for (i = 0; i < MESA_SHADER_STAGES; i++) |
| 295 | ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true; |
| 296 | } |
| 297 | |
Marek Olšák | e57dd7a | 2015-09-28 00:04:39 +0200 | [diff] [blame] | 298 | /* Set which shader types can be compiled at link time. */ |
| 299 | st->shader_has_one_variant[MESA_SHADER_VERTEX] = |
| 300 | st->has_shareable_shaders && |
| 301 | !st->clamp_vert_color_in_shader; |
| 302 | |
| 303 | st->shader_has_one_variant[MESA_SHADER_FRAGMENT] = |
| 304 | st->has_shareable_shaders && |
| 305 | !st->clamp_frag_color_in_shader && |
| 306 | !st->force_persample_in_shader; |
| 307 | |
| 308 | st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders; |
| 309 | st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders; |
| 310 | st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders; |
| 311 | |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 312 | _mesa_compute_version(ctx); |
| 313 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 314 | if (ctx->Version == 0) { |
| 315 | /* This can happen when a core profile was requested, but the driver |
| 316 | * does not support some features of GL 3.1 or later. |
| 317 | */ |
| 318 | st_destroy_context_priv(st); |
| 319 | return NULL; |
| 320 | } |
| 321 | |
Eric Anholt | be4b166 | 2013-01-17 16:49:57 -0800 | [diff] [blame] | 322 | _mesa_initialize_dispatch_tables(ctx); |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 323 | _mesa_initialize_vbo_vtxfmt(ctx); |
| 324 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 325 | return st; |
| 326 | } |
| 327 | |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 328 | static void st_init_driver_flags(struct gl_driver_flags *f) |
| 329 | { |
| 330 | f->NewArray = ST_NEW_VERTEX_ARRAYS; |
Marek Olšák | 99bd76d | 2013-04-15 13:00:54 +0200 | [diff] [blame] | 331 | f->NewRasterizerDiscard = ST_NEW_RASTERIZER; |
Marek Olšák | 77d8fbc | 2013-04-26 14:21:09 +0200 | [diff] [blame] | 332 | f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER; |
Marek Olšák | bda9094 | 2015-05-18 12:49:10 +0200 | [diff] [blame] | 333 | f->NewDefaultTessLevels = ST_NEW_TESS_STATE; |
Marek Olšák | e39ece0 | 2015-07-24 19:47:06 +0200 | [diff] [blame] | 334 | f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS; |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 335 | } |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 336 | |
Chia-I Wu | 57c6543 | 2010-06-23 17:40:49 +0800 | [diff] [blame] | 337 | struct st_context *st_create_context(gl_api api, struct pipe_context *pipe, |
Kristian Høgsberg | d3491e7 | 2010-10-12 11:58:47 -0400 | [diff] [blame] | 338 | const struct gl_config *visual, |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 339 | struct st_context *share, |
| 340 | const struct st_config_options *options) |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 341 | { |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 342 | struct gl_context *ctx; |
| 343 | struct gl_context *shareCtx = share ? share->ctx : NULL; |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 344 | struct dd_function_table funcs; |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 345 | struct st_context *st; |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 346 | |
| 347 | memset(&funcs, 0, sizeof(funcs)); |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 348 | st_init_driver_functions(pipe->screen, &funcs); |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 349 | |
Brian Paul | 733dba2 | 2012-09-29 08:47:56 -0600 | [diff] [blame] | 350 | ctx = _mesa_create_context(api, visual, shareCtx, &funcs); |
Emil Velikov | 1ab5e15 | 2011-07-11 15:42:15 +0100 | [diff] [blame] | 351 | if (!ctx) { |
| 352 | return NULL; |
| 353 | } |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 354 | |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 355 | st_init_driver_flags(&ctx->DriverFlags); |
| 356 | |
Keith Whitwell | b6e8256 | 2009-05-05 12:12:28 +0100 | [diff] [blame] | 357 | /* XXX: need a capability bit in gallium to query if the pipe |
| 358 | * driver prefers DP4 or MUL/MAD for vertex transformation. |
| 359 | */ |
Jakob Bornecrantz | 99611f0 | 2010-08-05 17:13:41 -0700 | [diff] [blame] | 360 | if (debug_get_option_mesa_mvp_dp4()) |
Marek Olšák | 002211f | 2014-08-03 04:31:56 +0200 | [diff] [blame] | 361 | ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE; |
Keith Whitwell | b6e8256 | 2009-05-05 12:12:28 +0100 | [diff] [blame] | 362 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 363 | st = st_create_context_priv(ctx, pipe, options); |
| 364 | if (!st) { |
| 365 | _mesa_destroy_context(ctx); |
Brian Paul | 87afc9b | 2008-05-16 16:04:30 -0600 | [diff] [blame] | 366 | } |
| 367 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 368 | return st; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 371 | |
| 372 | /** |
| 373 | * Callback to release the sampler view attached to a texture object. |
| 374 | * Called by _mesa_HashWalk(). |
| 375 | */ |
| 376 | static void |
| 377 | destroy_tex_sampler_cb(GLuint id, void *data, void *userData) |
| 378 | { |
| 379 | struct gl_texture_object *texObj = (struct gl_texture_object *) data; |
| 380 | struct st_context *st = (struct st_context *) userData; |
| 381 | |
| 382 | st_texture_release_sampler_view(st, st_texture_object(texObj)); |
| 383 | } |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 384 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 385 | void st_destroy_context( struct st_context *st ) |
| 386 | { |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 387 | struct pipe_context *pipe = st->pipe; |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 388 | struct gl_context *ctx = st->ctx; |
Brian Paul | f104e4d | 2009-05-11 16:09:39 -0600 | [diff] [blame] | 389 | GLuint i; |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 390 | |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 391 | _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st); |
| 392 | |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 393 | st_reference_fragprog(st, &st->fp, NULL); |
Brian Paul | d102049 | 2014-07-08 16:24:53 -0600 | [diff] [blame] | 394 | st_reference_geomprog(st, &st->gp, NULL); |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 395 | st_reference_vertprog(st, &st->vp, NULL); |
Ilia Mirkin | ba9fb96 | 2014-07-11 22:11:21 -0400 | [diff] [blame] | 396 | st_reference_tesscprog(st, &st->tcp, NULL); |
| 397 | st_reference_tesseprog(st, &st->tep, NULL); |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 398 | |
Brian Paul | f104e4d | 2009-05-11 16:09:39 -0600 | [diff] [blame] | 399 | /* release framebuffer surfaces */ |
| 400 | for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { |
| 401 | pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL); |
| 402 | } |
| 403 | pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL); |
Marek Olšák | f15bb3e | 2015-10-04 02:38:55 +0200 | [diff] [blame] | 404 | pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL); |
| 405 | pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL); |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 406 | |
Brian Paul | 753635f | 2008-09-16 08:51:28 -0600 | [diff] [blame] | 407 | _vbo_DestroyContext(st->ctx); |
| 408 | |
Brian Paul | 3d203b6 | 2010-12-13 17:20:12 -0700 | [diff] [blame] | 409 | st_destroy_program_variants(st); |
| 410 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 411 | _mesa_free_context_data(ctx); |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 412 | |
José Fonseca | 63da1aa | 2012-04-25 11:41:13 +0100 | [diff] [blame] | 413 | /* This will free the st_context too, so 'st' must not be accessed |
| 414 | * afterwards. */ |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 415 | st_destroy_context_priv(st); |
José Fonseca | 63da1aa | 2012-04-25 11:41:13 +0100 | [diff] [blame] | 416 | st = NULL; |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 417 | |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 418 | pipe->destroy( pipe ); |
| 419 | |
Kristian Høgsberg | 32f2fd1 | 2010-02-19 11:58:49 -0500 | [diff] [blame] | 420 | free(ctx); |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 424 | void st_init_driver_functions(struct pipe_screen *screen, |
| 425 | struct dd_function_table *functions) |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 426 | { |
Brian Paul | a37b221 | 2010-06-10 20:23:03 -0600 | [diff] [blame] | 427 | _mesa_init_shader_object_functions(functions); |
Brian Paul | 34a5d3b | 2011-04-10 12:48:28 -0600 | [diff] [blame] | 428 | _mesa_init_sampler_object_functions(functions); |
Brian | 601a9ea | 2007-11-07 08:18:50 -0700 | [diff] [blame] | 429 | |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 430 | st_init_blit_functions(functions); |
Brian | f6cd377 | 2008-03-20 14:50:17 -0600 | [diff] [blame] | 431 | st_init_bufferobject_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 432 | st_init_clear_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 433 | st_init_bitmap_functions(functions); |
Marek Olšák | f04f136 | 2015-08-24 02:55:20 +0200 | [diff] [blame] | 434 | st_init_copy_image_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 435 | st_init_drawpixels_functions(functions); |
Brian | bee148c | 2007-09-10 16:28:27 -0600 | [diff] [blame] | 436 | st_init_rasterpos_functions(functions); |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 437 | |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 438 | st_init_drawtex_functions(functions); |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 439 | |
Chia-I Wu | a1aa53b | 2010-02-25 23:10:47 +0800 | [diff] [blame] | 440 | st_init_eglimage_functions(functions); |
| 441 | |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 442 | st_init_fbo_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 443 | st_init_feedback_functions(functions); |
Dave Airlie | 1d90ee5 | 2013-03-04 06:14:18 +1000 | [diff] [blame] | 444 | st_init_msaa_functions(functions); |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 445 | st_init_perfmon_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 446 | st_init_program_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 447 | st_init_query_functions(functions); |
Brian Paul | c9b5583 | 2009-12-31 14:47:21 -0700 | [diff] [blame] | 448 | st_init_cond_render_functions(functions); |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 449 | st_init_readpixels_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 450 | st_init_texture_functions(functions); |
Marek Olšák | aea4ed4 | 2011-03-08 11:32:35 +0100 | [diff] [blame] | 451 | st_init_texture_barrier_functions(functions); |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 452 | st_init_flush_functions(screen, functions); |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 453 | st_init_string_functions(functions); |
Jakob Bornecrantz | a93f9f3 | 2010-05-21 20:37:23 +0100 | [diff] [blame] | 454 | st_init_viewport_functions(functions); |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 455 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 456 | st_init_xformfb_functions(functions); |
Marek Olšák | 5257a6d | 2011-03-05 20:32:28 +0100 | [diff] [blame] | 457 | st_init_syncobj_functions(functions); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 458 | |
Christian König | 8096422 | 2013-05-15 15:10:11 +0200 | [diff] [blame] | 459 | st_init_vdpau_functions(functions); |
| 460 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 461 | functions->UpdateState = st_invalidate_state; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 462 | } |