radeonsi/nir: add an option to convert TGSI to NIR
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Jul 2019 21:36:09 +0000 (17:36 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 31 Jul 2019 02:06:23 +0000 (22:06 -0400)
Use at your own risk.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_debug_options.h
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_state_shaders.c

index 12cbe194f63a40dcb205e554c9dcee4e5cda948f..4d701e1b81fc63d433e248bc1000f230bbeae832 100644 (file)
@@ -23,6 +23,7 @@
  *
  */
 
+#include "nir/tgsi_to_nir.h"
 #include "tgsi/tgsi_parse.h"
 #include "util/u_async_debug.h"
 #include "util/u_memory.h"
@@ -231,7 +232,11 @@ static void *si_create_compute_state(
        program->input_size = cso->req_input_mem;
 
        if (cso->ir_type != PIPE_SHADER_IR_NATIVE) {
-               if (cso->ir_type == PIPE_SHADER_IR_TGSI) {
+               if (sscreen->options.always_nir &&
+                   cso->ir_type == PIPE_SHADER_IR_TGSI) {
+                       program->ir_type = PIPE_SHADER_IR_NIR;
+                       sel->nir = tgsi_to_nir(cso->prog, ctx->screen);
+               } else if (cso->ir_type == PIPE_SHADER_IR_TGSI) {
                        sel->tokens = tgsi_dup_tokens(cso->prog);
                        if (!sel->tokens) {
                                FREE(program);
index d6cb315763250328e332e739957fe0fdf29d9a05..087e2984d02c71bde52207c5e17de8bacf603916 100644 (file)
@@ -1,5 +1,6 @@
 OPT_BOOL(clear_db_cache_before_clear, false, "Clear DB cache before fast depth clear")
 OPT_BOOL(enable_nir, false, "Enable NIR")
+OPT_BOOL(always_nir, false, "Enable NIR and always convert TGSI to NIR")
 OPT_BOOL(aux_debug, false, "Generate ddebug_dumps for the auxiliary context")
 OPT_BOOL(sync_compile, false, "Always compile synchronously (will cause stalls)")
 OPT_BOOL(dump_shader_binary, false, "Dump shader binary as part of ddebug_dumps")
index 3bf3284671d3fcf0a327bf2ae1eb6cb4d7705d66..5a7c9a0d4a7ed7bdf43e12882a6249ae7e0c7d58 100644 (file)
@@ -1131,6 +1131,9 @@ radeonsi_screen_create_impl(struct radeon_winsys *ws,
 #include "si_debug_options.h"
        }
 
+       if (sscreen->options.always_nir)
+               sscreen->options.enable_nir = true;
+
        sscreen->has_gfx9_scissor_bug = sscreen->info.family == CHIP_VEGA10 ||
                                        sscreen->info.family == CHIP_RAVEN;
        sscreen->has_msaa_sample_loc_bug = (sscreen->info.family >= CHIP_POLARIS10 &&
index 325eae19bed2cad7048d74df11612eaf8edca625..9e8e1db7a5297c7cee5355dfb0aa048e11e6e00c 100644 (file)
@@ -26,6 +26,7 @@
 #include "sid.h"
 
 #include "compiler/nir/nir_serialize.h"
+#include "nir/tgsi_to_nir.h"
 #include "tgsi/tgsi_parse.h"
 #include "util/hash_table.h"
 #include "util/crc32.h"
@@ -2626,7 +2627,8 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
 
        sel->so = state->stream_output;
 
-       if (state->type == PIPE_SHADER_IR_TGSI) {
+       if (state->type == PIPE_SHADER_IR_TGSI &&
+           !sscreen->options.always_nir) {
                sel->tokens = tgsi_dup_tokens(state->tokens);
                if (!sel->tokens) {
                        FREE(sel);
@@ -2636,9 +2638,12 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                tgsi_scan_shader(state->tokens, &sel->info);
                tgsi_scan_tess_ctrl(state->tokens, &sel->info, &sel->tcs_info);
        } else {
-               assert(state->type == PIPE_SHADER_IR_NIR);
-
-               sel->nir = state->ir.nir;
+               if (state->type == PIPE_SHADER_IR_TGSI) {
+                       sel->nir = tgsi_to_nir(state->tokens, ctx->screen);
+               } else {
+                       assert(state->type == PIPE_SHADER_IR_NIR);
+                       sel->nir = state->ir.nir;
+               }
 
                si_nir_opts(sel->nir);
                si_nir_scan_shader(sel->nir, &sel->info);