2011-08-07 21:36:11 +01:00
|
|
|
/* Copyright © 2011 Intel Corporation
|
2011-05-02 17:45:40 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "brw_vec4.h"
|
2014-05-19 18:20:37 +01:00
|
|
|
#include "brw_cfg.h"
|
2011-05-02 17:45:40 +01:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "brw_eu.h"
|
2012-01-18 12:53:40 +00:00
|
|
|
#include "main/macros.h"
|
2012-10-08 18:21:30 +01:00
|
|
|
#include "program/prog_print.h"
|
|
|
|
#include "program/prog_parameter.h"
|
2011-05-02 17:45:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace brw {
|
|
|
|
|
|
|
|
struct brw_reg
|
|
|
|
vec4_instruction::get_dst(void)
|
|
|
|
{
|
|
|
|
struct brw_reg brw_reg;
|
|
|
|
|
|
|
|
switch (dst.file) {
|
|
|
|
case GRF:
|
|
|
|
brw_reg = brw_vec8_grf(dst.reg + dst.reg_offset, 0);
|
|
|
|
brw_reg = retype(brw_reg, dst.type);
|
|
|
|
brw_reg.dw1.bits.writemask = dst.writemask;
|
|
|
|
break;
|
|
|
|
|
2011-09-06 20:29:15 +01:00
|
|
|
case MRF:
|
|
|
|
brw_reg = brw_message_reg(dst.reg + dst.reg_offset);
|
|
|
|
brw_reg = retype(brw_reg, dst.type);
|
|
|
|
brw_reg.dw1.bits.writemask = dst.writemask;
|
|
|
|
break;
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
case HW_REG:
|
2014-02-19 14:21:07 +00:00
|
|
|
assert(dst.type == dst.fixed_hw_reg.type);
|
2011-05-02 17:45:40 +01:00
|
|
|
brw_reg = dst.fixed_hw_reg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BAD_FILE:
|
|
|
|
brw_reg = brw_null_reg();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(!"not reached");
|
|
|
|
brw_reg = brw_null_reg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return brw_reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct brw_reg
|
2013-07-13 15:09:54 +01:00
|
|
|
vec4_instruction::get_src(const struct brw_vec4_prog_data *prog_data, int i)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
|
|
|
struct brw_reg brw_reg;
|
|
|
|
|
|
|
|
switch (src[i].file) {
|
|
|
|
case GRF:
|
|
|
|
brw_reg = brw_vec8_grf(src[i].reg + src[i].reg_offset, 0);
|
|
|
|
brw_reg = retype(brw_reg, src[i].type);
|
|
|
|
brw_reg.dw1.bits.swizzle = src[i].swizzle;
|
|
|
|
if (src[i].abs)
|
|
|
|
brw_reg = brw_abs(brw_reg);
|
|
|
|
if (src[i].negate)
|
|
|
|
brw_reg = negate(brw_reg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMM:
|
|
|
|
switch (src[i].type) {
|
|
|
|
case BRW_REGISTER_TYPE_F:
|
|
|
|
brw_reg = brw_imm_f(src[i].imm.f);
|
|
|
|
break;
|
|
|
|
case BRW_REGISTER_TYPE_D:
|
|
|
|
brw_reg = brw_imm_d(src[i].imm.i);
|
|
|
|
break;
|
|
|
|
case BRW_REGISTER_TYPE_UD:
|
|
|
|
brw_reg = brw_imm_ud(src[i].imm.u);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(!"not reached");
|
|
|
|
brw_reg = brw_null_reg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-04 20:50:16 +01:00
|
|
|
case UNIFORM:
|
2013-07-13 15:09:54 +01:00
|
|
|
brw_reg = stride(brw_vec4_grf(prog_data->dispatch_grf_start_reg +
|
|
|
|
(src[i].reg + src[i].reg_offset) / 2,
|
2011-05-04 20:50:16 +01:00
|
|
|
((src[i].reg + src[i].reg_offset) % 2) * 4),
|
|
|
|
0, 4, 1);
|
|
|
|
brw_reg = retype(brw_reg, src[i].type);
|
|
|
|
brw_reg.dw1.bits.swizzle = src[i].swizzle;
|
|
|
|
if (src[i].abs)
|
|
|
|
brw_reg = brw_abs(brw_reg);
|
|
|
|
if (src[i].negate)
|
|
|
|
brw_reg = negate(brw_reg);
|
2011-08-22 18:35:24 +01:00
|
|
|
|
|
|
|
/* This should have been moved to pull constants. */
|
|
|
|
assert(!src[i].reladdr);
|
2011-05-04 20:50:16 +01:00
|
|
|
break;
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
case HW_REG:
|
2014-02-19 14:21:07 +00:00
|
|
|
assert(src[i].type == src[i].fixed_hw_reg.type);
|
2011-05-02 17:45:40 +01:00
|
|
|
brw_reg = src[i].fixed_hw_reg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BAD_FILE:
|
|
|
|
/* Probably unused. */
|
|
|
|
brw_reg = brw_null_reg();
|
|
|
|
break;
|
|
|
|
case ATTR:
|
|
|
|
default:
|
|
|
|
assert(!"not reached");
|
|
|
|
brw_reg = brw_null_reg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return brw_reg;
|
|
|
|
}
|
|
|
|
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::vec4_generator(struct brw_context *brw,
|
2013-04-09 22:31:28 +01:00
|
|
|
struct gl_shader_program *shader_prog,
|
2013-02-17 19:25:37 +00:00
|
|
|
struct gl_program *prog,
|
2013-08-15 04:42:29 +01:00
|
|
|
struct brw_vec4_prog_data *prog_data,
|
2013-03-23 04:55:03 +00:00
|
|
|
void *mem_ctx,
|
|
|
|
bool debug_flag)
|
2013-08-15 04:42:29 +01:00
|
|
|
: brw(brw), shader_prog(shader_prog), prog(prog), prog_data(prog_data),
|
|
|
|
mem_ctx(mem_ctx), debug_flag(debug_flag)
|
2012-11-27 06:53:10 +00:00
|
|
|
{
|
2012-11-27 08:16:05 +00:00
|
|
|
p = rzalloc(mem_ctx, struct brw_compile);
|
|
|
|
brw_init_compile(brw, p, mem_ctx);
|
2012-11-27 06:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4_generator::~vec4_generator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_math1_gen4(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
|
|
|
brw_math(p,
|
|
|
|
dst,
|
|
|
|
brw_math_function(inst->opcode),
|
|
|
|
inst->base_mrf,
|
|
|
|
src,
|
2011-08-30 23:59:26 +01:00
|
|
|
BRW_MATH_DATA_VECTOR,
|
2011-05-02 17:45:40 +01:00
|
|
|
BRW_MATH_PRECISION_FULL);
|
|
|
|
}
|
|
|
|
|
2011-08-09 20:30:41 +01:00
|
|
|
static void
|
|
|
|
check_gen6_math_src_arg(struct brw_reg src)
|
|
|
|
{
|
|
|
|
/* Source swizzles are ignored. */
|
|
|
|
assert(!src.abs);
|
|
|
|
assert(!src.negate);
|
2011-09-30 21:48:18 +01:00
|
|
|
assert(src.dw1.bits.swizzle == BRW_SWIZZLE_XYZW);
|
2011-08-09 20:30:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_math1_gen6(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
2011-08-09 19:00:28 +01:00
|
|
|
/* Can't do writemask because math can't be align16. */
|
|
|
|
assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
|
2011-08-09 20:30:41 +01:00
|
|
|
check_gen6_math_src_arg(src);
|
2011-08-09 19:00:28 +01:00
|
|
|
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
2011-05-02 17:45:40 +01:00
|
|
|
brw_math(p,
|
|
|
|
dst,
|
|
|
|
brw_math_function(inst->opcode),
|
|
|
|
inst->base_mrf,
|
|
|
|
src,
|
|
|
|
BRW_MATH_DATA_SCALAR,
|
|
|
|
BRW_MATH_PRECISION_FULL);
|
2011-08-09 19:00:28 +01:00
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 20:24:47 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_math2_gen7(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src0,
|
|
|
|
struct brw_reg src1)
|
2011-10-18 20:24:47 +01:00
|
|
|
{
|
|
|
|
brw_math2(p,
|
|
|
|
dst,
|
|
|
|
brw_math_function(inst->opcode),
|
|
|
|
src0, src1);
|
|
|
|
}
|
|
|
|
|
2011-08-09 20:30:41 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_math2_gen6(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src0,
|
|
|
|
struct brw_reg src1)
|
2011-08-09 20:30:41 +01:00
|
|
|
{
|
|
|
|
/* Can't do writemask because math can't be align16. */
|
|
|
|
assert(dst.dw1.bits.writemask == WRITEMASK_XYZW);
|
|
|
|
/* Source swizzles are ignored. */
|
|
|
|
check_gen6_math_src_arg(src0);
|
|
|
|
check_gen6_math_src_arg(src1);
|
|
|
|
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_math2(p,
|
|
|
|
dst,
|
|
|
|
brw_math_function(inst->opcode),
|
|
|
|
src0, src1);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_math2_gen4(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src0,
|
|
|
|
struct brw_reg src1)
|
2011-08-09 20:30:41 +01:00
|
|
|
{
|
2011-09-29 01:37:56 +01:00
|
|
|
/* From the Ironlake PRM, Volume 4, Part 1, Section 6.1.13
|
|
|
|
* "Message Payload":
|
|
|
|
*
|
|
|
|
* "Operand0[7]. For the INT DIV functions, this operand is the
|
|
|
|
* denominator."
|
|
|
|
* ...
|
|
|
|
* "Operand1[7]. For the INT DIV functions, this operand is the
|
|
|
|
* numerator."
|
|
|
|
*/
|
|
|
|
bool is_int_div = inst->opcode != SHADER_OPCODE_POW;
|
|
|
|
struct brw_reg &op0 = is_int_div ? src1 : src0;
|
|
|
|
struct brw_reg &op1 = is_int_div ? src0 : src1;
|
|
|
|
|
2012-08-06 23:02:34 +01:00
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_saturate(p, false);
|
|
|
|
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
|
2011-09-29 01:37:56 +01:00
|
|
|
brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), op1.type), op1);
|
2012-08-06 23:02:34 +01:00
|
|
|
brw_pop_insn_state(p);
|
2011-08-09 20:30:41 +01:00
|
|
|
|
|
|
|
brw_math(p,
|
|
|
|
dst,
|
|
|
|
brw_math_function(inst->opcode),
|
|
|
|
inst->base_mrf,
|
2011-09-29 01:37:56 +01:00
|
|
|
op0,
|
2011-08-09 20:30:41 +01:00
|
|
|
BRW_MATH_DATA_VECTOR,
|
|
|
|
BRW_MATH_PRECISION_FULL);
|
|
|
|
}
|
|
|
|
|
2011-10-26 21:53:11 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_tex(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
2011-10-26 21:53:11 +01:00
|
|
|
{
|
|
|
|
int msg_type = -1;
|
|
|
|
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 5) {
|
2011-10-26 21:53:11 +01:00
|
|
|
switch (inst->opcode) {
|
|
|
|
case SHADER_OPCODE_TEX:
|
|
|
|
case SHADER_OPCODE_TXL:
|
|
|
|
if (inst->shadow_compare) {
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
|
|
|
|
} else {
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHADER_OPCODE_TXD:
|
2013-01-04 15:53:09 +00:00
|
|
|
if (inst->shadow_compare) {
|
|
|
|
/* Gen7.5+. Otherwise, lowered by brw_lower_texture_gradients(). */
|
2013-07-06 08:15:44 +01:00
|
|
|
assert(brw->is_haswell);
|
2013-01-04 15:53:09 +00:00
|
|
|
msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE;
|
|
|
|
} else {
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
|
|
|
|
}
|
2011-10-26 21:53:11 +01:00
|
|
|
break;
|
|
|
|
case SHADER_OPCODE_TXF:
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
|
|
|
|
break;
|
2013-12-10 14:36:31 +00:00
|
|
|
case SHADER_OPCODE_TXF_CMS:
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 7)
|
2013-01-24 08:35:15 +00:00
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS;
|
|
|
|
else
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
|
|
|
|
break;
|
2013-11-29 21:32:16 +00:00
|
|
|
case SHADER_OPCODE_TXF_MCS:
|
|
|
|
assert(brw->gen >= 7);
|
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS;
|
|
|
|
break;
|
2011-10-26 21:53:11 +01:00
|
|
|
case SHADER_OPCODE_TXS:
|
|
|
|
msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
|
|
|
|
break;
|
2013-03-31 09:31:12 +01:00
|
|
|
case SHADER_OPCODE_TG4:
|
2013-10-10 07:42:47 +01:00
|
|
|
if (inst->shadow_compare) {
|
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C;
|
|
|
|
} else {
|
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4;
|
|
|
|
}
|
2013-03-31 09:31:12 +01:00
|
|
|
break;
|
2013-10-08 09:42:10 +01:00
|
|
|
case SHADER_OPCODE_TG4_OFFSET:
|
2013-10-10 07:42:47 +01:00
|
|
|
if (inst->shadow_compare) {
|
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C;
|
|
|
|
} else {
|
|
|
|
msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO;
|
|
|
|
}
|
2013-10-08 09:42:10 +01:00
|
|
|
break;
|
2011-10-26 21:53:11 +01:00
|
|
|
default:
|
2013-03-23 14:22:08 +00:00
|
|
|
assert(!"should not get here: invalid vec4 texture opcode");
|
2011-10-26 21:53:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (inst->opcode) {
|
|
|
|
case SHADER_OPCODE_TEX:
|
|
|
|
case SHADER_OPCODE_TXL:
|
|
|
|
if (inst->shadow_compare) {
|
|
|
|
msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD_COMPARE;
|
|
|
|
assert(inst->mlen == 3);
|
|
|
|
} else {
|
|
|
|
msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD;
|
|
|
|
assert(inst->mlen == 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHADER_OPCODE_TXD:
|
|
|
|
/* There is no sample_d_c message; comparisons are done manually. */
|
|
|
|
msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS;
|
|
|
|
assert(inst->mlen == 4);
|
|
|
|
break;
|
|
|
|
case SHADER_OPCODE_TXF:
|
|
|
|
msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_LD;
|
|
|
|
assert(inst->mlen == 2);
|
|
|
|
break;
|
|
|
|
case SHADER_OPCODE_TXS:
|
|
|
|
msg_type = BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO;
|
|
|
|
assert(inst->mlen == 2);
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-23 14:22:08 +00:00
|
|
|
assert(!"should not get here: invalid vec4 texture opcode");
|
2011-10-26 21:53:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(msg_type != -1);
|
|
|
|
|
2011-11-12 10:21:44 +00:00
|
|
|
/* Load the message header if present. If there's a texture offset, we need
|
|
|
|
* to set it up explicitly and load the offset bitfield. Otherwise, we can
|
|
|
|
* use an implied move from g0 to the first message register.
|
|
|
|
*/
|
2014-01-18 22:29:19 +00:00
|
|
|
if (inst->header_present) {
|
|
|
|
if (brw->gen < 6 && !inst->texture_offset) {
|
|
|
|
/* Set up an implied move from g0 to the MRF. */
|
|
|
|
src = brw_vec8_grf(0, 0);
|
|
|
|
} else {
|
|
|
|
struct brw_reg header =
|
|
|
|
retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD);
|
|
|
|
|
|
|
|
/* Explicitly set up the message header by copying g0 to the MRF. */
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_MOV(p, header, retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
|
|
|
|
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
|
|
|
|
if (inst->texture_offset) {
|
|
|
|
/* Set the texel offset bits in DWord 2. */
|
|
|
|
brw_MOV(p, get_element_ud(header, 2),
|
|
|
|
brw_imm_ud(inst->texture_offset));
|
|
|
|
}
|
2014-01-18 22:32:49 +00:00
|
|
|
|
|
|
|
if (inst->sampler >= 16) {
|
|
|
|
/* The "Sampler Index" field can only store values between 0 and 15.
|
|
|
|
* However, we can add an offset to the "Sampler State Pointer"
|
|
|
|
* field, effectively selecting a different set of 16 samplers.
|
|
|
|
*
|
|
|
|
* The "Sampler State Pointer" needs to be aligned to a 32-byte
|
|
|
|
* offset, and each sampler state is only 16-bytes, so we can't
|
|
|
|
* exclusively use the offset - we have to use both.
|
|
|
|
*/
|
|
|
|
assert(brw->is_haswell); /* field only exists on Haswell */
|
|
|
|
brw_ADD(p,
|
|
|
|
get_element_ud(header, 3),
|
|
|
|
get_element_ud(brw_vec8_grf(0, 0), 3),
|
|
|
|
brw_imm_ud(16 * (inst->sampler / 16) *
|
|
|
|
sizeof(gen7_sampler_state)));
|
|
|
|
}
|
2014-01-18 22:29:19 +00:00
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
2011-10-26 21:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t return_format;
|
|
|
|
|
|
|
|
switch (dst.type) {
|
|
|
|
case BRW_REGISTER_TYPE_D:
|
|
|
|
return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
|
|
|
|
break;
|
|
|
|
case BRW_REGISTER_TYPE_UD:
|
|
|
|
return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:42:10 +01:00
|
|
|
uint32_t surface_index = ((inst->opcode == SHADER_OPCODE_TG4 ||
|
|
|
|
inst->opcode == SHADER_OPCODE_TG4_OFFSET)
|
2013-10-02 22:07:40 +01:00
|
|
|
? prog_data->base.binding_table.gather_texture_start
|
|
|
|
: prog_data->base.binding_table.texture_start) + inst->sampler;
|
2013-09-15 07:23:14 +01:00
|
|
|
|
2011-10-26 21:53:11 +01:00
|
|
|
brw_SAMPLE(p,
|
|
|
|
dst,
|
|
|
|
inst->base_mrf,
|
|
|
|
src,
|
2013-09-15 07:23:14 +01:00
|
|
|
surface_index,
|
2014-01-18 22:32:49 +00:00
|
|
|
inst->sampler % 16,
|
2011-10-26 21:53:11 +01:00
|
|
|
msg_type,
|
|
|
|
1, /* response length */
|
|
|
|
inst->mlen,
|
|
|
|
inst->header_present,
|
|
|
|
BRW_SAMPLER_SIMD_MODE_SIMD4X2,
|
|
|
|
return_format);
|
i965/vs: Rework binding table size calculation.
Unlike the FS, the VS backend already computed the binding table size.
However, it did so poorly: after compilation, it looked to see if any
pull constants/textures/UBOs were in use, and set num_surfaces to the
maximum surface index for that category. If the VS only used a single
texture or UBO, this overcounted by quite a bit.
The shader time surface was also noted at state upload time (during
drawing), not at compile time, which is inefficient. I believe it also
had an off by one error.
This patch computes it accurately, while also simplifying the code.
It also renames num_surfaces to binding_table_size, since num_surfaces
wasn't actually the number of surfaces used. For example, a VS that
used one UBO and no other surfaces would have set num_surfaces to
SURF_INDEX_VS_UBO(1) == 18, rather than 1. A bit of a misnomer there.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-08-15 04:25:40 +01:00
|
|
|
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base, surface_index);
|
2011-10-26 21:53:11 +01:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
void
|
2013-03-21 16:11:12 +00:00
|
|
|
vec4_generator::generate_vs_urb_write(vec4_instruction *inst)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
|
|
|
brw_urb_WRITE(p,
|
|
|
|
brw_null_reg(), /* dest */
|
|
|
|
inst->base_mrf, /* starting mrf reg nr */
|
|
|
|
brw_vec8_grf(0, 0), /* src */
|
2013-08-11 05:13:33 +01:00
|
|
|
inst->urb_write_flags,
|
2011-05-02 17:45:40 +01:00
|
|
|
inst->mlen,
|
|
|
|
0, /* response len */
|
|
|
|
inst->offset, /* urb destination offset */
|
|
|
|
BRW_URB_SWIZZLE_INTERLEAVE);
|
|
|
|
}
|
|
|
|
|
2013-03-21 16:11:12 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_urb_write(vec4_instruction *inst)
|
|
|
|
{
|
|
|
|
struct brw_reg src = brw_message_reg(inst->base_mrf);
|
|
|
|
brw_urb_WRITE(p,
|
|
|
|
brw_null_reg(), /* dest */
|
|
|
|
inst->base_mrf, /* starting mrf reg nr */
|
|
|
|
src,
|
|
|
|
inst->urb_write_flags,
|
|
|
|
inst->mlen,
|
|
|
|
0, /* response len */
|
|
|
|
inst->offset, /* urb destination offset */
|
|
|
|
BRW_URB_SWIZZLE_INTERLEAVE);
|
|
|
|
}
|
|
|
|
|
2013-03-23 14:42:32 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_thread_end(vec4_instruction *inst)
|
|
|
|
{
|
|
|
|
struct brw_reg src = brw_message_reg(inst->base_mrf);
|
|
|
|
brw_urb_WRITE(p,
|
|
|
|
brw_null_reg(), /* dest */
|
|
|
|
inst->base_mrf, /* starting mrf reg nr */
|
|
|
|
src,
|
|
|
|
BRW_URB_WRITE_EOT,
|
|
|
|
1, /* message len */
|
|
|
|
0, /* response len */
|
|
|
|
0, /* urb destination offset */
|
|
|
|
BRW_URB_SWIZZLE_INTERLEAVE);
|
|
|
|
}
|
|
|
|
|
2013-03-23 14:59:13 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_set_write_offset(struct brw_reg dst,
|
|
|
|
struct brw_reg src0,
|
|
|
|
struct brw_reg src1)
|
|
|
|
{
|
|
|
|
/* From p22 of volume 4 part 2 of the Ivy Bridge PRM (2.4.3.1 Message
|
|
|
|
* Header: M0.3):
|
|
|
|
*
|
|
|
|
* Slot 0 Offset. This field, after adding to the Global Offset field
|
|
|
|
* in the message descriptor, specifies the offset (in 256-bit units)
|
|
|
|
* from the start of the URB entry, as referenced by URB Handle 0, at
|
|
|
|
* which the data will be accessed.
|
|
|
|
*
|
|
|
|
* Similar text describes DWORD M0.4, which is slot 1 offset.
|
|
|
|
*
|
|
|
|
* Therefore, we want to multiply DWORDs 0 and 4 of src0 (the x components
|
|
|
|
* of the register for geometry shader invocations 0 and 1) by the
|
|
|
|
* immediate value in src1, and store the result in DWORDs 3 and 4 of dst.
|
|
|
|
*
|
|
|
|
* We can do this with the following EU instruction:
|
|
|
|
*
|
|
|
|
* mul(2) dst.3<1>UD src0<8;2,4>UD src1 { Align1 WE_all }
|
|
|
|
*/
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_MUL(p, suboffset(stride(dst, 2, 2, 1), 3), stride(src0, 8, 2, 4),
|
|
|
|
src1);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2013-03-23 15:18:43 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_set_vertex_count(struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
|
|
|
{
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
|
|
|
|
/* If we think of the src and dst registers as composed of 8 DWORDs each,
|
|
|
|
* we want to pick up the contents of DWORDs 0 and 4 from src, truncate
|
|
|
|
* them to WORDs, and then pack them into DWORD 2 of dst.
|
|
|
|
*
|
|
|
|
* It's easier to get the EU to do this if we think of the src and dst
|
|
|
|
* registers as composed of 16 WORDS each; then, we want to pick up the
|
|
|
|
* contents of WORDs 0 and 8 from src, and pack them into WORDs 4 and 5 of
|
|
|
|
* dst.
|
|
|
|
*
|
|
|
|
* We can do that by the following EU instruction:
|
|
|
|
*
|
|
|
|
* mov (2) dst.4<1>:uw src<8;1,0>:uw { Align1, Q1, NoMask }
|
|
|
|
*/
|
|
|
|
brw_MOV(p, suboffset(stride(retype(dst, BRW_REGISTER_TYPE_UW), 2, 2, 1), 4),
|
|
|
|
stride(retype(src, BRW_REGISTER_TYPE_UW), 8, 1, 0));
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2013-02-19 15:31:16 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_set_dword_2_immed(struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
|
|
|
{
|
|
|
|
assert(src.file == BRW_IMMEDIATE_VALUE);
|
|
|
|
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_MOV(p, suboffset(vec1(dst), 2), src);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2013-04-21 16:51:33 +01:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_prepare_channel_masks(struct brw_reg dst)
|
|
|
|
{
|
|
|
|
/* We want to left shift just DWORD 4 (the x component belonging to the
|
|
|
|
* second geometry shader invocation) by 4 bits. So generate the
|
|
|
|
* instruction:
|
|
|
|
*
|
|
|
|
* shl(1) dst.4<1>UD dst.4<0,1,0>UD 4UD { align1 WE_all }
|
|
|
|
*/
|
|
|
|
dst = suboffset(vec1(dst), 4);
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_SHL(p, dst, dst, brw_imm_ud(4));
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_set_channel_masks(struct brw_reg dst,
|
|
|
|
struct brw_reg src)
|
|
|
|
{
|
|
|
|
/* From p21 of volume 4 part 2 of the Ivy Bridge PRM (2.4.3.1 Message
|
|
|
|
* Header: M0.5):
|
|
|
|
*
|
|
|
|
* 15 Vertex 1 DATA [3] / Vertex 0 DATA[7] Channel Mask
|
|
|
|
*
|
|
|
|
* When Swizzle Control = URB_INTERLEAVED this bit controls Vertex 1
|
|
|
|
* DATA[3], when Swizzle Control = URB_NOSWIZZLE this bit controls
|
|
|
|
* Vertex 0 DATA[7]. This bit is ANDed with the corresponding
|
|
|
|
* channel enable to determine the final channel enable. For the
|
|
|
|
* URB_READ_OWORD & URB_READ_HWORD messages, when final channel
|
|
|
|
* enable is 1 it indicates that Vertex 1 DATA [3] will be included
|
|
|
|
* in the writeback message. For the URB_WRITE_OWORD &
|
|
|
|
* URB_WRITE_HWORD messages, when final channel enable is 1 it
|
|
|
|
* indicates that Vertex 1 DATA [3] will be written to the surface.
|
|
|
|
*
|
|
|
|
* 0: Vertex 1 DATA [3] / Vertex 0 DATA[7] channel not included
|
|
|
|
* 1: Vertex DATA [3] / Vertex 0 DATA[7] channel included
|
|
|
|
*
|
|
|
|
* 14 Vertex 1 DATA [2] Channel Mask
|
|
|
|
* 13 Vertex 1 DATA [1] Channel Mask
|
|
|
|
* 12 Vertex 1 DATA [0] Channel Mask
|
|
|
|
* 11 Vertex 0 DATA [3] Channel Mask
|
|
|
|
* 10 Vertex 0 DATA [2] Channel Mask
|
|
|
|
* 9 Vertex 0 DATA [1] Channel Mask
|
|
|
|
* 8 Vertex 0 DATA [0] Channel Mask
|
|
|
|
*
|
|
|
|
* (This is from a section of the PRM that is agnostic to the particular
|
|
|
|
* type of shader being executed, so "Vertex 0" and "Vertex 1" refer to
|
|
|
|
* geometry shader invocations 0 and 1, respectively). Since we have the
|
|
|
|
* enable flags for geometry shader invocation 0 in bits 3:0 of DWORD 0,
|
|
|
|
* and the enable flags for geometry shader invocation 1 in bits 7:0 of
|
|
|
|
* DWORD 4, we just need to OR them together and store the result in bits
|
|
|
|
* 15:8 of DWORD 5.
|
|
|
|
*
|
|
|
|
* It's easier to get the EU to do this if we think of the src and dst
|
|
|
|
* registers as composed of 32 bytes each; then, we want to pick up the
|
|
|
|
* contents of bytes 0 and 16 from src, OR them together, and store them in
|
|
|
|
* byte 21.
|
|
|
|
*
|
|
|
|
* We can do that by the following EU instruction:
|
|
|
|
*
|
|
|
|
* or(1) dst.21<1>UB src<0,1,0>UB src.16<0,1,0>UB { align1 WE_all }
|
|
|
|
*
|
|
|
|
* Note: this relies on the source register having zeros in (a) bits 7:4 of
|
|
|
|
* DWORD 0 and (b) bits 3:0 of DWORD 4. We can rely on (b) because the
|
|
|
|
* source register was prepared by GS_OPCODE_PREPARE_CHANNEL_MASKS (which
|
|
|
|
* shifts DWORD 4 left by 4 bits), and we can rely on (a) because prior to
|
|
|
|
* the execution of GS_OPCODE_PREPARE_CHANNEL_MASKS, DWORDs 0 and 4 need to
|
|
|
|
* contain valid channel mask values (which are in the range 0x0-0xf).
|
|
|
|
*/
|
|
|
|
dst = retype(dst, BRW_REGISTER_TYPE_UB);
|
|
|
|
src = retype(src, BRW_REGISTER_TYPE_UB);
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_OR(p, suboffset(vec1(dst), 21), vec1(src), suboffset(vec1(src), 16));
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2014-01-25 20:55:24 +00:00
|
|
|
void
|
|
|
|
vec4_generator::generate_gs_get_instance_id(struct brw_reg dst)
|
|
|
|
{
|
|
|
|
/* We want to right shift R0.0 & R0.1 by GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT
|
|
|
|
* and store into dst.0 & dst.4. So generate the instruction:
|
|
|
|
*
|
|
|
|
* shr(8) dst<1> R0<1,4,0> GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT { align1 WE_normal 1Q }
|
|
|
|
*/
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
dst = retype(dst, BRW_REGISTER_TYPE_UD);
|
|
|
|
struct brw_reg r0(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
|
|
|
|
brw_SHR(p, dst, stride(r0, 1, 4, 0),
|
|
|
|
brw_imm_ud(GEN7_GS_PAYLOAD_INSTANCE_ID_SHIFT));
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:36:11 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_oword_dual_block_offsets(struct brw_reg m1,
|
|
|
|
struct brw_reg index)
|
2011-08-07 21:36:11 +01:00
|
|
|
{
|
|
|
|
int second_vertex_offset;
|
|
|
|
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 6)
|
2011-08-07 21:36:11 +01:00
|
|
|
second_vertex_offset = 1;
|
|
|
|
else
|
|
|
|
second_vertex_offset = 16;
|
|
|
|
|
|
|
|
m1 = retype(m1, BRW_REGISTER_TYPE_D);
|
|
|
|
|
|
|
|
/* Set up M1 (message payload). Only the block offsets in M1.0 and
|
|
|
|
* M1.4 are used, and the rest are ignored.
|
|
|
|
*/
|
|
|
|
struct brw_reg m1_0 = suboffset(vec1(m1), 0);
|
|
|
|
struct brw_reg m1_4 = suboffset(vec1(m1), 4);
|
|
|
|
struct brw_reg index_0 = suboffset(vec1(index), 0);
|
|
|
|
struct brw_reg index_4 = suboffset(vec1(index), 4);
|
|
|
|
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
|
|
|
|
brw_MOV(p, m1_0, index_0);
|
|
|
|
|
|
|
|
if (index.file == BRW_IMMEDIATE_VALUE) {
|
2011-08-31 00:40:06 +01:00
|
|
|
index_4.dw1.ud += second_vertex_offset;
|
2011-08-07 21:36:11 +01:00
|
|
|
brw_MOV(p, m1_4, index_4);
|
|
|
|
} else {
|
|
|
|
brw_ADD(p, m1_4, index_4, brw_imm_d(second_vertex_offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2013-08-07 19:31:33 +01:00
|
|
|
void
|
|
|
|
vec4_generator::generate_unpack_flags(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst)
|
|
|
|
{
|
|
|
|
brw_push_insn_state(p);
|
|
|
|
brw_set_mask_control(p, BRW_MASK_DISABLE);
|
|
|
|
brw_set_access_mode(p, BRW_ALIGN_1);
|
|
|
|
|
|
|
|
struct brw_reg flags = brw_flag_reg(0, 0);
|
|
|
|
struct brw_reg dst_0 = suboffset(vec1(dst), 0);
|
|
|
|
struct brw_reg dst_4 = suboffset(vec1(dst), 4);
|
|
|
|
|
|
|
|
brw_AND(p, dst_0, flags, brw_imm_ud(0x0f));
|
|
|
|
brw_AND(p, dst_4, flags, brw_imm_ud(0xf0));
|
|
|
|
brw_SHR(p, dst_4, dst_4, brw_imm_ud(4));
|
|
|
|
|
|
|
|
brw_pop_insn_state(p);
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:36:11 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_scratch_read(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg index)
|
2011-08-07 21:36:11 +01:00
|
|
|
{
|
2011-08-31 00:47:43 +01:00
|
|
|
struct brw_reg header = brw_vec8_grf(0, 0);
|
|
|
|
|
|
|
|
gen6_resolve_implied_move(p, &header, inst->base_mrf);
|
2011-08-07 21:36:11 +01:00
|
|
|
|
|
|
|
generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
|
|
|
|
index);
|
|
|
|
|
|
|
|
uint32_t msg_type;
|
|
|
|
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 6)
|
2011-08-07 21:36:11 +01:00
|
|
|
msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
2013-07-06 08:36:46 +01:00
|
|
|
else if (brw->gen == 5 || brw->is_g4x)
|
2011-08-07 21:36:11 +01:00
|
|
|
msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
|
|
|
else
|
|
|
|
msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
|
|
|
|
|
|
|
/* Each of the 8 channel enables is considered for whether each
|
|
|
|
* dword is written.
|
|
|
|
*/
|
|
|
|
struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
|
|
|
|
brw_set_dest(p, send, dst);
|
2011-08-31 00:47:43 +01:00
|
|
|
brw_set_src0(p, send, header);
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen < 6)
|
2011-08-31 00:47:43 +01:00
|
|
|
send->header.destreg__conditionalmod = inst->base_mrf;
|
2011-08-07 21:36:11 +01:00
|
|
|
brw_set_dp_read_message(p, send,
|
|
|
|
255, /* binding table index: stateless access */
|
|
|
|
BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
|
|
|
|
msg_type,
|
|
|
|
BRW_DATAPORT_READ_TARGET_RENDER_CACHE,
|
|
|
|
2, /* mlen */
|
2012-11-09 19:17:48 +00:00
|
|
|
true, /* header_present */
|
2011-08-07 21:36:11 +01:00
|
|
|
1 /* rlen */);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_scratch_write(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg src,
|
|
|
|
struct brw_reg index)
|
2011-08-07 21:36:11 +01:00
|
|
|
{
|
2011-08-31 00:47:43 +01:00
|
|
|
struct brw_reg header = brw_vec8_grf(0, 0);
|
2011-08-31 01:56:33 +01:00
|
|
|
bool write_commit;
|
2011-08-31 00:47:43 +01:00
|
|
|
|
2011-08-07 21:36:11 +01:00
|
|
|
/* If the instruction is predicated, we'll predicate the send, not
|
|
|
|
* the header setup.
|
|
|
|
*/
|
|
|
|
brw_set_predicate_control(p, false);
|
|
|
|
|
2011-08-31 00:47:43 +01:00
|
|
|
gen6_resolve_implied_move(p, &header, inst->base_mrf);
|
2011-08-07 21:36:11 +01:00
|
|
|
|
|
|
|
generate_oword_dual_block_offsets(brw_message_reg(inst->base_mrf + 1),
|
|
|
|
index);
|
|
|
|
|
|
|
|
brw_MOV(p,
|
|
|
|
retype(brw_message_reg(inst->base_mrf + 2), BRW_REGISTER_TYPE_D),
|
|
|
|
retype(src, BRW_REGISTER_TYPE_D));
|
|
|
|
|
|
|
|
uint32_t msg_type;
|
|
|
|
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 7)
|
2011-10-08 05:09:53 +01:00
|
|
|
msg_type = GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
|
2013-07-06 08:36:46 +01:00
|
|
|
else if (brw->gen == 6)
|
2011-08-07 21:36:11 +01:00
|
|
|
msg_type = GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
|
|
|
|
else
|
|
|
|
msg_type = BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE;
|
|
|
|
|
|
|
|
brw_set_predicate_control(p, inst->predicate);
|
|
|
|
|
2011-08-31 01:56:33 +01:00
|
|
|
/* Pre-gen6, we have to specify write commits to ensure ordering
|
|
|
|
* between reads and writes within a thread. Afterwards, that's
|
|
|
|
* guaranteed and write commits only matter for inter-thread
|
|
|
|
* synchronization.
|
|
|
|
*/
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 6) {
|
2011-08-31 01:56:33 +01:00
|
|
|
write_commit = false;
|
|
|
|
} else {
|
|
|
|
/* The visitor set up our destination register to be g0. This
|
|
|
|
* means that when the next read comes along, we will end up
|
|
|
|
* reading from g0 and causing a block on the write commit. For
|
|
|
|
* write-after-read, we are relying on the value of the previous
|
|
|
|
* read being used (and thus blocking on completion) before our
|
|
|
|
* write is executed. This means we have to be careful in
|
|
|
|
* instruction scheduling to not violate this assumption.
|
|
|
|
*/
|
|
|
|
write_commit = true;
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:36:11 +01:00
|
|
|
/* Each of the 8 channel enables is considered for whether each
|
|
|
|
* dword is written.
|
|
|
|
*/
|
|
|
|
struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
|
|
|
|
brw_set_dest(p, send, dst);
|
2011-08-31 00:47:43 +01:00
|
|
|
brw_set_src0(p, send, header);
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen < 6)
|
2011-08-31 00:47:43 +01:00
|
|
|
send->header.destreg__conditionalmod = inst->base_mrf;
|
2011-08-07 21:36:11 +01:00
|
|
|
brw_set_dp_write_message(p, send,
|
|
|
|
255, /* binding table index: stateless access */
|
|
|
|
BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
|
|
|
|
msg_type,
|
|
|
|
3, /* mlen */
|
|
|
|
true, /* header present */
|
2011-10-08 06:26:40 +01:00
|
|
|
false, /* not a render target write */
|
2011-08-31 01:56:33 +01:00
|
|
|
write_commit, /* rlen */
|
2011-08-07 21:36:11 +01:00
|
|
|
false, /* eot */
|
2011-08-31 01:56:33 +01:00
|
|
|
write_commit);
|
2011-08-07 21:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-08-22 18:35:24 +01:00
|
|
|
void
|
2012-11-27 06:53:10 +00:00
|
|
|
vec4_generator::generate_pull_constant_load(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg index,
|
|
|
|
struct brw_reg offset)
|
2011-08-22 18:35:24 +01:00
|
|
|
{
|
2013-07-06 08:36:46 +01:00
|
|
|
assert(brw->gen <= 7);
|
2012-06-25 22:36:28 +01:00
|
|
|
assert(index.file == BRW_IMMEDIATE_VALUE &&
|
|
|
|
index.type == BRW_REGISTER_TYPE_UD);
|
|
|
|
uint32_t surf_index = index.dw1.ud;
|
|
|
|
|
2011-08-22 18:35:24 +01:00
|
|
|
struct brw_reg header = brw_vec8_grf(0, 0);
|
|
|
|
|
|
|
|
gen6_resolve_implied_move(p, &header, inst->base_mrf);
|
|
|
|
|
|
|
|
brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_D),
|
2012-06-25 22:36:28 +01:00
|
|
|
offset);
|
2011-08-22 18:35:24 +01:00
|
|
|
|
|
|
|
uint32_t msg_type;
|
|
|
|
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 6)
|
2011-08-22 18:35:24 +01:00
|
|
|
msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
2013-07-06 08:36:46 +01:00
|
|
|
else if (brw->gen == 5 || brw->is_g4x)
|
2011-08-22 18:35:24 +01:00
|
|
|
msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
|
|
|
else
|
|
|
|
msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
|
|
|
|
|
|
|
|
/* Each of the 8 channel enables is considered for whether each
|
|
|
|
* dword is written.
|
|
|
|
*/
|
|
|
|
struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
|
|
|
|
brw_set_dest(p, send, dst);
|
|
|
|
brw_set_src0(p, send, header);
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen < 6)
|
2011-08-31 00:47:43 +01:00
|
|
|
send->header.destreg__conditionalmod = inst->base_mrf;
|
2011-08-22 18:35:24 +01:00
|
|
|
brw_set_dp_read_message(p, send,
|
2012-06-25 22:36:28 +01:00
|
|
|
surf_index,
|
2011-08-22 18:35:24 +01:00
|
|
|
BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
|
|
|
|
msg_type,
|
|
|
|
BRW_DATAPORT_READ_TARGET_DATA_CACHE,
|
|
|
|
2, /* mlen */
|
2012-11-09 19:17:48 +00:00
|
|
|
true, /* header_present */
|
2011-08-22 18:35:24 +01:00
|
|
|
1 /* rlen */);
|
i965/vs: Rework binding table size calculation.
Unlike the FS, the VS backend already computed the binding table size.
However, it did so poorly: after compilation, it looked to see if any
pull constants/textures/UBOs were in use, and set num_surfaces to the
maximum surface index for that category. If the VS only used a single
texture or UBO, this overcounted by quite a bit.
The shader time surface was also noted at state upload time (during
drawing), not at compile time, which is inefficient. I believe it also
had an off by one error.
This patch computes it accurately, while also simplifying the code.
It also renames num_surfaces to binding_table_size, since num_surfaces
wasn't actually the number of surfaces used. For example, a VS that
used one UBO and no other surfaces would have set num_surfaces to
SURF_INDEX_VS_UBO(1) == 18, rather than 1. A bit of a misnomer there.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-08-15 04:25:40 +01:00
|
|
|
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base, surf_index);
|
2011-08-22 18:35:24 +01:00
|
|
|
}
|
|
|
|
|
2013-04-04 22:10:18 +01:00
|
|
|
void
|
|
|
|
vec4_generator::generate_pull_constant_load_gen7(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg surf_index,
|
|
|
|
struct brw_reg offset)
|
|
|
|
{
|
|
|
|
assert(surf_index.file == BRW_IMMEDIATE_VALUE &&
|
|
|
|
surf_index.type == BRW_REGISTER_TYPE_UD);
|
|
|
|
|
|
|
|
brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
|
|
|
|
brw_set_dest(p, insn, dst);
|
|
|
|
brw_set_src0(p, insn, offset);
|
|
|
|
brw_set_sampler_message(p, insn,
|
|
|
|
surf_index.dw1.ud,
|
|
|
|
0, /* LD message ignores sampler unit */
|
|
|
|
GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
|
|
|
|
1, /* rlen */
|
|
|
|
1, /* mlen */
|
|
|
|
false, /* no header */
|
|
|
|
BRW_SAMPLER_SIMD_MODE_SIMD4X2,
|
|
|
|
0);
|
i965/vs: Rework binding table size calculation.
Unlike the FS, the VS backend already computed the binding table size.
However, it did so poorly: after compilation, it looked to see if any
pull constants/textures/UBOs were in use, and set num_surfaces to the
maximum surface index for that category. If the VS only used a single
texture or UBO, this overcounted by quite a bit.
The shader time surface was also noted at state upload time (during
drawing), not at compile time, which is inefficient. I believe it also
had an off by one error.
This patch computes it accurately, while also simplifying the code.
It also renames num_surfaces to binding_table_size, since num_surfaces
wasn't actually the number of surfaces used. For example, a VS that
used one UBO and no other surfaces would have set num_surfaces to
SURF_INDEX_VS_UBO(1) == 18, rather than 1. A bit of a misnomer there.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-08-15 04:25:40 +01:00
|
|
|
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base, surf_index.dw1.ud);
|
2013-04-04 22:10:18 +01:00
|
|
|
}
|
|
|
|
|
2013-09-11 22:01:50 +01:00
|
|
|
void
|
|
|
|
vec4_generator::generate_untyped_atomic(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg atomic_op,
|
|
|
|
struct brw_reg surf_index)
|
|
|
|
{
|
|
|
|
assert(atomic_op.file == BRW_IMMEDIATE_VALUE &&
|
|
|
|
atomic_op.type == BRW_REGISTER_TYPE_UD &&
|
|
|
|
surf_index.file == BRW_IMMEDIATE_VALUE &&
|
|
|
|
surf_index.type == BRW_REGISTER_TYPE_UD);
|
|
|
|
|
|
|
|
brw_untyped_atomic(p, dst, brw_message_reg(inst->base_mrf),
|
|
|
|
atomic_op.dw1.ud, surf_index.dw1.ud,
|
|
|
|
inst->mlen, 1);
|
|
|
|
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base, surf_index.dw1.ud);
|
2013-09-11 22:01:50 +01:00
|
|
|
}
|
|
|
|
|
2013-09-11 22:03:13 +01:00
|
|
|
void
|
|
|
|
vec4_generator::generate_untyped_surface_read(vec4_instruction *inst,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg surf_index)
|
|
|
|
{
|
|
|
|
assert(surf_index.file == BRW_IMMEDIATE_VALUE &&
|
|
|
|
surf_index.type == BRW_REGISTER_TYPE_UD);
|
|
|
|
|
|
|
|
brw_untyped_surface_read(p, dst, brw_message_reg(inst->base_mrf),
|
|
|
|
surf_index.dw1.ud,
|
|
|
|
inst->mlen, 1);
|
|
|
|
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base, surf_index.dw1.ud);
|
2013-09-11 22:03:13 +01:00
|
|
|
}
|
|
|
|
|
2013-06-13 19:23:08 +01:00
|
|
|
/**
|
|
|
|
* Generate assembly for a Vec4 IR instruction.
|
|
|
|
*
|
|
|
|
* \param instruction The Vec4 IR instruction to generate code for.
|
|
|
|
* \param dst The destination register.
|
|
|
|
* \param src An array of up to three source registers.
|
|
|
|
*/
|
2011-05-02 17:45:40 +01:00
|
|
|
void
|
2013-02-17 19:34:05 +00:00
|
|
|
vec4_generator::generate_vec4_instruction(vec4_instruction *instruction,
|
|
|
|
struct brw_reg dst,
|
|
|
|
struct brw_reg *src)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
2013-06-13 19:23:08 +01:00
|
|
|
vec4_instruction *inst = (vec4_instruction *) instruction;
|
2011-05-02 17:45:40 +01:00
|
|
|
|
2013-10-16 21:18:11 +01:00
|
|
|
if (dst.width == BRW_WIDTH_4) {
|
|
|
|
/* This happens in attribute fixups for "dual instanced" geometry
|
|
|
|
* shaders, since they use attributes that are vec4's. Since the exec
|
|
|
|
* width is only 4, it's essential that the caller set
|
|
|
|
* force_writemask_all in order to make sure the instruction is executed
|
|
|
|
* regardless of which channels are enabled.
|
|
|
|
*/
|
|
|
|
assert(inst->force_writemask_all);
|
|
|
|
|
|
|
|
/* Fix up any <8;8,1> or <0;4,1> source registers to <4;4,1> to satisfy
|
|
|
|
* the following register region restrictions (from Graphics BSpec:
|
|
|
|
* 3D-Media-GPGPU Engine > EU Overview > Registers and Register Regions
|
|
|
|
* > Register Region Restrictions)
|
|
|
|
*
|
|
|
|
* 1. ExecSize must be greater than or equal to Width.
|
|
|
|
*
|
|
|
|
* 2. If ExecSize = Width and HorzStride != 0, VertStride must be set
|
|
|
|
* to Width * HorzStride."
|
|
|
|
*/
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (src[i].file == BRW_GENERAL_REGISTER_FILE)
|
|
|
|
src[i] = stride(src[i], 4, 4, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
switch (inst->opcode) {
|
2013-06-13 19:23:08 +01:00
|
|
|
case BRW_OPCODE_MOV:
|
|
|
|
brw_MOV(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_ADD:
|
|
|
|
brw_ADD(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_MUL:
|
|
|
|
brw_MUL(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_MACH:
|
|
|
|
brw_MACH(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_MAD:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 6);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_MAD(p, dst, src[0], src[1], src[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_FRC:
|
|
|
|
brw_FRC(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_RNDD:
|
|
|
|
brw_RNDD(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_RNDE:
|
|
|
|
brw_RNDE(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_RNDZ:
|
|
|
|
brw_RNDZ(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_AND:
|
|
|
|
brw_AND(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_OR:
|
|
|
|
brw_OR(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_XOR:
|
|
|
|
brw_XOR(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_NOT:
|
|
|
|
brw_NOT(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_ASR:
|
|
|
|
brw_ASR(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_SHR:
|
|
|
|
brw_SHR(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_SHL:
|
|
|
|
brw_SHL(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_CMP:
|
|
|
|
brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_SEL:
|
|
|
|
brw_SEL(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_DPH:
|
|
|
|
brw_DPH(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_DP4:
|
|
|
|
brw_DP4(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_DP3:
|
|
|
|
brw_DP3(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_DP2:
|
|
|
|
brw_DP2(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_F32TO16:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_F32TO16(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_F16TO32:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_F16TO32(p, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_LRP:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 6);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_LRP(p, dst, src[0], src[1], src[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_BFREV:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
/* BFREV only supports UD type for src and dst. */
|
|
|
|
brw_BFREV(p, retype(dst, BRW_REGISTER_TYPE_UD),
|
|
|
|
retype(src[0], BRW_REGISTER_TYPE_UD));
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_FBH:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
/* FBH only supports UD type for dst. */
|
|
|
|
brw_FBH(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_FBL:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
/* FBL only supports UD type for dst. */
|
|
|
|
brw_FBL(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_CBIT:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
/* CBIT only supports UD type for dst. */
|
|
|
|
brw_CBIT(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
|
|
|
|
break;
|
2013-09-19 21:01:08 +01:00
|
|
|
case BRW_OPCODE_ADDC:
|
|
|
|
assert(brw->gen >= 7);
|
|
|
|
brw_ADDC(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_SUBB:
|
|
|
|
assert(brw->gen >= 7);
|
|
|
|
brw_SUBB(p, dst, src[0], src[1]);
|
|
|
|
break;
|
2014-03-28 13:28:30 +00:00
|
|
|
case BRW_OPCODE_MAC:
|
|
|
|
brw_MAC(p, dst, src[0], src[1]);
|
|
|
|
break;
|
2013-06-13 19:23:08 +01:00
|
|
|
|
|
|
|
case BRW_OPCODE_BFE:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_BFE(p, dst, src[0], src[1], src[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_BFI1:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_BFI1(p, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_BFI2:
|
2013-09-20 06:55:24 +01:00
|
|
|
assert(brw->gen >= 7);
|
2013-06-13 19:23:08 +01:00
|
|
|
brw_BFI2(p, dst, src[0], src[1], src[2]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_IF:
|
|
|
|
if (inst->src[0].file != BAD_FILE) {
|
|
|
|
/* The instruction has an embedded compare (only allowed on gen6) */
|
2013-07-06 08:36:46 +01:00
|
|
|
assert(brw->gen == 6);
|
2013-06-13 19:23:08 +01:00
|
|
|
gen6_IF(p, inst->conditional_mod, src[0], src[1]);
|
|
|
|
} else {
|
|
|
|
struct brw_instruction *brw_inst = brw_IF(p, BRW_EXECUTE_8);
|
|
|
|
brw_inst->header.predicate_control = inst->predicate;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_ELSE:
|
|
|
|
brw_ELSE(p);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_ENDIF:
|
|
|
|
brw_ENDIF(p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_DO:
|
|
|
|
brw_DO(p, BRW_EXECUTE_8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_BREAK:
|
|
|
|
brw_BREAK(p);
|
|
|
|
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
|
|
|
|
break;
|
|
|
|
case BRW_OPCODE_CONTINUE:
|
|
|
|
/* FINISHME: We need to write the loop instruction support still. */
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 6)
|
2013-06-13 19:23:08 +01:00
|
|
|
gen6_CONT(p);
|
|
|
|
else
|
|
|
|
brw_CONT(p);
|
|
|
|
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BRW_OPCODE_WHILE:
|
|
|
|
brw_WHILE(p);
|
|
|
|
break;
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
case SHADER_OPCODE_RCP:
|
|
|
|
case SHADER_OPCODE_RSQ:
|
|
|
|
case SHADER_OPCODE_SQRT:
|
|
|
|
case SHADER_OPCODE_EXP2:
|
|
|
|
case SHADER_OPCODE_LOG2:
|
|
|
|
case SHADER_OPCODE_SIN:
|
|
|
|
case SHADER_OPCODE_COS:
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen == 6) {
|
2011-05-02 17:45:40 +01:00
|
|
|
generate_math1_gen6(inst, dst, src[0]);
|
|
|
|
} else {
|
2011-10-18 20:24:47 +01:00
|
|
|
/* Also works for Gen7. */
|
2011-05-02 17:45:40 +01:00
|
|
|
generate_math1_gen4(inst, dst, src[0]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHADER_OPCODE_POW:
|
2011-09-29 01:37:55 +01:00
|
|
|
case SHADER_OPCODE_INT_QUOTIENT:
|
|
|
|
case SHADER_OPCODE_INT_REMAINDER:
|
2013-07-06 08:36:46 +01:00
|
|
|
if (brw->gen >= 7) {
|
2011-10-18 20:24:47 +01:00
|
|
|
generate_math2_gen7(inst, dst, src[0], src[1]);
|
2013-07-06 08:36:46 +01:00
|
|
|
} else if (brw->gen == 6) {
|
2011-08-09 20:30:41 +01:00
|
|
|
generate_math2_gen6(inst, dst, src[0], src[1]);
|
|
|
|
} else {
|
|
|
|
generate_math2_gen4(inst, dst, src[0], src[1]);
|
|
|
|
}
|
2011-05-02 17:45:40 +01:00
|
|
|
break;
|
|
|
|
|
2011-10-26 21:53:11 +01:00
|
|
|
case SHADER_OPCODE_TEX:
|
|
|
|
case SHADER_OPCODE_TXD:
|
|
|
|
case SHADER_OPCODE_TXF:
|
2013-12-10 14:36:31 +00:00
|
|
|
case SHADER_OPCODE_TXF_CMS:
|
2013-11-29 21:32:16 +00:00
|
|
|
case SHADER_OPCODE_TXF_MCS:
|
2011-10-26 21:53:11 +01:00
|
|
|
case SHADER_OPCODE_TXL:
|
|
|
|
case SHADER_OPCODE_TXS:
|
2013-03-31 09:31:12 +01:00
|
|
|
case SHADER_OPCODE_TG4:
|
2013-10-08 09:42:10 +01:00
|
|
|
case SHADER_OPCODE_TG4_OFFSET:
|
2011-10-26 21:53:11 +01:00
|
|
|
generate_tex(inst, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
case VS_OPCODE_URB_WRITE:
|
2013-03-21 16:11:12 +00:00
|
|
|
generate_vs_urb_write(inst);
|
2011-05-02 17:45:40 +01:00
|
|
|
break;
|
|
|
|
|
2013-10-16 19:45:06 +01:00
|
|
|
case SHADER_OPCODE_GEN4_SCRATCH_READ:
|
2011-08-07 21:36:11 +01:00
|
|
|
generate_scratch_read(inst, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2013-10-16 19:45:06 +01:00
|
|
|
case SHADER_OPCODE_GEN4_SCRATCH_WRITE:
|
2011-08-07 21:36:11 +01:00
|
|
|
generate_scratch_write(inst, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
2011-08-22 18:35:24 +01:00
|
|
|
case VS_OPCODE_PULL_CONSTANT_LOAD:
|
2012-06-25 22:36:28 +01:00
|
|
|
generate_pull_constant_load(inst, dst, src[0], src[1]);
|
2011-08-22 18:35:24 +01:00
|
|
|
break;
|
|
|
|
|
2013-04-04 22:10:18 +01:00
|
|
|
case VS_OPCODE_PULL_CONSTANT_LOAD_GEN7:
|
|
|
|
generate_pull_constant_load_gen7(inst, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
2013-03-21 16:11:12 +00:00
|
|
|
case GS_OPCODE_URB_WRITE:
|
|
|
|
generate_gs_urb_write(inst);
|
|
|
|
break;
|
|
|
|
|
2013-03-23 14:42:32 +00:00
|
|
|
case GS_OPCODE_THREAD_END:
|
|
|
|
generate_gs_thread_end(inst);
|
|
|
|
break;
|
|
|
|
|
2013-03-23 14:59:13 +00:00
|
|
|
case GS_OPCODE_SET_WRITE_OFFSET:
|
|
|
|
generate_gs_set_write_offset(dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
2013-03-23 15:18:43 +00:00
|
|
|
case GS_OPCODE_SET_VERTEX_COUNT:
|
|
|
|
generate_gs_set_vertex_count(dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2013-02-19 15:31:16 +00:00
|
|
|
case GS_OPCODE_SET_DWORD_2_IMMED:
|
|
|
|
generate_gs_set_dword_2_immed(dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2013-04-21 16:51:33 +01:00
|
|
|
case GS_OPCODE_PREPARE_CHANNEL_MASKS:
|
|
|
|
generate_gs_prepare_channel_masks(dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_OPCODE_SET_CHANNEL_MASKS:
|
|
|
|
generate_gs_set_channel_masks(dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2014-01-25 20:55:24 +00:00
|
|
|
case GS_OPCODE_GET_INSTANCE_ID:
|
|
|
|
generate_gs_get_instance_id(dst);
|
|
|
|
break;
|
|
|
|
|
2012-11-27 22:10:52 +00:00
|
|
|
case SHADER_OPCODE_SHADER_TIME_ADD:
|
2013-10-02 22:07:40 +01:00
|
|
|
brw_shader_time_add(p, src[0],
|
|
|
|
prog_data->base.binding_table.shader_time_start);
|
2013-11-27 03:56:07 +00:00
|
|
|
brw_mark_surface_used(&prog_data->base,
|
|
|
|
prog_data->base.binding_table.shader_time_start);
|
2012-11-27 22:10:52 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-11 22:01:50 +01:00
|
|
|
case SHADER_OPCODE_UNTYPED_ATOMIC:
|
|
|
|
generate_untyped_atomic(inst, dst, src[0], src[1]);
|
|
|
|
break;
|
|
|
|
|
2013-09-11 22:03:13 +01:00
|
|
|
case SHADER_OPCODE_UNTYPED_SURFACE_READ:
|
|
|
|
generate_untyped_surface_read(inst, dst, src[0]);
|
|
|
|
break;
|
|
|
|
|
2013-08-07 19:31:33 +01:00
|
|
|
case VS_OPCODE_UNPACK_FLAGS_SIMD4X2:
|
|
|
|
generate_unpack_flags(inst, dst);
|
|
|
|
break;
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
default:
|
2012-11-14 22:24:31 +00:00
|
|
|
if (inst->opcode < (int) ARRAY_SIZE(opcode_descs)) {
|
2013-03-23 14:22:08 +00:00
|
|
|
_mesa_problem(&brw->ctx, "Unsupported opcode in `%s' in vec4\n",
|
2012-11-27 05:56:06 +00:00
|
|
|
opcode_descs[inst->opcode].name);
|
2011-05-02 17:45:40 +01:00
|
|
|
} else {
|
2013-03-23 14:22:08 +00:00
|
|
|
_mesa_problem(&brw->ctx, "Unsupported opcode %d in vec4", inst->opcode);
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
2012-11-27 05:56:06 +00:00
|
|
|
abort();
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-19 18:20:37 +01:00
|
|
|
vec4_generator::generate_code(exec_list *instructions,
|
|
|
|
struct annotation_info *annotation)
|
2011-05-02 17:45:40 +01:00
|
|
|
{
|
2013-03-23 04:55:03 +00:00
|
|
|
if (unlikely(debug_flag)) {
|
2014-02-03 19:13:48 +00:00
|
|
|
if (shader_prog) {
|
2013-12-23 07:29:31 +00:00
|
|
|
fprintf(stderr, "Native code for %s vertex shader %d:\n",
|
|
|
|
shader_prog->Label ? shader_prog->Label : "unnamed",
|
|
|
|
shader_prog->Name);
|
2012-10-08 18:21:30 +01:00
|
|
|
} else {
|
2013-12-23 07:29:31 +00:00
|
|
|
fprintf(stderr, "Native code for vertex program %d:\n", prog->Id);
|
2012-10-08 18:21:30 +01:00
|
|
|
}
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
2014-05-19 18:20:37 +01:00
|
|
|
cfg_t *cfg = NULL;
|
|
|
|
if (unlikely(debug_flag))
|
|
|
|
cfg = new(mem_ctx) cfg_t(instructions);
|
|
|
|
|
2012-11-27 06:53:10 +00:00
|
|
|
foreach_list(node, instructions) {
|
2011-05-02 17:45:40 +01:00
|
|
|
vec4_instruction *inst = (vec4_instruction *)node;
|
|
|
|
struct brw_reg src[3], dst;
|
|
|
|
|
2014-05-19 18:20:37 +01:00
|
|
|
if (unlikely(debug_flag))
|
|
|
|
annotate(brw, annotation, cfg, inst, p->next_insn_offset);
|
2011-05-02 17:45:40 +01:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3; i++) {
|
2013-07-13 15:09:54 +01:00
|
|
|
src[i] = inst->get_src(this->prog_data, i);
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
dst = inst->get_dst();
|
|
|
|
|
|
|
|
brw_set_conditionalmod(p, inst->conditional_mod);
|
|
|
|
brw_set_predicate_control(p, inst->predicate);
|
|
|
|
brw_set_predicate_inverse(p, inst->predicate_inverse);
|
|
|
|
brw_set_saturate(p, inst->saturate);
|
2012-11-28 22:16:03 +00:00
|
|
|
brw_set_mask_control(p, inst->force_writemask_all);
|
2014-04-04 14:51:59 +01:00
|
|
|
brw_set_acc_write_control(p, inst->writes_accumulator);
|
2011-05-02 17:45:40 +01:00
|
|
|
|
2012-12-01 02:29:34 +00:00
|
|
|
unsigned pre_emit_nr_insn = p->nr_insn;
|
|
|
|
|
2013-06-13 19:23:08 +01:00
|
|
|
generate_vec4_instruction(inst, dst, src);
|
2011-05-02 17:45:40 +01:00
|
|
|
|
2012-12-01 02:29:34 +00:00
|
|
|
if (inst->no_dd_clear || inst->no_dd_check) {
|
|
|
|
assert(p->nr_insn == pre_emit_nr_insn + 1 ||
|
|
|
|
!"no_dd_check or no_dd_clear set for IR emitting more "
|
|
|
|
"than 1 instruction");
|
|
|
|
|
|
|
|
struct brw_instruction *last = &p->store[pre_emit_nr_insn];
|
|
|
|
|
|
|
|
if (inst->no_dd_clear)
|
|
|
|
last->header.dependency_control |= BRW_DEPENDENCY_NOTCLEARED;
|
|
|
|
if (inst->no_dd_check)
|
|
|
|
last->header.dependency_control |= BRW_DEPENDENCY_NOTCHECKED;
|
|
|
|
}
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
brw_set_uip_jip(p);
|
2014-05-19 18:20:37 +01:00
|
|
|
annotation_finalize(annotation, p->next_insn_offset);
|
2011-05-02 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
2012-11-27 06:53:10 +00:00
|
|
|
const unsigned *
|
|
|
|
vec4_generator::generate_assembly(exec_list *instructions,
|
|
|
|
unsigned *assembly_size)
|
|
|
|
{
|
2014-05-19 18:20:37 +01:00
|
|
|
struct annotation_info annotation;
|
|
|
|
memset(&annotation, 0, sizeof(annotation));
|
|
|
|
|
2012-11-27 06:53:10 +00:00
|
|
|
brw_set_access_mode(p, BRW_ALIGN_16);
|
2014-05-19 18:20:37 +01:00
|
|
|
generate_code(instructions, &annotation);
|
|
|
|
brw_compact_instructions(p, 0, annotation.ann_count, annotation.ann);
|
|
|
|
|
|
|
|
if (unlikely(debug_flag)) {
|
|
|
|
dump_assembly(p->store, annotation.ann_count, annotation.ann,
|
|
|
|
brw, prog, brw_disassemble);
|
|
|
|
ralloc_free(annotation.ann);
|
|
|
|
}
|
|
|
|
|
2012-11-27 06:53:10 +00:00
|
|
|
return brw_get_program(p, assembly_size);
|
|
|
|
}
|
|
|
|
|
2011-05-02 17:45:40 +01:00
|
|
|
} /* namespace brw */
|