xref: /aosp_15_r20/external/angle/src/compiler/translator/spirv/TranslatorSPIRV.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 "common/hash_containers.h"
16 #include "compiler/translator/Compiler.h"
17 
18 namespace sh
19 {
20 
21 class TOutputVulkanGLSL;
22 class SpecConst;
23 class DriverUniform;
24 
25 // An index -> TVariable map, tracking the declarated color input attachments, as well as TVariables
26 // for depth and stencil input attachments.
27 struct InputAttachmentMap
28 {
29     TUnorderedMap<uint32_t, const TVariable *> color;
30     const TVariable *depth   = nullptr;
31     const TVariable *stencil = nullptr;
32 };
33 
34 class TranslatorSPIRV final : public TCompiler
35 {
36   public:
37     TranslatorSPIRV(sh::GLenum type, ShShaderSpec spec);
38 
39     void assignSpirvId(TSymbolUniqueId uniqueId, uint32_t spirvId);
40 
41   protected:
42     [[nodiscard]] bool translate(TIntermBlock *root,
43                                  const ShCompileOptions &compileOptions,
44                                  PerformanceDiagnostics *perfDiagnostics) override;
45     bool shouldFlattenPragmaStdglInvariantAll() override;
46 
47     [[nodiscard]] bool translateImpl(TIntermBlock *root,
48                                      const ShCompileOptions &compileOptions,
49                                      PerformanceDiagnostics *perfDiagnostics,
50                                      SpecConst *specConst,
51                                      DriverUniform *driverUniforms);
52     void assignInputAttachmentIds(const InputAttachmentMap &inputAttachmentMap);
53     void assignSpirvIds(TIntermBlock *root);
54 
55     // A map from TSymbolUniqueId::mId to SPIR-V reserved ids.  Used by the SPIR-V generator to
56     // quickly know when to use a reserved id and not have to resort to name matching.
57     angle::HashMap<int, uint32_t> mUniqueToSpirvIdMap;
58     uint32_t mFirstUnusedSpirvId;
59 };
60 
61 }  // namespace sh
62 
63 #endif  // COMPILER_TRANSLATOR_SPIRV_TRANSLATORSPIRV_H_
64