aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/lower_instructions.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: #include c99_math.h instead of core.hBrian Paul2015-02-261-1/+1
| | | | | | | We only need the M_LOG2E definition. Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Jose Fonseca <[email protected]>
* glsl: add lowering for double divide to rcp/mulDave Airlie2015-02-201-3/+4
| | | | | | | | It looks like no hw does div anyways, so we should just lower at the GLSL level. Reviewed-by: Ilia Mirkin <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
* glsl: remove bogus 'd' constant qualifiersIlia Mirkin2015-02-191-2/+2
| | | | | | | | | 0.0 is a double anyways. Apparently my version of gcc was happy with 0.0d as well, but this is not true of all compilers. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=89218 Signed-off-by: Ilia Mirkin <[email protected]>
* glsl: add a lowering pass for frexp/ldexp with double argumentsIlia Mirkin2015-02-191-1/+278
| | | | | Signed-off-by: Ilia Mirkin <[email protected]> Reviewed-by: Dave Airlie <[email protected]>
* glsl: lower double optional passes (v2)Dave Airlie2015-02-191-0/+175
| | | | | | | | | | | | These lowering passes are optional for the backend to request, currently the TGSI softpipe backend most likely the r600g backend would want to use these passes as is. They aim to hit the gallium opcodes from the standard rounding/truncation functions. v2: also lower floor in mod_to_floor Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* glsl/lower_instructions: add double lowering passesDave Airlie2015-02-191-0/+65
| | | | | | | This lowers double dot product and lrp to fma. Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* glsl: enable/disable certain lowering passes for doublesDave Airlie2015-02-191-3/+3
| | | | | | | | We want to restrict some lowering passes to floats only, and enable other for doubles. Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* glsl: Improve precision of mod(x,y)Iago Toral Quiroga2015-02-031-26/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, Mesa uses the lowering pass MOD_TO_FRACT to implement mod(x,y) as y * fract(x/y). This implementation has a down side though: it introduces precision errors due to the fract() operation. Even worse, since the result of fract() is multiplied by y, the larger y gets the larger the precision error we produce, so for large enough numbers the precision loss is significant. Some examples on i965: Operation Precision error ----------------------------------------------------- mod(-1.951171875, 1.9980468750) 0.0000000447 mod(121.57, 13.29) 0.0000023842 mod(3769.12, 321.99) 0.0000762939 mod(3769.12, 1321.99) 0.0001220703 mod(-987654.125, 123456.984375) 0.0160663128 mod( 987654.125, 123456.984375) 0.0312500000 This patch replaces the current lowering pass with a different one (MOD_TO_FLOOR) that follows the recommended implementation in the GLSL man pages: mod(x,y) = x - y * floor(x/y) This implementation eliminates the precision errors at the expense of an additional add instruction on some systems. On systems that can do negate with multiply-add in a single operation this new implementation would come at no additional cost. v2 (Ian Romanick) - Do not clone operands because when they are expressions we would be duplicating them and that can lead to suboptimal code. Fixes the following 16 dEQP tests: dEQP-GLES3.functional.shaders.builtin_functions.precision.mod.mediump_* dEQP-GLES3.functional.shaders.builtin_functions.precision.mod.highp_* Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add a pass to lower ir_unop_saturate to clamp(x, 0, 1)Abdiel Janulgue2014-08-311-0/+29
| | | | | | Signed-off-by: Abdiel Janulgue <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: add lowering passes for carry/borrowIlia Mirkin2014-05-021-0/+58
| | | | | Signed-off-by: Ilia Mirkin <[email protected]> Reviewed-by: Matt Turner <[email protected]>
* glsl: Use properly typed arguments for bitfieldInsert.Matt Turner2014-04-251-2/+2
| | | | | | | | bitfieldInsert takes scalar integers for its last two arguments. Since bitfieldInsert is lowered on i965 to two instructions that have more flexible arguments, I didn't notice when I wrote this. Reviewed-by: Ilia Mirkin <[email protected]>
* glsl: Delete LRP_TO_ARITH lowering pass flag.Kenneth Graunke2014-02-261-32/+0
| | | | | | | | | | | | | | Tt's kind of a trap---calling do_common_optimization() after lower_instructions() may cause opt_algebraic() to reintroduce ir_triop_lrp expressions that were lowered, effectively defeating the point. Because of this, nobody uses it. v2: Delete more code (caught by Ian Romanick). Cc: "10.1" <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Matt Turner <[email protected]> Acked-by: Eric Anholt <[email protected]>
* glsl: Use bitfieldInsert in ldexp() lowering.Matt Turner2014-01-271-4/+10
| | | | | | Shaves a few instructions off of lowered ldexp(). Reviewed-by: Ian Romanick <[email protected]>
* glsl: Remove silly OR(..., 0x0) from ldexp() lowering.Matt Turner2013-12-041-3/+1
| | | | | | I translated copysign(0.0f, x) a little too literally. Reviewed-by: Eric Anholt <[email protected]>
* glsl: Hide many classes local to individual .cpp files in anon namespaces.Eric Anholt2013-09-231-0/+4
| | | | | | | | This gives the compiler the chance to inline and not export class symbols even in the absence of LTO. Saves about 60kb on disk. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add ldexp_to_arith lowering pass.Matt Turner2013-09-171-0/+128
| | | | Reviewed-by: Paul Berry <[email protected]>
* glsl: Add a pass to lower bitfield-insert into bfm+bfi.Matt Turner2013-05-061-0/+39
| | | | | | | | | | i965/Gen7+ and Radeon/Evergreen+ have bfm/bfi instructions to implement bitfieldInsert() from ARB_gpu_shader5. v2: Add ir_binop_bfm and ir_triop_bfi to st_glsl_to_tgsi.cpp. Remove spurious temporary assignment and dereference. Reviewed-by: Chris Forbes <[email protected]>
* glsl: Convert mix() to use a new ir_triop_lrp opcode.Kenneth Graunke2013-02-281-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | Many GPUs have an instruction to do linear interpolation which is more efficient than simply performing the algebra necessary (two multiplies, an add, and a subtract). Pattern matching or peepholing this is more desirable, but can be tricky. By using an opcode, we can at least make shaders which use the mix() built-in get the more efficient behavior. Currently, all consumers lower ir_triop_lrp. Subsequent patches will actually generate different code. v2 [mattst88]: - Add LRP_TO_ARITH flag to ir_to_mesa.cpp. Will be removed in a subsequent patch and ir_triop_lrp translated directly. v3 [mattst88]: - Move changes from the next patch to opt_algebraic.cpp to accept 3-src operations. Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: fix unop/binop errors in commentsBrian Paul2012-07-031-2/+2
|
* glsl: Use a separate div_to_mul_rcp lowering flag for integers.Bryan Cain2011-08-311-55/+70
| | | | | | | | | | | | | | 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]>
* glsl: Fix type error when lowering integer divisionsPaul Berry2011-08-161-0/+4
| | | | | | | | | | | | | | | | | | | This patch fixes a bug when lowering an integer division: x/y to a multiplication by a reciprocal: int(float(x)*reciprocal(float(y))) If x was a plain int and y was an ivecN, the lowering pass incorrectly assigned the type of the product to be float, when in fact it should be vecN. This caused mesa to abort with an IR validation error. Fixes piglit tests {fs,vs}-op-div-int-ivec{2,3,4}. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Don't use MOD_TO_FRACT lowering on GLSL 1.30's % operator.Kenneth Graunke2011-06-291-1/+1
| | | | | | | | | | | | | MOD_TO_FRACT was designed to lower the GLSL 1.20 mod() function, which operates on floating point values. However, we also use ir_binop_mod for GLSL 1.30's % operator, which operates on integers. For now, make MOD_TO_FRACT only apply to floating-point mod operations. In the future, we may want to add a lowering pass for integer-based mod. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Fix DIV_TO_MUL_RCP lowering for uint result types.Kenneth Graunke2011-06-291-2/+7
| | | | | | | | f2i results in an int/ivec; we need i2u to get a uint/uvec. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Lower ir_binop_pow to a sequence of EXP2 and LOG2Ian Romanick2010-12-011-0/+26
|
* glsl: Use M_LOG2E constant instead of calling log2Ian Romanick2010-12-011-3/+3
|
* glsl: Combine many instruction lowering passes into one.Kenneth Graunke2010-11-191-0/+262
This should save on the overhead of tree-walking and provide a convenient place to add more instruction lowering in the future. Signed-off-by: Ian Romanick <[email protected]>