Potentially we'll want more than three sources for Phi nodes.

To avoid passing a mem_ctx parameter into each fs_inst() constructor, we
add a static thread-local variable to fs_inst that we set in the
fs_visitor() constructor.
---
Is __thread good enough? What about multi-context GL?

 src/mesa/drivers/dri/i965/brw_fs.cpp         | 10 ++++++++++
 src/mesa/drivers/dri/i965/brw_fs.h           |  4 +++-
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |  2 ++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp 
b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 77cdfa2..4d13446 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -51,10 +51,15 @@ extern "C" {
 #include "brw_fs_live_variables.h"
 #include "glsl/glsl_types.h"
 
+__thread void *fs_inst::mem_ctx;
+
 void
 fs_inst::init()
 {
    memset(this, 0, sizeof(*this));
+   assert(fs_inst::mem_ctx != NULL);
+
+   this->src = rzalloc_array(mem_ctx, fs_reg, 3);
 
    /* This will be the case for almost all instructions. */
    this->regs_written = 1;
@@ -111,6 +116,11 @@ dst:
 fs_inst::fs_inst(const fs_inst &that)
 {
    memcpy(this, &that, sizeof(that));
+
+   this->src = ralloc_array(mem_ctx, fs_reg, 3);
+
+   for (int i = 0; i < 3; i++)
+      this->src[i] = that.src[i];
 }
 
 #define ALU1(op)                                                        \
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h 
b/src/mesa/drivers/dri/i965/brw_fs.h
index f73f835..3623000 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -192,7 +192,7 @@ public:
    bool writes_flag();
 
    fs_reg dst;
-   fs_reg src[3];
+   fs_reg *src;
 
    /** @{
     * Annotation for the generated IR.  One of the two can be set.
@@ -223,6 +223,8 @@ public:
    uint8_t force_uncompressed:1;
    uint8_t force_sechalf:1;
    uint8_t force_writemask_all:1;
+
+   static __thread void *mem_ctx;
 };
 
 /**
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp 
b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 76f93c9..89f39a5 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -2947,6 +2947,7 @@ fs_visitor::fs_visitor(struct brw_context *brw,
    this->stage_prog_data = &c->prog_data.base;
    this->ctx = &brw->ctx;
    this->mem_ctx = ralloc_context(NULL);
+   fs_inst::mem_ctx = this->mem_ctx;
    if (shader_prog)
       shader = (struct brw_shader *)
          shader_prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
@@ -2986,5 +2987,6 @@ fs_visitor::fs_visitor(struct brw_context *brw,
 fs_visitor::~fs_visitor()
 {
    ralloc_free(this->mem_ctx);
+   fs_inst::mem_ctx = NULL;
    hash_table_dtor(this->variable_ht);
 }
-- 
1.8.3.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to