return NULL;
}
+static bool is_nir_enabled(struct r600_common_screen *screen) {
+ return (screen->debug_flags & DBG_NIR &&
+ screen->family >= CHIP_CEDAR &&
+ screen->family < CHIP_CAYMAN);
+}
+
/*
* pipe_screen
*/
return rscreen->b.chip_class > R700;
case PIPE_CAP_TGSI_TEXCOORD:
- return 0;
+ return is_nir_enabled(&rscreen->b);
case PIPE_CAP_FAKE_SW_MSAA:
return 0;
return 1;
case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
- if (family >= CHIP_CEDAR)
+ if (family >= CHIP_CEDAR && !is_nir_enabled(&rscreen->b))
return 256;
return 0;
{
case PIPE_SHADER_FRAGMENT:
case PIPE_SHADER_VERTEX:
- case PIPE_SHADER_COMPUTE:
break;
case PIPE_SHADER_GEOMETRY:
if (rscreen->b.family >= CHIP_CEDAR)
if (rscreen->b.info.drm_minor >= 37)
break;
return 0;
+ /* With NIR we currently disable TES, TCS and COMP shaders */
case PIPE_SHADER_TESS_CTRL:
case PIPE_SHADER_TESS_EVAL:
- if (rscreen->b.family >= CHIP_CEDAR)
+ if (rscreen->b.family >= CHIP_CEDAR &&
+ !is_nir_enabled(&rscreen->b))
+ break;
+ case PIPE_SHADER_COMPUTE:
+ if (!is_nir_enabled(&rscreen->b))
break;
default:
return 0;
case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
if (shader == PIPE_SHADER_COMPUTE) {
uint64_t max_const_buffer_size;
- pscreen->get_compute_param(pscreen, PIPE_SHADER_IR_TGSI,
- PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
- &max_const_buffer_size);
+ enum pipe_shader_ir ir_type = is_nir_enabled(&rscreen->b) ?
+ PIPE_SHADER_IR_NIR: PIPE_SHADER_IR_TGSI;
+ pscreen->get_compute_param(pscreen, ir_type,
+ PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
+ &max_const_buffer_size);
return MIN2(max_const_buffer_size, INT_MAX);
} else {
case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
return 16;
- case PIPE_SHADER_CAP_PREFERRED_IR:
+ case PIPE_SHADER_CAP_PREFERRED_IR:
+ if (is_nir_enabled(&rscreen->b))
+ return PIPE_SHADER_IR_NIR;
return PIPE_SHADER_IR_TGSI;
case PIPE_SHADER_CAP_SUPPORTED_IRS: {
int ir = 0;
if (shader == PIPE_SHADER_COMPUTE)
ir = 1 << PIPE_SHADER_IR_NATIVE;
- if (rscreen->b.family >= CHIP_CEDAR)
+ if (rscreen->b.family >= CHIP_CEDAR) {
ir |= 1 << PIPE_SHADER_IR_TGSI;
+ if (is_nir_enabled(&rscreen->b))
+ ir |= 1 << PIPE_SHADER_IR_NIR;
+ }
return ir;
}
case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
#include "r600_formats.h"
#include "r600_opcodes.h"
#include "r600_shader.h"
+#include "r600_dump.h"
#include "r600d.h"
+#include "sfn/sfn_nir.h"
#include "sb/sb_public.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_scan.h"
#include "tgsi/tgsi_dump.h"
+#include "tgsi/tgsi_from_mesa.h"
+#include "nir/tgsi_to_nir.h"
+#include "nir/nir_to_tgsi_info.h"
+#include "compiler/nir/nir.h"
#include "util/u_bitcast.h"
#include "util/u_memory.h"
#include "util/u_math.h"
return 0;
}
+extern const struct nir_shader_compiler_options r600_nir_options;
+static int nshader = 0;
int r600_pipe_shader_create(struct pipe_context *ctx,
struct r600_pipe_shader *shader,
union r600_shader_key key)
struct r600_context *rctx = (struct r600_context *)ctx;
struct r600_pipe_shader_selector *sel = shader->selector;
int r;
- bool dump = r600_can_dump_shader(&rctx->screen->b,
- tgsi_get_processor_type(sel->tokens));
- unsigned use_sb = !(rctx->screen->b.debug_flags & DBG_NO_SB);
+ struct r600_screen *rscreen = (struct r600_screen *)ctx->screen;
+
+ int processor = sel->ir_type == PIPE_SHADER_IR_TGSI ?
+ tgsi_get_processor_type(sel->tokens):
+ pipe_shader_type_from_mesa(sel->nir->info.stage);
+
+ bool dump = r600_can_dump_shader(&rctx->screen->b, processor);
+ unsigned use_sb = !(rctx->screen->b.debug_flags & DBG_NO_SB) &&
+ !(rscreen->b.debug_flags & DBG_NIR);
unsigned sb_disasm;
unsigned export_shader;
-
+
shader->shader.bc.isa = rctx->isa;
-
+
+ if (!(rscreen->b.debug_flags & DBG_NIR)) {
+ assert(sel->ir_type == PIPE_SHADER_IR_TGSI);
+ r = r600_shader_from_tgsi(rctx, shader, key);
+ if (r) {
+ R600_ERR("translation from TGSI failed !\n");
+ goto error;
+ }
+ } else {
+ if (sel->ir_type == PIPE_SHADER_IR_TGSI)
+ sel->nir = tgsi_to_nir_noscreen(sel->tokens, &r600_nir_options);
+ nir_tgsi_scan_shader(sel->nir, &sel->info, true);
+ r = r600_shader_from_nir(rctx, shader, &key);
+ if (r) {
+ fprintf(stderr, "--Failed shader--------------------------------------------------\n");
+
+ if (sel->ir_type == PIPE_SHADER_IR_TGSI) {
+ fprintf(stderr, "--TGSI--------------------------------------------------------\n");
+ tgsi_dump(sel->tokens, 0);
+ }
+
+ if (rscreen->b.debug_flags & DBG_NIR) {
+ fprintf(stderr, "--NIR --------------------------------------------------------\n");
+ nir_print_shader(sel->nir, stderr);
+ }
+
+ R600_ERR("translation from NIR failed !\n");
+ goto error;
+ }
+ }
+
if (dump) {
- fprintf(stderr, "--------------------------------------------------------------\n");
- tgsi_dump(sel->tokens, 0);
-
+ if (sel->ir_type == PIPE_SHADER_IR_TGSI) {
+ fprintf(stderr, "--TGSI--------------------------------------------------------\n");
+ tgsi_dump(sel->tokens, 0);
+ }
+
if (sel->so.num_outputs) {
r600_dump_streamout(&sel->so);
}
}
- r = r600_shader_from_tgsi(rctx, shader, key);
- if (r) {
- R600_ERR("translation from TGSI failed !\n");
- goto error;
- }
+
if (shader->shader.processor_type == PIPE_SHADER_VERTEX) {
/* only disable for vertex shaders in tess paths */
if (key.vs.as_ls)
r600_bytecode_disasm(&shader->shader.bc);
fprintf(stderr, "______________________________________________________________\n");
} else if ((dump && sb_disasm) || use_sb) {
- r = r600_sb_bytecode_process(rctx, &shader->shader.bc, &shader->shader,
+ r = r600_sb_bytecode_process(rctx, &shader->shader.bc, &shader->shader,
dump, use_sb);
if (r) {
R600_ERR("r600_sb_bytecode_process failed !\n");
}
}
+ if (dump) {
+ FILE *f;
+ char fname[1024];
+ snprintf(fname, 1024, "shader_from_%s_%d.cpp",
+ (sel->ir_type == PIPE_SHADER_IR_TGSI ?
+ (rscreen->b.debug_flags & DBG_NIR ? "tgsi-nir" : "tgsi")
+ : "nir"), nshader);
+ f = fopen(fname, "w");
+ print_shader_info(f, nshader++, &shader->shader);
+ print_shader_info(stderr, nshader++, &shader->shader);
+ print_pipe_info(stderr, &sel->info);
+ if (sel->ir_type == PIPE_SHADER_IR_TGSI) {
+ fprintf(f, "/****TGSI**********************************\n");
+ tgsi_dump_to_file(sel->tokens, 0, f);
+ }
+
+ if (rscreen->b.debug_flags & DBG_NIR){
+ fprintf(f, "/****NIR **********************************\n");
+ nir_print_shader(sel->nir, f);
+ }
+ fprintf(f, "******************************************/\n");
+ fclose(f);
+ }
+
if (shader->gs_copy_shader) {
if (dump) {
// dump copy shader
void r600_pipe_shader_destroy(struct pipe_context *ctx UNUSED, struct r600_pipe_shader *shader)
{
r600_resource_reference(&shader->bo, NULL);
- r600_bytecode_clear(&shader->shader.bc);
+ if (shader->shader.bc.cf.next)
+ r600_bytecode_clear(&shader->shader.bc);
r600_release_command_buffer(&shader->command_buffer);
}
r600_bytecode_add_alu(ctx->bc, &alu);
}
-static int generate_gs_copy_shader(struct r600_context *rctx,
- struct r600_pipe_shader *gs,
- struct pipe_stream_output_info *so)
+int generate_gs_copy_shader(struct r600_context *rctx,
+ struct r600_pipe_shader *gs,
+ struct pipe_stream_output_info *so)
{
struct r600_shader_ctx ctx = {};
struct r600_shader *gs_shader = &gs->shader;