summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Forbes <[email protected]>2014-08-10 11:42:08 +1200
committerChris Forbes <[email protected]>2014-08-15 19:10:32 +1200
commit301b71557b2f24f7f59402f634cd531d0adb3349 (patch)
treea2018e4940437828714f8b3c2eb30754f3c13705 /src
parent86dc34a0b0d967e9c8611bc29178fdb1de22c724 (diff)
i965/vec4: Add support for non-const sampler indices in generator
Signed-off-by: Chris Forbes <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/dri/i965/brw_vec4_generator.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
index 2bf72c17862..1b1e64773e6 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_generator.cpp
@@ -383,7 +383,57 @@ vec4_generator::generate_tex(vec4_instruction *inst,
brw_mark_surface_used(&prog_data->base, sampler + base_binding_table_index);
} else {
- /* XXX: Non-constant sampler index. */
+ /* Non-constant sampler index. */
+ /* Note: this clobbers `dst` as a temporary before emitting the send */
+
+ struct brw_reg addr = vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD));
+ struct brw_reg temp = vec1(retype(dst, BRW_REGISTER_TYPE_UD));
+
+ struct brw_reg sampler_reg = vec1(retype(sampler_index, BRW_REGISTER_TYPE_UD));
+
+ brw_push_insn_state(p);
+ brw_set_default_mask_control(p, BRW_MASK_DISABLE);
+ brw_set_default_access_mode(p, BRW_ALIGN_1);
+
+ /* Some care required: `sampler` and `temp` may alias:
+ * addr = sampler & 0xff
+ * temp = (sampler << 8) & 0xf00
+ * addr = addr | temp
+ */
+ brw_ADD(p, addr, sampler_reg, brw_imm_ud(base_binding_table_index));
+ brw_SHL(p, temp, sampler_reg, brw_imm_ud(8u));
+ brw_AND(p, temp, temp, brw_imm_ud(0x0f00));
+ brw_AND(p, addr, addr, brw_imm_ud(0x0ff));
+ brw_OR(p, addr, addr, temp);
+
+ /* a0.0 |= <descriptor> */
+ brw_inst *insn_or = brw_next_insn(p, BRW_OPCODE_OR);
+ brw_set_sampler_message(p, insn_or,
+ 0 /* surface */,
+ 0 /* sampler */,
+ msg_type,
+ 1 /* rlen */,
+ inst->mlen /* mlen */,
+ inst->header_present /* header */,
+ BRW_SAMPLER_SIMD_MODE_SIMD4X2,
+ return_format);
+ brw_inst_set_exec_size(p->brw, insn_or, BRW_EXECUTE_1);
+ brw_inst_set_src1_reg_type(p->brw, insn_or, BRW_REGISTER_TYPE_UD);
+ brw_set_src0(p, insn_or, addr);
+ brw_set_dest(p, insn_or, addr);
+
+
+ /* dst = send(offset, a0.0) */
+ brw_inst *insn_send = brw_next_insn(p, BRW_OPCODE_SEND);
+ brw_set_dest(p, insn_send, dst);
+ brw_set_src0(p, insn_send, src);
+ brw_set_indirect_send_descriptor(p, insn_send, BRW_SFID_SAMPLER, addr);
+
+ brw_pop_insn_state(p);
+
+ /* visitor knows more than we do about the surface limit required,
+ * so has already done marking.
+ */
}
}