* IN THE SOFTWARE.
*/
+#include <stdlib.h>
+
#include "vc4_qpu.h"
static void
{ QPU_GET_FIELD(inst, QPU_MUL_B) },
};
+ /* Branches only reference raddr_a (no mux), and we don't use that
+ * feature of branching.
+ */
+ if (QPU_GET_FIELD(inst, QPU_SIG) == QPU_SIG_BRANCH)
+ return false;
+
+ /* Load immediates don't read any registers. */
+ if (QPU_GET_FIELD(inst, QPU_SIG) == QPU_SIG_LOAD_IMM)
+ return false;
+
for (int i = 0; i < ARRAY_SIZE(src_regs); i++) {
if (!ignore_a &&
src_regs[i].mux == QPU_MUX_A &&
vc4_qpu_validate(uint64_t *insts, uint32_t num_inst)
{
bool scoreboard_locked = false;
+ bool threaded = false;
/* We don't want to do validation in release builds, but we want to
* keep compiling the validation code to make sure it doesn't get
for (int i = 0; i < num_inst; i++) {
uint64_t inst = insts[i];
+ uint32_t sig = QPU_GET_FIELD(inst, QPU_SIG);
- if (QPU_GET_FIELD(inst, QPU_SIG) != QPU_SIG_PROG_END) {
+ if (sig != QPU_SIG_PROG_END) {
if (qpu_inst_is_tlb(inst))
scoreboard_locked = true;
+ if (sig == QPU_SIG_THREAD_SWITCH ||
+ sig == QPU_SIG_LAST_THREAD_SWITCH) {
+ threaded = true;
+ }
+
continue;
}
last_sfu_inst = i;
}
- int last_r5_write = -10;
for (int i = 0; i < num_inst - 1; i++) {
uint64_t inst = insts[i];
- /* "An instruction that does a vector rotate by r5 must not
- * immediately follow an instruction that writes to r5."
- */
- if (last_r5_write == i - 1 &&
- QPU_GET_FIELD(inst, QPU_SIG) == QPU_SIG_SMALL_IMM &&
- QPU_GET_FIELD(inst, QPU_SMALL_IMM) == 48) {
- fail_instr(inst,
- "vector rotate by r5 immediately "
- "after r5 write");
+ if (QPU_GET_FIELD(inst, QPU_SIG) == QPU_SIG_SMALL_IMM &&
+ QPU_GET_FIELD(inst, QPU_SMALL_IMM) >=
+ QPU_SMALL_IMM_MUL_ROT) {
+ uint32_t mux_a = QPU_GET_FIELD(inst, QPU_MUL_A);
+ uint32_t mux_b = QPU_GET_FIELD(inst, QPU_MUL_B);
+
+ /* "The full horizontal vector rotate is only
+ * available when both of the mul ALU input arguments
+ * are taken from accumulators r0-r3."
+ */
+ if (mux_a > QPU_MUX_R3 || mux_b > QPU_MUX_R3) {
+ fail_instr(inst,
+ "MUL rotate using non-accumulator "
+ "input");
+ }
+
+ if (QPU_GET_FIELD(inst, QPU_SMALL_IMM) ==
+ QPU_SMALL_IMM_MUL_ROT) {
+ /* "An instruction that does a vector rotate
+ * by r5 must not immediately follow an
+ * instruction that writes to r5."
+ */
+ if (writes_reg(insts[i - 1], QPU_W_ACC5)) {
+ fail_instr(inst,
+ "vector rotate by r5 "
+ "immediately after r5 write");
+ }
+ }
+
+ /* "An instruction that does a vector rotate must not
+ * immediately follow an instruction that writes to the
+ * accumulator that is being rotated."
+ */
+ if (writes_reg(insts[i - 1], QPU_W_ACC0 + mux_a) ||
+ writes_reg(insts[i - 1], QPU_W_ACC0 + mux_b)) {
+ fail_instr(inst,
+ "vector rotate of value "
+ "written in previous instruction");
+ }
}
}
if (qpu_num_sf_accesses(inst) > 1)
fail_instr(inst, "Single instruction writes SFU twice");
}
+
+ /* "The uniform base pointer can be written (from SIMD element 0) by
+ * the processor to reset the stream, there must be at least two
+ * nonuniform-accessing instructions following a pointer change
+ * before uniforms can be accessed once more."
+ */
+ int last_unif_pointer_update = -3;
+ for (int i = 0; i < num_inst; i++) {
+ uint64_t inst = insts[i];
+ uint32_t waddr_add = QPU_GET_FIELD(inst, QPU_WADDR_ADD);
+ uint32_t waddr_mul = QPU_GET_FIELD(inst, QPU_WADDR_MUL);
+
+ if (reads_reg(inst, QPU_R_UNIF) &&
+ i - last_unif_pointer_update <= 2) {
+ fail_instr(inst,
+ "uniform read too soon after pointer update");
+ }
+
+ if (waddr_add == QPU_W_UNIFORMS_ADDRESS ||
+ waddr_mul == QPU_W_UNIFORMS_ADDRESS)
+ last_unif_pointer_update = i;
+ }
+
+ if (threaded) {
+ bool last_thrsw_found = false;
+ bool scoreboard_locked = false;
+ int tex_samples_outstanding = 0;
+ int last_tex_samples_outstanding = 0;
+ int thrsw_ip = -1;
+
+ for (int i = 0; i < num_inst; i++) {
+ uint64_t inst = insts[i];
+ uint32_t sig = QPU_GET_FIELD(inst, QPU_SIG);
+
+ if (i == thrsw_ip) {
+ /* In order to get texture results back in the
+ * correct order, before a new thrsw we have
+ * to read all the texture results from before
+ * the previous thrsw.
+ *
+ * FIXME: Is collecting the remaining results
+ * during the delay slots OK, or should we do
+ * this at THRSW signal time?
+ */
+ if (last_tex_samples_outstanding != 0) {
+ fail_instr(inst, "THRSW with texture "
+ "results from the previous "
+ "THRSW still in the FIFO.");
+ }
+
+ last_tex_samples_outstanding =
+ tex_samples_outstanding;
+ tex_samples_outstanding = 0;
+ }
+
+ if (qpu_inst_is_tlb(inst))
+ scoreboard_locked = true;
+
+ switch (sig) {
+ case QPU_SIG_THREAD_SWITCH:
+ case QPU_SIG_LAST_THREAD_SWITCH:
+ /* No thread switching with the scoreboard
+ * locked. Doing so means we may deadlock
+ * when the other thread tries to lock
+ * scoreboard.
+ */
+ if (scoreboard_locked) {
+ fail_instr(inst, "THRSW with the "
+ "scoreboard locked.");
+ }
+
+ /* No thread switching after lthrsw, since
+ * lthrsw means that we get delayed until the
+ * other shader is ready for us to terminate.
+ */
+ if (last_thrsw_found) {
+ fail_instr(inst, "THRSW after a "
+ "previous LTHRSW");
+ }
+
+ if (sig == QPU_SIG_LAST_THREAD_SWITCH)
+ last_thrsw_found = true;
+
+ /* No THRSW while we already have a THRSW
+ * queued.
+ */
+ if (i < thrsw_ip) {
+ fail_instr(inst,
+ "THRSW with a THRSW queued.");
+ }
+
+ thrsw_ip = i + 3;
+ break;
+
+ case QPU_SIG_LOAD_TMU0:
+ case QPU_SIG_LOAD_TMU1:
+ if (last_tex_samples_outstanding == 0) {
+ fail_instr(inst, "TMU load with nothing "
+ "in the results fifo from "
+ "the previous THRSW.");
+ }
+
+ last_tex_samples_outstanding--;
+ break;
+ }
+
+ uint32_t waddr_add = QPU_GET_FIELD(inst, QPU_WADDR_ADD);
+ uint32_t waddr_mul = QPU_GET_FIELD(inst, QPU_WADDR_MUL);
+ if (waddr_add == QPU_W_TMU0_S ||
+ waddr_add == QPU_W_TMU1_S ||
+ waddr_mul == QPU_W_TMU0_S ||
+ waddr_mul == QPU_W_TMU1_S) {
+ tex_samples_outstanding++;
+ }
+ }
+ }
}