summaryrefslogtreecommitdiffstats
path: root/src/glsl/builtins
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* texture_builtins.py: Generalize the "use_proj" field to support offsets.Kenneth Graunke2011-01-311-52/+57
| | | | | | | | Rather than passing "True", pass a bitfield describing the particular variant's features - either projection or offset. This should make the code a bit more readable ("Proj" instead of "True") and make it easier to support offsets in the future.
* texture_builtins.py: Refactor coordinate dimension calculations.Kenneth Graunke2011-01-311-5/+9
| | | | | For offsets, we'll want the straight sampler dimensionality, without the +1 for array types. Create a new function to do that; refactor.
* glsl: Change texel offsets to a single vector rvalue.Kenneth Graunke2011-01-311-1/+1
| | | | | | | | | | | Having these as actual integer values makes it difficult to implement the texture*Offset built-in functions, since the offset is actually a function parameter (which doesn't have a constant value). The original rationale was that some hardware needs these offset baked into the instruction opcode. However, at least i965 should be able to support non-constant offsets. Others should be able to rely on inlining and constant propagation.
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-4/+4
|
* generate_builtins.py: Whitespace fixes.Vinson Lee2011-01-141-7/+7
| | | | Also removed unnecessary semicolons.
* generate_builtins.py: Fix builds using Python 2.5.Vinson Lee2011-01-141-0/+2
|
* glsl/builtins: Remove unnecessary (constant bool (1)) from assignments.Kenneth Graunke2011-01-1212-269/+265
| | | | This isn't strictly necessary, but is definitely nicer.
* generate_builtins.py: Add missing import.Vinson Lee2011-01-121-0/+1
| | | | Import sys for sys.exit.
* glsl: Autogenerate builtin_functions.cpp as part of the build process.Kenneth Graunke2011-01-102-40/+9
| | | | | | Python is already necessary for other parts of Mesa, so there's no reason we can't just generate it. This patch updates both make and SCons to do so.
* glsl: Really remove unused "instructions" parameter.Kenneth Graunke2011-01-011-2/+1
| | | | | I forgot about this file, and it didn't show up until I tried to do "make builtins" from a clean build.
* glsl: Remove unused "instructions" parameter.Kenneth Graunke2011-01-011-4/+2
| | | | | | I think was used long ago, when we actually read the builtins into the shader's instruction stream directly, rather than creating a separate shader and linking the two. It doesn't seem to serve any purpose now.
* glsl/builtins: Compute the correct value for smoothstep(vec, vec, vec).Kenneth Graunke2010-12-171-87/+34
| | | | | | | | These mistakenly computed 't' instead of t * t * (3.0 - 2.0 * t). Also, properly vectorize the smoothstep(float, float, vec) variants. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Lazily import built-in function prototypes.Kenneth Graunke2010-11-301-1/+0
| | | | | | | | This makes a very simple 1.30 shader go from 196k of memory to 9k. NOTE: This -may- be a candidate for the 7.9 branch, as the benefit is substantial. However, it's not a simple change, so it may be wiser to wait for 7.10.
* glsl: Reimplement the "cross" built-in without ir_binop_cross.Kenneth Graunke2010-11-171-3/+5
| | | | | | We are not aware of any GPU that actually implements the cross product as a single instruction. Hence, there's no need for it to be an opcode. Future commits will remove it entirely.
* glsl: Implement the asinh, acosh, and atanh built-in functions.Kenneth Graunke2010-11-155-4/+79
|
* generate_builtins.py: Fix inconsistent use of tabs and spaces warning.Kenneth Graunke2010-11-151-3/+3
|
* glsl/builtins: Clean up some ugly autogenerated code in atan.Kenneth Graunke2010-11-031-20/+5
| | | | | | In particular, calling the abs function is silly, since there's already an expression opcode for that. Also, assigning to temporaries then assigning those to the final location is rather redundant.
* glsl/builtins: Rename 'x' to 'y_over_x' in atan(float) implementation.Kenneth Graunke2010-11-031-4/+4
| | | | For consistency with the vec2/vec3/vec4 variants.
* generate_builtins.py: Output large strings as arrays of characters.Kenneth Graunke2010-10-211-2/+14
| | | | | | This works around MSVC's 65535 byte limit, unfortunately at the expense of any semblance of readability and much larger file size. Hopefully I can implement a better solution later, but for now this fixes the build.
* glsl: Add support for GLSL 1.30's modf built-in.Kenneth Graunke2010-10-213-0/+51
|
* glsl: Add support for the 1.30 round() built-in.Kenneth Graunke2010-10-143-0/+31
| | | | | | | This implements round() via the ir_unop_round_even opcode, rather than adding a new opcode. We may wish to add one in the future, since it might enable a small performance increase on some hardware, but for now, this should suffice.
* glsl: Add front-end support for GLSL 1.30's roundEven built-in.Kenneth Graunke2010-10-143-0/+31
| | | | Implemented using the op-code introduced in the previous commit.
* glsl: Add front-end support for the "trunc" built-in.Kenneth Graunke2010-10-143-0/+31
|
* Drop GLcontext typedef and use struct gl_context insteadKristian Høgsberg2010-10-131-2/+2
|
* glsl: Rework assignments with write_masks to have LHS chan count match RHS.Eric Anholt2010-09-223-37/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turns out that most people new to this IR are surprised when an assignment to (say) 3 components on the LHS takes 4 components on the RHS. It also makes for quite strange IR output: (assign (constant bool (1)) (x) (var_ref color) (swiz x (var_ref v) )) (assign (constant bool (1)) (y) (var_ref color) (swiz yy (var_ref v) )) (assign (constant bool (1)) (z) (var_ref color) (swiz zzz (var_ref v) )) But even worse, even we get it wrong, as shown by this line of our current step(float, vec4): (assign (constant bool (1)) (w) (var_ref t) (expression float b2f (expression bool >= (swiz w (var_ref x))(var_ref edge)))) where we try to assign a float to the writemasked-out x channel and don't supply anything for the actual w channel we're writing. Drivers right now just get lucky since ir_to_mesa spams the float value across all the source channels of a vec4. Instead, the RHS will now have a number of components equal to the number of components actually being written. Hopefully this confuses everyone less, and it also makes codegen for a scalar target simpler. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl/builtins: Switch comparison functions to just return an expression.Kenneth Graunke2010-09-184-180/+36
|
* glsl/builtins: Fix equal and notEqual builtins.Kenneth Graunke2010-09-182-24/+24
| | | | | Commit 309cd4115b7cba669a0bf858e7809cb6dae90ddf incorrectly converted these to all_equal and any_nequal, which is the wrong operation.
* glsl2: Port equal() and notEqual() to ir_unop_all_equal and ir_unop_any_nequalIan Romanick2010-09-132-120/+24
|