From: Jonathan Marek Date: Fri, 31 May 2019 17:44:40 +0000 (-0400) Subject: nir: add type information to load uniform/input and store output intrinsics X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c12750527b7c4d1f4265ffa2346fd5c2346f41cd;p=mesa.git nir: add type information to load uniform/input and store output intrinsics This type information will be used by gather_ssa_types to get usable results Signed-off-by: Jonathan Marek Reviewed-by: Jason Ekstrand --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 9307b93b6b6..660f6ae04d8 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1289,6 +1289,11 @@ typedef enum { */ NIR_INTRINSIC_DESC_TYPE = 19, + /** + * The nir_alu_type of a uniform/input/output + */ + NIR_INTRINSIC_TYPE = 20, + NIR_INTRINSIC_NUM_INDEX_FLAGS, } nir_intrinsic_index_flag; @@ -1393,6 +1398,7 @@ INTRINSIC_IDX_ACCESSORS(format, FORMAT, unsigned) INTRINSIC_IDX_ACCESSORS(align_mul, ALIGN_MUL, unsigned) INTRINSIC_IDX_ACCESSORS(align_offset, ALIGN_OFFSET, unsigned) INTRINSIC_IDX_ACCESSORS(desc_type, DESC_TYPE, unsigned) +INTRINSIC_IDX_ACCESSORS(type, TYPE, nir_alu_type) static inline void nir_intrinsic_set_align(nir_intrinsic_instr *intrin, diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py index df459a3cdec..0ae33a17fe0 100644 --- a/src/compiler/nir/nir_intrinsics.py +++ b/src/compiler/nir/nir_intrinsics.py @@ -118,6 +118,8 @@ ALIGN_MUL = "NIR_INTRINSIC_ALIGN_MUL" ALIGN_OFFSET = "NIR_INTRINSIC_ALIGN_OFFSET" # The vulkan descriptor type for vulkan_resource_index DESC_TYPE = "NIR_INTRINSIC_DESC_TYPE" +# The nir_alu_type of a uniform/input/output +TYPE = "NIR_INTRINSIC_TYPE" # # Possible flags: @@ -640,11 +642,11 @@ def load(name, num_srcs, indices=[], flags=[]): flags=flags) # src[] = { offset }. -load("uniform", 1, [BASE, RANGE], [CAN_ELIMINATE, CAN_REORDER]) +load("uniform", 1, [BASE, RANGE, TYPE], [CAN_ELIMINATE, CAN_REORDER]) # src[] = { buffer_index, offset }. load("ubo", 2, [ACCESS, ALIGN_MUL, ALIGN_OFFSET], flags=[CAN_ELIMINATE, CAN_REORDER]) # src[] = { offset }. -load("input", 1, [BASE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER]) +load("input", 1, [BASE, COMPONENT, TYPE], [CAN_ELIMINATE, CAN_REORDER]) # src[] = { vertex, offset }. load("per_vertex_input", 2, [BASE, COMPONENT], [CAN_ELIMINATE, CAN_REORDER]) # src[] = { barycoord, offset }. @@ -679,7 +681,7 @@ def store(name, num_srcs, indices=[], flags=[]): intrinsic("store_" + name, [0] + ([1] * (num_srcs - 1)), indices=indices, flags=flags) # src[] = { value, offset }. -store("output", 2, [BASE, WRMASK, COMPONENT]) +store("output", 2, [BASE, WRMASK, COMPONENT, TYPE]) # src[] = { value, vertex, offset }. store("per_vertex_output", 3, [BASE, WRMASK, COMPONENT]) # src[] = { value, block_index, offset } diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 6f370173387..b0197399bdf 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -204,7 +204,7 @@ get_io_offset(nir_builder *b, nir_deref_instr *deref, static nir_intrinsic_instr * lower_load(nir_intrinsic_instr *intrin, struct lower_io_state *state, nir_ssa_def *vertex_index, nir_variable *var, nir_ssa_def *offset, - unsigned component) + unsigned component, const struct glsl_type *type) { const nir_shader *nir = state->builder.shader; nir_variable_mode mode = var->data.mode; @@ -261,6 +261,10 @@ lower_load(nir_intrinsic_instr *intrin, struct lower_io_state *state, nir_intrinsic_set_range(load, state->type_size(var->type, var->data.bindless)); + if (load->intrinsic == nir_intrinsic_load_input || + load->intrinsic == nir_intrinsic_load_uniform) + nir_intrinsic_set_type(load, nir_get_nir_type_for_glsl_type(type)); + if (vertex_index) { load->src[0] = nir_src_for_ssa(vertex_index); load->src[1] = nir_src_for_ssa(offset); @@ -277,7 +281,7 @@ lower_load(nir_intrinsic_instr *intrin, struct lower_io_state *state, static nir_intrinsic_instr * lower_store(nir_intrinsic_instr *intrin, struct lower_io_state *state, nir_ssa_def *vertex_index, nir_variable *var, nir_ssa_def *offset, - unsigned component) + unsigned component, const struct glsl_type *type) { nir_variable_mode mode = var->data.mode; @@ -301,6 +305,9 @@ lower_store(nir_intrinsic_instr *intrin, struct lower_io_state *state, if (mode == nir_var_shader_out) nir_intrinsic_set_component(store, component); + if (store->intrinsic == nir_intrinsic_store_output) + nir_intrinsic_set_type(store, nir_get_nir_type_for_glsl_type(type)); + nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(intrin)); if (vertex_index) @@ -356,13 +363,14 @@ lower_atomic(nir_intrinsic_instr *intrin, struct lower_io_state *state, static nir_intrinsic_instr * lower_interpolate_at(nir_intrinsic_instr *intrin, struct lower_io_state *state, - nir_variable *var, nir_ssa_def *offset, unsigned component) + nir_variable *var, nir_ssa_def *offset, unsigned component, + const struct glsl_type *type) { assert(var->data.mode == nir_var_shader_in); /* Ignore interpolateAt() for flat variables - flat is flat. */ if (var->data.interpolation == INTERP_MODE_FLAT) - return lower_load(intrin, state, NULL, var, offset, component); + return lower_load(intrin, state, NULL, var, offset, component, type); nir_intrinsic_op bary_op; switch (intrin->intrinsic) { @@ -485,12 +493,12 @@ nir_lower_io_block(nir_block *block, switch (intrin->intrinsic) { case nir_intrinsic_load_deref: replacement = lower_load(intrin, state, vertex_index, var, offset, - component_offset); + component_offset, deref->type); break; case nir_intrinsic_store_deref: replacement = lower_store(intrin, state, vertex_index, var, offset, - component_offset); + component_offset, deref->type); break; case nir_intrinsic_deref_atomic_add: @@ -516,7 +524,7 @@ nir_lower_io_block(nir_block *block, case nir_intrinsic_interp_deref_at_offset: assert(vertex_index == NULL); replacement = lower_interpolate_at(intrin, state, var, offset, - component_offset); + component_offset, deref->type); break; default: diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 4056bd77455..03509e1cc65 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -775,6 +775,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state) [NIR_INTRINSIC_ALIGN_MUL] = "align_mul", [NIR_INTRINSIC_ALIGN_OFFSET] = "align_offset", [NIR_INTRINSIC_DESC_TYPE] = "desc_type", + [NIR_INTRINSIC_TYPE] = "type", }; for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) { if (!info->index_map[idx]) @@ -811,6 +812,21 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state) } else if (idx == NIR_INTRINSIC_DESC_TYPE) { VkDescriptorType desc_type = nir_intrinsic_desc_type(instr); fprintf(fp, " desc_type=%s", vulkan_descriptor_type_name(desc_type)); + } else if (idx == NIR_INTRINSIC_TYPE) { + nir_alu_type type = nir_intrinsic_type(instr); + unsigned size = nir_alu_type_get_type_size(type); + const char *name; + switch (nir_alu_type_get_base_type(type)) { + case nir_type_int: name = "int"; break; + case nir_type_uint: name = "uint"; break; + case nir_type_bool: name = "bool"; break; + case nir_type_float: name = "float"; break; + default: name = "invalid"; + } + if (size) + fprintf(fp, " type=%s%u", name, size); + else + fprintf(fp, " type=%s", name); } else { unsigned off = info->index_map[idx] - 1; assert(index_name[idx]); /* forgot to update index_name table? */