// // 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. // // spirv_types.h: // Strong types for SPIR-V Ids to prevent mistakes when using the builder and parser APIs. // #ifndef COMMON_SPIRV_TYPES_H_ #define COMMON_SPIRV_TYPES_H_ #include "common/FastVector.h" #include <vector> namespace angle { namespace spirv { template <typename Helper> class BoxedUint32 { … }; struct IdRefHelper { … }; struct LiteralIntegerHelper { … }; IdRef; operator unsigned int() // IdResult, IdResultType, IdMemorySemantics and IdScope are all translated as IdRef. This makes // the type verification weaker, but stops the API from becoming tediously verbose. IdResult; IdResultType; IdMemorySemantics; IdScope; LiteralInteger; LiteralString; // Note: In ANGLE's use cases, all literals fit in 32 bits. LiteralContextDependentNumber; // TODO(syoussefi): To be made stronger when generating SPIR-V from the translator. // http://anglebug.com/40096715 LiteralExtInstInteger; struct PairLiteralIntegerIdRef { … }; struct PairIdRefLiteralInteger { … }; struct PairIdRefIdRef { … }; // Some instructions need 4 components. The drivers uniform struct in ANGLE has 8 fields. A value // of 8 means almost no instruction would end up making dynamic allocations. Notable exceptions are // user-defined structs/blocks and OpEntryPoint. constexpr size_t kFastVectorSize = …; FastVectorHelper; IdRefList; LiteralIntegerList; PairLiteralIntegerIdRefList; PairIdRefLiteralIntegerList; PairIdRefIdRefList; // Id 0 is invalid in SPIR-V. constexpr uint32_t kMinValidId = …; // The SPIR-V blob is a sequence of uint32_t's Blob; // Format of the SPIR-V header. // SPIR-V 1.0 Table 1: First Words of Physical Layout enum HeaderIndex { … }; // SPIR-V version constexpr uint32_t kVersion_1_0 = …; constexpr uint32_t kVersion_1_3 = …; constexpr uint32_t kVersion_1_4 = …; // Returns whether SPIR-V is valid. Useful for ASSERTs. Automatically generates a warning if // SPIR-V is not valid. bool Validate(const Blob &blob); #if defined(ANGLE_ENABLE_ASSERTS) void Print(const Blob &blob); #endif } // namespace spirv } // namespace angle #endif // COMMON_SPIRV_TYPES_H_