OSDN Git Service

gallium: introduce GLSL based interpolation rules. (v2)
authorDave Airlie <airlied@redhat.com>
Mon, 9 Jan 2012 15:57:02 +0000 (15:57 +0000)
committerDave Airlie <airlied@redhat.com>
Tue, 10 Jan 2012 11:54:44 +0000 (11:54 +0000)
This introduces an unspecified interpolation paramter that is only allowed for
color semantics, so a specified GLSL interpolation will override the ShadeModel
specified interpolation, but not vice-versa.

This fixes a lot of the interpolation tests in piglit.

v2: rename from unspecified to color

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/auxiliary/tgsi/tgsi_exec.c
src/gallium/auxiliary/tgsi/tgsi_exec.h
src/gallium/auxiliary/tgsi/tgsi_strings.c
src/gallium/drivers/softpipe/sp_quad_fs.c
src/gallium/drivers/softpipe/sp_state_derived.c
src/gallium/include/pipe/p_shader_tokens.h
src/mesa/state_tracker/st_program.c

index 3e2b899..52d4ff4 100644 (file)
@@ -2371,6 +2371,10 @@ exec_declaration(struct tgsi_exec_machine *mach,
                eval = eval_perspective_coef;
                break;
 
+            case TGSI_INTERPOLATE_COLOR:
+               eval = mach->flatshade_color ? eval_constant_coef : eval_perspective_coef;
+               break;
+
             default:
                assert(0);
                return;
index 223da2c..0817e14 100644 (file)
@@ -263,7 +263,7 @@ struct tgsi_exec_machine
    const struct tgsi_interp_coef *InterpCoefs;
    struct tgsi_exec_vector       QuadPos;
    float                         Face;    /**< +1 if front facing, -1 if back facing */
-
+   bool                          flatshade_color;
    /* Conditional execution masks */
    uint CondMask;  /**< For IF/ELSE/ENDIF */
    uint LoopMask;  /**< For BGNLOOP/ENDLOOP */
index aa12493..de9152d 100644 (file)
@@ -117,7 +117,8 @@ const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT] =
 {
    "CONSTANT",
    "LINEAR",
-   "PERSPECTIVE"
+   "PERSPECTIVE",
+   "COLOR"
 };
 
 const char *tgsi_primitive_names[PIPE_PRIM_MAX] =
index 7b08cd0..7800ba8 100644 (file)
@@ -74,6 +74,7 @@ shade_quad(struct quad_stage *qs, struct quad_header *quad)
    struct tgsi_exec_machine *machine = softpipe->fs_machine;
 
    /* run shader */
+   machine->flatshade_color = softpipe->rasterizer->flatshade ? TRUE : FALSE;
    return softpipe->fs_variant->run( softpipe->fs_variant, machine, quad );
 }
 
index 5685997..7b2b04e 100644 (file)
@@ -100,6 +100,9 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
          case TGSI_INTERPOLATE_PERSPECTIVE:
             interp = INTERP_PERSPECTIVE;
             break;
+         case TGSI_INTERPOLATE_COLOR:
+            assert(fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_COLOR);
+            break;
          default:
             assert(0);
             interp = INTERP_LINEAR;
@@ -111,8 +114,11 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
             break;
 
          case TGSI_SEMANTIC_COLOR:
-            if (softpipe->rasterizer->flatshade) {
-               interp = INTERP_CONSTANT;
+            if (fsInfo->input_interpolate[i] == TGSI_INTERPOLATE_COLOR) {
+               if (softpipe->rasterizer->flatshade)
+                  interp = INTERP_CONSTANT;
+               else
+                  interp = INTERP_PERSPECTIVE;
             }
             break;
          }
index 2fbe1df..cb1e698 100644 (file)
@@ -100,7 +100,8 @@ enum tgsi_file_type {
 #define TGSI_INTERPOLATE_CONSTANT      0
 #define TGSI_INTERPOLATE_LINEAR        1
 #define TGSI_INTERPOLATE_PERSPECTIVE   2
-#define TGSI_INTERPOLATE_COUNT         3
+#define TGSI_INTERPOLATE_COLOR         3 /* special color case for smooth/flat */
+#define TGSI_INTERPOLATE_COUNT         4
 
 #define TGSI_CYLINDRICAL_WRAP_X (1 << 0)
 #define TGSI_CYLINDRICAL_WRAP_Y (1 << 1)
index 8d7469d..8d08b2b 100644 (file)
@@ -441,7 +441,7 @@ st_translate_interp(enum glsl_interp_qualifier glsl_qual, bool is_color)
    switch (glsl_qual) {
    case INTERP_QUALIFIER_NONE:
       if (is_color)
-         return TGSI_INTERPOLATE_LINEAR;
+         return TGSI_INTERPOLATE_COLOR;
       return TGSI_INTERPOLATE_PERSPECTIVE;
    case INTERP_QUALIFIER_SMOOTH:
       return TGSI_INTERPOLATE_PERSPECTIVE;