xref: /aosp_15_r20/external/angle/src/libANGLE/Compiler.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2014 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 // Compiler.h: Defines the gl::Compiler class, abstracting the ESSL compiler
8 // that a GL context holds.
9 
10 #ifndef LIBANGLE_COMPILER_H_
11 #define LIBANGLE_COMPILER_H_
12 
13 #include <vector>
14 
15 #include "GLSLANG/ShaderLang.h"
16 #include "common/PackedEnums.h"
17 #include "libANGLE/Error.h"
18 #include "libANGLE/RefCountObject.h"
19 
20 namespace rx
21 {
22 class CompilerImpl;
23 class GLImplFactory;
24 }  // namespace rx
25 
26 namespace gl
27 {
28 class ShCompilerInstance;
29 class State;
30 
31 class Compiler final : public RefCountObjectNoID
32 {
33   public:
34     Compiler(rx::GLImplFactory *implFactory, const State &data, egl::Display *display);
35 
36     void onDestroy(const Context *context) override;
37 
38     ShCompilerInstance getInstance(ShaderType shaderType);
39     void putInstance(ShCompilerInstance &&instance);
getShaderOutputType()40     ShShaderOutput getShaderOutputType() const { return mOutputType; }
getBuiltInResources()41     const ShBuiltInResources &getBuiltInResources() const { return mResources; }
42 
43     static ShShaderSpec SelectShaderSpec(const State &state);
44 
45   private:
46     ~Compiler() override;
47     std::unique_ptr<rx::CompilerImpl> mImplementation;
48     ShShaderSpec mSpec;
49     ShShaderOutput mOutputType;
50     ShBuiltInResources mResources;
51     ShaderMap<std::vector<ShCompilerInstance>> mPools;
52 };
53 
54 class ShCompilerInstance final : public angle::NonCopyable
55 {
56   public:
57     ShCompilerInstance();
58     ShCompilerInstance(ShHandle handle, ShShaderOutput outputType, ShaderType shaderType);
59     ~ShCompilerInstance();
60     void destroy();
61 
62     ShCompilerInstance(ShCompilerInstance &&other);
63     ShCompilerInstance &operator=(ShCompilerInstance &&other);
64 
65     ShHandle getHandle();
66     ShaderType getShaderType() const;
67     ShBuiltInResources getBuiltInResources() const;
68     ShShaderOutput getShaderOutputType() const;
69 
70   private:
71     ShHandle mHandle;
72     ShShaderOutput mOutputType;
73     ShaderType mShaderType;
74 };
75 
76 }  // namespace gl
77 
78 #endif  // LIBANGLE_COMPILER_H_
79