From e483cb9a3add01dc552bd2a42763aff4be5808fc Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Sun, 12 Jun 2016 18:56:43 -0400 Subject: glsl: reuse main extension table to appropriately restrict extensions Previously we were only restricting based on ES/non-ES-ness and whether the overall enable bit had been flipped on. However we have been adding more fine-grained restrictions, such as based on compat profiles, as well as specific ES versions. Most of the time this doesn't matter, but it can create awkward situations and duplication of logic. Here we separate the main extension table into a separate object file, linked to the glsl compiler, which makes use of it with a custom function which takes the ES-ness of the shader into account (thus allowing desktop shaders to properly use ES extensions that would otherwise have been disallowed.) We can also now use this logic to generate #define's for all supported extensions automatically, removing the duplicate (and often inaccurate) list in glcpp. The effect of this change should be nil in most cases. However in some situations, extensions like GL_ARB_gpu_shader5 which were formerly available in compat contexts on the GLSL side of things will now become inaccessible. This regresses two ES CTS tests: ES3-CTS.shaders.shader_integer_mix.define ES31-CTS.shader_integer_mix.define however that is due to them using #version 100 instead of 300 es. As the extension is only defined for ES3, I believe this is the correct behavior. Signed-off-by: Ilia Mirkin Reviewed-by: Eric Engestrom (v2) v2 -> v3: integrate glcpp defines into the same mechanism --- src/compiler/glsl/glcpp/glcpp-parse.y | 204 ++-------------------------------- src/compiler/glsl/glcpp/glcpp.c | 2 +- src/compiler/glsl/glcpp/glcpp.h | 19 +++- src/compiler/glsl/glcpp/pp.c | 6 +- 4 files changed, 28 insertions(+), 203 deletions(-) (limited to 'src/compiler/glsl/glcpp') diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index a1597611144..ca376d983ff 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -1311,7 +1311,7 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value) } glcpp_parser_t * -glcpp_parser_create(const struct gl_extensions *extensions, gl_api api) +glcpp_parser_create(glcpp_extension_iterator extensions, void *state, gl_api api) { glcpp_parser_t *parser; @@ -1344,6 +1344,7 @@ glcpp_parser_create(const struct gl_extensions *extensions, gl_api api) parser->error = 0; parser->extensions = extensions; + parser->state = state; parser->api = api; parser->version_resolved = false; @@ -2279,8 +2280,6 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio const char *es_identifier, bool explicitly_set) { - const struct gl_extensions *extensions = parser->extensions; - if (parser->version_resolved) return; @@ -2292,199 +2291,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio (es_identifier && (strcmp(es_identifier, "es") == 0)); /* Add pre-defined macros. */ - if (parser->is_gles) { + if (parser->is_gles) add_builtin_define(parser, "GL_ES", 1); - add_builtin_define(parser, "GL_EXT_separate_shader_objects", 1); - add_builtin_define(parser, "GL_EXT_draw_buffers", 1); - - if (extensions != NULL) { - if (extensions->OES_EGL_image_external) - add_builtin_define(parser, "GL_OES_EGL_image_external", 1); - if (extensions->OES_sample_variables) { - add_builtin_define(parser, "GL_OES_sample_variables", 1); - add_builtin_define(parser, "GL_OES_shader_multisample_interpolation", 1); - } - if (extensions->OES_standard_derivatives) - add_builtin_define(parser, "GL_OES_standard_derivatives", 1); - if (extensions->ARB_texture_multisample) - add_builtin_define(parser, "GL_OES_texture_storage_multisample_2d_array", 1); - if (extensions->ARB_blend_func_extended) - add_builtin_define(parser, "GL_EXT_blend_func_extended", 1); - if (extensions->ARB_cull_distance) - add_builtin_define(parser, "GL_EXT_clip_cull_distance", 1); - - if (version >= 310) { - if (extensions->ARB_shader_image_load_store) - add_builtin_define(parser, "GL_OES_shader_image_atomic", 1); - - if (extensions->OES_geometry_shader) { - add_builtin_define(parser, "GL_OES_geometry_point_size", 1); - add_builtin_define(parser, "GL_OES_geometry_shader", 1); - } - if (extensions->ARB_gpu_shader5) { - add_builtin_define(parser, "GL_EXT_gpu_shader5", 1); - add_builtin_define(parser, "GL_OES_gpu_shader5", 1); - } - if (extensions->OES_texture_buffer) { - add_builtin_define(parser, "GL_EXT_texture_buffer", 1); - add_builtin_define(parser, "GL_OES_texture_buffer", 1); - } - - if (extensions->OES_shader_io_blocks) { - add_builtin_define(parser, "GL_EXT_shader_io_blocks", 1); - add_builtin_define(parser, "GL_OES_shader_io_blocks", 1); - } - } - } - } else { - add_builtin_define(parser, "GL_ARB_draw_buffers", 1); - add_builtin_define(parser, "GL_ARB_enhanced_layouts", 1); - add_builtin_define(parser, "GL_ARB_separate_shader_objects", 1); - add_builtin_define(parser, "GL_ARB_texture_rectangle", 1); - add_builtin_define(parser, "GL_AMD_shader_trinary_minmax", 1); - - if (extensions != NULL) { - if (extensions->EXT_texture_array) - add_builtin_define(parser, "GL_EXT_texture_array", 1); - - if (extensions->ARB_ES3_1_compatibility) - add_builtin_define(parser, "GL_ARB_ES3_1_compatibility", 1); - - if (extensions->ARB_arrays_of_arrays) - add_builtin_define(parser, "GL_ARB_arrays_of_arrays", 1); - - if (extensions->ARB_fragment_coord_conventions) { - add_builtin_define(parser, "GL_ARB_fragment_coord_conventions", - 1); - } - - if (extensions->ARB_fragment_layer_viewport) - add_builtin_define(parser, "GL_ARB_fragment_layer_viewport", 1); - - if (extensions->ARB_explicit_attrib_location) - add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1); - - if (extensions->ARB_explicit_uniform_location) - add_builtin_define(parser, "GL_ARB_explicit_uniform_location", 1); - - if (extensions->ARB_shader_texture_lod) - add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1); - - if (extensions->ARB_draw_instanced) - add_builtin_define(parser, "GL_ARB_draw_instanced", 1); - - if (extensions->ARB_conservative_depth) { - add_builtin_define(parser, "GL_AMD_conservative_depth", 1); - add_builtin_define(parser, "GL_ARB_conservative_depth", 1); - } - - if (extensions->ARB_shader_bit_encoding) - add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1); - - if (extensions->ARB_shader_clock) - add_builtin_define(parser, "GL_ARB_shader_clock", 1); - - if (extensions->ARB_uniform_buffer_object) - add_builtin_define(parser, "GL_ARB_uniform_buffer_object", 1); - - if (extensions->ARB_texture_cube_map_array) - add_builtin_define(parser, "GL_ARB_texture_cube_map_array", 1); - - if (extensions->ARB_shading_language_packing) - add_builtin_define(parser, "GL_ARB_shading_language_packing", 1); - - if (extensions->ARB_texture_multisample) - add_builtin_define(parser, "GL_ARB_texture_multisample", 1); - - if (extensions->ARB_texture_query_levels) - add_builtin_define(parser, "GL_ARB_texture_query_levels", 1); - - if (extensions->ARB_texture_query_lod) - add_builtin_define(parser, "GL_ARB_texture_query_lod", 1); - - if (extensions->ARB_gpu_shader5) - add_builtin_define(parser, "GL_ARB_gpu_shader5", 1); - - if (extensions->ARB_gpu_shader_fp64) - add_builtin_define(parser, "GL_ARB_gpu_shader_fp64", 1); - - if (extensions->ARB_vertex_attrib_64bit) - add_builtin_define(parser, "GL_ARB_vertex_attrib_64bit", 1); - - if (extensions->AMD_vertex_shader_layer) - add_builtin_define(parser, "GL_AMD_vertex_shader_layer", 1); - - if (extensions->AMD_vertex_shader_viewport_index) - add_builtin_define(parser, "GL_AMD_vertex_shader_viewport_index", 1); - - if (extensions->ARB_shading_language_420pack) - add_builtin_define(parser, "GL_ARB_shading_language_420pack", 1); - - if (extensions->ARB_sample_shading) - add_builtin_define(parser, "GL_ARB_sample_shading", 1); - - if (extensions->ARB_texture_gather) - add_builtin_define(parser, "GL_ARB_texture_gather", 1); - - if (extensions->ARB_shader_atomic_counters) - add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1); - - if (extensions->ARB_shader_atomic_counter_ops) - add_builtin_define(parser, "GL_ARB_shader_atomic_counter_ops", 1); - - if (extensions->ARB_viewport_array) - add_builtin_define(parser, "GL_ARB_viewport_array", 1); - - if (extensions->ARB_compute_shader) - add_builtin_define(parser, "GL_ARB_compute_shader", 1); - - if (extensions->ARB_shader_image_load_store) - add_builtin_define(parser, "GL_ARB_shader_image_load_store", 1); - - if (extensions->ARB_shader_image_size) - add_builtin_define(parser, "GL_ARB_shader_image_size", 1); - - if (extensions->ARB_shader_texture_image_samples) - add_builtin_define(parser, "GL_ARB_shader_texture_image_samples", 1); - - if (extensions->ARB_derivative_control) - add_builtin_define(parser, "GL_ARB_derivative_control", 1); - - if (extensions->ARB_shader_precision) - add_builtin_define(parser, "GL_ARB_shader_precision", 1); - - if (extensions->ARB_shader_storage_buffer_object) - add_builtin_define(parser, "GL_ARB_shader_storage_buffer_object", 1); - - if (extensions->ARB_tessellation_shader) - add_builtin_define(parser, "GL_ARB_tessellation_shader", 1); - - if (extensions->ARB_shader_subroutine) - add_builtin_define(parser, "GL_ARB_shader_subroutine", 1); - - if (extensions->ARB_shader_draw_parameters) - add_builtin_define(parser, "GL_ARB_shader_draw_parameters", 1); - - if (extensions->ARB_cull_distance) - add_builtin_define(parser, "GL_ARB_cull_distance", 1); - - if (extensions->ARB_shader_group_vote) - add_builtin_define(parser, "GL_ARB_shader_group_vote", 1); - } - } - - if (extensions != NULL) { - if (extensions->EXT_shader_integer_mix) - add_builtin_define(parser, "GL_EXT_shader_integer_mix", 1); - - if (extensions->EXT_shader_samples_identical) - add_builtin_define(parser, "GL_EXT_shader_samples_identical", 1); - - if (extensions->MESA_shader_integer_functions) - add_builtin_define(parser, "GL_MESA_shader_integer_functions", 1); - } - - if (version >= 150) + else if (version >= 150) add_builtin_define(parser, "GL_core_profile", 1); /* Currently, all ES2/ES3 implementations support highp in the @@ -2495,6 +2304,11 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio if (version >= 130 || parser->is_gles) add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1); + /* Add all the extension macros available in this context */ + if (parser->extensions) + parser->extensions(parser->state, add_builtin_define, parser, + version, parser->is_gles); + if (explicitly_set) { ralloc_asprintf_rewrite_tail(&parser->output, &parser->output_length, "#version %" PRIiMAX "%s%s", version, diff --git a/src/compiler/glsl/glcpp/glcpp.c b/src/compiler/glsl/glcpp/glcpp.c index c62f4efec9d..f08b14427f4 100644 --- a/src/compiler/glsl/glcpp/glcpp.c +++ b/src/compiler/glsl/glcpp/glcpp.c @@ -171,7 +171,7 @@ main (int argc, char *argv[]) _mesa_locale_init(); - ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, &gl_ctx); + ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, NULL, &gl_ctx); printf("%s", shader); fprintf(stderr, "%s", info_log); diff --git a/src/compiler/glsl/glcpp/glcpp.h b/src/compiler/glsl/glcpp/glcpp.h index d87e6b77dc5..07eaf684bee 100644 --- a/src/compiler/glsl/glcpp/glcpp.h +++ b/src/compiler/glsl/glcpp/glcpp.h @@ -171,6 +171,15 @@ typedef struct active_list { struct active_list *next; } active_list_t; +struct _mesa_glsl_parse_state; + +typedef void (*glcpp_extension_iterator)( + struct _mesa_glsl_parse_state *state, + void (*add_builtin_define)(glcpp_parser_t *, const char *, int), + glcpp_parser_t *data, + unsigned version, + bool es); + struct glcpp_parser { yyscan_t scanner; struct hash_table *defines; @@ -194,7 +203,8 @@ struct glcpp_parser { size_t output_length; size_t info_log_length; int error; - const struct gl_extensions *extensions; + glcpp_extension_iterator extensions; + void *state; gl_api api; bool version_resolved; bool has_new_line_number; @@ -204,10 +214,8 @@ struct glcpp_parser { bool is_gles; }; -struct gl_extensions; - glcpp_parser_t * -glcpp_parser_create (const struct gl_extensions *extensions, gl_api api); +glcpp_parser_create (glcpp_extension_iterator extensions, void *state, gl_api api); int glcpp_parser_parse (glcpp_parser_t *parser); @@ -220,7 +228,8 @@ glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser); int glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log, - const struct gl_extensions *extensions, struct gl_context *g_ctx); + glcpp_extension_iterator extensions, void *state, + struct gl_context *g_ctx); /* Functions for writing to the info log */ diff --git a/src/compiler/glsl/glcpp/pp.c b/src/compiler/glsl/glcpp/pp.c index 160c6662ff6..b5912799371 100644 --- a/src/compiler/glsl/glcpp/pp.c +++ b/src/compiler/glsl/glcpp/pp.c @@ -213,10 +213,12 @@ remove_line_continuations(glcpp_parser_t *ctx, const char *shader) int glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log, - const struct gl_extensions *extensions, struct gl_context *gl_ctx) + glcpp_extension_iterator extensions, void *state, + struct gl_context *gl_ctx) { int errors; - glcpp_parser_t *parser = glcpp_parser_create (extensions, gl_ctx->API); + glcpp_parser_t *parser = + glcpp_parser_create(extensions, state, gl_ctx->API); if (! gl_ctx->Const.DisableGLSLLineContinuations) *shader = remove_line_continuations(parser, *shader); -- cgit v1.2.3