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")
# 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
# 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
# qualifiers that influence the semantics of the intrinsic. However, for OpenCL
# images, the image variable doesn't contain format information, so it can be
# provided in the intrinsic as well. In the second and third, the image format
# and access qualifiers are provided as constant indices.
# In the first version, the image variable contains the memory and layout
# qualifiers that influence the semantics of the intrinsic. In the second and
# third, the image format and access qualifiers are provided as constant
# indices.
#
# 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
......@@ -387,16 +386,16 @@ atomic3("atomic_counter_comp_swap")
# 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
# 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,
indices=[ACCESS] + deref_indices, **kwargs)
indices=[ACCESS] + extra_indices, **kwargs)
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,
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("store", src_comp=[4, 1, 0, 1], deref_indices=[FORMAT])
image("load", src_comp=[4, 1, 1], extra_indices=[TYPE], dest_comp=0, flags=[CAN_ELIMINATE])
image("store", src_comp=[4, 1, 0, 1], extra_indices=[TYPE])
image("atomic_add", 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)
......
......@@ -3118,20 +3118,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
*/
intrin->src[4] = nir_src_for_ssa(image.lod);
if (opcode == SpvOpImageWrite) {
/* Add type info to the intrinsic for storing to untyped OpenCL images */
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);
}
if (opcode == SpvOpImageWrite)
nir_intrinsic_set_type(intrin, nir_get_nir_type_for_glsl_type(value->type));
break;
}
......@@ -3196,20 +3184,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
vtn_push_nir_ssa(b, w[2], result);
if (opcode == SpvOpImageRead) {
/* Add type info to the intrinsic for reading from OpenCL images */
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);
}
if (opcode == SpvOpImageRead)
nir_intrinsic_set_type(intrin, nir_get_nir_type_for_glsl_type(type->type));
} else {
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