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

microsoft/clc: Use image type instead of format for image load/store lowering

parent 59d40ca6
...@@ -98,30 +98,6 @@ clc_print_kernels_info(const struct clc_object *obj) ...@@ -98,30 +98,6 @@ clc_print_kernels_info(const struct clc_object *obj)
} }
} }
static enum glsl_base_type
glsl_base_type_for_image_pipe_format(enum pipe_format format)
{
switch (format) {
case PIPE_FORMAT_R32G32B32A32_FLOAT: return GLSL_TYPE_FLOAT;
case PIPE_FORMAT_R16G16B16A16_FLOAT: return GLSL_TYPE_FLOAT16;
case PIPE_FORMAT_R32G32B32A32_SINT: return GLSL_TYPE_INT;
case PIPE_FORMAT_R32G32B32A32_UINT: return GLSL_TYPE_UINT;
default: unreachable("Unexpected image format");
}
}
static enum pipe_format
pipe_format_for_nir_format(enum nir_alu_type format)
{
switch (format) {
case nir_type_float: return PIPE_FORMAT_R32G32B32A32_FLOAT;
case nir_type_float16: return PIPE_FORMAT_R16G16B16A16_FLOAT;
case nir_type_int: return PIPE_FORMAT_R32G32B32A32_SINT;
case nir_type_uint: return PIPE_FORMAT_R32G32B32A32_UINT;
default: unreachable("Unexpected nir format");
}
}
struct clc_image_lower_context struct clc_image_lower_context
{ {
struct clc_dxil_metadata *metadata; struct clc_dxil_metadata *metadata;
...@@ -135,12 +111,11 @@ struct clc_image_lower_context ...@@ -135,12 +111,11 @@ struct clc_image_lower_context
static nir_ssa_def * static nir_ssa_def *
lower_image_deref_impl(nir_builder *b, struct clc_image_lower_context *context, lower_image_deref_impl(nir_builder *b, struct clc_image_lower_context *context,
const struct glsl_type *new_var_type, const struct glsl_type *new_var_type,
unsigned *num_bindings, enum pipe_format image_format) unsigned *num_bindings)
{ {
nir_variable *in_var = nir_deref_instr_get_variable(context->deref); nir_variable *in_var = nir_deref_instr_get_variable(context->deref);
nir_variable *uniform = nir_variable_create(b->shader, nir_var_uniform, new_var_type, NULL); nir_variable *uniform = nir_variable_create(b->shader, nir_var_uniform, new_var_type, NULL);
uniform->data.access = in_var->data.access; uniform->data.access = in_var->data.access;
uniform->data.image.format = image_format;
uniform->data.binding = in_var->data.binding; uniform->data.binding = in_var->data.binding;
if (context->num_buf_ids > 0) { if (context->num_buf_ids > 0) {
// Need to assign a new binding // Need to assign a new binding
...@@ -156,7 +131,7 @@ lower_image_deref_impl(nir_builder *b, struct clc_image_lower_context *context, ...@@ -156,7 +131,7 @@ lower_image_deref_impl(nir_builder *b, struct clc_image_lower_context *context,
static nir_ssa_def * static nir_ssa_def *
lower_read_only_image_deref(nir_builder *b, struct clc_image_lower_context *context, lower_read_only_image_deref(nir_builder *b, struct clc_image_lower_context *context,
enum pipe_format image_format) nir_alu_type image_type)
{ {
nir_variable *in_var = nir_deref_instr_get_variable(context->deref); nir_variable *in_var = nir_deref_instr_get_variable(context->deref);
...@@ -165,20 +140,20 @@ lower_read_only_image_deref(nir_builder *b, struct clc_image_lower_context *cont ...@@ -165,20 +140,20 @@ lower_read_only_image_deref(nir_builder *b, struct clc_image_lower_context *cont
const struct glsl_type *new_var_type = const struct glsl_type *new_var_type =
glsl_sampler_type(glsl_get_sampler_dim(in_var->type), glsl_sampler_type(glsl_get_sampler_dim(in_var->type),
false, glsl_sampler_type_is_array(in_var->type), false, glsl_sampler_type_is_array(in_var->type),
glsl_base_type_for_image_pipe_format(image_format)); nir_get_glsl_base_type_for_nir_type(image_type));
return lower_image_deref_impl(b, context, new_var_type, context->num_srvs, image_format); return lower_image_deref_impl(b, context, new_var_type, context->num_srvs);
} }
static nir_ssa_def * static nir_ssa_def *
lower_read_write_image_deref(nir_builder *b, struct clc_image_lower_context *context, lower_read_write_image_deref(nir_builder *b, struct clc_image_lower_context *context,
enum pipe_format image_format) nir_alu_type image_type)
{ {
nir_variable *in_var = nir_deref_instr_get_variable(context->deref); nir_variable *in_var = nir_deref_instr_get_variable(context->deref);
const struct glsl_type *new_var_type = const struct glsl_type *new_var_type =
glsl_image_type(glsl_get_sampler_dim(in_var->type), glsl_image_type(glsl_get_sampler_dim(in_var->type),
glsl_sampler_type_is_array(in_var->type), glsl_sampler_type_is_array(in_var->type),
glsl_base_type_for_image_pipe_format(image_format)); nir_get_glsl_base_type_for_nir_type(image_type));
return lower_image_deref_impl(b, context, new_var_type, context->num_uavs, image_format); return lower_image_deref_impl(b, context, new_var_type, context->num_uavs);
} }
static void static void
...@@ -230,22 +205,22 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont ...@@ -230,22 +205,22 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont
switch (intrinsic->intrinsic) { switch (intrinsic->intrinsic) {
case nir_intrinsic_image_deref_load: case nir_intrinsic_image_deref_load:
case nir_intrinsic_image_deref_store: { case nir_intrinsic_image_deref_store: {
enum pipe_format intr_format = nir_intrinsic_format(intrinsic); dest_type = nir_intrinsic_type(intrinsic);
switch (intr_format) { switch (nir_alu_type_get_base_type(dest_type)) {
case PIPE_FORMAT_R32G32B32A32_FLOAT: type = FLOAT4; dest_type = nir_type_float; break; case nir_type_float: type = FLOAT4; break;
case PIPE_FORMAT_R32G32B32A32_SINT: type = INT4; dest_type = nir_type_int; break; case nir_type_int: type = INT4; break;
case PIPE_FORMAT_R32G32B32A32_UINT: type = UINT4; dest_type = nir_type_uint; break; case nir_type_uint: type = UINT4; break;
default: unreachable("Unsupported image format for load."); default: unreachable("Unsupported image type for load.");
} }
nir_ssa_def *image_deref = uniform_deref_dests[type]; nir_ssa_def *image_deref = uniform_deref_dests[type];
if (!image_deref) { if (!image_deref) {
const struct glsl_type *new_var_type; const struct glsl_type *new_var_type;
if (in_var->data.access & ACCESS_NON_WRITEABLE) { if (in_var->data.access & ACCESS_NON_WRITEABLE) {
image_deref = lower_read_only_image_deref(b, context, intr_format); image_deref = lower_read_only_image_deref(b, context, dest_type);
} else { } else {
image_deref = lower_read_write_image_deref(b, context, intr_format); image_deref = lower_read_write_image_deref(b, context, dest_type);
} }
uniform_deref_dests[type] = image_deref; uniform_deref_dests[type] = image_deref;
...@@ -302,9 +277,9 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont ...@@ -302,9 +277,9 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont
type = FLOAT4; type = FLOAT4;
const struct glsl_type *new_var_type; const struct glsl_type *new_var_type;
if (in_var->data.access & ACCESS_NON_WRITEABLE) { if (in_var->data.access & ACCESS_NON_WRITEABLE) {
image_deref = lower_read_only_image_deref(b, context, PIPE_FORMAT_R32G32B32A32_FLOAT); image_deref = lower_read_only_image_deref(b, context, nir_type_float32);
} else { } else {
image_deref = lower_read_write_image_deref(b, context, PIPE_FORMAT_R32G32B32A32_FLOAT); image_deref = lower_read_write_image_deref(b, context, nir_type_float32);
} }
uniform_deref_dests[type] = image_deref; uniform_deref_dests[type] = image_deref;
...@@ -375,9 +350,8 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont ...@@ -375,9 +350,8 @@ clc_lower_input_image_deref(nir_builder *b, struct clc_image_lower_context *cont
nir_ssa_def *image_deref = uniform_deref_dests[type]; nir_ssa_def *image_deref = uniform_deref_dests[type];
if (!image_deref) { if (!image_deref) {
enum pipe_format image_format = pipe_format_for_nir_format(tex->dest_type);
image_deref = uniform_deref_dests[type] = image_deref = uniform_deref_dests[type] =
lower_read_only_image_deref(b, context, image_format); lower_read_only_image_deref(b, context, tex->dest_type);
} }
nir_src uniform_src = nir_src_for_ssa(image_deref); nir_src uniform_src = nir_src_for_ssa(image_deref);
......
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