This will be used to give the optimization passes a chance to customize behavior for the particular target device. ---
I had things as one giant patch before because I thought you couldn't have a struct with no members, and having a temporary version with a dummy member seemed ugly. Turns out you can have an empty struct, though. src/gallium/auxiliary/nir/tgsi_to_nir.c | 5 +++-- src/gallium/auxiliary/nir/tgsi_to_nir.h | 3 ++- src/gallium/drivers/vc4/vc4_program.c | 5 ++++- src/glsl/nir/glsl_to_nir.cpp | 23 ++++++++++++++++++++++- src/glsl/nir/nir.c | 4 +++- src/glsl/nir/nir.h | 15 +++++++++++++-- src/mesa/main/mtypes.h | 2 ++ 7 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index 16d3d23..715f905 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -1234,7 +1234,8 @@ ttn_add_output_stores(struct ttn_compile *c) } struct nir_shader * -tgsi_to_nir(struct pipe_context *pctx, const void *tgsi_tokens) +tgsi_to_nir(struct pipe_context *pctx, const void *tgsi_tokens, + const nir_shader_compiler_options *options) { struct tgsi_parse_context parser; struct tgsi_shader_info scan; @@ -1245,7 +1246,7 @@ tgsi_to_nir(struct pipe_context *pctx, const void *tgsi_tokens) c = rzalloc(NULL, struct ttn_compile); if (!c) return NULL; - s = nir_shader_create(NULL); + s = nir_shader_create(NULL, options); if (!s) goto fail; c->s = s; diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.h b/src/gallium/auxiliary/nir/tgsi_to_nir.h index b9a4ed1..4d5eefa 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.h +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.h @@ -24,4 +24,5 @@ struct pipe_context; struct nir_shader * -tgsi_to_nir(struct pipe_context *pctx, const void *tgsi_tokens); +tgsi_to_nir(struct pipe_context *pctx, const void *tgsi_tokens, + const nir_shader_compiler_options *options); diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index 9f0f6a2..3c76025 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -2097,6 +2097,9 @@ nir_to_qir(struct vc4_compile *c) } } +static const nir_shader_compiler_options nir_options = { +}; + static struct vc4_compile * vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, struct vc4_key *key) @@ -2157,7 +2160,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage, tgsi_dump(tokens, 0); } - c->s = tgsi_to_nir(&vc4->base, tokens); + c->s = tgsi_to_nir(&vc4->base, tokens, &nir_options); nir_opt_global_to_local(c->s); nir_convert_to_ssa(c->s); diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp index 46cfac3..929291d 100644 --- a/src/glsl/nir/glsl_to_nir.cpp +++ b/src/glsl/nir/glsl_to_nir.cpp @@ -124,11 +124,32 @@ private: }; /* end of anonymous namespace */ +static const nir_shader_compiler_options default_options = { +}; + nir_shader * glsl_to_nir(exec_list *ir, _mesa_glsl_parse_state *state, bool native_integers) { - nir_shader *shader = nir_shader_create(NULL); + const nir_shader_compiler_options *options; + + if (state) { + struct gl_context *ctx = state->ctx; + struct gl_shader_compiler_options *gl_options = + &ctx->Const.ShaderCompilerOptions[state->stage]; + + if (!gl_options->NirOptions) { + nir_shader_compiler_options *new_options = + rzalloc(ctx, nir_shader_compiler_options); + options = gl_options->NirOptions = new_options; + } else { + options = gl_options->NirOptions; + } + } else { + options = &default_options; + } + + nir_shader *shader = nir_shader_create(NULL, options); if (state) { shader->num_user_structures = state->num_user_structures; diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index 10e6ed3..2c5c8db 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -29,7 +29,7 @@ #include <assert.h> nir_shader * -nir_shader_create(void *mem_ctx) +nir_shader_create(void *mem_ctx, const nir_shader_compiler_options *options) { nir_shader *shader = ralloc(mem_ctx, nir_shader); @@ -40,6 +40,8 @@ nir_shader_create(void *mem_ctx) shader->outputs = _mesa_hash_table_create(shader, _mesa_key_hash_string, _mesa_key_string_equal); + shader->options = options; + shader->num_user_structures = 0; shader->user_structures = NULL; diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 98d2689..cc0aed1 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -1326,6 +1326,9 @@ typedef struct nir_function { exec_node_data(nir_function_overload, \ exec_list_get_head(&(func)->overload_list), node) +typedef struct nir_shader_compiler_options { +} nir_shader_compiler_options; + typedef struct nir_shader { /** hash table of name -> uniform nir_variable */ struct hash_table *uniforms; @@ -1336,6 +1339,13 @@ typedef struct nir_shader { /** hash table of name -> output nir_variable */ struct hash_table *outputs; + /** Set of driver-specific options for the shader. + * + * The memory for the options is expected to be kept in a single static + * copy by the driver. + */ + const struct nir_shader_compiler_options *options; + /** list of global variables in the shader */ struct exec_list globals; @@ -1361,12 +1371,13 @@ typedef struct nir_shader { unsigned num_inputs, num_uniforms, num_outputs; } nir_shader; -#define nir_foreach_overload(shader, overload) \ +#define nir_foreach_overload(shader, overload) \ foreach_list_typed(nir_function, func, node, &(shader)->functions) \ foreach_list_typed(nir_function_overload, overload, node, \ &(func)->overload_list) -nir_shader *nir_shader_create(void *mem_ctx); +nir_shader *nir_shader_create(void *mem_ctx, + const nir_shader_compiler_options *options); /** creates a register, including assigning it an index and adding it to the list */ nir_register *nir_global_reg_create(nir_shader *shader); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 81a7c0e..d440e58 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3033,6 +3033,8 @@ struct gl_shader_compiler_options GLboolean OptimizeForAOS; struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ + + struct nir_shader_compiler_options *NirOptions; }; -- 2.1.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev