GitLab will be down for maintenance this Sunday 13th June, from approx 7-11am UTC. This is for a PostgreSQL migration. See the tracker issue for more informations.

Commit 79552431 authored by Icecream95's avatar Icecream95
Browse files

schedule stuff

parent 4798bfc4
Pipeline #306857 waiting for manual action with stages
......@@ -879,7 +879,7 @@ static bi_instr *
bi_take_instr(bi_context *ctx, struct bi_worklist st,
struct bi_clause_state *clause,
struct bi_tuple_state *tuple,
bool fma)
bool fma, struct util_dynarray *override)
{
#ifndef NDEBUG
/* Don't pair instructions if debugging */
......@@ -887,6 +887,40 @@ bi_take_instr(bi_context *ctx, struct bi_worklist st,
return NULL;
#endif
if (override) {
if (!util_dynarray_num_elements(override, int))
return NULL;
printf("top: %i ", util_dynarray_top(override, int));
if (!((util_dynarray_top(override, int))--)) {
if (!fma) ++util_dynarray_top(override, int);
else util_dynarray_pop(override, int);
printf("end clause fma %i\n", (int)fma);
return NULL;
}
// All this worklist tracking seems like a waste of time if it
// isn't used
unsigned idx = BITSET_LAST_BIT_SIZED(st.worklist, DIV_ROUND_UP(st.count, BITSET_WORDBITS)) - 1;
if (idx == ~0) {
printf("Shouldn't happen\n");
return NULL;
}
/* Update state to reflect taking the instruction */
bi_instr *instr = st.instructions[idx];
printf("sched: ");
bi_print_instr(instr, stdout);
BITSET_CLEAR(st.worklist, idx);
bi_update_worklist(st, idx);
bi_pop_instr(clause, tuple, instr, fma);
return instr;
}
// TODO: What should we do with this stuff when assembling?
if (tuple->add && tuple->add->op == BI_OPCODE_CUBEFACE)
return bi_lower_cubeface(ctx, clause, tuple);
else if (tuple->add && tuple->add->op == BI_OPCODE_PATOM_C_I32)
......@@ -1273,7 +1307,8 @@ bi_apply_constant_modifiers(struct bi_const_state *consts,
/* Schedule a single clause. If no instructions remain, return NULL. */
static bi_clause *
bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st)
bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st,
struct util_dynarray *override)
{
struct bi_clause_state clause_state = { 0 };
bi_clause *clause = rzalloc(ctx, bi_clause);
......@@ -1289,7 +1324,9 @@ bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st)
bi_index prev_reads[5] = { bi_null() };
unsigned nr_prev_reads = 0;
printf("clause:\n");
do {
printf("tuple:\n");
struct bi_tuple_state tuple_state = {
.last = (clause->tuple_count == 0),
.reg = reg_state,
......@@ -1306,8 +1343,8 @@ bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st)
tuple = &clause->tuples[idx];
/* Since we schedule backwards, we schedule ADD first */
tuple_state.add = bi_take_instr(ctx, st, &clause_state, &tuple_state, false);
tuple->fma = bi_take_instr(ctx, st, &clause_state, &tuple_state, true);
tuple_state.add = bi_take_instr(ctx, st, &clause_state, &tuple_state, false, override);
tuple->fma = bi_take_instr(ctx, st, &clause_state, &tuple_state, true, override);
tuple->add = tuple_state.add;
/* We may have a message, but only one per clause */
......@@ -1394,6 +1431,9 @@ bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st)
if (!clause->tuple_count)
return NULL;
if (override && clause->tuple_count == 8)
util_dynarray_pop(override, int);
/* Before merging, rewrite away any tuples that read only zero */
for (unsigned i = max_tuples - clause->tuple_count; i < max_tuples; ++i) {
bi_tuple *tuple = &clause->tuples[i];
......@@ -1473,7 +1513,7 @@ bi_schedule_clause(bi_context *ctx, bi_block *block, struct bi_worklist st)
}
static void
bi_schedule_block(bi_context *ctx, bi_block *block)
bi_schedule_block(bi_context *ctx, bi_block *block, struct util_dynarray *override)
{
list_inithead(&block->clauses);
......@@ -1487,7 +1527,7 @@ bi_schedule_block(bi_context *ctx, bi_block *block)
/* Schedule as many clauses as needed to fill the block */
bi_clause *u = NULL;
while((u = bi_schedule_clause(ctx, block, st)))
while((u = bi_schedule_clause(ctx, block, st, override)))
list_add(&u->link, &block->clauses);
/* Back-to-back bit affects only the last clause of a block,
......@@ -1589,12 +1629,12 @@ bi_lower_fau(bi_context *ctx, bi_block *block)
}
void
bi_schedule(bi_context *ctx)
bi_schedule(bi_context *ctx, struct util_dynarray *override)
{
bi_foreach_block(ctx, block) {
bi_block *bblock = (bi_block *) block;
bi_lower_fau(ctx, bblock);
bi_schedule_block(ctx, bblock);
bi_schedule_block(ctx, bblock, override);
}
bi_opt_dead_code_eliminate(ctx, true);
......
......@@ -36,7 +36,9 @@
#define BIFROST_DBG_VERBOSE 0x0008
#define BIFROST_DBG_INTERNAL 0x0010
#define BIFROST_DBG_NOSCHED 0x0020
#define BIFROST_DBG_REPLACE 0x0040
#define BIFROST_DBG_SHADERS_FS 0x0040
#define BIFROST_DBG_SHADERS_VS 0x0080
#define BIFROST_DBG_REPLACE 0x0100
extern int bifrost_debug;
......
......@@ -39,7 +39,8 @@
#include "bi_quirks.h"
#include "bi_builder.h"
void bi_parse(bi_builder *b, FILE *f);
// TODO: Use a header file
void bi_parse(bi_builder *b, struct util_dynarray *sizes, FILE *f);
static const struct debug_named_value bifrost_debug_options[] = {
{"msgs", BIFROST_DBG_MSGS, "Print debug messages"},
......@@ -49,6 +50,8 @@ static const struct debug_named_value bifrost_debug_options[] = {
{"internal", BIFROST_DBG_INTERNAL, "Dump even internal shaders"},
{"nosched", BIFROST_DBG_NOSCHED, "Force trivial scheduling"},
{"replace", BIFROST_DBG_REPLACE, "Replace shaders with assembly"},
{"fs", BIFROST_DBG_SHADERS_FS, "Dump fragment shaders"},
{"vs", BIFROST_DBG_SHADERS_VS, "Dump vertex shaders"},
DEBUG_NAMED_VALUE_END
};
......@@ -3058,7 +3061,13 @@ bifrost_compile_shader_nir(nir_shader *nir,
bool skip_internal = nir->info.internal;
skip_internal &= !(bifrost_debug & BIFROST_DBG_INTERNAL);
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) {
bool disassemble = (bifrost_debug & BIFROST_DBG_SHADERS) ||
(ctx->stage == MESA_SHADER_VERTEX &&
(bifrost_debug & BIFROST_DBG_SHADERS_VS)) ||
(ctx->stage == MESA_SHADER_FRAGMENT &&
(bifrost_debug & BIFROST_DBG_SHADERS_FS));
if (disassemble && !skip_internal) {
nir_print_shader(nir, stdout);
}
......@@ -3122,6 +3131,8 @@ bifrost_compile_shader_nir(nir_shader *nir,
bi_lower_swizzle(ctx);
struct util_dynarray sched_override = {0};
if (rep) {
// TODO: Free old instrs
list_inithead(&ctx->blocks);
......@@ -3141,16 +3152,17 @@ bifrost_compile_shader_nir(nir_shader *nir,
b->cursor = bi_after_block(blk);
printf("Replacing shader\n");
bi_parse(b, rep);
bi_parse(b, &sched_override, rep);
}
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)
if (disassemble && !skip_internal)
bi_print_shader(ctx, stdout);
bi_schedule(ctx);
bi_schedule(ctx, rep ? &sched_override : NULL);
bi_assign_scoreboard(ctx);
// TODO: Do RA for assembled shaders
if (!rep)
bi_register_allocate(ctx);
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)
if (disassemble && !skip_internal)
bi_print_shader(ctx, stdout);
unsigned final_clause = bi_pack(ctx, binary);
......@@ -3164,7 +3176,7 @@ bifrost_compile_shader_nir(nir_shader *nir,
info->bifrost.wait_6 = (first_deps & (1 << 6));
info->bifrost.wait_7 = (first_deps & (1 << 7));
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) {
if (disassemble && !skip_internal) {
disassemble_bifrost(stdout, binary->data, binary->size,
bifrost_debug & BIFROST_DBG_VERBOSE);
fflush(stdout);
......
......@@ -145,7 +145,7 @@ bit_builder(void *memctx)
return b;
}
void bi_parse(bi_builder *b, FILE *f);
void bi_parse(bi_builder *b, struct util_dynarray *clause_sizes, FILE *f);
static void
assemble(const char *filename)
......@@ -153,8 +153,10 @@ assemble(const char *filename)
FILE *fp = fopen(filename, "rb");
assert(fp);
struct util_dynarray dyn = {0};
bi_builder *b = bit_builder(NULL);
bi_parse(b, fp);
bi_parse(b, &dyn, fp);
bi_print_shader(b->shader, stdout);
}
......
......@@ -754,7 +754,7 @@ void bi_opt_copy_prop(bi_context *ctx);
void bi_opt_dead_code_eliminate(bi_context *ctx, bool soft);
void bi_opt_push_ubo(bi_context *ctx);
void bi_lower_swizzle(bi_context *ctx);
void bi_schedule(bi_context *ctx);
void bi_schedule(bi_context *ctx, struct util_dynarray *override);
void bi_assign_scoreboard(bi_context *ctx);
void bi_register_allocate(bi_context *ctx);
......
......@@ -270,7 +270,7 @@ imm_index:
instr_s:
{ instr = rzalloc(builder->shader, bi_instr); }
instr { if (instr->op != BI_OPCODE_NOP_I32) bi_builder_insert(&builder->cursor, instr); }
instr { bi_builder_insert(&builder->cursor, instr); ++clause_size; }
;
// Just hack the scheduler to keep instructions in the same places?
......@@ -422,7 +422,10 @@ clause_header:
;
clause:
T_CLAUSE clause_header '{' tuples '}'
T_CLAUSE clause_header '{' tuples '}' {
util_dynarray_append(clause_sizes, int, clause_size);
clause_size = 0;
}
;
"""
......@@ -454,6 +457,9 @@ pre = COPYRIGHT + """
bi_builder *builder;
bi_instr *instr;
int clause_size;
struct util_dynarray *clause_sizes;
int yydebug;
bool isFMA;
......@@ -474,7 +480,7 @@ void bi_yyset_lineno(int line);
int yyparse(void);
/* rename function? */
void bi_parse(bi_builder *b, FILE *f)
void bi_parse(bi_builder *b, struct util_dynarray *sizes, FILE *f)
{
bi_yyset_lineno(1);
bi_yyset_input(f);
......@@ -482,7 +488,14 @@ void bi_parse(bi_builder *b, FILE *f)
yydebug = 1;
//#endif
builder = b;
clause_size = 0;
clause_sizes = sizes;
yyparse();
printf("clauses:\\n");
util_dynarray_foreach(clause_sizes, int, elem) {
printf("%i\\n", *elem);
}
printf("/clauses\\n");
// info = k;
// variant = v;
// if (yyparse() || !resolve_labels()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment