summaryrefslogtreecommitdiffstats
path: root/src/glsl
Commit message (Collapse)AuthorAgeFilesLines
* 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: Don't mark assignment temporaries as read-onlyIan Romanick2012-01-061-5/+0
| | | | | | | | | | | | | | | The various l-value errors this was designed to catch are now caught by other means. Marking the temporaries as read-only now just prevents sensible error messages from being generated. It's 0:0(0): error: function parameter 'out p' references the read-only variable '_post_incdec_tmp' versus 0:13(5): error: function parameter 'out p' references a post-decrement operation Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Emit extra errors for l-value violations in 'out' or 'inout' parametersIan Romanick2012-01-061-4/+59
| | | | | | | | | | Somethings, like pre-increment operations, were not previously caught. After the 8.0 release, this code needs some major refactoring and clean-up. It's a mess. :( Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42755
* glsl: Emit errors for assignments to non-l-value expressionsIan Romanick2012-01-061-7/+22
| | | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42755
* glsl: Track descriptions of some expressions that can't be l-valuesIan Romanick2012-01-063-0/+19
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Add a lowering pass to remove reads of shader output variables.Vincent Lejeune2012-01-063-0/+143
| | | | | | | | | This is similar to Gallium's existing glsl_to_tgsi::remove_output_read lowering pass, but done entirely inside the GLSL compiler. Signed-off-by: Vincent Lejeune <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
* mesa: Fix transform feedback of unsubscripted arrays.Paul Berry2012-01-051-45/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is not explicitly stated in the GL 3.0 spec that transform feedback can be performed on a whole varying array (without supplying a subscript). However, it seems clear from context that this was the intent. Section 2.15 (TransformFeedback) says this: When writing varying variables that are arrays, individual array elements are written in order. And section 2.20.3 (Shader Variables), says this, in the description of GetTransformFeedbackVarying: For the selected varying variable, its type is returned into type. The size of the varying is returned into size. The value in size is in units of the type returned in type. If it were not possible to perform transform feedback on an unsubscripted array, the returned size would always be 1. This patch fixes the linker so that transform feedback on an unsubscripted array is supported. Fixes piglit tests "EXT_transform_feedback/builtin-varyings gl_ClipDistance[{4,8}]-no-subscript" and "EXT_transform_feedback/output_type *[2]-no-subscript". Note: on back-ends that set gl_shader_compiler_options::LowerClipDistance (for example i965), tests "EXT_transform_feedback/builtin-varyings gl_ClipDistance[{1,2,3,5,6,7}]" still fail. I hope to address this in a later patch. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* mesa: Fix transform feedback of gl_ClipDistance.Paul Berry2012-01-051-18/+41
| | | | | | | | | | | | | | On drivers that set gl_shader_compiler_options::LowerClipDistance (for example i965), references to gl_ClipDistance (a float[8] array) will be converted to references to gl_ClipDistanceMESA (a vec4[2] array). This patch modifies the linker so that requests for transform feedback of gl_ClipDistance are similarly converted. Fixes Piglit test "EXT_transform_feedback/builtin-varyings gl_ClipDistance". Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Make tfeedback_decl::var_name a const char *.Paul Berry2012-01-051-1/+1
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Add gl_transform_feedback_info::ComponentOffset.Paul Berry2012-01-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using transform feedback, there are three circumstances in which it is useful for Mesa to instruct a driver to stream out just a portion of a varying slot (rather than the whole vec4): (a) When a varying is smaller than a vec4, Mesa needs to instruct the driver to stream out just the first one, two, or three components of the varying slot. (b) In the future, when we implement varying packing, some varyings will be offset within the vec4, so Mesa will have to instruct the driver to stream out an arbitrary contiguous subset of the components of the varying slot (e.g. .yzw or .yz). (c) On drivers that set gl_shader_compiler_options::LowerClipDistance, if the client requests that an element of gl_ClipDistance be streamed out using transform feedback, Mesa will have to instruct the driver to stream out a single component of one of the gl_ClipDistance varying slots. Previous to this patch, only (a) was possible, since gl_transform_feedback_info specified only the number of components of the varying slot to stream out. This patch adds gl_transform_feedback_info::ComponentOffset, which indicates which components should be streamed out. Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Fix extra memset in store_tfeedback_info()Paul Berry2012-01-051-4/+3
| | | | | | | | | | | | | | Commit 9d36c96d6ec9f2c05c8e0b9ef18c5462cddee8c1 (mesa: Fix glGetTransformFeedbackVarying()) accidentally added an extra memset() call to the store_tfeedback_info() function, causing prog->LinkedTransformFeedback.NumBuffers to be erased. This patch removes the extra memset and rearranges the other operations in store_tfeedback_info() to be in the correct order. Fixes piglit tests "EXT_transform_feedback/api-errors *unbound*" Reviewed-by: Eric Anholt <[email protected]>
* mesa: Fix glGetTransformFeedbackVarying().Eric Anholt2012-01-051-6/+34
| | | | | | | | | | The current implementation was totally broken -- it was looking in an unpopulated structure for varyings, and trying to do so using the current list of varying names, not the list used at link time. v2: Fix leaking of memory into the program per re-link. Reviewed-by: Paul Berry <[email protected]>
* glsl: rename VERSION to VERSION_TOK for automakeMatt Turner2012-01-042-3/+3
| | | | Signed-off-by: Matt Turner <[email protected]>
* mesa: Check that all buffers are bound in BeginTransformFeedback.Paul Berry2012-01-041-2/+5
| | | | | | | | | | | | | | | | | | | | | | | From the EXT_transform_feedback spec: The error INVALID_OPERATION is generated by BeginTransformFeedbackEXT if any transform feedback buffer object binding point used in transform feedback mode does not have a buffer object bound. This required adding a new NumBuffers field to the gl_transform_feedback_info struct, to keep track of how many transform feedback buffers are required by the current program. Fixes Piglit tests: - EXT_transform_feedback/api-errors interleaved_unbound - EXT_transform_feedback/api-errors separate_unbound_0_1 - EXT_transform_feedback/api-errors separate_unbound_0_2 - EXT_transform_feedback/api-errors separate_unbound_1_2 Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Don't use base type for bit-not when there's an errorIan Romanick2012-01-041-1/+1
| | | | | | | | | | | | | | | | | | | | Other parts of the compiler assume that expressions will have well-formed types or the error type. Just using the type of the thing being operated on can cause expressions like ~3.14 or ~false to not have a well-formed type. This could then result in an assertion failure in the context epxression handler. If there is an error processing the expression, set the type of the IR expression to error. Fixes piglit's bit-not-0[789].frag tests. 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=42755 Reviewed-by: Kenneth Graunke <[email protected]> Cc: Vinson Lee <[email protected]>
* glsl: fix usage of potentially undefined data_end unionAlexander von Gluck2011-12-301-1/+1
| | | | | Reviewed-by: Ian Romanick <[email protected]> Signed-off-by: Brian Paul <[email protected]>
* glsl: remove old autogen.shMatt Turner2011-12-231-12/+0
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Record transform feedback strides/offsets in linker output.Paul Berry2011-12-201-1/+4
| | | | | | | | | | | | | | | | | | | | | | This patch adds two new fields to the gl_transform_feedback_info struct: - BufferStride records the total number of components (per vertex) that transform feedback is being instructed to store in each buffer. - Outputs[i].DstOffset records the offset within the interleaved structure of each transform feedback output. These values are needed by the i965 gen6 and r600g back-ends, so it seems better to have the linker provide them rather than force each back-end to compute them independently. Also, DstOffset helps pave the way for supporting ARB_transform_feedback3, which allows the transform feedback output to contain holes between attributes by specifying gl_SkipComponents{1,2,3,4} as the varying name. Reviewed-by: Marek Olšák <[email protected]>
* glsl: Fix crashes caused by Bison error messages involving "'%'".Kenneth Graunke2011-12-131-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Invalid shaders containing the character % at an unexpected location would cause Bison to call yyerror with a message of: syntax error, unexpected '%' Bison expects yyerror() to take a string, while _mesa_glsl_error() is a printf-style function. This hit the classic printf string escape issue: _mesa_glsl_error(loc, state, "unexpected '%'"); // invalid! _mesa_glsl_error(loc, state, "%s", "unexpected '%'"); // correct. This caused assertion failures after ralloc_asprintf_append called vsnprintf to determine the length of the text that would be printed: vsnprintf would see the invalid format and return -1, an invalid length. The solution is to define a proper yyerror() wrapper function that calls _mesa_glsl_error with the "%s". Since we compile with -p "_mesa_glsl", yyerror is defined as: #define yyerror _mesa_glsl_error So we have to #undef yyerror in order to be able to declare it. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43564 Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Acked-by: Paul Berry <[email protected]>
* mesa: add const flags to skip MaxVarying and MaxUniform linker checks (v2)Marek Olšák2011-12-131-10/+33
| | | | | | | | | This is only temporary until a better solution is available. v2: print warnings and add gallium CAPs Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[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: return visit_stop in ir_validate::visit_enter() to silence warningBrian Paul2011-12-021-0/+1
|
* 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]>