Loading...
Searching...
No Matches
shaderCode.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_SHADER_CODE_H
8#define PXR_IMAGING_HD_ST_SHADER_CODE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/resourceRegistry.h"
13#include "pxr/imaging/hdSt/enums.h"
14#include "pxr/imaging/hd/version.h"
15
16#include "pxr/usd/sdf/path.h"
17
18#include "pxr/base/tf/token.h"
19
20#include <memory>
21#include <string>
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26
27using HdStBindingRequestVector = std::vector<class HdStBindingRequest>;
28
29using HdStShaderCodeSharedPtr =
30 std::shared_ptr<class HdStShaderCode>;
31using HdStShaderCodeSharedPtrVector =
32 std::vector<HdStShaderCodeSharedPtr>;
33
34using HdSt_MaterialParamVector =
35 std::vector<class HdSt_MaterialParam>;
36using HdBufferSourceSharedPtr =
37 std::shared_ptr<class HdBufferSource>;
38using HdBufferSourceSharedPtrVector =
39 std::vector<HdBufferSourceSharedPtr>;
40using HdBufferArrayRangeSharedPtr =
41 std::shared_ptr<class HdBufferArrayRange>;
42using HdStTextureHandleSharedPtr =
43 std::shared_ptr<class HdStTextureHandle>;
44using HdStComputationSharedPtr =
45 std::shared_ptr<class HdStComputation>;
46
47class HioGlslfx;
48class HdSt_ResourceBinder;
50
58class HdStShaderCode : public std::enable_shared_from_this<HdStShaderCode>
59{
60public:
61 typedef size_t ID;
62
63 HDST_API
65 HDST_API
66 virtual ~HdStShaderCode();
67
75 virtual ID ComputeHash() const = 0;
76
78 HDST_API
79 static ID ComputeHash(HdStShaderCodeSharedPtrVector const &shaders);
80
91 HDST_API
92 virtual ID ComputeTextureSourceHash() const;
93
96 virtual std::string GetSource(TfToken const &shaderStageKey) const = 0;
97
101 HDST_API
102 VtDictionary GetLayout(TfTokenVector const &shaderStageKeys) const;
103
104 // XXX: Should be pure-virtual
106 HDST_API
107 virtual HdSt_MaterialParamVector const& GetParams() const;
108
110 HDST_API
111 virtual bool IsEnabledPrimvarFiltering() const;
112
114 HDST_API
115 virtual TfTokenVector const& GetPrimvarNames() const;
116
118
122
136 HdStTextureType type;
138 HdStTextureHandleSharedPtr handle;
139
142 size_t hash;
143 };
144 using NamedTextureHandleVector = std::vector<NamedTextureHandle>;
145
148 HDST_API
149 virtual NamedTextureHandleVector const & GetNamedTextureHandles() const;
150
152
153 // XXX: Should be pure-virtual
156 HDST_API
157 virtual HdBufferArrayRangeSharedPtr const& GetShaderData() const;
158
162 virtual void BindResources(int program,
163 HdSt_ResourceBinder const &binder) = 0;
164
166 virtual void UnbindResources(int program,
167 HdSt_ResourceBinder const &binder) = 0;
168
170 virtual void AddBindings(HdStBindingRequestVector* customBindings) = 0;
171
177 HDST_API
178 virtual TfToken GetMaterialTag() const;
179
185 public:
186 HDST_API
187 void AddSource(HdBufferArrayRangeSharedPtr const &range,
188 HdBufferSourceSharedPtr const &source);
189
190 HDST_API
191 void AddSources(HdBufferArrayRangeSharedPtr const &range,
192 HdBufferSourceSharedPtrVector &&sources);
193
194 HDST_API
195 void AddComputation(HdBufferArrayRangeSharedPtr const &range,
196 HdStComputationSharedPtr const &computation,
197 HdStComputeQueue const queue);
198
199 HdStResourceRegistry * GetResourceRegistry() const {
200 return _registry;
201 }
202
203 private:
204 friend class HdStResourceRegistry;
206 HdStResourceRegistry *_registry;
207 };
208
216 HDST_API
218
219private:
220
221 // No copying
222 HdStShaderCode(const HdStShaderCode &) = delete;
223 HdStShaderCode &operator =(const HdStShaderCode &) = delete;
224
225 // Returns the HioGlslfx instance used to configure this shader.
226 // This can return nullptr for shaders without a GLSLFX instance.
227 virtual HioGlslfx const * _GetGlslfx() const;
228};
229
230
231PXR_NAMESPACE_CLOSE_SCOPE
232
233#endif //HDST_SHADER_H
A central registry of all GPU resources.
The context available in implementations of AddResourcesFromTextures.
Definition: shaderCode.h:184
A base class representing the implementation (code) of a shader, used in conjunction with HdRenderPas...
Definition: shaderCode.h:59
static HDST_API ID ComputeHash(HdStShaderCodeSharedPtrVector const &shaders)
Returns the combined hash values of multiple shaders.
virtual void BindResources(int program, HdSt_ResourceBinder const &binder)=0
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
size_t hash
A hash unique to the corresponding asset; used to split draw batches when not using bindless textures...
Definition: shaderCode.h:142
virtual HDST_API TfTokenVector const & GetPrimvarNames() const
Returns the names of primvar that are used by this shader.
HdStTextureType type
Equal to handle->GetTextureObject()->GetTextureType().
Definition: shaderCode.h:136
HdStTextureHandleSharedPtr handle
The texture.
Definition: shaderCode.h:138
virtual HDST_API HdSt_MaterialParamVector const & GetParams() const
Returns the shader parameters for this shader.
virtual HDST_API NamedTextureHandleVector const & GetNamedTextureHandles() const
Textures that need to be bound for this shader.
virtual void AddBindings(HdStBindingRequestVector *customBindings)=0
Add custom bindings (used by codegen)
virtual HDST_API void AddResourcesFromTextures(ResourceContext &ctx) const
This function is called after textures have been allocated and loaded to add buffer sources and compu...
virtual std::string GetSource(TfToken const &shaderStageKey) const =0
Returns the shader source provided by this shader for shaderStageKey.
HDST_API VtDictionary GetLayout(TfTokenVector const &shaderStageKeys) const
Returns the resource layout for the shader stages specified by shaderStageKeys.
virtual HDST_API ID ComputeTextureSourceHash() const
Returns the hash value of the paths of the texture prims consumed by this shader.
virtual HDST_API TfToken GetMaterialTag() const
Material tags can be set in the meta-data of a glslfx file to control what rprim collection that prim...
virtual void UnbindResources(int program, HdSt_ResourceBinder const &binder)=0
Unbinds shader-specific resources.
virtual HDST_API bool IsEnabledPrimvarFiltering() const
Returns whether primvar filtering is enabled for this shader.
virtual HDST_API HdBufferArrayRangeSharedPtr const & GetShaderData() const
Returns a buffer which stores parameter fallback values and texture handles.
virtual ID ComputeHash() const =0
Returns the hash value of the shader code and configuration.
TfToken name
Name by which the texture will be accessed, i.e., the name of the accesor for thexture will be HdGet_...
Definition: shaderCode.h:130
Information necessary to bind textures and create accessor for the texture.
Definition: shaderCode.h:126
A class representing the config and shader source of a glslfx file.
Definition: glslfx.h:134
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A map with string keys and VtValue values.
Definition: dictionary.h:43
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440