Commit 4798bfc4 authored by Icecream95's avatar Icecream95
Browse files

shader replacement

parent 9b122c30
Pipeline #303268 waiting for manual action with stages
......@@ -36,6 +36,7 @@
#define BIFROST_DBG_VERBOSE 0x0008
#define BIFROST_DBG_INTERNAL 0x0010
#define BIFROST_DBG_NOSCHED 0x0020
#define BIFROST_DBG_REPLACE 0x0040
extern int bifrost_debug;
......
......@@ -28,7 +28,9 @@
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir_types.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_serialize.h"
#include "util/u_debug.h"
#include "util/mesa-sha1.h"
#include "disassemble.h"
#include "bifrost_compile.h"
......@@ -37,6 +39,8 @@
#include "bi_quirks.h"
#include "bi_builder.h"
void bi_parse(bi_builder *b, FILE *f);
static const struct debug_named_value bifrost_debug_options[] = {
{"msgs", BIFROST_DBG_MSGS, "Print debug messages"},
{"shaders", BIFROST_DBG_SHADERS, "Dump shaders in NIR and MIR"},
......@@ -44,6 +48,7 @@ static const struct debug_named_value bifrost_debug_options[] = {
{"verbose", BIFROST_DBG_VERBOSE, "Disassemble verbosely"},
{"internal", BIFROST_DBG_INTERNAL, "Dump even internal shaders"},
{"nosched", BIFROST_DBG_NOSCHED, "Force trivial scheduling"},
{"replace", BIFROST_DBG_REPLACE, "Replace shaders with assembly"},
DEBUG_NAMED_VALUE_END
};
......@@ -3059,6 +3064,31 @@ bifrost_compile_shader_nir(nir_shader *nir,
info->tls_size = nir->scratch_size;
FILE *rep = NULL;
if (bifrost_debug & BIFROST_DBG_REPLACE) {
unsigned char sha1[21];
char sha1buf[45];
struct blob blob;
blob_init(&blob);
nir_serialize(&blob, nir, true);
_mesa_sha1_compute(blob.data, blob.size, sha1);
_mesa_sha1_format(sha1buf, sha1);
// TODO: Support disassembling to files as well
strcpy(sha1buf + 40, ".asm");
printf("%s - %s: %s\n", ctx->nir->info.label ?: "",
ctx->inputs->is_blend ? "PAN_SHADER_BLEND" :
gl_shader_stage_name(ctx->stage),
sha1buf);
rep = fopen(sha1buf, "r");
}
nir_foreach_function(func, nir) {
if (!func->impl)
continue;
......@@ -3092,11 +3122,34 @@ bifrost_compile_shader_nir(nir_shader *nir,
bi_lower_swizzle(ctx);
if (rep) {
// TODO: Free old instrs
list_inithead(&ctx->blocks);
bi_block *blk = rzalloc(ctx, bi_block);
blk->base.predecessors = _mesa_set_create(blk,
_mesa_hash_pointer,
_mesa_key_pointer_equal);
list_addtail(&blk->base.link, &ctx->blocks);
list_inithead(&blk->base.instructions);
bi_builder _b = {0};
bi_builder *b = &_b;
b->shader = ctx;
b->cursor = bi_after_block(blk);
printf("Replacing shader\n");
bi_parse(b, rep);
}
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)
bi_print_shader(ctx, stdout);
bi_schedule(ctx);
bi_assign_scoreboard(ctx);
bi_register_allocate(ctx);
if (!rep)
bi_register_allocate(ctx);
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)
bi_print_shader(ctx, stdout);
......
......@@ -170,10 +170,15 @@ for group_num, group in enumerate(ops_grouped):
dst_reg = n_add("dst_reg")
code.append(f"instr->dest[0] = {dst_reg};")
# TODO: Maybe this is wrong?
src_offset = bool(ins["staging"] in ["r", "rw"])
for src in range(num_srcs):
reg = n_add("src_reg", True)
# TODO: Remove all the f-strings for old Python versions
code.append(f"instr->src[{src}] = {reg};")
if src_offset:
code.append(f'printf("Setting src {src} to %i\\n", {reg}.value);')
code.append(f"instr->src[{src + src_offset}] = {reg};")
# TODO: Fix source modifiers
for i in srcs[src]:
......@@ -187,7 +192,8 @@ for group_num, group in enumerate(ops_grouped):
# TODO: Is this correct?
# TODO: sr_count can get lost, is this a problem?
st = n_add("staging_reg", True)
code.append(f"instr->dest[0] = {st};")
snum = 0 if src_offset else num_srcs
code.append(f"instr->src[{snum}] = {st};")
ins_rule.append((" ".join(name), " ".join(code)))
......@@ -264,7 +270,7 @@ imm_index:
instr_s:
{ instr = rzalloc(builder->shader, bi_instr); }
instr { bi_builder_insert(&builder->cursor, instr); }
instr { if (instr->op != BI_OPCODE_NOP_I32) bi_builder_insert(&builder->cursor, instr); }
;
// Just hack the scheduler to keep instructions in the same places?
......
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