diff options
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/apps/compile.c | 1 | ||||
-rw-r--r-- | src/glsl/apps/process.c | 2 | ||||
-rw-r--r-- | src/glsl/apps/purify.c | 3 | ||||
-rw-r--r-- | src/glsl/apps/tokenise.c | 2 | ||||
-rw-r--r-- | src/glsl/apps/version.c | 2 | ||||
-rw-r--r-- | src/glsl/cl/sl_cl_parse.c | 120 | ||||
-rw-r--r-- | src/glsl/pp/sl_pp_context.h | 1 | ||||
-rw-r--r-- | src/glsl/pp/sl_pp_extension.c | 25 | ||||
-rw-r--r-- | src/glsl/pp/sl_pp_if.c | 2 |
9 files changed, 125 insertions, 33 deletions
diff --git a/src/glsl/apps/compile.c b/src/glsl/apps/compile.c index 3b3c083c2e..21c2b7617e 100644 --- a/src/glsl/apps/compile.c +++ b/src/glsl/apps/compile.c @@ -79,6 +79,7 @@ main(int argc, fseek(in, 0, SEEK_END); size = ftell(in); + assert(size != -1); fseek(in, 0, SEEK_SET); out = fopen(argv[3], "w"); diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 2d2ab911ac..c8a1a1868c 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -47,6 +47,7 @@ main(int argc, unsigned int i; if (argc != 3) { + printf("Usage: process infile outfile\n"); return 1; } @@ -57,6 +58,7 @@ main(int argc, fseek(in, 0, SEEK_END); size = ftell(in); + assert(size != -1); fseek(in, 0, SEEK_SET); out = fopen(argv[2], "wb"); diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c index 8c01f4fc6a..5ab6bae96d 100644 --- a/src/glsl/apps/purify.c +++ b/src/glsl/apps/purify.c @@ -25,6 +25,7 @@ * **************************************************************************/ +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -45,6 +46,7 @@ main(int argc, FILE *out; if (argc != 3) { + printf("Usage: purify infile outfile\n"); return 1; } @@ -55,6 +57,7 @@ main(int argc, fseek(in, 0, SEEK_END); size = ftell(in); + assert(size != -1); fseek(in, 0, SEEK_SET); out = fopen(argv[2], "wb"); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 9ff73157e9..b4c6d60930 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -46,6 +46,7 @@ main(int argc, unsigned int i; if (argc != 3) { + printf("Usage: tokenize infile outfile\n"); return 1; } @@ -56,6 +57,7 @@ main(int argc, fseek(in, 0, SEEK_END); size = ftell(in); + assert(size != -1); fseek(in, 0, SEEK_SET); out = fopen(argv[2], "wb"); diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index 40a4a069c3..9820ad94dc 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -45,6 +45,7 @@ main(int argc, FILE *out; if (argc != 3) { + printf("Usage: version infile outfile\n"); return 1; } @@ -55,6 +56,7 @@ main(int argc, fseek(in, 0, SEEK_END); size = ftell(in); + assert(size != -1); fseek(in, 0, SEEK_SET); out = fopen(argv[2], "wb"); diff --git a/src/glsl/cl/sl_cl_parse.c b/src/glsl/cl/sl_cl_parse.c index 883bc1ffd3..771bdfd082 100644 --- a/src/glsl/cl/sl_cl_parse.c +++ b/src/glsl/cl/sl_cl_parse.c @@ -161,6 +161,12 @@ #define TYPE_SPECIFIER_MAT34 30 #define TYPE_SPECIFIER_MAT43 31 +/* GL_EXT_texture_array */ +#define TYPE_SPECIFIER_SAMPLER_1D_ARRAY 32 +#define TYPE_SPECIFIER_SAMPLER_2D_ARRAY 33 +#define TYPE_SPECIFIER_SAMPLER_1D_ARRAY_SHADOW 34 +#define TYPE_SPECIFIER_SAMPLER_2D_ARRAY_SHADOW 35 + /* type specifier array */ #define TYPE_SPECIFIER_NONARRAY 0 #define TYPE_SPECIFIER_ARRAY 1 @@ -281,6 +287,10 @@ struct parse_dict { int sampler2DShadow; int sampler2DRect; int sampler2DRectShadow; + int sampler1DArray; + int sampler2DArray; + int sampler1DArrayShadow; + int sampler2DArrayShadow; int invariant; @@ -325,6 +335,9 @@ struct parse_dict { int _false; int _true; + + int all; + int _GL_ARB_fragment_coord_conventions; }; @@ -343,6 +356,8 @@ struct parse_context { unsigned int shader_type; unsigned int parsing_builtin; + unsigned int fragment_coord_conventions:1; + char error[256]; int process_error; }; @@ -382,7 +397,8 @@ _error(struct parse_context *ctx, const char *msg) { if (ctx->error[0] == '\0') { - strcpy(ctx->error, msg); + strncpy(ctx->error, msg, sizeof(ctx->error) - 1); + ctx->error[sizeof(ctx->error) - 1] = '\0'; } } @@ -460,6 +476,10 @@ _fetch_token(struct parse_context *ctx, case SL_PP_IDENTIFIER: case SL_PP_UINT: case SL_PP_FLOAT: + case SL_PP_EXTENSION_REQUIRE: + case SL_PP_EXTENSION_ENABLE: + case SL_PP_EXTENSION_WARN: + case SL_PP_EXTENSION_DISABLE: case SL_PP_EOF: ctx->tokens_read++; break; @@ -728,6 +748,20 @@ _parse_layout_qualifier(struct parse_context *ctx, struct parse_state *ps) { if (_parse_id(ctx, ctx->dict.layout, ps) == 0) { + if (!ctx->fragment_coord_conventions) { + _error(ctx, "GL_ARB_fragment_coord_conventions extension must be enabled " + "in order to use a layout qualifier"); + return -1; + } + + /* Layout qualifiers are only defined for fragment shaders, + * so do an early check. + */ + if (ctx->shader_type != 1) { + _error(ctx, "layout qualifiers are only valid for fragment shaders"); + return -1; + } + /* start of a parenthesised list of layout qualifiers */ if (_parse_token(ctx, SL_PP_LPAREN, ps)) { @@ -744,7 +778,7 @@ _parse_layout_qualifier(struct parse_context *ctx, _emit(ctx, &ps->out, LAYOUT_QUALIFIER_PIXEL_CENTER_INTEGER); } else { - _error(ctx, "expected a layout qualifier"); + _error(ctx, "expected a layout qualifier name"); return -1; } @@ -760,10 +794,9 @@ _parse_layout_qualifier(struct parse_context *ctx, return -1; } } - } - return -1; + return 0; } @@ -1005,6 +1038,15 @@ _parse_type_specifier_nonarray(struct parse_context *ctx, _update(ctx, e, TYPE_SPECIFIER_SAMPLER2DRECT); } else if (id == ctx->dict.sampler2DRectShadow) { _update(ctx, e, TYPE_SPECIFIER_SAMPLER2DRECTSHADOW); + } else if (id == ctx->dict.sampler1DArray) { + _update(ctx, e, TYPE_SPECIFIER_SAMPLER_1D_ARRAY); + } else if (id == ctx->dict.sampler2DArray) { + /* XXX check for GL_EXT_texture_array */ + _update(ctx, e, TYPE_SPECIFIER_SAMPLER_2D_ARRAY); + } else if (id == ctx->dict.sampler1DArrayShadow) { + _update(ctx, e, TYPE_SPECIFIER_SAMPLER_1D_ARRAY_SHADOW); + } else if (id == ctx->dict.sampler2DArrayShadow) { + _update(ctx, e, TYPE_SPECIFIER_SAMPLER_2D_ARRAY_SHADOW); } else if (_parse_identifier(ctx, &p) == 0) { _update(ctx, e, TYPE_SPECIFIER_TYPENAME); *ps = p; @@ -1068,8 +1110,9 @@ _parse_fully_specified_type(struct parse_context *ctx, struct parse_state p = *ps; if (_parse_layout_qualifier(ctx, &p)) { - _emit(ctx, &p.out, LAYOUT_QUALIFIER_NONE); + return -1; } + _emit(ctx, &p.out, LAYOUT_QUALIFIER_NONE); if (_parse_invariant_qualifier(ctx, &p)) { _emit(ctx, &p.out, TYPE_VARIANT); @@ -1920,6 +1963,14 @@ _parse_prectype(struct parse_context *ctx, type = TYPE_SPECIFIER_SAMPLER2DRECT; } else if (id == ctx->dict.sampler2DRectShadow) { type = TYPE_SPECIFIER_SAMPLER2DRECTSHADOW; + } else if (id == ctx->dict.sampler1DArray) { + type = TYPE_SPECIFIER_SAMPLER_1D_ARRAY; + } else if (id == ctx->dict.sampler2DArray) { + type = TYPE_SPECIFIER_SAMPLER_2D_ARRAY; + } else if (id == ctx->dict.sampler1DArrayShadow) { + type = TYPE_SPECIFIER_SAMPLER_1D_ARRAY_SHADOW; + } else if (id == ctx->dict.sampler2DArrayShadow) { + type = TYPE_SPECIFIER_SAMPLER_2D_ARRAY_SHADOW; } else { return -1; } @@ -2745,14 +2796,59 @@ _parse_external_declaration(struct parse_context *ctx, static int +_parse_extensions(struct parse_context *ctx, + struct parse_state *ps) +{ + for (;;) { + const struct sl_pp_token_info *input = _fetch_token(ctx, ps->in); + unsigned int enable; + + if (!input) { + return -1; + } + + switch (input->token) { + case SL_PP_EXTENSION_REQUIRE: + case SL_PP_EXTENSION_ENABLE: + case SL_PP_EXTENSION_WARN: + enable = 1; + break; + case SL_PP_EXTENSION_DISABLE: + enable = 0; + break; + default: + return 0; + } + + ps->in++; + if (input->data.extension == ctx->dict.all) { + ctx->fragment_coord_conventions = enable; + } + else if (input->data.extension == ctx->dict._GL_ARB_fragment_coord_conventions) { + ctx->fragment_coord_conventions = enable; + } + } +} + + +static int _parse_translation_unit(struct parse_context *ctx, struct parse_state *ps) { _emit(ctx, &ps->out, REVISION); + if (_parse_extensions(ctx, ps)) { + return -1; + } if (_parse_external_declaration(ctx, ps)) { return -1; } - while (_parse_external_declaration(ctx, ps) == 0) { + for (;;) { + if (_parse_extensions(ctx, ps)) { + return -1; + } + if (_parse_external_declaration(ctx, ps)) { + break; + } } _emit(ctx, &ps->out, EXTERNAL_NULL); if (_parse_token(ctx, SL_PP_EOF, ps)) { @@ -2817,6 +2913,10 @@ sl_cl_compile(struct sl_pp_context *context, ADD_NAME(ctx, sampler2DShadow); ADD_NAME(ctx, sampler2DRect); ADD_NAME(ctx, sampler2DRectShadow); + ADD_NAME(ctx, sampler1DArray); + ADD_NAME(ctx, sampler2DArray); + ADD_NAME(ctx, sampler1DArrayShadow); + ADD_NAME(ctx, sampler2DArrayShadow); ADD_NAME(ctx, invariant); @@ -2862,12 +2962,17 @@ sl_cl_compile(struct sl_pp_context *context, ADD_NAME_STR(ctx, _false, "false"); ADD_NAME_STR(ctx, _true, "true"); + ADD_NAME(ctx, all); + ADD_NAME_STR(ctx, _GL_ARB_fragment_coord_conventions, "GL_ARB_fragment_coord_conventions"); + ctx.out_buf = NULL; ctx.out_cap = 0; ctx.shader_type = shader_type; ctx.parsing_builtin = 1; + ctx.fragment_coord_conventions = 0; + ctx.error[0] = '\0'; ctx.process_error = 0; @@ -2875,7 +2980,8 @@ sl_cl_compile(struct sl_pp_context *context, ctx.tokens_read = 0; ctx.tokens = malloc(ctx.tokens_cap * sizeof(struct sl_pp_token_info)); if (!ctx.tokens) { - strncpy(error, "out of memory", cberror); + strncpy(error, "out of memory", cberror - 1); + error[cberror - 1] = '\0'; return -1; } diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h index b5419bc056..8abb9708b8 100644 --- a/src/glsl/pp/sl_pp_context.h +++ b/src/glsl/pp/sl_pp_context.h @@ -45,7 +45,6 @@ struct sl_pp_extension { int name; /*< GL_VENDOR_extension_name */ - int enabled; }; struct sl_pp_predefined { diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c index 1f00d94eba..d119677c26 100644 --- a/src/glsl/pp/sl_pp_extension.c +++ b/src/glsl/pp/sl_pp_extension.c @@ -53,8 +53,6 @@ sl_pp_context_add_extension(struct sl_pp_context *context, return -1; } - ext.enabled = 0; - context->extensions[context->num_extensions++] = ext; assert(context->num_extensions <= sizeof(context->extensions)); @@ -62,6 +60,7 @@ sl_pp_context_add_extension(struct sl_pp_context *context, return 0; } + /** * Process a "#extension name: behavior" directive. */ @@ -75,7 +74,6 @@ sl_pp_process_extension(struct sl_pp_context *context, int extension_name = -1; int behavior = -1; struct sl_pp_token_info out; - struct sl_pp_extension *extension = NULL; /* Grab the extension name. */ if (first < last && input[first].token == SL_PP_IDENTIFIER) { @@ -97,7 +95,6 @@ sl_pp_process_extension(struct sl_pp_context *context, for (i = 0; i < context->num_extensions; i++) { if (extension_name == context->extensions[i].name) { out.data.extension = extension_name; - extension = &context->extensions[i]; break; } } @@ -137,11 +134,6 @@ sl_pp_process_extension(struct sl_pp_context *context, return -1; } out.token = SL_PP_EXTENSION_REQUIRE; - - if (extension_name != context->dict.all) { - assert(extension); - extension->enabled = 1; - } } else if (behavior == context->dict.enable) { if (out.data.extension == -1) { /* Warning: the extension cannot be enabled. */ @@ -152,33 +144,18 @@ sl_pp_process_extension(struct sl_pp_context *context, return -1; } out.token = SL_PP_EXTENSION_ENABLE; - - if (extension_name != context->dict.all) { - assert(extension); - extension->enabled = 1; - } } else if (behavior == context->dict.warn) { if (out.data.extension == -1) { /* Warning: the extension is not supported. */ return 0; } out.token = SL_PP_EXTENSION_WARN; - - if (extension_name != context->dict.all) { - assert(extension); - extension->enabled = 1; - } } else if (behavior == context->dict.disable) { if (out.data.extension == -1) { /* Warning: the extension is not supported. */ return 0; } out.token = SL_PP_EXTENSION_DISABLE; - - if (extension_name != context->dict.all) { - assert(extension); - extension->enabled = 0; - } } else { strcpy(context->error_msg, "unrecognised behavior name"); return -1; diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index e233999ca8..25cb7a3ca1 100644 --- a/src/glsl/pp/sl_pp_if.c +++ b/src/glsl/pp/sl_pp_if.c @@ -40,7 +40,7 @@ _macro_is_defined(struct sl_pp_context *context, for (i = 0; i < context->num_extensions; i++) { if (macro_name == context->extensions[i].name) { - return context->extensions[i].enabled; + return 1; } } |