[Mesa-dev] [RFC 18/27] i965/fs: Split LIR emission ouf of ir-visitor

Topi Pohjolainen topi.pohjolainen at intel.com
Sat Feb 22 01:05:44 PST 2014


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 src/mesa/drivers/dri/i965/Makefile.sources   |   1 +
 src/mesa/drivers/dri/i965/brw_fs.cpp         |  44 ----------
 src/mesa/drivers/dri/i965/brw_fs.h           |  55 ++++++++-----
 src/mesa/drivers/dri/i965/brw_fs_emitter.cpp | 119 +++++++++++++++++++++++++++
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |  39 +--------
 5 files changed, 156 insertions(+), 102 deletions(-)
 create mode 100644 src/mesa/drivers/dri/i965/brw_fs_emitter.cpp

diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
index dc30eb3..cea8cb8 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -67,6 +67,7 @@ i965_FILES = \
 	brw_fs_sel_peephole.cpp \
 	brw_fs_vector_splitting.cpp \
 	brw_fs_visitor.cpp \
+	brw_fs_emitter.cpp \
 	brw_gs.c \
 	brw_gs_emit.c \
 	brw_gs_state.c \
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index bad3333..955894c 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -645,50 +645,6 @@ fs_visitor::emit_shader_time_write(enum shader_time_shader_type type,
                 fs_reg(), payload, offset, value));
 }
 
-fs_inst *
-fs_visitor::emit(enum opcode opcode)
-{
-   return emit(fs_inst(opcode));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst)
-{
-   return emit(fs_inst(opcode, dst));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst, fs_reg src0)
-{
-   return emit(fs_inst(opcode, dst, src0));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
-{
-   return emit(fs_inst(opcode, dst, src0, src1));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst,
-                 fs_reg src0, fs_reg src1, fs_reg src2)
-{
-   return emit(fs_inst(opcode, dst, src0, src1, src2));
-}
-
-void
-fs_visitor::push_force_uncompressed()
-{
-   force_uncompressed_stack++;
-}
-
-void
-fs_visitor::pop_force_uncompressed()
-{
-   force_uncompressed_stack--;
-   assert(force_uncompressed_stack >= 0);
-}
-
 /**
  * Returns true if the instruction has a flag that means it won't
  * update an entire destination register.
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 8427937..abc3666 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -237,12 +237,46 @@ public:
    /** @} */
 };
 
+class fs_emitter : public backend_emitter
+{
+public:
+   const unsigned dispatch_width; /**< 8 or 16 */
+
+protected:
+   fs_emitter(struct brw_context *brw,
+              struct brw_wm_compile *c,
+              unsigned dispatch_width);
+
+   fs_inst *emit(enum opcode opcode);
+   fs_inst *emit(enum opcode opcode, fs_reg dst);
+   fs_inst *emit(enum opcode opcode, fs_reg dst, fs_reg src0);
+   fs_inst *emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1);
+   fs_inst *emit(enum opcode opcode, fs_reg dst,
+                 fs_reg src0, fs_reg src1, fs_reg src2);
+
+   fs_inst *emit(fs_inst inst);
+   fs_inst *emit(fs_inst *inst);
+   void emit(exec_list list);
+
+   void push_force_uncompressed();
+   void pop_force_uncompressed();
+
+   struct brw_wm_compile * const c;
+
+   /** @{ debug annotation info */
+   const char *current_annotation;
+   const void *base_ir;
+   /** @} */
+
+   int force_uncompressed_stack;
+};
+
 /**
  * The fragment shader front-end.
  *
  * Translates either GLSL IR or Mesa IR (for ARB_fragment_program) into FS IR.
  */
-class fs_visitor : public backend_visitor, public backend_emitter
+class fs_visitor : public backend_visitor, public fs_emitter
 {
 public:
 
@@ -281,17 +315,6 @@ public:
 
    bool can_do_source_mods(fs_inst *inst);
 
-   fs_inst *emit(fs_inst inst);
-   fs_inst *emit(fs_inst *inst);
-   void emit(exec_list list);
-
-   fs_inst *emit(enum opcode opcode);
-   fs_inst *emit(enum opcode opcode, fs_reg dst);
-   fs_inst *emit(enum opcode opcode, fs_reg dst, fs_reg src0);
-   fs_inst *emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1);
-   fs_inst *emit(enum opcode opcode, fs_reg dst,
-                 fs_reg src0, fs_reg src1, fs_reg src2);
-
    fs_inst *MOV(fs_reg dst, fs_reg src);
    fs_inst *NOT(fs_reg dst, fs_reg src);
    fs_inst *RNDD(fs_reg dst, fs_reg src);
@@ -379,9 +402,6 @@ public:
    void insert_gen4_post_send_dependency_workarounds(fs_inst *inst);
    void lower_uniform_pull_constant_loads();
 
-   void push_force_uncompressed();
-   void pop_force_uncompressed();
-
    void emit_dummy_fs();
    fs_reg *emit_fragcoord_interpolation(ir_variable *ir);
    fs_inst *emit_linterp(const fs_reg &attr, const fs_reg &interp,
@@ -486,7 +506,6 @@ public:
    void visit_atomic_counter_intrinsic(ir_call *ir);
 
    struct gl_fragment_program *fp;
-   struct brw_wm_compile *c;
 
    int *param_size;
 
@@ -524,10 +543,6 @@ public:
 
    int grf_used;
    bool spilled_any_registers;
-
-   const unsigned dispatch_width; /**< 8 or 16 */
-
-   int force_uncompressed_stack;
 };
 
 /**
diff --git a/src/mesa/drivers/dri/i965/brw_fs_emitter.cpp b/src/mesa/drivers/dri/i965/brw_fs_emitter.cpp
new file mode 100644
index 0000000..4b143f1
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/brw_fs_emitter.cpp
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2014 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.
+ */
+
+/** @file brw_fs_emitter.cpp
+ *
+ * This file supports generating the FS LIR. The LIR makes it easier to do
+ * backend-specific optimizations than doing so in the GLSL IR or in the
+ * native code.
+ */
+#include "brw_fs.h"
+
+fs_inst *
+fs_emitter::emit(fs_inst inst)
+{
+   fs_inst *list_inst = new(mem_ctx) fs_inst;
+   *list_inst = inst;
+   emit(list_inst);
+   return list_inst;
+}
+
+fs_inst *
+fs_emitter::emit(fs_inst *inst)
+{
+   if (force_uncompressed_stack > 0)
+      inst->force_uncompressed = true;
+
+   inst->annotation = this->current_annotation;
+   inst->ir = this->base_ir;
+
+   this->instructions.push_tail(inst);
+
+   return inst;
+}
+
+void
+fs_emitter::emit(exec_list list)
+{
+   foreach_list_safe(node, &list) {
+      fs_inst *inst = (fs_inst *)node;
+      inst->remove();
+      emit(inst);
+   }
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode)
+{
+   return emit(fs_inst(opcode));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst)
+{
+   return emit(fs_inst(opcode, dst));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst, fs_reg src0)
+{
+   return emit(fs_inst(opcode, dst, src0));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
+{
+   return emit(fs_inst(opcode, dst, src0, src1));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst,
+                 fs_reg src0, fs_reg src1, fs_reg src2)
+{
+   return emit(fs_inst(opcode, dst, src0, src1, src2));
+}
+
+void
+fs_emitter::push_force_uncompressed()
+{
+   force_uncompressed_stack++;
+}
+
+void
+fs_emitter::pop_force_uncompressed()
+{
+   force_uncompressed_stack--;
+   assert(force_uncompressed_stack >= 0);
+}
+
+fs_emitter::fs_emitter(struct brw_context *brw,
+                       struct brw_wm_compile *_c,
+                       unsigned _dispatch_width)
+   : backend_emitter(brw, "FS", INTEL_DEBUG & DEBUG_WM),
+     dispatch_width(_dispatch_width),
+     c(_c),
+     current_annotation(NULL),
+     base_ir(NULL),
+     force_uncompressed_stack(0)
+{
+}
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 0fadc51..ed19157 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -2436,39 +2436,6 @@ fs_visitor::emit_untyped_surface_read(unsigned surf_index, fs_reg dst,
    emit(inst);
 }
 
-fs_inst *
-fs_visitor::emit(fs_inst inst)
-{
-   fs_inst *list_inst = new(mem_ctx) fs_inst;
-   *list_inst = inst;
-   emit(list_inst);
-   return list_inst;
-}
-
-fs_inst *
-fs_visitor::emit(fs_inst *inst)
-{
-   if (force_uncompressed_stack > 0)
-      inst->force_uncompressed = true;
-
-   inst->annotation = this->current_annotation;
-   inst->ir = this->base_ir;
-
-   this->instructions.push_tail(inst);
-
-   return inst;
-}
-
-void
-fs_visitor::emit(exec_list list)
-{
-   foreach_list_safe(node, &list) {
-      fs_inst *inst = (fs_inst *)node;
-      inst->remove();
-      emit(inst);
-   }
-}
-
 /** Emits a dummy fragment shader consisting of magenta for bringup purposes. */
 void
 fs_visitor::emit_dummy_fs()
@@ -2949,10 +2916,8 @@ fs_visitor::fs_visitor(struct brw_context *brw,
                        unsigned dispatch_width)
    : backend_visitor(shader_prog, &fp->Base, &c->prog_data.base,
                      MESA_SHADER_FRAGMENT),
-     backend_emitter(brw, "FS", INTEL_DEBUG & DEBUG_WM),
-     dispatch_width(dispatch_width)
+     fs_emitter(brw, c, dispatch_width)
 {
-   this->c = c;
    this->fp = fp;
 
    memset(this->outputs, 0, sizeof(this->outputs));
@@ -2964,8 +2929,6 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->params_remap = NULL;
    this->nr_params_remap = 0;
 
-   this->force_uncompressed_stack = 0;
-
    this->spilled_any_registers = false;
 
    this->param_size = rzalloc_array(mem_ctx, int, stage_prog_data->nr_params);
-- 
1.8.3.1



More information about the mesa-dev mailing list