glsl: change GLSL #pragma initialization
Initialize the shader's pragma settings before calling the compiler. Added pragma "Ignore" fields to allow overriding the #pragma directives found in shader source code.
This commit is contained in:
@@ -1956,6 +1956,8 @@ struct gl_query_state
|
||||
/** Set by #pragma directives */
|
||||
struct gl_sl_pragmas
|
||||
{
|
||||
GLboolean IgnoreOptimize; /**< ignore #pragma optimize(on/off) ? */
|
||||
GLboolean IgnoreDebug; /**< ignore #pragma debug(on/off) ? */
|
||||
GLboolean Optimize; /**< defaults on */
|
||||
GLboolean Debug; /**< defaults off */
|
||||
};
|
||||
@@ -2026,6 +2028,7 @@ struct gl_shader_state
|
||||
GLboolean EmitComments; /**< Annotated instructions */
|
||||
void *MemPool;
|
||||
GLbitfield Flags; /**< Mask of GLSL_x flags */
|
||||
struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -410,6 +410,12 @@ _mesa_init_shader_state(GLcontext * ctx)
|
||||
ctx->Shader.EmitCondCodes = GL_FALSE;
|
||||
ctx->Shader.EmitComments = GL_FALSE;
|
||||
ctx->Shader.Flags = get_shader_flags();
|
||||
|
||||
/* Default pragma settings */
|
||||
ctx->Shader.DefaultPragmas.IgnoreOptimize = GL_FALSE;
|
||||
ctx->Shader.DefaultPragmas.IgnoreDebug = GL_FALSE;
|
||||
ctx->Shader.DefaultPragmas.Optimize = GL_TRUE;
|
||||
ctx->Shader.DefaultPragmas.Debug = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1444,6 +1450,9 @@ _mesa_compile_shader(GLcontext *ctx, GLuint shaderObj)
|
||||
if (!sh)
|
||||
return;
|
||||
|
||||
/* set default pragma state for shader */
|
||||
sh->Pragmas = ctx->Shader.DefaultPragmas;
|
||||
|
||||
/* this call will set the sh->CompileStatus field to indicate if
|
||||
* compilation was successful.
|
||||
*/
|
||||
|
||||
@@ -2798,7 +2798,9 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
|
||||
shader->CompileStatus = success;
|
||||
|
||||
if (success) {
|
||||
_mesa_optimize_program(ctx, shader->Program);
|
||||
if (shader->Pragmas.Optimize) {
|
||||
_mesa_optimize_program(ctx, shader->Program);
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->Shader.Flags & GLSL_LOG) {
|
||||
|
||||
@@ -530,14 +530,6 @@ pp_ext_set(pp_ext *self, const char *name, GLboolean enable)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pp_pragmas_init(struct gl_sl_pragmas *pragmas)
|
||||
{
|
||||
pragmas->Optimize = GL_TRUE;
|
||||
pragmas->Debug = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called in response to #pragma. For example, "#pragma debug(on)" would
|
||||
* call this function as pp_pragma("debug", "on").
|
||||
@@ -553,10 +545,12 @@ pp_pragma(struct gl_sl_pragmas *pragmas, const char *pragma, const char *param)
|
||||
if (!param)
|
||||
return GL_FALSE; /* missing required param */
|
||||
if (_mesa_strcmp(param, "on") == 0) {
|
||||
pragmas->Optimize = GL_TRUE;
|
||||
if (!pragmas->IgnoreOptimize)
|
||||
pragmas->Optimize = GL_TRUE;
|
||||
}
|
||||
else if (_mesa_strcmp(param, "off") == 0) {
|
||||
pragmas->Optimize = GL_FALSE;
|
||||
if (!pragmas->IgnoreOptimize)
|
||||
pragmas->Optimize = GL_FALSE;
|
||||
}
|
||||
else {
|
||||
return GL_FALSE; /* invalid param */
|
||||
@@ -566,10 +560,12 @@ pp_pragma(struct gl_sl_pragmas *pragmas, const char *pragma, const char *param)
|
||||
if (!param)
|
||||
return GL_FALSE; /* missing required param */
|
||||
if (_mesa_strcmp(param, "on") == 0) {
|
||||
pragmas->Debug = GL_TRUE;
|
||||
if (!pragmas->IgnoreDebug)
|
||||
pragmas->Debug = GL_TRUE;
|
||||
}
|
||||
else if (_mesa_strcmp(param, "off") == 0) {
|
||||
pragmas->Debug = GL_FALSE;
|
||||
if (!pragmas->IgnoreDebug)
|
||||
pragmas->Debug = GL_FALSE;
|
||||
}
|
||||
else {
|
||||
return GL_FALSE; /* invalid param */
|
||||
@@ -945,7 +941,6 @@ preprocess_source (slang_string *output, const char *source,
|
||||
}
|
||||
|
||||
pp_state_init (&state, elog, extensions);
|
||||
pp_pragmas_init (pragmas);
|
||||
|
||||
/* add the predefined symbols to the symbol table */
|
||||
for (i = 0; predefined[i]; i++) {
|
||||
@@ -1296,6 +1291,8 @@ error:
|
||||
* \param output the post-process results
|
||||
* \param input the input text
|
||||
* \param elog log to record warnings, errors
|
||||
* \param extensions out extension settings
|
||||
* \param pragmas in/out #pragma settings
|
||||
* \return GL_TRUE for success, GL_FALSE for error
|
||||
*/
|
||||
GLboolean
|
||||
|
||||
Reference in New Issue
Block a user