};
+/** Set by #pragma directives */
+struct gl_sl_pragmas
+{
+ GLboolean Optimize; /**< defaults on */
+ GLboolean Debug; /**< defaults off */
+};
+
/**
* A GLSL vertex or fragment shader object.
GLuint Name; /**< AKA the handle */
GLint RefCount; /**< Reference count */
GLboolean DeletePending;
-
- const GLchar *Source; /**< Source code string */
GLboolean CompileStatus;
+ GLboolean Main; /**< shader defines main() */
+ const GLchar *Source; /**< Source code string */
struct gl_program *Program; /**< Post-compile assembly code */
GLchar *InfoLog;
- GLboolean Main; /**< shader defines main() */
+ struct gl_sl_pragmas Pragmas;
};
n = _slang_gen_var_decl(A, var, var->initializer);
/* emit GPU instructions */
- success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE, A->log);
+ success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_FALSE, A->log);
_slang_free_ir_tree(n);
}
#endif
/* Emit program instructions */
- success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE, A->log);
+ success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_TRUE, A->log);
_slang_free_ir_tree(n);
/* free codegen context */
slang_atom_pool *atoms;
slang_name_space space;
struct gl_program *program;
+ struct gl_sl_pragmas *pragmas;
slang_var_table *vartable;
slang_info_log *log;
struct slang_label_ *curFuncEndLabel;
slang_function_scope *funs;
slang_struct_scope *structs;
struct gl_program *program;
+ struct gl_sl_pragmas *pragmas;
slang_var_table *vartable;
GLuint default_precision[TYPE_SPECIFIER_COUNT];
GLboolean allow_precision;
A.space.structs = O->structs;
A.space.vars = O->vars;
A.program = O->program;
+ A.pragmas = O->pragmas;
A.vartable = O->vartable;
A.log = C->L;
A.curFuncEndLabel = NULL;
o.structs = &unit->structs;
o.vars = &unit->vars;
o.program = shader ? shader->Program : NULL;
+ o.pragmas = shader ? &shader->Pragmas : NULL;
o.vartable = _slang_new_var_table(maxRegs);
_slang_push_var_table(o.vartable);
A.space.structs = o.structs;
A.space.vars = o.vars;
A.program = o.program;
+ A.pragmas = &shader->Pragmas;
A.vartable = o.vartable;
A.log = C->L;
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin,
struct gl_shader *shader,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
byte *prod;
GLuint size, start, version;
/* Now preprocess the source string. */
slang_string_init(&preprocessed);
if (!_slang_preprocess_directives(&preprocessed, &source[start],
- infolog, extensions)) {
+ infolog, extensions, pragmas)) {
slang_string_free(&preprocessed);
slang_info_log_error(infolog, "failed to preprocess the source.");
return GL_FALSE;
compile_object(grammar * id, const char *source, slang_code_object * object,
slang_unit_type type, slang_info_log * infolog,
struct gl_shader *shader,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
slang_code_unit *builtins = NULL;
GLuint base_version = 110;
/* compile the actual shader - pass-in built-in library for external shader */
return compile_with_grammar(*id, source, &object->unit, type, infolog,
- builtins, shader, extensions);
+ builtins, shader, extensions, pragmas);
}
_slang_code_object_ctr(object);
success = compile_object(&id, shader->Source, object, type, infolog, shader,
- &ctx->Extensions);
+ &ctx->Extensions, &shader->Pragmas);
if (id != 0)
grammar_destroy(id);
if (!success)
-
+/**
+ * Convert the IR tree into GPU instructions.
+ * \param n root of IR tree
+ * \param vt variable table
+ * \param prog program to put GPU instructions into
+ * \param pragmas controls codegen options
+ * \param withEnd if true, emit END opcode at end
+ * \param log log for emitting errors/warnings/info
+ */
GLboolean
_slang_emit_code(slang_ir_node *n, slang_var_table *vt,
- struct gl_program *prog, GLboolean withEnd,
+ struct gl_program *prog,
+ const struct gl_sl_pragmas *pragmas,
+ GLboolean withEnd,
slang_info_log *log)
{
GET_CURRENT_CONTEXT(ctx);
emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions;
emitInfo.EmitCondCodes = ctx->Shader.EmitCondCodes;
- emitInfo.EmitComments = ctx->Shader.EmitComments;
+ emitInfo.EmitComments = ctx->Shader.EmitComments || pragmas->Debug;
emitInfo.EmitBeginEndSub = GL_TRUE;
if (!emitInfo.EmitCondCodes) {
extern GLboolean
_slang_emit_code(slang_ir_node *n, slang_var_table *vartable,
- struct gl_program *prog, GLboolean withEnd,
+ struct gl_program *prog,
+ const struct gl_sl_pragmas *pragmas,
+ GLboolean withEnd,
slang_info_log *log);
}
+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").
- * At this time, pragmas are silently ignored.
+ * \return GL_TRUE if pragma is valid, GL_FALSE if invalid
*/
-static void
-pp_pragma(const char *pragma, const char *param)
+static GLboolean
+pp_pragma(struct gl_sl_pragmas *pragmas, const char *pragma, const char *param)
{
#if 0
printf("#pragma %s %s\n", pragma, param);
#endif
+ if (_mesa_strcmp(pragma, "optimize") == 0) {
+ if (!param)
+ return GL_FALSE; /* missing required param */
+ if (_mesa_strcmp(param, "on") == 0) {
+ pragmas->Optimize = GL_TRUE;
+ }
+ else if (_mesa_strcmp(param, "off") == 0) {
+ pragmas->Optimize = GL_FALSE;
+ }
+ else {
+ return GL_FALSE; /* invalid param */
+ }
+ }
+ else if (_mesa_strcmp(pragma, "debug") == 0) {
+ if (!param)
+ return GL_FALSE; /* missing required param */
+ if (_mesa_strcmp(param, "on") == 0) {
+ pragmas->Debug = GL_TRUE;
+ }
+ else if (_mesa_strcmp(param, "off") == 0) {
+ pragmas->Debug = GL_FALSE;
+ }
+ else {
+ return GL_FALSE; /* invalid param */
+ }
+ }
+ /* all other pragmas are silently ignored */
+ return GL_TRUE;
}
preprocess_source (slang_string *output, const char *source,
grammar pid, grammar eid,
slang_info_log *elog,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
static const char *predefined[] = {
"__FILE__",
}
pp_state_init (&state, elog, extensions);
+ pp_pragmas_init (pragmas);
/* add the predefined symbols to the symbol table */
for (i = 0; predefined[i]; i++) {
else {
param = NULL;
}
- pp_pragma(pragma, param);
+ pp_pragma(pragmas, pragma, param);
}
break;
_slang_preprocess_directives(slang_string *output,
const char *input,
slang_info_log *elog,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
grammar pid, eid;
GLboolean success;
grammar_destroy (pid);
return GL_FALSE;
}
- success = preprocess_source (output, input, pid, eid, elog, extensions);
+ success = preprocess_source (output, input, pid, eid, elog, extensions, pragmas);
grammar_destroy (eid);
grammar_destroy (pid);
return success;
/*
* Mesa 3-D graphics library
- * Version: 6.5.3
*
- * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
extern GLboolean
_slang_preprocess_directives(slang_string *output, const char *input,
slang_info_log *,
- const struct gl_extensions *extensions);
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas);
#endif /* SLANG_PREPROCESS_H */