zink: fix spirv image operand ordering
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 19 Mar 2021 22:50:22 +0000 (18:50 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 23 Mar 2021 15:48:14 +0000 (15:48 +0000)
image operands are ordered by their operand's spirv value, meaning that
the availability operands need to go last here

Fixes: 882ab6afb77 ("zink: add spirv builder functions for image ops")

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9724>

src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c

index 1b74472..8c73c8f 100644 (file)
@@ -744,33 +744,30 @@ spirv_builder_emit_image_sample(struct spirv_builder *b,
 
    SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
    SpvId extra_operands[5];
-   int num_extra_operands = 0;
+   int num_extra_operands = 1;
    if (bias) {
-      extra_operands[++num_extra_operands] = bias;
+      extra_operands[num_extra_operands++] = bias;
       operand_mask |= SpvImageOperandsBiasMask;
    }
    if (lod) {
-      extra_operands[++num_extra_operands] = lod;
+      extra_operands[num_extra_operands++] = lod;
       operand_mask |= SpvImageOperandsLodMask;
    } else if (dx && dy) {
-      extra_operands[++num_extra_operands] = dx;
-      extra_operands[++num_extra_operands] = dy;
+      extra_operands[num_extra_operands++] = dx;
+      extra_operands[num_extra_operands++] = dy;
       operand_mask |= SpvImageOperandsGradMask;
    }
    assert(!(const_offset && offset));
    if (const_offset) {
-      extra_operands[++num_extra_operands] = const_offset;
+      extra_operands[num_extra_operands++] = const_offset;
       operand_mask |= SpvImageOperandsConstOffsetMask;
    } else if (offset) {
-      extra_operands[++num_extra_operands] = offset;
+      extra_operands[num_extra_operands++] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
 
    /* finalize num_extra_operands / extra_operands */
-   if (num_extra_operands > 0) {
-      extra_operands[0] = operand_mask;
-      num_extra_operands++;
-   }
+   extra_operands[0] = operand_mask;
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, operands + num_extra_operands);
    spirv_buffer_emit_word(&b->instructions, opcode | ((operands + num_extra_operands) << 16));
@@ -825,22 +822,21 @@ spirv_builder_emit_image_read(struct spirv_builder *b,
    SpvImageOperandsMask operand_mask = SpvImageOperandsMakeTexelVisibleMask | SpvImageOperandsNonPrivateTexelMask;
    SpvId extra_operands[5];
    int num_extra_operands = 1;
-   extra_operands[1] = spirv_builder_const_uint(b, 32, SpvScopeWorkgroup);
    if (lod) {
-      extra_operands[++num_extra_operands] = lod;
+      extra_operands[num_extra_operands++] = lod;
       operand_mask |= SpvImageOperandsLodMask;
    }
    if (sample) {
-      extra_operands[++num_extra_operands] = sample;
+      extra_operands[num_extra_operands++] = sample;
       operand_mask |= SpvImageOperandsSampleMask;
    }
    if (offset) {
-      extra_operands[++num_extra_operands] = offset;
+      extra_operands[num_extra_operands++] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
    /* finalize num_extra_operands / extra_operands */
    extra_operands[0] = operand_mask;
-   num_extra_operands++;
+   extra_operands[num_extra_operands++] = spirv_builder_const_uint(b, 32, SpvScopeWorkgroup);
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, 5 + num_extra_operands);
    spirv_buffer_emit_word(&b->instructions, SpvOpImageRead |
@@ -866,22 +862,21 @@ spirv_builder_emit_image_write(struct spirv_builder *b,
    SpvImageOperandsMask operand_mask = SpvImageOperandsMakeTexelAvailableMask | SpvImageOperandsNonPrivateTexelMask;
    SpvId extra_operands[5];
    int num_extra_operands = 1;
-   extra_operands[1] = spirv_builder_const_uint(b, 32, SpvScopeWorkgroup);
    if (lod) {
-      extra_operands[++num_extra_operands] = lod;
+      extra_operands[num_extra_operands++] = lod;
       operand_mask |= SpvImageOperandsLodMask;
    }
    if (sample) {
-      extra_operands[++num_extra_operands] = sample;
+      extra_operands[num_extra_operands++] = sample;
       operand_mask |= SpvImageOperandsSampleMask;
    }
    if (offset) {
-      extra_operands[++num_extra_operands] = offset;
+      extra_operands[num_extra_operands++] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
    /* finalize num_extra_operands / extra_operands */
    extra_operands[0] = operand_mask;
-   num_extra_operands++;
+   extra_operands[num_extra_operands++] = spirv_builder_const_uint(b, 32, SpvScopeWorkgroup);
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, 4 + num_extra_operands);
    spirv_buffer_emit_word(&b->instructions, SpvOpImageWrite |
@@ -910,30 +905,27 @@ spirv_builder_emit_image_gather(struct spirv_builder *b,
 
    SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
    SpvId extra_operands[4];
-   int num_extra_operands = 0;
+   int num_extra_operands = 1;
    if (lod) {
-      extra_operands[++num_extra_operands] = lod;
+      extra_operands[num_extra_operands++] = lod;
       operand_mask |= SpvImageOperandsLodMask;
    }
    if (sample) {
-      extra_operands[++num_extra_operands] = sample;
+      extra_operands[num_extra_operands++] = sample;
       operand_mask |= SpvImageOperandsSampleMask;
    }
    assert(!(const_offset && offset));
    if (const_offset) {
-      extra_operands[++num_extra_operands] = const_offset;
+      extra_operands[num_extra_operands++] = const_offset;
       operand_mask |= SpvImageOperandsConstOffsetMask;
    } else if (offset) {
-      extra_operands[++num_extra_operands] = offset;
+      extra_operands[num_extra_operands++] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
    if (dref)
       op = SpvOpImageDrefGather;
    /* finalize num_extra_operands / extra_operands */
-   if (num_extra_operands > 0) {
-      extra_operands[0] = operand_mask;
-      num_extra_operands++;
-   }
+   extra_operands[0] = operand_mask;
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, 6 + num_extra_operands);
    spirv_buffer_emit_word(&b->instructions, op |
@@ -965,29 +957,26 @@ spirv_builder_emit_image_fetch(struct spirv_builder *b,
 
    SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
    SpvId extra_operands[4];
-   int num_extra_operands = 0;
+   int num_extra_operands = 1;
    if (lod) {
-      extra_operands[++num_extra_operands] = lod;
+      extra_operands[num_extra_operands++] = lod;
       operand_mask |= SpvImageOperandsLodMask;
    }
    if (sample) {
-      extra_operands[++num_extra_operands] = sample;
+      extra_operands[num_extra_operands++] = sample;
       operand_mask |= SpvImageOperandsSampleMask;
    }
    assert(!(const_offset && offset));
    if (const_offset) {
-      extra_operands[++num_extra_operands] = const_offset;
+      extra_operands[num_extra_operands++] = const_offset;
       operand_mask |= SpvImageOperandsConstOffsetMask;
    } else if (offset) {
-      extra_operands[++num_extra_operands] = offset;
+      extra_operands[num_extra_operands++] = offset;
       operand_mask |= SpvImageOperandsOffsetMask;
    }
 
    /* finalize num_extra_operands / extra_operands */
-   if (num_extra_operands > 0) {
-      extra_operands[0] = operand_mask;
-      num_extra_operands++;
-   }
+   extra_operands[0] = operand_mask;
 
    spirv_buffer_prepare(&b->instructions, b->mem_ctx, 5 + num_extra_operands);
    spirv_buffer_emit_word(&b->instructions, SpvOpImageFetch |