From abf4fa3c03ebe5716c90c8a310945c3621cf598f Mon Sep 17 00:00:00 2001 From: Eduardo Lima Mitev Date: Tue, 16 Jun 2015 12:08:09 +0200 Subject: [PATCH] i965/nir/vec4: Add implementation placeholders for a new NIR->vec4 pass This patch will add a brw_vec4_nir.cpp file filled with entry point methods to the main functionality, following a structure similar to brw_fs_nir.cpp. Subsequent patches in this series will be adding the implementations for these methods, incrementally. Reviewed-by: Jason Ekstrand --- src/mesa/drivers/dri/i965/Makefile.sources | 1 + src/mesa/drivers/dri/i965/brw_vec4.h | 19 ++ src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 253 +++++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 src/mesa/drivers/dri/i965/brw_vec4_nir.cpp diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources index e861c2ccad5..3585126526a 100644 --- a/src/mesa/drivers/dri/i965/Makefile.sources +++ b/src/mesa/drivers/dri/i965/Makefile.sources @@ -125,6 +125,7 @@ i965_FILES = \ brw_vec4.h \ brw_vec4_live_variables.cpp \ brw_vec4_live_variables.h \ + brw_vec4_nir.cpp \ brw_vec4_reg_allocate.cpp \ brw_vec4_visitor.cpp \ brw_vec4_vp.cpp \ diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h index bf6183a74a6..f6f76f56fba 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4.h +++ b/src/mesa/drivers/dri/i965/brw_vec4.h @@ -45,6 +45,7 @@ extern "C" { #endif #include "glsl/ir.h" +#include "glsl/nir/nir.h" #ifdef __cplusplus @@ -389,6 +390,24 @@ public: void visit_atomic_counter_intrinsic(ir_call *ir); + virtual void emit_nir_code(); + virtual void nir_setup_inputs(nir_shader *shader); + virtual void nir_setup_uniforms(nir_shader *shader); + virtual void nir_setup_uniform(nir_variable *var); + virtual void nir_setup_builtin_uniform(nir_variable *var); + virtual void nir_setup_system_values(nir_shader *shader); + virtual void nir_emit_impl(nir_function_impl *impl); + virtual void nir_emit_cf_list(exec_list *list); + virtual void nir_emit_if(nir_if *if_stmt); + virtual void nir_emit_loop(nir_loop *loop); + virtual void nir_emit_block(nir_block *block); + virtual void nir_emit_instr(nir_instr *instr); + virtual void nir_emit_load_const(nir_load_const_instr *instr); + virtual void nir_emit_intrinsic(nir_intrinsic_instr *instr); + virtual void nir_emit_alu(nir_alu_instr *instr); + virtual void nir_emit_jump(nir_jump_instr *instr); + virtual void nir_emit_texture(nir_tex_instr *instr); + protected: void emit_vertex(); void lower_attributes_to_hw_regs(const int *attribute_map, diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp new file mode 100644 index 00000000000..7ec29784737 --- /dev/null +++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp @@ -0,0 +1,253 @@ +/* + * Copyright © 2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "brw_nir.h" +#include "brw_vec4.h" +#include "glsl/ir_uniform.h" + +namespace brw { + +void +vec4_visitor::emit_nir_code() +{ + nir_shader *nir = prog->nir; + + if (nir->num_inputs > 0) + nir_setup_inputs(nir); + + if (nir->num_uniforms > 0) + nir_setup_uniforms(nir); + + nir_setup_system_values(nir); + + /* get the main function and emit it */ + nir_foreach_overload(nir, overload) { + assert(strcmp(overload->function->name, "main") == 0); + assert(overload->impl); + nir_emit_impl(overload->impl); + } +} + +static bool +setup_system_values_block(nir_block *block, void *void_visitor) +{ + /* @TODO: Not yet implemented */ + return true; +} + +void +vec4_visitor::nir_setup_system_values(nir_shader *shader) +{ + nir_foreach_overload(shader, overload) { + assert(strcmp(overload->function->name, "main") == 0); + assert(overload->impl); + nir_foreach_block(overload->impl, setup_system_values_block, this); + } +} + +void +vec4_visitor::nir_setup_inputs(nir_shader *shader) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_setup_uniforms(nir_shader *shader) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_setup_uniform(nir_variable *var) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_setup_builtin_uniform(nir_variable *var) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_impl(nir_function_impl *impl) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_cf_list(exec_list *list) +{ + exec_list_validate(list); + foreach_list_typed(nir_cf_node, node, node, list) { + switch (node->type) { + case nir_cf_node_if: + nir_emit_if(nir_cf_node_as_if(node)); + break; + + case nir_cf_node_loop: + nir_emit_loop(nir_cf_node_as_loop(node)); + break; + + case nir_cf_node_block: + nir_emit_block(nir_cf_node_as_block(node)); + break; + + default: + unreachable("Invalid CFG node block"); + } + } +} + +void +vec4_visitor::nir_emit_if(nir_if *if_stmt) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_loop(nir_loop *loop) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_block(nir_block *block) +{ + nir_foreach_instr(block, instr) { + nir_emit_instr(instr); + } +} + +void +vec4_visitor::nir_emit_instr(nir_instr *instr) +{ + this->base_ir = instr; + + switch (instr->type) { + case nir_instr_type_load_const: + nir_emit_load_const(nir_instr_as_load_const(instr)); + break; + + case nir_instr_type_intrinsic: + nir_emit_intrinsic(nir_instr_as_intrinsic(instr)); + break; + + case nir_instr_type_alu: + nir_emit_alu(nir_instr_as_alu(instr)); + break; + + case nir_instr_type_jump: + nir_emit_jump(nir_instr_as_jump(instr)); + break; + + case nir_instr_type_tex: + nir_emit_texture(nir_instr_as_tex(instr)); + break; + + default: + fprintf(stderr, "VS instruction not yet implemented by NIR->vec4\n"); + break; + } +} + +void +vec4_visitor::nir_emit_load_const(nir_load_const_instr *instr) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr) +{ + switch (instr->intrinsic) { + + case nir_intrinsic_load_input_indirect: + /* fallthrough */ + case nir_intrinsic_load_input: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_store_output_indirect: + /* fallthrough */ + case nir_intrinsic_store_output: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_load_vertex_id: + unreachable("should be lowered by lower_vertex_id()"); + + case nir_intrinsic_load_vertex_id_zero_base: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_load_base_vertex: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_load_instance_id: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_load_uniform_indirect: + /* fallthrough */ + case nir_intrinsic_load_uniform: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_atomic_counter_read: + case nir_intrinsic_atomic_counter_inc: + case nir_intrinsic_atomic_counter_dec: + /* @TODO: Not yet implemented */ + break; + + case nir_intrinsic_load_ubo_indirect: + /* fallthrough */ + case nir_intrinsic_load_ubo: + /* @TODO: Not yet implemented */ + break; + + default: + unreachable("Unknown intrinsic"); + } +} + +void +vec4_visitor::nir_emit_alu(nir_alu_instr *instr) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_jump(nir_jump_instr *instr) +{ + /* @TODO: Not yet implemented */ +} + +void +vec4_visitor::nir_emit_texture(nir_tex_instr *instr) +{ + /* @TODO: Not yet implemented */ +} + +} -- 2.30.2