From 3868b30fc4f25845624535aabb68aa02b3d30bf5 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 7 Jan 2022 13:05:09 +1000 Subject: [PATCH] glsl/parser: extract consts/exts/api out of context at start. This stores these pointers separately. in theory now gl_context can be made more opaque later, if we split header files ups. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/compiler/glsl/ast_function.cpp | 2 +- src/compiler/glsl/ast_to_hir.cpp | 42 ++++++++++++++-------------- src/compiler/glsl/builtin_functions.cpp | 28 +++++++++---------- src/compiler/glsl/builtin_types.cpp | 12 ++++---- src/compiler/glsl/builtin_variables.cpp | 24 ++++++++-------- src/compiler/glsl/glsl_lexer.ll | 42 ++++++++++++++-------------- src/compiler/glsl/glsl_parser_extras.cpp | 47 ++++++++++++++++---------------- src/compiler/glsl/glsl_parser_extras.h | 5 +++- 8 files changed, 103 insertions(+), 99 deletions(-) diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp index 92ca6a4..e831190 100644 --- a/src/compiler/glsl/ast_function.cpp +++ b/src/compiler/glsl/ast_function.cpp @@ -631,7 +631,7 @@ generate_call(exec_list *instructions, ir_function_signature *sig, * instructions; just generate an ir_constant. */ if (state->is_version(120, 100) || - state->ctx->Const.AllowGLSLBuiltinConstantExpression) { + state->consts->AllowGLSLBuiltinConstantExpression) { ir_constant *value = sig->constant_expression_value(ctx, actual_parameters, NULL); diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index c929ba5..d5ebd78 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -2917,11 +2917,11 @@ static bool validate_stream_qualifier(YYLTYPE *loc, struct _mesa_glsl_parse_state *state, unsigned stream) { - if (stream >= state->ctx->Const.MaxVertexStreams) { + if (stream >= state->consts->MaxVertexStreams) { _mesa_glsl_error(loc, state, "invalid stream specified %d is larger than " "MAX_VERTEX_STREAMS - 1 (%d).", - stream, state->ctx->Const.MaxVertexStreams - 1); + stream, state->consts->MaxVertexStreams - 1); return false; } @@ -2948,7 +2948,7 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state, return; } - const struct gl_context *const ctx = state->ctx; + const struct gl_constants *consts = state->consts; unsigned elements = type->is_array() ? type->arrays_of_arrays_size() : 1; unsigned max_index = qual_binding + elements - 1; const glsl_type *base_type = type->without_array(); @@ -2965,11 +2965,11 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state, * The implementation-dependent maximum is GL_MAX_UNIFORM_BUFFER_BINDINGS. */ if (qual->flags.q.uniform && - max_index >= ctx->Const.MaxUniformBufferBindings) { + max_index >= consts->MaxUniformBufferBindings) { _mesa_glsl_error(loc, state, "layout(binding = %u) for %d UBOs exceeds " "the maximum number of UBO binding points (%d)", qual_binding, elements, - ctx->Const.MaxUniformBufferBindings); + consts->MaxUniformBufferBindings); return; } @@ -2983,11 +2983,11 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state, * be within this range." */ if (qual->flags.q.buffer && - max_index >= ctx->Const.MaxShaderStorageBufferBindings) { + max_index >= consts->MaxShaderStorageBufferBindings) { _mesa_glsl_error(loc, state, "layout(binding = %u) for %d SSBOs exceeds " "the maximum number of SSBO binding points (%d)", qual_binding, elements, - ctx->Const.MaxShaderStorageBufferBindings); + consts->MaxShaderStorageBufferBindings); return; } } else if (base_type->is_sampler()) { @@ -2998,7 +2998,7 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state, * with an array of size N, all elements of the array from binding * through binding + N - 1 must be within this range." */ - unsigned limit = ctx->Const.MaxCombinedTextureImageUnits; + unsigned limit = consts->MaxCombinedTextureImageUnits; if (max_index >= limit) { _mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers " @@ -3008,23 +3008,23 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state, return; } } else if (base_type->contains_atomic()) { - assert(ctx->Const.MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS); - if (qual_binding >= ctx->Const.MaxAtomicBufferBindings) { + assert(consts->MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS); + if (qual_binding >= consts->MaxAtomicBufferBindings) { _mesa_glsl_error(loc, state, "layout(binding = %d) exceeds the " "maximum number of atomic counter buffer bindings " "(%u)", qual_binding, - ctx->Const.MaxAtomicBufferBindings); + consts->MaxAtomicBufferBindings); return; } } else if ((state->is_version(420, 310) || state->ARB_shading_language_420pack_enable) && base_type->is_image()) { - assert(ctx->Const.MaxImageUnits <= MAX_IMAGE_UNITS); - if (max_index >= ctx->Const.MaxImageUnits) { + assert(consts->MaxImageUnits <= MAX_IMAGE_UNITS); + if (max_index >= consts->MaxImageUnits) { _mesa_glsl_error(loc, state, "Image binding %d exceeds the " "maximum number of image units (%d)", max_index, - ctx->Const.MaxImageUnits); + consts->MaxImageUnits); return; } @@ -3268,13 +3268,13 @@ apply_explicit_location(const struct ast_type_qualifier *qual, if (!state->check_explicit_uniform_location_allowed(loc, var)) return; - const struct gl_context *const ctx = state->ctx; + const struct gl_constants *consts = state->consts; unsigned max_loc = qual_location + var->type->uniform_locations() - 1; - if (max_loc >= ctx->Const.MaxUserAssignableUniformLocations) { + if (max_loc >= consts->MaxUserAssignableUniformLocations) { _mesa_glsl_error(loc, state, "location(s) consumed by uniform %s " ">= MAX_UNIFORM_LOCATIONS (%u)", var->name, - ctx->Const.MaxUserAssignableUniformLocations); + consts->MaxUserAssignableUniformLocations); return; } @@ -8808,20 +8808,20 @@ ast_cs_input_layout::hir(exec_list *instructions, } ralloc_free(local_size_str); - if (qual_local_size[i] > state->ctx->Const.MaxComputeWorkGroupSize[i]) { + if (qual_local_size[i] > state->consts->MaxComputeWorkGroupSize[i]) { _mesa_glsl_error(&loc, state, "local_size_%c exceeds MAX_COMPUTE_WORK_GROUP_SIZE" " (%d)", 'x' + i, - state->ctx->Const.MaxComputeWorkGroupSize[i]); + state->consts->MaxComputeWorkGroupSize[i]); break; } total_invocations *= qual_local_size[i]; if (total_invocations > - state->ctx->Const.MaxComputeWorkGroupInvocations) { + state->consts->MaxComputeWorkGroupInvocations) { _mesa_glsl_error(&loc, state, "product of local_sizes exceeds " "MAX_COMPUTE_WORK_GROUP_INVOCATIONS (%d)", - state->ctx->Const.MaxComputeWorkGroupInvocations); + state->consts->MaxComputeWorkGroupInvocations); break; } } diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index 6c8fc1e..4b5c326 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -312,49 +312,49 @@ static bool gpu_shader4_integer(const _mesa_glsl_parse_state *state) { return state->EXT_gpu_shader4_enable && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool gpu_shader4_array(const _mesa_glsl_parse_state *state) { return state->EXT_gpu_shader4_enable && - state->ctx->Extensions.EXT_texture_array; + state->exts->EXT_texture_array; } static bool gpu_shader4_array_integer(const _mesa_glsl_parse_state *state) { return gpu_shader4_array(state) && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool gpu_shader4_rect(const _mesa_glsl_parse_state *state) { return state->EXT_gpu_shader4_enable && - state->ctx->Extensions.NV_texture_rectangle; + state->exts->NV_texture_rectangle; } static bool gpu_shader4_rect_integer(const _mesa_glsl_parse_state *state) { return gpu_shader4_rect(state) && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool gpu_shader4_tbo(const _mesa_glsl_parse_state *state) { return state->EXT_gpu_shader4_enable && - state->ctx->Extensions.EXT_texture_buffer_object; + state->exts->EXT_texture_buffer_object; } static bool gpu_shader4_tbo_integer(const _mesa_glsl_parse_state *state) { return gpu_shader4_tbo(state) && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool @@ -368,21 +368,21 @@ static bool gpu_shader4_integer_derivs_only(const _mesa_glsl_parse_state *state) { return gpu_shader4_derivs_only(state) && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool gpu_shader4_array_derivs_only(const _mesa_glsl_parse_state *state) { return gpu_shader4_derivs_only(state) && - state->ctx->Extensions.EXT_texture_array; + state->exts->EXT_texture_array; } static bool gpu_shader4_array_integer_derivs_only(const _mesa_glsl_parse_state *state) { return gpu_shader4_array_derivs_only(state) && - state->ctx->Extensions.EXT_texture_integer; + state->exts->EXT_texture_integer; } static bool @@ -465,7 +465,7 @@ texture_array_lod(const _mesa_glsl_parse_state *state) return lod_exists_in_stage(state) && (state->EXT_texture_array_enable || (state->EXT_gpu_shader4_enable && - state->ctx->Extensions.EXT_texture_array)); + state->exts->EXT_texture_array)); } static bool @@ -473,7 +473,7 @@ texture_array(const _mesa_glsl_parse_state *state) { return state->EXT_texture_array_enable || (state->EXT_gpu_shader4_enable && - state->ctx->Extensions.EXT_texture_array); + state->exts->EXT_texture_array); } static bool @@ -593,7 +593,7 @@ derivatives(const _mesa_glsl_parse_state *state) return derivatives_only(state) && (state->is_version(110, 300) || state->OES_standard_derivatives_enable || - state->ctx->Const.AllowGLSLRelaxedES); + state->consts->AllowGLSLRelaxedES); } static bool @@ -875,7 +875,7 @@ shader_integer_functions2_int64(const _mesa_glsl_parse_state *state) static bool is_nir(const _mesa_glsl_parse_state *state) { - return state->ctx->Const.ShaderCompilerOptions[state->stage].NirOptions; + return state->consts->ShaderCompilerOptions[state->stage].NirOptions; } static bool diff --git a/src/compiler/glsl/builtin_types.cpp b/src/compiler/glsl/builtin_types.cpp index f9588e6..ae5bf16 100644 --- a/src/compiler/glsl/builtin_types.cpp +++ b/src/compiler/glsl/builtin_types.cpp @@ -333,17 +333,17 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state) add_type(symbols, glsl_type::samplerCubeShadow_type); - if (state->ctx->Extensions.EXT_texture_array) { + if (state->exts->EXT_texture_array) { add_type(symbols, glsl_type::sampler1DArray_type); add_type(symbols, glsl_type::sampler2DArray_type); add_type(symbols, glsl_type::sampler1DArrayShadow_type); add_type(symbols, glsl_type::sampler2DArrayShadow_type); } - if (state->ctx->Extensions.EXT_texture_buffer_object) { + if (state->exts->EXT_texture_buffer_object) { add_type(symbols, glsl_type::samplerBuffer_type); } - if (state->ctx->Extensions.EXT_texture_integer) { + if (state->exts->EXT_texture_integer) { add_type(symbols, glsl_type::isampler1D_type); add_type(symbols, glsl_type::isampler2D_type); add_type(symbols, glsl_type::isampler3D_type); @@ -354,17 +354,17 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state) add_type(symbols, glsl_type::usampler3D_type); add_type(symbols, glsl_type::usamplerCube_type); - if (state->ctx->Extensions.NV_texture_rectangle) { + if (state->exts->NV_texture_rectangle) { add_type(symbols, glsl_type::isampler2DRect_type); add_type(symbols, glsl_type::usampler2DRect_type); } - if (state->ctx->Extensions.EXT_texture_array) { + if (state->exts->EXT_texture_array) { add_type(symbols, glsl_type::isampler1DArray_type); add_type(symbols, glsl_type::isampler2DArray_type); add_type(symbols, glsl_type::usampler1DArray_type); add_type(symbols, glsl_type::usampler2DArray_type); } - if (state->ctx->Extensions.EXT_texture_buffer_object) { + if (state->exts->EXT_texture_buffer_object) { add_type(symbols, glsl_type::isamplerBuffer_type); add_type(symbols, glsl_type::usamplerBuffer_type); } diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp index d2d9d17..51d2b85 100644 --- a/src/compiler/glsl/builtin_variables.cpp +++ b/src/compiler/glsl/builtin_variables.cpp @@ -757,12 +757,12 @@ builtin_variable_generator::generate_constants() */ if (state->is_version(0, 300)) { add_const("gl_MaxVertexOutputVectors", - state->ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4); + state->consts->Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4); add_const("gl_MaxFragmentInputVectors", - state->ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents / 4); + state->consts->Program[MESA_SHADER_FRAGMENT].MaxInputComponents / 4); } else { add_const("gl_MaxVaryingVectors", - state->ctx->Const.MaxVarying); + state->consts->MaxVarying); } /* EXT_blend_func_extended brings a built in constant @@ -778,7 +778,7 @@ builtin_variable_generator::generate_constants() * compat profile in GLSL 4.20. GLSL ES never supported this constant. */ if (compatibility || !state->is_version(420, 100)) { - add_const("gl_MaxVaryingFloats", state->ctx->Const.MaxVarying * 4); + add_const("gl_MaxVaryingFloats", state->consts->MaxVarying * 4); } /* Texel offsets were introduced in ARB_shading_language_420pack (which @@ -798,7 +798,7 @@ builtin_variable_generator::generate_constants() add_const("gl_MaxClipDistances", state->Const.MaxClipPlanes); } if (state->is_version(130, 0)) { - add_const("gl_MaxVaryingComponents", state->ctx->Const.MaxVarying * 4); + add_const("gl_MaxVaryingComponents", state->consts->MaxVarying * 4); } if (state->has_cull_distance()) { add_const("gl_MaxCullDistances", state->Const.MaxClipPlanes); @@ -1188,7 +1188,7 @@ builtin_variable_generator::generate_tcs_special_vars() add_output(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2), GLSL_PRECISION_HIGH, "gl_TessLevelInner")->data.patch = 1; /* XXX What to do if multiple are flipped on? */ - int bbox_slot = state->ctx->Const.NoPrimitiveBoundingBoxOutput ? -1 : + int bbox_slot = state->consts->NoPrimitiveBoundingBoxOutput ? -1 : VARYING_SLOT_BOUNDING_BOX0; if (state->EXT_primitive_bounding_box_enable) add_output(bbox_slot, array(vec4_t, 2), "gl_BoundingBoxEXT") @@ -1229,7 +1229,7 @@ builtin_variable_generator::generate_tes_special_vars() "gl_PatchVerticesIn"); add_system_value(SYSTEM_VALUE_TESS_COORD, vec3_t, GLSL_PRECISION_HIGH, "gl_TessCoord"); - if (this->state->ctx->Const.GLSLTessLevelsAsInputs) { + if (this->state->consts->GLSLTessLevelsAsInputs) { add_input(VARYING_SLOT_TESS_LEVEL_OUTER, array(float_t, 4), GLSL_PRECISION_HIGH, "gl_TessLevelOuter")->data.patch = 1; add_input(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2), @@ -1313,14 +1313,14 @@ builtin_variable_generator::generate_fs_special_vars() GLSL_PRECISION_HIGH : GLSL_PRECISION_MEDIUM); - if (this->state->ctx->Const.GLSLFragCoordIsSysVal) { + if (this->state->consts->GLSLFragCoordIsSysVal) { add_system_value(SYSTEM_VALUE_FRAG_COORD, vec4_t, frag_coord_precision, "gl_FragCoord"); } else { add_input(VARYING_SLOT_POS, vec4_t, frag_coord_precision, "gl_FragCoord"); } - if (this->state->ctx->Const.GLSLFrontFacingIsSysVal) { + if (this->state->consts->GLSLFrontFacingIsSysVal) { var = add_system_value(SYSTEM_VALUE_FRONT_FACE, bool_t, "gl_FrontFacing"); var->data.interpolation = INTERP_MODE_FLAT; } else { @@ -1329,7 +1329,7 @@ builtin_variable_generator::generate_fs_special_vars() } if (state->is_version(120, 100)) { - if (this->state->ctx->Const.GLSLPointCoordIsSysVal) + if (this->state->consts->GLSLPointCoordIsSysVal) add_system_value(SYSTEM_VALUE_POINT_COORD, vec2_t, GLSL_PRECISION_MEDIUM, "gl_PointCoord"); else @@ -1505,8 +1505,8 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type, void builtin_variable_generator::generate_varyings() { - struct gl_shader_compiler_options *options = - &state->ctx->Const.ShaderCompilerOptions[state->stage]; + const struct gl_shader_compiler_options *options = + &state->consts->ShaderCompilerOptions[state->stage]; /* gl_Position and gl_PointSize are not visible from fragment shaders. */ if (state->stage != MESA_SHADER_FRAGMENT) { diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll index 37b6b7d..ed393ec 100644 --- a/src/compiler/glsl/glsl_lexer.ll +++ b/src/compiler/glsl/glsl_lexer.ll @@ -455,25 +455,25 @@ sampler1D DEPRECATED_ES_TYPE(glsl_type::sampler1D_type); sampler2D { yylval->type = glsl_type::sampler2D_type; return BASIC_TYPE_TOK; } sampler3D { yylval->type = glsl_type::sampler3D_type; return BASIC_TYPE_TOK; } samplerCube { yylval->type = glsl_type::samplerCube_type; return BASIC_TYPE_TOK; } -sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArray_type); -sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArray_type); +sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler1DArray_type); +sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler2DArray_type); sampler1DShadow DEPRECATED_ES_TYPE(glsl_type::sampler1DShadow_type); sampler2DShadow { yylval->type = glsl_type::sampler2DShadow_type; return BASIC_TYPE_TOK; } samplerCubeShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::samplerCubeShadow_type); -sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArrayShadow_type); -sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArrayShadow_type); -isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler1D_type); -isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler2D_type); -isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler3D_type); -isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isamplerCube_type); -isampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::isampler1DArray_type); -isampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::isampler2DArray_type); -usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler1D_type); -usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler2D_type); -usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler3D_type); -usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usamplerCube_type); -usampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::usampler1DArray_type); -usampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::usampler2DArray_type); +sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler1DArrayShadow_type); +sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler2DArrayShadow_type); +isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler1D_type); +isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler2D_type); +isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler3D_type); +isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isamplerCube_type); +isampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, glsl_type::isampler1DArray_type); +isampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, glsl_type::isampler2DArray_type); +usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler1D_type); +usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler2D_type); +usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler3D_type); +usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usamplerCube_type); +usampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, glsl_type::usampler1DArray_type); +usampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, glsl_type::usampler2DArray_type); /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */ /* these are reserved but not defined in GLSL 3.00 */ @@ -713,15 +713,15 @@ common KEYWORD(130, 300, 0, 0, COMMON); partition KEYWORD(130, 300, 0, 0, PARTITION); active KEYWORD(130, 300, 0, 0, ACTIVE); superp KEYWORD(130, 100, 0, 0, SUPERP); -samplerBuffer TYPE_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object), glsl_type::samplerBuffer_type); +samplerBuffer TYPE_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object), glsl_type::samplerBuffer_type); filter KEYWORD(130, 300, 0, 0, FILTER); row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR); /* Additional reserved words in GLSL 1.40 */ -isampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.NV_texture_rectangle && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler2DRect_type); -usampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.NV_texture_rectangle && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler2DRect_type); -isamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object && yyextra->ctx->Extensions.EXT_texture_integer), glsl_type::isamplerBuffer_type); -usamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object && yyextra->ctx->Extensions.EXT_texture_integer), glsl_type::usamplerBuffer_type); +isampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, glsl_type::isampler2DRect_type); +usampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, glsl_type::usampler2DRect_type); +isamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object && yyextra->exts->EXT_texture_integer), glsl_type::isamplerBuffer_type); +usamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object && yyextra->exts->EXT_texture_integer), glsl_type::usamplerBuffer_type); /* Additional reserved words in GLSL ES 3.00 */ resource KEYWORD(420, 300, 0, 0, RESOURCE); diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 2acdd4f..956909b 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -61,7 +61,8 @@ static const unsigned known_desktop_gl_versions[] = _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(), + : ctx(_ctx), exts(&_ctx->Extensions), consts(&_ctx->Const), + api(_ctx->API), cs_input_local_size_specified(false), cs_input_local_size(), switch_state(), warnings_enabled(true) { assert(stage < MESA_SHADER_STAGES); @@ -417,10 +418,10 @@ _mesa_glsl_parse_state::set_valid_gl_and_glsl_versions(YYLTYPE *locp) * Later calls to _mesa_glsl_initialize_types will misbehave if * the version is invalid. */ - switch (this->ctx->API) { + switch (this->api) { case API_OPENGL_COMPAT: case API_OPENGL_CORE: - this->language_version = this->ctx->Const.GLSLVersion; + this->language_version = this->consts->GLSLVersion; break; case API_OPENGLES: @@ -458,8 +459,8 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version, } else if (strcmp(ident, "compatibility") == 0) { compat_token_present = true; - if (this->ctx->API != API_OPENGL_COMPAT && - !this->ctx->Const.AllowGLSLCompatShaders) { + if (this->api != API_OPENGL_COMPAT && + !this->consts->AllowGLSLCompatShaders) { _mesa_glsl_error(locp, this, "the compatibility profile is not supported"); } @@ -495,8 +496,8 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version, this->language_version = version; this->compat_shader = compat_token_present || - this->ctx->Const.ForceCompatShaders || - (this->ctx->API == API_OPENGL_COMPAT && + this->consts->ForceCompatShaders || + (this->api == API_OPENGL_COMPAT && this->language_version == 140) || (!this->es_shader && this->language_version < 140); @@ -598,7 +599,7 @@ struct _mesa_glsl_extension { * Predicate that checks whether the relevant extension is available for * this context. */ - bool (*available_pred)(const struct gl_context *, + bool (*available_pred)(const struct gl_extensions *, gl_api api, uint8_t version); /** @@ -628,9 +629,9 @@ struct _mesa_glsl_extension { /** Checks if the context supports a user-facing extension */ #define EXT(name_str, driver_cap, ...) \ static UNUSED bool \ -has_##name_str(const struct gl_context *ctx, gl_api api, uint8_t version) \ +has_##name_str(const struct gl_extensions *exts, gl_api api, uint8_t version) \ { \ - return ctx->Extensions.driver_cap && (version >= \ + return exts->driver_cap && (version >= \ _mesa_extension_table[MESA_EXTENSION_##name_str].version[api]); \ } #include "main/extensions_table.h" @@ -793,7 +794,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = { bool _mesa_glsl_extension::compatible_with_state( const _mesa_glsl_parse_state *state, gl_api api, uint8_t gl_version) const { - return this->available_pred(state->ctx, api, gl_version); + return this->available_pred(state->exts, api, gl_version); } /** @@ -830,8 +831,8 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, const char *behavior_string, YYLTYPE *behavior_locp, _mesa_glsl_parse_state *state) { - uint8_t gl_version = state->ctx->Extensions.Version; - gl_api api = state->ctx->API; + uint8_t gl_version = state->exts->Version; + gl_api api = state->api; ext_behavior behavior; if (strcmp(behavior_string, "warn") == 0) { behavior = extension_warn; @@ -879,7 +880,7 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, const _mesa_glsl_extension *extension = find_extension(name); if (extension && (extension->compatible_with_state(state, api, gl_version) || - (state->ctx->Const.AllowGLSLCompatShaders && + (state->consts->AllowGLSLCompatShaders && extension->compatible_with_state(state, API_OPENGL_COMPAT, gl_version)))) { extension->set_flags(state, behavior); if (extension->available_pred == has_ANDROID_extension_pack_es31a) { @@ -2051,8 +2052,8 @@ add_builtin_defines(struct _mesa_glsl_parse_state *state, unsigned version, bool es) { - unsigned gl_version = state->ctx->Extensions.Version; - gl_api api = state->ctx->API; + unsigned gl_version = state->exts->Version; + gl_api api = state->api; if (gl_version != 0xff) { unsigned i; @@ -2094,27 +2095,27 @@ do_late_parsing_checks(struct _mesa_glsl_parse_state *state) } static void -opt_shader_and_create_symbol_table(struct gl_context *ctx, +opt_shader_and_create_symbol_table(const struct gl_constants *consts, struct glsl_symbol_table *source_symbols, struct gl_shader *shader) { assert(shader->CompileStatus != COMPILE_FAILURE && !shader->ir->is_empty()); - struct gl_shader_compiler_options *options = - &ctx->Const.ShaderCompilerOptions[shader->Stage]; + const struct gl_shader_compiler_options *options = + &consts->ShaderCompilerOptions[shader->Stage]; /* Do some optimization at compile time to reduce shader IR size * and reduce later work if the same shader is linked multiple times */ - if (ctx->Const.GLSLOptimizeConservatively) { + if (consts->GLSLOptimizeConservatively) { /* Run it just once. */ do_common_optimization(shader->ir, false, false, options, - ctx->Const.NativeIntegers); + consts->NativeIntegers); } else { /* Repeat it until it stops making changes. */ while (do_common_optimization(shader->ir, false, false, options, - ctx->Const.NativeIntegers)) + consts->NativeIntegers)) ; } @@ -2308,7 +2309,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, lower_builtins(shader->ir); assign_subroutine_indexes(state); lower_subroutine(shader->ir, state); - opt_shader_and_create_symbol_table(ctx, state->symbols, shader); + opt_shader_and_create_symbol_table(&ctx->Const, state->symbols, shader); } if (!force_recompile) { diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h index 880eba8..d654741 100644 --- a/src/compiler/glsl/glsl_parser_extras.h +++ b/src/compiler/glsl/glsl_parser_extras.h @@ -373,7 +373,10 @@ struct _mesa_glsl_parse_state { void process_version_directive(YYLTYPE *locp, int version, const char *ident); - struct gl_context *const ctx; + struct gl_context *const ctx; /* only to be used for debug callback. */ + const struct gl_extensions *exts; + const struct gl_constants *consts; + gl_api api; void *scanner; exec_list translation_unit; glsl_symbol_table *symbols; -- 2.7.4