Loading...
Searching...
No Matches
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
34PXR_NAMESPACE_OPEN_SCOPE
35
37using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
38
40
45class HdStGLSLProgram final
46{
47public:
48 typedef size_t ID;
49
50 HDST_API
51 HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
52 HDST_API
54
56 HDST_API
57 bool CompileShader(HgiShaderStage stage, std::string const & source);
58
60 HDST_API
62
64 HDST_API
65 bool Link();
66
68 HDST_API
69 bool Validate() const;
70
72 HgiShaderProgramHandle const &GetProgram() const { return _program; }
73
75 HDST_API
76 static HdStGLSLProgramSharedPtr GetComputeProgram(
77 TfToken const &shaderToken,
78 HdStResourceRegistry *resourceRegistry);
79
80 HDST_API
81 static HdStGLSLProgramSharedPtr GetComputeProgram(
82 TfToken const &shaderFileName,
83 TfToken const &shaderToken,
84 HdStResourceRegistry *resourceRegistry);
85
86 using PopulateDescriptorCallback =
87 std::function<void(HgiShaderFunctionDesc &computeDesc)>;
88
89 HDST_API
90 static HdStGLSLProgramSharedPtr GetComputeProgram(
91 TfToken const &shaderToken,
92 HdStResourceRegistry *resourceRegistry,
93 PopulateDescriptorCallback populateDescriptor);
94
95 HDST_API
96 static HdStGLSLProgramSharedPtr GetComputeProgram(
97 TfToken const &shaderToken,
98 std::string const &defines,
99 HdStResourceRegistry *resourceRegistry,
100 PopulateDescriptorCallback populateDescriptor);
101
102 HDST_API
103 static HdStGLSLProgramSharedPtr GetComputeProgram(
104 TfToken const &shaderFileName,
105 TfToken const &shaderToken,
106 std::string const &defines,
107 HdStResourceRegistry *resourceRegistry,
108 PopulateDescriptorCallback populateDescriptor);
109
111 TfToken const & GetRole() const {return _role;}
112
113private:
114 HdStResourceRegistry *const _registry;
115 TfToken _role;
116
117 HgiShaderProgramDesc _programDesc;
118 HgiShaderProgramHandle _program;
119
120 // An identifier for uniquely identifying the program, for debugging
121 // purposes - programs that fail to compile for one reason or another
122 // will get deleted, and their GL program IDs reused, so we can't use
123 // that to identify it uniquely
124 size_t _debugID;
125};
126
127
128PXR_NAMESPACE_CLOSE_SCOPE
129
130#endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
An instance of a glsl program.
Definition: glslProgram.h:46
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:72
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:111
A central registry of all GPU resources.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Describes the properties needed to create a GPU shader function.
Describes the properties needed to create a GPU shader program.
Definition: shaderProgram.h:52