[Mesa-dev] [PATCH 05/13] nir: Add a a nir_shader_info struct
Iago Toral
itoral at igalia.com
Fri Oct 9 02:22:50 PDT 2015
Hi Jason,
On Thu, 2015-10-01 at 18:50 -0700, Jason Ekstrand wrote:
> This commit also adds code to glsl_to_nir and prog_to_nir to fill it out.
> ---
> src/glsl/nir/glsl_to_nir.cpp | 18 ++++++++++++++++++
> src/glsl/nir/nir.c | 1 +
> src/glsl/nir/nir.h | 34 ++++++++++++++++++++++++++++++++++
> src/mesa/program/prog_to_nir.c | 13 +++++++++++++
> 4 files changed, 66 insertions(+)
>
> diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
> index ba08e17..6820962 100644
> --- a/src/glsl/nir/glsl_to_nir.cpp
> +++ b/src/glsl/nir/glsl_to_nir.cpp
> @@ -144,8 +144,26 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
>
> nir_lower_outputs_to_temporaries(shader);
>
> + /* TODO: Use _mesa_fls instead */
> + unsigned num_textures = 0;
> + for (unsigned i = 0; i < 8 * sizeof(sh->Program->SamplersUsed); i++)
> + if (sh->Program->SamplersUsed & (1 << i))
> + num_textures = i;
> +
> shader->gs.vertices_out = sh->Geom.VerticesOut;
> shader->gs.invocations = sh->Geom.Invocations;
> + shader->info.name = ralloc_asprintf(shader, "GLSL%d", sh->Name);
> + shader->info.num_textures = num_textures;
> + shader->info.num_ubos = sh->NumUniformBlocks;
> + shader->info.num_abos = shader_prog->NumAtomicBuffers;
> + shader->info.num_ssbos = shader_prog->NumBufferInterfaceBlocks;
> + shader->info.num_images = sh->NumImages;
> + shader->info.inputs_read = sh->Program->InputsRead;
> + shader->info.outputs_written = sh->Program->OutputsWritten;
> + shader->info.system_values_read = sh->Program->SystemValuesRead;
> + shader->info.uses_texture_gather = sh->Program->UsesGather;
> + shader->info.uses_clip_distance_out = sh->Program->UsesClipDistanceOut;
> + shader->info.separate_shader = shader_prog->SeparateShader;
>
> return shader;
> }
> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
> index fe10b38..7a469a6 100644
> --- a/src/glsl/nir/nir.c
> +++ b/src/glsl/nir/nir.c
> @@ -41,6 +41,7 @@ nir_shader_create(void *mem_ctx,
> exec_list_make_empty(&shader->outputs);
>
> shader->options = options;
> + memset(&shader->info, 0, sizeof(shader->info));
>
> exec_list_make_empty(&shader->functions);
> exec_list_make_empty(&shader->registers);
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index d0c7b04..320ffee 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -1454,6 +1454,37 @@ typedef struct nir_shader_compiler_options {
> bool native_integers;
> } nir_shader_compiler_options;
>
> +typedef struct nir_shader_info {
> + const char *name;
> +
> + /* Number of textures used by this shader */
> + unsigned num_textures;
> + /* Number of uniform buffers used by this shader */
> + unsigned num_ubos;
> + /* Number of atomic buffers used by this shader */
> + unsigned num_abos;
> + /* Number of shader storage buffers used by this shader */
> + unsigned num_ssbos;
> + /* Number of images used by this shader */
> + unsigned num_images;
> +
> + /* Which inputs are actually read */
> + uint64_t inputs_read;
> + /* Which outputs are actually written */
> + uint64_t outputs_written;
> + /* Which system values are actually read */
> + uint64_t system_values_read;
> +
> + /* Whether or not this shader ever uses textureGather() */
> + bool uses_texture_gather;
> +
> + /* Whether or not this shader uses the gl_ClipDistance output */
> + bool uses_clip_distance_out;
> +
> + /* Whether or not separate shader objects were used */
> + bool separate_shader;
> +} nir_shader_info;
> +
> typedef struct nir_shader {
> /** list of uniforms (nir_variable) */
> struct exec_list uniforms;
> @@ -1471,6 +1502,9 @@ typedef struct nir_shader {
> */
> const struct nir_shader_compiler_options *options;
>
> + /** Various bits of compile-time information about a given shader */
> + struct nir_shader_info info;
> +
> /** list of global variables in the shader (nir_variable) */
> struct exec_list globals;
>
> diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
> index 1bd735a..fc00534 100644
> --- a/src/mesa/program/prog_to_nir.c
> +++ b/src/mesa/program/prog_to_nir.c
> @@ -1122,6 +1122,19 @@ prog_to_nir(const struct gl_program *prog,
>
> ptn_add_output_stores(c);
>
> + s->info.name = ralloc_asprintf(s, "ARB%d", prog->Id);
> + s->info.num_textures = _mesa_fls(prog->SamplersUsed);
> + s->info.num_ubos = 0;
> + s->info.num_abos = 0;
> + s->info.num_ssbos = 0;
> + s->info.num_images = 0;
I have just noticed that the version of the patch that was committed
does:
shader->info.num_ubos = sh->NumUniformBlocks;
shader->info.num_ssbos = shader_prog->NumBufferInterfaceBlocks;
This is not really correct at the moment. See [1] for a detailed
explanation of why.
I see that nothing uses shader->info.num_ubos for now, so I guess this
is not a real problem at the moment. I plan on sending an actual series
based on my RFC in [1] which should provide a better interface for this,
but as it is now, the only way to compute num_ubos and num_ssbos would
be to iterate through UniformBlocks and count.
Iago
[1]
http://lists.freedesktop.org/archives/mesa-dev/2015-October/095951.html
> + s->info.inputs_read = prog->InputsRead;
> + s->info.outputs_written = prog->OutputsWritten;
> + s->info.system_values_read = prog->SystemValuesRead;
> + s->info.uses_texture_gather = false;
> + s->info.uses_clip_distance_out = false;
> + s->info.separate_shader = false;
> +
> fail:
> if (c->error) {
> ralloc_free(s);
More information about the mesa-dev
mailing list