1 //
2 // Copyright 2013 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
7 #ifdef ANGLE_ENABLE_ESSL
8 # include "compiler/translator/glsl/TranslatorESSL.h"
9 #endif // ANGLE_ENABLE_ESSL
10
11 #ifdef ANGLE_ENABLE_GLSL
12 # include "compiler/translator/glsl/TranslatorGLSL.h"
13 #endif // ANGLE_ENABLE_GLSL
14
15 #ifdef ANGLE_ENABLE_HLSL
16 # include "compiler/translator/hlsl/TranslatorHLSL.h"
17 #endif // ANGLE_ENABLE_HLSL
18
19 #ifdef ANGLE_ENABLE_VULKAN
20 # include "compiler/translator/spirv/TranslatorSPIRV.h"
21 #endif // ANGLE_ENABLE_VULKAN
22
23 #ifdef ANGLE_ENABLE_METAL
24 # include "compiler/translator/msl/TranslatorMSL.h"
25 #endif // ANGLE_ENABLE_METAL
26
27 #ifdef ANGLE_ENABLE_WEBGPU
28 # include "compiler/translator/msl/TranslatorMSL.h"
29 #endif // ANGLE_ENABLE_METAL
30
31 #ifdef ANGLE_ENABLE_WGPU
32 # include "compiler/translator/wgsl/TranslatorWGSL.h"
33 #endif
34
35 #include "compiler/translator/util.h"
36
37 namespace sh
38 {
39
40 //
41 // This function must be provided to create the actual
42 // compile object used by higher level code. It returns
43 // a subclass of TCompiler.
44 //
ConstructCompiler(sh::GLenum type,ShShaderSpec spec,ShShaderOutput output)45 TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
46 {
47 #ifdef ANGLE_ENABLE_ESSL
48 if (IsOutputESSL(output))
49 {
50 return new TranslatorESSL(type, spec);
51 }
52 #endif // ANGLE_ENABLE_ESSL
53
54 #ifdef ANGLE_ENABLE_GLSL
55 if (IsOutputGLSL(output))
56 {
57 return new TranslatorGLSL(type, spec, output);
58 }
59 #endif // ANGLE_ENABLE_GLSL
60
61 #ifdef ANGLE_ENABLE_HLSL
62 if (IsOutputHLSL(output))
63 {
64 return new TranslatorHLSL(type, spec, output);
65 }
66 #endif // ANGLE_ENABLE_HLSL
67
68 #ifdef ANGLE_ENABLE_VULKAN
69 if (IsOutputSPIRV(output))
70 {
71 return new TranslatorSPIRV(type, spec);
72 }
73 #endif // ANGLE_ENABLE_VULKAN
74
75 #ifdef ANGLE_ENABLE_METAL
76 if (IsOutputMSL(output))
77 {
78 return new TranslatorMSL(type, spec, output);
79 }
80 #endif // ANGLE_ENABLE_METAL
81
82 #ifdef ANGLE_ENABLE_WGPU
83 if (IsOutputWGSL(output))
84 {
85 return new TranslatorWGSL(type, spec, output);
86 }
87 #endif // ANGLE_ENABLE_WGPU
88
89 // Unsupported compiler or unknown format. Return nullptr per the sh::ConstructCompiler API.
90 return nullptr;
91 }
92
93 //
94 // Delete the compiler made by ConstructCompiler
95 //
DeleteCompiler(TCompiler * compiler)96 void DeleteCompiler(TCompiler *compiler)
97 {
98 SafeDelete(compiler);
99 }
100
101 } // namespace sh
102