xref: /aosp_15_r20/external/angle/src/compiler/translator/CodeGen.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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_NULL
8 #    include "compiler/translator/null/TranslatorNULL.h"
9 #endif  // ANGLE_ENABLE_NULL
10 
11 #ifdef ANGLE_ENABLE_ESSL
12 #    include "compiler/translator/glsl/TranslatorESSL.h"
13 #endif  // ANGLE_ENABLE_ESSL
14 
15 #ifdef ANGLE_ENABLE_GLSL
16 #    include "compiler/translator/glsl/TranslatorGLSL.h"
17 #endif  // ANGLE_ENABLE_GLSL
18 
19 #ifdef ANGLE_ENABLE_HLSL
20 #    include "compiler/translator/hlsl/TranslatorHLSL.h"
21 #endif  // ANGLE_ENABLE_HLSL
22 
23 #ifdef ANGLE_ENABLE_VULKAN
24 #    include "compiler/translator/spirv/TranslatorSPIRV.h"
25 #endif  // ANGLE_ENABLE_VULKAN
26 
27 #ifdef ANGLE_ENABLE_METAL
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  // ANGLE_ENABLE_WGPU
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_NULL
48     if (IsOutputNULL(output))
49     {
50         return new TranslatorNULL(type, spec);
51     }
52 #endif  // ANGLE_ENABLE_NULL
53 
54 #ifdef ANGLE_ENABLE_ESSL
55     if (IsOutputESSL(output))
56     {
57         return new TranslatorESSL(type, spec);
58     }
59 #endif  // ANGLE_ENABLE_ESSL
60 
61 #ifdef ANGLE_ENABLE_GLSL
62     if (IsOutputGLSL(output))
63     {
64         return new TranslatorGLSL(type, spec, output);
65     }
66 #endif  // ANGLE_ENABLE_GLSL
67 
68 #ifdef ANGLE_ENABLE_HLSL
69     if (IsOutputHLSL(output))
70     {
71         return new TranslatorHLSL(type, spec, output);
72     }
73 #endif  // ANGLE_ENABLE_HLSL
74 
75 #ifdef ANGLE_ENABLE_VULKAN
76     if (IsOutputSPIRV(output))
77     {
78         return new TranslatorSPIRV(type, spec);
79     }
80 #endif  // ANGLE_ENABLE_VULKAN
81 
82 #ifdef ANGLE_ENABLE_METAL
83     if (IsOutputMSL(output))
84     {
85         return new TranslatorMSL(type, spec, output);
86     }
87 #endif  // ANGLE_ENABLE_METAL
88 
89 #ifdef ANGLE_ENABLE_WGPU
90     if (IsOutputWGSL(output))
91     {
92         return new TranslatorWGSL(type, spec, output);
93     }
94 #endif  // ANGLE_ENABLE_WGPU
95 
96     // Unsupported compiler or unknown format. Return nullptr per the sh::ConstructCompiler API.
97     return nullptr;
98 }
99 
100 //
101 // Delete the compiler made by ConstructCompiler
102 //
DeleteCompiler(TCompiler * compiler)103 void DeleteCompiler(TCompiler *compiler)
104 {
105     SafeDelete(compiler);
106 }
107 
108 }  // namespace sh
109