<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Feb 26, 2018 at 6:01 AM, Jose Maria Casanova Crespo <span dir="ltr"><<a href="mailto:jmcasanova@igalia.com" target="_blank">jmcasanova@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The introduction of 16-bit types with VK_KHR_16bit_storages implies that<br>
push constant offsets could be multiple of 2-bytes. Some assertions are<br>
updated so offsets should be just multiple of size of the base type but<br>
in some cases we can not assume it as doubles aren't aligned to 8 bytes<br>
in some cases.<br>
<br>
For 16-bit types, the push constant offset takes into account the<br>
internal offset in the 32-bit uniform bucket adding 2-bytes when we access<br>
not 32-bit aligned elements. In all 32-bit aligned cases it just becomes 0.<br>
<br>
v2: Assert offsets to be aligned to the dest type size. (Jason Ekstrand)<br>
---<br>
src/compiler/spirv/vtn_<wbr>variables.c | 2 --<br>
src/intel/compiler/brw_fs_nir.<wbr>cpp | 15 ++++++++++-----<br>
src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c | 2 --<br>
3 files changed, 10 insertions(+), 9 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/vtn_<wbr>variables.c b/src/compiler/spirv/vtn_<wbr>variables.c<br>
index 105b33a5671..7e8a090adde 100644<br>
--- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
+++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
@@ -753,8 +753,6 @@ _vtn_load_store_tail(struct vtn_builder *b, nir_intrinsic_op op, bool load,<br>
}<br>
<br>
if (op == nir_intrinsic_load_push_<wbr>constant) {<br>
- vtn_assert(access_offset % 4 == 0);<br>
-<br>
nir_intrinsic_set_base(instr, access_offset);<br>
nir_intrinsic_set_range(instr, access_size);<br>
}<br>
diff --git a/src/intel/compiler/brw_fs_<wbr>nir.cpp b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
index 03d0bba24a8..6f721ac3a43 100644<br>
--- a/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
+++ b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
@@ -3887,16 +3887,21 @@ fs_visitor::nir_emit_<wbr>intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr<br>
break;<br>
<br>
case nir_intrinsic_load_uniform: {<br>
- /* Offsets are in bytes but they should always be multiples of 4 */<br>
- assert(instr->const_index[0] % 4 == 0);<br>
+ /* Offsets are in bytes but they should always aligned to<br>
+ * the type size<br>
+ */<br>
+ assert(instr->const_index[0] % 4 == 0||<br></blockquote><div><br></div><div>Hrm... I was going to say you don't need the first half of the assert but then I remembered that NIR may place doubles with bad alignments because we really don't care that much if they're getting pulled. In any case, you need a space before "||". :-)<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ instr->const_index[0] % type_sz(dest.type) == 0);<br>
<br>
fs_reg src(UNIFORM, instr->const_index[0] / 4, dest.type);<br>
<br>
nir_const_value *const_offset = nir_src_as_const_value(instr-><wbr>src[0]);<br>
if (const_offset) {<br>
- /* Offsets are in bytes but they should always be multiples of 4 */<br>
- assert(const_offset->u32[0] % 4 == 0);<br>
- src.offset = const_offset->u32[0];<br>
+ assert(const_offset->u32[0] % type_sz(dest.type) == 0);<br>
+ /* For 16-bit types we add the module of the const_index[0]<br>
+ * offset to access to not 32-bit aligned element<br>
+ */<br>
+ src.offset = const_offset->u32[0] + instr->const_index[0] % 4;<br>
<br>
for (unsigned j = 0; j < instr->num_components; j++) {<br>
bld.MOV(offset(dest, bld, j), offset(src, bld, j));<br>
diff --git a/src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c b/src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c<br>
index b66552825b9..ad60d0c824e 100644<br>
--- a/src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c<br>
+++ b/src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c<br>
@@ -41,8 +41,6 @@ anv_nir_lower_push_constants(<wbr>nir_shader *shader)<br>
if (intrin->intrinsic != nir_intrinsic_load_push_<wbr>constant)<br>
continue;<br>
<br>
- assert(intrin->const_index[0] % 4 == 0);<br>
-<br>
/* We just turn them into uniform loads */<br>
intrin->intrinsic = nir_intrinsic_load_uniform;<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
</font></span></blockquote></div><br></div></div>