summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mesa/program/prog_to_nir.c2
-rw-r--r--src/mesa/state_tracker/st_program.c60
2 files changed, 61 insertions, 1 deletions
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index 9d4f6d63dcc..312b299361e 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -1024,7 +1024,7 @@ prog_to_nir(const struct gl_program *prog,
c->parameters = rzalloc(s, nir_variable);
c->parameters->type =
glsl_array_type(glsl_vec4_type(), prog->Parameters->NumParameters, 0);
- c->parameters->name = "parameters";
+ c->parameters->name = strdup(prog->Parameters->Parameters[0].Name);
c->parameters->data.read_only = true;
c->parameters->data.mode = nir_var_uniform;
exec_list_push_tail(&s->uniforms, &c->parameters->node);
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 4d017d8c61d..c2daa4d2ffa 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -37,6 +37,7 @@
#include "main/mtypes.h"
#include "program/prog_parameter.h"
#include "program/prog_print.h"
+#include "program/prog_to_nir.h"
#include "program/programopt.h"
#include "compiler/nir/nir.h"
@@ -378,6 +379,37 @@ st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
}
/**
+ * Translate ARB (asm) program to NIR
+ */
+static nir_shader *
+st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
+ gl_shader_stage stage)
+{
+ enum pipe_shader_type p_stage = stage; /* valid for VS/FS */
+ const bool is_scalar =
+ st->pipe->screen->get_shader_param(st->pipe->screen, p_stage,
+ PIPE_SHADER_CAP_SCALAR_ISA);
+
+ const struct gl_shader_compiler_options *options =
+ &st->ctx->Const.ShaderCompilerOptions[stage];
+
+ /* Translate to NIR */
+ nir_shader *nir = prog_to_nir(prog, options->NirOptions);
+ NIR_PASS_V(nir, nir_lower_regs_to_ssa); /* turn registers into SSA */
+ nir_validate_shader(nir, "after st/ptn lower_regs_to_ssa");
+
+ NIR_PASS_V(nir, st_nir_lower_wpos_ytransform, prog, st->pipe->screen);
+ NIR_PASS_V(nir, nir_lower_system_values);
+
+ /* Optimise NIR */
+ NIR_PASS_V(nir, nir_opt_constant_folding);
+ st_nir_opts(nir, is_scalar);
+ nir_validate_shader(nir, "after st/ptn NIR opts");
+
+ return nir;
+}
+
+/**
* Translate a vertex program.
*/
bool
@@ -539,6 +571,19 @@ st_translate_vertex_program(struct st_context *st,
st_store_ir_in_disk_cache(st, &stvp->Base, false);
}
+ bool use_nir = PIPE_SHADER_IR_NIR ==
+ st->pipe->screen->get_shader_param(st->pipe->screen, PIPE_SHADER_VERTEX,
+ PIPE_SHADER_CAP_PREFERRED_IR);
+
+ if (use_nir) {
+ nir_shader *nir =
+ st_translate_prog_to_nir(st, &stvp->Base, MESA_SHADER_VERTEX);
+
+ stvp->tgsi.type = PIPE_SHADER_IR_NIR;
+ stvp->tgsi.ir.nir = nir;
+ return true;
+ }
+
return stvp->tgsi.tokens != NULL;
}
@@ -708,6 +753,21 @@ st_translate_fragment_program(struct st_context *st,
}
}
+
+ bool use_nir = PIPE_SHADER_IR_NIR ==
+ st->pipe->screen->get_shader_param(st->pipe->screen,
+ PIPE_SHADER_FRAGMENT,
+ PIPE_SHADER_CAP_PREFERRED_IR);
+
+ if (use_nir && !stfp->ati_fs) {
+ nir_shader *nir =
+ st_translate_prog_to_nir(st, &stfp->Base, MESA_SHADER_FRAGMENT);
+
+ stfp->tgsi.type = PIPE_SHADER_IR_NIR;
+ stfp->tgsi.ir.nir = nir;
+ return true;
+ }
+
/*
* Convert Mesa program inputs to TGSI input register semantics.
*/