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
17#include <functional>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
22using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
23
25
30class HdStGLSLProgram final
31{
32public:
33 typedef size_t ID;
34
35 HDST_API
36 HdStGLSLProgram(TfToken const &role, HdStResourceRegistry*const registry);
37 HDST_API
39
41 HDST_API
42 bool CompileShader(HgiShaderStage stage, std::string const & source);
43
45 HDST_API
47
49 HDST_API
50 bool Link();
51
53 HDST_API
54 bool Validate() const;
55
57 HgiShaderProgramHandle const &GetProgram() const { return _program; }
58
60 HDST_API
61 static HdStGLSLProgramSharedPtr GetComputeProgram(
62 TfToken const &shaderToken,
63 HdStResourceRegistry *resourceRegistry);
64
65 HDST_API
66 static HdStGLSLProgramSharedPtr GetComputeProgram(
67 TfToken const &shaderFileName,
68 TfToken const &shaderToken,
69 HdStResourceRegistry *resourceRegistry);
70
71 using PopulateDescriptorCallback =
72 std::function<void(HgiShaderFunctionDesc &computeDesc)>;
73
74 HDST_API
75 static HdStGLSLProgramSharedPtr GetComputeProgram(
76 TfToken const &shaderToken,
77 HdStResourceRegistry *resourceRegistry,
78 PopulateDescriptorCallback populateDescriptor);
79
80 HDST_API
81 static HdStGLSLProgramSharedPtr GetComputeProgram(
82 TfToken const &shaderToken,
83 std::string const &defines,
84 HdStResourceRegistry *resourceRegistry,
85 PopulateDescriptorCallback populateDescriptor);
86
87 HDST_API
88 static HdStGLSLProgramSharedPtr GetComputeProgram(
89 TfToken const &shaderFileName,
90 TfToken const &shaderToken,
91 std::string const &defines,
92 HdStResourceRegistry *resourceRegistry,
93 PopulateDescriptorCallback populateDescriptor);
94
96 TfToken const & GetRole() const {return _role;}
97
98private:
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
113PXR_NAMESPACE_CLOSE_SCOPE
114
115#endif // PXR_IMAGING_HD_ST_GLSL_PROGRAM_H
An instance of a glsl program.
Definition: glslProgram.h:31
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:57
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:96
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