diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index 5353f4e9540..1323bda58a9 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -308,6 +308,8 @@ emit_access_decorations(struct ntv_context *ctx, nir_variable *var, SpvId var_id switch (1 << bit) { case ACCESS_COHERENT: /* SpvDecorationCoherent can't be used with vulkan memory model */ + if (!ctx->sinfo->have_vulkan_memory_model) + spirv_builder_emit_decoration(&ctx->builder, var_id, SpvDecorationCoherent); break; case ACCESS_RESTRICT: spirv_builder_emit_decoration(&ctx->builder, var_id, SpvDecorationRestrict); @@ -2968,7 +2970,8 @@ emit_image_deref_store(struct ntv_context *ctx, nir_intrinsic_instr *intr) glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_SUBPASS_MS; SpvId sample = use_sample ? get_src(ctx, &intr->src[2], &atype) : 0; assert(nir_src_bit_size(intr->src[3]) == glsl_base_type_bit_size(glsl_get_sampler_result_type(type))); - spirv_builder_emit_image_write(&ctx->builder, img, coord, texel, 0, sample, 0); + bool coherent = ctx->sinfo->have_vulkan_memory_model && (nir_intrinsic_access(intr) & ACCESS_COHERENT); + spirv_builder_emit_image_write(&ctx->builder, img, coord, texel, 0, sample, coherent); } static SpvId @@ -3023,9 +3026,11 @@ emit_image_deref_load(struct ntv_context *ctx, nir_intrinsic_instr *intr) SpvId sample = use_sample ? get_src(ctx, &intr->src[2], &atype) : 0; SpvId dest_type = spirv_builder_type_vector(&ctx->builder, base_type, intr->def.num_components); + + bool coherent = ctx->sinfo->have_vulkan_memory_model && (nir_intrinsic_access(intr) & ACCESS_COHERENT); SpvId result = spirv_builder_emit_image_read(&ctx->builder, dest_type, - img, coord, 0, sample, 0, sparse); + img, coord, 0, sample, sparse, coherent); if (sparse) result = extract_sparse_load(ctx, result, dest_type, &intr->def); diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c index 31ca1987561..cc0099193e2 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.c @@ -1023,8 +1023,8 @@ spirv_builder_emit_image_read(struct spirv_builder *b, SpvId coordinate, SpvId lod, SpvId sample, - SpvId offset, - bool sparse) + bool sparse, + bool coherent) { SpvId result = spirv_builder_new_id(b); @@ -1041,9 +1041,9 @@ spirv_builder_emit_image_read(struct spirv_builder *b, extra_operands[num_extra_operands++] = sample; operand_mask |= SpvImageOperandsSampleMask; } - if (offset) { - extra_operands[num_extra_operands++] = offset; - operand_mask |= SpvImageOperandsOffsetMask; + if (coherent) { + extra_operands[num_extra_operands++] = spirv_builder_const_uint(b, 32, SpvScopeDevice); + operand_mask |= SpvImageOperandsMakeTexelVisibleMask | SpvImageOperandsNonPrivateTexelMask; } /* finalize num_extra_operands / extra_operands */ extra_operands[0] = operand_mask; @@ -1067,10 +1067,10 @@ spirv_builder_emit_image_write(struct spirv_builder *b, SpvId texel, SpvId lod, SpvId sample, - SpvId offset) + bool coherent) { SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone; - SpvId extra_operands[5]; + SpvId extra_operands[7]; int num_extra_operands = 1; if (lod) { extra_operands[num_extra_operands++] = lod; @@ -1080,9 +1080,9 @@ spirv_builder_emit_image_write(struct spirv_builder *b, extra_operands[num_extra_operands++] = sample; operand_mask |= SpvImageOperandsSampleMask; } - if (offset) { - extra_operands[num_extra_operands++] = offset; - operand_mask |= SpvImageOperandsOffsetMask; + if (coherent) { + extra_operands[num_extra_operands++] = spirv_builder_const_uint(b, 32, SpvScopeDevice); + operand_mask |= SpvImageOperandsMakeTexelAvailableMask | SpvImageOperandsNonPrivateTexelMask; } /* finalize num_extra_operands / extra_operands */ extra_operands[0] = operand_mask; diff --git a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h index b4a9cb5f227..be66495cbd5 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h +++ b/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h @@ -347,8 +347,8 @@ spirv_builder_emit_image_read(struct spirv_builder *b, SpvId coordinate, SpvId lod, SpvId sample, - SpvId offset, - bool sparse); + bool sparse, + bool coherent); void spirv_builder_emit_image_write(struct spirv_builder *b, @@ -357,7 +357,7 @@ spirv_builder_emit_image_write(struct spirv_builder *b, SpvId texel, SpvId lod, SpvId sample, - SpvId offset); + bool coherent); SpvId spirv_builder_emit_image_fetch(struct spirv_builder *b,