summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrancisco Jerez <currojerez@riseup.net>2015-02-06 01:14:51 +0200
committerFrancisco Jerez <currojerez@riseup.net>2015-02-10 16:05:51 +0200
commitf2668f9f214201503419342b980d3afa8b796926 (patch)
treebed9ffabb096d25d3e2ae6857b72fda589f90acf /src
parentc472793a2a55bb529bf4297f04ff785ce52cfc6e (diff)
downloadexternal_mesa3d-f2668f9f214201503419342b980d3afa8b796926.zip
external_mesa3d-f2668f9f214201503419342b980d3afa8b796926.tar.gz
external_mesa3d-f2668f9f214201503419342b980d3afa8b796926.tar.bz2
i965/fs: Fix stack allocation of fs_inst and stop stealing src array provided on construction.
Using 'ralloc*(this, ...)' is wrong if the object has automatic storage or was allocated through any other means. Use normal dynamic memory instead. Reviewed-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/dri/i965/brw_fs.cpp68
-rw-r--r--src/mesa/drivers/dri/i965/brw_ir_fs.h8
2 files changed, 39 insertions, 37 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 23c99b8..2f26425 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -54,13 +54,16 @@ extern "C" {
void
fs_inst::init(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
- fs_reg *src, int sources)
+ const fs_reg *src, unsigned sources)
{
memset(this, 0, sizeof(*this));
+ this->src = new fs_reg[MAX2(sources, 3)];
+ for (unsigned i = 0; i < sources; i++)
+ this->src[i] = src[i];
+
this->opcode = opcode;
this->dst = dst;
- this->src = src;
this->sources = sources;
this->exec_size = exec_size;
@@ -75,7 +78,7 @@ fs_inst::init(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
if (dst.file == GRF) {
this->exec_size = dst.width;
} else {
- for (int i = 0; i < sources; ++i) {
+ for (unsigned i = 0; i < sources; ++i) {
if (src[i].file != GRF && src[i].file != ATTR)
continue;
@@ -90,7 +93,7 @@ fs_inst::init(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
}
assert(this->exec_size != 0);
- for (int i = 0; i < sources; ++i) {
+ for (unsigned i = 0; i < sources; ++i) {
switch (this->src[i].file) {
case BAD_FILE:
this->src[i].effective_width = 8;
@@ -140,82 +143,68 @@ fs_inst::init(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
fs_inst::fs_inst()
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- init(BRW_OPCODE_NOP, 8, dst, src, 0);
+ init(BRW_OPCODE_NOP, 8, dst, NULL, 0);
}
fs_inst::fs_inst(enum opcode opcode, uint8_t exec_size)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- init(opcode, exec_size, reg_undef, src, 0);
+ init(opcode, exec_size, reg_undef, NULL, 0);
}
fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- init(opcode, 0, dst, src, 0);
+ init(opcode, 0, dst, NULL, 0);
}
fs_inst::fs_inst(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
const fs_reg &src0)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
+ const fs_reg src[1] = { src0 };
init(opcode, exec_size, dst, src, 1);
}
fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst, const fs_reg &src0)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
+ const fs_reg src[1] = { src0 };
init(opcode, 0, dst, src, 1);
}
fs_inst::fs_inst(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
const fs_reg &src0, const fs_reg &src1)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
- src[1] = src1;
+ const fs_reg src[2] = { src0, src1 };
init(opcode, exec_size, dst, src, 2);
}
fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst, const fs_reg &src0,
const fs_reg &src1)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
- src[1] = src1;
+ const fs_reg src[2] = { src0, src1 };
init(opcode, 0, dst, src, 2);
}
fs_inst::fs_inst(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
const fs_reg &src0, const fs_reg &src1, const fs_reg &src2)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
- src[1] = src1;
- src[2] = src2;
+ const fs_reg src[3] = { src0, src1, src2 };
init(opcode, exec_size, dst, src, 3);
}
fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst, const fs_reg &src0,
const fs_reg &src1, const fs_reg &src2)
{
- fs_reg *src = ralloc_array(this, fs_reg, 3);
- src[0] = src0;
- src[1] = src1;
- src[2] = src2;
+ const fs_reg src[3] = { src0, src1, src2 };
init(opcode, 0, dst, src, 3);
}
-fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst, fs_reg src[], int sources)
+fs_inst::fs_inst(enum opcode opcode, const fs_reg &dst,
+ const fs_reg src[], unsigned sources)
{
init(opcode, 0, dst, src, sources);
}
fs_inst::fs_inst(enum opcode opcode, uint8_t exec_width, const fs_reg &dst,
- fs_reg src[], int sources)
+ const fs_reg src[], unsigned sources)
{
init(opcode, exec_width, dst, src, sources);
}
@@ -224,17 +213,28 @@ fs_inst::fs_inst(const fs_inst &that)
{
memcpy(this, &that, sizeof(that));
- this->src = ralloc_array(this, fs_reg, that.sources);
+ this->src = new fs_reg[MAX2(that.sources, 3)];
- for (int i = 0; i < that.sources; i++)
+ for (unsigned i = 0; i < that.sources; i++)
this->src[i] = that.src[i];
}
+fs_inst::~fs_inst()
+{
+ delete[] this->src;
+}
+
void
fs_inst::resize_sources(uint8_t num_sources)
{
if (this->sources != num_sources) {
- this->src = reralloc(this, this->src, fs_reg, num_sources);
+ fs_reg *src = new fs_reg[MAX2(num_sources, 3)];
+
+ for (unsigned i = 0; i < MIN2(this->sources, num_sources); ++i)
+ src[i] = this->src[i];
+
+ delete[] this->src;
+ this->src = src;
this->sources = num_sources;
}
}
@@ -374,7 +374,7 @@ fs_visitor::LOAD_PAYLOAD(const fs_reg &dst, fs_reg *src, int sources)
* dealing with whole registers. If this ever changes, we can deal
* with it later.
*/
- int size = src[i].effective_width * type_sz(src[i].type);
+ int size = inst->src[i].effective_width * type_sz(src[i].type);
assert(size % 32 == 0);
inst->regs_written += (size + 31) / 32;
}
diff --git a/src/mesa/drivers/dri/i965/brw_ir_fs.h b/src/mesa/drivers/dri/i965/brw_ir_fs.h
index 0c7dcaf..9ef1261 100644
--- a/src/mesa/drivers/dri/i965/brw_ir_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_ir_fs.h
@@ -191,7 +191,7 @@ class fs_inst : public backend_instruction {
fs_inst &operator=(const fs_inst &);
void init(enum opcode opcode, uint8_t exec_width, const fs_reg &dst,
- fs_reg *src, int sources);
+ const fs_reg *src, unsigned sources);
public:
DECLARE_RALLOC_CXX_OPERATORS(fs_inst)
@@ -210,10 +210,12 @@ public:
const fs_reg &src0, const fs_reg &src1, const fs_reg &src2);
fs_inst(enum opcode opcode, const fs_reg &dst, const fs_reg &src0,
const fs_reg &src1, const fs_reg &src2);
- fs_inst(enum opcode opcode, const fs_reg &dst, fs_reg src[], int sources);
+ fs_inst(enum opcode opcode, const fs_reg &dst, const fs_reg src[],
+ unsigned sources);
fs_inst(enum opcode opcode, uint8_t exec_size, const fs_reg &dst,
- fs_reg src[], int sources);
+ const fs_reg src[], unsigned sources);
fs_inst(const fs_inst &that);
+ ~fs_inst();
void resize_sources(uint8_t num_sources);