On 26 November 2012 10:48, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 11/21/2012 07:23 PM, Chris Forbes wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Implements BGRA swizzle, sign recovery, and normalization<br>
as required by ARB_vertex_type_10_10_10_2_<u></u>rev.<br>
<br>
V2: Ported to the new VS backend, since that's all that's left;<br>
fixed normalization.<br>
<br>
V3: Moved fixups out of the GLSL-only path, so it works for FF/VP too.<br>
<br>
Signed-off-by: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>><br>
---<br>
src/mesa/drivers/dri/i965/brw_<u></u>vec4.h | 1 +<br>
src/mesa/drivers/dri/i965/brw_<u></u>vec4_emit.cpp | 2 +<br>
src/mesa/drivers/dri/i965/brw_<u></u>vec4_visitor.cpp | 124 ++++++++++++++++++++++---<br>
3 files changed, 114 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<u></u>brw_vec4.h b/src/mesa/drivers/dri/i965/<u></u>brw_vec4.h<br>
index ac1fb46..f0a2417 100644<br>
--- a/src/mesa/drivers/dri/i965/<u></u>brw_vec4.h<br>
+++ b/src/mesa/drivers/dri/i965/<u></u>brw_vec4.h<br>
@@ -376,6 +376,7 @@ public:<br>
void visit_instructions(const exec_list *list);<br>
<br>
void setup_vp_regs();<br>
+ void emit_attribute_fixups();<br>
void emit_vertex_program_code();<br>
void emit_vp_sop(uint32_t condmod, dst_reg dst,<br>
src_reg src0, src_reg src1, src_reg one);<br>
diff --git a/src/mesa/drivers/dri/i965/<u></u>brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/<u></u>brw_vec4_emit.cpp<br>
index a162420..dbfcd0f 100644<br>
--- a/src/mesa/drivers/dri/i965/<u></u>brw_vec4_emit.cpp<br>
+++ b/src/mesa/drivers/dri/i965/<u></u>brw_vec4_emit.cpp<br>
@@ -776,6 +776,8 @@ vec4_visitor::generate_vs_<u></u>instruction(vec4_instruction *instruction,<br>
bool<br>
vec4_visitor::run()<br>
{<br>
+ emit_attribute_fixups();<br>
+<br>
/* Generate VS IR for main(). (the visitor only descends into<br>
* functions called "main").<br>
*/<br>
diff --git a/src/mesa/drivers/dri/i965/<u></u>brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/<u></u>brw_vec4_visitor.cpp<br>
index a176e8a..f243699 100644<br>
--- a/src/mesa/drivers/dri/i965/<u></u>brw_vec4_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/<u></u>brw_vec4_visitor.cpp<br>
@@ -799,6 +799,117 @@ vec4_visitor::emit_if_gen6(ir_<u></u>if *ir)<br>
emit(IF(this->result, src_reg(0), BRW_CONDITIONAL_NZ));<br>
}<br>
<br>
+static dst_reg<br>
+with_writemask(dst_reg const & r, int mask)<br>
</blockquote>
<br></div></div>
Isn't that const in the wrong place? I'm super sharp about C++, but I thought most of the rules for references were the same as the rules for pointers.</blockquote><div><br>Actually it's fine. The rule is that "const" comes after the thing it's describing, except that if you put "const" at the beginning then the compiler knows what you mean. So:<br>
<br>"char * const *foo" means "foo is a pointer to a constant pointer to a char"<br>"char const **foo" means "foo is a pointer to a pointer to a constant char"<br>"const char **foo" also means "foo is a pointer to a pointer to a constant char"<br>
<br>I actually prefer Chris's style of putting the "const" after the type, because it means I only have to remember one rule ("const comes after the thing it describes"), but the grand tradition of code review has beaten me into conformance with the status quo :)<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+ dst_reg result = r;<br>
+ result.writemask = mask;<br>
+ return result;<br>
+}<br>
+<br>
+void<br>
+vec4_visitor::emit_attribute_<u></u>fixups()<br>
+{<br>
+ dst_reg * sign_recovery_shift = NULL;<br>
+ dst_reg * normalize_factor = NULL;<br>
+ dst_reg * es3_normalize_factor = NULL;<br>
+<br>
+ for (int i = 0; i < VERT_ATTRIB_MAX; i++) {<br>
+ if (prog_data->inputs_read & BITFIELD64_BIT(i)) {<br>
+ uint8_t wa_flags = c->key.gl_attrib_wa_flags[i];<br>
+ dst_reg * reg = new (mem_ctx) dst_reg(ATTR, i);<br>
+ dst_reg reg_d = *reg;<br>
+ reg_d.type = BRW_REGISTER_TYPE_D;<br>
+ dst_reg reg_ud = *reg;<br>
+ reg_ud.type = BRW_REGISTER_TYPE_UD;<br>
+<br>
+ /* Do GL_FIXED rescaling for GLES2.0. Our GL_FIXED attributes<br>
+ * come in as floating point conversions of the integer values.<br>
+ */<br>
+ if (wa_flags & BRW_ATTRIB_WA_COMPONENT_MASK) {<br>
+ dst_reg dst = *reg;<br>
+ dst.type = brw_type_for_base_type(glsl_<u></u>type::vec4_type);<br>
+ dst.writemask = (1 << (wa_flags & BRW_ATTRIB_WA_COMPONENT_MASK)) - 1;<br>
+ emit(MUL(dst, src_reg(dst), src_reg(1.0f / 65536.0f)));<br>
+ }<br>
+<br>
+ /* Do sign recovery for 2101010 formats if required. */<br>
+ if (wa_flags & BRW_ATTRIB_WA_SIGN) {<br>
+ if (!sign_recovery_shift) {<br>
+ // shift constant: <22,22,22,30><br>
+ sign_recovery_shift = new (mem_ctx) dst_reg(this, glsl_type::uvec4_type);<br>
+ emit(MOV(with_writemask(*sign_<u></u>recovery_shift, WRITEMASK_XYZ), src_reg(22u)));<br>
+ emit(MOV(with_writemask(*sign_<u></u>recovery_shift, WRITEMASK_W), src_reg(30u)));<br>
+ }<br>
+<br>
+ emit(SHL(reg_ud, src_reg(reg_ud), src_reg(*sign_recovery_shift))<u></u>);<br>
+ emit(ASR(reg_d, src_reg(reg_d), src_reg(*sign_recovery_shift))<u></u>);<br>
+ }<br>
+<br>
+ /* Apply BGRA swizzle if required. */<br>
+ if (wa_flags & BRW_ATTRIB_WA_BGRA) {<br>
+ src_reg temp = src_reg(*reg);<br>
+ temp.swizzle = BRW_SWIZZLE4(2,1,0,3);<br>
+ emit(MOV(*reg, temp));<br>
+ }<br>
+<br>
+ if (wa_flags & BRW_ATTRIB_WA_NORMALIZE_ES3) {<br>
+ // 2.3 signed normalization for ES3<br>
+ // f = c / (2^(b-1)-1)<br>
+ if (!es3_normalize_factor) {<br>
+ // mul constant: 1 / (2^(b-1) - 1)<br>
+ es3_normalize_factor = new (mem_ctx) dst_reg(this, glsl_type::vec4_type);<br>
+ emit(MOV(with_writemask(*es3_<u></u>normalize_factor, WRITEMASK_XYZ),<br>
+ src_reg(1.0f / ((1<<9) - 1))));<br>
+ emit(MOV(with_writemask(*es3_<u></u>normalize_factor, WRITEMASK_W),<br>
+ src_reg(1.0f / ((1<<1) - 1))));<br>
+ }<br>
+<br>
+ dst_reg dst = *reg;<br>
+ dst.type = brw_type_for_base_type(glsl_<u></u>type::vec4_type);<br>
+ emit(MOV(dst, src_reg(reg_d)));<br>
+ emit(MUL(dst, src_reg(dst), src_reg(*es3_normalize_factor)<u></u>));<br>
+ emit_minmax(BRW_CONDITIONAL_G, dst, src_reg(dst), src_reg(-1.0f));<br>
+ }<br>
+<br>
+ if (wa_flags & BRW_ATTRIB_WA_NORMALIZE) {<br>
+ // 2.1 unsigned normalization<br>
+ // f = c/(2^n-1)<br>
+<br>
+ // 2.2 signed normalization<br>
+ // f = (2c+1)/(2^n-1)<br>
+<br>
+ if (!normalize_factor) {<br>
+ // 1 / (2^b - 1) for b=<10,10,10,2><br>
+ normalize_factor = new (mem_ctx) dst_reg(this, glsl_type::vec4_type);<br>
+ emit(MOV(with_writemask(*<u></u>normalize_factor, WRITEMASK_XYZ),<br>
+ src_reg(1.0f / ((1<<10) - 1))));<br>
+ emit(MOV(with_writemask(*<u></u>normalize_factor, WRITEMASK_W),<br>
+ src_reg(1.0f / ((1<<2) - 1))));<br>
+ }<br>
+<br>
+ dst_reg dst = *reg;<br>
+ dst.type = brw_type_for_base_type(glsl_<u></u>type::vec4_type);<br>
+ emit(MOV(dst, src_reg((wa_flags & BRW_ATTRIB_WA_SIGN) ? reg_d : reg_ud)));<br>
+<br>
+ if (wa_flags & BRW_ATTRIB_WA_SIGN) {<br>
+ //emit(MAD(dst, src_reg(dst), src_reg(2.0f), src_reg(1.0f)));<br>
+ emit(MUL(dst, src_reg(dst), src_reg(2.0f)));<br>
+ emit(ADD(dst, src_reg(dst), src_reg(1.0f)));<br>
+ }<br>
+<br>
+ emit(MUL(dst, src_reg(dst), src_reg(*normalize_factor)));<br>
+ }<br>
+<br>
+ if (wa_flags & BRW_ATTRIB_WA_SCALE) {<br>
+ dst_reg dst = *reg;<br>
+ dst.type = brw_type_for_base_type(glsl_<u></u>type::vec4_type);<br>
+ emit(MOV(dst, src_reg((wa_flags & BRW_ATTRIB_WA_SIGN) ? reg_d : reg_ud)));<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
+<br>
void<br>
vec4_visitor::visit(ir_<u></u>variable *ir)<br>
{<br>
@@ -810,19 +921,6 @@ vec4_visitor::visit(ir_<u></u>variable *ir)<br>
switch (ir->mode) {<br>
case ir_var_in:<br>
reg = new(mem_ctx) dst_reg(ATTR, ir->location);<br>
-<br>
- /* Do GL_FIXED rescaling for GLES2.0. Our GL_FIXED attributes<br>
- * come in as floating point conversions of the integer values.<br>
- */<br>
- for (int i = ir->location; i < ir->location + type_size(ir->type); i++) {<br>
- uint8_t wa_flags = c->key.gl_attrib_wa_flags[i];<br>
- if (wa_flags & BRW_ATTRIB_WA_COMPONENT_MASK) {<br>
- dst_reg dst = *reg;<br>
- dst.type = brw_type_for_base_type(ir-><u></u>type);<br>
- dst.writemask = (1 << (wa_flags & BRW_ATTRIB_WA_COMPONENT_MASK)) - 1;<br>
- emit(MUL(dst, src_reg(dst), src_reg(1.0f / 65536.0f)));<br>
- }<br>
- }<br>
break;<br>
<br>
case ir_var_out:<br>
<br>
</blockquote>
<br></div></div><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>