<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 23, 2018 at 1:26 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>
relaxed so offsets can be multiple of 4-bytes or multiple of size of the<br>
base type.<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>
 src/compiler/spirv/vtn_<wbr>variables.c              |  1 -<br>
 src/intel/compiler/brw_fs_nir.<wbr>cpp               | 16 +++++++++++-----<br>
 src/intel/vulkan/anv_nir_<wbr>lower_push_constants.c |  2 --<br>
 3 files changed, 11 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/vtn_<wbr>variables.c b/src/compiler/spirv/vtn_<wbr>variables.c<br>
index 81658afbd9..87236d0abd 100644<br>
--- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
+++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
@@ -760,7 +760,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>
diff --git a/src/intel/compiler/brw_fs_<wbr>nir.cpp b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
index abf9098252..27611a21d0 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,22 @@ 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 be multiple of 4<br>
+       * or multiple of the size of the destination type. 2 for 16-bits<br>
+       * types. <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+       */<br>
+      assert(instr->const_index[0] % 4 == 0 ||<br>
+             instr->const_index[0] % type_sz(dest.type) == 0);<br></blockquote><div><br></div><div>Doubles are required to be 8-byte aligned so we can just have the dest type size check.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       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] % 4 == 0 ||<br>
+                const_offset->u32[0] % type_sz(dest.type) == 0);<br></blockquote><div><br></div><div>Same here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         /* For 16-bit types we add the module of the const_index[0]<br>
+          * offset to access to not 32-bit aligned element */<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 b66552825b..ad60d0c824 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>
______________________________<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></div>