Commit a950d64a authored by Jesse Natalie's avatar Jesse Natalie Committed by Erik Faye-Lund

nir/spirv: Use image type instead of format for load/store intrinsics

parent 3862bd9d
...@@ -374,11 +374,10 @@ atomic3("atomic_counter_comp_swap") ...@@ -374,11 +374,10 @@ atomic3("atomic_counter_comp_swap")
# All image intrinsics come in three versions. One which take an image target # All image intrinsics come in three versions. One which take an image target
# passed as a deref chain as the first source, one which takes an index as the # passed as a deref chain as the first source, one which takes an index as the
# first source, and one which takes a bindless handle as the first source. # first source, and one which takes a bindless handle as the first source.
# In the first version, the image variable likely contains the memory and layout # In the first version, the image variable contains the memory and layout
# qualifiers that influence the semantics of the intrinsic. However, for OpenCL # qualifiers that influence the semantics of the intrinsic. In the second and
# images, the image variable doesn't contain format information, so it can be # third, the image format and access qualifiers are provided as constant
# provided in the intrinsic as well. In the second and third, the image format # indices.
# and access qualifiers are provided as constant indices.
# #
# All image intrinsics take a four-coordinate vector and a sample index as # All image intrinsics take a four-coordinate vector and a sample index as
# 2nd and 3rd sources, determining the location within the image that will be # 2nd and 3rd sources, determining the location within the image that will be
...@@ -387,16 +386,16 @@ atomic3("atomic_counter_comp_swap") ...@@ -387,16 +386,16 @@ atomic3("atomic_counter_comp_swap")
# argument with the value to be written, and image atomic operations take # argument with the value to be written, and image atomic operations take
# either one or two additional scalar arguments with the same meaning as in # either one or two additional scalar arguments with the same meaning as in
# the ARB_shader_image_load_store specification. # the ARB_shader_image_load_store specification.
def image(name, src_comp=[], deref_indices=[], **kwargs): def image(name, src_comp=[], extra_indices=[], **kwargs):
intrinsic("image_deref_" + name, src_comp=[1] + src_comp, intrinsic("image_deref_" + name, src_comp=[1] + src_comp,
indices=[ACCESS] + deref_indices, **kwargs) indices=[ACCESS] + extra_indices, **kwargs)
intrinsic("image_" + name, src_comp=[1] + src_comp, intrinsic("image_" + name, src_comp=[1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS], **kwargs) indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
intrinsic("bindless_image_" + name, src_comp=[1] + src_comp, intrinsic("bindless_image_" + name, src_comp=[1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS], **kwargs) indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
image("load", src_comp=[4, 1, 1], deref_indices=[FORMAT], dest_comp=0, flags=[CAN_ELIMINATE]) image("load", src_comp=[4, 1, 1], extra_indices=[TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
image("store", src_comp=[4, 1, 0, 1], deref_indices=[FORMAT]) image("store", src_comp=[4, 1, 0, 1], extra_indices=[TYPE])
image("atomic_add", src_comp=[4, 1, 1], dest_comp=1) image("atomic_add", src_comp=[4, 1, 1], dest_comp=1)
image("atomic_imin", src_comp=[4, 1, 1], dest_comp=1) image("atomic_imin", src_comp=[4, 1, 1], dest_comp=1)
image("atomic_umin", src_comp=[4, 1, 1], dest_comp=1) image("atomic_umin", src_comp=[4, 1, 1], dest_comp=1)
......
...@@ -3118,20 +3118,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, ...@@ -3118,20 +3118,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
*/ */
intrin->src[4] = nir_src_for_ssa(image.lod); intrin->src[4] = nir_src_for_ssa(image.lod);
if (opcode == SpvOpImageWrite) { if (opcode == SpvOpImageWrite)
/* Add type info to the intrinsic for storing to untyped OpenCL images */ nir_intrinsic_set_type(intrin, nir_get_nir_type_for_glsl_type(value->type));
enum pipe_format format = vtn_get_value_type(b, w[1])->image_format;
if (format == PIPE_FORMAT_NONE) {
switch (glsl_get_base_type(value->type)) {
case GLSL_TYPE_INT: format = PIPE_FORMAT_R32G32B32A32_SINT; break;
case GLSL_TYPE_UINT: format = PIPE_FORMAT_R32G32B32A32_SINT; break;
case GLSL_TYPE_FLOAT: format = PIPE_FORMAT_R32G32B32A32_FLOAT; break;
case GLSL_TYPE_FLOAT16: format = PIPE_FORMAT_R16G16B16A16_FLOAT; break;
default: unreachable("unexpected format");
}
}
nir_intrinsic_set_format(intrin, format);
}
break; break;
} }
...@@ -3196,20 +3184,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, ...@@ -3196,20 +3184,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
vtn_push_nir_ssa(b, w[2], result); vtn_push_nir_ssa(b, w[2], result);
if (opcode == SpvOpImageRead) { if (opcode == SpvOpImageRead)
/* Add type info to the intrinsic for reading from OpenCL images */ nir_intrinsic_set_type(intrin, nir_get_nir_type_for_glsl_type(type->type));
enum pipe_format format = vtn_get_value_type(b, w[1])->image_format;
if (format == PIPE_FORMAT_NONE) {
switch (glsl_get_base_type(type->type)) {
case GLSL_TYPE_INT: format = PIPE_FORMAT_R32G32B32A32_SINT; break;
case GLSL_TYPE_UINT: format = PIPE_FORMAT_R32G32B32A32_SINT; break;
case GLSL_TYPE_FLOAT: format = PIPE_FORMAT_R32G32B32A32_FLOAT; break;
case GLSL_TYPE_FLOAT16: format = PIPE_FORMAT_R16G16B16A16_FLOAT; break;
default: unreachable("unexpected format");
}
}
nir_intrinsic_set_format(intrin, format);
}
} else { } else {
nir_builder_instr_insert(&b->nb, &intrin->instr); nir_builder_instr_insert(&b->nb, &intrin->instr);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment