<div dir="ltr"><div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br><br></div>Might be worth adding something to nir_validate at some point. Doesn't have to be today though.<br><br></div>--Jason<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 6, 2016 at 5:32 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
In 19a541f (nir: Get rid of nir_constant_data) a number of places that<br>
operated on nir_constant::values were mechanically converted to operate<br>
on the whole array without regard for the base type. Only<br>
GLSL_TYPE_FLOAT and GLSL_TYPE_DOUBLE can be matrices, so only those<br>
types can have data in the non-0 array element.<br>
<br>
See also b870394.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
Cc: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
Cc: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>><br>
---<br>
src/compiler/glsl/glsl_to_nir.<wbr>cpp | 32 ++++++++++++++++++------------<wbr>--<br>
src/compiler/nir/nir_print.c | 11 ++++++-----<br>
2 files changed, 24 insertions(+), 19 deletions(-)<br>
<br>
diff --git a/src/compiler/glsl/glsl_to_<wbr>nir.cpp b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
index 4debc37..18a53b6 100644<br>
--- a/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
+++ b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
@@ -207,17 +207,21 @@ constant_copy(ir_constant *ir, void *mem_ctx)<br>
ret->num_elements = 0;<br>
switch (ir->type->base_type) {<br>
case GLSL_TYPE_UINT:<br>
- for (unsigned c = 0; c < cols; c++) {<br>
- for (unsigned r = 0; r < rows; r++)<br>
- ret->values[c].u32[r] = ir->value.u[c * rows + r];<br>
- }<br>
+ /* Only float base types can be matrices. */<br>
+ assert(cols == 1);<br>
+<br>
+ for (unsigned r = 0; r < rows; r++)<br>
+ ret->values[0].u32[r] = ir->value.u[r];<br>
+<br>
break;<br>
<br>
case GLSL_TYPE_INT:<br>
- for (unsigned c = 0; c < cols; c++) {<br>
- for (unsigned r = 0; r < rows; r++)<br>
- ret->values[c].i32[r] = ir->value.i[c * rows + r];<br>
- }<br>
+ /* Only float base types can be matrices. */<br>
+ assert(cols == 1);<br>
+<br>
+ for (unsigned r = 0; r < rows; r++)<br>
+ ret->values[0].i32[r] = ir->value.i[r];<br>
+<br>
break;<br>
<br>
case GLSL_TYPE_FLOAT:<br>
@@ -235,12 +239,12 @@ constant_copy(ir_constant *ir, void *mem_ctx)<br>
break;<br>
<br>
case GLSL_TYPE_BOOL:<br>
- for (unsigned c = 0; c < cols; c++) {<br>
- for (unsigned r = 0; r < rows; r++) {<br>
- ret->values[c].u32[r] = ir->value.b[c * rows + r] ?<br>
- NIR_TRUE : NIR_FALSE;<br>
- }<br>
- }<br>
+ /* Only float base types can be matrices. */<br>
+ assert(cols == 1);<br>
+<br>
+ for (unsigned r = 0; r < rows; r++)<br>
+ ret->values[0].u32[r] = ir->value.b[r] ? NIR_TRUE : NIR_FALSE;<br>
+<br>
break;<br>
<br>
case GLSL_TYPE_STRUCT:<br>
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c<br>
index eb5f57f..e51b6f5 100644<br>
--- a/src/compiler/nir/nir_print.c<br>
+++ b/src/compiler/nir/nir_print.c<br>
@@ -303,11 +303,12 @@ print_constant(nir_constant *c, const struct glsl_type *type, print_state *state<br>
case GLSL_TYPE_UINT:<br>
case GLSL_TYPE_INT:<br>
case GLSL_TYPE_BOOL:<br>
- for (i = 0; i < cols; i++) {<br>
- for (j = 0; j < rows; j++) {<br>
- if (i + j > 0) fprintf(fp, ", ");<br>
- fprintf(fp, "0x%08x", c->values[i].u32[j]);<br>
- }<br>
+ /* Only float base types can be matrices. */<br>
+ assert(cols == 1);<br>
+<br>
+ for (i = 0; i < rows; i++) {<br>
+ if (i > 0) fprintf(fp, ", ");<br>
+ fprintf(fp, "0x%08x", c->values[0].u32[i]);<br>
}<br>
break;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.7.4<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>