mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 21:40:08 +01:00
nir: Store gl_shader_stage in nir_shader.
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@whitecape.org> Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
parent
dfacae3a56
commit
d4d5b430a5
5 changed files with 34 additions and 7 deletions
|
|
@ -1765,6 +1765,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)
|
||||
|
|
@ -1776,7 +1791,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);
|
||||
|
|
@ -1785,9 +1805,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;
|
||||
|
|
|
|||
|
|
@ -132,7 +132,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);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,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);
|
||||
|
||||
|
|
@ -50,6 +52,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1474,6 +1474,9 @@ typedef struct nir_shader {
|
|||
* access plus one
|
||||
*/
|
||||
unsigned num_inputs, num_uniforms, num_outputs;
|
||||
|
||||
/** The shader stage, such as MESA_SHADER_VERTEX. */
|
||||
gl_shader_stage stage;
|
||||
} nir_shader;
|
||||
|
||||
#define nir_foreach_overload(shader, overload) \
|
||||
|
|
@ -1482,6 +1485,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 */
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "prog_instruction.h"
|
||||
#include "prog_parameter.h"
|
||||
#include "prog_print.h"
|
||||
#include "program.h"
|
||||
|
||||
/**
|
||||
* \file prog_to_nir.c
|
||||
|
|
@ -1081,11 +1082,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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue