glsl: add several EmitNo* options, and MaxUnrollIterations

This increases the chance that GLSL programs will actually work.

Note that continues and returns are not yet lowered, so linking
will just fail if not supported.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Luca Barbieri
2010-09-05 22:29:58 +02:00
committed by Ian Romanick
parent 6d3a2c97f4
commit e591c4625c
11 changed files with 27 additions and 19 deletions

View File

@@ -685,7 +685,7 @@ ast_struct_specifier::ast_struct_specifier(char *identifier,
} }
bool bool
do_common_optimization(exec_list *ir, bool linked) do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
{ {
GLboolean progress = GL_FALSE; GLboolean progress = GL_FALSE;
@@ -718,7 +718,7 @@ do_common_optimization(exec_list *ir, bool linked)
loop_state *ls = analyze_loop_variables(ir); loop_state *ls = analyze_loop_variables(ir);
progress = set_loop_controls(ir, ls) || progress; progress = set_loop_controls(ir, ls) || progress;
progress = unroll_loops(ir, ls) || progress; progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
delete ls; delete ls;
return progress; return progress;

View File

@@ -28,7 +28,7 @@
* Prototypes for optimization passes to be called by the compiler and drivers. * Prototypes for optimization passes to be called by the compiler and drivers.
*/ */
bool do_common_optimization(exec_list *ir, bool linked); bool do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations);
bool do_algebraic(exec_list *instructions); bool do_algebraic(exec_list *instructions);
bool do_constant_folding(exec_list *instructions); bool do_constant_folding(exec_list *instructions);

View File

@@ -1471,7 +1471,7 @@ link_shaders(GLcontext *ctx, struct gl_shader_program *prog)
* some of that unused. * some of that unused.
*/ */
for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
while (do_common_optimization(prog->_LinkedShaders[i]->ir, true)) while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32))
; ;
} }

View File

@@ -57,7 +57,7 @@ set_loop_controls(exec_list *instructions, loop_state *ls);
extern bool extern bool
unroll_loops(exec_list *instructions, loop_state *ls); unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations);
/** /**

View File

@@ -27,10 +27,11 @@
class loop_unroll_visitor : public ir_hierarchical_visitor { class loop_unroll_visitor : public ir_hierarchical_visitor {
public: public:
loop_unroll_visitor(loop_state *state) loop_unroll_visitor(loop_state *state, unsigned max_iterations)
{ {
this->state = state; this->state = state;
this->progress = false; this->progress = false;
this->max_iterations = max_iterations;
} }
virtual ir_visitor_status visit_leave(ir_loop *ir); virtual ir_visitor_status visit_leave(ir_loop *ir);
@@ -38,6 +39,7 @@ public:
loop_state *state; loop_state *state;
bool progress; bool progress;
unsigned max_iterations;
}; };
@@ -62,7 +64,7 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
/* Don't try to unroll loops that have zillions of iterations either. /* Don't try to unroll loops that have zillions of iterations either.
*/ */
if (ls->max_iterations > 32) if (ls->max_iterations > max_iterations)
return visit_continue; return visit_continue;
if (ls->num_loop_jumps > 0) if (ls->num_loop_jumps > 0)
@@ -90,9 +92,9 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
bool bool
unroll_loops(exec_list *instructions, loop_state *ls) unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations)
{ {
loop_unroll_visitor v(ls); loop_unroll_visitor v(ls, max_iterations);
v.run(instructions); v.run(instructions);

View File

@@ -215,7 +215,7 @@ compile_shader(GLcontext *ctx, struct gl_shader *shader)
loop_state *ls = analyze_loop_variables(shader->ir); loop_state *ls = analyze_loop_variables(shader->ir);
progress = set_loop_controls(shader->ir, ls) || progress; progress = set_loop_controls(shader->ir, ls) || progress;
progress = unroll_loops(shader->ir, ls) || progress; progress = unroll_loops(shader->ir, ls, 32) || progress;
delete ls; delete ls;
} while (progress); } while (progress);

View File

@@ -141,7 +141,7 @@ brw_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
do { do {
progress = false; progress = false;
progress = do_common_optimization(shader->ir, true) || progress; progress = do_common_optimization(shader->ir, true, 32) || progress;
} while (progress); } while (progress);
validate_ir_tree(shader->ir); validate_ir_tree(shader->ir);

View File

@@ -2187,7 +2187,6 @@ struct gl_shader_compiler_options
{ {
/** Driver-selectable options: */ /** Driver-selectable options: */
GLboolean EmitHighLevelInstructions; /**< IF/ELSE/ENDIF vs. BRA, etc. */ GLboolean EmitHighLevelInstructions; /**< IF/ELSE/ENDIF vs. BRA, etc. */
GLboolean EmitContReturn; /**< Emit CONT/RET opcodes? */
GLboolean EmitCondCodes; /**< Use condition codes? */ GLboolean EmitCondCodes; /**< Use condition codes? */
GLboolean EmitComments; /**< Annotated instructions */ GLboolean EmitComments; /**< Annotated instructions */
GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */ GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */
@@ -2196,6 +2195,12 @@ struct gl_shader_compiler_options
* support control flow. * support control flow.
*/ */
GLboolean EmitNoIfs; GLboolean EmitNoIfs;
GLboolean EmitNoLoops;
GLboolean EmitNoFunctions;
GLboolean EmitNoCont; /**< Emit CONT opcode? */
GLboolean EmitNoMainReturn; /**< Emit CONT/RET opcodes? */
GLuint MaxUnrollIterations;
struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
}; };

View File

@@ -97,10 +97,14 @@ _mesa_init_shader_state(GLcontext *ctx)
struct gl_shader_compiler_options options; struct gl_shader_compiler_options options;
GLuint i; GLuint i;
options.EmitHighLevelInstructions = GL_TRUE; options.EmitHighLevelInstructions = GL_TRUE;
options.EmitContReturn = GL_TRUE;
options.EmitCondCodes = GL_FALSE; options.EmitCondCodes = GL_FALSE;
options.EmitComments = GL_FALSE; options.EmitComments = GL_FALSE;
options.EmitNoIfs = GL_FALSE; options.EmitNoIfs = GL_FALSE;
options.EmitNoLoops = GL_FALSE;
options.EmitNoFunctions = GL_FALSE;
options.EmitNoCont = GL_FALSE;
options.EmitNoMainReturn = GL_FALSE;
options.MaxUnrollIterations = 32;
/* Default pragma settings */ /* Default pragma settings */
options.DefaultPragmas.IgnoreOptimize = GL_FALSE; options.DefaultPragmas.IgnoreOptimize = GL_FALSE;

View File

@@ -2719,7 +2719,7 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
do_div_to_mul_rcp(ir); do_div_to_mul_rcp(ir);
do_explog_to_explog2(ir); do_explog_to_explog2(ir);
progress = do_common_optimization(ir, true) || progress; progress = do_common_optimization(ir, true, options->MaxUnrollIterations) || progress;
if (options->EmitNoIfs) if (options->EmitNoIfs)
progress = do_if_to_cond_assign(ir) || progress; progress = do_if_to_cond_assign(ir) || progress;
@@ -2799,7 +2799,7 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
/* Do some optimization at compile time to reduce shader IR size /* Do some optimization at compile time to reduce shader IR size
* and reduce later work if the same shader is linked multiple times * and reduce later work if the same shader is linked multiple times
*/ */
while (do_common_optimization(shader->ir, false)) while (do_common_optimization(shader->ir, false, 32))
; ;
validate_ir_tree(shader->ir); validate_ir_tree(shader->ir);

View File

@@ -135,11 +135,8 @@ void st_init_limits(struct st_context *st)
= CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
1, MAX_DRAW_BUFFERS); 1, MAX_DRAW_BUFFERS);
/* Is TGSI_OPCODE_CONT supported? */
/* XXX separate query for early function return? */
for(i = 0; i < MESA_SHADER_TYPES; ++i) for(i = 0; i < MESA_SHADER_TYPES; ++i)
st->ctx->ShaderCompilerOptions[i].EmitContReturn = st->ctx->ShaderCompilerOptions[i].EmitNoCont = !screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED);
screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED);
/* Quads always follow GL provoking rules. */ /* Quads always follow GL provoking rules. */
c->QuadsFollowProvokingVertexConvention = GL_FALSE; c->QuadsFollowProvokingVertexConvention = GL_FALSE;