Mesa (glsl2): i915: Ask the compiler to flatten out all the if statements that it can.
Eric Anholt
anholt at kemper.freedesktop.org
Mon Jul 19 17:48:42 UTC 2010
Module: Mesa
Branch: glsl2
Commit: 95c08920ea3d040360e5cc51d8a852d21a0329ee
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=95c08920ea3d040360e5cc51d8a852d21a0329ee
Author: Eric Anholt <eric at anholt.net>
Date: Mon Jul 19 10:21:58 2010 -0700
i915: Ask the compiler to flatten out all the if statements that it can.
---
src/mesa/drivers/dri/i915/i915_context.c | 2 ++
src/mesa/main/mtypes.h | 5 +++++
src/mesa/shader/ir_to_mesa.cpp | 13 ++++++++++++-
src/mesa/shader/shader_api.c | 1 +
4 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c
index b3fe1c0..d8715cf 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -174,6 +174,8 @@ i915CreateContext(int api,
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
+ ctx->Shader.EmitNoIfs = GL_TRUE;
+
ctx->Const.MaxDrawBuffers = 1;
_tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 9a36740..be9eaaa 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2038,6 +2038,11 @@ struct gl_shader_state
GLboolean EmitCondCodes; /**< Use condition codes? */
GLboolean EmitComments; /**< Annotated instructions */
GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */
+ /**
+ * Attempts to flatten all ir_if (OPCODE_IF) for GPUs that can't
+ * support control flow.
+ */
+ GLboolean EmitNoIfs;
void *MemPool;
GLbitfield Flags; /**< Mask of GLSL_x flags */
struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp
index 84cfff4..58320c9 100644
--- a/src/mesa/shader/ir_to_mesa.cpp
+++ b/src/mesa/shader/ir_to_mesa.cpp
@@ -2026,8 +2026,10 @@ link_uniforms_to_shared_uniform_list(struct gl_uniform_list *uniforms,
}
struct gl_program *
-get_mesa_program(GLcontext *ctx, void *mem_ctx, struct gl_shader *shader)
+get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
+ struct gl_shader *shader)
{
+ void *mem_ctx = shader_program;
ir_to_mesa_visitor v;
struct prog_instruction *mesa_instructions, *mesa_inst;
ir_instruction **mesa_instruction_annotation;
@@ -2112,6 +2114,13 @@ get_mesa_program(GLcontext *ctx, void *mem_ctx, struct gl_shader *shader)
mesa_inst->TexShadow = inst->tex_shadow;
mesa_instruction_annotation[i] = inst->ir;
+ if (ctx->Shader.EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) {
+ shader_program->InfoLog =
+ talloc_asprintf_append(shader_program->InfoLog,
+ "Couldn't flatten if statement\n");
+ shader_program->LinkStatus = false;
+ }
+
if (mesa_inst->Opcode == OPCODE_BGNSUB)
inst->function->inst = i;
else if (mesa_inst->Opcode == OPCODE_CAL)
@@ -2206,6 +2215,8 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
progress = do_constant_variable_unlinked(shader->ir) || progress;
progress = do_constant_folding(shader->ir) || progress;
progress = do_if_return(shader->ir) || progress;
+ if (ctx->Shader.EmitNoIfs)
+ progress = do_if_to_cond_assign(shader->ir) || progress;
progress = do_vec_index_to_swizzle(shader->ir) || progress;
/* Do this one after the previous to let the easier pass handle
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index f05ebc9..cd02d7d 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -431,6 +431,7 @@ _mesa_init_shader_state(GLcontext * ctx)
ctx->Shader.EmitContReturn = GL_TRUE;
ctx->Shader.EmitCondCodes = GL_FALSE;
ctx->Shader.EmitComments = GL_FALSE;
+ ctx->Shader.EmitNoIfs = GL_FALSE;
ctx->Shader.Flags = get_shader_flags();
/* Default pragma settings */
More information about the mesa-commit
mailing list