• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 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 // TranslatorMetal:
7 //   A GLSL-based translator that outputs shaders that fit GL_KHR_vulkan_glsl.
8 //   It takes into account some considerations for Metal backend also.
9 //   The shaders are then fed into glslang to spit out SPIR-V.
10 //   See: https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt
11 //
12 //   The SPIR-V will then be translated to Metal Shading Language later in Metal backend.
13 //
14 
15 #ifndef LIBANGLE_RENDERER_METAL_TRANSLATORMETAL_H_
16 #define LIBANGLE_RENDERER_METAL_TRANSLATORMETAL_H_
17 
18 #include "compiler/translator/TranslatorVulkan.h"
19 #include "compiler/translator/tree_util/DriverUniform.h"
20 #include "compiler/translator/tree_util/SpecializationConstant.h"
21 
22 namespace sh
23 {
24 
25 // TODO: http://anglebug.com/5339 Implement it using actual specialization constant. For now we are
26 // redirecting to driver uniforms
27 class SpecConstMetal : public SpecConst
28 {
29   public:
SpecConstMetal(TSymbolTable * symbolTable,ShCompileOptions compileOptions,GLenum shaderType)30     SpecConstMetal(TSymbolTable *symbolTable, ShCompileOptions compileOptions, GLenum shaderType)
31         : SpecConst(symbolTable, compileOptions, shaderType)
32     {}
~SpecConstMetal()33     ~SpecConstMetal() override {}
34 
35   private:
36 };
37 
38 class DriverUniformMetal : public DriverUniform
39 {
40   public:
DriverUniformMetal()41     DriverUniformMetal() : DriverUniform(DriverUniformMode::InterfaceBlock) {}
~DriverUniformMetal()42     ~DriverUniformMetal() override {}
43 
44     TIntermBinary *getHalfRenderAreaRef() const override;
45     TIntermBinary *getFlipXYRef() const override;
46     TIntermBinary *getNegFlipXYRef() const override;
47     TIntermSwizzle *getNegFlipYRef() const override;
48     TIntermBinary *getCoverageMaskFieldRef() const;
49 
50   protected:
51     TFieldList *createUniformFields(TSymbolTable *symbolTable) override;
52 };
53 
54 class TranslatorMetal : public TranslatorVulkan
55 {
56   public:
57     TranslatorMetal(sh::GLenum type, ShShaderSpec spec);
58 
59   protected:
60     ANGLE_NO_DISCARD bool translate(TIntermBlock *root,
61                                     ShCompileOptions compileOptions,
62                                     PerformanceDiagnostics *perfDiagnostics) override;
63 
64     ANGLE_NO_DISCARD bool transformDepthBeforeCorrection(
65         TIntermBlock *root,
66         const DriverUniform *driverUniforms) override;
67 
68     ANGLE_NO_DISCARD bool insertSampleMaskWritingLogic(TInfoSinkBase &sink,
69                                                        TIntermBlock *root,
70                                                        const DriverUniformMetal *driverUniforms);
71     ANGLE_NO_DISCARD bool insertRasterizerDiscardLogic(TInfoSinkBase &sink, TIntermBlock *root);
72 };
73 
74 }  // namespace sh
75 
76 #endif /* LIBANGLE_RENDERER_METAL_TRANSLATORMETAL_H_ */
77