1 // 2 // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // TranslatorSPIRV: 7 // A set of transformations that prepare the AST to be compatible with GL_KHR_vulkan_glsl followed 8 // by a pass that generates SPIR-V. 9 // See: https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt 10 // 11 12 #ifndef COMPILER_TRANSLATOR_SPIRV_TRANSLATORSPIRV_H_ 13 #define COMPILER_TRANSLATOR_SPIRV_TRANSLATORSPIRV_H_ 14 15 #include "compiler/translator/Compiler.h" 16 17 namespace sh 18 { 19 20 class TOutputVulkanGLSL; 21 class SpecConst; 22 class DriverUniform; 23 24 // An index -> TVariable map, tracking the declarated input attachments. 25 using InputAttachmentMap = TUnorderedMap<uint32_t, const TVariable *>; 26 27 class TranslatorSPIRV final : public TCompiler 28 { 29 public: 30 TranslatorSPIRV(sh::GLenum type, ShShaderSpec spec); 31 32 void assignSpirvId(TSymbolUniqueId uniqueId, uint32_t spirvId); 33 34 protected: 35 [[nodiscard]] bool translate(TIntermBlock *root, 36 const ShCompileOptions &compileOptions, 37 PerformanceDiagnostics *perfDiagnostics) override; 38 bool shouldFlattenPragmaStdglInvariantAll() override; 39 40 [[nodiscard]] bool translateImpl(TIntermBlock *root, 41 const ShCompileOptions &compileOptions, 42 PerformanceDiagnostics *perfDiagnostics, 43 SpecConst *specConst, 44 DriverUniform *driverUniforms); 45 void assignInputAttachmentIds(const InputAttachmentMap &inputAttachmentMap); 46 void assignSpirvIds(TIntermBlock *root); 47 48 // A map from TSymbolUniqueId::mId to SPIR-V reserved ids. Used by the SPIR-V generator to 49 // quickly know when to use a reserved id and not have to resort to name matching. 50 angle::HashMap<int, uint32_t> mUniqueToSpirvIdMap; 51 uint32_t mFirstUnusedSpirvId; 52 }; 53 54 } // namespace sh 55 56 #endif // COMPILER_TRANSLATOR_SPIRV_TRANSLATORSPIRV_H_ 57