[Mesa-dev] [PATCH 10/20] i965/fs: Split LIR emission ouf of ir-visitor

Topi Pohjolainen topi.pohjolainen at intel.com
Fri Apr 11 00:28:50 PDT 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           |  53 ++++++++-----
 src/mesa/drivers/dri/i965/brw_fs_emitter.cpp | 110 +++++++++++++++++++++++++++
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |  30 +-------
 5 files changed, 146 insertions(+), 92 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 8205fe9..f28e46f 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -68,6 +68,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 b5f327e..eddc256 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -678,50 +678,6 @@ fs_visitor::no16(const char *format, ...)
    va_end(va);
 }
 
-fs_inst *
-fs_visitor::emit(enum opcode opcode)
-{
-   return emit(new(mem_ctx) fs_inst(opcode));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst)
-{
-   return emit(new(mem_ctx) fs_inst(opcode, dst));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst, fs_reg src0)
-{
-   return emit(new(mem_ctx) fs_inst(opcode, dst, src0));
-}
-
-fs_inst *
-fs_visitor::emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
-{
-   return emit(new(mem_ctx) 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(new(mem_ctx) 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 78c53dd..caf4d84 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -239,12 +239,45 @@ public:
    bool force_writemask_all:1;
 };
 
+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);
+   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:
 
@@ -283,16 +316,6 @@ public:
 
    bool can_do_source_mods(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);
@@ -383,9 +406,6 @@ public:
    void no16(const char *msg, ...);
    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,
@@ -491,7 +511,6 @@ public:
    void visit_atomic_counter_intrinsic(ir_call *ir);
 
    struct gl_fragment_program *fp;
-   struct brw_wm_compile *c;
 
    int *param_size;
 
@@ -537,10 +556,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..4c6b5ad
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/brw_fs_emitter.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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)
+{
+   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(new(mem_ctx) fs_inst(opcode));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst)
+{
+   return emit(new(mem_ctx) fs_inst(opcode, dst));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst, fs_reg src0)
+{
+   return emit(new(mem_ctx) fs_inst(opcode, dst, src0));
+}
+
+fs_inst *
+fs_emitter::emit(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
+{
+   return emit(new(mem_ctx) 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(new(mem_ctx) 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 d6cd53c..df150c3 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -2449,30 +2449,6 @@ fs_visitor::emit_untyped_surface_read(unsigned surf_index, fs_reg dst,
    emit(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()
@@ -2953,10 +2929,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;
    this->simd16_unsupported = false;
    this->no16_msg = NULL;
@@ -2970,8 +2944,6 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->pull_constant_loc = NULL;
    this->push_constant_loc = NULL;
 
-   this->force_uncompressed_stack = 0;
-
    this->spilled_any_registers = false;
    this->do_dual_src = false;
 
-- 
1.8.3.1



More information about the mesa-dev mailing list