glsl: make compiler options per-target

This allows us to specify different options, especially useful for chips
without unified shaders.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Luca Barbieri
2010-09-05 18:49:54 +02:00
committed by Ian Romanick
parent ede4205b24
commit 6d3a2c97f4
8 changed files with 64 additions and 25 deletions

View File

@@ -174,7 +174,11 @@ i915CreateContext(int api,
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
ctx->Shader.EmitNoIfs = GL_TRUE; /* FINISHME: Are there other options that should be enabled for software
* FINISHME: vertex shaders?
*/
ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitCondCodes = GL_TRUE;
ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT].EmitNoIfs = GL_TRUE;
ctx->Const.MaxDrawBuffers = 1; ctx->Const.MaxDrawBuffers = 1;

View File

@@ -66,6 +66,7 @@ GLboolean brwCreateContext( int api,
struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context); struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
struct intel_context *intel = &brw->intel; struct intel_context *intel = &brw->intel;
GLcontext *ctx = &intel->ctx; GLcontext *ctx = &intel->ctx;
unsigned i;
if (!brw) { if (!brw) {
printf("%s: failed to alloc context\n", __FUNCTION__); printf("%s: failed to alloc context\n", __FUNCTION__);
@@ -110,8 +111,10 @@ GLboolean brwCreateContext( int api,
ctx->Const.MaxPointSizeAA = 255.0; ctx->Const.MaxPointSizeAA = 255.0;
/* We want the GLSL compiler to emit code that uses condition codes */ /* We want the GLSL compiler to emit code that uses condition codes */
ctx->Shader.EmitCondCodes = GL_TRUE; for (i = 0; i <= MESA_SHADER_FRAGMENT; i++) {
ctx->Shader.EmitNVTempInitialization = GL_TRUE; ctx->ShaderCompilerOptions[i].EmitCondCodes = GL_TRUE;
ctx->ShaderCompilerOptions[i].EmitNVTempInitialization = GL_TRUE;
}
ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024); ctx->Const.VertexProgram.MaxNativeInstructions = (16 * 1024);
ctx->Const.VertexProgram.MaxAluInstructions = 0; ctx->Const.VertexProgram.MaxAluInstructions = 0;

View File

@@ -337,6 +337,9 @@ static void r600ParseOptions(context_t *r600, radeonScreenPtr screen)
static void r600InitGLExtensions(GLcontext *ctx) static void r600InitGLExtensions(GLcontext *ctx)
{ {
context_t *r600 = R700_CONTEXT(ctx); context_t *r600 = R700_CONTEXT(ctx);
#ifdef R600_ENABLE_GLSL_TEST
unsigned i;
#endif
driInitExtensions(ctx, card_extensions, GL_TRUE); driInitExtensions(ctx, card_extensions, GL_TRUE);
if (r600->radeon.radeonScreen->kernel_mm) if (r600->radeon.radeonScreen->kernel_mm)
@@ -347,7 +350,8 @@ static void r600InitGLExtensions(GLcontext *ctx)
_mesa_enable_2_0_extensions(ctx); _mesa_enable_2_0_extensions(ctx);
/* glsl compiler has problem if this is not GL_TRUE */ /* glsl compiler has problem if this is not GL_TRUE */
ctx->Shader.EmitCondCodes = GL_TRUE; for (i = 0; i <= MESA_SHADER_FRAGMENT; i++)
ctx->ShaderCompilerOptions[i].EmitCondCodes = GL_TRUE;
#endif /* R600_ENABLE_GLSL_TEST */ #endif /* R600_ENABLE_GLSL_TEST */
if (driQueryOptionb if (driQueryOptionb

View File

@@ -2175,6 +2175,16 @@ struct gl_shader_program
struct gl_shader_state struct gl_shader_state
{ {
struct gl_shader_program *CurrentProgram; /**< The user-bound program */ struct gl_shader_program *CurrentProgram; /**< The user-bound program */
void *MemPool;
GLbitfield Flags; /**< Mask of GLSL_x flags */
};
/**
* Compiler options for a single GLSL shaders type
*/
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 EmitContReturn; /**< Emit CONT/RET opcodes? */
@@ -2186,12 +2196,10 @@ struct gl_shader_state
* support control flow. * support control flow.
*/ */
GLboolean EmitNoIfs; GLboolean EmitNoIfs;
void *MemPool;
GLbitfield Flags; /**< Mask of GLSL_x flags */
struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
}; };
/** /**
* Transform feedback object state * Transform feedback object state
*/ */
@@ -3212,6 +3220,7 @@ struct __GLcontextRec
struct gl_ati_fragment_shader_state ATIFragmentShader; struct gl_ati_fragment_shader_state ATIFragmentShader;
struct gl_shader_state Shader; /**< GLSL shader object state */ struct gl_shader_state Shader; /**< GLSL shader object state */
struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES];
struct gl_query_state Query; /**< occlusion, timer queries */ struct gl_query_state Query; /**< occlusion, timer queries */

View File

@@ -516,8 +516,10 @@ _mesa_emit_nv_temp_initialization(GLcontext *ctx,
{ {
struct prog_instruction *inst; struct prog_instruction *inst;
GLuint i; GLuint i;
struct gl_shader_compiler_options* options =
&ctx->ShaderCompilerOptions[_mesa_program_target_to_index(program->Target)];
if (!ctx->Shader.EmitNVTempInitialization) if (!options->EmitNVTempInitialization)
return; return;
/* We'll swizzle up a zero temporary so we can use it for the /* We'll swizzle up a zero temporary so we can use it for the

View File

@@ -94,18 +94,24 @@ _mesa_init_shader_state(GLcontext *ctx)
/* Device drivers may override these to control what kind of instructions /* Device drivers may override these to control what kind of instructions
* are generated by the GLSL compiler. * are generated by the GLSL compiler.
*/ */
ctx->Shader.EmitHighLevelInstructions = GL_TRUE; struct gl_shader_compiler_options options;
ctx->Shader.EmitContReturn = GL_TRUE; GLuint i;
ctx->Shader.EmitCondCodes = GL_FALSE; options.EmitHighLevelInstructions = GL_TRUE;
ctx->Shader.EmitComments = GL_FALSE; options.EmitContReturn = GL_TRUE;
ctx->Shader.EmitNoIfs = GL_FALSE; options.EmitCondCodes = GL_FALSE;
ctx->Shader.Flags = get_shader_flags(); options.EmitComments = GL_FALSE;
options.EmitNoIfs = GL_FALSE;
/* Default pragma settings */ /* Default pragma settings */
ctx->Shader.DefaultPragmas.IgnoreOptimize = GL_FALSE; options.DefaultPragmas.IgnoreOptimize = GL_FALSE;
ctx->Shader.DefaultPragmas.IgnoreDebug = GL_FALSE; options.DefaultPragmas.IgnoreDebug = GL_FALSE;
ctx->Shader.DefaultPragmas.Optimize = GL_TRUE; options.DefaultPragmas.Optimize = GL_TRUE;
ctx->Shader.DefaultPragmas.Debug = GL_FALSE; options.DefaultPragmas.Debug = GL_FALSE;
for(i = 0; i < MESA_SHADER_TYPES; ++i)
memcpy(&ctx->ShaderCompilerOptions[i], &options, sizeof(options));
ctx->Shader.Flags = get_shader_flags();
} }
@@ -789,13 +795,16 @@ static void
compile_shader(GLcontext *ctx, GLuint shaderObj) compile_shader(GLcontext *ctx, GLuint shaderObj)
{ {
struct gl_shader *sh; struct gl_shader *sh;
struct gl_shader_compiler_options *options;
sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader"); sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader");
if (!sh) if (!sh)
return; return;
options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(sh->Type)];
/* set default pragma state for shader */ /* set default pragma state for shader */
sh->Pragmas = ctx->Shader.DefaultPragmas; sh->Pragmas = options->DefaultPragmas;
/* this call will set the sh->CompileStatus field to indicate if /* this call will set the sh->CompileStatus field to indicate if
* compilation was successful. * compilation was successful.

View File

@@ -186,6 +186,7 @@ public:
GLcontext *ctx; GLcontext *ctx;
struct gl_program *prog; struct gl_program *prog;
struct gl_shader_program *shader_program; struct gl_shader_program *shader_program;
struct gl_shader_compiler_options *options;
int next_temp; int next_temp;
@@ -2096,7 +2097,7 @@ ir_to_mesa_visitor::visit(ir_if *ir)
ir->condition->accept(this); ir->condition->accept(this);
assert(this->result.file != PROGRAM_UNDEFINED); assert(this->result.file != PROGRAM_UNDEFINED);
if (ctx->Shader.EmitCondCodes) { if (this->options->EmitCondCodes) {
cond_inst = (ir_to_mesa_instruction *)this->instructions.get_tail(); cond_inst = (ir_to_mesa_instruction *)this->instructions.get_tail();
/* See if we actually generated any instruction for generating /* See if we actually generated any instruction for generating
@@ -2526,6 +2527,8 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
GLenum target; GLenum target;
const char *target_string; const char *target_string;
GLboolean progress; GLboolean progress;
struct gl_shader_compiler_options *options =
&ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
switch (shader->Type) { switch (shader->Type) {
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
@@ -2552,6 +2555,7 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
v.ctx = ctx; v.ctx = ctx;
v.prog = prog; v.prog = prog;
v.shader_program = shader_program; v.shader_program = shader_program;
v.options = options;
add_uniforms_to_parameters_list(shader_program, shader, prog); add_uniforms_to_parameters_list(shader_program, shader, prog);
@@ -2629,7 +2633,7 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
if (mesa_inst->SrcReg[src].RelAddr) if (mesa_inst->SrcReg[src].RelAddr)
prog->IndirectRegisterFiles |= 1 << mesa_inst->SrcReg[src].File; prog->IndirectRegisterFiles |= 1 << mesa_inst->SrcReg[src].File;
if (ctx->Shader.EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) { if (options->EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) {
fail_link(shader_program, "Couldn't flatten if statement\n"); fail_link(shader_program, "Couldn't flatten if statement\n");
} }
@@ -2703,6 +2707,8 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
bool progress; bool progress;
exec_list *ir = prog->_LinkedShaders[i]->ir; exec_list *ir = prog->_LinkedShaders[i]->ir;
struct gl_shader_compiler_options *options =
&ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(prog->_LinkedShaders[i]->Type)];
do { do {
progress = false; progress = false;
@@ -2715,7 +2721,7 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
progress = do_common_optimization(ir, true) || progress; progress = do_common_optimization(ir, true) || progress;
if (ctx->Shader.EmitNoIfs) if (options->EmitNoIfs)
progress = do_if_to_cond_assign(ir) || progress; progress = do_if_to_cond_assign(ir) || progress;
progress = do_vec_index_to_cond_assign(ir) || progress; progress = do_vec_index_to_cond_assign(ir) || progress;

View File

@@ -68,6 +68,7 @@ void st_init_limits(struct st_context *st)
struct pipe_screen *screen = st->pipe->screen; struct pipe_screen *screen = st->pipe->screen;
struct gl_constants *c = &st->ctx->Const; struct gl_constants *c = &st->ctx->Const;
struct gl_program_constants *pc; struct gl_program_constants *pc;
unsigned i;
c->MaxTextureLevels c->MaxTextureLevels
= _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
@@ -136,7 +137,8 @@ void st_init_limits(struct st_context *st)
/* Is TGSI_OPCODE_CONT supported? */ /* Is TGSI_OPCODE_CONT supported? */
/* XXX separate query for early function return? */ /* XXX separate query for early function return? */
st->ctx->Shader.EmitContReturn = for(i = 0; i < MESA_SHADER_TYPES; ++i)
st->ctx->ShaderCompilerOptions[i].EmitContReturn =
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. */