1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/************************************************************************** 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved. 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish, 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions: 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software. 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/ 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/imports.h" 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/accum.h" 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/context.h" 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/samplerobj.h" 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "main/shaderobj.h" 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "program/prog_cache.h" 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "vbo/vbo.h" 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glapi/glapi.h" 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_context.h" 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_debug.h" 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_bitmap.h" 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_blit.h" 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_bufferobjects.h" 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_clear.h" 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_condrender.h" 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_drawpixels.h" 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_rasterpos.h" 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_drawtex.h" 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_eglimage.h" 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_fbo.h" 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_feedback.h" 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_program.h" 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_queryobj.h" 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_readpixels.h" 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_texture.h" 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_xformfb.h" 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_flush.h" 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_syncobj.h" 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_strings.h" 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_texturebarrier.h" 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_cb_viewport.h" 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_atom.h" 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_draw.h" 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_extensions.h" 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_gen_mipmap.h" 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "st_program.h" 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_context.h" 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_inlines.h" 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_upload_mgr.h" 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "cso_cache/cso_context.h" 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE) 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Called via ctx->Driver.UpdateState() 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid st_invalidate_state(struct gl_context * ctx, GLuint new_state) 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct st_context *st = st_context(ctx); 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Replace _NEW_FRAG_CLAMP with ST_NEW_FRAGMENT_PROGRAM for the fallback. */ 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (st->clamp_frag_color_in_shader && (new_state & _NEW_FRAG_CLAMP)) { 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org new_state &= ~_NEW_FRAG_CLAMP; 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */ 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT)) { 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.st |= ST_NEW_VERTEX_PROGRAM; 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.mesa |= new_state; 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.st |= ST_NEW_MESA; 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* This is the only core Mesa module we depend upon. 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * No longer use swrast, swsetup, tnl. 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _vbo_InvalidateState(ctx, new_state); 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Check for multisample env var override. 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgint 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgst_get_msaa(void) 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *msaa = _mesa_getenv("__GL_FSAA_MODE"); 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (msaa) 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return atoi(msaa); 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 0; 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic struct st_context * 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgst_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct st_config_options *options) 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct pipe_screen *screen = pipe->screen; 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint i; 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct st_context *st = ST_CALLOC_STRUCT( st_context ); 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->options = *options; 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ctx->st = st; 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->ctx = ctx; 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->pipe = pipe; 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* XXX: this is one-off, per-screen init: */ 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_debug_init(); 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* state tracker needs the VBO module */ 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _vbo_CreateContext(ctx); 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.mesa = ~0; 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->dirty.st = ~0; 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->uploader = u_upload_create(st->pipe, 65536, 4, PIPE_BIND_VERTEX_BUFFER); 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, 4, 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org PIPE_BIND_INDEX_BUFFER); 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) { 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned alignment = 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT); 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, alignment, 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org PIPE_BIND_CONSTANT_BUFFER); 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->cso_context = cso_create_context(pipe); 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_atoms( st ); 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_bitmap(st); 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_clear(st); 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_draw( st ); 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_generate_mipmap(st); 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_blit(st); 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if(pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->internal_target = PIPE_TEXTURE_2D; 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->internal_target = PIPE_TEXTURE_RECT; 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Vertex element objects used for drawing rectangles for glBitmap, 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * glDrawPixels, glClear, etc. 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (i = 0; i < Elements(st->velems_util_draw); i++) { 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->velems_util_draw[i].src_offset = i * 4 * sizeof(float); 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->velems_util_draw[i].instance_divisor = 0; 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->velems_util_draw[i].vertex_buffer_index = 0; 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* we want all vertex data to be placed in buffer objects */ 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vbo_use_buffer_objects(ctx); 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* make sure that no VBOs are left mapped when we're drawing. */ 185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org vbo_always_unmap_buffers(ctx); 186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Need these flags: 188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; 190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; 192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->pixel_xfer.cache = _mesa_new_program_cache(); 194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->force_msaa = st_get_msaa(); 196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->has_stencil_export = 197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT); 198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* GL limits and extensions */ 200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_limits(st); 201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_extensions(st); 202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return st; 204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void st_init_driver_flags(struct gl_driver_flags *f) 207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org f->NewArray = ST_NEW_VERTEX_ARRAYS; 209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct st_context *st_create_context(gl_api api, struct pipe_context *pipe, 212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct gl_config *visual, 213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct st_context *share, 214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct st_config_options *options) 215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct gl_context *ctx; 217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct gl_context *shareCtx = share ? share->ctx : NULL; 218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct dd_function_table funcs; 219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Sanity checks */ 221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org STATIC_ASSERT(MESA_SHADER_VERTEX == PIPE_SHADER_VERTEX); 222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org STATIC_ASSERT(MESA_SHADER_FRAGMENT == PIPE_SHADER_FRAGMENT); 223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org STATIC_ASSERT(MESA_SHADER_GEOMETRY == PIPE_SHADER_GEOMETRY); 224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(&funcs, 0, sizeof(funcs)); 226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_driver_functions(&funcs); 227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ctx = _mesa_create_context(api, visual, shareCtx, &funcs, NULL); 229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (!ctx) { 230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return NULL; 231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_driver_flags(&ctx->DriverFlags); 234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* XXX: need a capability bit in gallium to query if the pipe 236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * driver prefers DP4 or MUL/MAD for vertex transformation. 237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (debug_get_option_mesa_mvp_dp4()) 239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _mesa_set_mvp_with_dp4( ctx, GL_TRUE ); 240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return st_create_context_priv(ctx, pipe, options); 242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void st_destroy_context_priv( struct st_context *st ) 246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint shader, i; 248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_atoms( st ); 250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_draw( st ); 251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_generate_mipmap(st); 252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_blit(st); 253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_clear(st); 254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_bitmap(st); 255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_drawpix(st); 256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_drawtex(st); 257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (shader = 0; shader < Elements(st->state.sampler_views); shader++) { 259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (i = 0; i < Elements(st->state.sampler_views[0]); i++) { 260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe_sampler_view_release(st->pipe, 261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org &st->state.sampler_views[shader][i]); 262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (st->default_texture) { 266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->ctx->Driver.DeleteTexture(st->ctx, st->default_texture); 267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st->default_texture = NULL; 268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_upload_destroy(st->uploader); 271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (st->indexbuf_uploader) { 272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_upload_destroy(st->indexbuf_uploader); 273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (st->constbuf_uploader) { 275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org u_upload_destroy(st->constbuf_uploader); 276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org free( st ); 278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid st_destroy_context( struct st_context *st ) 282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct pipe_context *pipe = st->pipe; 284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct cso_context *cso = st->cso_context; 285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct gl_context *ctx = st->ctx; 286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org GLuint i; 287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* need to unbind and destroy CSO objects before anything else */ 289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org cso_release_all(st->cso_context); 290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_reference_fragprog(st, &st->fp, NULL); 292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_reference_vertprog(st, &st->vp, NULL); 293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* release framebuffer surfaces */ 295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { 296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL); 297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL); 299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe->set_index_buffer(pipe, NULL); 301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (i = 0; i < PIPE_SHADER_TYPES; i++) { 303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe->set_constant_buffer(pipe, i, 0, NULL); 304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); 307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _vbo_DestroyContext(st->ctx); 309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_program_variants(st); 311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _mesa_free_context_data(ctx); 313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* This will free the st_context too, so 'st' must not be accessed 315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * afterwards. */ 316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_destroy_context_priv(st); 317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st = NULL; 318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org cso_destroy_context(cso); 320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org pipe->destroy( pipe ); 322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org free(ctx); 324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid st_init_driver_functions(struct dd_function_table *functions) 328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _mesa_init_shader_object_functions(functions); 330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org _mesa_init_sampler_object_functions(functions); 331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org functions->Accum = _mesa_accum; 333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_blit_functions(functions); 335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_bufferobject_functions(functions); 336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_clear_functions(functions); 337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_bitmap_functions(functions); 338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_drawpixels_functions(functions); 339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_rasterpos_functions(functions); 340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_drawtex_functions(functions); 342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_eglimage_functions(functions); 344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_fbo_functions(functions); 346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_feedback_functions(functions); 347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_program_functions(functions); 348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_query_functions(functions); 349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_cond_render_functions(functions); 350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_readpixels_functions(functions); 351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_texture_functions(functions); 352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_texture_barrier_functions(functions); 353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_flush_functions(functions); 354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_string_functions(functions); 355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_viewport_functions(functions); 356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_xformfb_functions(functions); 358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org st_init_syncobj_functions(functions); 359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org functions->UpdateState = st_invalidate_state; 361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 362