nir/vtn: ImageSizeLod op can be applied to images

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5242>
This commit is contained in:
Jesse Natalie
2020-05-11 09:08:15 -07:00
committed by Marge Bot
parent 701cb9d60c
commit 5ce6821900

View File

@@ -3000,6 +3000,14 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
access |= ACCESS_COHERENT; access |= ACCESS_COHERENT;
break; break;
case SpvOpImageQuerySizeLod:
res_val = vtn_untyped_value(b, w[3]);
image.image = vtn_get_image(b, w[3]);
image.coord = NULL;
image.sample = NULL;
image.lod = vtn_ssa_value(b, w[4])->def;
break;
case SpvOpImageQuerySize: case SpvOpImageQuerySize:
res_val = vtn_untyped_value(b, w[3]); res_val = vtn_untyped_value(b, w[3]);
image.image = vtn_get_image(b, w[3]); image.image = vtn_get_image(b, w[3]);
@@ -3094,6 +3102,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
switch (opcode) { switch (opcode) {
#define OP(S, N) case SpvOp##S: op = nir_intrinsic_image_deref_##N; break; #define OP(S, N) case SpvOp##S: op = nir_intrinsic_image_deref_##N; break;
OP(ImageQuerySize, size) OP(ImageQuerySize, size)
OP(ImageQuerySizeLod, size)
OP(ImageRead, load) OP(ImageRead, load)
OP(ImageWrite, store) OP(ImageWrite, store)
OP(AtomicLoad, load) OP(AtomicLoad, load)
@@ -3122,10 +3131,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
intrin->src[0] = nir_src_for_ssa(&image.image->dest.ssa); intrin->src[0] = nir_src_for_ssa(&image.image->dest.ssa);
if (opcode == SpvOpImageQuerySize) { /* size doesn't take non-lod coordinate parameters */
/* ImageQuerySize only has an LOD which is currently always 0 */ if (opcode != SpvOpImageQuerySize && opcode != SpvOpImageQuerySizeLod) {
intrin->src[1] = nir_src_for_ssa(nir_imm_int(&b->nb, 0));
} else {
/* The image coordinate is always 4 components but we may not have that /* The image coordinate is always 4 components but we may not have that
* many. Swizzle to compensate. * many. Swizzle to compensate.
*/ */
@@ -3150,17 +3157,20 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
nir_intrinsic_set_access(intrin, access); nir_intrinsic_set_access(intrin, access);
switch (opcode) { switch (opcode) {
case SpvOpAtomicLoad:
case SpvOpImageQuerySize: case SpvOpImageQuerySize:
intrin->src[1] = nir_src_for_ssa(nir_imm_int(&b->nb, 0));
break;
case SpvOpImageQuerySizeLod:
intrin->src[1] = nir_src_for_ssa(image.lod);
break;
case SpvOpAtomicLoad:
case SpvOpImageRead: case SpvOpImageRead:
if (opcode == SpvOpImageRead || opcode == SpvOpAtomicLoad) { /* Only OpImageRead can support a lod parameter if
/* Only OpImageRead can support a lod parameter if * SPV_AMD_shader_image_load_store_lod is used but the current NIR
* SPV_AMD_shader_image_load_store_lod is used but the current NIR * intrinsics definition for atomics requires us to set it for
* intrinsics definition for atomics requires us to set it for * OpAtomicLoad.
* OpAtomicLoad. */
*/ intrin->src[3] = nir_src_for_ssa(image.lod);
intrin->src[3] = nir_src_for_ssa(image.lod);
}
break; break;
case SpvOpAtomicStore: case SpvOpAtomicStore:
case SpvOpImageWrite: { case SpvOpImageWrite: {
@@ -5068,7 +5078,6 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
case SpvOpImageFetch: case SpvOpImageFetch:
case SpvOpImageGather: case SpvOpImageGather:
case SpvOpImageDrefGather: case SpvOpImageDrefGather:
case SpvOpImageQuerySizeLod:
case SpvOpImageQueryLod: case SpvOpImageQueryLod:
case SpvOpImageQueryLevels: case SpvOpImageQueryLevels:
case SpvOpImageQuerySamples: case SpvOpImageQuerySamples:
@@ -5081,6 +5090,7 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
vtn_handle_image(b, opcode, w, count); vtn_handle_image(b, opcode, w, count);
break; break;
case SpvOpImageQuerySizeLod:
case SpvOpImageQuerySize: { case SpvOpImageQuerySize: {
struct vtn_type *image_type = vtn_get_value_type(b, w[3]); struct vtn_type *image_type = vtn_get_value_type(b, w[3]);
vtn_assert(image_type->base_type == vtn_base_type_image); vtn_assert(image_type->base_type == vtn_base_type_image);