HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
glslProgram.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
8 #define PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/version.h"
12 #include "pxr/imaging/hdSt/api.h"
13 #include "pxr/imaging/hgi/buffer.h"
15 #include "pxr/imaging/hgi/enums.h"
16 
17 #include <functional>
18 
20 
22 using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
23 
25 
26 /// \class HdStGLSLProgram
27 ///
28 /// An instance of a glsl program.
29 ///
30 class HdStGLSLProgram final
31 {
32 public:
33  typedef size_t ID;
34 
35  HDST_API
36  HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
37  HDST_API
39 
40  /// Compile shader source for a shader stage.
41  HDST_API
42  bool CompileShader(HgiShaderStage stage, std::string const & source);
43 
44  /// Compile shader source for a shader stage from an HgiShaderFunctionDesc.
45  HDST_API
46  bool CompileShader(HgiShaderFunctionDesc const &desc);
47 
48  /// Link the compiled shaders together.
49  HDST_API
50  bool Link();
51 
52  /// Validate if this program is a valid progam in the current context.
53  HDST_API
54  bool Validate() const;
55 
56  /// Returns HgiShaderProgramHandle for the shader program.
57  HgiShaderProgramHandle const &GetProgram() const { return _program; }
58 
59  /// Convenience method to get a shared compute shader program
60  HDST_API
62  TfToken const &shaderToken,
63  HdStResourceRegistry *resourceRegistry);
64 
65  HDST_API
67  TfToken const &shaderFileName,
68  TfToken const &shaderToken,
69  HdStResourceRegistry *resourceRegistry);
70 
72  std::function<void(HgiShaderFunctionDesc &computeDesc)>;
73 
74  HDST_API
76  TfToken const &shaderToken,
77  HdStResourceRegistry *resourceRegistry,
78  PopulateDescriptorCallback populateDescriptor);
79 
80  HDST_API
82  TfToken const &shaderToken,
83  std::string const &defines,
84  HdStResourceRegistry *resourceRegistry,
85  PopulateDescriptorCallback populateDescriptor);
86 
87  HDST_API
89  TfToken const &shaderFileName,
90  TfToken const &shaderToken,
91  std::string const &defines,
92  HdStResourceRegistry *resourceRegistry,
93  PopulateDescriptorCallback populateDescriptor);
94 
95  /// Returns the role of the GPU data in this resource.
96  TfToken const & GetRole() const {return _role;}
97 
98 private:
99  HdStResourceRegistry *const _registry;
100  TfToken _role;
101 
102  HgiShaderProgramDesc _programDesc;
103  HgiShaderProgramHandle _program;
104 
105  // An identifier for uniquely identifying the program, for debugging
106  // purposes - programs that fail to compile for one reason or another
107  // will get deleted, and their GL program IDs reused, so we can't use
108  // that to identify it uniquely
109  size_t _debugID;
110 };
111 
112 
114 
115 #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:96
std::function< void(HgiShaderFunctionDesc &computeDesc)> PopulateDescriptorCallback
Definition: glslProgram.h:72
Definition: token.h:70
HDST_API bool CompileShader(HgiShaderStage stage, std::string const &source)
Compile shader source for a shader stage.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
HDST_API bool Link()
Link the compiled shaders together.
std::shared_ptr< class HdStGLSLProgram > HdStGLSLProgramSharedPtr
HDST_API ~HdStGLSLProgram()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API HdStGLSLProgram(TfToken const &role, HdStResourceRegistry *const registry)
HgiShaderProgramHandle const & GetProgram() const
Returns HgiShaderProgramHandle for the shader program.
Definition: glslProgram.h:57
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDST_API bool Validate() const
Validate if this program is a valid progam in the current context.
static HDST_API HdStGLSLProgramSharedPtr GetComputeProgram(TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry)
Convenience method to get a shared compute shader program.
HgiBits HgiShaderStage
Definition: enums.h:357