draw: add nir info gathering and building support
authorDave Airlie <airlied@redhat.com>
Thu, 5 Sep 2019 05:47:19 +0000 (15:47 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 28 Nov 2019 04:48:56 +0000 (14:48 +1000)
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/draw/draw_fs.c
src/gallium/auxiliary/draw/draw_gs.c
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_vs_exec.c
src/gallium/auxiliary/draw/draw_vs_llvm.c

index 1543bd86f170252c086baac7a92e3ab9c4e1d12b..e3bd25193dca842fb2e3a2e30fc51fa748720c59 100644 (file)
@@ -32,6 +32,7 @@
 #include "util/u_prim.h"
 
 #include "tgsi/tgsi_parse.h"
+#include "nir/nir_to_tgsi_info.h"
 
 #include "draw_fs.h"
 #include "draw_private.h"
@@ -47,7 +48,10 @@ draw_create_fragment_shader(struct draw_context *draw,
    dfs = CALLOC_STRUCT(draw_fragment_shader);
    if (dfs) {
       dfs->base = *shader;
-      tgsi_scan_shader(shader->tokens, &dfs->info);
+      if (shader->type == PIPE_SHADER_IR_TGSI)
+         tgsi_scan_shader(shader->tokens, &dfs->info);
+      else
+         nir_tgsi_scan_shader(shader->ir.nir, &dfs->info, false);
    }
 
    return dfs;
index 94cfe860b6d7efa7b4621f55fac6a74496fb6990..1e5d3a86ea01acd02823492a551f73e1cca219f9 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_exec.h"
-
+#include "nir/nir_to_tgsi_info.h"
 #include "pipe/p_shader_tokens.h"
 
 #include "util/u_math.h"
@@ -793,13 +793,17 @@ draw_create_geometry_shader(struct draw_context *draw,
 
    gs->draw = draw;
    gs->state = *state;
-   gs->state.tokens = tgsi_dup_tokens(state->tokens);
-   if (!gs->state.tokens) {
-      FREE(gs);
-      return NULL;
-   }
 
-   tgsi_scan_shader(state->tokens, &gs->info);
+   if (state->type == PIPE_SHADER_IR_TGSI) {
+      gs->state.tokens = tgsi_dup_tokens(state->tokens);
+      if (!gs->state.tokens) {
+         FREE(gs);
+         return NULL;
+      }
+
+      tgsi_scan_shader(state->tokens, &gs->info);
+   } else
+      nir_tgsi_scan_shader(state->ir.nir, &gs->info, false);
 
    /* setup the defaults */
    gs->max_out_prims = 0;
index 7c4d49e760e26c249821d6f41f54572f8aad7f10..ac3eaf11b2787342ec0cdc0db242745d4a6c50e3 100644 (file)
@@ -43,6 +43,7 @@
 #include "gallivm/lp_bld_flow.h"
 #include "gallivm/lp_bld_debug.h"
 #include "gallivm/lp_bld_tgsi.h"
+#include "gallivm/lp_bld_nir.h"
 #include "gallivm/lp_bld_printf.h"
 #include "gallivm/lp_bld_intr.h"
 #include "gallivm/lp_bld_init.h"
@@ -646,7 +647,10 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
    memcpy(&variant->key, key, shader->variant_key_size);
 
    if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) {
-      tgsi_dump(llvm->draw->vs.vertex_shader->state.tokens, 0);
+      if (llvm->draw->vs.vertex_shader->state.type == PIPE_SHADER_IR_TGSI)
+         tgsi_dump(llvm->draw->vs.vertex_shader->state.tokens, 0);
+      else
+         nir_print_shader(llvm->draw->vs.vertex_shader->state.ir.nir, stderr);
       draw_llvm_dump_variant_key(&variant->key);
    }
 
@@ -712,10 +716,17 @@ generate_vs(struct draw_llvm_variant *variant,
    params.ssbo_sizes_ptr = num_ssbos_ptr;
    params.image = draw_image;
 
-   lp_build_tgsi_soa(variant->gallivm,
-                     tokens,
-                     &params,
-                     outputs);
+   if (llvm->draw->vs.vertex_shader->state.ir.nir &&
+       llvm->draw->vs.vertex_shader->state.type == PIPE_SHADER_IR_NIR)
+      lp_build_nir_soa(variant->gallivm,
+                       llvm->draw->vs.vertex_shader->state.ir.nir,
+                       &params,
+                       outputs);
+   else
+      lp_build_tgsi_soa(variant->gallivm,
+                        tokens,
+                        &params,
+                        outputs);
 
    {
       LLVMValueRef out;
@@ -2495,7 +2506,10 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
    }
 
    if (gallivm_debug & (GALLIVM_DEBUG_TGSI | GALLIVM_DEBUG_IR)) {
-      tgsi_dump(tokens, 0);
+      if (llvm->draw->gs.geometry_shader->state.type == PIPE_SHADER_IR_TGSI)
+         tgsi_dump(tokens, 0);
+      else
+         nir_print_shader(llvm->draw->gs.geometry_shader->state.ir.nir, stderr);
       draw_gs_llvm_dump_variant_key(&variant->key);
    }
 
@@ -2515,10 +2529,16 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
    params.ssbo_sizes_ptr = num_ssbos_ptr;
    params.image = image;
 
-   lp_build_tgsi_soa(variant->gallivm,
-                     tokens,
-                     &params,
-                     outputs);
+   if (llvm->draw->gs.geometry_shader->state.type == PIPE_SHADER_IR_TGSI)
+      lp_build_tgsi_soa(variant->gallivm,
+                        tokens,
+                        &params,
+                        outputs);
+   else
+      lp_build_nir_soa(variant->gallivm,
+                       llvm->draw->gs.geometry_shader->state.ir.nir,
+                       &params,
+                       outputs);
 
    sampler->destroy(sampler);
    image->destroy(image);
index 20aada25fa088a11af4e9d43a5a4ff535ddf3e77..29b18d671ff36f9cfbbd05af04324723ecdfb5de 100644 (file)
@@ -230,6 +230,7 @@ draw_create_vs_exec(struct draw_context *draw,
 
    tgsi_scan_shader(state->tokens, &vs->base.info);
 
+   vs->base.state.type = state->type;
    vs->base.state.stream_output = state->stream_output;
    vs->base.draw = draw;
    vs->base.prepare = vs_exec_prepare;
index 04484ff13b821344046ead966a493b1819478f9a..c8ebe04efe18ee4cfac8800d482e2d9f7adfdb7a 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_scan.h"
-
+#include "nir/nir_to_tgsi_info.h"
 static void
 vs_llvm_prepare(struct draw_vertex_shader *shader,
                 struct draw_context *draw)
@@ -90,15 +90,21 @@ draw_create_vs_llvm(struct draw_context *draw,
    if (!vs)
       return NULL;
 
-   /* we make a private copy of the tokens */
-   vs->base.state.tokens = tgsi_dup_tokens(state->tokens);
-   if (!vs->base.state.tokens) {
-      FREE(vs);
-      return NULL;
+   /* due to some bugs in the feedback state tracker we have to check
+      for ir.nir & PIPE_SHADER_IR_NIR here. */
+   if (state->ir.nir && state->type == PIPE_SHADER_IR_NIR)
+      nir_tgsi_scan_shader(state->ir.nir, &vs->base.info, false);
+   else {
+      /* we make a private copy of the tokens */
+      vs->base.state.tokens = tgsi_dup_tokens(state->tokens);
+      if (!vs->base.state.tokens) {
+         FREE(vs);
+         return NULL;
+      }
+
+      tgsi_scan_shader(state->tokens, &vs->base.info);
    }
 
-   tgsi_scan_shader(state->tokens, &vs->base.info);
-
    vs->variant_key_size = 
       draw_llvm_variant_key_size(
          vs->base.info.file_max[TGSI_FILE_INPUT]+1,
@@ -106,6 +112,8 @@ draw_create_vs_llvm(struct draw_context *draw,
               vs->base.info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
          vs->base.info.file_max[TGSI_FILE_IMAGE]+1);
 
+   vs->base.state.type = state->type;
+   vs->base.state.ir.nir = state->ir.nir;
    vs->base.state.stream_output = state->stream_output;
    vs->base.draw = draw;
    vs->base.prepare = vs_llvm_prepare;