2007-09-25 14:21:18 -06:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State validation for vertex/fragment shaders.
|
|
|
|
* Note that we have to delay most vertex/fragment shader translation
|
|
|
|
* until rendering time since the linkage between the vertex outputs and
|
|
|
|
* fragment inputs can vary depending on the pairing of shaders.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Brian Paul
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main/imports.h"
|
|
|
|
#include "main/mtypes.h"
|
2010-06-10 23:02:41 -06:00
|
|
|
#include "program/program.h"
|
2007-09-25 14:21:18 -06:00
|
|
|
|
|
|
|
#include "pipe/p_context.h"
|
|
|
|
|
2008-05-07 16:44:33 -06:00
|
|
|
#include "util/u_simple_shaders.h"
|
|
|
|
|
2008-03-11 18:54:31 -06:00
|
|
|
#include "cso_cache/cso_context.h"
|
2008-01-14 19:12:46 -07:00
|
|
|
|
2007-09-25 14:21:18 -06:00
|
|
|
#include "st_context.h"
|
|
|
|
#include "st_atom.h"
|
|
|
|
#include "st_program.h"
|
|
|
|
|
|
|
|
|
2010-01-11 19:04:11 -07:00
|
|
|
/**
|
|
|
|
* Return pointer to a pass-through fragment shader.
|
|
|
|
* This shader is used when a texture is missing/incomplete.
|
|
|
|
*/
|
2008-05-07 16:44:33 -06:00
|
|
|
static void *
|
|
|
|
get_passthrough_fs(struct st_context *st)
|
|
|
|
{
|
|
|
|
if (!st->passthrough_fs) {
|
|
|
|
st->passthrough_fs =
|
2013-01-14 17:07:58 +01:00
|
|
|
util_make_fragment_passthrough_shader(st->pipe, TGSI_SEMANTIC_COLOR,
|
|
|
|
TGSI_INTERPOLATE_PERSPECTIVE);
|
2008-05-07 16:44:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return st->passthrough_fs;
|
|
|
|
}
|
|
|
|
|
2010-01-11 19:04:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update fragment program state/atom. This involves translating the
|
|
|
|
* Mesa fragment program into a gallium fragment program and binding it.
|
|
|
|
*/
|
2007-09-25 14:21:18 -06:00
|
|
|
static void
|
2009-11-15 11:15:25 -08:00
|
|
|
update_fp( struct st_context *st )
|
2007-09-25 14:21:18 -06:00
|
|
|
{
|
|
|
|
struct st_fragment_program *stfp;
|
2010-12-16 08:43:21 -07:00
|
|
|
struct st_fp_variant_key key;
|
2007-09-25 14:21:18 -06:00
|
|
|
|
2007-10-29 09:24:29 -06:00
|
|
|
assert(st->ctx->FragmentProgram._Current);
|
|
|
|
stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
|
2008-05-07 08:55:33 -06:00
|
|
|
assert(stfp->Base.Base.Target == GL_FRAGMENT_PROGRAM_ARB);
|
2007-09-25 14:21:18 -06:00
|
|
|
|
2010-12-13 17:20:12 -07:00
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
key.st = st;
|
|
|
|
|
2012-01-23 03:11:17 +01:00
|
|
|
/* _NEW_FRAG_CLAMP */
|
|
|
|
key.clamp_color = st->clamp_frag_color_in_shader &&
|
2012-08-04 13:32:21 +02:00
|
|
|
st->ctx->Color._ClampFragmentColor &&
|
|
|
|
!st->ctx->DrawBuffer->_IntegerColor;
|
2012-01-23 03:11:17 +01:00
|
|
|
|
2010-12-16 08:43:21 -07:00
|
|
|
st->fp_variant = st_get_fp_variant(st, stfp, &key);
|
2007-09-25 14:21:18 -06:00
|
|
|
|
2008-05-07 08:55:33 -06:00
|
|
|
st_reference_fragprog(st, &st->fp, stfp);
|
2008-03-11 18:54:31 -06:00
|
|
|
|
2008-05-07 16:44:33 -06:00
|
|
|
if (st->missing_textures) {
|
|
|
|
/* use a pass-through frag shader that uses no textures */
|
|
|
|
void *fs = get_passthrough_fs(st);
|
|
|
|
cso_set_fragment_shader_handle(st->cso_context, fs);
|
|
|
|
}
|
|
|
|
else {
|
2010-12-13 17:20:12 -07:00
|
|
|
cso_set_fragment_shader_handle(st->cso_context,
|
2010-12-16 08:43:21 -07:00
|
|
|
st->fp_variant->driver_shader);
|
2008-05-07 16:44:33 -06:00
|
|
|
}
|
2009-11-15 11:15:25 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 19:04:11 -07:00
|
|
|
|
2009-11-15 11:15:25 -08:00
|
|
|
const struct st_tracked_state st_update_fp = {
|
|
|
|
"st_update_fp", /* name */
|
|
|
|
{ /* dirty */
|
2012-08-04 13:32:21 +02:00
|
|
|
_NEW_BUFFERS, /* mesa */
|
2009-11-15 11:15:25 -08:00
|
|
|
ST_NEW_FRAGMENT_PROGRAM /* st */
|
|
|
|
},
|
|
|
|
update_fp /* update */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-11 19:04:11 -07:00
|
|
|
/**
|
|
|
|
* Update vertex program state/atom. This involves translating the
|
|
|
|
* Mesa vertex program into a gallium fragment program and binding it.
|
|
|
|
*/
|
2009-11-15 11:15:25 -08:00
|
|
|
static void
|
|
|
|
update_vp( struct st_context *st )
|
|
|
|
{
|
|
|
|
struct st_vertex_program *stvp;
|
2010-12-16 08:43:21 -07:00
|
|
|
struct st_vp_variant_key key;
|
2009-11-15 11:15:25 -08:00
|
|
|
|
|
|
|
/* find active shader and params -- Should be covered by
|
|
|
|
* ST_NEW_VERTEX_PROGRAM
|
|
|
|
*/
|
|
|
|
assert(st->ctx->VertexProgram._Current);
|
|
|
|
stvp = st_vertex_program(st->ctx->VertexProgram._Current);
|
|
|
|
assert(stvp->Base.Base.Target == GL_VERTEX_PROGRAM_ARB);
|
|
|
|
|
2010-12-13 17:20:12 -07:00
|
|
|
memset(&key, 0, sizeof key);
|
|
|
|
key.st = st; /* variants are per-context */
|
|
|
|
|
|
|
|
/* When this is true, we will add an extra input to the vertex
|
|
|
|
* shader translation (for edgeflags), an extra output with
|
|
|
|
* edgeflag semantics, and extend the vertex shader to pass through
|
|
|
|
* the input to the output. We'll need to use similar logic to set
|
|
|
|
* up the extra vertex_element input for edgeflags.
|
|
|
|
* _NEW_POLYGON, ST_NEW_EDGEFLAGS_DATA
|
|
|
|
*/
|
|
|
|
key.passthrough_edgeflags = (st->vertdata_edgeflags && (
|
|
|
|
st->ctx->Polygon.FrontMode != GL_FILL ||
|
|
|
|
st->ctx->Polygon.BackMode != GL_FILL));
|
|
|
|
|
2012-01-23 03:11:17 +01:00
|
|
|
key.clamp_color = st->clamp_vert_color_in_shader &&
|
|
|
|
st->ctx->Light._ClampVertexColor;
|
|
|
|
|
2010-12-16 08:43:21 -07:00
|
|
|
st->vp_variant = st_get_vp_variant(st, stvp, &key);
|
2009-11-15 11:15:25 -08:00
|
|
|
|
|
|
|
st_reference_vertprog(st, &st->vp, stvp);
|
|
|
|
|
|
|
|
cso_set_vertex_shader_handle(st->cso_context,
|
2010-12-16 08:43:21 -07:00
|
|
|
st->vp_variant->driver_shader);
|
2007-09-25 14:21:18 -06:00
|
|
|
|
2009-11-15 11:15:25 -08:00
|
|
|
st->vertex_result_to_slot = stvp->result_to_output;
|
2007-09-25 14:21:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-15 11:15:25 -08:00
|
|
|
const struct st_tracked_state st_update_vp = {
|
|
|
|
"st_update_vp", /* name */
|
2008-05-02 10:08:03 +00:00
|
|
|
{ /* dirty */
|
2009-12-19 17:12:14 +01:00
|
|
|
_NEW_POLYGON, /* mesa */
|
2009-12-19 20:25:43 +01:00
|
|
|
ST_NEW_VERTEX_PROGRAM | ST_NEW_EDGEFLAGS_DATA /* st */
|
2007-09-25 14:21:18 -06:00
|
|
|
},
|
2010-12-13 17:20:12 -07:00
|
|
|
update_vp /* update */
|
2007-09-25 14:21:18 -06:00
|
|
|
};
|
2010-06-28 17:31:21 -04:00
|
|
|
|
2010-12-13 17:20:12 -07:00
|
|
|
|
|
|
|
|
2010-06-28 17:31:21 -04:00
|
|
|
static void
|
|
|
|
update_gp( struct st_context *st )
|
|
|
|
{
|
|
|
|
struct st_geometry_program *stgp;
|
2010-12-16 08:43:21 -07:00
|
|
|
struct st_gp_variant_key key;
|
2010-06-28 17:31:21 -04:00
|
|
|
|
|
|
|
if (!st->ctx->GeometryProgram._Current) {
|
|
|
|
cso_set_geometry_shader_handle(st->cso_context, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stgp = st_geometry_program(st->ctx->GeometryProgram._Current);
|
|
|
|
assert(stgp->Base.Base.Target == MESA_GEOMETRY_PROGRAM);
|
|
|
|
|
2010-12-13 17:20:12 -07:00
|
|
|
memset(&key, 0, sizeof(key));
|
|
|
|
key.st = st;
|
|
|
|
|
2010-12-16 08:43:21 -07:00
|
|
|
st->gp_variant = st_get_gp_variant(st, stgp, &key);
|
2010-06-28 17:31:21 -04:00
|
|
|
|
|
|
|
st_reference_geomprog(st, &st->gp, stgp);
|
|
|
|
|
2010-12-13 17:20:12 -07:00
|
|
|
cso_set_geometry_shader_handle(st->cso_context,
|
2010-12-16 08:43:21 -07:00
|
|
|
st->gp_variant->driver_shader);
|
2010-06-28 17:31:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct st_tracked_state st_update_gp = {
|
2010-12-13 17:20:12 -07:00
|
|
|
"st_update_gp", /* name */
|
|
|
|
{ /* dirty */
|
|
|
|
0, /* mesa */
|
|
|
|
ST_NEW_GEOMETRY_PROGRAM /* st */
|
2010-06-28 17:31:21 -04:00
|
|
|
},
|
2010-12-13 17:20:12 -07:00
|
|
|
update_gp /* update */
|
2010-06-28 17:31:21 -04:00
|
|
|
};
|