mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 07:28:11 +02:00
glsl: move some lowering to the compiler
Rather than doing this lowering potentially multiple times when a shader is relinked we can instead do it once in the compiler. This change also gets us closer to converting to NIR at compile time. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27690>
This commit is contained in:
parent
82d617e8b1
commit
0f0fa64eed
5 changed files with 18 additions and 15 deletions
|
|
@ -2193,6 +2193,7 @@ do_late_parsing_checks(struct _mesa_glsl_parse_state *state)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
opt_shader_and_create_symbol_table(const struct gl_constants *consts,
|
opt_shader_and_create_symbol_table(const struct gl_constants *consts,
|
||||||
|
const struct gl_extensions *exts,
|
||||||
struct glsl_symbol_table *source_symbols,
|
struct glsl_symbol_table *source_symbols,
|
||||||
struct gl_shader *shader)
|
struct gl_shader *shader)
|
||||||
{
|
{
|
||||||
|
|
@ -2229,6 +2230,17 @@ opt_shader_and_create_symbol_table(const struct gl_constants *consts,
|
||||||
|
|
||||||
optimize_dead_builtin_variables(shader->ir, other);
|
optimize_dead_builtin_variables(shader->ir, other);
|
||||||
|
|
||||||
|
lower_vector_derefs(shader);
|
||||||
|
|
||||||
|
lower_packing_builtins(shader->ir, exts->ARB_shading_language_packing,
|
||||||
|
exts->ARB_gpu_shader5,
|
||||||
|
consts->GLSLHasHalfFloatPacking);
|
||||||
|
do_mat_op_to_vec(shader->ir);
|
||||||
|
|
||||||
|
lower_instructions(shader->ir, exts->ARB_gpu_shader5);
|
||||||
|
|
||||||
|
do_vec_index_to_cond_assign(shader->ir);
|
||||||
|
|
||||||
validate_ir_tree(shader->ir);
|
validate_ir_tree(shader->ir);
|
||||||
|
|
||||||
/* Retain any live IR, but trash the rest. */
|
/* Retain any live IR, but trash the rest. */
|
||||||
|
|
@ -2399,7 +2411,8 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
|
||||||
lower_builtins(shader->ir);
|
lower_builtins(shader->ir);
|
||||||
assign_subroutine_indexes(state);
|
assign_subroutine_indexes(state);
|
||||||
lower_subroutine(shader->ir, state);
|
lower_subroutine(shader->ir, state);
|
||||||
opt_shader_and_create_symbol_table(&ctx->Const, state->symbols, shader);
|
opt_shader_and_create_symbol_table(&ctx->Const, &ctx->Extensions,
|
||||||
|
state->symbols, shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force_recompile) {
|
if (!force_recompile) {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#ifndef GLSL_IR_OPTIMIZATION_H
|
#ifndef GLSL_IR_OPTIMIZATION_H
|
||||||
#define GLSL_IR_OPTIMIZATION_H
|
#define GLSL_IR_OPTIMIZATION_H
|
||||||
|
|
||||||
|
struct gl_shader;
|
||||||
struct gl_linked_shader;
|
struct gl_linked_shader;
|
||||||
struct gl_shader_program;
|
struct gl_shader_program;
|
||||||
|
|
||||||
|
|
@ -60,7 +61,7 @@ bool lower_packing_builtins(exec_list *instructions,
|
||||||
bool has_shading_language_packing,
|
bool has_shading_language_packing,
|
||||||
bool has_gpu_shader5,
|
bool has_gpu_shader5,
|
||||||
bool has_half_float_packing);
|
bool has_half_float_packing);
|
||||||
bool lower_vector_derefs(gl_linked_shader *shader);
|
bool lower_vector_derefs(gl_shader *shader);
|
||||||
void optimize_dead_builtin_variables(exec_list *instructions,
|
void optimize_dead_builtin_variables(exec_list *instructions,
|
||||||
enum ir_variable_mode other);
|
enum ir_variable_mode other);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2919,17 +2919,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
|
||||||
if (!prog->data->LinkStatus)
|
if (!prog->data->LinkStatus)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
lower_vector_derefs(shader);
|
|
||||||
|
|
||||||
lower_packing_builtins(ir, ctx->Extensions.ARB_shading_language_packing,
|
|
||||||
ctx->Extensions.ARB_gpu_shader5,
|
|
||||||
ctx->Const.GLSLHasHalfFloatPacking);
|
|
||||||
do_mat_op_to_vec(ir);
|
|
||||||
|
|
||||||
lower_instructions(ir, ctx->Extensions.ARB_gpu_shader5);
|
|
||||||
|
|
||||||
do_vec_index_to_cond_assign(ir);
|
|
||||||
|
|
||||||
const struct gl_shader_compiler_options *gl_options =
|
const struct gl_shader_compiler_options *gl_options =
|
||||||
&consts->ShaderCompilerOptions[i];
|
&consts->ShaderCompilerOptions[i];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ vector_deref_visitor::handle_rvalue(ir_rvalue **rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
lower_vector_derefs(gl_linked_shader *shader)
|
lower_vector_derefs(gl_shader *shader)
|
||||||
{
|
{
|
||||||
vector_deref_visitor v(shader->ir, shader->Stage);
|
vector_deref_visitor v(shader->ir, shader->Stage);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -401,7 +401,7 @@ TESTS = [
|
||||||
gl_FragColor = vec4(b * a, 0.0, 0.0);
|
gl_FragColor = vec4(b * a, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
r'\(expression +f16vec2 \* \(var_ref b\) \(var_ref a\)'),
|
r'\(expression f16vec2 \+ \(expression f16vec2 \* \(array_ref \(var_ref b\) \(constant int \(0\)\) \) \(swiz x \(var_ref a\) \)\) \(expression f16vec2 \* \(array_ref \(var_ref b\) \(constant int \(1\)\) \) \(swiz y \(var_ref a\) \)\) \) \)'),
|
||||||
Test("f32 simple struct deref",
|
Test("f32 simple struct deref",
|
||||||
"""
|
"""
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue