dawn_native: deduplicate samplers

Bug:dawn:143
Change-Id: I3aee914100fed87ea98cf22a7b90070c165780a2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7361
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
This commit is contained in:
Idan Raiter
2019-05-20 18:16:34 +00:00
committed by Commit Bot service account
parent 027a8f6464
commit 2bc3169f0d
5 changed files with 153 additions and 3 deletions

View File

@@ -14,6 +14,7 @@
#include "dawn_native/Sampler.h"
#include "common/HashUtils.h"
#include "dawn_native/Device.h"
#include "dawn_native/ValidationUtils_autogen.h"
@@ -45,16 +46,60 @@ namespace dawn_native {
// SamplerBase
SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor*) : ObjectBase(device) {
SamplerBase::SamplerBase(DeviceBase* device,
const SamplerDescriptor* descriptor,
bool blueprint)
: ObjectBase(device),
mAddressModeU(descriptor->addressModeU),
mAddressModeV(descriptor->addressModeV),
mAddressModeW(descriptor->addressModeW),
mMagFilter(descriptor->magFilter),
mMinFilter(descriptor->minFilter),
mMipmapFilter(descriptor->mipmapFilter),
mLodMinClamp(descriptor->lodMinClamp),
mLodMaxClamp(descriptor->lodMaxClamp),
mCompareFunction(descriptor->compareFunction),
mIsBlueprint(blueprint) {
}
SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag) {
}
SamplerBase::~SamplerBase() {
// Do not uncache the actual cached object if we are a blueprint
if (!mIsBlueprint && !IsError()) {
GetDevice()->UncacheSampler(this);
}
}
// static
SamplerBase* SamplerBase::MakeError(DeviceBase* device) {
return new SamplerBase(device, ObjectBase::kError);
}
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 {
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;
}
} // namespace dawn_native