summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Initialize member variable is_ubo_var in constructor.Vinson Lee2013-06-271-1/+1
| | | | | | | Fixes "Uninitialized scalar field" defect reported by Coverity. Signed-off-by: Vinson Lee <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Use the C99 variadic macro syntax.José Fonseca2013-06-272-4/+4
| | | | | | | MSVC does not support the old GCC syntax. See also http://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html
* glsl: Move all var decls to the front of the IR list in reverse orderIan Romanick2013-06-261-0/+18
| | | | | | | | | | | | | | | | | | This has the (intended!) side effect that vertex shader inputs and fragment shader outputs will appear in the IR in the same order that they appeared in the shader code. This results in the locations being assigned in the declared order. Many (arguably buggy) applications depend on this behavior, and it matches what nearly all other drivers do. Fixes the (new) piglit test attrib-assignments. NOTE: This is a candidate for stable release branches (and requires the previous commit to prevent a regression in OpenGL ES 2.0 conformance test stencil_plane_operation). Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Chad Versace <[email protected]>
* glsl: Streamline the built-in type handling code.Kenneth Graunke2013-06-266-694/+424
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Over the last few years, the compiler has grown to support 7 different language versions and 6 extensions that add new built-in types. With more and more features being added, some of our core code has devolved into an unmaintainable spaghetti of sorts. A few problems with the old code: 1. Built-in types are declared...where exactly? The types in builtin_types.h were organized in arrays by the language version or extension they were introduced in. It's factored out to avoid duplicates---every type only exists in one array. But that means that sampler1D is declared in 110, sampler2D is in core types, sampler3D is a unique global not in a list...and so on. 2. Spaghetti call-chains with weird parameters: generate_300ES_types calls generate_130_types which calls generate_120_types and generate_EXT_texture_array_types, which calls generate_110_types, which calls generate_100ES_types...and more Except that ES doesn't want 1D types, so we have a skip_1d parameter. add_deprecated also falls into this category. 3. Missing type accessors. Common types have convenience pointers (like glsl_type::vec4_type), but others may not be accessible at all without a symbol table (for example, sampler types). 4. Global variable declarations in a header file? #include "builtin_types.h" in two C++ files would break the build. The new code addresses these problems. All built-in types are declared together in a single table, independent of when they were introduced. The macro that declares a new built-in type also creates a convenience pointer, so every type is available and it won't get out of sync. The code to populate a symbol table with the appropriate types for a particular language version and set of extensions is now a single table-driven function. The table lists the type name and GL/ES versions when it was introduced (similar to how the lexer handles reserved words). A single loop adds types based on the language version. Explicit extension checks then add additional types. If they were already added based on the language version, glsl_symbol_table simply ignores the request to add them a second time, meaning we don't need to worry about duplicates and can simply list types where they belong. v2: Mark uvecs and shadow samplers as ES3 only, and 1DArrayShadow as unsupported in ES entirely. Add a touch more doxygen. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Don't use random pointers as an array of glsl_type objects.Kenneth Graunke2013-06-261-1/+1
| | | | | | | | | | | | Using a random glsl_type convenience pointer as an array is a really bad idea, for all the reasons mentioned in the previous commit. The new glsl_type::bvec() function is simpler anyway. Prevents breakage in the next commit. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Stop being clever with pointer arithmetic when fetching types.Kenneth Graunke2013-06-261-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | Currently, vector types are linked together closely: the glsl_type objects for float, vec2, vec3, and vec4 are all elements of the same array, in that exact order. This makes it possible to obtain vector types via pointer arithmetic on the scalar type's convenience pointer. For example, float_type + (3 - 1) = vec3. However, relying on this is extremely fragile. There's no particular reason the underlying type objects need to be stored in an array. They could be individual class members, possibly with padding between them. Then the pointer arithmetic would break, and we'd get bad pointers to non-heap allocated data, causing subtle breakage that can't be detected by valgrind. Cue insanity. Or someone could simply reorder the type variables, causing us to get the wrong type entirely. Also cue insanity. Writing this explicitly is much safer. With the new helper functions, it's a bit less code even. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Add simple vector type accessor helpers.Kenneth Graunke2013-06-262-0/+61
| | | | | | | | | | | | | | | | This patch introduces new functions to quickly grab a pointer to a vector type. For example: glsl_type::bvec(4) returns glsl_type::bvec4_type glsl_type::ivec(3) returns glsl_type::ivec3_type glsl_type::uvec(2) returns glsl_type::uvec2_type glsl_type::vec(1) returns glsl_type::float_type This is less wordy than glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1), which can help avoid extra word wrapping. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* mesa: Move the common _mesa_glsl_compile_shader() code to glsl/.Eric Anholt2013-06-213-60/+98
| | | | | | | | | | | 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 <[email protected]> (v1) Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Use shared code for converting shader targets to short strings.Eric Anholt2013-06-214-7/+50
| | | | | | | | 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 <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Remove ir_print_visitor.h includes and usageEric Anholt2013-06-216-6/+0
| | | | | | | | | | | | | We have ir->print() to do the old declaration of a visitor and having the IR accept the visitor (yuck!). And now you can call _mesa_print_ir() safely anywhere that you know what an ir_instruction is. A couple of missing printf("\n")s are added in error paths -- when an expression is handed to the visitor, it doesn't print '\n' (since it might be a step in printing a whole expression tree). Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Make _mesa_print_ir() available from anything including ir.h.Eric Anholt2013-06-213-3/+11
| | | | | | | | | | No more forgetting to #include "ir_print_visitor.h" when doing temporary debug code, or forgetting and leaving it in after removing your temporary debug code. Also, available from C code so you don't need to move the caller to C++ just to call it (see also: ir_to_mesa.cpp). Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Make some files safe to include from CPaul Berry2013-06-213-0/+8
| | | | | Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Disallow return with a void argument from void functions.Matt Turner2013-06-141-1/+17
| | | | | | NOTE: This is a candidate for the stable branches. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Allow implicit conversion of return values.Matt Turner2013-06-141-9/+22
| | | | | | Required by ARB_shading_language_420pack. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add gl_{Max,Min}ProgramTexelOffset built-in constants.Matt Turner2013-06-141-0/+7
| | | | | | | | Required by ARB_shading_language_420pack. Note that the 420pack spec incorrectly specifies their values as (Min, Max) = (-7, 8) when they should be (-8, 7) as listed in the GLSL 4.30 and ESSL 3.0 specs. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Allow swizzles on scalars.Matt Turner2013-06-141-1/+3
| | | | | | Required by ARB_shading_language_420pack. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Allow .length() method on vectors and matrices.Matt Turner2013-06-141-20/+38
| | | | | | Required by ARB_shading_language_420pack. Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Add infrastructure for ARB_shading_language_420pack.Todd Previte2013-06-143-0/+6
| | | | | | | | v2 [mattst88] - Split infrastructure into separate patch. - Add preprocessor #define. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix null check in read_dereference.Vinson Lee2013-06-131-1/+1
| | | | | | | Fixes "Logically dead code" defect reported by Coverity. Signed-off-by: Vinson Lee <[email protected]> Reviewed-by: Brian Paul <[email protected]>
* mesa: fix OES_EGL_image_external being partially allowed in the core profileMarek Olšák2013-06-131-7/+7
| | | | Reviewed-by: Chad Versace <[email protected]>
* glsl: Generate smaller values for uniform locationsIan Romanick2013-06-121-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we would generate uniform locations as (slot << 16) + array_index. We do this to handle applications that assume the location of a[2] will be +1 from the location of a[1]. This resulted in every uniform location being at least 0x10000. The OpenGL 4.3 spec was amended to require this behavior, but previous versions did not require locations of array (or structure) members be sequential. We've now encountered two applications that assume uniform values will be "small." As far as we can tell, these applications store the GLint returned by glGetUniformLocation in a int16_t or possibly an int8_t. THIS BEHAVIOR IS NOT GUARANTEED OR IMPLIED BY ANY VERSION OF OpenGL. Other implementations happen to have both these behaviors (sequential array elements and small values) since OpenGL 2.0, so let's just match their behavior. Fixes "3D Bowling" on Android. NOTE: This is a candidate for stable release branches. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-and-tested-by: Chad Versace <[email protected]>
* glsl: Add gl_shader_program::UniformLocationBaseScaleIan Romanick2013-06-121-0/+2
| | | | | | | | | | | | | | | | This is used by _mesa_uniform_merge_location_offset and _mesa_uniform_split_location_offset to determine how the base and offset are packed. Previously, this value was hard coded as (1U<<16) in those functions via the shift and mask contained therein. The value is still (1U<<16), but it can be changed in the future. The next patch dynamically generates this value. NOTE: This is a candidate for stable release branches. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-and-tested-by: Chad Versace <[email protected]>
* glsl: Allow the use of determinant() in GLSL 1.50.Kenneth Graunke2013-06-101-0/+4
| | | | | | | | | | We already implemented this for ES3, so we just need to turn it on. Fixes 6 Piglit tests: spec/glsl-1.50/compiler/built-in-functions/determinant-mat[234].{vert,frag} Reviewed-by: Matt Turner <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glcpp: Automatically #define GL_core_profile 1 on GLSL 1.50+.Kenneth Graunke2013-06-101-0/+3
| | | | | | | | | | Page 17 of the GLSL 1.50.11 specification states: "There is a built-in macro definition for each profile the implementation supports. All implementations provide the following macro: Reviewed-by: Matt Turner <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Parse "#version 150 core" directives.Kenneth Graunke2013-06-101-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 <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Bail on parsing if the #version directive is bogus.Kenneth Graunke2013-06-101-0/+6
| | | | | | | | | | | | | | | | | | | If we didn't successfully parse the #version line, there's no point in continuing with parsing and compiling: it's already failed. Furthermore, it can actually be harmful: right after handling #version, we call _mesa_glsl_initialize_types(), which checks state->es_shader and language_version. If it isn't valid, it hits an assertion failure. Fixes Piglit's "invalid-version-es." When processing "#version 110 es", our code set state->es_shader and state->language_version = 110. It then properly determined that this was invalid and flagged an error. Since we continued anyway, we hit the assertion mentioned above. NOTE: This is a candidate for the 9.1 branch. Reviewed-by: Matt Turner <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl linker: Initialize member variable interface_namespace.Vinson Lee2013-06-061-1/+2
| | | | | | | Fixes "Uninitialized pointer field" defect reported by Coverity. Signed-off-by: Vinson Lee <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix uniform buffer object counting.Eric Anholt2013-06-062-3/+34
| | | | | | | | | | | | | | | | | | | | We were counting uniforms located in UBOs against the default uniform block limit, while not doing any counting against the specific combined limit. Note that I couldn't quite find justification for the way I did this, but I think it's the only sensible thing: The spec talks about components, so each "float" in a std140 block would count as 1 component and a "vec4" would count as 4, though they occupy the same amount of space. Since GPU limits on uniform buffer loads are surely going to be about the size of the blocks, I just counted them that way. Fixes link failures in piglit arb_uniform_buffer_object/maxuniformblocksize when ported to geometry shaders on Paul's GS branch, since in that case the max block size is bigger than the default uniform block component limit. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Make a local variable to avoid restating this array lookup.Eric Anholt2013-06-061-8/+8
| | | | | | v2: Convert another instance of the array lookup. (caught by Tapani) Reviewed-by: Ian Romanick <[email protected]>
* glcpp: Add test case for recently fixed loop-control underflow bug.Carl Worth2013-06-032-0/+25
| | | | | | | To trigger the bug, it suffices to have a line-continuation followed by a newline and then a non-line-continuation backslash. Reviewed-by: Kenneth Graunke <[email protected]>
* glcpp: Fix post-decrement underflow in loop-control variableCarl Worth2013-06-031-1/+3
| | | | | | | | | | | | | This loop-control condition with a post-decrement operator would lead to an underflow of collapsed_newlines. This in turn would cause a subsequent execution of the loop to labor inordinately trying to return the loop-control variable to a value of 0 again. Fix this by dis-intertwining the test and the decrement. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=65112 Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix MSVC build.José Fonseca2013-05-281-3/+3
| | | | | | | | | | | | It appears that `sizeof(Class::member)` is either non-standard or merely unsupported in MSVC. So use `sizeof(instance->member)` instead, which is guaranteed to work everywhere. Also promote the assert to a static assert. Trivial.
* mesa: fix GLSL program objects with more than 16 samplers combinedMarek Olšák2013-05-284-79/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | The problem is the sampler units are allocated from the same pool for all shader stages, so if a vertex shader uses 12 samplers (0..11), the fragment shader samplers start at index 12, leaving only 4 sampler units for the fragment shader. The main cause is probably the fact that samplers (texture unit -> sampler unit mapping, etc.) are tracked globally for an entire program object. This commit adapts the GLSL linker and core Mesa such that the sampler units are assigned to sampler uniforms for each shader stage separately (if a sampler uniform is used in all shader stages, it may occupy a different sampler unit in each, and vice versa, an i-th sampler unit may refer to a different sampler uniform in each shader stage), and the sampler-specific variables are moved from gl_shader_program to gl_shader. This doesn't require any driver changes, and it fixes piglit/max-samplers for gallium and classic swrast. It also works with any number of shader stages. v2: - converted tabs to spaces - added an assertion to _mesa_get_sampler_uniform_value Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl linker: compare interface blocks during interstage linkingKenneth Graunke2013-05-233-0/+49
| | | | | | | | | | | | Verify that interface blocks match when linking separate shader stages into a program. Fixes piglit glsl-1.50 tests: * linker/interface-blocks-vs-fs-member-count-mismatch.shader_test * linker/interface-blocks-vs-fs-member-order-mismatch.shader_test Signed-off-by: Kenneth Graunke <[email protected]> Signed-off-by: Jordan Justen <[email protected]>
* glsl linker: compare interface blocks during intrastage linkingJordan Justen2013-05-234-0/+82
| | | | | | | | | | | | | | | | Verify that interface blocks match when combining compilation units at the same stage. (For example, when merging all vertex shaders.) Fixes piglit glsl-1.50 test: * linker/interface-blocks-multiple-vs-member-count-mismatch.shader_test v5 (Ken): Rename to link_interface_blocks.cpp and drop the separate .h file for consistency with other linker code. Remove "ok" variable. Fold cross_validate_interface_blocks into its caller. Signed-off-by: Jordan Justen <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl linker: support arrays of interface block instancesJordan Justen2013-05-231-11/+50
| | | | | | | | | | | | | | | With this change we now support interface block arrays. For example, cases like this: out block_name { float f; } block_instance[2]; This allows Mesa to pass the piglit glsl-1.50 test: * execution/interface-blocks-complex-vs-fs.shader_test Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl link_varyings: link interface blocks using the block nameJordan Justen2013-05-231-4/+29
| | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl linker: remove interface block instance namesJordan Justen2013-05-234-0/+207
| | | | | | | | Convert interface blocks with instance names into flat interface blocks without an instance name. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl ast_to_hir: support in/out for interface blocksJordan Justen2013-05-231-6/+22
| | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl ast_to_hir: reject row/column_major for in/out interface blocksJordan Justen2013-05-231-1/+5
| | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl ast_to_hir: move uniform block symbols to interface blocks namespaceJordan Justen2013-05-231-1/+1
| | | | | | | Uniform/interface blocks are a separate namespace from types. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl_symbol_table: add interface block namespacesJordan Justen2013-05-232-3/+85
| | | | | | | | For interface blocks, there are three separate namespaces for uniform, input and output blocks. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl parser: allow in & out for interface block membersJordan Justen2013-05-231-25/+12
| | | | | | | | | | | | | Previously uniform blocks allowed for the 'uniform' keyword to be used with members of a uniform blocks. With interface blocks 'in' can be used on 'in' interface block members and 'out' can be used on 'out' interface block members. The basic_interface_block rule will verify that the same qualifier type is used with the block and each member. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl ast_to_hir: reject interpolation qualifiers for uniform blocksJordan Justen2013-05-231-0/+6
| | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl parser: handle interface block member qualifierJordan Justen2013-05-231-1/+43
| | | | | | | | | | | | | | | | | | | | | An interface block member may specify the type: in { in vec4 in_var_with_qualifier; }; When specified with the member, it must match the same type as interface block type. It can also omit the qualifier: uniform { vec4 uniform_var_without_qualifier; }; When the type is not specified with the member, it will adopt the same type as the interface block. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl parser: on desktop GL require GLSL 150 for instance namesJordan Justen2013-05-231-5/+3
| | | | | | | | | | | Interface blocks in GLSL 150 allow an instance name to be used. v2: * use state->check_version Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl parser: reject VS+in & FS+out interface blocksJordan Justen2013-05-231-0/+14
| | | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: parse in/out types for interface blocksJordan Justen2013-05-231-11/+40
| | | | | | | | | | | Previously only 'uniform' was allowed for uniform blocks. Now, in/out can be parsed, but it will only be allowed for GLSL >= 150. Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl parser: rename uniform block to interface blockJordan Justen2013-05-231-12/+12
| | | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: rename ast_uniform_block to ast_interface_blockJordan Justen2013-05-233-12/+12
| | | | | | Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>