• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_SAMPLER_H_
16 #define DAWNNATIVE_SAMPLER_H_
17 
18 #include "dawn_native/CachedObject.h"
19 #include "dawn_native/Error.h"
20 #include "dawn_native/Forward.h"
21 #include "dawn_native/ObjectBase.h"
22 
23 #include "dawn_native/dawn_platform.h"
24 
25 namespace dawn_native {
26 
27     class DeviceBase;
28 
29     MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor);
30 
31     class SamplerBase : public ApiObjectBase, public CachedObject {
32       public:
33         SamplerBase(DeviceBase* device,
34                     const SamplerDescriptor* descriptor,
35                     ApiObjectBase::UntrackedByDeviceTag tag);
36         SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor);
37         ~SamplerBase() override;
38 
39         static SamplerBase* MakeError(DeviceBase* device);
40 
41         ObjectType GetType() const override;
42 
43         bool IsComparison() const;
44         bool IsFiltering() const;
45 
46         // Functions necessary for the unordered_set<SamplerBase*>-based cache.
47         size_t ComputeContentHash() override;
48 
49         struct EqualityFunc {
50             bool operator()(const SamplerBase* a, const SamplerBase* b) const;
51         };
52 
GetMaxAnisotropy()53         uint16_t GetMaxAnisotropy() const {
54             return mMaxAnisotropy;
55         }
56 
57       protected:
58         // Constructor used only for mocking and testing.
59         SamplerBase(DeviceBase* device);
60         void DestroyImpl() override;
61 
62       private:
63         SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag);
64 
65         // TODO(cwallez@chromium.org): Store a crypto hash of the items instead?
66         wgpu::AddressMode mAddressModeU;
67         wgpu::AddressMode mAddressModeV;
68         wgpu::AddressMode mAddressModeW;
69         wgpu::FilterMode mMagFilter;
70         wgpu::FilterMode mMinFilter;
71         wgpu::FilterMode mMipmapFilter;
72         float mLodMinClamp;
73         float mLodMaxClamp;
74         wgpu::CompareFunction mCompareFunction;
75         uint16_t mMaxAnisotropy;
76     };
77 
78 }  // namespace dawn_native
79 
80 #endif  // DAWNNATIVE_SAMPLER_H_
81