summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* nir: Recognize a pattern for doing b2f without the opcode.Eric Anholt2015-04-011-0/+1
| | | | | | | Since we have patterns based on b2f, generate them if we see the b2f equivalent using an iand. This is common when generating NIR from TGSI. Reviewed-by: Connor Abbott <[email protected]>
* mesa: Make a shared header for 3D pipeline enum / #defines.Eric Anholt2015-04-012-1/+172
| | | | | | | | | | | | | | | | | | NIR uses these enums/#defines in nir_variables and associated intrinsics, but I want to be able to use them from TGSI->NIR and NIR->TGSI. Otherwise, we had to pull in all of mtypes.h. This doesn't cover all of the enums we might want from a shared compiler core (like varying slots or vert attribs), but it at least covers what I need at the moment (system values and interp qualifiers). v2: Move to src/glsl since util/ is really vague. Include in Makefile.am list. Use plain bitshifts and stdint types instead of undefined BITFIELD64_BIT. v3: Rename to shader_enums.h. Move it into Makefile.sources. Reviewed-by: Kenneth Graunke <[email protected]> (v2, with recommendation to rename)
* nir: add nir_builder.h to the tarballEmil Velikov2015-04-011-0/+1
| | | | | | | | | | | | | | The header was added with commit 2a135c470e3(nir: Add an ALU op builder kind of like ir_builder.h) but did not made it into to the sources list. Fortunately it remained unused until a recent commit faf6106c6f6(nir: Implement a Mesa IR -> NIR translator.) v2: Remove the bogus dependency. Tweak commit message. Signed-off-by: Emil Velikov <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Matt Turner <[email protected]>
* glsl: Remove bogus Makefile dependency.Matt Turner2015-03-311-2/+0
|
* glsl: Reassociate multiplication of mat*mat*vec.Matt Turner2015-03-311-0/+14
| | | | | | | | | | | | | | | | | | | The typical case of mat4*mat4*vec4 is 80 scalar multiplications, but mat4*(mat4*vec4) is only 32. On HSW (with vec4 vertex shaders): instructions in affected programs: 4420 -> 3194 (-27.74%) On BDW (with scalar vertex shaders): instructions in affected programs: 12756 -> 6726 (-47.27%) Implementing a general matrix chain ordering is harder (or at least tedious) because of having to walk the GLSL IR to create a list of multiplicands. I'm guessing that this patch handles 90+% of cases, but of course to tell definitively you'd have to implement the general thing. Reviewed-by: Chris Forbes <[email protected]>
* glsl: Implement type inferencing of matrix types.Matt Turner2015-03-311-4/+6
| | | | Reviewed-by: Chris Forbes <[email protected]>
* glsl: Factor out a get_mul_type() function.Matt Turner2015-03-313-57/+78
| | | | Reviewed-by: Chris Forbes <[email protected]>
* glsl: allow ForceGLSLVersion to override #version directivesBrian Paul2015-03-302-4/+8
| | | | | | | | | | | | Previously, the ctx->Const.ForceGLSLVersion setting only worked if the shader lacked a #version directive. Now, the ForceGLSLVersion setting will override the #version directive too. This change should be safe since it should be rare to have an app that has a mix of shader versions and we only wanted to override the #version for shaders which lacked the #version directive. Reviewed-by: Ilia Mirkin <[email protected]>
* glsl: fail when a shader's input var has not an equivalent out var in previousSamuel Iglesias Gonsalvez2015-03-301-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GLSL ES 3.00 spec, 4.3.10 (Linking of Vertex Outputs and Fragment Inputs), page 45 says the following: "The type of vertex outputs and fragment input with the same name must match, otherwise the link command will fail. The precision does not need to match. Only those fragment inputs statically used (i.e. read) in the fragment shader must be declared as outputs in the vertex shader; declaring superfluous vertex shader outputs is permissible." [...] "The term static use means that after preprocessing the shader includes at least one statement that accesses the input or output, even if that statement is never actually executed." And it includes a table with all the possibilities. Similar table or content is present in other GLSL specs: GLSL 4.40, GLSL 1.50, etc but for more stages (vertex and geometry shaders, etc). This patch detects that case and returns a link error. It fixes the following dEQP test: dEQP-GLES3.functional.shaders.linkage.varying.rules.illegal_usage_1 However, it adds a new regression in piglit because the test hasn't a vertex shader and it checks the link status. bin/glslparsertest \ tests/spec/glsl-1.50/compiler/gs-also-uses-smooth-flat-noperspective.geom pass \ 1.50 --check-link This piglit test is wrong according to the spec wording above, so if this patch is merged it should be updated. Signed-off-by: Samuel Iglesias Gonsalvez <[email protected]> Reviewed-by: Ben Widawsky <[email protected]>
* glsl: fix unreachable(!"") to unreachable("")Tapani Pälli2015-03-301-1/+1
| | | | | | | | Correct error with commit 151fb1e where assert was renamed to unreachable without removing ! from string argument. Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* nir: Fix copy and pasted error message in nir_validate.Kenneth Graunke2015-03-281-2/+1
| | | | | | | | | | These are nir_cf_nodes, not ALU instructions. Also, use unreachable() to preempt said review feedback. v2: Do it right (thanks Ilia). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Lower subtraction to add with negation when !lower_negate.Kenneth Graunke2015-03-271-0/+2
| | | | | | | | | | | prog->nir will generate fsub opcodes, but i965 doesn't implement them. We may as well lower them at the NIR level, since it's trivial to do. Suggested by Connor Abbott. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* nir: Add builder helpers for MOVs with ALU sources and swizzling MOVs.Kenneth Graunke2015-03-271-0/+44
| | | | | | | | | | These will be useful for prog->nir and tgsi->nir. v2: Don't forget to mark nir_swizzle as inline (Eric). Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* nir: Add nir_builder helpers for creating load_const intrinsics.Kenneth Graunke2015-03-271-0/+35
| | | | | | | | Both prog->nir and tgsi->nir will want to use these. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: mark uniform and input interface blocks as read onlyTimothy Arceri2015-03-281-0/+6
| | | | | Reviewed-by: Mark Janes <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* nir: Add optional lowering of flrp.Eric Anholt2015-03-272-0/+2
| | | | | Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
* nir: Add glsl_float_type() wrapper.Kenneth Graunke2015-03-252-0/+7
| | | | | Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Jordan Justen <[email protected]>
* glsl: Use INFINITY instead of std::numeric_limits<float>::infinity().Matt Turner2015-03-252-4/+4
| | | | Reviewed-by: Jose Fonseca <[email protected]>
* glsl: Constify ir_instruction::equalsIan Romanick2015-03-252-15/+26
| | | | | | | | v2: Don't be lazy. Constify the as_foo functions and use those instead of ugly casts. Suggested by Curro. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Francisco Jerez <[email protected]>
* glsl: Constify the as_foo functionsIan Romanick2015-03-251-0/+10
| | | | | | | | | Now that they're all implemented using macros, this is trivial. v2: Remove redundant parenthesis. Suggested by Curro. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Francisco Jerez <[email protected]>
* glsl: Implement remaining as_foo functions with macrosIan Romanick2015-03-251-31/+9
| | | | | | | | | | | | The downcast functions for non-leaf classes were previously implemented "by hand." Now they are implemented using macros based on the is_foo functions added in the previous patch. v2: Remove redundant parenthesis. Suggested by Curro (on the next patch). Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Francisco Jerez <[email protected]>
* glsl: Add is_rvalue, is_dereference, and is_jump methodsIan Romanick2015-03-251-0/+25
| | | | | | | | | | These functions deteremine when an IR node is one of the non-leaf classes. v2: Adjust indentation to line up. Suggested by Matt. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Francisco Jerez <[email protected]>
* nir: Fix typo.Matt Turner2015-03-241-1/+1
|
* nir: Recognize sat(add(b2f(a), b2f(b))) as a logical OR.Matt Turner2015-03-241-0/+1
| | | | | | | | | | | Transform this into b2f(or(a, b)). instructions in affected programs: 432 -> 430 (-0.46%) helped: 2 Acked-by: Ian Romanick <[email protected]> Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir: Recognize mul(b2f(a), b2f(b)) as a logical AND.Matt Turner2015-03-241-0/+2
| | | | | | | | | | | | Transform this into b2f(and(a, b)). total instructions in shared programs: 6205448 -> 6204391 (-0.02%) instructions in affected programs: 284030 -> 282973 (-0.37%) helped: 903 HURT: 6 Acked-by: Ian Romanick <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
* glsl: Recognize sat(add(b2f(a), b2f(b))) as a logical OR.Matt Turner2015-03-241-0/+12
| | | | | | Transform this into b2f(or(a, b)). Reviewed-by: Ian Romanick <[email protected]>
* glsl: Recognize mul(b2f(a), b2f(b)) as a logical AND.Matt Turner2015-03-241-0/+4
| | | | | | | | | | Transform this into b2f(and(a, b)). total instructions in shared programs: 6190291 -> 6189225 (-0.02%) instructions in affected programs: 267247 -> 266181 (-0.40%) helped: 866 Reviewed-by: Ian Romanick <[email protected]>
* nir: Handle mixed scalar/vector arguments to logical and/or/xor.Matt Turner2015-03-241-18/+21
| | | | Reviewed-by: Connor Abbott <[email protected]>
* glsl: Allow vector logic ops to be generated.Matt Turner2015-03-241-3/+3
| | | | | | | They're not accessible from the source language, but optimizations are allowed to generate them. Reviewed-by: Ian Romanick <[email protected]>
* glsl: add the remaining files to the tarballEmil Velikov2015-03-242-0/+2
| | | | | Signed-off-by: Emil Velikov <[email protected]> Reviewed-by: Matt Turner <[email protected]>
* glsl: Generate link error for non-matching gl_FragCoord redeclarationsAnuj Phogat2015-03-241-13/+2
| | | | | | | | | | | in different fragment shaders. This also applies to a case when gl_FragCoord is redeclared with no layout qualifiers in one fragment shader and not declared but used in other fragment shader. Signed-off-by: Anuj Phogat <[email protected]> Khronos Bug#12957 Cc: "10.5" <[email protected]> Reviewed-by: Chris Forbes <[email protected]>
* glsl: avoid calling base_alignment when samplers are involvedIlia Mirkin2015-03-242-9/+4
| | | | | | | | | | | | Earlier commit 53bf7c8fd2e changed the logic to always call base_alignment on structs. 1ec715ce8b12 hacked the function to return 0 for sampler fields, but didn't handle sampler arrays. Instead of extending the hack, avoid calling base_alignment in the first place on non-UBO uniforms. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=89726 Signed-off-by: Ilia Mirkin <[email protected]> Reviewed-by: Tapani Palli <[email protected]>
* glsl: fix names in lower_constant_arrays_to_uniformsTapani Pälli2015-03-231-3/+1
| | | | | | | | | | | | | | Patch changes lowering pass to use unique name for each uniform so that arrays from different stages cannot end up having same name. v2: instead of global counter, use pointer to achieve unique name (Kenneth Graunke) Signed-off-by: Tapani Pälli <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=89590 Reviewed-by: Chris Forbes <[email protected]> Cc: 10.5 10.4 <[email protected]>
* scons: Cleanup flex/bison settings specification.Jose Fonseca2015-03-221-8/+12
| | | | Reviewed-by: Brian Paul <[email protected]>
* glsl: Disable MSVC switch warning on a per-file basis.Jose Fonseca2015-03-221-0/+4
| | | | | | | | | | | | | This addresses ...\glsl_parser.cpp(...) : warning C4065: switch statement contains 'default' but no 'case' labels This is on code generated by bison, which we have little control. It seems useful to have this warning otherwise enabled. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Avoid GLboolean vs bool arithmetic MSVC warnings.Jose Fonseca2015-03-221-2/+3
| | | | | | | | | | | | | Note that GLboolean is an alias for unsigned char, which lacks the implicit true/false semantics that C++/C99 bool have. Reviewed-by: Brian Paul <[email protected]> v2: Change gl_shader::IsES and gl_shader_program::IsES to be bool as recommended by Ian Romanick. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Annotate as_foo functions that the this pointer cannot be NULLIan Romanick2015-03-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We use the idiom ir_foo *x = y->as_foo(); if (x == NULL) return; all over the place. GCC generates some quite lovely code for this. One such example: 340a5b: 83 7d 18 04 cmpl $0x4,0x18(%rbp) 340a5f: 0f 85 06 04 00 00 jne 340e6b 340a65: 48 85 ed test %rbp,%rbp 340a68: 0f 84 fd 03 00 00 je 340e6b This case used as_expression() (ir_type_expression is 4). Note that it checks the ir_type, then checks that the pointer isn't NULL. There is some disconnect in GCC around the condition in the as_foo functions. return ir_type == ir_type_##TYPE ? (ir_##TYPE *) this : NULL; \ It believes "this" could be NULL, so it emits check outside the function just for fun. This patch uses assume() to tell GCC that it need not bother with extra NULL checking of the pointer returned by the as_foo functions. text data bss dec hex filename 4836430 158688 26248 5021366 4c9eb6 i965_dri-before.so 4836173 158688 26248 5021109 4c9db5 i965_dri-after.so v2: Replace 'if (this == NULL) unreachable("this cannot be NULL")' with assume(this != NULL). Suggested by Ilia Mirkin. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
* nir/lower_io: Add a assign_locations function that sorts by [in]direct useJason Ekstrand2015-03-192-0/+75
| | | | | | | v2: Delete the set of indirectly accessed variables when we're done with it v3: Rename from _packed to _scalar Reviewed-by: Connor Abbott <[email protected]>
* nir/lower_io: Make variable location assignment a manual operationJason Ekstrand2015-03-192-12/+5
| | | | | | | | | | Previously, we just assigned variable locations in nir_lower_io. Now, we force the user to assign variable locations for us. This gives the backend a bit more control over where variables are placed. v2: Rename from _packed to _scalar Reviewed-by: Connor Abbott <[email protected]>
* nir: Use a list instead of a hash_table for inputs, outputs, and uniformsJason Ekstrand2015-03-196-35/+29
| | | | | | | | | | | | We never did a single hash table lookup in the entire NIR code base that I found so there was no real benifit to doing it that way. I suppose that for linking, we'll probably want to be able to lookup by name but we can leave building that hash table to the linker. In the mean time this was causing problems with GLSL IR -> NIR because GLSL IR doesn't guarantee us unique names of uniforms, etc. This was causing massive rendering isues in the unreal4 Sun Temple demo. Reviewed-by: Connor Abbott <[email protected]>
* mesa: Replace _mesa_round_to_even() with _mesa_roundeven().Matt Turner2015-03-183-15/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Eric's initial patch adding constant expression evaluation for ir_unop_round_even used nearbyint. The open-coded _mesa_round_to_even implementation came about without much explanation after a reviewer asked whether nearbyint depended on the application not modifying the rounding mode. Of course (as Eric commented) we rely on the application not changing the rounding mode from its default (round-to-nearest) in many other places, including the IROUND function used by _mesa_round_to_even! Worse, IROUND() is implemented using the trunc(x + 0.5) trick which fails for x = nextafterf(0.5, 0.0). Still worse, _mesa_round_to_even unexpectedly returns an int. I suspect that could cause problems when rounding large integral values not representable as an int in ir_constant_expression.cpp's ir_unop_round_even evaluation. Its use of _mesa_round_to_even is clearly broken for doubles (as noted during review). The constant expression evaluation code for the packing built-in functions also mistakenly assumed that _mesa_round_to_even returned a float, as can be seen by the cast through a signed integer type to an unsigned (since negative float -> unsigned conversions are undefined). rint() and nearbyint() implement the round-half-to-even behavior we want when the rounding mode is set to the default round-to-nearest. The only difference between them is that nearbyint() raises the inexact exception. This patch implements _mesa_roundeven{f,}, a function similar to the roundeven function added by a yet unimplemented technical specification (ISO/IEC TS 18661-1:2014), with a small difference in behavior -- we don't bother raising the inexact exception, which I don't think we care about anyway. At least recent Intel CPUs can quickly change a subset of the bits in the x87 floating-point control register, but the exception mask bits are not included. rint() does not need to change these bits, but nearbyint() does (twice: save old, set new, and restore old) in order to raise the inexact exception, which would incur some penalty. Reviewed-by: Carl Worth <[email protected]>
* nir/peephole_select: Allow uniform/input loads and load_constJason Ekstrand2015-03-171-0/+25
| | | | | | | | | | | | | | | | | | | Shader-db results on HSW: total instructions in shared programs: 4174156 -> 4157291 (-0.40%) instructions in affected programs: 145397 -> 128532 (-11.60%) helped: 383 HURT: 0 GAINED: 20 LOST: 22 There are two more tests lost than gained. However, comparing this with GLSL IR vs. NIR results, the overall delta is reduced from 85/44 gained/lost on current master to 71/32 with this commit. Therefore, I think it's probably a boon since we are getting "closer" to where we were before. Reviewed-by: Connor Abbott <[email protected]>
* nir/peephole_select: Copy instructions into the block before the ifJason Ekstrand2015-03-171-13/+20
| | | | | | | | | Previously we tried to do poor-man's copy propagation as we created the select instructions. Instead, this commit just moves the instructions from the blocks inside the if into the block before. Copy propagation will take care of making sure we don't have any extra mov's in there for us. Reviewed-by: Connor Abbott <[email protected]>
* nir/peephole_select: Rename are_all_move_to_phi and use a switchJason Ekstrand2015-03-171-25/+31
| | | | Reviewed-by: Connor Abbott <[email protected]>
* glsl: Expose built-in packing functions under GLSL 4.2.Matt Turner2015-03-131-1/+1
| | | | | | | | | | | | | | ARB_shading_language_packing is part of GLSL 4.2, not 4.0 as I mistakenly believed. The following functions are available only with ARB_shading_language_packing, GLSL 4.2 (not GLSL 4.0), or ES 3.0: - packSnorm2x16 - unpackSnorm2x16 - packHalf2x16 - unpackHalf2x16 Reviewed-by: Carl Worth <[email protected]> Reviewed-by: Marek Olšák <[email protected]>
* glsl: optimize (0 cmp x + y) into (-x cmp y).Samuel Iglesias Gonsalvez2015-03-131-3/+12
| | | | | | | | | | | | | The optimization done by commit 34ec1a24d did not take it into account. Fixes: dEQP-GLES3.functional.shaders.random.all_features.fragment.20 Signed-off-by: Samuel Iglesias Gonsalvez <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]> Cc: "10.4 10.5" <[email protected]>
* nir: Fix non-determinism in nir_lower_vars_to_ssa().Kenneth Graunke2015-03-121-97/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we stored derefs in a hash table, using the malloc'd pointer as the key. Then, we walked through the hash table and generated code, based on the order of the hash table's elements. Memory addresses returned by malloc are pretty much random, which meant that the hash was random, and the hash table's elements would be walked in some random order. This led to successive compiles of the same shader using different variable names and slightly different orderings of phi-nodes. Code could not be diff'd, and the final assembly would sometimes change slightly too. It turns out the only point of the hash table was to avoid inserting the same node multiple times for different dereferences. We never actually searched the hash table! This patch uses an intrusive linked list instead. Since exec_list uses head and tail sentinels, checking prev or next against NULL will tell us whether the node is already in the list. Pair programming with Jason Ekstrand. Signed-off-by: Jason Ekstrand <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Connor Abbott <[email protected]>
* util: Fix foreach_list_typed_safe when exec_node is not at offset 0.Jason Ekstrand2015-03-121-2/+2
| | | | | | | | | | | | | | | | | | | | __next and __prev are pointers to the structure containing the exec_node link, not the embedded exec_node. NULL checks would fail unless the embedded exec_node happened to be at offset 0 in the parent struct. v2: Jason Ekstrand <[email protected]>: Use "(__node)->__field.next != NULL" to check for the end of the list instead of the "&__next->__field != NULL". The former is far more obviously correct as it matches what the non-safe versions do. The original code tried to avoid any use of __next as the client code may delete it during its execution. However, since the looping condition is checked after the iteration clause but before the client code is executed, we know that __node is valid during the looping condition. Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Connor Abbott <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* nir: Add intrinsics for SYSTEM_VALUE_BASE_VERTEX and VERTEX_ID_ZERO_BASEKenneth Graunke2015-03-122-0/+8
| | | | | | | | | Ian and I added these around the time Connor was developing NIR. Now that both exist, we should make them work together! Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
* nir/worklist: Don't change the start index when computing the tail indexJason Ekstrand2015-03-112-7/+7
| | | | Reviewed-by: Mark Janes <[email protected]>