[Mesa-dev] [PATCH 1/2] nir: Store gl_shader_stage in nir_shader.
Jason Ekstrand
jason at jlekstrand.net
Tue Aug 25 10:58:57 PDT 2015
The non-TGSI bits and the patch that follows are
Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>
On Fri, Aug 21, 2015 at 7:52 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> This makes it easy for NIR passes to inspect what kind of shader they're
> operating on.
>
> Thanks to Michel Dänzer for helping me figure out where TGSI stores the
> shader stage information.
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
> src/gallium/auxiliary/nir/tgsi_to_nir.c | 25 +++++++++++++++++++++----
> src/glsl/nir/glsl_to_nir.cpp | 2 +-
> src/glsl/nir/nir.c | 6 +++++-
> src/glsl/nir/nir.h | 4 ++++
> src/mesa/program/prog_to_nir.c | 4 +++-
> 5 files changed, 34 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c
> index 93dfb80..199680d 100644
> --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
> +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
> @@ -1764,6 +1764,21 @@ ttn_add_output_stores(struct ttn_compile *c)
> }
> }
>
> +static gl_shader_stage
> +tgsi_processor_to_shader_stage(unsigned processor)
> +{
> + switch (processor) {
> + case TGSI_PROCESSOR_FRAGMENT: return MESA_SHADER_FRAGMENT;
> + case TGSI_PROCESSOR_VERTEX: return MESA_SHADER_VERTEX;
> + case TGSI_PROCESSOR_GEOMETRY: return MESA_SHADER_GEOMETRY;
> + case TGSI_PROCESSOR_TESS_CTRL: return MESA_SHADER_TESS_CTRL;
> + case TGSI_PROCESSOR_TESS_EVAL: return MESA_SHADER_TESS_EVAL;
> + case TGSI_PROCESSOR_COMPUTE: return MESA_SHADER_COMPUTE;
> + default:
> + unreachable("invalid TGSI processor");
> + };
> +}
> +
> struct nir_shader *
> tgsi_to_nir(const void *tgsi_tokens,
> const nir_shader_compiler_options *options)
> @@ -1775,7 +1790,12 @@ tgsi_to_nir(const void *tgsi_tokens,
> int ret;
>
> c = rzalloc(NULL, struct ttn_compile);
> - s = nir_shader_create(NULL, options);
> +
> + tgsi_scan_shader(tgsi_tokens, &scan);
> + c->scan = &scan;
> +
> + s = nir_shader_create(NULL, tgsi_processor_to_shader_stage(scan.processor),
> + options);
>
> nir_function *func = nir_function_create(s, "main");
> nir_function_overload *overload = nir_function_overload_create(func);
> @@ -1784,9 +1804,6 @@ tgsi_to_nir(const void *tgsi_tokens,
> nir_builder_init(&c->build, impl);
> nir_builder_insert_after_cf_list(&c->build, &impl->body);
>
> - tgsi_scan_shader(tgsi_tokens, &scan);
> - c->scan = &scan;
> -
> s->num_inputs = scan.file_max[TGSI_FILE_INPUT] + 1;
> s->num_uniforms = scan.const_file_max[0] + 1;
> s->num_outputs = scan.file_max[TGSI_FILE_OUTPUT] + 1;
> diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
> index 913f2f4..f3798dd 100644
> --- a/src/glsl/nir/glsl_to_nir.cpp
> +++ b/src/glsl/nir/glsl_to_nir.cpp
> @@ -131,7 +131,7 @@ private:
> nir_shader *
> glsl_to_nir(struct gl_shader *sh, const nir_shader_compiler_options *options)
> {
> - nir_shader *shader = nir_shader_create(NULL, options);
> + nir_shader *shader = nir_shader_create(NULL, sh->Stage, options);
>
> nir_visitor v1(shader, sh->Stage);
> nir_function_visitor v2(&v1);
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
> index 2f7cbae..1dc7cdd 100644
> --- a/src/glsl/nir/nir.c
> +++ b/src/glsl/nir/nir.c
> @@ -29,7 +29,9 @@
> #include <assert.h>
>
> nir_shader *
> -nir_shader_create(void *mem_ctx, const nir_shader_compiler_options *options)
> +nir_shader_create(void *mem_ctx,
> + gl_shader_stage stage,
> + const nir_shader_compiler_options *options)
> {
> nir_shader *shader = ralloc(mem_ctx, nir_shader);
>
> @@ -49,6 +51,8 @@ nir_shader_create(void *mem_ctx, const nir_shader_compiler_options *options)
> shader->num_outputs = 0;
> shader->num_uniforms = 0;
>
> + shader->stage = stage;
> +
> return shader;
> }
>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index 222a219..31a1ab8 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -1469,6 +1469,9 @@ typedef struct nir_shader {
>
> /** the number of uniforms that are only accessed directly */
> unsigned num_direct_uniforms;
> +
> + /** The shader stage, such as MESA_SHADER_VERTEX. */
> + gl_shader_stage stage;
> } nir_shader;
>
> #define nir_foreach_overload(shader, overload) \
> @@ -1477,6 +1480,7 @@ typedef struct nir_shader {
> &(func)->overload_list)
>
> nir_shader *nir_shader_create(void *mem_ctx,
> + gl_shader_stage stage,
> const nir_shader_compiler_options *options);
>
> /** creates a register, including assigning it an index and adding it to the list */
> diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
> index d54f934..e088578 100644
> --- a/src/mesa/program/prog_to_nir.c
> +++ b/src/mesa/program/prog_to_nir.c
> @@ -33,6 +33,7 @@
> #include "prog_instruction.h"
> #include "prog_parameter.h"
> #include "prog_print.h"
> +#include "program.h"
>
> /**
> * \file prog_to_nir.c
> @@ -1079,11 +1080,12 @@ prog_to_nir(const struct gl_program *prog,
> {
> struct ptn_compile *c;
> struct nir_shader *s;
> + gl_shader_stage stage = _mesa_program_enum_to_shader_stage(prog->Target);
>
> c = rzalloc(NULL, struct ptn_compile);
> if (!c)
> return NULL;
> - s = nir_shader_create(NULL, options);
> + s = nir_shader_create(NULL, stage, options);
> if (!s)
> goto fail;
> c->prog = prog;
> --
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list