Loading...
Searching...
No Matches
glslProgram.h
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"
14#include "pxr/imaging/hgi/shaderProgram.h"
15#include "pxr/imaging/hgi/enums.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
20using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
21
23
28class HdStGLSLProgram final
29{
30public:
31 typedef size_t ID;
32
33 HDST_API
34 HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
35 HDST_API
37
39 HDST_API
40 bool CompileShader(HgiShaderStage stage, std::string const & source);
41
43 HDST_API
45
47 HDST_API
48 bool Link();
49
51 HDST_API
52 bool Validate() const;
53
55 HgiShaderProgramHandle const &GetProgram() const { return _program; }
56
58 HDST_API
59 static HdStGLSLProgramSharedPtr GetComputeProgram(
60 TfToken const &shaderToken,
61 HdStResourceRegistry *resourceRegistry);
62
63 HDST_API
64 static HdStGLSLProgramSharedPtr GetComputeProgram(
65 TfToken const &shaderFileName,
66 TfToken const &shaderToken,
67 HdStResourceRegistry *resourceRegistry);
68
69 using PopulateDescriptorCallback =
70 std::function<void(HgiShaderFunctionDesc &computeDesc)>;
71
72 HDST_API
73 static HdStGLSLProgramSharedPtr GetComputeProgram(
74 TfToken const &shaderToken,
75 HdStResourceRegistry *resourceRegistry,
76 PopulateDescriptorCallback populateDescriptor);
77
78 HDST_API
79 static HdStGLSLProgramSharedPtr GetComputeProgram(
80 TfToken const &shaderToken,
81 std::string const &defines,
82 HdStResourceRegistry *resourceRegistry,
83 PopulateDescriptorCallback populateDescriptor);
84
85 HDST_API
86 static HdStGLSLProgramSharedPtr GetComputeProgram(
87 TfToken const &shaderFileName,
88 TfToken const &shaderToken,
89 std::string const &defines,
90 HdStResourceRegistry *resourceRegistry,
91 PopulateDescriptorCallback populateDescriptor);
92
94 TfToken const & GetRole() const {return _role;}
95
96private:
97 HdStResourceRegistry *const _registry;
98 TfToken _role;
99
100 HgiShaderProgramDesc _programDesc;
101 HgiShaderProgramHandle _program;
102
103 // An identifier for uniquely identifying the program, for debugging
104 // purposes - programs that fail to compile for one reason or another
105 // will get deleted, and their GL program IDs reused, so we can't use
106 // that to identify it uniquely
107 size_t _debugID;
108};
109
110
111PXR_NAMESPACE_CLOSE_SCOPE
112
113#endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
An instance of a glsl program.
Definition: glslProgram.h:29
HDST_API bool CompileShader(HgiShaderFunctionDesc const &desc)
Compile shader source for a shader stage from an HgiShaderFunctionDesc.
HDST_API bool CompileShader(HgiShaderStage stage, std::string const &source)
Compile shader source for a shader stage.
HDST_API bool Validate() const
Validate if this program is a valid progam in the current context.
HgiShaderProgramHandle const & GetProgram() const
Returns HgiShaderProgramHandle for the shader program.
Definition: glslProgram.h:55
HDST_API bool Link()
Link the compiled shaders together.
static HDST_API HdStGLSLProgramSharedPtr GetComputeProgram(TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry)
Convenience method to get a shared compute shader program.
TfToken const & GetRole() const
Returns the role of the GPU data in this resource.
Definition: glslProgram.h:94
A central registry of all GPU resources.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Describes the properties needed to create a GPU shader function.
Describes the properties needed to create a GPU shader program.
Definition: shaderProgram.h:35