blob: 2fd938c15402e7d8b51b9b256ca54740018e7f12 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Corentin Wallezf07e3bd2017-04-20 14:38:20 -04002//
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
Corentin Wallez30965a72018-07-24 16:42:33 +020015#ifndef DAWNNATIVE_SAMPLER_H_
16#define DAWNNATIVE_SAMPLER_H_
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040017
Austin Eng84bcf442019-10-30 00:20:03 +000018#include "dawn_native/CachedObject.h"
Corentin Wallezd37523f2018-07-24 13:53:51 +020019#include "dawn_native/Error.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040020
Corentin Wallez36afbb62018-07-25 17:03:23 +020021#include "dawn_native/dawn_platform.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040022
Corentin Wallez49a65d02018-07-24 16:45:45 +020023namespace dawn_native {
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040024
Corentin Wallez1ae19e82018-05-17 17:09:07 -040025 class DeviceBase;
26
Corentin Wallez36afbb62018-07-25 17:03:23 +020027 MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor);
Corentin Wallez1ae19e82018-05-17 17:09:07 -040028
Austin Eng84bcf442019-10-30 00:20:03 +000029 class SamplerBase : public CachedObject {
Corentin Wallezc1400f02017-11-24 13:59:42 -050030 public:
Austin Eng84bcf442019-10-30 00:20:03 +000031 SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor);
Idan Raiter2bc31692019-05-20 18:16:34 +000032 ~SamplerBase() override;
Corentin Walleza594f8f2019-02-13 13:09:18 +000033
34 static SamplerBase* MakeError(DeviceBase* device);
35
Austin Eng7817a9a2020-04-20 23:43:20 +000036 bool HasCompareFunction() const;
37
Bryan Bernhart24bf7a42020-12-03 18:42:13 +000038 // Functions necessary for the unordered_set<SamplerBase*>-based cache.
39 size_t ComputeContentHash() override;
40
Idan Raiter2bc31692019-05-20 18:16:34 +000041 struct EqualityFunc {
42 bool operator()(const SamplerBase* a, const SamplerBase* b) const;
43 };
44
shrekshaof8c5e4a2020-12-24 03:11:17 +000045 uint16_t GetMaxAnisotropy() const {
46 return mMaxAnisotropy;
47 }
48
Corentin Walleza594f8f2019-02-13 13:09:18 +000049 private:
50 SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag);
Idan Raiter2bc31692019-05-20 18:16:34 +000051
52 // TODO(cwallez@chromium.org): Store a crypto hash of the items instead?
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000053 wgpu::AddressMode mAddressModeU;
54 wgpu::AddressMode mAddressModeV;
55 wgpu::AddressMode mAddressModeW;
56 wgpu::FilterMode mMagFilter;
57 wgpu::FilterMode mMinFilter;
58 wgpu::FilterMode mMipmapFilter;
Idan Raiter2bc31692019-05-20 18:16:34 +000059 float mLodMinClamp;
60 float mLodMaxClamp;
Corentin Wallez1f6c8c42019-10-23 11:57:41 +000061 wgpu::CompareFunction mCompareFunction;
shrekshaof8c5e4a2020-12-24 03:11:17 +000062 uint16_t mMaxAnisotropy;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040063 };
64
Corentin Wallez49a65d02018-07-24 16:45:45 +020065} // namespace dawn_native
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040066
Corentin Wallez30965a72018-07-24 16:42:33 +020067#endif // DAWNNATIVE_SAMPLER_H_