summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/dri/i965/brw_fs.cpp16
-rw-r--r--src/mesa/drivers/dri/i965/brw_vs_constval.c8
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_pass2.c9
-rw-r--r--src/mesa/drivers/dri/i965/gen6_sf_state.c15
-rw-r--r--src/mesa/main/mtypes.h45
5 files changed, 52 insertions, 41 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8b85f3bc1ed..93323739a25 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -672,14 +672,7 @@ fs_visitor::calculate_urb_setup()
/* FINISHME: The sf doesn't map VS->FS inputs for us very well. */
for (unsigned int i = 0; i < VERT_RESULT_MAX; i++) {
if (c->key.vp_outputs_written & BITFIELD64_BIT(i)) {
- int fp_index;
-
- if (i >= VERT_RESULT_VAR0)
- fp_index = i - (VERT_RESULT_VAR0 - FRAG_ATTRIB_VAR0);
- else if (i <= VERT_RESULT_TEX7)
- fp_index = i;
- else
- fp_index = -1;
+ int fp_index = vert_result_to_frag_attrib(i);
if (fp_index >= 0)
urb_setup[fp_index] = urb_next++;
@@ -1828,17 +1821,12 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
key.vp_outputs_written |= BITFIELD64_BIT(FRAG_ATTRIB_WPOS);
for (int i = 0; i < FRAG_ATTRIB_MAX; i++) {
- int vp_index = -1;
-
if (!(fp->Base.InputsRead & BITFIELD64_BIT(i)))
continue;
key.proj_attrib_mask |= 1 << i;
- if (i <= FRAG_ATTRIB_TEX7)
- vp_index = i;
- else if (i >= FRAG_ATTRIB_VAR0)
- vp_index = i - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
+ int vp_index = vert_result_to_frag_attrib(i);
if (vp_index >= 0)
key.vp_outputs_written |= BITFIELD64_BIT(vp_index);
diff --git a/src/mesa/drivers/dri/i965/brw_vs_constval.c b/src/mesa/drivers/dri/i965/brw_vs_constval.c
index 47cc0a7da7a..4d9d4b714e8 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_constval.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_constval.c
@@ -144,14 +144,10 @@ static void calc_sizes( struct tracker *t )
* which describes the fragment program input sizes.
*/
for (vertRes = VERT_RESULT_TEX0; vertRes < VERT_RESULT_MAX; vertRes++) {
- GLint fragAttrib;
/* map vertex program output index to fragment program input index */
- if (vertRes <= VERT_RESULT_TEX7)
- fragAttrib = FRAG_ATTRIB_TEX0 + vertRes - VERT_RESULT_TEX0;
- else if (vertRes >= VERT_RESULT_VAR0)
- fragAttrib = FRAG_ATTRIB_VAR0 + vertRes - VERT_RESULT_VAR0;
- else
+ GLint fragAttrib = vert_result_to_frag_attrib(vertRes);
+ if (fragAttrib < 0)
continue;
assert(fragAttrib >= FRAG_ATTRIB_TEX0);
assert(fragAttrib <= FRAG_ATTRIB_MAX);
diff --git a/src/mesa/drivers/dri/i965/brw_wm_pass2.c b/src/mesa/drivers/dri/i965/brw_wm_pass2.c
index 8c2b9e7020b..f1d70f79a77 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_pass2.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_pass2.c
@@ -94,14 +94,7 @@ static void init_registers( struct brw_wm_compile *c )
} else {
for (j = 0; j < VERT_RESULT_MAX; j++) {
if (c->key.vp_outputs_written & BITFIELD64_BIT(j)) {
- int fp_index;
-
- if (j >= VERT_RESULT_VAR0)
- fp_index = j - (VERT_RESULT_VAR0 - FRAG_ATTRIB_VAR0);
- else if (j <= VERT_RESULT_TEX7)
- fp_index = j;
- else
- fp_index = -1;
+ int fp_index = vert_result_to_frag_attrib(j);
nr_interp_regs++;
if (fp_index >= 0)
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 5bb731dc8fd..714914aa6bb 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -35,19 +35,12 @@
uint32_t
get_attr_override(struct brw_context *brw, int fs_attr, int two_side_color)
{
- int attr_index = 0, i, vs_attr;
+ int attr_index = 0, i;
int bfc = 0;
+ int vs_attr = frag_attrib_to_vert_result(fs_attr);
- if (fs_attr <= FRAG_ATTRIB_TEX7)
- vs_attr = fs_attr;
- else if (fs_attr == FRAG_ATTRIB_FACE)
- vs_attr = 0; /* XXX */
- else if (fs_attr == FRAG_ATTRIB_PNTC)
- vs_attr = 0; /* XXX */
- else {
- assert(fs_attr >= FRAG_ATTRIB_VAR0);
- vs_attr = fs_attr - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
- }
+ if (vs_attr < 0)
+ vs_attr = 0;
/* Find the source index (0 = first attribute after the 4D position)
* for this output attribute. attr is currently a VERT_RESULT_* but should
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index ad5979796d6..bf96fdf9635 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -215,7 +215,9 @@ typedef enum
/**
- * Indexes for vertex program result attributes
+ * Indexes for vertex program result attributes. Note that
+ * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make
+ * assumptions about the layout of this enum.
*/
typedef enum
{
@@ -313,7 +315,9 @@ typedef enum
/**
- * Indexes for fragment program input attributes.
+ * Indexes for fragment program input attributes. Note that
+ * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make
+ * assumptions about the layout of this enum.
*/
typedef enum
{
@@ -336,6 +340,43 @@ typedef enum
} gl_frag_attrib;
/**
+ * Convert from a gl_vert_result value to the corresponding gl_frag_attrib.
+ *
+ * VERT_RESULT_HPOS is converted to FRAG_ATTRIB_WPOS.
+ *
+ * gl_vert_result values which have no corresponding gl_frag_attrib
+ * (VERT_RESULT_PSIZ, VERT_RESULT_BFC0, VERT_RESULT_BFC1, and
+ * VERT_RESULT_EDGE) are converted to a value of -1.
+ */
+static inline int vert_result_to_frag_attrib(int vert_result)
+{
+ if (vert_result >= VERT_RESULT_VAR0)
+ return vert_result - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0;
+ else if (vert_result <= VERT_RESULT_TEX7)
+ return vert_result;
+ else
+ return -1;
+}
+
+/**
+ * Convert from a gl_frag_attrib value to the corresponding gl_vert_result.
+ *
+ * FRAG_ATTRIB_WPOS is converted to VERT_RESULT_HPOS.
+ *
+ * gl_frag_attrib values which have no corresponding gl_vert_result
+ * (FRAG_ATTRIB_FACE and FRAG_ATTRIB_PNTC) are converted to a value of -1.
+ */
+static inline int frag_attrib_to_vert_result(int frag_attrib)
+{
+ if (frag_attrib <= FRAG_ATTRIB_TEX7)
+ return frag_attrib;
+ else if (frag_attrib >= FRAG_ATTRIB_VAR0)
+ return frag_attrib - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;
+ else
+ return -1;
+}
+
+/**
* Bitflags for fragment program input attributes.
*/
/*@{*/