if (variable_storage(ir))
return;
- if (strcmp(ir->name, "gl_FragColor") == 0) {
- this->frag_color = ir;
- } else if (strcmp(ir->name, "gl_FragData") == 0) {
- this->frag_data = ir;
- } else if (strcmp(ir->name, "gl_FragDepth") == 0) {
- this->frag_depth = ir;
- }
-
if (ir->mode == ir_var_in) {
if (!strcmp(ir->name, "gl_FragCoord")) {
reg = emit_fragcoord_interpolation(ir);
assert(reg);
hash_table_insert(this->variable_ht, reg, ir);
return;
- }
+ } else if (ir->mode == ir_var_out) {
+ reg = new(this->mem_ctx) fs_reg(this, ir->type);
- if (ir->mode == ir_var_uniform) {
+ if (ir->location == FRAG_RESULT_COLOR) {
+ /* Writing gl_FragColor outputs to all color regions. */
+ for (int i = 0; i < MAX2(c->key.nr_color_regions, 1); i++) {
+ this->outputs[i] = *reg;
+ }
+ } else if (ir->location == FRAG_RESULT_DEPTH) {
+ this->frag_depth = ir;
+ } else {
+ /* gl_FragData or a user-defined FS output */
+ assert(ir->location >= FRAG_RESULT_DATA0 &&
+ ir->location < FRAG_RESULT_DATA0 + BRW_MAX_DRAW_BUFFERS);
+
+ /* General color output. */
+ for (unsigned int i = 0; i < MAX2(1, ir->type->length); i++) {
+ int output = ir->location - FRAG_RESULT_DATA0 + i;
+ this->outputs[output] = *reg;
+ this->outputs[output].reg_offset += 4 * i;
+ }
+ }
+ } else if (ir->mode == ir_var_uniform) {
int param_index = c->prog_data.nr_params;
if (c->dispatch_width == 16) {
if (intel->gen < 5)
temp.type = op[0].type;
+ resolve_ud_negate(&op[0]);
+ resolve_ud_negate(&op[1]);
+
inst = emit(BRW_OPCODE_CMP, temp, op[0], op[1]);
inst->conditional_mod = brw_conditional_for_comparison(ir->operation);
emit(BRW_OPCODE_AND, this->result, this->result, fs_reg(0x1));
if (intel->gen < 5)
temp.type = op[0].type;
+ resolve_ud_negate(&op[0]);
+
inst = emit(BRW_OPCODE_CMP, temp, op[0], fs_reg(0.0f));
inst->conditional_mod = BRW_CONDITIONAL_NZ;
inst = emit(BRW_OPCODE_AND, this->result, this->result, fs_reg(1));
break;
case ir_binop_min:
+ resolve_ud_negate(&op[0]);
+ resolve_ud_negate(&op[1]);
+
if (intel->gen >= 6) {
inst = emit(BRW_OPCODE_SEL, this->result, op[0], op[1]);
inst->conditional_mod = BRW_CONDITIONAL_L;
}
break;
case ir_binop_max:
+ resolve_ud_negate(&op[0]);
+ resolve_ud_negate(&op[1]);
+
if (intel->gen >= 6) {
inst = emit(BRW_OPCODE_SEL, this->result, op[0], op[1]);
inst->conditional_mod = BRW_CONDITIONAL_GE;
for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
fs_inst *inst = emit(BRW_OPCODE_MOV,
fs_reg(MRF, base_mrf + mlen + i), coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
fs_inst *inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, base_mrf + mlen + i),
coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
}
base_mrf + mlen + i * 2,
coordinate.type),
coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
}
fs_inst *inst = NULL;
switch (ir->op) {
case ir_tex:
- inst = emit(FS_OPCODE_TEX, dst);
+ inst = emit(SHADER_OPCODE_TEX, dst);
break;
case ir_txb:
inst = emit(FS_OPCODE_TXB, dst);
break;
case ir_txl:
- inst = emit(FS_OPCODE_TXL, dst);
+ inst = emit(SHADER_OPCODE_TXL, dst);
break;
case ir_txd:
- inst = emit(FS_OPCODE_TXD, dst);
+ inst = emit(SHADER_OPCODE_TXD, dst);
break;
case ir_txs:
- inst = emit(FS_OPCODE_TXS, dst);
+ inst = emit(SHADER_OPCODE_TXS, dst);
break;
case ir_txf:
- inst = emit(FS_OPCODE_TXF, dst);
+ inst = emit(SHADER_OPCODE_TXF, dst);
break;
}
inst->base_mrf = base_mrf;
fs_reg(MRF, base_mrf + mlen + i * reg_width,
coordinate.type),
coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
}
fs_inst *inst = NULL;
switch (ir->op) {
case ir_tex:
- inst = emit(FS_OPCODE_TEX, dst);
+ inst = emit(SHADER_OPCODE_TEX, dst);
break;
case ir_txb:
ir->lod_info.bias->accept(this);
emit(BRW_OPCODE_MOV, fs_reg(MRF, base_mrf + mlen), this->result);
mlen += reg_width;
- inst = emit(FS_OPCODE_TXL, dst);
+ inst = emit(SHADER_OPCODE_TXL, dst);
break;
case ir_txd: {
ir->lod_info.grad.dPdx->accept(this);
mlen += reg_width;
}
- inst = emit(FS_OPCODE_TXD, dst);
+ inst = emit(SHADER_OPCODE_TXD, dst);
break;
}
case ir_txs:
ir->lod_info.lod->accept(this);
emit(BRW_OPCODE_MOV, fs_reg(MRF, base_mrf + mlen, BRW_REGISTER_TYPE_UD), this->result);
mlen += reg_width;
- inst = emit(FS_OPCODE_TXS, dst);
+ inst = emit(SHADER_OPCODE_TXS, dst);
break;
case ir_txf:
mlen = header_present + 4 * reg_width;
emit(BRW_OPCODE_MOV,
fs_reg(MRF, base_mrf + mlen - reg_width, BRW_REGISTER_TYPE_UD),
this->result);
- inst = emit(FS_OPCODE_TXF, dst);
+ inst = emit(SHADER_OPCODE_TXF, dst);
break;
}
inst->base_mrf = base_mrf;
for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
fs_inst *inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, base_mrf + mlen),
coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
mlen += reg_width;
for (int i = 0; i < ir->coordinate->type->vector_elements; i++) {
fs_inst *inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, base_mrf + mlen),
coordinate);
- if (i < 3 && c->key.gl_clamp_mask[i] & (1 << sampler))
+ if (i < 3 && c->key.tex.gl_clamp_mask[i] & (1 << sampler))
inst->saturate = true;
coordinate.reg_offset++;
mlen += reg_width;
/* Generate the SEND */
fs_inst *inst = NULL;
switch (ir->op) {
- case ir_tex: inst = emit(FS_OPCODE_TEX, dst); break;
+ case ir_tex: inst = emit(SHADER_OPCODE_TEX, dst); break;
case ir_txb: inst = emit(FS_OPCODE_TXB, dst); break;
- case ir_txl: inst = emit(FS_OPCODE_TXL, dst); break;
- case ir_txd: inst = emit(FS_OPCODE_TXD, dst); break;
- case ir_txf: inst = emit(FS_OPCODE_TXF, dst); break;
- case ir_txs: inst = emit(FS_OPCODE_TXS, dst); break;
+ case ir_txl: inst = emit(SHADER_OPCODE_TXL, dst); break;
+ case ir_txd: inst = emit(SHADER_OPCODE_TXD, dst); break;
+ case ir_txf: inst = emit(SHADER_OPCODE_TXF, dst); break;
+ case ir_txs: inst = emit(SHADER_OPCODE_TXS, dst); break;
}
inst->base_mrf = base_mrf;
inst->mlen = mlen;
*/
bool hw_compare_supported = ir->op != ir_txd;
if (ir->shadow_comparitor && !hw_compare_supported) {
- assert(c->key.compare_funcs[sampler] != GL_NONE);
+ assert(c->key.tex.compare_funcs[sampler] != GL_NONE);
/* No need to even sample for GL_ALWAYS or GL_NEVER...bail early */
- if (c->key.compare_funcs[sampler] == GL_ALWAYS)
+ if (c->key.tex.compare_funcs[sampler] == GL_ALWAYS)
return swizzle_result(ir, fs_reg(1.0f), sampler);
- else if (c->key.compare_funcs[sampler] == GL_NEVER)
+ else if (c->key.tex.compare_funcs[sampler] == GL_NEVER)
return swizzle_result(ir, fs_reg(0.0f), sampler);
}
fs_reg coordinate = this->result;
if (ir->offset != NULL) {
- ir_constant *offset = ir->offset->as_constant();
- assert(offset != NULL);
-
- signed char offsets[3];
- for (unsigned i = 0; i < ir->offset->type->vector_elements; i++)
- offsets[i] = (signed char) offset->value.i[i];
-
- /* Combine all three offsets into a single unsigned dword:
- *
- * bits 11:8 - U Offset (X component)
- * bits 7:4 - V Offset (Y component)
- * bits 3:0 - R Offset (Z component)
- */
- unsigned offset_bits = 0;
- for (unsigned i = 0; i < ir->offset->type->vector_elements; i++) {
- const unsigned shift = 4 * (2 - i);
- offset_bits |= (offsets[i] << shift) & (0xF << shift);
- }
+ uint32_t offset_bits = brw_texture_offset(ir->offset->as_constant());
/* Explicitly set up the message header by copying g0 to msg reg m1. */
emit(BRW_OPCODE_MOV, fs_reg(MRF, 1, BRW_REGISTER_TYPE_UD),
- fs_reg(GRF, 0, BRW_REGISTER_TYPE_UD));
+ fs_reg(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)));
/* Then set the offset bits in DWord 2 of the message header. */
emit(BRW_OPCODE_MOV,
/* FINISHME: This needs to be done pre-filtering. */
uint32_t conditional = 0;
- switch (c->key.compare_funcs[sampler]) {
+ switch (c->key.tex.compare_funcs[sampler]) {
/* GL_ALWAYS and GL_NEVER were handled at the top of the function */
case GL_LESS: conditional = BRW_CONDITIONAL_L; break;
case GL_GREATER: conditional = BRW_CONDITIONAL_G; break;
{
this->result = orig_val;
+ if (ir->op == ir_txs)
+ return;
+
if (ir->type == glsl_type::float_type) {
/* Ignore DEPTH_TEXTURE_MODE swizzling. */
assert(ir->sampler->type->sampler_shadow);
- } else if (c->key.tex_swizzles[sampler] != SWIZZLE_NOOP) {
+ } else if (c->key.tex.swizzles[sampler] != SWIZZLE_NOOP) {
fs_reg swizzled_result = fs_reg(this, glsl_type::vec4_type);
for (int i = 0; i < 4; i++) {
- int swiz = GET_SWZ(c->key.tex_swizzles[sampler], i);
+ int swiz = GET_SWZ(c->key.tex.swizzles[sampler], i);
fs_reg l = swizzled_result;
l.reg_offset += i;
emit(BRW_OPCODE_MOV, l, fs_reg(1.0f));
} else {
fs_reg r = orig_val;
- r.reg_offset += GET_SWZ(c->key.tex_swizzles[sampler], i);
+ r.reg_offset += GET_SWZ(c->key.tex.swizzles[sampler], i);
emit(BRW_OPCODE_MOV, l, r);
}
}
expr->operands[i]->accept(this);
op[i] = this->result;
+
+ resolve_ud_negate(&op[i]);
}
switch (expr->operation) {
this->current_annotation = "compute pixel deltas from v0";
if (brw->has_pln) {
- this->delta_x = fs_reg(this, glsl_type::vec2_type);
- this->delta_y = this->delta_x;
- this->delta_y.reg_offset++;
+ this->delta_x[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC] =
+ fs_reg(this, glsl_type::vec2_type);
+ this->delta_y[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC] =
+ this->delta_x[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC];
+ this->delta_y[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC].reg_offset++;
} else {
- this->delta_x = fs_reg(this, glsl_type::float_type);
- this->delta_y = fs_reg(this, glsl_type::float_type);
+ this->delta_x[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC] =
+ fs_reg(this, glsl_type::float_type);
+ this->delta_y[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC] =
+ fs_reg(this, glsl_type::float_type);
}
- emit(BRW_OPCODE_ADD, this->delta_x,
+ emit(BRW_OPCODE_ADD, this->delta_x[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC],
this->pixel_x, fs_reg(negate(brw_vec1_grf(1, 0))));
- emit(BRW_OPCODE_ADD, this->delta_y,
+ emit(BRW_OPCODE_ADD, this->delta_y[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC],
this->pixel_y, fs_reg(negate(brw_vec1_grf(1, 1))));
this->current_annotation = "compute pos.w and 1/pos.w";
* interpolate the other attributes.
*/
this->wpos_w = fs_reg(this, glsl_type::float_type);
- emit(FS_OPCODE_LINTERP, wpos_w, this->delta_x, this->delta_y,
+ emit(FS_OPCODE_LINTERP, wpos_w,
+ this->delta_x[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC],
+ this->delta_y[BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC],
interp_reg(FRAG_ATTRIB_WPOS, 3));
/* Compute the pixel 1/W value from wpos.w. */
this->pixel_w = fs_reg(this, glsl_type::float_type);
this->wpos_w = fs_reg(this, glsl_type::float_type);
emit_math(SHADER_OPCODE_RCP, this->wpos_w, this->pixel_w);
- this->delta_x = fs_reg(brw_vec8_grf(2, 0));
- this->delta_y = fs_reg(brw_vec8_grf(3, 0));
+ for (int i = 0; i < BRW_WM_BARYCENTRIC_INTERP_MODE_COUNT; ++i) {
+ uint8_t reg = c->barycentric_coord_reg[i];
+ this->delta_x[i] = fs_reg(brw_vec8_grf(reg, 0));
+ this->delta_y[i] = fs_reg(brw_vec8_grf(reg + 1, 0));
+ }
this->current_annotation = NULL;
}
void
-fs_visitor::emit_color_write(int index, int first_color_mrf, fs_reg color)
+fs_visitor::emit_color_write(int target, int index, int first_color_mrf)
{
int reg_width = c->dispatch_width / 8;
fs_inst *inst;
+ fs_reg color = outputs[target];
+ fs_reg mrf;
+
+ /* If there's no color data to be written, skip it. */
+ if (color.file == BAD_FILE)
+ return;
+
+ color.reg_offset += index;
if (c->dispatch_width == 8 || intel->gen >= 6) {
/* SIMD8 write looks like:
* m + 7: a1
*/
inst = emit(BRW_OPCODE_MOV,
- fs_reg(MRF, first_color_mrf + index * reg_width),
+ fs_reg(MRF, first_color_mrf + index * reg_width, color.type),
color);
inst->saturate = c->key.clamp_fragment_color;
} else {
* destination + 4.
*/
inst = emit(BRW_OPCODE_MOV,
- fs_reg(MRF, BRW_MRF_COMPR4 + first_color_mrf + index),
+ fs_reg(MRF, BRW_MRF_COMPR4 + first_color_mrf + index,
+ color.type),
color);
inst->saturate = c->key.clamp_fragment_color;
} else {
push_force_uncompressed();
- inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, first_color_mrf + index),
+ inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, first_color_mrf + index,
+ color.type),
color);
inst->saturate = c->key.clamp_fragment_color;
pop_force_uncompressed();
push_force_sechalf();
color.sechalf = true;
- inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, first_color_mrf + index + 4),
+ inst = emit(BRW_OPCODE_MOV, fs_reg(MRF, first_color_mrf + index + 4,
+ color.type),
color);
inst->saturate = c->key.clamp_fragment_color;
pop_force_sechalf();
fs_visitor::emit_fb_writes()
{
this->current_annotation = "FB write header";
- GLboolean header_present = GL_TRUE;
+ bool header_present = true;
int base_mrf = 2;
int nr = base_mrf;
int reg_width = c->dispatch_width / 8;
nr += reg_width;
}
- fs_reg color = reg_undef;
- if (this->frag_color)
- color = *(variable_storage(this->frag_color));
- else if (this->frag_data) {
- color = *(variable_storage(this->frag_data));
- color.type = BRW_REGISTER_TYPE_F;
- }
-
for (int target = 0; target < c->key.nr_color_regions; target++) {
this->current_annotation = ralloc_asprintf(this->mem_ctx,
"FB write target %d",
target);
- if (this->frag_color || this->frag_data) {
- for (int i = 0; i < 4; i++) {
- emit_color_write(i, color_mrf, color);
- color.reg_offset++;
- }
- }
-
- if (this->frag_color)
- color.reg_offset -= 4;
+ for (int i = 0; i < 4; i++)
+ emit_color_write(target, i, color_mrf);
fs_inst *inst = emit(FS_OPCODE_FB_WRITE);
inst->target = target;
}
if (c->key.nr_color_regions == 0) {
- if (c->key.alpha_test && (this->frag_color || this->frag_data)) {
+ if (c->key.alpha_test) {
/* If the alpha test is enabled but there's no color buffer,
* we still need to send alpha out the pipeline to our null
* renderbuffer.
*/
- color.reg_offset += 3;
- emit_color_write(3, color_mrf, color);
+ emit_color_write(0, 3, color_mrf);
}
fs_inst *inst = emit(FS_OPCODE_FB_WRITE);
this->current_annotation = NULL;
}
+
+void
+fs_visitor::resolve_ud_negate(fs_reg *reg)
+{
+ if (reg->type != BRW_REGISTER_TYPE_UD ||
+ !reg->negate)
+ return;
+
+ fs_reg temp = fs_reg(this, glsl_type::uint_type);
+ emit(BRW_OPCODE_MOV, temp, *reg);
+ *reg = temp;
+}