summaryrefslogtreecommitdiff
path: root/src/glsl/glsl_parser_extras.cpp
AgeCommit message (Collapse)AuthorFilesLines
2013-10-29glsl: Add built-in functions and constants required for ↵Francisco Jerez1-0/+6
ARB_shader_atomic_counters. v2: Represent atomics as GLSL intrinsics. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-10-29glsl: Add extension enables for ARB_shader_atomic_counters.Francisco Jerez1-0/+1
Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-10-15glsl: Add new GLSL 1.50 constants.Paul Berry1-0/+10
This patch populates the following built-in GLSL 1.50 variables based on constants stored in ctx->Const: - gl_MaxVertexOutputComponents - gl_MaxGeometryInputComponents - gl_MaxGeometryOutputComponents - gl_MaxFragmentInputComponents - gl_MaxGeometryTextureImageUnits - gl_MaxGeometryOutputVertices - gl_MaxGeometryTotalOutputComponents - gl_MaxGeometryUniformComponents - gl_MaxGeometryVaryingComponents On i965/gen7, fixes all Piglit tests in "spec/glsl-1.50/built-in constants/*" except for gl_MaxCombinedTextureImageUnits and gl_MaxGeometryUniformComponents. Reviewed-by: Matt Turner <mattst88@gmail.com>
2013-10-07glsl: Remove glsl_parser_state MaxVaryingFloats fieldIan Romanick1-1/+0
Pull the data directly from the context like the other varying related limits. The parser state shadow copies were added back when the parser state didn't have a pointer to the context. There's no reason to do it now days. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-10-05glsl: add plumbing for GL_ARB_texture_query_levelsChris Forbes1-0/+1
Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> Reviewed-by: Matt Turner <mattst88@gmail.com>
2013-10-03glsl: add texture gather changesMaxence Le Dore1-0/+1
V2 [Chris Forbes]: - Add new pattern, fixup parameter reading. V3: Rebase onto new builtins machinery Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-10-01glsl: Switch ast_node to the non-zeroing allocator.Francisco Jerez1-1/+2
All member variables of ast_node are already being initialized from its constructor, but some of its derived classes were leaving members uninitialized -- Fix them. Using rzalloc makes it more likely that we will start relying on the allocator to zero out all memory if the class is ever extended with new member variables. That's bad because it ties objects to some specific allocation scheme, and gives unpredictable results when an object is created with a different allocator -- Stack allocation, array allocation, or aggregation inside a different object are some of the useful possibilities that come to my mind. v2: Use NULL initialization instead of default construction for pointers. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-10-01glsl: Initialize all member variables of _mesa_glsl_parse_state on construction.Francisco Jerez1-2/+14
The _mesa_glsl_parse_state object relies on the memory allocator zeroing out its contents before it's initialized, which is quite an unusual practice in the C++ world because it ties objects to some specific allocation scheme, and gives unpredictable results when an object is created with a different allocator -- Stack allocation, array allocation, or aggregation inside a different object are some of the useful possibilities that come to my mind. Initialize all fields from the constructor and stop using the zeroing allocator. Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-09-26glsl: Create and use a has_uniform_buffer_objects() helper.Kenneth Graunke1-4/+0
This is better than overriding the extension enable based on the language version; it's robust against shaders that do: #version 140 #extension GL_ARB_uniform_buffer_object : disable Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-09-26glsl: Create and use a has_explicit_attrib_location() helper.Kenneth Graunke1-4/+0
Explicit attribute locations are supported with GLSL 3.30, GLSL ES 3.00, or "#extension GL_ARB_explicit_attrib_location: enable". Using a helper function makes it easy to check for this. This enables support in GLSL 3.30, which was previously missing. Previously, we overrode the extension enable flag for ES 3.00. This is not robust against a shader such as: #version 330 #extension GL_ARB_explicit_attrib_location : disable Disabling extensions should not remove core language functionality. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-09-13mesa: Rename MESA_shader_integer_mix to EXT_shader_integer_mixIan Romanick1-1/+1
Everyone at the Khronos meeting was as surprised that GLSL didn't already support this as we were. Several vendors said they'd ship it, but there didn't seem to be enough interest to put in the effort to make it ARB or KHR. v2: Fix a couple typos and rename the spec file to EXT_shader_integer_mix.spec. Suggested by Roland. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com>
2013-09-09glsl: Implement MESA_shader_integer_mix extension.Matt Turner1-0/+1
Because why doesn't GLSL allow you to do this already? Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-09-09glsl: Switch to the new built-in function module.Kenneth Graunke1-1/+1
All built-ins are now handled by the new code; the old system is dead. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-08-21glsl: Remove ubo_qualifiers_allowed variable.Matt Turner1-1/+0
No longer used. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
2013-08-21glsl: Rename ubo_qualifiers_valid to ubo_qualifiers_allowed.Matt Turner1-1/+1
The variable means that UBO qualifiers are allowed in a particular context (e.g., not allowed in a struct field declaration), rather than a particular set of UBO qualifiers are valid. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
2013-08-19glsl: Disallow embedded structure definitionsIan Romanick1-0/+1
Continue to allow them in GLSL 1.10 because the spec allows it. Generate an error in all other versions because the specs specifically disallow it. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Cc: "9.2" <mesa-stable@lists.freedesktop.org>
2013-08-01glsl: Export the compiler's GS layout qualifiers to the gl_shader.Eric Anholt1-0/+31
Next step is to validate them at link time. v2 (Paul Berry <stereotype441@gmail.com>): Don't attempt to export the layout qualifiers in the event of a compile error, since some of them are set up by ast_to_hir(), and ast_to_hir() isn't guaranteed to have run in the event of a compile error. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> v3 (Paul Berry <stereotype441@gmail.com>): Use PRIM_UNKNOWN to represent "not set in this shader". Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-08-01glsl: Parse the GLSL 1.50 GS layout qualifiers.Eric Anholt1-0/+4
Limited semantic checking (compatibility between declarations, checking that they're in the right shader target, etc.) is done. v2: Remove stray debug printfs. v3 (Paul Berry <stereotype441@gmail.com>): Process input layout qualifiers at ast_to_hir time rather than at parse time, since certain error conditions depend on the relative ordering between input layout qualifiers, declarations, and calls to .length(). Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-07-30mesa,glsl,st/dri: add a new driconf option force_glsl_version for UnigineMarek Olšák1-1/+2
See documentation in mtypes.h. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-07-29glsl: Remove shader stage checking for extension handling.Kenneth Graunke1-61/+28
Certain extensions only add functionality to particular shader stages. (For example, ARB_draw_instanced only adds variables to the vertex shader stage.) Previously, we only allowed such extensions to be enabled in the shader stages where they're useful. However, I've never found any text which mandates that behavior; in my opinion, you should be able to turn on extensions in any shader stage, even if they have no effect. Fixes Piglit tests glslparsertest/glsl2/draw_buffers-05.vert and ARB_draw_instanced/preprocessor/feature-macro-enabled.frag. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=29185 Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2013-07-27glsl: Be consistent about '\n', '.', and capitalization in errors/warnings.Paul Berry1-8/+8
The majority of calls to _mesa_glsl_error(), _mesa_glsl_warning(), and _mesa_glsl_parse_state::check_version() use a message that begins with a lower case letter and ends without a period. This patch makes all messages follow that convention. Also, error/warning messages shouldn't end in '\n', since _mesa_glsl_msg() automatically adds '\n' at the end of the message. Reviewed-by: Matt Turner <mattst88@gmail.com>
2013-07-21glsl: Initialize ast_function member variables.Vinson Lee1-1/+2
Fixes "Uninitialized pointer field" defect reported by Coverity. Signed-off-by: Vinson Lee <vlee@freedesktop.org>
2013-07-16glsl: Initialize ast_jump_statement::opt_return_value.Vinson Lee1-0/+1
opt_return_value was not initialized if mode != ast_return. Fixes "Uninitialized pointer field" defect reported by Coverity. Signed-off-by: Vinson Lee <vlee@freedesktop.org> Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
2013-07-11glsl: Add support for C-style initializers.Matt Turner1-0/+188
Required by GL_ARB_shading_language_420pack. Parts based on work done by Todd Previte and Ken Graunke, implementing basic support for C-style initializers of arrays. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-07-11glsl: Add infrastructure for aggregate initializers.Matt Turner1-0/+13
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-07-11glsl: Add an is_declaration field to ast_struct_specifier.Matt Turner1-0/+1
Will be used in a later commit to differentiate between a structure type declaration and a variable declaration of a struct type. I.e., the difference between struct S { float x; }; (is_declaration = true) and S s; (is_declaration = false) Also note that is_declaration = true for struct S { float x; } s; Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-07-11glsl: Change type of is_array to bool.Matt Turner1-1/+1
Reviewed-by: Ian Romanick <ian.d.romainck@intel.com>
2013-06-21mesa: Move the common _mesa_glsl_compile_shader() code to glsl/.Eric Anholt1-0/+83
This code had no relation to ir_to_mesa.cpp, since it was also used by intel and state_tracker, and most of it was duplicated with the standalone compiler (which has periodically drifted from the Mesa copy). v2: Split from the ir_to_mesa to shaderapi.c changes. Acked-by: Paul Berry <stereotype441@gmail.com> (v1) Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-06-21mesa: Use shared code for converting shader targets to short strings.Eric Anholt1-0/+35
We were duplicating this code all over the place, and they all would need updating for the next set of shader targets. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-06-14mesa: Add infrastructure for ARB_shading_language_420pack.Todd Previte1-0/+1
v2 [mattst88] - Split infrastructure into separate patch. - Add preprocessor #define. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-06-10glsl: Parse "#version 150 core" directives.Kenneth Graunke1-0/+13
Previously we only supported "#version 150". This patch recognizes "compatibility" to give the user a more descriptive error message. Fixes Piglit's version-150-core-profile test. Reviewed-by: Matt Turner <mattst88@gmail.com> Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-13glsl: add AMD_vertex_shader_layer supportJordan Justen1-0/+1
This GLSL extension requires that AMD_vertex_shader_layer be enabled by the driver. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-05-13glsl: Add lowering pass for ir_triop_vector_insertIan Romanick1-0/+1
This will eventually replace do_vec_index_to_cond_assign. This lowering pass is called in all the places where do_vec_index_to_cond_assign or do_vec_index_to_swizzle is called. v2: Use WRITEMASK_* instead of integer literals. Use a more concise method of generating broadcast_index. Both suggested by Eric. v3: Use a series of scalar compares instead of a single vector compare. Suggested by Eric and Ken. It still uses 'if (cond) v.x = y;' instead of conditional assignments because ir_builder doesn't do conditional assignments, and I'd rather keep the code simple. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-05-12glsl: Add a pass to flip matrix/vector multiplies to use dot products.Kenneth Graunke1-0/+4
This pass flips (matrix * vector) operations to (vector * matrixTranspose) for certain built-in matrices (currently gl_ModelViewProjectionMatrix and gl_TextureMatrix). This is equivalent, but results in dot products rather than multiplies and adds. On some hardware, this is more efficient. This pass is conditionalized on ctx->mvp_with_dp4, the flag drivers set to indicate they prefer dot products. Improves performance in Lightsmark by 1.01131% +/- 0.162069% (n = 10) on a Haswell GT2 system. Passes Piglit on Ivybridge. v2: Use struct gl_shader_compiler_options instead of plumbing through another boolean flag for this purpose. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2013-05-12glsl: Pass struct shader_compiler_options into do_common_optimization.Kenneth Graunke1-1/+3
do_common_optimization may need to make choices about whether to emit certain kinds of instructions. gl_context::ShaderCompilerOptions contains exactly that information, so it makes sense to pass it in. Rather than passing the whole array, pass the structure for the stage that's currently being worked on. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2013-05-11mesa: move max texture image unit constants to gl_program_constantsMarek Olšák1-2/+2
Const.MaxTextureImageUnits -> Const.FragmentProgram.MaxTextureImageUnits Const.MaxVertexTextureImageUnits -> Const.VertexProgram.MaxTextureImageUnits etc. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2013-05-06mesa: Add infrastructure for ARB_gpu_shader5.Matt Turner1-0/+1
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
2013-04-04glsl: Add an optimization pass to flatten simple nested if blocks.Kenneth Graunke1-0/+1
GLBenchmark 2.7's shaders contain conditional blocks like: if (x) { if (y) { ... } } where the outer conditional's then clause contains exactly one statement (the nested if) and there are no else clauses. This can easily be optimized into: if (x && y) { ... } This saves a few instructions in GLBenchmark 2.7: total instructions in shared programs: 11833 -> 11649 (-1.55%) instructions in affected programs: 8234 -> 8050 (-2.23%) It also helps CS:GO slightly (-0.05%/-0.22%). More importantly, however, it simplifies the control flow graph, which could enable other optimizations. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Eric Anholt <eric@anholt.net>
2013-03-29glsl: Implement ARB_texture_query_lodDave Airlie1-0/+1
v2 [mattst88]: - Rebase. - #define GL_ARB_texture_query_lod to 1. - Remove comma after ir_lod in ir.h for MSVC. - Handled ir_lod in ir_hv_accept.cpp, ir_rvalue_visitor.cpp, opt_tree_grafting.cpp. - Rename textureQueryLOD to textureQueryLod, see https://www.khronos.org/bugzilla/show_bug.cgi?id=821 - Fix ir_reader of (lod ...). v3 [mattst88]: - Rename textureQueryLod to textureQueryLOD, pending resolution of Khronos 821. - Add ir_lod case to ir_to_mesa.cpp. Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2013-03-05mesa: Report ARB_debug_output for both shader errors and warnings.Eric Anholt1-8/+7
This ends up reusing the dynamic ID support, so a silly enum gets to go away. We don't assign good IDs to different messages yet, but at least that's tractable now. Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
2013-03-02glsl: add support for ARB_texture_multisampleChris Forbes1-0/+1
V2: - emit `sample` parameter properly for multisample texelFetch() - fix spurious whitespace change - introduce a new opcode ir_txf_ms rather than overloading the existing ir_txf further. This makes doing the right thing in the driver somewhat simpler. V3: - fix weird whitespace V4: - don't forget to include the new opcode in tex_opcode_strs[] (thanks Kenneth for spotting this) Signed-off-by: Chris Forbes <chrisf@ijw.co.nz> [V2] Reviewed-by: Eric Anholt <eric@anholt.net> [V2] Reviewed-by: Paul Berry <stereotype441@gmail.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-02-12glsl: Fix unsupported version error for GLSL ES 3.00, future proof for 3.30.Paul Berry1-54/+58
When the user specifies an unsupported GLSL version, _mesa_glsl_parse_state::process_version_directive() nicely gives them an error message telling them which GLSL versions are supported. Previous to this patch, the logic for determining whether a given language version was supported was independent from the logic to generate this error message string; as a result, we had a bug where GLSL 3.00 would never be listed in the error message as an available language version, even if it was really available. To make matters worse, the code for generating the error message string assumed that desktop GL versions were always separated by 0.10, an assumption that will be wrong as soon as we support GLSL 3.30. This patch fixes both problems by adding a table of supported GLSL versions to _mesa_glsl_parse_state; this table is used both to generate the error message and to check whether a given version is supported. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2013-02-06glsl: fix incorrect comment about do_common_optimizationMarek Olšák1-2/+2
2013-01-25glsl: Add infrastructure for ARB_shading_language_packingMatt Turner1-0/+1
Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Paul Berry <stereotype441@gmail.com>
2012-12-17glsl: Fix gl_context vs. ralloc context in check_version again, again.Kenneth Graunke1-2/+2
Dave found some, but there were more. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=58039
2012-12-16glsl_parser_extras.cpp: fixup gl vs mem contexts again.Dave Airlie1-4/+4
This should fix: https://bugs.freedesktop.org/show_bug.cgi?id=58039 Tested-by: Darxus on bug 58039 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-12-06glsl: Allow layout qualifiers in GLSL 3.00 ESIan Romanick1-0/+4
Note that while 'packed' is a reserved word in GLSL ES, row_major is not. This means that we have to use the string-based matching for that. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl: Make {Min,Max}ProgramTexelOffset available to compiler.Paul Berry1-0/+2
These constants need to be made available to shaders in GLSL 3.00 ES. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Eric Anholt <eric@anholt.net> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl/parser: Handle "#version 300 es" directive.Paul Berry1-26/+79
Note that GLSL 1.00 is selected using "#version 100", so "#version 100 es" is prohibited. v2: Check for GLES3 before allowing '#version 300 es' v3: Make sure a correct language_version is set in _mesa_glsl_parse_state::process_version_directive. Signed-off-by: Paul Berry <stereotype441@gmail.com> Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>
2012-12-06glsl/parser: Extract version directive processing into a function.Paul Berry1-0/+52
Version directive handling is going to have to be used within two parser rules, one for desktop-style version directives (e.g. "#version 130") and one for the new ES-style version directive (e.g. "#version 300 es"), so this patch moves it to a function that can be called from both rules. No functional change. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Carl Worth <cworth@cworth.org>