HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sampler.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_HGI_SAMPLER_H
8 #define PXR_IMAGING_HGI_SAMPLER_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/base/tf/envSetting.h"
13 
14 #include "pxr/imaging/hgi/api.h"
15 #include "pxr/imaging/hgi/enums.h"
16 #include "pxr/imaging/hgi/handle.h"
17 #include "pxr/imaging/hgi/types.h"
18 
19 #include <string>
20 #include <vector>
21 
23 
24 /// Sets the maximum anisotropic filtering ratio for all samplers.
25 /// By default this is 16x. The actual value used depends on the
26 /// device limits. A value of 1 effectively disables anisotropic sampling.
27 ///
28 HGI_API
30 
31 /// \struct HgiSamplerDesc
32 ///
33 /// Describes the properties needed to create a GPU sampler.
34 ///
35 /// <ul>
36 /// <li>debugName:
37 /// This label can be applied as debug label for GPU debugging.</li>
38 /// <li>magFilter:
39 /// The (magnification) filter used to combine pixels when the sample area is
40 /// smaller than a pixel.</li>
41 /// <li>minFilter:
42 /// The (minification) filter used to combine pixels when the sample area is
43 /// larger than a pixel.</li>
44 /// <li> mipFilter:
45 /// The filter used for combining pixels between two mipmap levels.</li>
46 /// <li>addressMode***:
47 /// Wrapping modes.</li>
48 /// <li>borderColor:
49 /// The border color for clamped texture values.</li>
50 /// <li>enableCompare:
51 /// Enables sampler comparison against a reference value during lookups.</li>
52 /// <li>compareFunction:
53 /// The comparison function to apply if sampler compare is enabled.</li>
54 /// <li>maxAnisotropy:
55 /// Maximum anisotropic filtering ratio. The default value of 16 corresponds
56 /// to the previously internal default value. The actual value used is subject
57 /// to the device maximum supported anisotropy and the HGI_MAX_ANISOTROPY
58 /// setting. A value of 1 effectively disables anisotropic sampling.</li>
59 /// </ul>
60 ///
62 {
71  , enableCompare(false)
73  , maxAnisotropy(16)
74  {}
75 
76  std::string debugName;
86  uint32_t maxAnisotropy;
87 };
88 
89 HGI_API
90 bool operator==(
91  const HgiSamplerDesc& lhs,
92  const HgiSamplerDesc& rhs);
93 
94 HGI_API
95 bool operator!=(
96  const HgiSamplerDesc& lhs,
97  const HgiSamplerDesc& rhs);
98 
99 
100 ///
101 /// \class HgiSampler
102 ///
103 /// Represents a graphics platform independent GPU sampler resource that
104 /// perform texture sampling operations.
105 /// Samplers should be created via Hgi::CreateSampler.
106 ///
108 {
109 public:
110  HGI_API
111  virtual ~HgiSampler();
112 
113  /// The descriptor describes the object.
114  HGI_API
115  HgiSamplerDesc const& GetDescriptor() const;
116 
117  /// This function returns the handle to the Hgi backend's gpu resource, cast
118  /// to a uint64_t. Clients should avoid using this function and instead
119  /// use Hgi base classes so that client code works with any Hgi platform.
120  /// For transitioning code to Hgi, it can however we useful to directly
121  /// access a platform's internal resource handles.
122  /// There is no safety provided in using this. If you by accident pass a
123  /// HgiMetal resource into an OpenGL call, bad things may happen.
124  /// In OpenGL this returns the GLuint resource name.
125  /// In Metal this returns the id<MTLSamplerState> as uint64_t.
126  /// In Vulkan this returns the VkSampler as uint64_t.
127  HGI_API
128  virtual uint64_t GetRawResource() const = 0;
129 
130 protected:
131  HGI_API
132  HgiSampler(HgiSamplerDesc const& desc);
133 
135 
136 private:
137  HgiSampler() = delete;
138  HgiSampler & operator=(const HgiSampler&) = delete;
139  HgiSampler(const HgiSampler&) = delete;
140 };
141 
143 using HgiSamplerHandleVector = std::vector<HgiSamplerHandle>;
144 
145 
147 
148 #endif
HgiSamplerAddressMode
Definition: enums.h:159
HgiCompareFunction
Definition: enums.h:527
HgiCompareFunction compareFunction
Definition: sampler.h:85
HgiMipFilter
Definition: enums.h:202
HgiMipFilter mipFilter
Definition: sampler.h:79
HgiSamplerAddressMode addressModeU
Definition: sampler.h:80
HgiSamplerFilter minFilter
Definition: sampler.h:78
HgiSamplerFilter magFilter
Definition: sampler.h:77
PXR_NAMESPACE_OPEN_SCOPE HGI_API TfEnvSetting< int > HGI_MAX_ANISOTROPY
virtual HGI_API ~HgiSampler()
virtual HGI_API uint64_t GetRawResource() const =0
HgiBorderColor
Definition: enums.h:221
std::string debugName
Definition: sampler.h:76
HGI_API HgiSamplerDesc const & GetDescriptor() const
The descriptor describes the object.
HgiBorderColor borderColor
Definition: sampler.h:83
HgiSamplerDesc()
Definition: sampler.h:63
HgiSamplerAddressMode addressModeV
Definition: sampler.h:81
bool enableCompare
Definition: sampler.h:84
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
#define HGI_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
uint32_t maxAnisotropy
Definition: sampler.h:86
std::vector< HgiSamplerHandle > HgiSamplerHandleVector
Definition: sampler.h:143
HgiSamplerDesc _descriptor
Definition: sampler.h:134
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HgiSamplerFilter
Definition: enums.h:181
HgiSamplerAddressMode addressModeW
Definition: sampler.h:82