HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
samplerObject.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_SAMPLER_OBJECT_H
25 #define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
30 #include "pxr/imaging/hgi/handle.h"
31 #include "pxr/imaging/hd/enums.h"
32 #include "pxr/imaging/hd/types.h"
33 
34 #include <memory>
35 
37 
38 class Hgi;
45 
47  std::shared_ptr<class HdStSamplerObject>;
48 
49 /// \class HdStSamplerObject
50 ///
51 /// A base class encapsulating a GPU sampler object and, optionally, a
52 /// texture sampler handle (for bindless textures).
53 ///
54 /// The subclasses of HdStSamplerObject mirror the subclasses of
55 /// HdStTextureObject with the intention that they will be used in
56 /// conjunction (e.g., the not yet existing HdStPtexSamplerObject will
57 /// have two samplers and texture sampler handles for the texels and
58 /// layout texture in a HdStPtexTextureObject).
59 ///
60 /// The GPU resources is con-/destructed immediately in the
61 /// c'tor/d'tor. By going through the HdSt_SamplerObjectRegistry, we
62 /// can obtain a shared pointer that can safely be dropped in a
63 /// different thread. The HdSt_SamplerObjectRegistry is also dispatching
64 /// by texture type to construct the corresponding sampler type.
65 ///
67 {
68 public:
69  virtual ~HdStSamplerObject() = 0;
70 
71 protected:
72  explicit HdStSamplerObject(
73  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
74 
75  Hgi* _GetHgi() const;
77 };
78 
79 /// \class HdStUvSamplerObject
80 ///
81 /// A sampler suitable for HdStUvTextureObject.
82 ///
83 class HdStUvSamplerObject final : public HdStSamplerObject {
84 public:
85  HDST_API
87  HdStUvTextureObject const &uvTexture,
88  HdSamplerParameters const &samplerParameters,
89  bool createBindlessHandle,
90  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
91 
92  HDST_API
93  ~HdStUvSamplerObject() override;
94 
95  /// The sampler.
96  ///
97  const HgiSamplerHandle &GetSampler() const {
98  return _sampler;
99  }
100 
101  /// The GL sampler texture handle for bindless textures (as returned by
102  /// glGetTextureSamplerHandleARB).
103  ///
104  /// Only available when requested.
105  ///
106  uint64_t GetGLTextureSamplerHandle() const {
107  return _glTextureSamplerHandle;
108  }
109 
110 private:
111  HgiSamplerHandle _sampler;
112  const uint64_t _glTextureSamplerHandle;
113 };
114 
115 /// \class HdStFieldSamplerObject
116 ///
117 /// A sampler suitable for HdStFieldTextureObject.
118 ///
120 public:
122  HdStFieldTextureObject const &uvTexture,
123  HdSamplerParameters const &samplerParameters,
124  bool createBindlessHandle,
125  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
126 
127  ~HdStFieldSamplerObject() override;
128 
129  /// The sampler.
130  ///
131  const HgiSamplerHandle &GetSampler() const {
132  return _sampler;
133  }
134 
135  /// The GL sampler texture handle for bindless textures (as returned by
136  /// glGetTextureSamplerHandleARB).
137  ///
138  /// Only available when requested.
139  ///
140  uint64_t GetGLTextureSamplerHandle() const {
141  return _glTextureSamplerHandle;
142  }
143 
144 private:
145  HgiSamplerHandle _sampler;
146  const uint64_t _glTextureSamplerHandle;
147 };
148 
149 /// \class HdStPtexSamplerObject
150 ///
151 /// Ptex doesn't bind samplers, so this class is just holding the
152 /// texture handles for bindless textures.
153 ///
155 public:
157  HdStPtexTextureObject const &ptexTexture,
158  // samplerParameters are ignored by ptex
159  HdSamplerParameters const &samplerParameters,
160  bool createBindlessHandle,
161  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
162 
163  ~HdStPtexSamplerObject() override;
164 
165  /// The GPU sampler object for the texels texture.
166  ///
168  return _texelsSampler;
169  }
170 
171  /// The GL texture handle for bindless textures (as returned by
172  /// glGetTextureHandleARB). This is for texels.
173  ///
174  /// Only available when requested.
175  ///
176  uint64_t GetTexelsGLTextureHandle() const {
177  return _texelsGLTextureHandle;
178  }
179 
180  /// Similar to GetGLTexelsTextureHandle but for layout.
181  ///
182  uint64_t GetLayoutGLTextureHandle() const {
183  return _layoutGLTextureHandle;
184  }
185 
186 private:
187  HgiSamplerHandle _texelsSampler;
188 
189  const uint64_t _texelsGLTextureHandle;
190  const uint64_t _layoutGLTextureHandle;
191 };
192 
193 /// \class HdStUdimSamplerObject
194 ///
195 /// A sampler suitable for Udim textures (wraps one GPU sampler
196 /// for the texels texture).
197 ///
199 public:
201  HdStUdimTextureObject const &ptexTexture,
202  // samplerParameters are ignored by udim (at least for now)
203  HdSamplerParameters const &samplerParameters,
204  bool createBindlessHandle,
205  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
206 
207  ~HdStUdimSamplerObject() override;
208 
209  /// The GPU sampler object for the texels texture.
210  ///
212  return _texelsSampler;
213  }
214 
215  /// The GL texture handle for bindless textures (as returned by
216  /// glGetTextureHandleARB). This is for texels.
217  ///
218  /// Only available when requested.
219  ///
220  uint64_t GetTexelsGLTextureHandle() const {
221  return _texelsGLTextureHandle;
222  }
223 
224  /// Similar to GetGLTexelsTextureHandle but for layout.
225  ///
226  uint64_t GetLayoutGLTextureHandle() const {
227  return _layoutGLTextureHandle;
228  }
229 
230 private:
231  HgiSamplerHandle _texelsSampler;
232 
233  const uint64_t _texelsGLTextureHandle;
234  const uint64_t _layoutGLTextureHandle;
235 };
236 
237 template<HdTextureType textureType>
239 
240 /// \class HdStTypedSamplerObject
241 ///
242 /// A template alias such that, e.g., HdStUvSamplerObject can be
243 /// accessed as HdStTypedSamplerObject<HdTextureType::Uv>.
244 ///
245 template<HdTextureType textureType>
248 
249 template<>
252 };
253 
254 template<>
257 };
258 
259 template<>
262 };
263 
264 template<>
267 };
268 
270 
271 #endif
uint64_t GetLayoutGLTextureHandle() const
~HdStUdimSamplerObject() override
const HgiSamplerHandle & GetSampler() const
uint64_t GetTexelsGLTextureHandle() const
uint64_t GetLayoutGLTextureHandle() const
HdSt_SamplerObjectRegistry *const _samplerObjectRegistry
Definition: samplerObject.h:76
HDST_API ~HdStUvSamplerObject() override
HdStUdimSamplerObject(HdStUdimTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, bool createBindlessHandle, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
const HgiSamplerHandle & GetTexelsSampler() const
HdTextureType
Definition: enums.h:221
uint64_t GetTexelsGLTextureHandle() const
HDST_API HdStUvSamplerObject(HdStUvTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, bool createBindlessHandle, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
Definition: hgi.h:106
HdStPtexSamplerObject(HdStPtexTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, bool createBindlessHandle, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
uint64_t GetGLTextureSamplerHandle() const
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual ~HdStSamplerObject()=0
uint64_t GetGLTextureSamplerHandle() const
const HgiSamplerHandle & GetSampler() const
Definition: samplerObject.h:97
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:47
HdStFieldSamplerObject(HdStFieldTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, bool createBindlessHandle, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
const HgiSamplerHandle & GetTexelsSampler() const
~HdStPtexSamplerObject() override
Hgi * _GetHgi() const
HdStSamplerObject(HdSt_SamplerObjectRegistry *samplerObjectRegistry)
~HdStFieldSamplerObject() override