summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Short-circuit lower_if_to_cond_assign when MaxIfDepth is UINT_MAX.Kenneth Graunke2011-10-211-0/+3
| | | | | | | | | | Setting MaxIfDepth to UINT_MAX effectively means "don't lower anything." Explicitly checking for this common case allows us to avoid walking the IR, computing nesting levels, and so on. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Bryan Cain <[email protected]>
* ir_to_mesa: Move some things outside the 'extern "C"' blocksIan Romanick2011-10-183-7/+0
| | | | | | | | | | | Having a few of these includes or forward declarations inside the 'extern "C"' block can cause problems later. Specifically, it prevents C++ linkage functions from being added to ir_to_mesa.h and makes G++ angry if 'struct foo' is seen both inside and outside an 'extern "C"'. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Stop tree grafting if a variable is overwritten as an 'out' param.Kenneth Graunke2011-10-181-11/+28
| | | | | | | | | | | | | | | While reviewing some compiler cleanups I'd sent out, Paul noticed that tree grafting wasn't taking "out" parameters into account. Further investigation revealed that it isn't strictly necessary: ir_call ends basic blocks, and tree grafting currently only operates on basic blocks. So calls already kill grafts. However, just to be safe, this patch makes "out" parameters explicitly kill grafts. Paul and I both prefer this. It's a bit clearer. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* mesa: Add a flag for shader programs to allow SSO linkage in GLES2.Eric Anholt2011-10-181-1/+2
| | | | | | | | On converting fixed function programs to generate GLSL, the linker became cranky that we were trying to make something that wasn't a linked vertex+fragment program. Given that the Mesa GLES2 drivers also support desktop GL with EXT_sso, just telling the linker to shut up seems like the easiest solution.
* glsl: Add gl_CurrentAttrib{Vert,Frag}MESA internal builtin uniforms.Eric Anholt2011-10-181-1/+24
| | | | | These will be used by the FF VS/FS to represent the current attributes when they don't have an active vertex array.
* linker: Fix a slightly incorrect commentIan Romanick2011-10-101-1/+4
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove unused method ir_variable::component_slotsIan Romanick2011-10-072-16/+0
| | | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove version check when looking for identifiers containing "__".Jason Wood2011-10-061-2/+1
| | | | Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Consider "__" in identifers as reserved.Eric Anholt2011-10-051-0/+13
| | | | | | Fixes double-underscore-*.frag. Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Add a gl_vert_result for gl_ClipVertex.Paul Berry2011-10-051-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this patch, clip planes didn't work properly in Mesa when using vertex shaders, because Mesa assigned both gl_ClipVertex and gl_Position to the same gl_vert_result (VERT_RESULT_HPOS). As a result, backends couldn't distinguish between the two variables, so any shader that wrote different values to them would fail to work properly. This patch paves the way for proper support of gl_ClipVertex by creating a new enumerated value in gl_vert_result for it (VERT_RESULT_CLIP_VERTEX). After this patch, a back-end may add support for gl_ClipVertex using the following algorithm: - If using a user-supplied GLSL vertex shader: - If the bit corresponding to VERT_RESULT_CLIP_VERTEX is set in gl_program::OutputsWritten: - Clip using the vertex shader output VERT_RESULT_CLIP_VERTEX and the clip planes defined in gl_context::Transform.EyeUserPlane. - Else: - Clip using the vertex shader output VERT_RESULT_HPOS and the clip planes defined in gl_context::Transform.EyeUserPlane. - Else (either using fixed function or an ARB vertex program): - Clip using the vertex shader output VERT_RESULT_HPOS and the clip planes defined in gl_context::Transform._ClipUserPlane (*) where (*) represents the normal Mesa behavior before this patch. An example of implementing the above algorithm can be found in the patch that follows this one, which implements gl_ClipVertex in i965 Gen6. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove unneeded headers.Stéphane Marchesin2011-10-042-2/+0
|
* linker: Use gl_shader_program::AttributeBindings for attrib locationsIan Romanick2011-10-041-74/+64
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Delete symbol table in post-link shadersIan Romanick2011-10-041-0/+8
| | | | | | | | | | The symbol table in the linked shaders may contain references to variables that were removed (e.g., unused uniforms). Since it may contain junk, there is no possible valid use. Delete it and set the pointer to NULL. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Remove ARB_draw_buffers extension enable flagIan Romanick2011-10-041-1/+0
| | | | | | | | | | | | | All drivers in Mesa have supported this extension for eons. This extension is an optional features in desktop OpenGL (via GL_ARB_draw_buffers) and OpenGL ES 2.x (via GL_NV_draw_buffers). The extension is not usable in OpenGL ES 1.x. There is no glDrawBuffers* entry point in OpenGL ES 1.x contexts, and glGet*v generate errors when MAX_DRAW_BUFFERS or DRAW_BUFFERi is queried. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]>
* glcpp: Add a test for #elif with an undefined macro.Carl Worth2011-09-302-0/+8
| | | | | | | | | | | | | | | | | | As written, this test correctly raises an error for #elif being used with an undefined macro (and not as an argument to "defined"). If the preceding #if were '#if 1' then this diagnositc would correctly be hidden. That allows code such as the following to not raise an error: #ifndef MAYBE_UNDEFINED #elif MAYBE_UNDEFINED < 5 ... #endif So this test case is working as expected already. We add it here just to improve test coverage. Reviewed-by: Kenneth Graunke <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glcpp: Raise error if defining any macro containing two consecutive underscoresCarl Worth2011-09-303-3/+7
| | | | | | | | | | | | | | | | | | The specification reserves any macro name containing two consecutive underscores, (anywhere within the name). Previously, we only raised this error for macro names that started with two underscores. Fix the implementation to check for two underscores anywhere, and also update the corresponding 086-reserved-macro-names test. This also fixes the following two piglit tests: spec/glsl-1.30/preprocessor/reserved/double-underscore-02.frag spec/glsl-1.30/preprocessor/reserved/double-underscore-03.frag Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glcpp: Implement token pasting for non-function-like macrosCarl Worth2011-09-301-36/+47
| | | | | | | | | | | | | | | | | | | | This is as simple as abstracting one existing block of code into a function call and then adding a single call to that function for the case of a non-function-like macro. This fixes the recently-added 097-paste-with-non-function-macro test as well as the following piglit tests: spec/glsl-1.30/preprocessor/concat/concat-01.frag spec/glsl-1.30/preprocessor/concat/concat-02.frag Also, the concat-04.frag test now passes for the right reason. The test is intended to fail the compilation, but before this commit it was failing compilation (and hence passing the test) for the wrong reason. Reviewed-by: Kenneth Graunke <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glcpp: Test a non-function-like macro using the token paste operatorCarl Worth2011-09-302-0/+7
| | | | | | | | Apparently we never implemented this, (but we've got a GLSL 1.30 test in piglit that is exercising this case). Reviewed-by: Kenneth Graunke <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glcpp: Fix two (or more) successive applications of token pastingCarl Worth2011-09-301-2/+0
| | | | | | | | | | | | | | | | | There was already a loop here to look for multiple token pastes, but it was mistakenly incrementing the iterator counter after performing one paste. Instead, leave the loop iterator in place to coalesce as many tokens as necessary into one. This fixes the recently add 096-paste-twice test as well as the following piglit test: spec/glsl-1.30/preprocessor/concat/concat-03.frag Reviewed-by: Kenneth Graunke <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glcpp: Add a test for a macro that implements token pasting twice.Carl Worth2011-09-302-0/+7
| | | | | | | This is something that piglit is exercising that currently fails. Reviewed-by: Kenneth Graunke <[email protected]> Signed-off-by: Carl Worth <[email protected]>
* glsl 1.30: Fix numerical instabilities in asinhPaul Berry2011-09-281-4/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The formula we were previously using for asinh: asinh x = ln(x + sqrt(x * x + 1)) is numerically unstable: when x is a large negative value, the quantity x + sqrt(x * x + 1) is a small positive value (on the order of 1/(2|x|)). Since the logarithm function is very sensitive in this range, any error in the computation of the square root manifests as a large error in the result. This patch changes to the equivalent formula: asinh x = sign(x) * ln(abs(x) + sqrt(x * x + 1)) which is only slightly more expensive to compute, and is numerically stable for all x. Fixes piglit tests spec/glsl-1.30/execution/built-in-functions/[fv]s-asinh-*. Reviewed-by: Chad Versace <[email protected]> Acked-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Add support for constant expression evaluation on trunc().Eric Anholt2011-09-281-0/+2
| | | | | | | Fixes the glsl-1.30/compiler/built-in-functions/trunc-* tests under 1.30. Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix assertion checking types of constant bitshift expressions.Eric Anholt2011-09-281-1/+3
| | | | | | | | Bitshifts are one of the rare places that GLSL allows mixed base types without an implicit conversion occurring. Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix Android buildChad Versace2011-09-241-0/+1
| | | | | | Add lower_clip_distance.cpp to list of source files. Signed-off-by: Chad Versace <[email protected]>
* glsl: Free all S-Expressions immediately after reading IR.Kenneth Graunke2011-09-231-2/+3
| | | | | | | | | For some reason I thought subexpressions were chained off the top-level one. This isn't the case, so just create a temporary context and free it. All of this memory would be eventually freed, but now is freed much sooner. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Defer initialization of built-in functions until they're needed.Kenneth Graunke2011-09-234-3/+7
| | | | | | | | | | | | | | | Very simple shaders don't actually use GLSL built-ins. For example: - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - gl_FragColor = vec4(0.0); Both of the shaders used by _mesa_meta_glsl_Clear() also qualify. By waiting to initialize the built-ins until the first time we need to look for a signature, we can avoid the overhead entirely in these cases. Makes piglit run roughly 18% faster (255 vs. 312 seconds). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* mesa: set up gl_vert_result and gl_frag_attrib values for gl_ClipDistance.Paul Berry2011-09-231-4/+4
| | | | | | | | | | | | This patch assigns enumerated values for gl_ClipDistance in the gl_vert_result and gl_frag_attrib enums, so that driver back-ends can assign gl_ClipDistance to the appropriate hardware registers. It also adjusts the functions _mesa_vert_result_to_frag_attrib() and _mesa_frag_attrib_to_vert_result() (which translate between the two enums) to correctly translate the new enumerated values. Reviewed-by: Eric Anholt <[email protected]> Tested-by: Brian Paul <[email protected]>
* mesa: Add a flag to indicate whether a program uses gl_ClipDistance.Paul Berry2011-09-231-1/+4
| | | | | | | | | | | | | | | | | | GLSL 1.30 requires us to use gl_ClipDistance for clipping if the vertex shader contains a static write to it, and otherwise use user-defined clipping planes. Since the driver needs to behave differently in these two cases, we need a flag to record whether the shader has written to gl_ClipDistance. The new flag is called UsesClipDistance. We initially store it in gl_shader_program (since that is the data structure that is available when we check to see whethe gl_ClipDistance was written to), and we later copy it to a flag with the same name in gl_vertex_program, since that is a more convenient place for the driver to access it (in i965, at least). Reviewed-by: Eric Anholt <[email protected]> Tested-by: Brian Paul <[email protected]>
* glsl: Implement a lowering pass for gl_ClipDistance.Paul Berry2011-09-235-0/+350
| | | | | | | | | | | | | | | | | | | In i965 GEN6+ (and I suspect most other hardware), gl_ClipDistance needs to be laid out as a pair of vec4's (the first containing clip distances 0-3, and the second containing clip distances 4-7). However, it is declared in GLSL as an array of 8 floats. This lowering pass acts at the GLSL level, modifying the declaration of gl_ClipDistance so that it is an array of vec4's rather than an array of floats, and renaming it to gl_ClipDistanceMESA. In addition, it modifies all accesses to the array so that they access the appropiate component of one of the vec4's. Since some hardware may not internally represent gl_ClipDistance as a pair of vec4's, this lowering pass is optional. To enable it, set the LowerClipDistance flag in gl_shader_compiler_options to true. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl hierarchical visitor: Do not overwrite base_ir for parameter lists.Paul Berry2011-09-232-7/+17
| | | | | | | | | | | | | | This patch fixes a bug in ir_hirearchical_visitor: when traversing an exec_list representing the formal or actual parameters of a function, it modified base_ir to point to each parameter in turn, rather than leaving it as a pointer to the enclosing statement. This was a problem, since base_ir is used by visitor classes to locate the statement containing the node being visited (usually so that additional statements can be inserted before or after it). Without this fix, visitors might attempt to insert statements into parameter lists. Reviewed-by: Kenneth Graunke <[email protected]>
* make: Don't use builtin_stubs.cpp for standalone GLSL compiler.Kenneth Graunke2011-09-201-4/+4
| | | | | | | | | | | | | | | | builtin_stubs.cpp is only supposed to be used for builtin_compiler. It contains a stub version of _mesa_glsl_initialize_functions() that does nothing. libglsl.a already contains builtin_function.cpp, the generated file that contains a version of _mesa_glsl_initialize_functions() that actually initializes all the built-in functions. By mistakenly linking to builtin_stubs, glsl_compiler and glsl_test are unable to compile any shaders that use built-in functions. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Remove field array_lvalue from ir_variable.Paul Berry2011-09-144-32/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The array_lvalue field was attempting to enforce the restriction that whole arrays can't be used on the left-hand side of an assignment in GLSL 1.10 or GLSL ES, and can't be used as out or inout parameters in GLSL 1.10. However, it was buggy (it didn't work properly for built-in arrays), and it was clumsy (it unnecessarily kept track on a variable-by-variable basis, and it didn't cover the GLSL ES case). This patch removes the array_lvalue field completely in favor of explicit checks in ast_parameter_declarator::hir() (this check is added) and in do_assignment (this check was already present). This causes a benign behavioral change: when the user attempts to pass an array as an out or inout parameter of a function in GLSL 1.10, the error is now flagged at the time the function definition is encountered, rather than at the time of invocation. Previously we allowed such functions to be defined, and only flagged the error if they were invoked. Fixes Piglit tests spec/glsl-1.10/compiler/qualifiers/fn-{out,inout}-array-prohibited* and spec/glsl-1.20/compiler/assignment-operators/assign-builtin-array-allowed.vert. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Silence "ast_to_hir.cpp:1984:25: warning: comparison of unsigned ↵Ian Romanick2011-09-091-1/+1
| | | | | | | | | | | expression >= 0 is always true" ast_type_qualifier::location should have been a signed integer from the beginning, and the giant comment in apply_type_qualifier_to_variable explains why. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40207 Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Silence several "warning: unused parameter"Ian Romanick2011-09-098-0/+16
|
* glsl: Don't do structure splitting until link time.Eric Anholt2011-09-081-1/+1
| | | | | | | | | We were splitting on each side of an unlinked program, and the two sides lost track of which variables they referenced, resulting in assertion failure during validation. Fixes piglit link-struct-uniform-usage. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Clarify error message about whole-array assignment in GLSL 1.10.Eric Anholt2011-09-081-6/+25
| | | | | | | | | | | | | | | | | Previously, it would produce: Failed to compile FS: 0:6(7): error: non-lvalue in assignment and now it produces: Failed to compile FS: 0:5(7): error: whole array assignment is not allowed in GLSL 1.10 or GLSL ES 1.00. Also, add spec quotation to the two places we have code for array lvalues in GLSL 1.10. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: When assiging from a whole array, mark it as used.Eric Anholt2011-09-081-0/+1
| | | | | | Fixes piglit link-uniform-array-size. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Fix setting of OutputsWritten for whole array dereference.Eric Anholt2011-09-081-4/+2
| | | | | | | | We just want to mark the whole thing used, not mark from each element the whole size in use. Fixes undefined URB entry writes on i965, which blew up with debugging enabled. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Make sure gl_ClipDistance and gl_ClipVertex are not both written.Paul Berry2011-09-081-0/+19
| | | | | | | | | | | | | From section 7.1 (Vertex Shader Special Variables) of the GLSL 1.30 spec: "It is an error for a shader to statically write both gl_ClipVertex and gl_ClipDistance." Fixes piglit test mixing-clip-distance-and-clip-vertex-disallowed.c. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Check that gl_ClipDistance[] is not sized too large.Paul Berry2011-09-081-0/+15
| | | | | | | | | Fixes piglit tests clip-distance-explicit-too-large-with-access.{frag,vert} and clip-distance-explicit-too-large.{frag,vert}. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Rework oversize array check for gl_TexCoord.Paul Berry2011-09-081-12/+33
| | | | | | | | | | | | | The check now applies both when explicitly declaring the size of gl_TexCoord and when implicitly setting the size of gl_TexCoord by accessing it using integral constant expressions. This is prep work for adding similar size checks to gl_ClipDistance. Fixes piglit tests texcoord/implicit-access-max.{frag,vert}. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add constant gl_MaxClipDistances.Paul Berry2011-09-081-0/+15
| | | | | | | Fixes piglit tests {vs,fs}-clip-distance-sizeable-to-max.shader_test. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Make gl_ClipDistance[] implicitly sized.Paul Berry2011-09-081-4/+24
| | | | | | | | | | | | | | | From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special Variables): The gl_ClipDistance array is predeclared as unsized and must be sized by the shader either redeclaring it with a size or indexing it only with integral constant expressions. Fixes piglit tests clip-distance-implicit-length.vert, clip-distance-implicit-nonconst-access.vert, and {vs,fs}-clip-distance-explicitly-sized.shader_test. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: s/int/unsigned/ to silence warningBrian Paul2011-09-071-2/+2
|
* glsl/ir_reader: Make sure constants have the right number of components.Kenneth Graunke2011-09-071-0/+5
| | | | | | | | The list of numbers in (constant type (<numbers>)) needs to contain exactly type->components() numbers (16 for a mat4, 3 for a vec3, etc.) Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl/builtins: Fix invalid float constant in noise4 built-in.Kenneth Graunke2011-09-071-2/+2
| | | | | | | Throwing away the extra numbers ought to match the existing behavior. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl/builtins: Fix invalid vecN constants in hyperbolic functions.Kenneth Graunke2011-09-075-21/+21
| | | | | | | | | | Each of these vecN constants only provided one component, which is illegal. The printed IR is meant to contain exactly as many components as are necessary; the IR reader does not splat single values. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Use a separate div_to_mul_rcp lowering flag for integers.Bryan Cain2011-08-312-61/+77
| | | | | | | | | | | | | | Using multiply and reciprocal for integer division involves potentially lossy floating point conversions. This is okay for older GPUs that represent integers as floating point, but undesirable for GPUs with native integer division instructions. TGSI, for example, has UDIV/IDIV instructions for integer division, so it makes sense to handle this directly. Likewise for i965. Reviewed-by: Ian Romanick <[email protected]> Signed-off-by: Bryan Cain <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glcpp: Add GL_ARB_conservative_depth #define.Kenneth Graunke2011-08-251-1/+3
| | | | | | | Forgotten in the patch that enabled the extension. Reviewed-by: Ian Romanick <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: fix crash when a const is passed to texelFetchOffsetDave Airlie2011-08-251-0/+1
| | | | | | | while debugging texelFetchOffset we kept hitting the assert. Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>