src/compiler/translator/BuildSPIRV.cpp


Log

Author Commit Date CI Message
Chris Dalton fa3d7d5c 2022-08-05T00:57:40 Make PLS coherent on Vulkan Uses the VK_EXT_fragment_shader_interlock extension to make the shader image implementation of PLS coherent on Vulkan. This extension is supported on AMD, Apple, NVIDIA, and Intel. Bug: angleproject:7279 Change-Id: Ic0253eb20932eb6be0b1f433ba454e48b57be2f5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3813816 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Chris Dalton <chris@rive.app> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Shahbaz Youssefi 6f80f0f0 2022-08-06T02:29:19 Translator: Clean up the compile flag passing interface Historically, compile flags were sent to the translator as a bitmask. Recently, we were getting close to running out of bits. Additionally, direct-to-metal work had started to introduce constants to be passed to the translator, which were misplaced in ShBuiltInResources and Caps. Recent work on Pixel Local Storage adds even more constants, aggravating the situation. In this change, the interface to passing compile flags is reworked. A struct is passed (instead of a bitmask) that has one bit for each flag. This can be indefinitely extended. Additionally, the constants needed by metal and PLS are also placed in this struct. In turn, the backends can set these options directly, and don't have to hack them into Caps to further get hacked into ShBuiltInResources. Bug: angleproject:7559 Change-Id: If93f1e1b8818ad3a0ac708ab04ab93b4b397d114 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3812562 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org>
Amirali Abdolrashidi 7fe0694c 2022-07-14T16:42:30 Vulkan: Use push constants for driver uniforms * Updated the driver uniforms so they would be defined as push constants in SPIR-V. Their data would be updated via pushConstants() when handling the driver uniform dirty bits. * Updated TOutputVulkanGLSL to be able to generate the push constants as required. * When handling the driver uniform dirty bits, we no longer allocate a buffer. * Removed the driver uniform descriptor set from the pipeline layout. * Removed the binding-related functions and flags for the driver uniforms. * In invalidateGraphicsDescriptorSet(), DIRTY_BIT_DESCRIPTOR_SETS is used instead of DIRTY_BIT_DRIVER_UNIFORMS_BINDING. (Same for invalidateComputeDescriptorSet()) * DIRTY_BIT_DRIVER_UNIFORMS_BINDING is replaced with DIRTY_BIT_DRIVER_UNIFORMS in other places. * Removed mDriverUniform and DriverUniformsDescriptorSet from ContextVk. * Added mSupportedVulkanShaderStageMask to RendererVk, which is used in creating the pipeline layout and updating the push constants. * Added a TODO note for driverUniformsDescriptorSetIndex. Bug: angleproject:6858 Change-Id: I91037d378528962a816b12ff3f21249ee17b7652 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3782570 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Lingfeng Yang 3ccaddf9 2022-07-26T10:02:01 Vulkan: EXT_YUV_target: layout(yuv) support This CL adds support for layout(yuv) in the shader, via a new decoration. The SPIRV decoration enum number is WIP and depends on final spec. The decoration is only active if enabled via a flag in ShaderLang, which will be connected with the feature supports_yuv_target in a future CL. Bug: b/223456677 Change-Id: I29a724e689d1336a3e42c83d7afa944a11e07353 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3765890 Auto-Submit: Lingfeng Yang <lfy@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Lingfeng Yang <lfy@google.com>
Shahbaz Youssefi 73019ede 2022-05-27T14:15:51 Vulkan: SPIR-V Gen: No RelaxedPrecision on bitCount() and findLSB() Similarly to findMSB(), RelaxedPrecision shouldn't be applied to these instructions. They return lowp, but RelaxedPrecision affects the parameters as well. Bug: b/234143723 Change-Id: Iab7c1c0497bbc832569ced7456eaefbf52d796d6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3672847 Reviewed-by: Chia-I Wu <olv@google.com> Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 98c2e169 2022-05-20T16:17:49 Vulkan: Reduce pre-rotation spec const to bool The specialization constant now only dictates whether x and y should be swapped. The complete 8 possible states of rotation and y-flip are achieved by using this swap in combination with a driver uniform for x and y flip. Swapping is still a specialization constant to avoid degrading performance of dFdx/dFdy which otherwise would need both to be evaluated instead of one. On platforms which don't support pre-rotation, the specialization constant will never change and driver uniforms entirely govern y-flip. On platforms that do support pre-rotation, only two variations of the pipeline are needed. Bug: angleproject:7366 Change-Id: I73f84e89fa9349d2098fa5b21573aee57d93a30c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3663151 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Lingfeng Yang <lfy@google.com> Reviewed-by: Charlie Lao <cclao@google.com>
Amirali Abdolrashidi fea19567 2022-05-17T17:44:06 Vulkan: Remove removeEarlyFragmentTestsOpt flag * Removed removeEarlyFragmentTestsOptimization and the related SPIRV transformation and variables. * Removed mUsesEarlyFragmentTestsOptimization. * Removed SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION. * Merged updateUsesEarlyFragmentTestsOptimization() into updateFragmentInoutRange(). Bug: angleproject:7347 Change-Id: I7299bd4e8ab5363e5cf06eb48419d4f469106e12 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3648217 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com>
Shahbaz Youssefi 62fe36d3 2022-05-04T22:46:52 Vulkan: Emulate YUV built-ins In this change, the rgb_2_yuv and yuv_2_rgb built-ins are emulated with normal functions that perform matrix multiplication based on the given conversion function. Bug: angleproject:6818 Change-Id: I67adb029109aaf6a674b1ee75105c1b352325eb2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3630599 Reviewed-by: Shahbaz Youssefi <syoussefi@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 0f00fbae 2022-01-21T00:28:48 Translator: Make vec/matrix size getters unsigned TType stored type's primary and secondary sizes as `unsigned char`, but the getters returned `int`. This caused unnecessary casts when the size was passed from one TType to another, as well as comparisons with other unsigned numbers. This change specifies the type of these members as `uint8_t` and makes the getters return the same type. The call sites are accordingly adjusted to remove unnecessary casts, use the correct type in local variables, and add casts when passed to ostream::operator<<. Bug: angleproject:6755 Change-Id: Ia4d86bd4ccb5c1a2ae1e10a0085a5166c3a6bcf7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3402850 Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 7d33e71a 2021-11-15T11:20:25 Vulkan: SPIR-V Gen: Don't generate names for constants Multiple constant variables can have the same value, and they are coalesced to the same SPIR-V id. It's not useful to attempt to generate multiple constants with different names, especially as those names don't make it into the SPIR-V-Cross-generated GLSL. Additionally, most constants in the translator don't retain their name, only the ones that are not folded do (and which are folded is a rather arbitrary decision). By generating names for these constants, the SPIR-V gen code was introducing a bug where multiple OpNames could be generated for the same OpConstant* id. This change removes OpNames generated for constants in the first place. Bug: angleproject:6644 Change-Id: Ife2f4bee8e2eb095dc0b22994420ee1dfc6023c6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3282425 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com>
Shahbaz Youssefi b3d77208 2021-10-14T15:38:51 Vulkan: SPIR-V Gen: Make unfolded constants SPIR-V constants If a constant is not folded by the translator, for example because it's an array, this change makes sure that it becomes a constant in SPIR-V anyway. This is particularly important to support cases where a constant is required, for example as argument to textureGatherOffsets(). Bug: angleproject:4889 Bug: angleproject:5362 Change-Id: Ic43e4be13a8917bb100ea64902ba90048cfbb9ee Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3223642 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi f3d5dac3 2021-08-23T17:25:15 Vulkan: SPIR-V Gen: Drop dependency to glslang The SPIR-V gen path is now made default. Compilation through glslang is still supported for debugging, and is enabled on the GLSL* end2end tests for smoke testing. On release builds, glslang is not supported. To test with glslang, add the following gn arg (only necessary if dcheck is disabled): angle_enable_spirv_gen_through_glslang = true Then enable the generateSPIRVThroughGlslang feature. This can be done by setting an environment variable: ANGLE_FEATURE_OVERRIDES_ENABLED=generateSPIRVThroughGlslang ./angle_deqp_gles2_tests Binary size saving: - 1.3MB on Linux (SPIR-V gen itself: 240KB) - 730KB on Android (SPIR-V gen itself: 140KB) Perf tests: - LinkProgramBenchmark.Run/vulkan_compile_single_thread * Through glslang: truncated mean: 1287033.36 * Direct SPIR-V Gen: truncated mean: 244495.91 (~80% reduction) - LinkProgramBenchmark.Run/vulkan_compile_multi_thread * Through glslang: truncated mean: 4565894.83 * Direct SPIR-V Gen: truncated mean: 1158164.10 (~75% reduction) Bug: angleproject:4889 Bug: angleproject:6210 Change-Id: I486342702977c8114e90073b97183aba115a8b2d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3115140 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 9112b1a9 2021-09-13T15:39:53 Vulkan: SPIR-V Gen: Fix precision of findMsb In GLSL, findMsb operates on a highp operand, while returning a lowp result. In SPIR-V, RelaxedPrecision cannot be applied on the FindSMsb instruction as that affects the operand as well. This change makes sure RelaxedPrecision is not applied to a FindSMsb instruction. Bug: angleproject:4889 Bug: angleproject:6132 Change-Id: I6a0defbbd53ec703c7ecbad5cd5c79d215b11c32 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3158506 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 1ce78397 2021-07-30T16:51:45 Remove support for WEBGL_debug_shader_precision This extension was rejected, and the implementation was hacky. This clean up is part of an ongoing work to improve precision handling. Bug: angleproject:6059 Change-Id: If08581ec6f19cf1698ffa3dd6d248dc5e68a1d31 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3064303 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 3036e090 2021-07-29T15:55:39 Vulkan: Direct SPIR-V Gen: Support the precise keyword The precise keyword is different in GLSL in that it defines what arithmetic operations _that have led to the value being assigned to a variable_ should be done precisely (i.e. not "contracted"). A tree traverser is implemented that detects precise access chains and applies precise-ness to the right hand side of assignment expressions to said access chains. This is only done if the shader uses the precise keyword in the first place. The algorithm for this is inspired by the implementation in glslang. This change additionally: - Fixes parser to allow precise on function parameters - Fixes GLSL code generation to output precise on struct members and function parameters. Bug: angleproject:4889 Change-Id: Ie3808c3c8c08da308e88af20f5f90379d9d14d47 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3056369 Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi dbe986d7 2021-07-26T01:43:44 Vulkan: SPIR-V Gen: Fixes to tessellation shader support - TCS barrier() built-in is correctly looked up - Patch decorations are fixed Bug: angleproject:4889 Change-Id: I1befcaca85a965c9d46b1b41ec74597de44bf2b2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3052687 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 63fa7080 2021-07-25T23:19:02 Vulkan: SPIR-V Gen: Fix bugs with ES3.1 texture* builtins - Add missing ImageCubeArray capability for image cube arrays - Remove extra Lod image operand for sampler/image buffers Bug: angleproject:4889 Change-Id: I96545092528b7dcecf902561e194b17636217ef4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3052683 Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 715bab1f 2021-07-25T23:35:17 Vulkan: SPIR-V Gen: Fixes to geometry shader support - max_vertices=0 is invalid in SPIR-V and is fixed (similarly to anglebug.com/5411) - gl_PrimitiveID used in fragment shaders requires the Geometry capability. Bug: angleproject:4889 Change-Id: If8c6a9d455d0582d61c3c52b5f773bcb5ca64b53 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3052684 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi b19fbbda 2021-07-25T21:57:12 Vulkan: SPIR-V Gen: Support multiview Bug: angleproject:4889 Change-Id: Ibe66f53357473dbb4435af58775b524d83ed250b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3052675 Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 9416e84e 2021-07-23T14:53:43 Vulkan: SPIR-V Gen: Add missing DepthReplacing execution mode Shaders writing to gl_FragDepth need this execution mode specified. Bug: angleproject:4889 Change-Id: I315c90f9161f4d3d51b1c856f1364fb26a4bd404 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3048317 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi cc69d861 2021-07-22T12:49:39 Vulkan: SPIR-V Gen: Fix textureProj's coordinate adjustment The OpCompositeInsert's parameters were given in the wrong order. Additionally, some instructions were not having RelaxedPrecision applied correctly; this is fixed by deriving the decorations from the type of the argument that's passed in a function instead of the type of the parameter itself. Bug: angleproject:4889 Change-Id: I34a54fcc0ef1699e554f9e1abb94c93a5b34b6d3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3046102 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 9f7a86a8 2021-07-21T14:54:03 Vulkan: SPIR-V Gen: Fix bugs with matrix ops A number of matrix operations are fixed in this change, such as matrix/scalar, ++matrix etc. This change fixes most of the failing dEQP-GLES2.* tests. The test suite will be enabled once the remaining 32 failures are fixed. Bug: angleproject:4889 Change-Id: I0905dfaeabe50716432ce354b890be35f2a16e59 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3042555 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 45d4641a 2021-07-21T10:58:29 Vulkan: SPIR-V Gen: Support tessellation shaders Bug: angleproject:4889 Change-Id: I7370e037a82689260e27bfd5e72c5c8c982efa58 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3041624 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 7f199d75 2021-07-20T00:11:23 Vulkan: SPIR-V Gen: Support geometry shaders Geometry shader built-ins are implemented. A bug in DeclarePerVertexBlocks is fixed w.r.t to gl_PerVertex arrays and a new AST validation option is added to catch that sort of error. Bug: angleproject:4889 Change-Id: I40b2929e450eac8ae840bbf1a1583e6c4c047c88 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3041623 Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 6e261453 2021-07-20T22:34:33 Vulkan: SPIR-V Gen: Fix I/O block arrays Since the qualifier on intermediate nodes are EvqTemporary, the code that autodeduced the block storage of I/O blocks was incorrectly assigning them std140 when an indexed I/O block array was encountered. This resulted in duplicate types in the SPIR-V. This is generally benign (other than creating an unnecessary type) except for gl_PerVertex as it adds BuiltIn decorations. gl_PerVertex may be an array in geometry and tessellation shaders. Bug: angleproject:4889 Change-Id: Iaa8e414ae01a4be127dc52df0e9406546b23d24c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3041621 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi e9decf0c 2021-07-19T14:29:21 Vulkan: SPIR-V Gen: Support framebuffer fetch Bug: angleproject:4889 Change-Id: Ia75b45b5d0f6cb3b6ca8a8f8a987bb857e45ad33 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3040120 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi a8807cbf 2021-07-17T00:00:27 Vulkan: SPIR-V Gen: Support interpolateAt* The interpolateAt* builtins take their first argument as a pointer, so only the OpAccessChain result should be given to the corresponding SPIR-V instruction. A test is written in this change to handle interpolateAt* when given a swizzled lvalue, which is not representable in SPIR-V. This can be supported by having the AST transform: interpolateAtX(value.zy) to: interpolateAtX(value).zy which can be done right when the function is parsed and the AST node for it is created (by taking the swizzle out of the parameter and applying it to the node). However, swizzled lvalues as parameter to interpolateAt* is only allowed in desktop GLSL, and so the test is disabled. From the GLSL ES3.2 spec: > Component selection operators (e.g. .xy) may not be used when > specifying interpolant. Bug: angleproject:4889 Change-Id: I043969f22011e6171c7ae225ded3a5013e8cfa4e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3035588 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi f4ce6d00 2021-07-15T11:07:25 Vulkan: SPIR-V Gen: Support bool in interface blocks SPIR-V doesn't allow bool in interface blocks. Another type specialization is added for this purpose, turning those bools to uint. Bug: angleproject:4889 Change-Id: I803bffcf5ea58c913d4df6e7aae3386c67901b25 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3032021 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 9c6fb52c 2021-07-13T14:10:41 Vulkan: SPIR-V Gen: Assignment between mismatching SPIR-V types In general, GLSL qualifiers translate to SPIR-V decorations on SPIR-V variables. In the case of blocks (struct or interface block), OpMemberDecorate is used, which due to its specification in SPIR-V, can only apply decorations to direct members of a block. This makes it impossible for example to decorate a nested member of a block through its variable id. As such, some decorations such as RowMajor and Invariant apply to members of a block given its _type_ id. Unfortunately SPIR-V requires ArrayStride to also be applied to a type directly, rather than a member of a block. This implies that some types, such as structs used in uniform/buffer interface block, or decorated with invariant or row_major, as well as arrays (of any type) used inside and outside interface blocks to produce different SPIR-V types from the same GLSL type. The SpirvTypeSpec data previously introduced specialize these types. It's necessary to "cast" between these types when needed. The translator handles casts at load/store boundary: - Upon load, the value is cast to the type with the default SpirvTypeSpec. - Upon store, the value is cast from the default to the store target SpirvTypeSpec. - All intermediate results use the default SpirvTypeSpec. Bug: angleproject:4889 Change-Id: I6fa28e518ec6b517ff163f44b6892859eb4b10fd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3026145 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 5e579a18 2021-07-13T01:22:48 Vulkan: SPIR-V Gen: Support row-major blocks The SPIR-V type generation is refactored to contain all type-differentiating properties in a specific struct that is passed around. The following can lead to different SPIR-V types generated from the same GLSL type: - Block storage for blocks - Invariant for blocks - Row-major for blocks with matrices - Row-major for matrix arrays in blocks - Bool when used inside an interface block (not yet implemented) Previously, block storage and invariant were passed around. Instead, with this change the aggregate of all the above is passed around. The row-major specialization is added in this change. This change also refactors the uniform/buffer block encoding to use the existing encoders in blocklayout.h. Bug: angleproject:4889 Change-Id: I3cfa8bd96bb380a1f1f05fbbd6b3eebd702c9e24 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3021670 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 3dda3afa 2021-07-14T16:11:01 Vulkan: SPIR-V Gen: Add missing SampleRateShading capability Bug: angleproject:4889 Bug: chromium:1229324 Change-Id: I8782ea4b0f9967c12b205a8c48d5f85bd94e950c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3027044 Reviewed-by: Kenneth Russell <kbr@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 07c39616 2021-07-08T17:01:31 Vulkan: SPIR-V Gen: Enable GLSLTest* This change includes an assortment of small fixes to enable most of GLSLTest* end2end tests. - User-defined std140 storage buffers were mistakenly turned to std430. - External and WEBGL samplers were redundantly redeclaring the sampler2D type. - `invariant` specified on a field of struct type didn't apply it to said struct's members. - Arrays of struct as a member of an interface block didn't have their size aligned, producing incorrect stride - Interpolation and auxiliary qualifiers are now generated - Arrays of opaque uniforms are now correctly passed to functions when indexed. - atan(x, y)'s built-in Op is fixed - early_fragment_tests is now generated Additionally, the SPIR-V transformer didn't handle the Invariant decoration applied to gl_PerVertex built-ins, which is possible as a result of: #pragma STDGL invariant(all) This bug existed in the transformer due to two bugs: - ANGLE didn't generate this line when generating GLSL to feed to glslang. This is fixed by this change. - glslang itself ignores this line: https://github.com/KhronosGroup/glslang/issues/2689 Bug: angleproject:4889 Change-Id: I15ad9fcc178abc1eae944e7a58f4e6153fa5dfd9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3016762 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi c6784c9c 2021-07-09T16:48:55 Vulkan: SPIR-V Gen: Fix size of matrix in std140 layout Matrices are treated like arrays, so the size of each column should also be expanded to the size of vec4, similar to how it's done for arrays of smaller-than-vec4 elements. Bug: angleproject:4889 Change-Id: I1f4d8d0e06922c4bb9261fbbf0f4565dfdec55c8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3018641 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 8d0eb08c 2021-07-05T23:22:24 Vulkan: SPIR-V Gen: Take advantage of OpConstantNull As part of fixing GLSLTest*.MissingReturn* tests, refactoring is done such that complex null values are declared concisely with OpConstantNull. The tests are fixed by making the SPIR-V generator implicitly add a `return <null-value-of-correct-type>;` if the return statement is missing from GLSL. Bug: angleproject:4889 Change-Id: Iffd80c5e6ce66afcdbf3813bffade6928f292007 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3010578 Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 81ed8d40 2021-07-02T00:54:25 Vulkan: SPIR-V Gen: Support barrier* built-ins This change enables the ComputeShaderTest suite and additionally includes the following fixes: - OpArrayLength was given the array type instead of variable. - Struct arrays inside interface blocks were not decorated with ArrayStride. Bug: angleproject:4889 Change-Id: Ibae95371bcea10e58c86b8fe1d1e172a18d56a09 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3001908 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi afdf378f 2021-07-01T21:55:58 Vulkan: SPIR-V Gen: Support == and != on complex types In GLSL, == and != produce a bool. In SPIR-V, there are only component-wise comparison operations. For ==, OpAll should be used to reduce it to a single bool, and for !=, OpAny. For matrices, the comparison is done column by column with a similar reduction for each column, and one for the final result. For structs and arrays, the comparison is similarly done field by field or element by element respectively. Bug: angleproject:4889 Change-Id: I8157c1931b7d1dedd74a3825967f5e212d346900 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3001905 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi cfaaf2ab 2021-06-30T17:23:55 Vulkan: SPIR-V Gen: Fixes to std430 block definition Bug: angleproject:4889 Change-Id: I18feff0916f348c8514cc97ba438d42fc00d0cba Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2999023 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi 3b0fcf6a 2021-06-30T15:14:48 Vulkan: SPIR-V Gen: Support type casts in constructors GLSL basic, vector and matrix constructors can convert between types. This was already done for constants used in constructors. This change implements the cast for non-constant expressions. Bug: angleproject:4889 Change-Id: I0a8c1a6e97ffced0d1652032a41fb87c70be16ca Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2999022 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi dc59772e 2021-06-22T22:37:26 Vulkan: SPIR-V Gen: Support switch With the infrastructure to support this in place, switch is simply implemented as a conditional with multiple blocks. Each block either ends with a branch to the merge block or the next block, implementing fallthrough. Bug: angleproject:4889 Change-Id: I5831531d918ac06648cced7707d1d48ffeb6b1b0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2983559 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi a8c9cecf 2021-06-12T00:12:34 Vulkan: SPIR-V Gen: Support break and continue This is simply done by issuing a branch to the merge or continue blocks respectively. Bug: angleproject:4889 Change-Id: I3e96a3b0f1a0533aa4eac519ab64a87600c0983b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2957810 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 153240b2 2021-06-11T16:36:32 Vulkan: SPIR-V Gen: Support loops Loops are similar to if-else in that they generate a number of blocks where the first block specifies divergence (OpLoopMerge) and the merge block. Differently from if-else, there is a block where the condition is evaluated and a block which `continue;` leads to (this last block is the only one allowed to back-jump to the beginning of the loop). Bug: angleproject:4889 Change-Id: Ic59f4bf3e05fbf93cb5af85acd3bc4b0da8412af Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2957809 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi c75a1d6f 2021-06-11T23:27:33 Vulkan: SPIR-V Gen: Support the ternary operator Bug: angleproject:4889 Change-Id: I3ac193e08fc74cc784b688cc049fb786ab68657d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2957808 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 7d023dac 2021-06-10T00:13:41 Vulkan: SPIR-V Gen: Basic support for fragment shaders Fragment shader built-ins are implemented in this change and direct SPIR-V generation for fragment shaders is enabled. Bug: angleproject:4889 Change-Id: I6f92a5585f242122a81c97a9b1aa2763009161a0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2951625 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 99a98963 2021-06-10T16:11:13 Vulkan: SPIR-V Gen: Support discard This is simply done with OpKill. If-else blocks now check if the block is already terminated (through return, discard, continue or break) before adding the branch to merge block. Bug: angleproject:4889 Change-Id: I713286cf38e40f9048486d2914a4355ddbc686ac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2953369 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 9c500951 2021-06-10T15:48:57 Vulkan: SPIR-V Gen: Fix user-defined blocks The _u prefix was missing from blocks and their fields. Bug: angleproject:4889 Change-Id: I31f3b393bc81352c8cf7a433dd652692833fc3f7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2953368 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 5a737833 2021-06-10T15:19:59 Vulkan: SPIR-V Gen: Fix row-major matrices Prior to this change, row-major and column-major matrices generated different types. That is not correct. With this change, the same type is generated for both. Row-major only comes into account when calculating the alignment and offset of fields in a block. Bug: angleproject:4889 Change-Id: Ifa03e1799a2510b90323d9d4fc2f681a3184069b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2953367 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi e48f2210 2021-06-10T13:23:34 Vulkan: SPIR-V Gen: Support short-circuiting && and || When short-circuiting is necessary (because the right-hand side has side effects), the following code is generated in SPIR-V: // For left && right: result = left if (left) result = right // For left || right: result = left if (!left) result = right Bug: angleproject:4889 Change-Id: Id87b56dc4a1463ed781852a23d2ba6eb2015d700 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2953366 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 64ca25f1 2021-06-08T17:15:49 Vulkan: SPIR-V Gen: Unary operators The line raster emulation coded uses round() which was previously not translated. This change implements all operations supported by TIntermUnary nodes. Bresenham line emulation is now allowed. Bug: angleproject:4889 Change-Id: I1ffbe3f9bf0299f7efa2c6d1e8f011fefdbb2ddb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2951624 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 0297779c 2021-06-08T01:06:21 Vulkan: SPIR-V Gen: Handle invariant variables The Invariant decoration is applied to variable declarations and block members as necessary. When invariant is applied to a gl_PerVertex built-in, it's applied to the appropriate member in DeclarePerVertexBlocks. Bug: angleproject:4889 Change-Id: Idaa8d4ab92f975381a0237d372f0a4044ff983e0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2946116 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 18ddd131 2021-06-07T14:59:43 Vulkan: SPIR-V Gen: Support mediump/lowp The mediump and lowp precisions translate to a RelaxedPrecision decoration in SPIR-V. This change implements this decoration and enables SPIR-V generation when emulating Bresenham lines. Prior to this change, Bresenham line emulation resulted in a validation error due to the vertex shader output being without RelaxedPrecision but the fragment shader input (translated by glslang) with it. The function that produces a new id is given a list of decorations to apply, which itself is automatically deriven from the TType where applicable, to minimize the risk of any id missing this decoration. Bug: angleproject:4889 Change-Id: I30cc5a278634c5d83d63cd65b057336f9f573baa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2946113 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 29227eef 2021-06-05T22:25:01 Vulkan: SPIR-V Gen: Specialization constants With specialization constant qualifier and ids set in the node types, the SPIR-V generation for these variables are trivially handled. This is in preparation for enabling line raster emulation as well as fragment shaders in general. Bug: angleproject:4889 Change-Id: Ie4d4e47b222ac66d1e0eee29f55ac09990313580 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2939337 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 6746e5dd 2021-06-01T22:48:14 Vulkan: SPIR-V Gen: Basic support for compute shaders This change enables direct SPIR-V generation for compute shaders and enables a few tests. A handful of built-in functions are translated to support said tests. Bug: angleproject:4889 Change-Id: I8fd6dc50ff31559a738ba680a993fb197e29fcf9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2939330 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi ee4a5266 2021-06-01T14:57:24 Vulkan: SPIR-V Gen: Function calls This change implements function calls. As a result, transform feedback tests are enabled as well as support for transform feedback emulation (which contains functions and if blocks). `const` and opaque uniform function arguments take intermediate values, while the rest take memory objects. If the argument being passed is an unindexed lvalue, it can be directly given to the function. Otherwise a temporary variable is made which is initialized by the parameter if necessary (in and inout parameters) and later overwrites the parameter if necessary (out and inout parameters). Bug: angleproject:4889 Change-Id: I8976cdd17870c35d5a2daeed3c38de57ada931d9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2930363 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 77831a6d 2021-05-31T22:41:58 Vulkan: SPIR-V Gen: If-else blocks This change implements if-else blocks as well as a few simple binary operations (equality, less-than etc). It builds on prior work to generate the function in separate blocks and introduces a "conditionals" stack to support nesting of if-else blocks, switches and loops. Bug: angleproject:4889 Change-Id: If7694000487811837ed5946753568b41d67199f0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2929660 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi fafd64a6 2021-06-01T17:08:07 Vulkan: SPIR-V Gen: Matrix decorations Matrices in blocks require MatrixStride and one of ColMajor or RowMajor decorations. Bug: angleproject:4889 Change-Id: I14ddb32fd3dbc977bf41703b016dc6d1c0722475 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2930368 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi 683064b7 2021-06-02T02:59:55 Vulkan: Fix missing operand list in OpExecutionMode parser & builder Bug: angleproject:4889 Change-Id: Ie864031caeddfcf5202044b0f9c197b3883ceaf7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2934782 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi c2ad5824 2021-05-31T12:20:27 Vulkan: SPIR-V Gen: Code blocks This change lays the foundation for implementing branches and loops. In SPIR-V, every block starts with an OpLabel (which identifies the block and serves as the branch target to that block), and ends in a branch. An `if` for example implies the existence of four blocks, the header including code leading up to the if, the true and false blocks and the "merge" block, including the code following the if-else blocks. This change includes support code for generating function code split in blocks, even though only one block is currently used. Bug: angleproject:4889 Change-Id: I10f96b78b6f00c20bc7f9c81e854ab5543bf8fde Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2929659 Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Shahbaz Youssefi be873929 2021-05-26T21:55:50 Vulkan: SPIR-V Gen: Handle constants and constructors This change translates constants and constructors (minus type casting). With this change, shaders such as gl_Position = vec4(aposition, 0, 1); are translated correctly. Bug: angleproject:4889 Change-Id: I4463717cf880c6d05db179b98691d5cabc1a2d7c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2920192 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi aa2626f9 2021-05-21T15:24:55 Vulkan: SPIR-V Gen: Handle load/store access chain This change implements a key instruction of SPIR-V, OpAccessChain. Inspired by glslang's implementation, a class is added (AccessChain) that tracks "indices" into a base value. These indices could select a field of a block, an element of an array, a column of a matrix, or a component of a vector. Nuances (such as multi-component swizzle as an lvalue not representable in SPIR-V) and optimizations (such as all-literal indices to an rvalue) that are implemented in glslang have also been implemented in this change. As a result, this change implements all manners of loads and stores (with the exception of this gotcha: https://github.com/KhronosGroup/glslang/issues/2637). The change uses this feature to translate the basic shader which does `gl_Position = positionAttr;` (by implementing EOpAssign), and enables a test that uses this shader. Bug: angleproject:4889 Change-Id: I22dbe5b169ce499eaac657902164aca3b0ebc193 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2911880 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>
Shahbaz Youssefi c229ccfe 2021-05-18T15:51:12 Vulkan: SPIR-V Gen: Handle gl_PerVertex If not declared by the shader, default gl_PerVertex is now explicitly declared in AST prior to SPIR-V generation. The SPIR-V generation code then doesn't need to declare them magically. Bug: angleproject:4889 Change-Id: Icc593bc1ccc3162487bdbae7f66bc775d098778d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2905952 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Shahbaz Youssefi 9bc837f6 2021-04-07T15:24:12 Vulkan: Generate SPIR-V directly from the translator; Part 1 This is the first change in a series to generate SPIR-V directly from the translator's AST, instead of the generating text GLSL and feeding it to glslang. This change implements the majority of the work needed to map AST types to SPIR-V types, and declare types and interface variables in SPIR-V. Additionally, it lays the infrastructure to conditionally enabling this path in end2end tests. No tests are currently enabled as the change doesn't actually generate code for function bodies yet. Bug: angleproject:4889 Change-Id: Iacb28b6907fd48c50e4cc5a0e7ad72f6eed241d4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2889603 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>