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 // TranslatorVulkan:
7 //   A GLSL-based translator that outputs shaders that fit GL_KHR_vulkan_glsl and feeds them into
8 //   glslang to spit out SPIR-V.
9 //   See: https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt
10 //
11 
12 #ifndef COMPILER_TRANSLATOR_TRANSLATORVULKAN_H_
13 #define COMPILER_TRANSLATOR_TRANSLATORVULKAN_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 class TranslatorVulkan : public TCompiler
25 {
26   public:
27     TranslatorVulkan(sh::GLenum type, ShShaderSpec spec);
28 
29   protected:
30     ANGLE_NO_DISCARD bool translate(TIntermBlock *root,
31                                     ShCompileOptions compileOptions,
32                                     PerformanceDiagnostics *perfDiagnostics) override;
33     bool shouldFlattenPragmaStdglInvariantAll() override;
34 
35     // Subclass can call this method to transform the AST before writing the final output.
36     // See TranslatorMetal.cpp.
37     ANGLE_NO_DISCARD bool translateImpl(TInfoSinkBase &sink,
38                                         TIntermBlock *root,
39                                         ShCompileOptions compileOptions,
40                                         PerformanceDiagnostics *perfDiagnostics,
41                                         SpecConst *specConst,
42                                         DriverUniform *driverUniforms);
43 
44     // Give subclass such as TranslatorMetal a chance to do depth transform before
45     // TranslatorVulkan apply its own transform.
transformDepthBeforeCorrection(TIntermBlock * root,const DriverUniform * driverUniforms)46     ANGLE_NO_DISCARD virtual bool transformDepthBeforeCorrection(
47         TIntermBlock *root,
48         const DriverUniform *driverUniforms)
49     {
50         return true;
51     }
52 
53     // Generate SPIR-V out of intermediate GLSL through glslang.
54     ANGLE_NO_DISCARD bool compileToSpirv(const TInfoSinkBase &glsl);
55 };
56 
57 }  // namespace sh
58 
59 #endif  // COMPILER_TRANSLATOR_TRANSLATORVULKAN_H_
60