summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* glsl: convervative_depth is not allowed in the vertex shaderMarek Olšák2011-11-221-2/+2
| | | | | Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: finish up ARB_conservative_depth (v2)Marek Olšák2011-11-223-4/+16
| | | | | | | v2: updated an error message Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* mesa: rename the AMD_conservative_depth extension flag to ARBMarek Olšák2011-11-222-3/+3
| | | | | Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* linker: Remove erroneous multiply by 4 in uniform usage calculationIan Romanick2011-11-221-5/+5
| | | | | | | | | | | | | | | The old count_uniform_size::num_shader_uniforms was actually calculating the number of components used. Multiplying by 4 when setting gl_shader::num_uniform_components caused us to count 4x as many uniform components as were actually used. Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42930 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42966 Acked-by: Marek Olšák <[email protected]> Tested-by: Vinson Lee <[email protected]> Tested-by: Pavel Ondračka <[email protected]> Reviewed-and-tested-by: Kenneth Graunke <[email protected]>
* mesa: set the gl_FragDepth layout in the GLSL linkerMarek Olšák2011-11-191-0/+52
| | | | | Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: when cloning a variable, copy the depth layout tooMarek Olšák2011-11-191-0/+1
| | | | | | This fixes AMD_conservative_depth. Reviewed-by: Kenneth Graunke <[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: Always search for an exact function signature match.Kenneth Graunke2011-11-141-29/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we would fail to compile the following shader due to a bug in lazy built-in importing: #version 130 void main() { float f = abs(5.0); int i = abs(5); } The first call, abs(5.0), would fail to find a local signature, look through the built-ins, and import "float abs(float)". The second call, abs(5), would find the newly imported float signature in the local shader, and settle for that. Unfortunately, it failed to search the built-ins for the correct/exact signature, "int abs(int)". Thus, abs(5) ended up being a float, causing a bizarre type error when we tried to assign it to an int. Fixes piglit test builtin-overload-matching.frag. This is /not/ a candidate for stable branches, as it should only be possible to trigger this bug using GLSL 1.30's built-in functions that take integer arguments. Plus, the changes are fairly invasive. Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Split code to generate an ir_call out from match_function_by_name.Kenneth Graunke2011-11-141-165/+173
| | | | | | | | | | | | | | | | | | | | | | match_function_by_name performs two fairly separate tasks: 1. Hunt down the appropriate ir_function_signature for the callee. 2. Generate the actual ir_call (assuming we found the callee). Both of these are complicated. The first has to handle exact/inexact matches, lazy importing of built-in prototypes, different scoping rules for 1.10, 1.20+, and ES. Not to mention printing a user-friendly error message with pretty-printed "maybe you meant this" candidate signatures. The second has to deal with void/non-void functions, pre-call implicit conversions for "in" parmeters, and post-call "out" call conversions. Trying to do both in one function is just too unwieldy. Time to split. This patch purely moves the code to generate an ir_call into a separate function and reindents it. Otherwise, the code is identical. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Add a new matching_signature() variant that returns exact/inexact.Kenneth Graunke2011-11-142-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | When matching function signatures across multiple linked shaders, we often want to see if the current shader has _any_ match, but also know whether or not it was exact. (If not, we may want to keep looking.) This could be done via the existing mechanisms: sig = f->exact_matching_signature(params); if (sig != NULL) { exact = true; } else { sig = f->matching_signature(params); exact = false; } However, this requires walking the list of function signatures twice, which also means walking each signature's formal parameter lists twice. This could be rather expensive. Since matching_signature already internally knows whether a match was exact or not, we can just return it to get that information for free. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* linker: Validate resource usage in the linkerIan Romanick2011-11-141-0/+44
| | | | | | | | This is also done in ir_to_mesa and st_glsl_to_tgsi, but that code will be removed soon. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* linker: Count the number of uniform components used by a shader during linkingIan Romanick2011-11-141-2/+17
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* linker: Count the number of samplers used by a shader during linkingIan Romanick2011-11-141-1/+28
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add missing ';' in action statement.José Fonseca2011-11-141-1/+1
| | | | | | | Addresses the warnings: warning: a `;' might be needed at the end of action code warning: future versions of Bison will not add the `;'
* glcpp: Add GL_ARB_draw_instanced #define.Morgan Armand2011-11-121-0/+3
|
* mesa: Make gl_VertexID be a system value like gl_InstanceID.Eric Anholt2011-11-111-1/+1
| | | | Reviewed-by: Ian Romanick <[email protected]>
* glsl: Move builtin_variables.h into .cpp.Eric Anholt2011-11-112-111/+86
| | | | | | | This used to be script-generated, but now it's just a bunch of static variables in a .h file for no good reason. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Move ir_variable.cpp to builtin_variables.cpp.Eric Anholt2011-11-112-1/+1
| | | | | | It's only about builtins, not variables in general. Reviewed-by: Ian Romanick <[email protected]>
* glsl: Handle constant expressions involving ir_binop_equal/nequal.Kenneth Graunke2011-11-101-0/+6
| | | | | | | | | | | Constant expressions which called GLSL's equal() and notEqual() built-ins on bvecs would hit an assertion failure; we simply forgot to implement them for booleans. NOTE: This is a candidate for stable release branches. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[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: Assign transform feedback varying slots in linker.Paul Berry2011-11-091-63/+490
| | | | | | | | | | | | | | | | | | | | This patch modifies the GLSL linker to assign additional slots for varying variables used by transform feedback, and record the varying slots used by transform feedback for use by the driver back-end. This required modifying assign_varying_locations() so that it assigns a varying location if either (a) the varying is used by the next stage of the GL pipeline, or (b) the varying is required by transform feedback. In order to avoid duplicating the code to assign a single varying location, I moved it into its own function, assign_varying_location(). In addition, to support transform feedback in the case where there is no fragment shader, it is now possible to call assign_varying_locations() with a consumer of NULL. Reviewed-by: Marek Olšák <[email protected]> Tested-by: Marek Olšák <[email protected]>
* glsl: Clamp vector indices when lowering to swizzlesIan Romanick2011-11-091-2/+20
| | | | | | | | | | | | | This prevents other code from seeing a swizzle of the 16th component of a vector, for example. NOTE: This is a candidate for the 7.11 branch. Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42517 Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Paul Berry <[email protected]> Tested-by: Christian Holler <[email protected]>
* mesa,glsl,mapi: Put extern "C" { ... } where appropriate.José Fonseca2011-11-092-6/+9
| | | | | Probably a several places missing, but enough to cover all headers (in)directly included by uniform_query.cpp, and fix the MSVC build.
* glsl: remove trailing comma to silence warningBrian Paul2011-11-081-1/+1
|
* linker: Use app-specified fragment data location during linkingIan Romanick2011-11-081-7/+9
| | | | | | | | Fixes piglit's bindfragdata-link-error. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Generate IR for switch statementsDan McCabe2011-11-073-45/+254
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now modifying the GLSL compiler has been pretty straightforward. This is where things get interesting. But still pretty straightforward. Switch statements can be thought of a series of if/then/else statements. Case labels are compared with the value of a test expression and the case statements are executed if the comparison is true. There are a couple of aspects of switch statements that complicate this simple view of the world. The primary one is that cases can fall through sequentially to subsequent case, unless a break statement is encountered, in which case, the switch statement exits completely. But break handling is further complicated by the fact that a break statement can impact the exit of a loop. Thus, we need to coordinate break processing between switch statements and loop statements. The code generated by a switch statement maintains three temporary state variables: int test_value; bool is_fallthru; bool is_break; test_value is initialized to the value of the test expression at the head of the switch statement. This is the value that case labels are compared against. is_fallthru is used to sequentially fall through to subsequent cases and is initialized to false. When a case label matches the test expression, this state variable is set to true. It will also be forced to false if a break statement has been encountered. This forcing to false on break MUST be after every case test. In practice, we defer that forcing to immediately after the last case comparison prior to executing a case statement, but that is an optimization. is_break is used to indicate that a break statement has been executed and is initialized to false. When a break statement is encountered, it is set to true. This state variable is then used to conditionally force is_fallthru to to false to prevent subsequent case statements from executing. Code generation for break statements depends on whether the break statement is inside a switch statement or inside a loop statement. If it inside a loop statement is inside a break statement, the same code as before gets generated. But if a switch statement is inside a loop statement, code is emitted to set the is_break state to true. Just as ASTs for loop statements are managed in a stack-like manner to handle nesting, we also add a bool to capture the innermost switch or loop condition. Note that we still need to maintain a loop AST stack to properly handle for-loop code generation on a continue statement. Technically, we don't (yet) need a switch AST stack, but I am using one for orthogonality with loop statements, in anticipation of future use. Note that a simple boolean stack would have sufficed. We will illustrate a switch statement with its analogous conditional code that a switch statement corresponds to by examining an example. Consider the following switch statement: switch (42) { case 0: case 1: gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0); case 2: case 3: gl_FragColor = vec4(4.0, 3.0, 2.0, 1.0); break; case 4: default: gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } Note that case 0 and case 1 fall through to cases 2 and 3 if they occur. Note that case 4 and the default case must be reached explicitly, since cases 2 and 3 break at the end of their case. Finally, note that case 4 and the default case don't break but simply fall through to the end of the switch. For this code, the equivalent code can be expressed as: int test_val = 42; // capture value of test expression bool is_fallthru = false; // prevent initial fall through bool is_break = false; // capture the execution of a break stmt is_fallthru |= (test_val == 0); // enable fallthru on case 0 is_fallthru |= (test_val == 1); // enable fallthru on case 1 is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0); } is_fallthru |= (test_val == 2); // enable fallthru on case 2 is_fallthru |= (test_val == 3); // enable fallthru on case 3 is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(4.0, 3.0, 2.0, 1.0); is_break = true; // inhibit all subsequent fallthru for break } is_fallthru |= (test_val == 4); // enable fallthru on case 4 is_fallthru = true; // enable fallthru for default case is_fallthru &= !is_break; // inhibit fallthru on previous break if (is_fallthru) { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); } The code generate for |= and &= uses the conditional assignment capabilities of the IR. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Reference data structure ctors in grammarDan McCabe2011-11-073-16/+193
| | | | | | | | | | | | | | | | | We now tie the grammar to the ctors of the ASTs they reference. This requires that we actually have definitions of the ctors. In addition, we also need to define "print" and "hir" methods for the AST classes. The Print methods are pretty simple to flesh out. However, at this stage of the development, we simply stub out the "hir" methods and flesh them out later. Also, since actual class instances get returned by the productions in the grammar, we also need to designate the type of the productions that reference those instances. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Create AST structs corresponding to new productions in grammarDan McCabe2011-11-071-0/+59
| | | | | | | | | | | Previously we added productions for: switch_body case_label_list case_statement case_statement_list Now add AST structs corresponding to those productions. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add productions to GLSL grammar for switch statementDan McCabe2011-11-071-3/+61
| | | | | | | | | | | | | The grammar is modified to support switch statements. Rather than follow the grammar in the appendix, which allows case labels to be placed ANYWHERE as a regular statement, we follow the development of the grammar as described in the body of the GLSL spec. In this variation, the switch statement has a body which consists of a list of case statements. A case statement is preceded by a list of case labels and ends with a list of statements. Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Create AST data structures for switch statement and case labelDan McCabe2011-11-071-4/+20
| | | | | | | Data structures for switch statement and case label are created that parallel the structure of other AST data. Reviewed-by: Kenneth Graunke <[email protected]>
* Delete code made dead by previous uniform related patchesIan Romanick2011-11-071-152/+0
| | | | | Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* mesa: Rewrite the way uniforms are tracked and handledIan Romanick2011-11-071-1/+1
| | | | | | | | | | | | | | | | | | | | | Switch all of the code in ir_to_mesa, st_glsl_to_tgsi, glUniform*, glGetUniform, glGetUniformLocation, and glGetActiveUniforms to use the gl_uniform_storage structures in the gl_shader_program. A couple of notes: * Like most rewrite-the-world patches, this should be reviewed by applying the patch and examining the modified functions. * This leaves a lot of dead code around in linker.cpp and uniform_query.cpp. This will be deleted in the next patches. v2: Update the comment block (previously a FINISHME) in _mesa_uniform about generating GL_INVALID_VALUE when an out-of-range sampler index is specified. Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* linker: Track uniform locations to new tracking structuresIan Romanick2011-11-072-0/+98
| | | | | | | This is just the infrastructure and the code. It's not used yet. Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* linker: Add helper class for parcelling out backing storage to uniformsIan Romanick2011-11-071-0/+86
| | | | | Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* linker: Add helper class for determining uniform usageIan Romanick2011-11-071-0/+68
| | | | | | | | | | v2: Remane class count_uniform_size based on feedback from Eric: "Maybe just "count_uniform_size"? "usage" makes me think "way it's dereferenced" or something." Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* glsl: Add new structures for tracking uniforms in linked shadersIan Romanick2011-11-071-0/+125
| | | | | | | | | | | | | | v2: Update some comments based on feedback from Eric Anholt. v3: Remove gl_uniform_storage::dirty field. Make gl_uniform_storage::initialized be bool, and make gl_uniform_storage::sampler be uint8_t. v4: Include stdbool.h after Tom Stellard noticed a build failure that was introduced by the changes in v2. Oops. Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* linker: Make invalidate_variable_locations available outside the compilation ↵Ian Romanick2011-11-072-5/+9
| | | | | | | unit Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* glsl: Allow glsl_types.h to be included in C sourcesIan Romanick2011-11-071-8/+15
| | | | | | | | Some C code will want access to the glsl_base_type and glsl_sampler_dim enums in the near future. Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
* linker: Check that initializers for global variables matchIan Romanick2011-11-037-7/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This requires tracking a couple extra fields in ir_variable: * A flag to indicate that a variable had an initializer. * For non-const variables, a field to track the constant value of the variable's initializer. For variables non-constant initalizers, ir_variable::has_initializer will be true, but ir_variable::constant_initializer will be NULL. The linker can use the values of these fields to check adherence to the GLSL 4.20 rules for shared global variables: "If a shared global has multiple initializers, the initializers must all be constant expressions, and they must all have the same value. Otherwise, a link error will result. (A shared global having only one initializer does not require that initializer to be a constant expression.)" Previous to 4.20 the GLSL spec simply said that initializers must have the same value. In this case of non-constant initializers, this was impossible to determine. As a result, no vendor actually implemented that behavior. The 4.20 behavior matches the behavior of NVIDIA's shipping implementations. NOTE: This is candidate for the 7.11 branch. This patch also needs the preceding patch "glsl: Refactor generate_ARB_draw_buffers_variables to use add_builtin_constant" Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=34687 Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Paul Berry <[email protected]>
* glsl: Refactor generate_ARB_draw_buffers_variables to use add_builtin_constantIan Romanick2011-11-031-7/+4
| | | | | | | | v2: Remove int cast based on feedback from Ken. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Paul Berry <[email protected]>
* glsl: Put all bitfields in ir_variable together for better packingIan Romanick2011-11-031-8/+8
| | | | | | | | | The diff looks weird because ir_variable::depth_layout was between the last two bitfields in the structure. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Paul Berry <[email protected]>
* linker: Fix the indentation of a block in cross_validate_globalsIan Romanick2011-11-031-25/+32
| | | | | | | | I suspect the indentation got messed up during a code merge. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Paul Berry <[email protected]>
* glsl: add support for GL_OES_EGL_image_externalChia-I Wu2011-11-0315-1/+70
| | | | | | | | | | 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: Fix type mismatch when incrementing or decrementing uint.Paul Berry2011-11-021-8/+24
| | | | | | | | | | | When converting an expression like "++x" to GLSL IR we were failing to account for the possibility that x might be an unsigned integral type. As a result the user would receive a bogus error message "Could not implicitly convert operands to arithmetic operator". Fixes piglit tests {vs,fs}-{increment,decrement}-uint. Reviewed-by: Kenneth Graunke <[email protected]>
* scons: include src/glsl/Makefile.sourcesChia-I Wu2011-11-021-68/+14
| | | | Reviewed-by: Brian Paul <[email protected]>
* android: include src/glsl/Makefile.sourcesChia-I Wu2011-11-021-86/+10
| | | | | | | | | | This also fixes the build error due to missing link_uniforms.cpp in the source lists. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Chad Versace <[email protected]> [olv: the missing link_uniforms.cpp was added before this patch is committed]
* glsl: Refactor source lists to Makefile.sourcesChia-I Wu2011-11-022-73/+113
| | | | | | | | With the hope that Android.mk and SConscript can share the file to reduce future breakage. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Chad Versace <[email protected]>
* Build link_uniforms for androidEugeni Dodonov2011-11-011-0/+1
| | | | | | Otherwise android-x86 build fails. Signed-off-by: Eugeni Dodonov <[email protected]>