mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 13:28:06 +02:00
glsl: Add pragma to disable all warnings
Use #pragma warning(off) and #pragma warning(on) to disable or enable all warnings. This is a big hammer. If we ever need a smaller hammer, we can enhance this functionality. There is one lame thing about this. Because we parse everything, create an AST, then convert the AST to GLSL IR, we have to treat the #pragma like a statment. This means that you can't do something like ' void ' #pragma warning(off) ' __foo ' #pragma warning(on) ' (float param0); Fixing that would, as far as I can tell, require a huge amount of work. I did try just handling the #pragma during parsing (like we do for state for the whole shader. v2: Fix the #pragma lines in the commit message that git-commit ate. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
011abfc963
commit
c5a4c26450
8 changed files with 89 additions and 10 deletions
|
|
@ -1315,6 +1315,20 @@ private:
|
|||
ast_layout_expression *local_size[3];
|
||||
};
|
||||
|
||||
class ast_warnings_toggle : public ast_node {
|
||||
public:
|
||||
ast_warnings_toggle(bool _enable)
|
||||
: enable(_enable)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
virtual ir_rvalue *hir(exec_list *instructions,
|
||||
struct _mesa_glsl_parse_state *state);
|
||||
|
||||
private:
|
||||
bool enable;
|
||||
};
|
||||
/*@}*/
|
||||
|
||||
extern void
|
||||
|
|
|
|||
|
|
@ -8766,3 +8766,11 @@ remove_per_vertex_blocks(exec_list *instructions,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
ir_rvalue *
|
||||
ast_warnings_toggle::hir(exec_list *,
|
||||
struct _mesa_glsl_parse_state *state)
|
||||
{
|
||||
state->warnings_enabled = enable;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,6 +295,14 @@ HASH ^{SPC}#{SPC}
|
|||
BEGIN PP;
|
||||
return PRAGMA_OPTIMIZE_OFF;
|
||||
}
|
||||
^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}on{SPC}\) {
|
||||
BEGIN PP;
|
||||
return PRAGMA_WARNING_ON;
|
||||
}
|
||||
^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}off{SPC}\) {
|
||||
BEGIN PP;
|
||||
return PRAGMA_WARNING_OFF;
|
||||
}
|
||||
^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
|
||||
BEGIN PP;
|
||||
return PRAGMA_INVARIANT_ALL;
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
|
|||
%token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
|
||||
%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
|
||||
%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
|
||||
%token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF
|
||||
%token PRAGMA_INVARIANT_ALL
|
||||
%token LAYOUT_TOK
|
||||
%token DOT_TOK
|
||||
|
|
@ -246,6 +247,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
|
|||
%type <n> unary_operator
|
||||
%type <expression> function_identifier
|
||||
%type <node> external_declaration
|
||||
%type <node> pragma_statement
|
||||
%type <declarator_list> init_declarator_list
|
||||
%type <declarator_list> single_declaration
|
||||
%type <expression> initializer
|
||||
|
|
@ -328,10 +330,10 @@ version_statement:
|
|||
;
|
||||
|
||||
pragma_statement:
|
||||
PRAGMA_DEBUG_ON EOL
|
||||
| PRAGMA_DEBUG_OFF EOL
|
||||
| PRAGMA_OPTIMIZE_ON EOL
|
||||
| PRAGMA_OPTIMIZE_OFF EOL
|
||||
PRAGMA_DEBUG_ON EOL { $$ = NULL; }
|
||||
| PRAGMA_DEBUG_OFF EOL { $$ = NULL; }
|
||||
| PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; }
|
||||
| PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; }
|
||||
| PRAGMA_INVARIANT_ALL EOL
|
||||
{
|
||||
/* Pragma invariant(all) cannot be used in a fragment shader.
|
||||
|
|
@ -353,6 +355,18 @@ pragma_statement:
|
|||
} else {
|
||||
state->all_invariant = true;
|
||||
}
|
||||
|
||||
$$ = NULL;
|
||||
}
|
||||
| PRAGMA_WARNING_ON EOL
|
||||
{
|
||||
void *mem_ctx = state->linalloc;
|
||||
$$ = new(mem_ctx) ast_warnings_toggle(true);
|
||||
}
|
||||
| PRAGMA_WARNING_OFF EOL
|
||||
{
|
||||
void *mem_ctx = state->linalloc;
|
||||
$$ = new(mem_ctx) ast_warnings_toggle(false);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
@ -2723,7 +2737,7 @@ jump_statement:
|
|||
external_declaration:
|
||||
function_definition { $$ = $1; }
|
||||
| declaration { $$ = $1; }
|
||||
| pragma_statement { $$ = NULL; }
|
||||
| pragma_statement { $$ = $1; }
|
||||
| layout_defaults { $$ = $1; }
|
||||
| ';' { $$ = NULL; }
|
||||
;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
|
|||
gl_shader_stage stage,
|
||||
void *mem_ctx)
|
||||
: ctx(_ctx), cs_input_local_size_specified(false), cs_input_local_size(),
|
||||
switch_state()
|
||||
switch_state(), warnings_enabled(true)
|
||||
{
|
||||
assert(stage < MESA_SHADER_STAGES);
|
||||
this->stage = stage;
|
||||
|
|
@ -527,11 +527,13 @@ void
|
|||
_mesa_glsl_warning(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
if (state->warnings_enabled) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
_mesa_glsl_msg(locp, state, MESA_DEBUG_TYPE_OTHER, fmt, ap);
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
_mesa_glsl_msg(locp, state, MESA_DEBUG_TYPE_OTHER, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -614,6 +614,13 @@ struct _mesa_glsl_parse_state {
|
|||
|
||||
char *info_log;
|
||||
|
||||
/**
|
||||
* Are warnings enabled?
|
||||
*
|
||||
* Emission of warngins is controlled by '#pragma warning(...)'.
|
||||
*/
|
||||
bool warnings_enabled;
|
||||
|
||||
/**
|
||||
* \name Enable bits for GLSL extensions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#version 130
|
||||
|
||||
float __foo(float x)
|
||||
{
|
||||
return 6.0 * x;
|
||||
}
|
||||
|
||||
#pragma warning(off)
|
||||
float __bar(float x)
|
||||
{
|
||||
return 3.0 * x;
|
||||
}
|
||||
#pragma warning(on)
|
||||
|
||||
float __blat(float x)
|
||||
{
|
||||
return 2.0 * x;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(__foo(gl_Vertex.x), __bar(gl_Vertex.y), __blat(gl_Vertex.z), 1.0);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
0:3(7): warning: identifier `__foo' uses reserved `__' string
|
||||
0:15(7): warning: identifier `__blat' uses reserved `__' string
|
||||
Loading…
Add table
Reference in a new issue