diff options
author | Eric Anholt <[email protected]> | 2019-12-18 16:30:37 -0800 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-21 19:29:59 +0000 |
commit | 85e424c591bf5665981bf60ae4d416afb7a72dce (patch) | |
tree | 8531580327ee7f7617f2074ceb13a898a698bcce /src/freedreno/vulkan/tu_shader.c | |
parent | 3ac662e8df687270cda6f8404354d7a1d0e67f7a (diff) |
turnip: Refactor the intrinsic lowering.
Too many things in one function, split them out based on the intrinsic.
Reviewed-by: Jonathan Marek <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3433>
Diffstat (limited to 'src/freedreno/vulkan/tu_shader.c')
-rw-r--r-- | src/freedreno/vulkan/tu_shader.c | 83 |
1 files changed, 48 insertions, 35 deletions
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 |