Refactor code that converts between gl_vert_result and gl_frag_attrib.

Previously, this conversion was duplicated in several places in the
i965 driver.  This patch moves it to a common location in mtypes.h,
near the declaration of gl_vert_result and gl_frag_attrib.

I've also added comments to remind us that we may need to revisit the
conversion code when adding elements to gl_vert_result and
gl_frag_attrib.

Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Paul Berry
2011-08-30 11:46:29 -07:00
parent afaf024f57
commit 6489a1d5ba
5 changed files with 52 additions and 41 deletions
+2 -14
View File
@@ -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);
+2 -6
View File
@@ -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);
+1 -8
View File
@@ -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)
+4 -11
View File
@@ -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
+43 -2
View File
@@ -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
{
@@ -335,6 +339,43 @@ 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.
*/