[Mesa-dev] [PATCH] gallium: introduce GLSL based interpolation rules.

2012-01-09 Thread Dave Airlie
From: Dave Airlie airl...@redhat.com

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.

Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/gallium/auxiliary/tgsi/tgsi_exec.c  |4 
 src/gallium/auxiliary/tgsi/tgsi_exec.h  |2 +-
 src/gallium/auxiliary/tgsi/tgsi_strings.c   |1 +
 src/gallium/drivers/softpipe/sp_quad_fs.c   |1 +
 src/gallium/drivers/softpipe/sp_state_derived.c |   10 --
 src/gallium/include/pipe/p_shader_tokens.h  |9 +
 src/mesa/state_tracker/st_program.c |2 +-
 7 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 61ab58a..451d84f 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -2377,6 +2377,10 @@ exec_declaration(struct tgsi_exec_machine *mach,
eval = eval_perspective_coef;
break;
 
+case TGSI_INTERPOLATE_UNSPECIFIED:
+   eval = mach-flatshade_unspecified ? eval_constant_coef : 
eval_perspective_coef;
+   break;
+
 default:
assert(0);
return;
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h 
b/src/gallium/auxiliary/tgsi/tgsi_exec.h
index ac021ce..7b1e785 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h
@@ -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_unspecified;
/* Conditional execution masks */
uint CondMask;  /** For IF/ELSE/ENDIF */
uint LoopMask;  /** For BGNLOOP/ENDLOOP */
diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c 
b/src/gallium/auxiliary/tgsi/tgsi_strings.c
index 973b9fe..02d766e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
@@ -114,6 +114,7 @@ const char *tgsi_type_names[5] =
 
 const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT] =
 {
+   UNSPECIFIED,
CONSTANT,
LINEAR,
PERSPECTIVE
diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c 
b/src/gallium/drivers/softpipe/sp_quad_fs.c
index 7b08cd0..8720947 100644
--- a/src/gallium/drivers/softpipe/sp_quad_fs.c
+++ b/src/gallium/drivers/softpipe/sp_quad_fs.c
@@ -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_unspecified = softpipe-rasterizer-flatshade ? TRUE : 
FALSE;
return softpipe-fs_variant-run( softpipe-fs_variant, machine, quad );
 }
 
diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c 
b/src/gallium/drivers/softpipe/sp_state_derived.c
index 5685997..1442a7e 100644
--- a/src/gallium/drivers/softpipe/sp_state_derived.c
+++ b/src/gallium/drivers/softpipe/sp_state_derived.c
@@ -100,6 +100,9 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
  case TGSI_INTERPOLATE_PERSPECTIVE:
 interp = INTERP_PERSPECTIVE;
 break;
+ case TGSI_INTERPOLATE_UNSPECIFIED:
+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_UNSPECIFIED) {
+   if (softpipe-rasterizer-flatshade)
+  interp = INTERP_CONSTANT;
+   else
+  interp = INTERP_PERSPECTIVE;
 }
 break;
  }
diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
b/src/gallium/include/pipe/p_shader_tokens.h
index 75e17a1..c9a79b4 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -97,10 +97,11 @@ enum tgsi_file_type {
 #define TGSI_WRITEMASK_YZW  0x0E
 #define TGSI_WRITEMASK_XYZW 0x0F
 
-#define TGSI_INTERPOLATE_CONSTANT  0
-#define TGSI_INTERPOLATE_LINEAR1
-#define TGSI_INTERPOLATE_PERSPECTIVE   2
-#define TGSI_INTERPOLATE_COUNT 3
+#define TGSI_INTERPOLATE_UNSPECIFIED   0 /* only legal for colors */
+#define TGSI_INTERPOLATE_CONSTANT  1
+#define TGSI_INTERPOLATE_LINEAR2
+#define TGSI_INTERPOLATE_PERSPECTIVE   3
+#define TGSI_INTERPOLATE_COUNT 4
 
 #define TGSI_CYLINDRICAL_WRAP_X (1  0)
 #define 

Re: [Mesa-dev] [PATCH] gallium: introduce GLSL based interpolation rules.

2012-01-09 Thread Brian Paul

On 01/09/2012 08:58 AM, Dave Airlie wrote:

From: Dave Airlieairl...@redhat.com

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.

Signed-off-by: Dave Airlieairl...@redhat.com
---
  src/gallium/auxiliary/tgsi/tgsi_exec.c  |4 
  src/gallium/auxiliary/tgsi/tgsi_exec.h  |2 +-
  src/gallium/auxiliary/tgsi/tgsi_strings.c   |1 +
  src/gallium/drivers/softpipe/sp_quad_fs.c   |1 +
  src/gallium/drivers/softpipe/sp_state_derived.c |   10 --
  src/gallium/include/pipe/p_shader_tokens.h  |9 +
  src/mesa/state_tracker/st_program.c |2 +-
  7 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 61ab58a..451d84f 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -2377,6 +2377,10 @@ exec_declaration(struct tgsi_exec_machine *mach,
 eval = eval_perspective_coef;
 break;

+case TGSI_INTERPOLATE_UNSPECIFIED:
+   eval = mach-flatshade_unspecified ? eval_constant_coef : 
eval_perspective_coef;
+   break;
+
  default:
 assert(0);
 return;
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.h 
b/src/gallium/auxiliary/tgsi/tgsi_exec.h
index ac021ce..7b1e785 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.h
@@ -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_unspecified;
 /* Conditional execution masks */
 uint CondMask;  /**  For IF/ELSE/ENDIF */
 uint LoopMask;  /**  For BGNLOOP/ENDLOOP */
diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c 
b/src/gallium/auxiliary/tgsi/tgsi_strings.c
index 973b9fe..02d766e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
@@ -114,6 +114,7 @@ const char *tgsi_type_names[5] =

  const char *tgsi_interpolate_names[TGSI_INTERPOLATE_COUNT] =
  {
+   UNSPECIFIED,
 CONSTANT,
 LINEAR,
 PERSPECTIVE
diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c 
b/src/gallium/drivers/softpipe/sp_quad_fs.c
index 7b08cd0..8720947 100644
--- a/src/gallium/drivers/softpipe/sp_quad_fs.c
+++ b/src/gallium/drivers/softpipe/sp_quad_fs.c
@@ -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_unspecified = softpipe-rasterizer-flatshade ? TRUE : 
FALSE;
 return softpipe-fs_variant-run( softpipe-fs_variant, machine, quad );
  }

diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c 
b/src/gallium/drivers/softpipe/sp_state_derived.c
index 5685997..1442a7e 100644
--- a/src/gallium/drivers/softpipe/sp_state_derived.c
+++ b/src/gallium/drivers/softpipe/sp_state_derived.c
@@ -100,6 +100,9 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
   case TGSI_INTERPOLATE_PERSPECTIVE:
  interp = INTERP_PERSPECTIVE;
  break;
+ case TGSI_INTERPOLATE_UNSPECIFIED:
+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_UNSPECIFIED) {
+   if (softpipe-rasterizer-flatshade)
+  interp = INTERP_CONSTANT;
+   else
+  interp = INTERP_PERSPECTIVE;
  }
  break;
   }
diff --git a/src/gallium/include/pipe/p_shader_tokens.h 
b/src/gallium/include/pipe/p_shader_tokens.h
index 75e17a1..c9a79b4 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -97,10 +97,11 @@ enum tgsi_file_type {
  #define TGSI_WRITEMASK_YZW  0x0E
  #define TGSI_WRITEMASK_XYZW 0x0F

-#define TGSI_INTERPOLATE_CONSTANT  0
-#define TGSI_INTERPOLATE_LINEAR1
-#define TGSI_INTERPOLATE_PERSPECTIVE   2
-#define TGSI_INTERPOLATE_COUNT 3
+#define TGSI_INTERPOLATE_UNSPECIFIED   0 /* only legal for colors */
+#define TGSI_INTERPOLATE_CONSTANT  1
+#define TGSI_INTERPOLATE_LINEAR2
+#define TGSI_INTERPOLATE_PERSPECTIVE   3
+#define