All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslProgram.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
25 #define PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/version.h"
29 #include "pxr/imaging/hdSt/api.h"
30 #include "pxr/imaging/hgi/buffer.h"
31 #include "pxr/imaging/hgi/shaderProgram.h"
32 #include "pxr/imaging/hgi/enums.h"
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
37 using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
38 
40 
45 class HdStGLSLProgram final
46 {
47 public:
48  typedef size_t ID;
49 
50  HDST_API
51  HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
52  HDST_API
53  ~HdStGLSLProgram();
54 
56  HDST_API
57  bool CompileShader(HgiShaderStage stage, std::string const & source);
58 
60  HDST_API
61  bool Link();
62 
64  HDST_API
65  bool Validate() const;
66 
68  HgiShaderProgramHandle const &GetProgram() const { return _program; }
69 
71  HDST_API
72  static HdStGLSLProgramSharedPtr GetComputeProgram(
73  TfToken const &shaderToken,
74  HdStResourceRegistry *resourceRegistry);
75 
76  HDST_API
77  static HdStGLSLProgramSharedPtr GetComputeProgram(
78  TfToken const &shaderFileName,
79  TfToken const &shaderToken,
80  HdStResourceRegistry *resourceRegistry);
81 
82  using PopulateDescriptorCallback =
83  std::function<void(HgiShaderFunctionDesc &computeDesc)>;
84 
85  HDST_API
86  static HdStGLSLProgramSharedPtr GetComputeProgram(
87  TfToken const &shaderToken,
88  HdStResourceRegistry *resourceRegistry,
89  PopulateDescriptorCallback populateDescriptor);
90 
91  HDST_API
92  static HdStGLSLProgramSharedPtr GetComputeProgram(
93  TfToken const &shaderToken,
94  std::string const &defines,
95  HdStResourceRegistry *resourceRegistry,
96  PopulateDescriptorCallback populateDescriptor);
97 
99  TfToken const & GetRole() const {return _role;}
100 
101 private:
102  HdStResourceRegistry *const _registry;
103  TfToken _role;
104 
105  HgiShaderProgramDesc _programDesc;
106  HgiShaderProgramHandle _program;
107 
108  // An identifier for uniquely identifying the program, for debugging
109  // purposes - programs that fail to compile for one reason or another
110  // will get deleted, and their GL program IDs reused, so we can't use
111  // that to identify it uniquely
112  size_t _debugID;
113 };
114 
115 
116 PXR_NAMESPACE_CLOSE_SCOPE
117 
118 #endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
TfToken const & GetRole() const
Returns the role of the GPU data in this resource.
Definition: glslProgram.h:99
An instance of a glsl program.
Definition: glslProgram.h:45
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HgiShaderProgramHandle const & GetProgram() const
Returns HdResource of the program object.
Definition: glslProgram.h:68
A central registry of all GPU resources.
HDST_API bool Link()
Link the compiled shaders together.
HDST_API bool CompileShader(HgiShaderStage stage, std::string const &source)
Compile shader source for a shader stage.
Describes the properties needed to create a GPU shader program.
Definition: shaderProgram.h:51
static HDST_API HdStGLSLProgramSharedPtr GetComputeProgram(TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry)
Convenience method to get a shared compute shader program.
HDST_API bool Validate() const
Validate if this program is a valid progam in the current context.