foreach_s(node, t, &c->instructions) {
struct qinst *inst = (struct qinst *)node;
- if (qir_has_side_effects(inst)) {
+ if (qir_has_side_effects(c, inst)) {
if (inst->op == QOP_TLB_DISCARD_SETUP)
last_sf = NULL;
continue;
if (inst->dst.file == QFILE_TEMP &&
!used[inst->dst.index] &&
- (!qir_has_side_effects(inst) ||
+ (!qir_has_side_effects(c, inst) ||
inst->op == QOP_TEX_RESULT)) {
if (inst->op == QOP_TEX_RESULT) {
dce_tex = true;
shader->program_id = vc4->next_compiled_program_id++;
if (stage == QSTAGE_FRAG) {
+ bool input_live[c->num_input_semantics];
+ struct simple_node *node;
+
+ memset(input_live, 0, sizeof(input_live));
+ foreach(node, &c->instructions) {
+ struct qinst *inst = (struct qinst *)node;
+ for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
+ if (inst->src[i].file == QFILE_VARY)
+ input_live[inst->src[i].index] = true;
+ }
+ }
+
shader->input_semantics = ralloc_array(shader,
struct vc4_varying_semantic,
c->num_input_semantics);
for (int i = 0; i < c->num_input_semantics; i++) {
struct vc4_varying_semantic *sem = &c->input_semantics[i];
+ if (!input_live[i])
+ continue;
+
/* Skip non-VS-output inputs. */
if (sem->semantic == (uint8_t)~0)
continue;
abort();
}
+/**
+ * Returns whether the instruction has any side effects that must be
+ * preserved.
+ */
bool
-qir_has_side_effects(struct qinst *inst)
+qir_has_side_effects(struct vc4_compile *c, struct qinst *inst)
{
+ /* We can dead-code eliminate varyings, because we only tell the VS
+ * about the live ones at the end. But we have to preserve the
+ * point/line coordinates reads, because they're generated by
+ * fixed-function hardware.
+ */
for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
- if (inst->src[i].file == QFILE_VARY)
+ if (inst->src[i].file == QFILE_VARY &&
+ c->input_semantics[inst->src[i].index].semantic == 0xff) {
return true;
+ }
}
return qir_op_info[inst->op].has_side_effects;
struct qreg qir_get_temp(struct vc4_compile *c);
int qir_get_op_nsrc(enum qop qop);
bool qir_reg_equals(struct qreg a, struct qreg b);
-bool qir_has_side_effects(struct qinst *inst);
+bool qir_has_side_effects(struct vc4_compile *c, struct qinst *inst);
bool qir_depends_on_flags(struct qinst *inst);
bool qir_writes_r4(struct qinst *inst);
bool qir_reads_r4(struct qinst *inst);