xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/ProgramD3D.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 // ProgramD3D.h: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
10 #define LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
11 
12 #include <string>
13 #include <vector>
14 
15 #include "compiler/translator/hlsl/blocklayoutHLSL.h"
16 #include "libANGLE/Constants.h"
17 #include "libANGLE/formatutils.h"
18 #include "libANGLE/renderer/ProgramImpl.h"
19 #include "libANGLE/renderer/d3d/ProgramExecutableD3D.h"
20 #include "libANGLE/renderer/d3d/RendererD3D.h"
21 #include "libANGLE/renderer/d3d/ShaderD3D.h"
22 #include "platform/autogen/FeaturesD3D_autogen.h"
23 
24 namespace rx
25 {
26 class RendererD3D;
27 
28 class ProgramD3DMetadata final : angle::NonCopyable
29 {
30   public:
31     ProgramD3DMetadata(RendererD3D *renderer,
32                        const gl::SharedCompiledShaderState &fragmentShader,
33                        const gl::ShaderMap<SharedCompiledShaderStateD3D> &attachedShaders,
34                        int shaderVersion);
35     ~ProgramD3DMetadata();
36 
37     int getRendererMajorShaderModel() const;
38     bool usesBroadcast(const gl::Version &clientVersion) const;
39     bool usesSecondaryColor() const;
40     bool usesPointCoord() const;
41     bool usesFragCoord() const;
42     bool usesPointSize() const;
43     bool usesInsertedPointCoordValue() const;
44     bool usesViewScale() const;
45     bool hasMultiviewEnabled() const;
46     bool usesVertexID() const;
47     bool usesViewID() const;
48     bool canSelectViewInVertexShader() const;
49     bool addsPointCoordToVertexShader() const;
50     bool usesTransformFeedbackGLPosition() const;
51     bool usesSystemValuePointSize() const;
52     bool usesMultipleFragmentOuts() const;
53     bool usesCustomOutVars() const;
54     bool usesSampleMask() const;
55     const gl::SharedCompiledShaderState &getFragmentShader() const;
56     FragDepthUsage getFragDepthUsage() const;
57     uint8_t getClipDistanceArraySize() const;
58     uint8_t getCullDistanceArraySize() const;
59 
60   private:
61     const int mRendererMajorShaderModel;
62     const std::string mShaderModelSuffix;
63     const bool mUsesViewScale;
64     const bool mCanSelectViewInVertexShader;
65     gl::SharedCompiledShaderState mFragmentShader;
66     const gl::ShaderMap<SharedCompiledShaderStateD3D> &mAttachedShaders;
67     int mShaderVersion;
68 };
69 
70 class ProgramD3D : public ProgramImpl
71 {
72   public:
73     ProgramD3D(const gl::ProgramState &data, RendererD3D *renderer);
74     ~ProgramD3D() override;
75 
76     void destroy(const gl::Context *context) override;
77 
78     angle::Result load(const gl::Context *context,
79                        gl::BinaryInputStream *stream,
80                        std::shared_ptr<LinkTask> *loadTaskOut,
81                        egl::CacheGetResult *resultOut) override;
82     void save(const gl::Context *context, gl::BinaryOutputStream *stream) override;
83     void setBinaryRetrievableHint(bool retrievable) override;
84     void setSeparable(bool separable) override;
85 
86     void prepareForLink(const gl::ShaderMap<ShaderImpl *> &shaders) override;
87     angle::Result link(const gl::Context *context, std::shared_ptr<LinkTask> *linkTaskOut) override;
88     GLboolean validate(const gl::Caps &caps) override;
89 
getState()90     const gl::ProgramState &getState() const { return mState; }
91 
getExecutable()92     const ProgramExecutableD3D *getExecutable() const
93     {
94         return GetImplAs<ProgramExecutableD3D>(&mState.getExecutable());
95     }
getExecutable()96     ProgramExecutableD3D *getExecutable()
97     {
98         return GetImplAs<ProgramExecutableD3D>(&mState.getExecutable());
99     }
100 
101   private:
102     class GetVertexExecutableTask;
103     class GetPixelExecutableTask;
104     class GetGeometryExecutableTask;
105     class GetComputeExecutableTask;
106     class LinkLoadTaskD3D;
107     class LinkTaskD3D;
108     class LoadTaskD3D;
109 
110     friend class LinkTaskD3D;
111     friend class LoadTaskD3D;
112 
113     angle::Result linkJobImpl(d3d::Context *context,
114                               const gl::Caps &caps,
115                               const gl::Version &clientVersion,
116                               const gl::ProgramLinkedResources &resources,
117                               const gl::ProgramMergedVaryings &mergedVaryings);
getAttachedShader(gl::ShaderType shaderType)118     const SharedCompiledShaderStateD3D &getAttachedShader(gl::ShaderType shaderType)
119     {
120         return getExecutable()->mAttachedShaders[shaderType];
121     }
122 
123     void linkResources(const gl::ProgramLinkedResources &resources);
124 
125     RendererD3D *mRenderer;
126 };
127 }  // namespace rx
128 
129 #endif  // LIBANGLE_RENDERER_D3D_PROGRAMD3D_H_
130