From: Eric Anholt Date: Thu, 19 Dec 2019 00:30:37 +0000 (-0800) Subject: turnip: Refactor the intrinsic lowering. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=85e424c591bf5665981bf60ae4d416afb7a72dce;p=mesa.git turnip: Refactor the intrinsic lowering. Too many things in one function, split them out based on the intrinsic. Reviewed-by: Jonathan Marek Part-of: --- diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c index 0b755a99f8e..514f3d852f9 100644 --- a/src/freedreno/vulkan/tu_shader.c +++ b/src/freedreno/vulkan/tu_shader.c @@ -233,45 +233,34 @@ lower_sampler(nir_builder *b, nir_tex_instr *instr, struct tu_shader *shader, return true; } -static bool -lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, - struct tu_shader *shader, - const struct tu_pipeline_layout *layout) +static void +lower_load_push_constant(nir_builder *b, nir_intrinsic_instr *instr, + struct tu_shader *shader) { - /* TODO: remove this when layered rendering is implemented */ - if (instr->intrinsic == nir_intrinsic_load_layer_id) { - nir_ssa_def_rewrite_uses(&instr->dest.ssa, - nir_src_for_ssa(nir_imm_int(b, 0))); - nir_instr_remove(&instr->instr); - return true; - } - - if (instr->intrinsic == nir_intrinsic_load_push_constant) { - /* note: ir3 wants load_ubo, not load_uniform */ - assert(nir_intrinsic_base(instr) == 0); - - nir_intrinsic_instr *load = - nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_ubo); - load->num_components = instr->num_components; - load->src[0] = nir_src_for_ssa(nir_imm_int(b, 0)); - load->src[1] = instr->src[0]; - nir_ssa_dest_init(&load->instr, &load->dest, - load->num_components, instr->dest.ssa.bit_size, - instr->dest.ssa.name); - nir_builder_instr_insert(b, &load->instr); - nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(&load->dest.ssa)); + /* note: ir3 wants load_ubo, not load_uniform */ + assert(nir_intrinsic_base(instr) == 0); + + nir_intrinsic_instr *load = + nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_ubo); + load->num_components = instr->num_components; + load->src[0] = nir_src_for_ssa(nir_imm_int(b, 0)); + load->src[1] = instr->src[0]; + nir_ssa_dest_init(&load->instr, &load->dest, + load->num_components, instr->dest.ssa.bit_size, + instr->dest.ssa.name); + nir_builder_instr_insert(b, &load->instr); + nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(&load->dest.ssa)); - nir_instr_remove(&instr->instr); - - return true; - } - - if (instr->intrinsic != nir_intrinsic_vulkan_resource_index) - return false; + nir_instr_remove(&instr->instr); +} +static void +lower_vulkan_resource_index(nir_builder *b, nir_intrinsic_instr *instr, + struct tu_shader *shader, + const struct tu_pipeline_layout *layout) +{ nir_const_value *const_val = nir_src_as_const_value(instr->src[0]); - unsigned set = nir_intrinsic_desc_set(instr); unsigned binding = nir_intrinsic_binding(instr); struct tu_descriptor_set_layout *set_layout = layout->set[set].layout; @@ -304,8 +293,32 @@ lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(nir_imm_int(b, index))); nir_instr_remove(&instr->instr); +} - return true; +static bool +lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, + struct tu_shader *shader, + const struct tu_pipeline_layout *layout) +{ + switch (instr->intrinsic) { + case nir_intrinsic_load_layer_id: + /* TODO: remove this when layered rendering is implemented */ + nir_ssa_def_rewrite_uses(&instr->dest.ssa, + nir_src_for_ssa(nir_imm_int(b, 0))); + nir_instr_remove(&instr->instr); + return true; + + case nir_intrinsic_load_push_constant: + lower_load_push_constant(b, instr, shader); + return true; + + case nir_intrinsic_vulkan_resource_index: + lower_vulkan_resource_index(b, instr, shader, layout); + return true; + + default: + return false; + } } static bool