mesa/formats: add more MESA_FORMAT_LAYOUTs
[mesa.git] / src / mesa / state_tracker / st_atom_shader.c
index f416293a7e4c7712d7268dca9d4fcb0562af36c5..fee15a980f30d60af729820825d45da0eb339548 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2003 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * 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
+ * IN NO EVENT SHALL VMWARE 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.
@@ -40,9 +40,8 @@
 #include "program/program.h"
 
 #include "pipe/p_context.h"
-
+#include "pipe/p_shader_tokens.h"
 #include "util/u_simple_shaders.h"
-
 #include "cso_cache/cso_context.h"
 
 #include "st_context.h"
 #include "st_program.h"
 
 
-/**
- * Return pointer to a pass-through fragment shader.
- * This shader is used when a texture is missing/incomplete.
- */
-static void *
-get_passthrough_fs(struct st_context *st)
-{
-   if (!st->passthrough_fs) {
-      st->passthrough_fs =
-         util_make_fragment_passthrough_shader(st->pipe);
-   }
-
-   return st->passthrough_fs;
-}
-
-
 /**
  * Update fragment program state/atom.  This involves translating the
  * Mesa fragment program into a gallium fragment program and binding it.
@@ -74,7 +57,7 @@ static void
 update_fp( struct st_context *st )
 {
    struct st_fragment_program *stfp;
-   struct st_fp_varient_key key;
+   struct st_fp_variant_key key;
 
    assert(st->ctx->FragmentProgram._Current);
    stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
@@ -83,26 +66,27 @@ update_fp( struct st_context *st )
    memset(&key, 0, sizeof(key));
    key.st = st;
 
-   st->fp_varient = st_get_fp_varient(st, stfp, &key);
+   /* _NEW_FRAG_CLAMP */
+   key.clamp_color = st->clamp_frag_color_in_shader &&
+                     st->ctx->Color._ClampFragmentColor;
+
+   /* Ignore sample qualifier while computing this flag. */
+   key.persample_shading =
+      _mesa_get_min_invocations_per_fragment(st->ctx, &stfp->Base, true) > 1;
+
+   st->fp_variant = st_get_fp_variant(st, stfp, &key);
 
    st_reference_fragprog(st, &st->fp, stfp);
 
-   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 {
-      cso_set_fragment_shader_handle(st->cso_context,
-                                     st->fp_varient->driver_shader);
-   }
+   cso_set_fragment_shader_handle(st->cso_context,
+                                  st->fp_variant->driver_shader);
 }
 
 
 const struct st_tracked_state st_update_fp = {
    "st_update_fp",                                     /* name */
    {                                                   /* dirty */
-      0,                                               /* mesa */
+      _NEW_BUFFERS | _NEW_MULTISAMPLE,                 /* mesa */
       ST_NEW_FRAGMENT_PROGRAM                           /* st */
    },
    update_fp                                   /* update */
@@ -118,7 +102,7 @@ static void
 update_vp( struct st_context *st )
 {
    struct st_vertex_program *stvp;
-   struct st_vp_varient_key key;
+   struct st_vp_variant_key key;
 
    /* find active shader and params -- Should be covered by
     * ST_NEW_VERTEX_PROGRAM
@@ -135,18 +119,23 @@ update_vp( struct st_context *st )
     * 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));
+   key.passthrough_edgeflags = st->vertdata_edgeflags;
+
+   key.clamp_color = st->clamp_vert_color_in_shader &&
+                     st->ctx->Light._ClampVertexColor &&
+                     (stvp->Base.Base.OutputsWritten &
+                      (VARYING_SLOT_COL0 |
+                       VARYING_SLOT_COL1 |
+                       VARYING_SLOT_BFC0 |
+                       VARYING_SLOT_BFC1));
 
-   st->vp_varient = st_get_vp_varient(st, stvp, &key);
+   st->vp_variant = st_get_vp_variant(st, stvp, &key);
 
    st_reference_vertprog(st, &st->vp, stvp);
 
    cso_set_vertex_shader_handle(st->cso_context, 
-                                st->vp_varient->driver_shader);
+                                st->vp_variant->driver_shader);
 
    st->vertex_result_to_slot = stvp->result_to_output;
 }
@@ -155,8 +144,8 @@ update_vp( struct st_context *st )
 const struct st_tracked_state st_update_vp = {
    "st_update_vp",                                     /* name */
    {                                                   /* dirty */
-      _NEW_POLYGON,                                    /* mesa */
-      ST_NEW_VERTEX_PROGRAM | ST_NEW_EDGEFLAGS_DATA    /* st */
+      0,                                                /* mesa */
+      ST_NEW_VERTEX_PROGRAM                             /* st */
    },
    update_vp                                           /* update */
 };
@@ -167,7 +156,7 @@ static void
 update_gp( struct st_context *st )
 {
    struct st_geometry_program *stgp;
-   struct st_gp_varient_key key;
+   struct st_gp_variant_key key;
 
    if (!st->ctx->GeometryProgram._Current) {
       cso_set_geometry_shader_handle(st->cso_context, NULL);
@@ -175,17 +164,17 @@ update_gp( struct st_context *st )
    }
 
    stgp = st_geometry_program(st->ctx->GeometryProgram._Current);
-   assert(stgp->Base.Base.Target == MESA_GEOMETRY_PROGRAM);
+   assert(stgp->Base.Base.Target == GL_GEOMETRY_PROGRAM_NV);
 
    memset(&key, 0, sizeof(key));
    key.st = st;
 
-   st->gp_varient = st_get_gp_varient(st, stgp, &key);
+   st->gp_variant = st_get_gp_variant(st, stgp, &key);
 
    st_reference_geomprog(st, &st->gp, stgp);
 
    cso_set_geometry_shader_handle(st->cso_context,
-                                  st->gp_varient->driver_shader);
+                                  st->gp_variant->driver_shader);
 }
 
 const struct st_tracked_state st_update_gp = {
@@ -196,3 +185,75 @@ const struct st_tracked_state st_update_gp = {
    },
    update_gp                           /* update */
 };
+
+
+
+static void
+update_tcp( struct st_context *st )
+{
+   struct st_tessctrl_program *sttcp;
+   struct st_tcp_variant_key key;
+
+   if (!st->ctx->TessCtrlProgram._Current) {
+      cso_set_tessctrl_shader_handle(st->cso_context, NULL);
+      return;
+   }
+
+   sttcp = st_tessctrl_program(st->ctx->TessCtrlProgram._Current);
+   assert(sttcp->Base.Base.Target == GL_TESS_CONTROL_PROGRAM_NV);
+
+   memset(&key, 0, sizeof(key));
+   key.st = st;
+
+   st->tcp_variant = st_get_tcp_variant(st, sttcp, &key);
+
+   st_reference_tesscprog(st, &st->tcp, sttcp);
+
+   cso_set_tessctrl_shader_handle(st->cso_context,
+                                  st->tcp_variant->driver_shader);
+}
+
+const struct st_tracked_state st_update_tcp = {
+   "st_update_tcp",                    /* name */
+   {                                   /* dirty */
+      0,                               /* mesa */
+      ST_NEW_TESSCTRL_PROGRAM           /* st */
+   },
+   update_tcp                                  /* update */
+};
+
+
+
+static void
+update_tep( struct st_context *st )
+{
+   struct st_tesseval_program *sttep;
+   struct st_tep_variant_key key;
+
+   if (!st->ctx->TessEvalProgram._Current) {
+      cso_set_tesseval_shader_handle(st->cso_context, NULL);
+      return;
+   }
+
+   sttep = st_tesseval_program(st->ctx->TessEvalProgram._Current);
+   assert(sttep->Base.Base.Target == GL_TESS_EVALUATION_PROGRAM_NV);
+
+   memset(&key, 0, sizeof(key));
+   key.st = st;
+
+   st->tep_variant = st_get_tep_variant(st, sttep, &key);
+
+   st_reference_tesseprog(st, &st->tep, sttep);
+
+   cso_set_tesseval_shader_handle(st->cso_context,
+                                  st->tep_variant->driver_shader);
+}
+
+const struct st_tracked_state st_update_tep = {
+   "st_update_tep",                    /* name */
+   {                                   /* dirty */
+      0,                               /* mesa */
+      ST_NEW_TESSEVAL_PROGRAM           /* st */
+   },
+   update_tep                                  /* update */
+};