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" |
Samuel Pitoiset | 8aa6669 | 2016-01-03 15:41:48 +0100 | [diff] [blame] | 46 | #include "st_cb_compute.h" |
Brian Paul | c9b5583 | 2009-12-31 14:47:21 -0700 | [diff] [blame] | 47 | #include "st_cb_condrender.h" |
Marek Olšák | f04f136 | 2015-08-24 02:55:20 +0200 | [diff] [blame] | 48 | #include "st_cb_copyimage.h" |
Brian | 184b6a1 | 2007-08-02 14:21:16 -0600 | [diff] [blame] | 49 | #include "st_cb_drawpixels.h" |
Brian Paul | d7a4d49 | 2008-06-20 08:09:59 -0600 | [diff] [blame] | 50 | #include "st_cb_rasterpos.h" |
Brian Paul | 4424c66 | 2008-08-12 18:02:44 -0600 | [diff] [blame] | 51 | #include "st_cb_drawtex.h" |
Chia-I Wu | a1aa53b | 2010-02-25 23:10:47 +0800 | [diff] [blame] | 52 | #include "st_cb_eglimage.h" |
Brian | 64da751 | 2007-08-09 12:27:44 -0600 | [diff] [blame] | 53 | #include "st_cb_fbo.h" |
Brian | b4bacd1 | 2007-09-17 14:24:11 -0600 | [diff] [blame] | 54 | #include "st_cb_feedback.h" |
Dave Airlie | 1d90ee5 | 2013-03-04 06:14:18 +1000 | [diff] [blame] | 55 | #include "st_cb_msaa.h" |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 56 | #include "st_cb_perfmon.h" |
Brian Paul | 22a3d02 | 2008-03-24 11:55:29 -0600 | [diff] [blame] | 57 | #include "st_cb_program.h" |
Brian | 2486474 | 2007-08-11 19:57:37 +0100 | [diff] [blame] | 58 | #include "st_cb_queryobj.h" |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 59 | #include "st_cb_readpixels.h" |
Brian | 4435bae | 2007-08-06 15:49:11 -0600 | [diff] [blame] | 60 | #include "st_cb_texture.h" |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 61 | #include "st_cb_xformfb.h" |
Keith Whitwell | 5c2c056 | 2007-08-10 12:57:14 +0100 | [diff] [blame] | 62 | #include "st_cb_flush.h" |
Marek Olšák | 5257a6d | 2011-03-05 20:32:28 +0100 | [diff] [blame] | 63 | #include "st_cb_syncobj.h" |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 64 | #include "st_cb_strings.h" |
Marek Olšák | aea4ed4 | 2011-03-08 11:32:35 +0100 | [diff] [blame] | 65 | #include "st_cb_texturebarrier.h" |
Jakob Bornecrantz | a93f9f3 | 2010-05-21 20:37:23 +0100 | [diff] [blame] | 66 | #include "st_cb_viewport.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 67 | #include "st_atom.h" |
| 68 | #include "st_draw.h" |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 69 | #include "st_extensions.h" |
Brian | 62abcb9 | 2008-02-08 14:54:18 -0700 | [diff] [blame] | 70 | #include "st_gen_mipmap.h" |
Nicolai Hähnle | 4ecc32b | 2016-04-25 21:35:10 -0500 | [diff] [blame] | 71 | #include "st_pbo.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 72 | #include "st_program.h" |
Christian König | 8096422 | 2013-05-15 15:10:11 +0200 | [diff] [blame] | 73 | #include "st_vdpau.h" |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 74 | #include "st_texture.h" |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 75 | #include "pipe/p_context.h" |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 76 | #include "util/u_inlines.h" |
Marek Olšák | 76d9a99 | 2012-04-13 19:27:45 +0200 | [diff] [blame] | 77 | #include "util/u_upload_mgr.h" |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 78 | #include "cso_cache/cso_context.h" |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 79 | |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 80 | |
Brian Paul | 6b97fe5 | 2010-08-06 15:09:51 -0600 | [diff] [blame] | 81 | DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE) |
Jakob Bornecrantz | 99611f0 | 2010-08-05 17:13:41 -0700 | [diff] [blame] | 82 | |
| 83 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 84 | /** |
Nicolai Hähnle | 2123bfc | 2016-01-04 17:31:05 -0500 | [diff] [blame] | 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: |
Nicolai Hähnle | 084ca0d | 2016-07-07 09:25:31 +0200 | [diff] [blame] | 93 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 94 | st_update_debug_callback(st); |
Nicolai Hähnle | 2123bfc | 2016-01-04 17:31:05 -0500 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
Marek Olšák | 5f51a24 | 2016-02-02 01:27:55 +0100 | [diff] [blame] | 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 | /** |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 127 | * Called via ctx->Driver.UpdateState() |
| 128 | */ |
Brian Paul | 4cd1bd4 | 2016-01-06 08:33:36 -0700 | [diff] [blame] | 129 | void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 130 | { |
| 131 | struct st_context *st = st_context(ctx); |
| 132 | |
Marek Olšák | c8fe3b9 | 2016-07-17 18:38:38 +0200 | [diff] [blame] | 133 | if (new_state & _NEW_BUFFERS) { |
| 134 | st->dirty |= ST_NEW_DSA | |
| 135 | ST_NEW_FB_STATE | |
| 136 | ST_NEW_SAMPLE_MASK | |
| 137 | ST_NEW_SAMPLE_SHADING | |
| 138 | ST_NEW_FS_STATE | |
| 139 | ST_NEW_POLY_STIPPLE | |
| 140 | ST_NEW_VIEWPORT | |
| 141 | ST_NEW_RASTERIZER | |
| 142 | ST_NEW_SCISSOR | |
| 143 | ST_NEW_WINDOW_RECTANGLES; |
| 144 | } else { |
| 145 | /* These set a subset of flags set by _NEW_BUFFERS, so we only have to |
| 146 | * check them when _NEW_BUFFERS isn't set. |
| 147 | */ |
| 148 | if (new_state & (_NEW_DEPTH | |
| 149 | _NEW_STENCIL)) |
| 150 | st->dirty |= ST_NEW_DSA; |
| 151 | |
| 152 | if (new_state & _NEW_PROGRAM) |
Marek Olšák | c7954b1 | 2016-07-17 20:59:42 +0200 | [diff] [blame^] | 153 | st->dirty |= ST_NEW_RASTERIZER; |
Marek Olšák | c8fe3b9 | 2016-07-17 18:38:38 +0200 | [diff] [blame] | 154 | |
| 155 | if (new_state & _NEW_SCISSOR) |
| 156 | st->dirty |= ST_NEW_RASTERIZER | |
| 157 | ST_NEW_SCISSOR | |
| 158 | ST_NEW_WINDOW_RECTANGLES; |
| 159 | |
| 160 | if (new_state & _NEW_FOG) |
| 161 | st->dirty |= ST_NEW_FS_STATE; |
| 162 | |
| 163 | if (new_state & _NEW_POLYGONSTIPPLE) |
| 164 | st->dirty |= ST_NEW_POLY_STIPPLE; |
| 165 | |
| 166 | if (new_state & _NEW_VIEWPORT) |
| 167 | st->dirty |= ST_NEW_VIEWPORT; |
| 168 | |
| 169 | if (new_state & _NEW_FRAG_CLAMP) { |
| 170 | if (st->clamp_frag_color_in_shader) |
| 171 | st->dirty |= ST_NEW_FS_STATE; |
| 172 | else |
| 173 | st->dirty |= ST_NEW_RASTERIZER; |
| 174 | } |
Marek Olšák | bc1c836 | 2012-01-23 03:11:17 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Marek Olšák | c8fe3b9 | 2016-07-17 18:38:38 +0200 | [diff] [blame] | 177 | if (new_state & _NEW_MULTISAMPLE) { |
| 178 | st->dirty |= ST_NEW_BLEND | |
| 179 | ST_NEW_SAMPLE_MASK | |
| 180 | ST_NEW_SAMPLE_SHADING | |
| 181 | ST_NEW_RASTERIZER | |
| 182 | ST_NEW_FS_STATE; |
| 183 | } else { |
| 184 | /* These set a subset of flags set by _NEW_MULTISAMPLE, so we only |
| 185 | * have to check them when _NEW_MULTISAMPLE isn't set. |
| 186 | */ |
| 187 | if (new_state & (_NEW_LIGHT | |
| 188 | _NEW_LINE | |
| 189 | _NEW_POINT | |
| 190 | _NEW_POLYGON | |
| 191 | _NEW_TRANSFORM)) |
| 192 | st->dirty |= ST_NEW_RASTERIZER; |
| 193 | } |
| 194 | |
| 195 | if (new_state & (_NEW_PROJECTION | |
| 196 | _NEW_TRANSFORM)) |
| 197 | st->dirty |= ST_NEW_CLIP_STATE; |
| 198 | |
| 199 | if (new_state & _NEW_COLOR) |
| 200 | st->dirty |= ST_NEW_BLEND | |
| 201 | ST_NEW_DSA; |
| 202 | |
| 203 | if (new_state & _NEW_PIXEL) |
| 204 | st->dirty |= ST_NEW_PIXEL_TRANSFER; |
| 205 | |
| 206 | if (new_state & _NEW_TEXTURE) |
| 207 | st->dirty |= ST_NEW_SAMPLER_VIEWS | |
| 208 | ST_NEW_SAMPLERS | |
| 209 | ST_NEW_IMAGE_UNITS; |
| 210 | |
| 211 | if (new_state & _NEW_CURRENT_ATTRIB) |
| 212 | st->dirty |= ST_NEW_VERTEX_ARRAYS; |
| 213 | |
| 214 | if (new_state & _NEW_PROGRAM_CONSTANTS) |
| 215 | st->dirty |= ST_NEW_CONSTANTS; |
| 216 | |
Marek Olšák | bc1c836 | 2012-01-23 03:11:17 +0100 | [diff] [blame] | 217 | /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */ |
Marek Olšák | c8fe3b9 | 2016-07-17 18:38:38 +0200 | [diff] [blame] | 218 | if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT)) |
| 219 | st->dirty |= ST_NEW_VS_STATE; |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 220 | |
Marek Olšák | 79dcd69 | 2016-07-17 20:37:58 +0200 | [diff] [blame] | 221 | /* Which shaders are dirty will be determined manually. */ |
| 222 | if (new_state & _NEW_PROGRAM) { |
| 223 | st->gfx_shaders_may_be_dirty = true; |
| 224 | st->compute_shader_may_be_dirty = true; |
| 225 | } |
| 226 | |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 227 | /* This is the only core Mesa module we depend upon. |
| 228 | * No longer use swrast, swsetup, tnl. |
| 229 | */ |
| 230 | _vbo_InvalidateState(ctx, new_state); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 233 | |
| 234 | static void |
| 235 | st_destroy_context_priv(struct st_context *st) |
| 236 | { |
| 237 | uint shader, i; |
| 238 | |
| 239 | st_destroy_atoms( st ); |
| 240 | st_destroy_draw( st ); |
| 241 | st_destroy_clear(st); |
| 242 | st_destroy_bitmap(st); |
| 243 | st_destroy_drawpix(st); |
| 244 | st_destroy_drawtex(st); |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 245 | st_destroy_perfmon(st); |
Nicolai Hähnle | 4ecc32b | 2016-04-25 21:35:10 -0500 | [diff] [blame] | 246 | st_destroy_pbo_helpers(st); |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 247 | |
Brian Paul | 2f0143c | 2015-02-28 09:01:33 -0700 | [diff] [blame] | 248 | for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) { |
| 249 | for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) { |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 250 | pipe_sampler_view_release(st->pipe, |
| 251 | &st->state.sampler_views[shader][i]); |
| 252 | } |
| 253 | } |
| 254 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 255 | u_upload_destroy(st->uploader); |
| 256 | if (st->indexbuf_uploader) { |
| 257 | u_upload_destroy(st->indexbuf_uploader); |
| 258 | } |
| 259 | if (st->constbuf_uploader) { |
| 260 | u_upload_destroy(st->constbuf_uploader); |
| 261 | } |
Marek Olšák | 0a60ebe | 2014-12-07 14:21:41 +0100 | [diff] [blame] | 262 | |
Brian Paul | 44f48fe | 2016-02-19 08:51:51 -0700 | [diff] [blame] | 263 | /* free glDrawPixels cache data */ |
| 264 | free(st->drawpix_cache.image); |
| 265 | pipe_resource_reference(&st->drawpix_cache.texture, NULL); |
| 266 | |
Nicolai Hähnle | 615ba11 | 2016-06-08 13:22:52 +0200 | [diff] [blame] | 267 | /* free glReadPixels cache data */ |
| 268 | st_invalidate_readpix_cache(st); |
| 269 | |
Marek Olšák | 0a60ebe | 2014-12-07 14:21:41 +0100 | [diff] [blame] | 270 | cso_destroy_context(st->cso_context); |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 271 | free( st ); |
| 272 | } |
| 273 | |
| 274 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 275 | static struct st_context * |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 276 | st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, |
| 277 | const struct st_config_options *options) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 278 | { |
Marek Olšák | 8c655f4 | 2012-04-24 17:04:18 +0200 | [diff] [blame] | 279 | struct pipe_screen *screen = pipe->screen; |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 280 | uint i; |
Brian Paul | f1a59a6 | 2009-02-12 10:14:36 -0700 | [diff] [blame] | 281 | struct st_context *st = ST_CALLOC_STRUCT( st_context ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 282 | |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 283 | st->options = *options; |
| 284 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 285 | ctx->st = st; |
| 286 | |
| 287 | st->ctx = ctx; |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 288 | st->pipe = pipe; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 289 | |
Keith Whitwell | b02ef74 | 2009-10-05 15:50:11 +0100 | [diff] [blame] | 290 | /* XXX: this is one-off, per-screen init: */ |
| 291 | st_debug_init(); |
| 292 | |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 293 | /* state tracker needs the VBO module */ |
| 294 | _vbo_CreateContext(ctx); |
Brian | 8984a28 | 2007-10-31 11:35:50 -0600 | [diff] [blame] | 295 | |
Marek Olšák | c8fe3b9 | 2016-07-17 18:38:38 +0200 | [diff] [blame] | 296 | st->dirty = ST_ALL_STATES_MASK; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 297 | |
Brian Paul | 282bb87 | 2013-10-17 09:28:17 -0600 | [diff] [blame] | 298 | /* Create upload manager for vertex data for glBitmap, glDrawPixels, |
| 299 | * glClear, etc. |
| 300 | */ |
Marek Olšák | ecb2da1 | 2015-12-19 17:54:31 +0100 | [diff] [blame] | 301 | st->uploader = u_upload_create(st->pipe, 65536, PIPE_BIND_VERTEX_BUFFER, |
| 302 | PIPE_USAGE_STREAM); |
Marek Olšák | 8c655f4 | 2012-04-24 17:04:18 +0200 | [diff] [blame] | 303 | |
| 304 | if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { |
Marek Olšák | 37d0aea | 2015-12-19 17:43:48 +0100 | [diff] [blame] | 305 | st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, |
Marek Olšák | ecb2da1 | 2015-12-19 17:54:31 +0100 | [diff] [blame] | 306 | PIPE_BIND_INDEX_BUFFER, |
| 307 | PIPE_USAGE_STREAM); |
Marek Olšák | 8c655f4 | 2012-04-24 17:04:18 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Marek Olšák | 37d0aea | 2015-12-19 17:43:48 +0100 | [diff] [blame] | 310 | if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) |
| 311 | st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, |
Marek Olšák | ecb2da1 | 2015-12-19 17:54:31 +0100 | [diff] [blame] | 312 | PIPE_BIND_CONSTANT_BUFFER, |
| 313 | PIPE_USAGE_STREAM); |
Marek Olšák | 7a05459 | 2012-04-24 20:16:50 +0200 | [diff] [blame] | 314 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 315 | st->cso_context = cso_create_context(pipe); |
Zack Rusin | 9780327 | 2007-09-14 04:08:58 -0400 | [diff] [blame] | 316 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 317 | st_init_atoms( st ); |
Brian Paul | ce5c867 | 2008-04-03 12:54:32 -0600 | [diff] [blame] | 318 | st_init_clear(st); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 319 | st_init_draw( st ); |
Nicolai Hähnle | 4ecc32b | 2016-04-25 21:35:10 -0500 | [diff] [blame] | 320 | st_init_pbo_helpers(st); |
Brian | 61d0215 | 2007-08-02 20:40:19 -0600 | [diff] [blame] | 321 | |
Brian Paul | 282bb87 | 2013-10-17 09:28:17 -0600 | [diff] [blame] | 322 | /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */ |
| 323 | if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) |
Luca Barbieri | 3070e0e | 2010-08-06 07:39:21 +0200 | [diff] [blame] | 324 | st->internal_target = PIPE_TEXTURE_2D; |
| 325 | else |
| 326 | st->internal_target = PIPE_TEXTURE_RECT; |
| 327 | |
Brian Paul | b63fe05 | 2016-02-16 10:22:31 -0700 | [diff] [blame] | 328 | /* Setup vertex element info for 'struct st_util_vertex'. |
Brian Paul | 84e5cb3 | 2012-08-17 14:33:31 -0600 | [diff] [blame] | 329 | */ |
Brian Paul | b63fe05 | 2016-02-16 10:22:31 -0700 | [diff] [blame] | 330 | { |
| 331 | const unsigned slot = cso_get_aux_vertex_buffer_slot(st->cso_context); |
| 332 | |
| 333 | /* If this assertion ever fails all state tracker calls to |
| 334 | * cso_get_aux_vertex_buffer_slot() should be audited. This |
| 335 | * particular call would have to be moved to just before each |
| 336 | * drawing call. |
| 337 | */ |
| 338 | assert(slot == 0); |
| 339 | |
| 340 | STATIC_ASSERT(sizeof(struct st_util_vertex) == 9 * sizeof(float)); |
| 341 | |
| 342 | memset(&st->util_velems, 0, sizeof(st->util_velems)); |
| 343 | st->util_velems[0].src_offset = 0; |
| 344 | st->util_velems[0].vertex_buffer_index = slot; |
| 345 | st->util_velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT; |
| 346 | st->util_velems[1].src_offset = 3 * sizeof(float); |
| 347 | st->util_velems[1].vertex_buffer_index = slot; |
| 348 | st->util_velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; |
| 349 | st->util_velems[2].src_offset = 7 * sizeof(float); |
| 350 | st->util_velems[2].vertex_buffer_index = slot; |
| 351 | st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT; |
Roland Scheidegger | ae7b7bf | 2010-03-09 15:09:01 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Brian | 1e6d1ab | 2007-08-17 15:27:18 +0100 | [diff] [blame] | 354 | /* we want all vertex data to be placed in buffer objects */ |
| 355 | vbo_use_buffer_objects(ctx); |
| 356 | |
Brian Paul | 2997b45 | 2011-10-25 17:41:12 -0600 | [diff] [blame] | 357 | |
| 358 | /* make sure that no VBOs are left mapped when we're drawing. */ |
| 359 | vbo_always_unmap_buffers(ctx); |
| 360 | |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 361 | /* Need these flags: |
| 362 | */ |
Brian Paul | a063615 | 2016-02-16 10:22:32 -0700 | [diff] [blame] | 363 | ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 364 | |
Brian Paul | a063615 | 2016-02-16 10:22:32 -0700 | [diff] [blame] | 365 | ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; |
Brian | e3bdd66 | 2007-08-16 17:33:49 -0600 | [diff] [blame] | 366 | |
Marek Olšák | 5ba15d8 | 2012-07-09 05:08:36 +0200 | [diff] [blame] | 367 | st->has_stencil_export = |
| 368 | screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT); |
Marek Olšák | 4362bda | 2013-01-31 22:30:44 +0100 | [diff] [blame] | 369 | st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3); |
Marek Olšák | 0127d26 | 2014-08-02 21:38:25 +0200 | [diff] [blame] | 370 | st->has_etc1 = screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8, |
| 371 | PIPE_TEXTURE_2D, 0, |
| 372 | PIPE_BIND_SAMPLER_VIEW); |
Ilia Mirkin | 33edda7 | 2015-02-16 02:27:37 -0500 | [diff] [blame] | 373 | st->has_etc2 = screen->is_format_supported(screen, PIPE_FORMAT_ETC2_RGB8, |
| 374 | PIPE_TEXTURE_2D, 0, |
| 375 | PIPE_BIND_SAMPLER_VIEW); |
Marek Olšák | 3e10ab6 | 2013-03-14 17:18:43 +0100 | [diff] [blame] | 376 | st->prefer_blit_based_texture_transfer = screen->get_param(screen, |
| 377 | PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); |
Marek Olšák | b99645f | 2015-10-20 00:12:53 +0200 | [diff] [blame] | 378 | st->force_persample_in_shader = |
| 379 | screen->get_param(screen, PIPE_CAP_SAMPLE_SHADING) && |
| 380 | !screen->get_param(screen, PIPE_CAP_FORCE_PERSAMPLE_INTERP); |
Marek Olšák | f4e938e | 2015-09-27 23:36:59 +0200 | [diff] [blame] | 381 | st->has_shareable_shaders = screen->get_param(screen, |
| 382 | PIPE_CAP_SHAREABLE_SHADERS); |
Christoph Bumiller | 8acaf86 | 2013-03-15 22:11:31 +0100 | [diff] [blame] | 383 | st->needs_texcoord_semantic = |
| 384 | screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD); |
Christoph Bumiller | 729abfd | 2013-04-12 13:42:01 +0200 | [diff] [blame] | 385 | st->apply_texture_swizzle_to_border_color = |
| 386 | !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & |
| 387 | (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 | |
| 388 | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600)); |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 389 | st->has_time_elapsed = |
| 390 | screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED); |
Ilia Mirkin | 20dee33 | 2015-10-29 02:52:57 -0400 | [diff] [blame] | 391 | st->has_half_float_packing = |
| 392 | screen->get_param(screen, PIPE_CAP_TGSI_PACK_HALF_FLOAT); |
Ilia Mirkin | 2860f20 | 2015-12-31 14:11:07 -0500 | [diff] [blame] | 393 | st->has_multi_draw_indirect = |
| 394 | screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT); |
Christoph Bumiller | 8acaf86 | 2013-03-15 22:11:31 +0100 | [diff] [blame] | 395 | |
Brian | c6499a7 | 2007-11-05 18:04:30 -0700 | [diff] [blame] | 396 | /* GL limits and extensions */ |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 397 | st_init_limits(st->pipe->screen, &ctx->Const, &ctx->Extensions); |
Marek Olšák | 4155d1c | 2014-09-12 16:41:19 +0200 | [diff] [blame] | 398 | st_init_extensions(st->pipe->screen, &ctx->Const, |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 399 | &ctx->Extensions, &st->options, ctx->Mesa_DXTn); |
| 400 | |
Nicolai Hähnle | babf655 | 2015-11-25 12:19:03 +0100 | [diff] [blame] | 401 | if (st_have_perfmon(st)) { |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 402 | ctx->Extensions.AMD_performance_monitor = GL_TRUE; |
| 403 | } |
| 404 | |
Marek Olšák | 5c69173 | 2014-08-03 04:20:31 +0200 | [diff] [blame] | 405 | /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */ |
| 406 | if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) { |
| 407 | if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) { |
| 408 | st->clamp_vert_color_in_shader = GL_TRUE; |
| 409 | } |
| 410 | |
| 411 | if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) { |
| 412 | st->clamp_frag_color_in_shader = GL_TRUE; |
| 413 | } |
| 414 | |
| 415 | /* For drivers which cannot do color clamping, it's better to just |
| 416 | * disable ARB_color_buffer_float in the core profile, because |
| 417 | * the clamping is deprecated there anyway. */ |
| 418 | if (ctx->API == API_OPENGL_CORE && |
| 419 | (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) { |
| 420 | st->clamp_vert_color_in_shader = GL_FALSE; |
| 421 | st->clamp_frag_color_in_shader = GL_FALSE; |
| 422 | ctx->Extensions.ARB_color_buffer_float = GL_FALSE; |
| 423 | } |
| 424 | } |
Brian | af3d6c8 | 2007-08-21 20:15:00 -0600 | [diff] [blame] | 425 | |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 426 | /* called after _mesa_create_context/_mesa_init_point, fix default user |
| 427 | * settable max point size up |
| 428 | */ |
Brian Paul | a063615 | 2016-02-16 10:22:32 -0700 | [diff] [blame] | 429 | ctx->Point.MaxSize = MAX2(ctx->Const.MaxPointSize, |
| 430 | ctx->Const.MaxPointSizeAA); |
Abdiel Janulgue | 49e0431 | 2014-12-01 14:59:08 +0200 | [diff] [blame] | 431 | /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */ |
| 432 | ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !st->has_shader_model3; |
Marek Olšák | 35e755f | 2014-08-03 04:36:19 +0200 | [diff] [blame] | 433 | |
Tapani Pälli | f17c8c2 | 2015-06-29 09:48:52 +0300 | [diff] [blame] | 434 | if (!ctx->Extensions.ARB_gpu_shader5) { |
| 435 | for (i = 0; i < MESA_SHADER_STAGES; i++) |
| 436 | ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true; |
| 437 | } |
| 438 | |
Marek Olšák | e57dd7a | 2015-09-28 00:04:39 +0200 | [diff] [blame] | 439 | /* Set which shader types can be compiled at link time. */ |
| 440 | st->shader_has_one_variant[MESA_SHADER_VERTEX] = |
| 441 | st->has_shareable_shaders && |
| 442 | !st->clamp_vert_color_in_shader; |
| 443 | |
| 444 | st->shader_has_one_variant[MESA_SHADER_FRAGMENT] = |
| 445 | st->has_shareable_shaders && |
| 446 | !st->clamp_frag_color_in_shader && |
| 447 | !st->force_persample_in_shader; |
| 448 | |
| 449 | st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders; |
| 450 | st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders; |
| 451 | st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders; |
Marek Olšák | 55b097d | 2016-06-07 23:03:38 +0200 | [diff] [blame] | 452 | st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders; |
Marek Olšák | e57dd7a | 2015-09-28 00:04:39 +0200 | [diff] [blame] | 453 | |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 454 | _mesa_compute_version(ctx); |
| 455 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 456 | if (ctx->Version == 0) { |
| 457 | /* This can happen when a core profile was requested, but the driver |
| 458 | * does not support some features of GL 3.1 or later. |
| 459 | */ |
| 460 | st_destroy_context_priv(st); |
| 461 | return NULL; |
| 462 | } |
| 463 | |
Eric Anholt | be4b166 | 2013-01-17 16:49:57 -0800 | [diff] [blame] | 464 | _mesa_initialize_dispatch_tables(ctx); |
Jordan Justen | 4bea4cb | 2012-11-16 10:30:19 -0800 | [diff] [blame] | 465 | _mesa_initialize_vbo_vtxfmt(ctx); |
| 466 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 467 | return st; |
| 468 | } |
| 469 | |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 470 | static void st_init_driver_flags(struct gl_driver_flags *f) |
| 471 | { |
| 472 | f->NewArray = ST_NEW_VERTEX_ARRAYS; |
Marek Olšák | 99bd76d | 2013-04-15 13:00:54 +0200 | [diff] [blame] | 473 | f->NewRasterizerDiscard = ST_NEW_RASTERIZER; |
Marek Olšák | 77d8fbc | 2013-04-26 14:21:09 +0200 | [diff] [blame] | 474 | f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER; |
Marek Olšák | bda9094 | 2015-05-18 12:49:10 +0200 | [diff] [blame] | 475 | f->NewDefaultTessLevels = ST_NEW_TESS_STATE; |
Marek Olšák | e39ece0 | 2015-07-24 19:47:06 +0200 | [diff] [blame] | 476 | f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS; |
Ilia Mirkin | 9d6f9cc | 2014-09-19 20:59:17 -0400 | [diff] [blame] | 477 | f->NewAtomicBuffer = ST_NEW_ATOMIC_BUFFER; |
Ilia Mirkin | 6880036 | 2016-01-18 00:08:24 -0500 | [diff] [blame] | 478 | f->NewShaderStorageBuffer = ST_NEW_STORAGE_BUFFER; |
Ilia Mirkin | 7809316 | 2016-01-08 19:58:33 -0500 | [diff] [blame] | 479 | f->NewImageUnits = ST_NEW_IMAGE_UNITS; |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 480 | } |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 481 | |
Chia-I Wu | 57c6543 | 2010-06-23 17:40:49 +0800 | [diff] [blame] | 482 | 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] | 483 | const struct gl_config *visual, |
Vadim Girlin | a6457c0 | 2012-04-12 04:30:03 +0400 | [diff] [blame] | 484 | struct st_context *share, |
| 485 | const struct st_config_options *options) |
Brian | 80d2658 | 2007-11-01 17:46:04 -0600 | [diff] [blame] | 486 | { |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 487 | struct gl_context *ctx; |
| 488 | struct gl_context *shareCtx = share ? share->ctx : NULL; |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 489 | struct dd_function_table funcs; |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 490 | struct st_context *st; |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 491 | |
| 492 | memset(&funcs, 0, sizeof(funcs)); |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 493 | st_init_driver_functions(pipe->screen, &funcs); |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 494 | |
Emil Velikov | db8790c | 2016-06-07 17:33:48 +0100 | [diff] [blame] | 495 | ctx = calloc(1, sizeof(struct gl_context)); |
| 496 | if (!ctx) |
| 497 | return NULL; |
| 498 | |
| 499 | if (!_mesa_initialize_context(ctx, api, visual, shareCtx, &funcs)) { |
| 500 | free(ctx); |
Emil Velikov | 1ab5e15 | 2011-07-11 15:42:15 +0100 | [diff] [blame] | 501 | return NULL; |
| 502 | } |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 503 | |
Marek Olšák | c5e473f | 2012-04-16 04:56:12 +0200 | [diff] [blame] | 504 | st_init_driver_flags(&ctx->DriverFlags); |
| 505 | |
Keith Whitwell | b6e8256 | 2009-05-05 12:12:28 +0100 | [diff] [blame] | 506 | /* XXX: need a capability bit in gallium to query if the pipe |
| 507 | * driver prefers DP4 or MUL/MAD for vertex transformation. |
| 508 | */ |
Jakob Bornecrantz | 99611f0 | 2010-08-05 17:13:41 -0700 | [diff] [blame] | 509 | if (debug_get_option_mesa_mvp_dp4()) |
Marek Olšák | 002211f | 2014-08-03 04:31:56 +0200 | [diff] [blame] | 510 | ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE; |
Keith Whitwell | b6e8256 | 2009-05-05 12:12:28 +0100 | [diff] [blame] | 511 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 512 | st = st_create_context_priv(ctx, pipe, options); |
| 513 | if (!st) { |
| 514 | _mesa_destroy_context(ctx); |
Brian Paul | 87afc9b | 2008-05-16 16:04:30 -0600 | [diff] [blame] | 515 | } |
| 516 | |
Brian Paul | a46d757 | 2014-09-09 09:56:47 -0600 | [diff] [blame] | 517 | return st; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 520 | |
| 521 | /** |
| 522 | * Callback to release the sampler view attached to a texture object. |
| 523 | * Called by _mesa_HashWalk(). |
| 524 | */ |
| 525 | static void |
| 526 | destroy_tex_sampler_cb(GLuint id, void *data, void *userData) |
| 527 | { |
| 528 | struct gl_texture_object *texObj = (struct gl_texture_object *) data; |
| 529 | struct st_context *st = (struct st_context *) userData; |
| 530 | |
| 531 | st_texture_release_sampler_view(st, st_texture_object(texObj)); |
| 532 | } |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 533 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 534 | void st_destroy_context( struct st_context *st ) |
| 535 | { |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 536 | struct pipe_context *pipe = st->pipe; |
Kristian Høgsberg | f9995b3 | 2010-10-12 12:26:10 -0400 | [diff] [blame] | 537 | struct gl_context *ctx = st->ctx; |
Brian Paul | f104e4d | 2009-05-11 16:09:39 -0600 | [diff] [blame] | 538 | GLuint i; |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 539 | |
Christian König | d117ddb | 2014-03-23 17:01:38 +0100 | [diff] [blame] | 540 | _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st); |
| 541 | |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 542 | st_reference_fragprog(st, &st->fp, NULL); |
Brian Paul | d102049 | 2014-07-08 16:24:53 -0600 | [diff] [blame] | 543 | st_reference_geomprog(st, &st->gp, NULL); |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 544 | st_reference_vertprog(st, &st->vp, NULL); |
Ilia Mirkin | ba9fb96 | 2014-07-11 22:11:21 -0400 | [diff] [blame] | 545 | st_reference_tesscprog(st, &st->tcp, NULL); |
| 546 | st_reference_tesseprog(st, &st->tep, NULL); |
Samuel Pitoiset | 7c79c1e | 2016-01-07 22:02:43 +0100 | [diff] [blame] | 547 | st_reference_compprog(st, &st->cp, NULL); |
Brian Paul | 69fd676 | 2008-05-20 14:38:22 -0600 | [diff] [blame] | 548 | |
Brian Paul | f104e4d | 2009-05-11 16:09:39 -0600 | [diff] [blame] | 549 | /* release framebuffer surfaces */ |
| 550 | for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { |
| 551 | pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL); |
| 552 | } |
| 553 | pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL); |
Marek Olšák | f15bb3e | 2015-10-04 02:38:55 +0200 | [diff] [blame] | 554 | pipe_sampler_view_reference(&st->pixel_xfer.pixelmap_sampler_view, NULL); |
| 555 | pipe_resource_reference(&st->pixel_xfer.pixelmap_texture, NULL); |
Brian Paul | f2b3f6c | 2008-04-17 11:12:44 -0600 | [diff] [blame] | 556 | |
Brian Paul | a063615 | 2016-02-16 10:22:32 -0700 | [diff] [blame] | 557 | _vbo_DestroyContext(ctx); |
Brian Paul | 753635f | 2008-09-16 08:51:28 -0600 | [diff] [blame] | 558 | |
Brian Paul | 3d203b6 | 2010-12-13 17:20:12 -0700 | [diff] [blame] | 559 | st_destroy_program_variants(st); |
| 560 | |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 561 | _mesa_free_context_data(ctx); |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 562 | |
José Fonseca | 63da1aa | 2012-04-25 11:41:13 +0100 | [diff] [blame] | 563 | /* This will free the st_context too, so 'st' must not be accessed |
| 564 | * afterwards. */ |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 565 | st_destroy_context_priv(st); |
José Fonseca | 63da1aa | 2012-04-25 11:41:13 +0100 | [diff] [blame] | 566 | st = NULL; |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 567 | |
Brian Paul | a770d40 | 2008-04-24 12:11:24 -0600 | [diff] [blame] | 568 | pipe->destroy( pipe ); |
| 569 | |
Kristian Høgsberg | 32f2fd1 | 2010-02-19 11:58:49 -0500 | [diff] [blame] | 570 | free(ctx); |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Rob Clark | d640837 | 2015-08-10 11:41:29 -0400 | [diff] [blame] | 573 | static void |
| 574 | st_emit_string_marker(struct gl_context *ctx, const GLchar *string, GLsizei len) |
| 575 | { |
| 576 | struct st_context *st = ctx->st; |
| 577 | st->pipe->emit_string_marker(st->pipe, string, len); |
| 578 | } |
Brian | 91564ee | 2007-11-05 16:15:43 -0700 | [diff] [blame] | 579 | |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 580 | void st_init_driver_functions(struct pipe_screen *screen, |
| 581 | struct dd_function_table *functions) |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 582 | { |
Brian Paul | a37b221 | 2010-06-10 20:23:03 -0600 | [diff] [blame] | 583 | _mesa_init_shader_object_functions(functions); |
Brian Paul | 34a5d3b | 2011-04-10 12:48:28 -0600 | [diff] [blame] | 584 | _mesa_init_sampler_object_functions(functions); |
Brian | 601a9ea | 2007-11-07 08:18:50 -0700 | [diff] [blame] | 585 | |
Brian | 0df877a | 2008-03-18 17:16:23 -0600 | [diff] [blame] | 586 | st_init_blit_functions(functions); |
Nicolai Hähnle | 70e66c5 | 2016-01-09 18:05:58 -0500 | [diff] [blame] | 587 | st_init_bufferobject_functions(screen, functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 588 | st_init_clear_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 589 | st_init_bitmap_functions(functions); |
Marek Olšák | f04f136 | 2015-08-24 02:55:20 +0200 | [diff] [blame] | 590 | st_init_copy_image_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 591 | st_init_drawpixels_functions(functions); |
Brian | bee148c | 2007-09-10 16:28:27 -0600 | [diff] [blame] | 592 | st_init_rasterpos_functions(functions); |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 593 | |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 594 | st_init_drawtex_functions(functions); |
Chia-I Wu | 3406475 | 2009-09-22 15:00:24 +0800 | [diff] [blame] | 595 | |
Chia-I Wu | a1aa53b | 2010-02-25 23:10:47 +0800 | [diff] [blame] | 596 | st_init_eglimage_functions(functions); |
| 597 | |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 598 | st_init_fbo_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 599 | st_init_feedback_functions(functions); |
Dave Airlie | 1d90ee5 | 2013-03-04 06:14:18 +1000 | [diff] [blame] | 600 | st_init_msaa_functions(functions); |
Christoph Bumiller | 4cd1cfb | 2014-07-04 13:02:06 +0200 | [diff] [blame] | 601 | st_init_perfmon_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 602 | st_init_program_functions(functions); |
Brian Paul | 04996bc | 2008-06-17 13:13:34 -0600 | [diff] [blame] | 603 | st_init_query_functions(functions); |
Brian Paul | c9b5583 | 2009-12-31 14:47:21 -0700 | [diff] [blame] | 604 | st_init_cond_render_functions(functions); |
Brian | 6f27aab | 2007-08-10 11:37:21 -0600 | [diff] [blame] | 605 | st_init_readpixels_functions(functions); |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 606 | st_init_texture_functions(functions); |
Marek Olšák | aea4ed4 | 2011-03-08 11:32:35 +0100 | [diff] [blame] | 607 | st_init_texture_barrier_functions(functions); |
Marek Olšák | a0ad185 | 2015-04-29 15:05:19 +0200 | [diff] [blame] | 608 | st_init_flush_functions(screen, functions); |
Keith Whitwell | 39407fd | 2007-08-10 16:42:26 +0100 | [diff] [blame] | 609 | st_init_string_functions(functions); |
Jakob Bornecrantz | a93f9f3 | 2010-05-21 20:37:23 +0100 | [diff] [blame] | 610 | st_init_viewport_functions(functions); |
Samuel Pitoiset | 8aa6669 | 2016-01-03 15:41:48 +0100 | [diff] [blame] | 611 | st_init_compute_functions(functions); |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 612 | |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 613 | st_init_xformfb_functions(functions); |
Marek Olšák | 5257a6d | 2011-03-05 20:32:28 +0100 | [diff] [blame] | 614 | st_init_syncobj_functions(functions); |
Brian Paul | fef6e36 | 2010-05-10 21:11:21 -0600 | [diff] [blame] | 615 | |
Christian König | 8096422 | 2013-05-15 15:10:11 +0200 | [diff] [blame] | 616 | st_init_vdpau_functions(functions); |
| 617 | |
Rob Clark | d640837 | 2015-08-10 11:41:29 -0400 | [diff] [blame] | 618 | if (screen->get_param(screen, PIPE_CAP_STRING_MARKER)) |
| 619 | functions->EmitStringMarker = st_emit_string_marker; |
| 620 | |
Nicolai Hähnle | 2123bfc | 2016-01-04 17:31:05 -0500 | [diff] [blame] | 621 | functions->Enable = st_Enable; |
Brian | d775509 | 2007-10-31 11:08:07 -0600 | [diff] [blame] | 622 | functions->UpdateState = st_invalidate_state; |
Marek Olšák | 5f51a24 | 2016-02-02 01:27:55 +0100 | [diff] [blame] | 623 | functions->QueryMemoryInfo = st_query_memory_info; |
Brian | 6da9234 | 2007-08-06 20:53:28 +0100 | [diff] [blame] | 624 | } |