From: Caio Marcelo de Oliveira Filho Date: Fri, 20 Sep 2019 16:27:00 +0000 (-0700) Subject: glsl: Add ir_demote X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=af1a6f0f770ae7432fd506f5f33fbe9e00e253af;p=mesa.git glsl: Add ir_demote To represent the new `demote` keyword when using EXT_demote_to_helper_invocation extension. Most of the changes are to include it in the visitors. Demote is not considered a control flow, so also include an empty visit member function in ir_control_flow_visitor. Only NIR actually supports `demote`, so assert the translations for TGSI and Mesa's gl_program -- since the demote is not expected to appear for those. Reviewed-by: Kenneth Graunke --- diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 1e096a66c20..883cfb57601 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -63,6 +63,7 @@ public: virtual void visit(ir_loop *); virtual void visit(ir_if *); virtual void visit(ir_discard *); + virtual void visit(ir_demote *); virtual void visit(ir_loop_jump *); virtual void visit(ir_return *); virtual void visit(ir_call *); @@ -775,6 +776,15 @@ nir_visitor::visit(ir_discard *ir) nir_builder_instr_insert(&b, &discard->instr); } +void +nir_visitor::visit(ir_demote *ir) +{ + nir_intrinsic_instr *demote = + nir_intrinsic_instr_create(this->shader, nir_intrinsic_demote); + + nir_builder_instr_insert(&b, &demote->instr); +} + void nir_visitor::visit(ir_emit_vertex *ir) { diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index ba831f2c1ed..e3c28bbb2b8 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -74,6 +74,7 @@ enum ir_node_type { ir_type_loop_jump, ir_type_return, ir_type_discard, + ir_type_demote, ir_type_emit_vertex, ir_type_end_primitive, ir_type_barrier, @@ -1804,6 +1805,28 @@ public: /*@}*/ +/** + * IR instruction representing demote statements from + * GL_EXT_demote_to_helper_invocation. + */ +class ir_demote : public ir_instruction { +public: + ir_demote() + : ir_instruction(ir_type_demote) + { + } + + virtual ir_demote *clone(void *mem_ctx, struct hash_table *ht) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); +}; + + /** * Texture sampling opcodes used in ir_texture */ diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp index c492fdbb3d0..eb24ffe9be2 100644 --- a/src/compiler/glsl/ir_clone.cpp +++ b/src/compiler/glsl/ir_clone.cpp @@ -102,6 +102,12 @@ ir_discard::clone(void *mem_ctx, struct hash_table *ht) const return new(mem_ctx) ir_discard(new_condition); } +ir_demote * +ir_demote::clone(void *mem_ctx, struct hash_table *ht) const +{ + return new(mem_ctx) ir_demote(); +} + ir_loop_jump * ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const { diff --git a/src/compiler/glsl/ir_hierarchical_visitor.cpp b/src/compiler/glsl/ir_hierarchical_visitor.cpp index 1d23a776643..8fcf48e2bb4 100644 --- a/src/compiler/glsl/ir_hierarchical_visitor.cpp +++ b/src/compiler/glsl/ir_hierarchical_visitor.cpp @@ -304,6 +304,24 @@ ir_hierarchical_visitor::visit_leave(ir_discard *ir) return visit_continue; } +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_demote *ir) +{ + if (this->callback_enter != NULL) + this->callback_enter(ir, this->data_enter); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_demote *ir) +{ + if (this->callback_leave != NULL) + this->callback_leave(ir, this->data_leave); + + return visit_continue; +} + ir_visitor_status ir_hierarchical_visitor::visit_enter(ir_if *ir) { diff --git a/src/compiler/glsl/ir_hierarchical_visitor.h b/src/compiler/glsl/ir_hierarchical_visitor.h index 5f5acd041b8..e10bb7c60db 100644 --- a/src/compiler/glsl/ir_hierarchical_visitor.h +++ b/src/compiler/glsl/ir_hierarchical_visitor.h @@ -133,6 +133,8 @@ public: virtual ir_visitor_status visit_leave(class ir_return *); virtual ir_visitor_status visit_enter(class ir_discard *); virtual ir_visitor_status visit_leave(class ir_discard *); + virtual ir_visitor_status visit_enter(class ir_demote *); + virtual ir_visitor_status visit_leave(class ir_demote *); virtual ir_visitor_status visit_enter(class ir_if *); virtual ir_visitor_status visit_leave(class ir_if *); virtual ir_visitor_status visit_enter(class ir_emit_vertex *); diff --git a/src/compiler/glsl/ir_hv_accept.cpp b/src/compiler/glsl/ir_hv_accept.cpp index f04a5b6fd19..6e5e25378e1 100644 --- a/src/compiler/glsl/ir_hv_accept.cpp +++ b/src/compiler/glsl/ir_hv_accept.cpp @@ -378,6 +378,18 @@ ir_discard::accept(ir_hierarchical_visitor *v) } +ir_visitor_status +ir_demote::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + return v->visit_leave(this); +} + + ir_visitor_status ir_if::accept(ir_hierarchical_visitor *v) { diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp index b3a62ce38bd..2eaebb21d47 100644 --- a/src/compiler/glsl/ir_print_visitor.cpp +++ b/src/compiler/glsl/ir_print_visitor.cpp @@ -564,6 +564,13 @@ ir_print_visitor::visit(ir_discard *ir) } +void +ir_print_visitor::visit(ir_demote *ir) +{ + fprintf(f, "(demote)"); +} + + void ir_print_visitor::visit(ir_if *ir) { diff --git a/src/compiler/glsl/ir_print_visitor.h b/src/compiler/glsl/ir_print_visitor.h index 652cd90bc00..a71e1aba886 100644 --- a/src/compiler/glsl/ir_print_visitor.h +++ b/src/compiler/glsl/ir_print_visitor.h @@ -63,6 +63,7 @@ public: virtual void visit(ir_call *); virtual void visit(ir_return *); virtual void visit(ir_discard *); + virtual void visit(ir_demote *); virtual void visit(ir_if *); virtual void visit(ir_loop *); virtual void visit(ir_loop_jump *); diff --git a/src/compiler/glsl/ir_visitor.h b/src/compiler/glsl/ir_visitor.h index 117b5bc6ae8..b06e310ffd7 100644 --- a/src/compiler/glsl/ir_visitor.h +++ b/src/compiler/glsl/ir_visitor.h @@ -59,6 +59,7 @@ public: virtual void visit(class ir_call *) = 0; virtual void visit(class ir_return *) = 0; virtual void visit(class ir_discard *) = 0; + virtual void visit(class ir_demote *) = 0; virtual void visit(class ir_if *) = 0; virtual void visit(class ir_loop *) = 0; virtual void visit(class ir_loop_jump *) = 0; @@ -83,6 +84,7 @@ public: virtual void visit(class ir_assignment *) {} virtual void visit(class ir_constant *) {} virtual void visit(class ir_call *) {} + virtual void visit(class ir_demote *) {} virtual void visit(class ir_emit_vertex *) {} virtual void visit(class ir_end_primitive *) {} virtual void visit(class ir_barrier *) {} diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 777fd168c7e..679b46ba7ee 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -252,6 +252,7 @@ public: virtual void visit(ir_call *); virtual void visit(ir_return *); virtual void visit(ir_discard *); + virtual void visit(ir_demote *); virtual void visit(ir_texture *); virtual void visit(ir_if *); virtual void visit(ir_emit_vertex *); @@ -2201,6 +2202,12 @@ ir_to_mesa_visitor::visit(ir_discard *ir) emit(ir, OPCODE_KIL, undef_dst, this->result); } +void +ir_to_mesa_visitor::visit(ir_demote *ir) +{ + assert(!"demote statement unsupported"); +} + void ir_to_mesa_visitor::visit(ir_if *ir) { diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 9b982569490..b0afe2d2385 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -284,6 +284,7 @@ public: virtual void visit(ir_call *); virtual void visit(ir_return *); virtual void visit(ir_discard *); + virtual void visit(ir_demote *); virtual void visit(ir_texture *); virtual void visit(ir_if *); virtual void visit(ir_emit_vertex *); @@ -4626,6 +4627,12 @@ glsl_to_tgsi_visitor::visit(ir_discard *ir) } } +void +glsl_to_tgsi_visitor::visit(ir_demote *ir) +{ + assert(!"demote statement unsupported"); +} + void glsl_to_tgsi_visitor::visit(ir_if *ir) {