/* 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++;
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);
* 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);
} 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)
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
/**
- * 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
{
/**
- * 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
{
FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
} 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.
*/