summaryrefslogtreecommitdiffstats
path: root/src/glsl/builtins
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Fix pi/2 constant in acos built-in functionIan Romanick2012-06-131-4/+4
| | | | | | | | | | | | In single precision, 1.5707963 becomes 1.5707962513 which is too small. However, 1.5707964 becomes 1.5707963705 which is just right. The value 1.5707964 is already used in asin.ir. NOTE: This is a candidate for stable release branches. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Olivier Galibert <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: New unary opcodes for ARB_shader_bit_encoding support.Olivier Galibert2012-06-075-0/+106
| | | | | | | The opcodes are bitcast_f2u, bitcast_f2i, bitcast_i2f and bitcast_u2f. Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Scaffolding for ARB_shader_bit_encoding.Olivier Galibert2012-06-071-0/+1
| | | | | | | | That adds support for activating the extension. It doesn't actually *do* anything yet, of course. Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl/builtins: Fix textureGrad() for Array samplers.Kenneth Graunke2012-06-051-3/+3
| | | | | | | | | | | | We were incorrectly assuming that the coordinate's dimensionality is equal to the gradient's dimensionality. For array types, the coordinate has one more component. Fixes 12 subcases of oglconform's glsl-bif-tex-grad test. NOTE: This is a candidate for stable release branches. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Add implementation of inverse() for mat2/3/4.Eric Anholt2012-04-242-0/+110
| | | | | | | | | | | | This is taken from the ogl-math project, with Inverse renamed to adj (since it's not actually the inverse), transposed, and our types plugged in. There are potential CSE opportunities in this code (particularly for hardware with RCP but not DIV), but we should be doing CSE anyway, so don't hand-optimize. Fixes piglit inverse tests. Acked-by: Kenneth Graunke <[email protected]>
* glsl: Add support for generating builtin code from GLSL instead of IR.Eric Anholt2012-04-241-4/+16
| | | | | | | | This takes advantage of the builtin compiler to generate IR into a string, the same way we read GLSL for function prototypes for our profiles. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl/builtins: Rework profiles to use the new '.glsl' common suffix.Kenneth Graunke2012-04-1720-4807/+1902
| | | | | | | | | | | | | | | | | | | | Deletes a lot of pointless duplication, as well as some run-time effort. Conveniently, GLSL 1.40 no longer needs a .vert variant, since it doesn't define any built-ins specific to the vertex shader stage. ARB_texture_rectangle and OES_EGL_image_external also only need a single profile, since the .vert and .frag variants were identical. I didn't bother with EXT_texture_array and OES_texture_3D because they're so tiny that the savings would be miniscule. Cuts the generated builtin_function.cpp from 1.7MB to 1.0MB (41%). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Acked-by: Ian Romanick <[email protected]>
* glsl/builtins: Support stage-agnostic built-in profiles.Kenneth Graunke2012-04-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The built-in subsystem uses "profiles," or GLSL shaders containing prototypes for all built-ins supported within a particular language version (or extension) and shader stage. Since profiles were stage-specific, we had to cut and paste almost all the prototypes between (e.g.) 110.vert and 110.frag. Naturally, this led to sundry cut and paste bugs, where someone fixed an issue in .frag but neglected to update .vert, or vice-versa. Geometry shaders would have only made this worse. This patch introduces support for a new '.glsl' profile suffix which contains prototypes common to all shader stages. The existing '.frag' and '.vert' profiles need only contain the few stage-specific built-ins. Not only does this remove duplication, it makes built-in setup slightly faster: we don't need to re-read the common prototypes and function bodies for both the vertex and fragment shader stage. Internally, this was trivial. We already create a list of gl_shader objects to search through for built-ins: one for the core language version/stage, and additional shaders for any extensions in use. This patch simply adds another shader to the list: core/common, core/stage, and extensions. The next patch will update the profiles to remove the duplication. It's separated out purely to make review easier. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Acked-by: Ian Romanick <[email protected]>
* glsl/builtins: Use ivec for texel offsets in textureProjGradOffset.Kenneth Graunke2012-04-173-4/+4
| | | | | | | | | | | | | | | | | The GLSL 1.30 -> 4.10 specs all erroneously say "vec2" for a few overloads of textureProjGradOffset, while most overloads and all other texturing functions use ivec types. The GLSL 4.20 specification corrects these to "ivec2", but doesn't mention this as being a conscious change in behavior. Nor does the ARB_shading_language_420pack extension. So presumably it was a typo. At any rate, our builtin functions all use ivec already, so the fact that these prototypes use plain vecs will only lead to applications dying in a fire when trying to use them. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Add remaining *sampler2DRect* texture functions.Eric Anholt2012-04-163-0/+158
| | | | | | Fixes the new piglit texelFetch() tests on these. Note that the rest of the new functions are not tested (same as the non-2DRect versions of most of them).
* glsl: Fix the prototype of textureProjGradOffset(sampler2DShadow)Eric Anholt2012-04-161-1/+1
| | | | | | | Indirectly caught by Ken's review of my GLSL 1.40 changes where I copy-and-pasted this line. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add textureSize(*samplerBuffer) support.Eric Anholt2012-04-163-0/+9
| | | | | | Fixes the corresponding new tests in piglit. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Don't apply optimization passes to builtins.Eric Anholt2012-04-111-1/+1
| | | | | | The builtins we have are generally optimized, having been hand-written. This avoids generating bad code when an optimization pass prints debug output.
* glsl: Add texelFetch(*samplerBuffer) entrypoints to GLSL 1.40.Eric Anholt2012-04-093-4/+15
| | | | | | | | Fix texelFetch(sampler2DRect) and textureSize(samplerBuffer) generation to not reference a LOD at the same time because it's easier than not fixing it. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Convert ir_call to be a statement rather than a value.Kenneth Graunke2012-04-022-45/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Aside from ir_call, our IR is cleanly split into two classes: - Statements (typeless; used for side effects, control flow) - Values (deeply nestable, pure, typed expression trees) Unfortunately, ir_call confused all this: - For void functions, we placed ir_call directly in the instruction stream, treating it as an untyped statement. Yet, it was a subclass of ir_rvalue, and no other ir_rvalue could be used in this way. - For functions with a return value, ir_call could be placed in arbitrary expression trees. While this fit naturally with the source language, it meant that expressions might not be pure, making it difficult to transform and optimize them. To combat this, we always emitted ir_call directly in the RHS of an ir_assignment, only using a temporary variable in expression trees. Many passes relied on this assumption; the acos and atan built-ins violated it. This patch makes ir_call a statement (ir_instruction) rather than a value (ir_rvalue). Non-void calls now take a ir_dereference of a variable, and store the return value there---effectively a call and assignment rolled into one. They cannot be embedded in expressions. All expression trees are now pure, without exception. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: initialise const force glsl extension warning in fake ctxDave Airlie2012-03-251-0/+1
| | | | | | | | | valgrind complained about an uninitialised value being used in glsl_parser_extras.cpp, and this was the one it was giving out about. Just initialise the value in the fakectx. Signed-off-by: Dave Airlie <[email protected]>
* glsl: Add GLSL 1.40 textureSize() implementations for sampler2DRect.Eric Anholt2012-03-153-2/+19
| | | | | | | | | | | | | By setting lod to 0 in the builtin function implementation, we avoid needing to update all the visitors to ignore LOD in this case, when the hardware drivers actually want to ask for LOD 0 for rectangular textures. Fixes piglit spec/GLSL-1.40/textureSize-*Rect. v2: Change style of looking for substrings. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Set up generated builtin functions handling for GLSL 1.40.Eric Anholt2012-03-151-3/+3
| | | | | | | Otherwise, when we go to use ir_reader on the generated code, we won't have the types present. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Drop ftransform() from GLSL 1.40 profile.Eric Anholt2012-03-151-2/+0
| | | | | | | | | This is the one builtin function claimed to be dropped due to the ARB_compatibility split. Fixes piglit spec/GLSL-1.40/compiler/ftransform.vert Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Copy GLSL 1.30 builtin profile to GLSL 1.40.Eric Anholt2012-03-152-0/+1946
| | | | | | All that's changed is the #version changing to 140. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: When failing to compile some builtins, print the error.Eric Anholt2012-03-151-0/+8
| | | | | | | This makes the process slightly more debuggable, though it would be nice if the build just failed immediately instead. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl/builtins: Add missing mix(genType, genType, bvec) built-ins.Kenneth Graunke2012-01-063-1/+11
| | | | | | | | | | | | The IR for mix(float, float, bool) was missing a write mask, causing the IR reader to die horribly. Furthermore, I neglected to add any of the new prototypes to the 1.30 profiles. Fixes oglconform's glsl-bif-com advanced.mix test cases. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44477 Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Fix samplerCubeShadow support in shader compilerAnuj Phogat2011-12-071-1/+1
| | | | | | | | | | | This patch fixes the samplerCubeShadow support in GLSL shader compiler. shader compiler was picking the 'r' texture coordinate for shadow comparison when the expected behaviour is to use 'q' texture coordinate in case of cube shadow maps. Signed-off-by: Anuj Phogat <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add missing textureSize(samplerCubeShadow, int) variant.Kenneth Graunke2011-11-161-0/+1
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Remove textureGradOffset built-ins taking samplerCube parameters.Kenneth Graunke2011-11-103-9/+0
| | | | | | | | | These simply don't exist in the 1.30 specification---none of the Offset variants allow samplerCube. This must have been a cut and paste error from textureGrad, which /does/ allow cubemaps. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Fix misnamed textureProjOffset prototypes in built-in profiles.Kenneth Graunke2011-11-102-62/+62
| | | | | | | | Due to a cut and paste error, these were accidentally misnamed textureProj() rather than textureProjOffset(). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Remove texture built-ins with 'bias' from 1.30 VS profile.Kenneth Graunke2011-11-101-118/+4
| | | | | | | | | | | From the GLSL 1.30 spec, section 8.7 "Texture Lookup Functions": "In all functions below, the bias parameter is optional for fragment shaders. The bias parameter is not accepted in a vertex shader." This was a cut and paste mistake. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: add support for GL_OES_EGL_image_externalChia-I Wu2011-11-034-0/+20
| | | | | | | | | | This extension introduces a new sampler type: samplerExternalOES. texture2D (and texture2DProj) can be used to do a texture look up in an external texture. Reviewed-by: Brian Paul <[email protected]> Acked-by: Jakob Bornecrantz <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add isinf() and isnan() builtins.Paul Berry2011-10-314-4/+34
| | | | | | | | | | | | | The implementations are as follows: isinf(x) = (abs(x) == +infinity) isnan(x) = (x != x) Note: the latter formula is not necessarily obvious. It works because NaN is the only floating point number that does not equal itself. Fixes piglit tests "isinf-and-isnan fs_basic" and "isinf-and-isnan vs_basic".
* glsl: Add '.ir' extension to builtin IR filesPaul Berry2011-10-3166-3/+9
| | | | | | | | This patch adds the extension '.ir' to all the files in src/glsl/builtins/ir/, and changes generate_builtins.py so that it no longer globs on '*' to find the files to build. This prevents spurious files (such as EMACS' infamous *~ backup files) from breaking the build.
* 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: Defer initialization of built-in functions until they're needed.Kenneth Graunke2011-09-231-2/+4
| | | | | | | | | | | | | | | 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]>
* 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/builtins: Uncomment textureSize prototypes.Kenneth Graunke2011-08-232-4/+0
| | | | | | Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Dave Airlie <[email protected]>
* texture_builtins.py: Add support for textureSize (txs).Kenneth Graunke2011-08-231-14/+36
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: improve the accuracy of the atan(x,y) builtin function.Paul Berry2011-08-011-1/+3
| | | | | | | | | | The previous formula for atan(x,y) returned a value of +/- pi whenever |x|<0.0001, and used a formula based on atan(y/x) otherwise. This broke in cases where both x and y were small (e.g. atan(1e-5, 1e-5)). This patch modifies the formula so that it returns a value of +/- pi whenever |x|<1e-8*|y|, and uses the formula based on atan(y/x) otherwise.
* glsl: improve the accuracy of the asin() builtin function.Paul Berry2011-08-011-28/+40
| | | | | | | | | | | | | | | | | | | | | | | | The previous formula for asin(x) was algebraically equivalent to: sign(x)*(pi/2 - sqrt(1-|x|)*(A + B|x| + C|x|^2)) where A, B, and C were arbitrary constants determined by a curve fit. This formula had a worst case absolute error of 0.00448, an unbounded worst case relative error, and a discontinuity near x=0. Changed the formula to: sign(x)*(pi/2 - sqrt(1-|x|)*(pi/2 + (pi/4-1)|x| + A|x|^2 + B|x|^3)) where A and B are arbitrary constants determined by a curve fit. This has a worst case absolute error of 0.00039, a worst case relative error of 0.000405, and no discontinuities. I don't expect a significant performance degradation, since the extra multiply-accumulate should be fast compared to the sqrt() computation. Fixes piglit tests {vs,fs}-asin-float and {vs,fs}-atan-*
* glsl: improve the accuracy of the radians() builtin functionPaul Berry2011-07-281-4/+4
| | | | | | | | | | | The constant used in the radians() function didn't have enough precision, causing a relative error of 1.676e-5, which is far worse than the precision of 32-bit floats. This patch reduces the relative error to 1.14e-9, which is the best we can do in 32 bits. Fixes piglit tests {fs,vs}-radians-{float,vec2,vec3,vec4}. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl/builtins: Actually implement int/ivec variants of abs().Kenneth Graunke2011-06-141-0/+20
| | | | | | | Signed-off-by: Kenneth Graunke <[email protected]> NOTE: This is a candidate for stable release branches (and don't forget to re-run "make builtins" after cherry-picking.)
* glsl/generate_builtins.py: Remove regexp to kill pointer addresses.Kenneth Graunke2011-06-141-4/+0
| | | | | | | | | Commit 56ef62d9885f805bbfb2243dc860ff425d5b4d3b "glsl: Generate readable unique names at print time." changed ir_print_visitor to not generate @0x1234567 suffixes except where necessary. So there's no need to manually remove them. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Add compiler support for ARB_shader_texture_lod.Kenneth Graunke2011-05-093-0/+174
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Tested-by: Marek Olšák <[email protected]>
* glsl: Explicitly specify a type when reading/printing ir_texture.Kenneth Graunke2011-03-141-5/+6
| | | | | | This is necessary for GLSL 1.30+ shadow sampling functions, which return a single float rather than splatting the value to a vec4 based on GL_DEPTH_TEXTURE_MODE.
* texture_builtins.py: Add support for 130-style Shadow sampler variants.Kenneth Graunke2011-03-141-1/+53
|
* glsl: Enable GL_OES_texture_3D extension for ES2.Kenneth Graunke2011-02-282-0/+14
|
* glsl/builtins: Fix return type for textureSize sampler2DArray variants.Kenneth Graunke2011-02-272-4/+4
| | | | A copy and paste error.
* glsl: Fix use of uninitialized values in _mesa_glsl_parse_state ctor.Kenneth Graunke2011-02-011-0/+2
| | | | | | This has probably existed since e5e34ab18eeaffa465 or so. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* texture_builtins.py: Fix a warning about mixed tabs/spaces.Kenneth Graunke2011-01-311-1/+1
|
* glsl/builtins: Uncomment prototypes for texture*Offset functions.Kenneth Graunke2011-01-312-20/+0
|
* texture_builtins.py: Generate texture*Offset functions.Kenneth Graunke2011-01-311-5/+80
|