[Mesa-stable] [PATCH 1/2] spirv: Fix image writes with less than 4 components.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Sat Jul 14 23:24:55 UTC 2018


nir_validate complains in case less than 4 components are
provided.

CC: 18.1 <mesa-stable at lists.freedesktop.org>
---
 src/compiler/spirv/spirv_to_nir.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 48154303ff2..b082af57b10 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2450,10 +2450,20 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
    case SpvOpAtomicStore:
       intrin->src[3] = nir_src_for_ssa(vtn_ssa_value(b, w[4])->def);
       break;
-   case SpvOpImageWrite:
-      intrin->src[3] = nir_src_for_ssa(vtn_ssa_value(b, w[3])->def);
-      break;
+   case SpvOpImageWrite: {
+      nir_ssa_def *value = vtn_ssa_value(b, w[3])->def;
 
+      if (value->num_components < 4) {
+         unsigned swiz[4];
+         for (unsigned i = 0; i < 4; i++)
+            swiz[i] = i < value->num_components ? i : 0;
+
+         value = nir_swizzle(&b->nb, value, swiz, 4, false);
+      }
+
+      intrin->src[3] = nir_src_for_ssa(value);
+      break;
+   }
    case SpvOpAtomicCompareExchange:
    case SpvOpAtomicIIncrement:
    case SpvOpAtomicIDecrement:
-- 
2.18.0



More information about the mesa-stable mailing list