// // Copyright 2021 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // BuildSPIRV: Helper for OutputSPIRV to build SPIR-V. // #ifndef COMPILER_TRANSLATOR_SPIRV_BUILDSPIRV_H_ #define COMPILER_TRANSLATOR_SPIRV_BUILDSPIRV_H_ #include "common/FixedVector.h" #include "common/PackedEnums.h" #include "common/bitset_utils.h" #include "common/hash_containers.h" #include "common/hash_utils.h" #include "common/spirv/spirv_instruction_builder_autogen.h" #include "compiler/translator/Compiler.h" spirv; namespace sh { // Helper classes to map types to ids // The same GLSL type may map to multiple SPIR-V types when said GLSL type is used differently in // the shader source, for example used with |invariant| and without, used in an interface block etc. // This type contains the pieces of information that differentiate SPIR-V types derived from the // same GLSL type. This is referred to as "SPIR-V type specialization" henceforth. struct SpirvType; class SpirvTypeSpec { … }; struct SpirvType { … }; bool operator==(const SpirvType &a, const SpirvType &b); struct SpirvIdAndIdList { … }; struct SpirvIdAndStorageClass { … }; struct SpirvTypeHash { … }; struct SpirvIdAndIdListHash { … }; struct SpirvIdAndStorageClassHash { … }; // Data tracked per SPIR-V type (keyed by SpirvType). struct SpirvTypeData { … }; // Decorations to be applied to variable or intermediate ids which are not part of the SPIR-V type // and are not specific enough (like DescriptorSet) to be handled automatically. Currently, these // are: // // RelaxedPrecision: used to implement |lowp| and |mediump| // NoContraction: used to implement |precise|. // Invariant: used to implement |invariant|, which is applied to output variables. // Memory qualifiers: used to implement |coherent, volatile, restrict, readonly, writeonly|, // which apply to shader storage blocks, variables declared within shader // storage blocks, and images. // // Note that Invariant applies to output variables, NoContraction to arithmetic instructions, and // memory qualifiers to shader storage and images, so they are mutually exclusive. A maximum of 6 // decorations are possible. FixedVector::push_back will ASSERT if the given size is ever not // enough. SpirvDecorations; // A block of code. SPIR-V produces forward references to blocks, such as OpBranchConditional // specifying the id of the if and else blocks, each of those referencing the id of the block after // the else. Additionally, local variable declarations are accumulated at the top of the first // block in a function. For these reasons, each block of SPIR-V is generated separately and // assembled at the end of the function, allowing prior blocks to be modified when necessary. struct SpirvBlock { … }; // Conditional code, constituting ifs, switches and loops. struct SpirvConditional { … }; // List of known extensions enum class SPIRVExtensions { … }; // Helper class to construct SPIR-V class SPIRVBuilder : angle::NonCopyable { … }; } // namespace sh #endif // COMPILER_TRANSLATOR_SPIRV_BUILDSPIRV_H_