From 760c6777a0530b4894dec564cdf218f5364b4df1 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 21 Feb 2014 15:23:42 -0800 Subject: [PATCH] i965/fs: Drop the emit(fs_inst) overload. Using this emit function implicitly creates three copies, which is pointlessly inefficient. 1. Code creates the original instruction. 2. Calling emit(fs_inst) copies it into the function. 3. It then allocates a new fs_inst and copies it into that. The second could be eliminated by changing the signature to fs_inst(const fs_inst &) but that wouldn't eliminate the third. Making callers heap allocate the instruction and call emit(fs_inst *) allows us to just use the original one, with no extra copies, and isn't much more of a burden. Reviewed-by: Matt Turner Signed-off-by: Kenneth Graunke --- src/mesa/drivers/dri/i965/brw_fs.cpp | 14 +++++----- src/mesa/drivers/dri/i965/brw_fs.h | 1 - src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 27 ++++++++------------ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index 65ee2f021e4..a88c621d047 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -642,8 +642,8 @@ fs_visitor::emit_shader_time_write(enum shader_time_shader_type type, else payload = fs_reg(this, glsl_type::uint_type); - emit(fs_inst(SHADER_OPCODE_SHADER_TIME_ADD, - fs_reg(), payload, offset, value)); + emit(new(mem_ctx) fs_inst(SHADER_OPCODE_SHADER_TIME_ADD, + fs_reg(), payload, offset, value)); } void @@ -672,32 +672,32 @@ fs_visitor::fail(const char *format, ...) fs_inst * fs_visitor::emit(enum opcode opcode) { - return emit(fs_inst(opcode)); + return emit(new(mem_ctx) fs_inst(opcode)); } fs_inst * fs_visitor::emit(enum opcode opcode, fs_reg dst) { - return emit(fs_inst(opcode, 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(fs_inst(opcode, dst, 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(fs_inst(opcode, dst, src0, 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(fs_inst(opcode, dst, src0, src1, src2)); + return emit(new(mem_ctx) fs_inst(opcode, dst, src0, src1, src2)); } void diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 1d95ed72201..fff7d8e474d 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -284,7 +284,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); diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp index 9a0090dcc38..9b090be7bde 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp @@ -743,8 +743,8 @@ fs_visitor::visit(ir_expression *ir) packed_consts.type = result.type; fs_reg const_offset_reg = fs_reg(const_offset->value.u[0] & ~15); - emit(fs_inst(FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD, - packed_consts, surf_index, const_offset_reg)); + emit(new(mem_ctx) fs_inst(FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD, + packed_consts, surf_index, const_offset_reg)); for (int i = 0; i < ir->type->vector_elements; i++) { packed_consts.set_smear(const_offset->value.u[0] % 16 / 4 + i); @@ -2399,9 +2399,10 @@ fs_visitor::emit_untyped_atomic(unsigned atomic_op, unsigned surf_index, } /* Emit the instruction. */ - fs_inst inst(SHADER_OPCODE_UNTYPED_ATOMIC, dst, atomic_op, surf_index); - inst.base_mrf = 0; - inst.mlen = mlen; + fs_inst *inst = new(mem_ctx) fs_inst(SHADER_OPCODE_UNTYPED_ATOMIC, dst, + atomic_op, surf_index); + inst->base_mrf = 0; + inst->mlen = mlen; emit(inst); } @@ -2432,21 +2433,13 @@ fs_visitor::emit_untyped_surface_read(unsigned surf_index, fs_reg dst, mlen += operand_len; /* Emit the instruction. */ - fs_inst inst(SHADER_OPCODE_UNTYPED_SURFACE_READ, dst, surf_index); - inst.base_mrf = 0; - inst.mlen = mlen; + fs_inst *inst = new(mem_ctx) + fs_inst(SHADER_OPCODE_UNTYPED_SURFACE_READ, dst, surf_index); + inst->base_mrf = 0; + inst->mlen = mlen; 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) { -- 2.30.2