[Mesa-dev] [PATCH] [rfc] nir: pass uniform storage instead of shader program
Dave Airlie
airlied at gmail.com
Tue May 1 01:50:42 UTC 2018
From: Dave Airlie <airlied at redhat.com>
Only the asserts were accessing anything, and I'm not sure the
value of those is worth preserving, this removes mtypes.h includes
from nir which seemed like a laudable goal.
---
src/compiler/nir/nir.h | 8 ++++----
src/compiler/nir/nir_lower_atomics.c | 9 ++++-----
src/compiler/nir/nir_lower_samplers.c | 18 ++++++++----------
src/compiler/nir/nir_lower_samplers_as_deref.c | 12 ++++--------
src/mesa/drivers/dri/i965/brw_link.cpp | 4 ++--
src/mesa/main/glspirv.h | 1 +
src/mesa/state_tracker/st_glsl_to_nir.cpp | 6 +++---
7 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index f3326e6..dd38eab 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -56,7 +56,7 @@ extern "C" {
#endif
struct gl_program;
-struct gl_shader_program;
+struct gl_uniform_storage;
#define NIR_FALSE 0u
#define NIR_TRUE (~0u)
@@ -2597,9 +2597,9 @@ void nir_lower_io_to_scalar(nir_shader *shader, nir_variable_mode mask);
void nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
bool nir_lower_samplers(nir_shader *shader,
- const struct gl_shader_program *shader_program);
+ const struct gl_uniform_storage *uniform_storage);
bool nir_lower_samplers_as_deref(nir_shader *shader,
- const struct gl_shader_program *shader_program);
+ const struct gl_uniform_storage *uniform_storage);
typedef struct nir_lower_subgroups_options {
uint8_t subgroup_size;
@@ -2756,7 +2756,7 @@ typedef struct nir_lower_bitmap_options {
void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *options);
bool nir_lower_atomics(nir_shader *shader,
- const struct gl_shader_program *shader_program,
+ const struct gl_uniform_storage *uniform_storage,
bool use_binding_as_idx);
bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned ssbo_offset);
bool nir_lower_to_source_mods(nir_shader *shader);
diff --git a/src/compiler/nir/nir_lower_atomics.c b/src/compiler/nir/nir_lower_atomics.c
index 383e323..eed9143 100644
--- a/src/compiler/nir/nir_lower_atomics.c
+++ b/src/compiler/nir/nir_lower_atomics.c
@@ -28,7 +28,6 @@
#include "compiler/glsl/ir_uniform.h"
#include "nir.h"
#include "main/config.h"
-#include "main/mtypes.h"
#include <assert.h>
/*
@@ -38,7 +37,7 @@
static bool
lower_instr(nir_intrinsic_instr *instr,
- const struct gl_shader_program *shader_program,
+ const struct gl_uniform_storage *uniform_storage,
nir_shader *shader, bool use_binding_as_idx)
{
nir_intrinsic_op op;
@@ -101,7 +100,7 @@ lower_instr(nir_intrinsic_instr *instr,
unsigned idx = use_binding_as_idx ?
instr->variables[0]->var->data.binding :
- shader_program->data->UniformStorage[uniform_loc].opaque[shader->info.stage].index;
+ uniform_storage[uniform_loc].opaque[shader->info.stage].index;
nir_intrinsic_instr *new_instr = nir_intrinsic_instr_create(mem_ctx, op);
nir_intrinsic_set_base(new_instr, idx);
@@ -178,7 +177,7 @@ lower_instr(nir_intrinsic_instr *instr,
bool
nir_lower_atomics(nir_shader *shader,
- const struct gl_shader_program *shader_program,
+ const struct gl_uniform_storage *uniform_storage,
bool use_binding_as_idx)
{
bool progress = false;
@@ -195,7 +194,7 @@ nir_lower_atomics(nir_shader *shader,
continue;
impl_progress |= lower_instr(nir_instr_as_intrinsic(instr),
- shader_program, shader,
+ uniform_storage, shader,
use_binding_as_idx);
}
}
diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c
index 7690665..ed2e1be 100644
--- a/src/compiler/nir/nir_lower_samplers.c
+++ b/src/compiler/nir/nir_lower_samplers.c
@@ -28,7 +28,6 @@
#include "compiler/glsl/ir_uniform.h"
#include "main/compiler.h"
-#include "main/mtypes.h"
/* Calculate the sampler index based on array indicies and also
* calculate the base uniform location for struct members.
@@ -85,7 +84,8 @@ calc_sampler_offsets(nir_deref *tail, nir_tex_instr *instr,
}
static bool
-lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_program,
+lower_sampler(nir_tex_instr *instr,
+ const struct gl_uniform_storage *uniform_storage,
gl_shader_stage stage, nir_builder *b)
{
if (instr->texture == NULL)
@@ -115,11 +115,8 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
instr->texture_array_size = array_elements;
}
- assert(location < shader_program->data->NumUniformStorage &&
- shader_program->data->UniformStorage[location].opaque[stage].active);
-
instr->texture_index +=
- shader_program->data->UniformStorage[location].opaque[stage].index;
+ uniform_storage[location].opaque[stage].index;
instr->sampler_index = instr->texture_index;
@@ -129,7 +126,8 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
}
static bool
-lower_impl(nir_function_impl *impl, const struct gl_shader_program *shader_program,
+lower_impl(nir_function_impl *impl,
+ const struct gl_uniform_storage *uniform_storage,
gl_shader_stage stage)
{
nir_builder b;
@@ -140,7 +138,7 @@ lower_impl(nir_function_impl *impl, const struct gl_shader_program *shader_progr
nir_foreach_instr(instr, block) {
if (instr->type == nir_instr_type_tex)
progress |= lower_sampler(nir_instr_as_tex(instr),
- shader_program, stage, &b);
+ uniform_storage, stage, &b);
}
}
@@ -149,13 +147,13 @@ lower_impl(nir_function_impl *impl, const struct gl_shader_program *shader_progr
bool
nir_lower_samplers(nir_shader *shader,
- const struct gl_shader_program *shader_program)
+ const struct gl_uniform_storage *uniform_storage)
{
bool progress = false;
nir_foreach_function(function, shader) {
if (function->impl)
- progress |= lower_impl(function->impl, shader_program,
+ progress |= lower_impl(function->impl, uniform_storage,
shader->info.stage);
}
diff --git a/src/compiler/nir/nir_lower_samplers_as_deref.c b/src/compiler/nir/nir_lower_samplers_as_deref.c
index cb0c827..1f3fbbc 100644
--- a/src/compiler/nir/nir_lower_samplers_as_deref.c
+++ b/src/compiler/nir/nir_lower_samplers_as_deref.c
@@ -60,11 +60,10 @@
#include "compiler/glsl/ir_uniform.h"
#include "main/compiler.h"
-#include "main/mtypes.h"
struct lower_samplers_as_deref_state {
nir_shader *shader;
- const struct gl_shader_program *shader_program;
+ const struct gl_uniform_storage *uniform_storage;
struct hash_table *remap_table;
};
@@ -125,10 +124,7 @@ lower_deref(nir_deref_var *deref,
path = ralloc_asprintf(state->remap_table, "lower@%s", var->name);
remove_struct_derefs(&deref->deref, state, b, &path, &location);
- assert(location < state->shader_program->data->NumUniformStorage &&
- state->shader_program->data->UniformStorage[location].opaque[stage].active);
-
- binding = state->shader_program->data->UniformStorage[location].opaque[stage].index;
+ binding = state->uniform_storage[location].opaque[stage].index;
if (orig_type == deref->deref.type) {
/* Fast path: We did not encounter any struct derefs. */
@@ -227,13 +223,13 @@ lower_impl(nir_function_impl *impl, struct lower_samplers_as_deref_state *state)
bool
nir_lower_samplers_as_deref(nir_shader *shader,
- const struct gl_shader_program *shader_program)
+ const struct gl_uniform_storage *uniform_storage)
{
bool progress = false;
struct lower_samplers_as_deref_state state;
state.shader = shader;
- state.shader_program = shader_program;
+ state.uniform_storage = uniform_storage;
state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
_mesa_key_string_equal);
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 7841626..7c87d89 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -299,8 +299,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
struct gl_program *prog = shader->Program;
brw_shader_gather_info(prog->nir, prog);
- NIR_PASS_V(prog->nir, nir_lower_samplers, shProg);
- NIR_PASS_V(prog->nir, nir_lower_atomics, shProg, false);
+ NIR_PASS_V(prog->nir, nir_lower_samplers, shProg->data->UniformStorage);
+ NIR_PASS_V(prog->nir, nir_lower_atomics, shProg->data->UniformStorage, false);
NIR_PASS_V(prog->nir, nir_lower_atomics_to_ssbo,
prog->nir->info.num_abos);
diff --git a/src/mesa/main/glspirv.h b/src/mesa/main/glspirv.h
index cbcd3c0..31ffda1 100644
--- a/src/mesa/main/glspirv.h
+++ b/src/mesa/main/glspirv.h
@@ -32,6 +32,7 @@ extern "C" {
struct gl_context;
struct gl_shader;
+struct gl_shader_program;
/**
* A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index bcf6a7c..bde1384 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -467,7 +467,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
st_set_prog_affected_state_flags(prog);
NIR_PASS_V(nir, st_nir_lower_builtin);
- NIR_PASS_V(nir, nir_lower_atomics, shader_program, true);
+ NIR_PASS_V(nir, nir_lower_atomics, shader_program->data->UniformStorage, true);
if (st->ctx->_Shader->Flags & GLSL_DUMP) {
_mesa_log("\n");
@@ -813,9 +813,9 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
}
if (screen->get_param(screen, PIPE_CAP_NIR_SAMPLERS_AS_DEREF))
- NIR_PASS_V(nir, nir_lower_samplers_as_deref, shader_program);
+ NIR_PASS_V(nir, nir_lower_samplers_as_deref, shader_program->data->UniformStorage);
else
- NIR_PASS_V(nir, nir_lower_samplers, shader_program);
+ NIR_PASS_V(nir, nir_lower_samplers, shader_program->data->UniformStorage);
}
} /* extern "C" */
--
2.9.5
More information about the mesa-dev
mailing list