2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Sampler.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-05-20 18:16:34 +00:00
|
|
|
#include "common/HashUtils.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Device.h"
|
|
|
|
#include "dawn_native/ValidationUtils_autogen.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-05-22 17:18:52 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) {
|
2018-09-10 14:17:24 +00:00
|
|
|
if (descriptor->nextInChain != nullptr) {
|
|
|
|
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
|
|
|
|
}
|
2019-01-04 04:56:08 +00:00
|
|
|
|
2019-12-12 11:41:02 +00:00
|
|
|
if (std::isnan(descriptor->lodMinClamp) || std::isnan(descriptor->lodMaxClamp)) {
|
|
|
|
return DAWN_VALIDATION_ERROR("LOD clamp bounds must not be NaN");
|
2019-05-22 17:18:52 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 04:56:08 +00:00
|
|
|
if (descriptor->lodMinClamp < 0 || descriptor->lodMaxClamp < 0) {
|
2019-12-12 11:41:02 +00:00
|
|
|
return DAWN_VALIDATION_ERROR("LOD clamp bounds must be positive");
|
2019-01-04 04:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptor->lodMinClamp > descriptor->lodMaxClamp) {
|
|
|
|
return DAWN_VALIDATION_ERROR(
|
|
|
|
"Min lod clamp value cannot greater than max lod clamp value");
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:45:17 +00:00
|
|
|
DAWN_TRY(ValidateFilterMode(descriptor->minFilter));
|
|
|
|
DAWN_TRY(ValidateFilterMode(descriptor->magFilter));
|
|
|
|
DAWN_TRY(ValidateFilterMode(descriptor->mipmapFilter));
|
|
|
|
DAWN_TRY(ValidateAddressMode(descriptor->addressModeU));
|
|
|
|
DAWN_TRY(ValidateAddressMode(descriptor->addressModeV));
|
|
|
|
DAWN_TRY(ValidateAddressMode(descriptor->addressModeW));
|
2019-07-08 08:29:57 +00:00
|
|
|
DAWN_TRY(ValidateCompareFunction(descriptor->compare));
|
2018-05-28 18:26:40 +00:00
|
|
|
return {};
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 21:09:07 +00:00
|
|
|
// SamplerBase
|
2018-03-29 18:02:52 +00:00
|
|
|
|
2019-10-30 00:20:03 +00:00
|
|
|
SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor)
|
|
|
|
: CachedObject(device),
|
2019-05-20 18:16:34 +00:00
|
|
|
mAddressModeU(descriptor->addressModeU),
|
|
|
|
mAddressModeV(descriptor->addressModeV),
|
|
|
|
mAddressModeW(descriptor->addressModeW),
|
|
|
|
mMagFilter(descriptor->magFilter),
|
|
|
|
mMinFilter(descriptor->minFilter),
|
|
|
|
mMipmapFilter(descriptor->mipmapFilter),
|
|
|
|
mLodMinClamp(descriptor->lodMinClamp),
|
|
|
|
mLodMaxClamp(descriptor->lodMaxClamp),
|
2019-10-30 00:20:03 +00:00
|
|
|
mCompareFunction(descriptor->compare) {
|
2017-05-08 13:17:44 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
2019-10-30 00:20:03 +00:00
|
|
|
: CachedObject(device, tag) {
|
2019-02-13 13:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 18:16:34 +00:00
|
|
|
SamplerBase::~SamplerBase() {
|
2019-10-30 00:20:03 +00:00
|
|
|
if (IsCachedReference()) {
|
2019-05-20 18:16:34 +00:00
|
|
|
GetDevice()->UncacheSampler(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
// static
|
|
|
|
SamplerBase* SamplerBase::MakeError(DeviceBase* device) {
|
|
|
|
return new SamplerBase(device, ObjectBase::kError);
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:16:34 +00:00
|
|
|
size_t SamplerBase::HashFunc::operator()(const SamplerBase* module) const {
|
|
|
|
size_t hash = 0;
|
|
|
|
|
|
|
|
HashCombine(&hash, module->mAddressModeU);
|
|
|
|
HashCombine(&hash, module->mAddressModeV);
|
|
|
|
HashCombine(&hash, module->mAddressModeW);
|
|
|
|
HashCombine(&hash, module->mMagFilter);
|
|
|
|
HashCombine(&hash, module->mMinFilter);
|
|
|
|
HashCombine(&hash, module->mMipmapFilter);
|
|
|
|
HashCombine(&hash, module->mLodMinClamp);
|
|
|
|
HashCombine(&hash, module->mLodMaxClamp);
|
|
|
|
HashCombine(&hash, module->mCompareFunction);
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SamplerBase::EqualityFunc::operator()(const SamplerBase* a, const SamplerBase* b) const {
|
2019-05-22 17:18:52 +00:00
|
|
|
if (a == b) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-12 11:41:02 +00:00
|
|
|
ASSERT(!std::isnan(a->mLodMinClamp));
|
|
|
|
ASSERT(!std::isnan(b->mLodMinClamp));
|
|
|
|
ASSERT(!std::isnan(a->mLodMaxClamp));
|
|
|
|
ASSERT(!std::isnan(b->mLodMaxClamp));
|
2019-05-22 17:18:52 +00:00
|
|
|
|
2019-05-20 18:16:34 +00:00
|
|
|
return a->mAddressModeU == b->mAddressModeU && a->mAddressModeV == b->mAddressModeV &&
|
|
|
|
a->mAddressModeW == b->mAddressModeW && a->mMagFilter == b->mMagFilter &&
|
|
|
|
a->mMinFilter == b->mMinFilter && a->mMipmapFilter == b->mMipmapFilter &&
|
|
|
|
a->mLodMinClamp == b->mLodMinClamp && a->mLodMaxClamp == b->mLodMaxClamp &&
|
|
|
|
a->mCompareFunction == b->mCompareFunction;
|
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|