i965: support for two-sided lighting on Sandybridge
VS places color attributes together so that SF unit can fetch the right attribute according to object orientation. This fixes light issue in mesa demo geartrain, projtex.
This commit is contained in:
@@ -1029,6 +1029,13 @@
|
||||
# define ATTRIBUTE_0_CONST_SOURCE_SHIFT 9
|
||||
# define ATTRIBUTE_0_SWIZZLE_SHIFT 6
|
||||
# define ATTRIBUTE_0_SOURCE_SHIFT 0
|
||||
|
||||
# define ATTRIBUTE_SWIZZLE_INPUTATTR 0
|
||||
# define ATTRIBUTE_SWIZZLE_INPUTATTR_FACING 1
|
||||
# define ATTRIBUTE_SWIZZLE_INPUTATTR_W 2
|
||||
# define ATTRIBUTE_SWIZZLE_INPUTATTR_FACING_W 3
|
||||
# define ATTRIBUTE_SWIZZLE_SHIFT 6
|
||||
|
||||
/* DW16: Point sprite texture coordinate enables */
|
||||
/* DW17: Constant interpolation enables */
|
||||
/* DW18: attr 0-7 wrap shortest enables */
|
||||
|
||||
@@ -130,6 +130,7 @@ static void brw_upload_vs_prog(struct brw_context *brw)
|
||||
key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
|
||||
key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
|
||||
ctx->Polygon.BackMode != GL_FILL);
|
||||
key.two_side_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
|
||||
|
||||
/* _NEW_POINT */
|
||||
if (ctx->Point.PointSprite) {
|
||||
@@ -157,7 +158,7 @@ static void brw_upload_vs_prog(struct brw_context *brw)
|
||||
*/
|
||||
const struct brw_tracked_state brw_vs_prog = {
|
||||
.dirty = {
|
||||
.mesa = _NEW_TRANSFORM | _NEW_POLYGON | _NEW_POINT,
|
||||
.mesa = _NEW_TRANSFORM | _NEW_POLYGON | _NEW_POINT | _NEW_LIGHT,
|
||||
.brw = BRW_NEW_VERTEX_PROGRAM,
|
||||
.cache = 0
|
||||
},
|
||||
|
||||
@@ -44,6 +44,7 @@ struct brw_vs_prog_key {
|
||||
GLuint nr_userclip:4;
|
||||
GLuint copy_edgeflag:1;
|
||||
GLuint point_coord_replace:8;
|
||||
GLuint two_side_color: 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -140,11 +140,13 @@ clear_current_const(struct brw_vs_compile *c)
|
||||
static void brw_vs_alloc_regs( struct brw_vs_compile *c )
|
||||
{
|
||||
struct intel_context *intel = &c->func.brw->intel;
|
||||
GLuint i, reg = 0, mrf;
|
||||
GLuint i, reg = 0, mrf, j;
|
||||
int attributes_in_vue;
|
||||
int first_reladdr_output;
|
||||
int max_constant;
|
||||
int constant = 0;
|
||||
int vert_result_reoder[VERT_RESULT_MAX];
|
||||
int bfc = 0;
|
||||
|
||||
/* Determine whether to use a real constant buffer or use a block
|
||||
* of GRF registers for constants. The later is faster but only
|
||||
@@ -291,7 +293,36 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )
|
||||
mrf = 4;
|
||||
|
||||
first_reladdr_output = get_first_reladdr_output(&c->vp->program);
|
||||
for (i = 0; i < VERT_RESULT_MAX; i++) {
|
||||
|
||||
for (i = 0; i < VERT_RESULT_MAX; i++)
|
||||
vert_result_reoder[i] = i;
|
||||
|
||||
/* adjust attribute order in VUE for BFC0/BFC1 on Gen6+ */
|
||||
if (intel->gen >= 6 && c->key.two_side_color) {
|
||||
if ((c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_COL1)) &&
|
||||
(c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC1))) {
|
||||
assert(c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_COL0));
|
||||
assert(c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC0));
|
||||
bfc = 2;
|
||||
} else if ((c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_COL0)) &&
|
||||
(c->prog_data.outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC0)))
|
||||
bfc = 1;
|
||||
|
||||
if (bfc) {
|
||||
for (i = 0; i < bfc; i++) {
|
||||
vert_result_reoder[VERT_RESULT_COL0 + i * 2 + 0] = VERT_RESULT_COL0 + i;
|
||||
vert_result_reoder[VERT_RESULT_COL0 + i * 2 + 1] = VERT_RESULT_BFC0 + i;
|
||||
}
|
||||
|
||||
for (i = VERT_RESULT_COL0 + bfc * 2; i < VERT_RESULT_BFC0 + bfc; i++) {
|
||||
vert_result_reoder[i] = i - bfc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < VERT_RESULT_MAX; j++) {
|
||||
i = vert_result_reoder[j];
|
||||
|
||||
if (c->prog_data.outputs_written & BITFIELD64_BIT(i)) {
|
||||
c->nr_outputs++;
|
||||
assert(i < Elements(c->regs[PROGRAM_OUTPUT]));
|
||||
|
||||
@@ -33,9 +33,10 @@
|
||||
#include "intel_batchbuffer.h"
|
||||
|
||||
static uint32_t
|
||||
get_attr_override(struct brw_context *brw, int fs_attr)
|
||||
get_attr_override(struct brw_context *brw, int fs_attr, int two_side_color)
|
||||
{
|
||||
int attr_index = 0, i, vs_attr;
|
||||
int bfc = 0;
|
||||
|
||||
if (fs_attr <= FRAG_ATTRIB_TEX7)
|
||||
vs_attr = fs_attr;
|
||||
@@ -57,6 +58,30 @@ get_attr_override(struct brw_context *brw, int fs_attr)
|
||||
attr_index++;
|
||||
}
|
||||
|
||||
assert(attr_index < 32);
|
||||
|
||||
if (two_side_color) {
|
||||
if ((brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_COL1)) &&
|
||||
(brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC1))) {
|
||||
assert(brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_COL0));
|
||||
assert(brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC0));
|
||||
bfc = 2;
|
||||
} else if ((brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_COL0)) &&
|
||||
(brw->vs.prog_data->outputs_written & BITFIELD64_BIT(VERT_RESULT_BFC0)))
|
||||
bfc = 1;
|
||||
}
|
||||
|
||||
if (bfc && (fs_attr <= FRAG_ATTRIB_TEX7 && fs_attr > FRAG_ATTRIB_WPOS)) {
|
||||
if (fs_attr == FRAG_ATTRIB_COL0)
|
||||
attr_index |= (ATTRIBUTE_SWIZZLE_INPUTATTR_FACING << ATTRIBUTE_SWIZZLE_SHIFT);
|
||||
else if (fs_attr == FRAG_ATTRIB_COL1 && bfc == 2) {
|
||||
attr_index++;
|
||||
attr_index |= (ATTRIBUTE_SWIZZLE_INPUTATTR_FACING << ATTRIBUTE_SWIZZLE_SHIFT);
|
||||
} else {
|
||||
attr_index += bfc;
|
||||
}
|
||||
}
|
||||
|
||||
return attr_index;
|
||||
}
|
||||
|
||||
@@ -75,6 +100,7 @@ upload_sf_state(struct brw_context *brw)
|
||||
GLboolean render_to_fbo = brw->intel.ctx.DrawBuffer->Name != 0;
|
||||
int attr = 0;
|
||||
int urb_start;
|
||||
int two_side_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
|
||||
|
||||
/* _NEW_TRANSFORM */
|
||||
if (ctx->Transform.ClipPlanesEnabled)
|
||||
@@ -224,7 +250,7 @@ upload_sf_state(struct brw_context *brw)
|
||||
|
||||
for (; attr < 64; attr++) {
|
||||
if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(attr)) {
|
||||
attr_overrides |= get_attr_override(brw, attr);
|
||||
attr_overrides |= get_attr_override(brw, attr, two_side_color);
|
||||
attr++;
|
||||
break;
|
||||
}
|
||||
@@ -232,7 +258,7 @@ upload_sf_state(struct brw_context *brw)
|
||||
|
||||
for (; attr < 64; attr++) {
|
||||
if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(attr)) {
|
||||
attr_overrides |= get_attr_override(brw, attr) << 16;
|
||||
attr_overrides |= get_attr_override(brw, attr, two_side_color) << 16;
|
||||
attr++;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user