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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
8 #define PXR_IMAGING_HD_ST_SAMPLER_OBJECT_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 #include "pxr/imaging/hdSt/enums.h"
13 
14 #include "pxr/imaging/hgi/handle.h"
15 #include "pxr/imaging/hd/types.h"
16 
17 #include <memory>
18 
20 
21 class Hgi;
28 
30  std::shared_ptr<class HdStSamplerObject>;
31 
32 /// \class HdStSamplerObject
33 ///
34 /// A base class encapsulating a GPU sampler object.
35 ///
36 /// The subclasses of HdStSamplerObject mirror the subclasses of
37 /// HdStTextureObject with the intention that they will be used in
38 /// conjunction (e.g., the not yet existing HdStPtexSamplerObject will
39 /// have two samplers and texture sampler handles for the texels and
40 /// layout texture in a HdStPtexTextureObject).
41 ///
42 /// The GPU resources is con-/destructed immediately in the
43 /// c'tor/d'tor. By going through the HdSt_SamplerObjectRegistry, we
44 /// can obtain a shared pointer that can safely be dropped in a
45 /// different thread. The HdSt_SamplerObjectRegistry is also dispatching
46 /// by texture type to construct the corresponding sampler type.
47 ///
49 {
50 public:
51  virtual ~HdStSamplerObject() = 0;
52 
53 protected:
54  explicit HdStSamplerObject(
55  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
56 
57  Hgi* _GetHgi() const;
59 };
60 
61 /// \class HdStUvSamplerObject
62 ///
63 /// A sampler suitable for HdStUvTextureObject.
64 ///
65 class HdStUvSamplerObject final : public HdStSamplerObject {
66 public:
67  HDST_API
69  HdStUvTextureObject const &uvTexture,
70  HdSamplerParameters const &samplerParameters,
71  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
72 
73  HDST_API
74  ~HdStUvSamplerObject() override;
75 
76  /// The sampler.
77  ///
78  const HgiSamplerHandle &GetSampler() const {
79  return _sampler;
80  }
81 
82 private:
83  HgiSamplerHandle _sampler;
84 };
85 
86 /// \class HdStFieldSamplerObject
87 ///
88 /// A sampler suitable for HdStFieldTextureObject.
89 ///
91 public:
93  HdStFieldTextureObject const &uvTexture,
94  HdSamplerParameters const &samplerParameters,
95  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
96 
97  ~HdStFieldSamplerObject() override;
98 
99  /// The sampler.
100  ///
101  const HgiSamplerHandle &GetSampler() const {
102  return _sampler;
103  }
104 
105 private:
106  HgiSamplerHandle _sampler;
107 };
108 
109 /// \class HdStPtexSamplerObject
110 ///
111 /// Ptex doesn't bind samplers, so this class is just holding a
112 /// sampler to resolve handles for bindless textures.
113 ///
115 public:
117  HdStPtexTextureObject const &ptexTexture,
118  // samplerParameters are ignored by ptex
119  HdSamplerParameters const &samplerParameters,
120  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
121 
122  ~HdStPtexSamplerObject() override;
123 
124  /// The GPU sampler object for the texels texture.
125  ///
127  return _texelsSampler;
128  }
129 
130  /// The GPU sampler object for the layout texture.
131  ///
133  return _layoutSampler;
134  }
135 
136 private:
137  HgiSamplerHandle _texelsSampler;
138  HgiSamplerHandle _layoutSampler;
139 };
140 
141 /// \class HdStUdimSamplerObject
142 ///
143 /// A sampler suitable for Udim textures (wraps one GPU sampler
144 /// for the texels texture).
145 ///
147 public:
149  HdStUdimTextureObject const &ptexTexture,
150  // samplerParameters are ignored by udim (at least for now)
151  HdSamplerParameters const &samplerParameters,
152  HdSt_SamplerObjectRegistry * samplerObjectRegistry);
153 
154  ~HdStUdimSamplerObject() override;
155 
156  /// The GPU sampler object for the texels texture.
157  ///
159  return _texelsSampler;
160  }
161 
162  /// The GPU sampler object for the layout texture.
163  ///
165  return _layoutSampler;
166  }
167 
168 private:
169  HgiSamplerHandle _texelsSampler;
170  HgiSamplerHandle _layoutSampler;
171 };
172 
173 template<HdStTextureType textureType>
175 
176 /// \class HdStTypedSamplerObject
177 ///
178 /// A template alias such that, e.g., HdStUvSamplerObject can be
179 /// accessed as HdStTypedSamplerObject<HdStTextureType::Uv>.
180 ///
181 template<HdStTextureType textureType>
184 
185 template<>
188 };
189 
190 template<>
193 };
194 
195 template<>
198 };
199 
200 template<>
203 };
204 
206 
207 #endif
~HdStUdimSamplerObject() override
const HgiSamplerHandle & GetSampler() const
HdSt_SamplerObjectRegistry *const _samplerObjectRegistry
Definition: samplerObject.h:58
HDST_API ~HdStUvSamplerObject() override
HDST_API HdStUvSamplerObject(HdStUvTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
HdStUdimSamplerObject(HdStUdimTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
const HgiSamplerHandle & GetTexelsSampler() const
HdStPtexSamplerObject(HdStPtexTextureObject const &ptexTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
Definition: hgi.h:93
HdStFieldSamplerObject(HdStFieldTextureObject const &uvTexture, HdSamplerParameters const &samplerParameters, HdSt_SamplerObjectRegistry *samplerObjectRegistry)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define HDST_API
Definition: api.h:23
const HgiSamplerHandle & GetLayoutSampler() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdStTextureType
Definition: enums.h:30
virtual ~HdStSamplerObject()=0
const HgiSamplerHandle & GetSampler() const
Definition: samplerObject.h:78
std::shared_ptr< class HdStSamplerObject > HdStSamplerObjectSharedPtr
Definition: samplerObject.h:30
const HgiSamplerHandle & GetLayoutSampler() const
const HgiSamplerHandle & GetTexelsSampler() const
~HdStPtexSamplerObject() override
Hgi * _GetHgi() const
HdStSamplerObject(HdSt_SamplerObjectRegistry *samplerObjectRegistry)
~HdStFieldSamplerObject() override