summaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv
diff options
context:
space:
mode:
authorSamuel Pitoiset <[email protected]>2020-01-06 08:27:49 +0100
committerSamuel Pitoiset <[email protected]>2020-01-09 07:58:33 +0100
commit1b808d208f7ae6b7934ada37378c654991a5ca5a (patch)
tree033069ef6ba151e411a279e18550cc3bbdc28d56 /src/compiler/spirv
parent37bfd854c71be8ace37080fbca36d0a1ef68fb8a (diff)
spirv,nir: add new lod parameter to image_{load,store} intrinsics
SPV_AMD_shader_image_load_store_lod allows to use a lod parameter with OpImageRead, OpImageWrite and OpImageSparseRead. According to the specification, this parameter should be a 32-bit integer. It is initialized to 0 when no lod parameter is found during SPIR-V->NIR translation. Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c32
-rw-r--r--src/compiler/spirv/vtn_private.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index a4b09a404df..e54fc6906b8 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2710,6 +2710,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
val->image->image = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
val->image->coord = get_image_coord(b, w[4]);
val->image->sample = vtn_ssa_value(b, w[5])->def;
+ val->image->lod = nir_imm_int(&b->nb, 0);
return;
}
@@ -2748,6 +2749,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
image.image = vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
image.coord = NULL;
image.sample = NULL;
+ image.lod = NULL;
break;
case SpvOpImageRead: {
@@ -2774,6 +2776,14 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
scope = vtn_constant_uint(b, w[arg]);
}
+ if (operands & SpvImageOperandsLodMask) {
+ uint32_t arg = image_operand_arg(b, w, count, 5,
+ SpvImageOperandsLodMask);
+ image.lod = vtn_ssa_value(b, w[arg])->def;
+ } else {
+ image.lod = nir_imm_int(&b->nb, 0);
+ }
+
/* TODO: Volatile. */
break;
@@ -2805,6 +2815,14 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
scope = vtn_constant_uint(b, w[arg]);
}
+ if (operands & SpvImageOperandsLodMask) {
+ uint32_t arg = image_operand_arg(b, w, count, 4,
+ SpvImageOperandsLodMask);
+ image.lod = vtn_ssa_value(b, w[arg])->def;
+ } else {
+ image.lod = nir_imm_int(&b->nb, 0);
+ }
+
/* TODO: Volatile. */
break;
@@ -2861,6 +2879,14 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
case SpvOpAtomicLoad:
case SpvOpImageQuerySize:
case SpvOpImageRead:
+ if (opcode == SpvOpImageRead || opcode == SpvOpAtomicLoad) {
+ /* Only OpImageRead can support a lod parameter if
+ * SPV_AMD_shader_image_load_store_lod is used but the current NIR
+ * intrinsics definition for atomics requires us to set it for
+ * OpAtomicLoad.
+ */
+ intrin->src[3] = nir_src_for_ssa(image.lod);
+ }
break;
case SpvOpAtomicStore:
case SpvOpImageWrite: {
@@ -2870,6 +2896,12 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
assert(op == nir_intrinsic_image_deref_store);
intrin->num_components = 4;
intrin->src[3] = nir_src_for_ssa(expand_to_vec4(&b->nb, value));
+ /* Only OpImageWrite can support a lod parameter if
+ * SPV_AMD_shader_image_load_store_lod is used but the current NIR
+ * intrinsics definition for atomics requires us to set it for
+ * OpAtomicStore.
+ */
+ intrin->src[4] = nir_src_for_ssa(image.lod);
break;
}
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 7c7527582b4..436bac8a664 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -534,6 +534,7 @@ struct vtn_image_pointer {
struct vtn_pointer *image;
nir_ssa_def *coord;
nir_ssa_def *sample;
+ nir_ssa_def *lod;
};
struct vtn_sampled_image {