diff options
Diffstat (limited to 'src/mesa/shader/slang/slang_compile.c')
-rw-r--r-- | src/mesa/shader/slang/slang_compile.c | 134 |
1 files changed, 131 insertions, 3 deletions
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 29c5ca2f4b2..fd5d4afacb6 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -56,6 +56,9 @@ */ +/** re-defined below, should be the same though */ +#define TYPE_SPECIFIER_COUNT 32 + /** * Allocate storage for a variable of 'size' bytes from given pool. @@ -129,6 +132,7 @@ typedef struct slang_parse_ctx_ GLboolean global_scope; /**< Is object being declared a global? */ slang_atom_pool *atoms; slang_unit_type type; /**< Vertex vs. Fragment */ + GLuint version; /**< user-specified (or default) #version */ } slang_parse_ctx; /* slang_output_ctx */ @@ -141,6 +145,7 @@ typedef struct slang_output_ctx_ slang_var_pool *global_pool; struct gl_program *program; slang_var_table *vartable; + GLuint default_precision[TYPE_SPECIFIER_COUNT]; } slang_output_ctx; /* _slang_compile() */ @@ -525,7 +530,7 @@ parse_type_qualifier(slang_parse_ctx * C, slang_type_qualifier * qual) #define TYPE_SPECIFIER_MAT42 29 #define TYPE_SPECIFIER_MAT34 30 #define TYPE_SPECIFIER_MAT43 31 - +#define TYPE_SPECIFIER_COUNT 32 static int parse_type_specifier(slang_parse_ctx * C, slang_output_ctx * O, @@ -1817,10 +1822,111 @@ parse_declaration(slang_parse_ctx * C, slang_output_ctx * O) return 1; } -/* external declaration */ + +#define PRECISION_LOW 0 +#define PRECISION_MEDIUM 1 +#define PRECISION_HIGH 2 + +static int +parse_default_precision(slang_parse_ctx * C, slang_output_ctx * O) +{ +#if FEATURE_es2_glsl + int precision, type; + + precision = *C->I++; + switch (precision) { + case PRECISION_LOW: + case PRECISION_MEDIUM: + case PRECISION_HIGH: + /* OK */ + break; + default: + _mesa_problem(NULL, "unexpected precision %d at %s:%d\n", + precision, __FILE__, __LINE__); + return 0; + } + + type = *C->I++; + switch (type) { + case TYPE_SPECIFIER_FLOAT: + case TYPE_SPECIFIER_INT: + case TYPE_SPECIFIER_SAMPLER1D: + case TYPE_SPECIFIER_SAMPLER2D: + case TYPE_SPECIFIER_SAMPLER3D: + case TYPE_SPECIFIER_SAMPLERCUBE: + case TYPE_SPECIFIER_SAMPLER1DSHADOW: + case TYPE_SPECIFIER_SAMPLER2DSHADOW: + case TYPE_SPECIFIER_SAMPLER2DRECT: + case TYPE_SPECIFIER_SAMPLER2DRECTSHADOW: + /* OK */ + break; + default: + _mesa_problem(NULL, "unexpected type %d at %s:%d\n", + type, __FILE__, __LINE__); + return 0; + } + + assert(type < TYPE_SPECIFIER_COUNT); + O->default_precision[type] = precision; + + return 1; +#else + slang_info_log_error(C->L, "syntax error at \"precision\""); + return 0; +#endif +} + + +/** + * Initialize the default precision for all types. + * XXX this info isn't used yet. + */ +static void +init_default_precision(slang_output_ctx *O, slang_unit_type type) +{ + GLuint i; + for (i = 0; i < TYPE_SPECIFIER_COUNT; i++) { +#if FEATURE_es2_glsl + O->default_precision[i] = PRECISION_LOW; +#else + O->default_precision[i] = PRECISION_HIGH; +#endif + } +#if FEATURE_es2_glsl + if (type == SLANG_UNIT_VERTEX_SHADER) { + O->default_precision[TYPE_SPECIFIER_FLOAT] = PRECISION_HIGH; + O->default_precision[TYPE_SPECIFIER_INT] = PRECISION_HIGH; + } + else { + O->default_precision[TYPE_SPECIFIER_INT] = PRECISION_MEDIUM; + } +#endif +} + + +static int +parse_invariant(slang_parse_ctx * C, slang_output_ctx * O) +{ + if (C->version >= 120 || FEATURE_es2_glsl) { + slang_atom *a = parse_identifier(C); + /* XXX not doing anything with this var yet */ + /*printf("ID: %s\n", (char*) a);*/ + return a ? 1 : 0; + } + else { + slang_info_log_error(C->L, "syntax error at \"invariant\""); + return 0; + } +} + + +/* external declaration or default precision specifier */ #define EXTERNAL_NULL 0 #define EXTERNAL_FUNCTION_DEFINITION 1 #define EXTERNAL_DECLARATION 2 +#define DEFAULT_PRECISION 3 +#define INVARIANT_STMT 4 + static GLboolean parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, @@ -1843,6 +1949,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, } /* setup output context */ + init_default_precision(&o, unit->type); o.funs = &unit->funs; o.structs = &unit->structs; o.vars = &unit->vars; @@ -1868,6 +1975,12 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, case EXTERNAL_DECLARATION: success = parse_declaration(C, &o); break; + case DEFAULT_PRECISION: + success = parse_default_precision(C, &o); + break; + case INVARIANT_STMT: + success = parse_invariant(C, &o); + break; default: success = GL_FALSE; } @@ -1904,6 +2017,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, static GLboolean compile_binary(const byte * prod, slang_code_unit * unit, + GLuint version, slang_unit_type type, slang_info_log * infolog, slang_code_unit * builtin, slang_code_unit * downlink, struct gl_program *program) @@ -1919,6 +2033,7 @@ compile_binary(const byte * prod, slang_code_unit * unit, C.global_scope = GL_TRUE; C.atoms = &unit->object->atompool; C.type = type; + C.version = version; if (!check_revision(&C)) return GL_FALSE; @@ -1946,6 +2061,8 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, #if FEATURE_ARB_shading_language_120 maxVersion = 120; +#elif FEATURE_es2_glsl + maxVersion = 100; #else maxVersion = 110; #endif @@ -1995,7 +2112,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, slang_string_free(&preprocessed); /* Syntax is okay - translate it to internal representation. */ - if (!compile_binary(prod, unit, type, infolog, builtin, + if (!compile_binary(prod, unit, version, type, infolog, builtin, &builtin[SLANG_BUILTIN_TOTAL - 1], program)) { grammar_alloc_free(prod); @@ -2039,6 +2156,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, struct gl_program *program) { slang_code_unit *builtins = NULL; + GLuint base_version = 110; /* load GLSL grammar */ *id = grammar_load_from_text((const byte *) (slang_shader_syn)); @@ -2066,6 +2184,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, /* compile core functionality first */ if (!compile_binary(slang_core_gc, &object->builtin[SLANG_BUILTIN_CORE], + base_version, SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, NULL, NULL)) return GL_FALSE; @@ -2073,6 +2192,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, #if FEATURE_ARB_shading_language_120 if (!compile_binary(slang_120_core_gc, &object->builtin[SLANG_BUILTIN_120_CORE], + 120, SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_CORE], NULL)) return GL_FALSE; @@ -2081,6 +2201,11 @@ compile_object(grammar * id, const char *source, slang_code_object * object, /* compile common functions and variables, link to core */ if (!compile_binary(slang_common_builtin_gc, &object->builtin[SLANG_BUILTIN_COMMON], +#if FEATURE_ARB_shading_language_120 + 120, +#else + base_version, +#endif SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, #if FEATURE_ARB_shading_language_120 &object->builtin[SLANG_BUILTIN_120_CORE], @@ -2094,12 +2219,14 @@ compile_object(grammar * id, const char *source, slang_code_object * object, if (type == SLANG_UNIT_FRAGMENT_SHADER) { if (!compile_binary(slang_fragment_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET], + base_version, SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_COMMON], NULL)) return GL_FALSE; #if FEATURE_ARB_shading_language_120 if (!compile_binary(slang_120_fragment_gc, &object->builtin[SLANG_BUILTIN_TARGET], + 120, SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_COMMON], NULL)) return GL_FALSE; @@ -2108,6 +2235,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, else if (type == SLANG_UNIT_VERTEX_SHADER) { if (!compile_binary(slang_vertex_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET], + base_version, SLANG_UNIT_VERTEX_BUILTIN, infolog, NULL, &object->builtin[SLANG_BUILTIN_COMMON], NULL)) return GL_FALSE; |