From 84bcf44fae4b2880b9dffd1d72a999565e5a5759 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 30 Oct 2019 00:20:03 +0000 Subject: [PATCH] Only mark objects as cached right before inserting into the cache This fixes bugs where we try to uncache objects that fail creation. Bug: dawn:249 Change-Id: Ic60b3ce702dfdda18baa6d263911885a43d3cda7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12820 Reviewed-by: Kai Ninomiya Commit-Queue: Austin Eng --- BUILD.gn | 2 ++ src/dawn_native/AttachmentState.cpp | 4 +-- src/dawn_native/AttachmentState.h | 7 ++--- src/dawn_native/BindGroupLayout.cpp | 9 +++---- src/dawn_native/BindGroupLayout.h | 9 +++---- src/dawn_native/CachedObject.cpp | 27 +++++++++++++++++++ src/dawn_native/CachedObject.h | 41 +++++++++++++++++++++++++++++ src/dawn_native/ComputePipeline.cpp | 8 +++--- src/dawn_native/ComputePipeline.h | 5 +--- src/dawn_native/Device.cpp | 26 +++++++++++++----- src/dawn_native/Pipeline.cpp | 4 +-- src/dawn_native/Pipeline.h | 4 +-- src/dawn_native/PipelineLayout.cpp | 9 +++---- src/dawn_native/PipelineLayout.h | 9 +++---- src/dawn_native/RenderPipeline.cpp | 9 +++---- src/dawn_native/RenderPipeline.h | 6 +---- src/dawn_native/Sampler.cpp | 14 ++++------ src/dawn_native/Sampler.h | 9 +++---- src/dawn_native/ShaderModule.cpp | 13 +++------ src/dawn_native/ShaderModule.h | 9 +++---- 20 files changed, 135 insertions(+), 89 deletions(-) create mode 100644 src/dawn_native/CachedObject.cpp create mode 100644 src/dawn_native/CachedObject.h diff --git a/BUILD.gn b/BUILD.gn index b186c00d7a..ef14cc67bb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -156,6 +156,8 @@ source_set("libdawn_native_sources") { "src/dawn_native/BuddyMemoryAllocator.h", "src/dawn_native/Buffer.cpp", "src/dawn_native/Buffer.h", + "src/dawn_native/CachedObject.cpp", + "src/dawn_native/CachedObject.h", "src/dawn_native/CommandAllocator.cpp", "src/dawn_native/CommandAllocator.h", "src/dawn_native/CommandBuffer.cpp", diff --git a/src/dawn_native/AttachmentState.cpp b/src/dawn_native/AttachmentState.cpp index 79ce913def..5ff33b3309 100644 --- a/src/dawn_native/AttachmentState.cpp +++ b/src/dawn_native/AttachmentState.cpp @@ -116,11 +116,11 @@ namespace dawn_native { } AttachmentState::AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint) - : AttachmentStateBlueprint(blueprint), RefCounted(), mDevice(device) { + : AttachmentStateBlueprint(blueprint), CachedObject(device) { } AttachmentState::~AttachmentState() { - mDevice->UncacheAttachmentState(this); + GetDevice()->UncacheAttachmentState(this); } std::bitset AttachmentState::GetColorAttachmentsMask() const { diff --git a/src/dawn_native/AttachmentState.h b/src/dawn_native/AttachmentState.h index d31ea0696c..74c5432f23 100644 --- a/src/dawn_native/AttachmentState.h +++ b/src/dawn_native/AttachmentState.h @@ -16,7 +16,7 @@ #define DAWNNATIVE_ATTACHMENTSTATE_H_ #include "common/Constants.h" -#include "dawn_native/RefCounted.h" +#include "dawn_native/CachedObject.h" #include "dawn_native/dawn_platform.h" @@ -56,7 +56,7 @@ namespace dawn_native { uint32_t mSampleCount = 0; }; - class AttachmentState : public AttachmentStateBlueprint, public RefCounted { + class AttachmentState : public AttachmentStateBlueprint, public CachedObject { public: AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint); ~AttachmentState() override; @@ -66,9 +66,6 @@ namespace dawn_native { bool HasDepthStencilAttachment() const; wgpu::TextureFormat GetDepthStencilFormat() const; uint32_t GetSampleCount() const; - - private: - DeviceBase* mDevice; }; } // namespace dawn_native diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index ac5308d0ba..d15103391c 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -129,9 +129,8 @@ namespace dawn_native { // BindGroupLayoutBase BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, - const BindGroupLayoutDescriptor* descriptor, - bool blueprint) - : ObjectBase(device), mIsBlueprint(blueprint) { + const BindGroupLayoutDescriptor* descriptor) + : CachedObject(device) { for (uint32_t i = 0; i < descriptor->bindingCount; ++i) { auto& binding = descriptor->bindings[i]; @@ -171,12 +170,12 @@ namespace dawn_native { } BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag), mIsBlueprint(true) { + : CachedObject(device, tag) { } BindGroupLayoutBase::~BindGroupLayoutBase() { // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncacheBindGroupLayout(this); } } diff --git a/src/dawn_native/BindGroupLayout.h b/src/dawn_native/BindGroupLayout.h index 8c275f0b5f..4c0dd7aae8 100644 --- a/src/dawn_native/BindGroupLayout.h +++ b/src/dawn_native/BindGroupLayout.h @@ -16,9 +16,9 @@ #define DAWNNATIVE_BINDGROUPLAYOUT_H_ #include "common/Constants.h" +#include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" #include "dawn_native/Forward.h" -#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -30,11 +30,9 @@ namespace dawn_native { MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*, const BindGroupLayoutDescriptor* descriptor); - class BindGroupLayoutBase : public ObjectBase { + class BindGroupLayoutBase : public CachedObject { public: - BindGroupLayoutBase(DeviceBase* device, - const BindGroupLayoutDescriptor* descriptor, - bool blueprint = false); + BindGroupLayoutBase(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); ~BindGroupLayoutBase() override; static BindGroupLayoutBase* MakeError(DeviceBase* device); @@ -66,7 +64,6 @@ namespace dawn_native { BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag); LayoutBindingInfo mBindingInfo; - bool mIsBlueprint = false; uint32_t mDynamicUniformBufferCount = 0; uint32_t mDynamicStorageBufferCount = 0; }; diff --git a/src/dawn_native/CachedObject.cpp b/src/dawn_native/CachedObject.cpp new file mode 100644 index 0000000000..b91baed167 --- /dev/null +++ b/src/dawn_native/CachedObject.cpp @@ -0,0 +1,27 @@ +// Copyright 2019 The Dawn Authors +// +// 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. + +#include "dawn_native/CachedObject.h" + +namespace dawn_native { + + bool CachedObject::IsCachedReference() const { + return mIsCachedReference; + } + + void CachedObject::SetIsCachedReference() { + mIsCachedReference = true; + } + +} // namespace dawn_native diff --git a/src/dawn_native/CachedObject.h b/src/dawn_native/CachedObject.h new file mode 100644 index 0000000000..b498b91771 --- /dev/null +++ b/src/dawn_native/CachedObject.h @@ -0,0 +1,41 @@ +// Copyright 2019 The Dawn Authors +// +// 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. + +#ifndef DAWNNATIVE_CACHED_OBJECT_H_ +#define DAWNNATIVE_CACHED_OBJECT_H_ + +#include "dawn_native/ObjectBase.h" + +namespace dawn_native { + + // Some objects are cached so that instead of creating new duplicate objects, + // we increase the refcount of an existing object. + // When an object is successfully created, the device should call + // SetIsCachedReference() and insert the object into the cache. + class CachedObject : public ObjectBase { + public: + using ObjectBase::ObjectBase; + + bool IsCachedReference() const; + + private: + friend class DeviceBase; + void SetIsCachedReference(); + + bool mIsCachedReference = false; + }; + +} // namespace dawn_native + +#endif // DAWNNATIVE_CACHED_OBJECT_H_ diff --git a/src/dawn_native/ComputePipeline.cpp b/src/dawn_native/ComputePipeline.cpp index a9bfb21a10..137d6488e0 100644 --- a/src/dawn_native/ComputePipeline.cpp +++ b/src/dawn_native/ComputePipeline.cpp @@ -34,12 +34,10 @@ namespace dawn_native { // ComputePipelineBase ComputePipelineBase::ComputePipelineBase(DeviceBase* device, - const ComputePipelineDescriptor* descriptor, - bool blueprint) + const ComputePipelineDescriptor* descriptor) : PipelineBase(device, descriptor->layout, wgpu::ShaderStage::Compute), mModule(descriptor->computeStage.module), - mEntryPoint(descriptor->computeStage.entryPoint), - mIsBlueprint(blueprint) { + mEntryPoint(descriptor->computeStage.entryPoint) { } ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) @@ -48,7 +46,7 @@ namespace dawn_native { ComputePipelineBase::~ComputePipelineBase() { // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncacheComputePipeline(this); } } diff --git a/src/dawn_native/ComputePipeline.h b/src/dawn_native/ComputePipeline.h index 006c469d96..43d7966568 100644 --- a/src/dawn_native/ComputePipeline.h +++ b/src/dawn_native/ComputePipeline.h @@ -26,9 +26,7 @@ namespace dawn_native { class ComputePipelineBase : public PipelineBase { public: - ComputePipelineBase(DeviceBase* device, - const ComputePipelineDescriptor* descriptor, - bool blueprint = false); + ComputePipelineBase(DeviceBase* device, const ComputePipelineDescriptor* descriptor); ~ComputePipelineBase() override; static ComputePipelineBase* MakeError(DeviceBase* device); @@ -47,7 +45,6 @@ namespace dawn_native { // TODO(cwallez@chromium.org): Store a crypto hash of the module instead. Ref mModule; std::string mEntryPoint; - bool mIsBlueprint = false; }; } // namespace dawn_native diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 8fa12782b4..bbb83bd975 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -191,7 +191,7 @@ namespace dawn_native { ResultOrError DeviceBase::GetOrCreateBindGroupLayout( const BindGroupLayoutDescriptor* descriptor) { - BindGroupLayoutBase blueprint(this, descriptor, true); + BindGroupLayoutBase blueprint(this, descriptor); auto iter = mCaches->bindGroupLayouts.find(&blueprint); if (iter != mCaches->bindGroupLayouts.end()) { @@ -201,18 +201,20 @@ namespace dawn_native { BindGroupLayoutBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreateBindGroupLayoutImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->bindGroupLayouts.insert(backendObj); return backendObj; } void DeviceBase::UncacheBindGroupLayout(BindGroupLayoutBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->bindGroupLayouts.erase(obj); ASSERT(removedCount == 1); } ResultOrError DeviceBase::GetOrCreateComputePipeline( const ComputePipelineDescriptor* descriptor) { - ComputePipelineBase blueprint(this, descriptor, true); + ComputePipelineBase blueprint(this, descriptor); auto iter = mCaches->computePipelines.find(&blueprint); if (iter != mCaches->computePipelines.end()) { @@ -222,18 +224,20 @@ namespace dawn_native { ComputePipelineBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreateComputePipelineImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->computePipelines.insert(backendObj); return backendObj; } void DeviceBase::UncacheComputePipeline(ComputePipelineBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->computePipelines.erase(obj); ASSERT(removedCount == 1); } ResultOrError DeviceBase::GetOrCreatePipelineLayout( const PipelineLayoutDescriptor* descriptor) { - PipelineLayoutBase blueprint(this, descriptor, true); + PipelineLayoutBase blueprint(this, descriptor); auto iter = mCaches->pipelineLayouts.find(&blueprint); if (iter != mCaches->pipelineLayouts.end()) { @@ -243,18 +247,20 @@ namespace dawn_native { PipelineLayoutBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreatePipelineLayoutImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->pipelineLayouts.insert(backendObj); return backendObj; } void DeviceBase::UncachePipelineLayout(PipelineLayoutBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->pipelineLayouts.erase(obj); ASSERT(removedCount == 1); } ResultOrError DeviceBase::GetOrCreateRenderPipeline( const RenderPipelineDescriptor* descriptor) { - RenderPipelineBase blueprint(this, descriptor, true); + RenderPipelineBase blueprint(this, descriptor); auto iter = mCaches->renderPipelines.find(&blueprint); if (iter != mCaches->renderPipelines.end()) { @@ -264,18 +270,20 @@ namespace dawn_native { RenderPipelineBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreateRenderPipelineImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->renderPipelines.insert(backendObj); return backendObj; } void DeviceBase::UncacheRenderPipeline(RenderPipelineBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->renderPipelines.erase(obj); ASSERT(removedCount == 1); } ResultOrError DeviceBase::GetOrCreateSampler( const SamplerDescriptor* descriptor) { - SamplerBase blueprint(this, descriptor, true); + SamplerBase blueprint(this, descriptor); auto iter = mCaches->samplers.find(&blueprint); if (iter != mCaches->samplers.end()) { @@ -285,18 +293,20 @@ namespace dawn_native { SamplerBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreateSamplerImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->samplers.insert(backendObj); return backendObj; } void DeviceBase::UncacheSampler(SamplerBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->samplers.erase(obj); ASSERT(removedCount == 1); } ResultOrError DeviceBase::GetOrCreateShaderModule( const ShaderModuleDescriptor* descriptor) { - ShaderModuleBase blueprint(this, descriptor, true); + ShaderModuleBase blueprint(this, descriptor); auto iter = mCaches->shaderModules.find(&blueprint); if (iter != mCaches->shaderModules.end()) { @@ -306,11 +316,13 @@ namespace dawn_native { ShaderModuleBase* backendObj; DAWN_TRY_ASSIGN(backendObj, CreateShaderModuleImpl(descriptor)); + backendObj->SetIsCachedReference(); mCaches->shaderModules.insert(backendObj); return backendObj; } void DeviceBase::UncacheShaderModule(ShaderModuleBase* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->shaderModules.erase(obj); ASSERT(removedCount == 1); } @@ -323,6 +335,7 @@ namespace dawn_native { } Ref attachmentState = AcquireRef(new AttachmentState(this, *blueprint)); + attachmentState->SetIsCachedReference(); mCaches->attachmentStates.insert(attachmentState.Get()); return attachmentState; } @@ -346,6 +359,7 @@ namespace dawn_native { } void DeviceBase::UncacheAttachmentState(AttachmentState* obj) { + ASSERT(obj->IsCachedReference()); size_t removedCount = mCaches->attachmentStates.erase(obj); ASSERT(removedCount == 1); } diff --git a/src/dawn_native/Pipeline.cpp b/src/dawn_native/Pipeline.cpp index 246afe9a81..9d24011250 100644 --- a/src/dawn_native/Pipeline.cpp +++ b/src/dawn_native/Pipeline.cpp @@ -43,11 +43,11 @@ namespace dawn_native { PipelineBase::PipelineBase(DeviceBase* device, PipelineLayoutBase* layout, wgpu::ShaderStage stages) - : ObjectBase(device), mStageMask(stages), mLayout(layout) { + : CachedObject(device), mStageMask(stages), mLayout(layout) { } PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : CachedObject(device, tag) { } wgpu::ShaderStage PipelineBase::GetStageMask() const { diff --git a/src/dawn_native/Pipeline.h b/src/dawn_native/Pipeline.h index 5373bd0123..5c6e6ee53e 100644 --- a/src/dawn_native/Pipeline.h +++ b/src/dawn_native/Pipeline.h @@ -15,8 +15,8 @@ #ifndef DAWNNATIVE_PIPELINE_H_ #define DAWNNATIVE_PIPELINE_H_ +#include "dawn_native/CachedObject.h" #include "dawn_native/Forward.h" -#include "dawn_native/ObjectBase.h" #include "dawn_native/PerStage.h" #include "dawn_native/PipelineLayout.h" #include "dawn_native/ShaderModule.h" @@ -33,7 +33,7 @@ namespace dawn_native { const PipelineLayoutBase* layout, SingleShaderStage stage); - class PipelineBase : public ObjectBase { + class PipelineBase : public CachedObject { public: wgpu::ShaderStage GetStageMask() const; PipelineLayoutBase* GetLayout(); diff --git a/src/dawn_native/PipelineLayout.cpp b/src/dawn_native/PipelineLayout.cpp index 8c2a4296a2..4aea64bcac 100644 --- a/src/dawn_native/PipelineLayout.cpp +++ b/src/dawn_native/PipelineLayout.cpp @@ -56,9 +56,8 @@ namespace dawn_native { // PipelineLayoutBase PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, - const PipelineLayoutDescriptor* descriptor, - bool blueprint) - : ObjectBase(device), mIsBlueprint(blueprint) { + const PipelineLayoutDescriptor* descriptor) + : CachedObject(device) { ASSERT(descriptor->bindGroupLayoutCount <= kMaxBindGroups); for (uint32_t group = 0; group < descriptor->bindGroupLayoutCount; ++group) { mBindGroupLayouts[group] = descriptor->bindGroupLayouts[group]; @@ -67,12 +66,12 @@ namespace dawn_native { } PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : CachedObject(device, tag) { } PipelineLayoutBase::~PipelineLayoutBase() { // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncachePipelineLayout(this); } } diff --git a/src/dawn_native/PipelineLayout.h b/src/dawn_native/PipelineLayout.h index f10149805c..fd769f2eaf 100644 --- a/src/dawn_native/PipelineLayout.h +++ b/src/dawn_native/PipelineLayout.h @@ -16,9 +16,9 @@ #define DAWNNATIVE_PIPELINELAYOUT_H_ #include "common/Constants.h" +#include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" #include "dawn_native/Forward.h" -#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -32,11 +32,9 @@ namespace dawn_native { using BindGroupLayoutArray = std::array, kMaxBindGroups>; - class PipelineLayoutBase : public ObjectBase { + class PipelineLayoutBase : public CachedObject { public: - PipelineLayoutBase(DeviceBase* device, - const PipelineLayoutDescriptor* descriptor, - bool blueprint = false); + PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor); ~PipelineLayoutBase() override; static PipelineLayoutBase* MakeError(DeviceBase* device); @@ -65,7 +63,6 @@ namespace dawn_native { BindGroupLayoutArray mBindGroupLayouts; std::bitset mMask; - bool mIsBlueprint = false; }; } // namespace dawn_native diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 69bc2cd096..54c5a72c00 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -366,8 +366,7 @@ namespace dawn_native { // RenderPipelineBase RenderPipelineBase::RenderPipelineBase(DeviceBase* device, - const RenderPipelineDescriptor* descriptor, - bool blueprint) + const RenderPipelineDescriptor* descriptor) : PipelineBase(device, descriptor->layout, wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment), @@ -378,8 +377,7 @@ namespace dawn_native { mVertexModule(descriptor->vertexStage.module), mVertexEntryPoint(descriptor->vertexStage.entryPoint), mFragmentModule(descriptor->fragmentStage->module), - mFragmentEntryPoint(descriptor->fragmentStage->entryPoint), - mIsBlueprint(blueprint) { + mFragmentEntryPoint(descriptor->fragmentStage->entryPoint) { if (descriptor->vertexInput != nullptr) { mVertexInput = *descriptor->vertexInput; } else { @@ -451,8 +449,7 @@ namespace dawn_native { } RenderPipelineBase::~RenderPipelineBase() { - // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncacheRenderPipeline(this); } } diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index aa5c49a27e..7cf2861799 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -54,9 +54,7 @@ namespace dawn_native { class RenderPipelineBase : public PipelineBase { public: - RenderPipelineBase(DeviceBase* device, - const RenderPipelineDescriptor* descriptor, - bool blueprint = false); + RenderPipelineBase(DeviceBase* device, const RenderPipelineDescriptor* descriptor); ~RenderPipelineBase() override; static RenderPipelineBase* MakeError(DeviceBase* device); @@ -119,8 +117,6 @@ namespace dawn_native { std::string mVertexEntryPoint; Ref mFragmentModule; std::string mFragmentEntryPoint; - - bool mIsBlueprint = false; }; } // namespace dawn_native diff --git a/src/dawn_native/Sampler.cpp b/src/dawn_native/Sampler.cpp index 749624090a..230da340e0 100644 --- a/src/dawn_native/Sampler.cpp +++ b/src/dawn_native/Sampler.cpp @@ -52,10 +52,8 @@ namespace dawn_native { // SamplerBase - SamplerBase::SamplerBase(DeviceBase* device, - const SamplerDescriptor* descriptor, - bool blueprint) - : ObjectBase(device), + SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor) + : CachedObject(device), mAddressModeU(descriptor->addressModeU), mAddressModeV(descriptor->addressModeV), mAddressModeW(descriptor->addressModeW), @@ -64,17 +62,15 @@ namespace dawn_native { mMipmapFilter(descriptor->mipmapFilter), mLodMinClamp(descriptor->lodMinClamp), mLodMaxClamp(descriptor->lodMaxClamp), - mCompareFunction(descriptor->compare), - mIsBlueprint(blueprint) { + mCompareFunction(descriptor->compare) { } SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : CachedObject(device, tag) { } SamplerBase::~SamplerBase() { - // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncacheSampler(this); } } diff --git a/src/dawn_native/Sampler.h b/src/dawn_native/Sampler.h index a64e4f2883..a642422e78 100644 --- a/src/dawn_native/Sampler.h +++ b/src/dawn_native/Sampler.h @@ -15,8 +15,8 @@ #ifndef DAWNNATIVE_SAMPLER_H_ #define DAWNNATIVE_SAMPLER_H_ +#include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" -#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -26,11 +26,9 @@ namespace dawn_native { MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor); - class SamplerBase : public ObjectBase { + class SamplerBase : public CachedObject { public: - SamplerBase(DeviceBase* device, - const SamplerDescriptor* descriptor, - bool blueprint = false); + SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor); ~SamplerBase() override; static SamplerBase* MakeError(DeviceBase* device); @@ -56,7 +54,6 @@ namespace dawn_native { float mLodMinClamp; float mLodMaxClamp; wgpu::CompareFunction mCompareFunction; - bool mIsBlueprint = false; }; } // namespace dawn_native diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 84c8efbf44..ef7015bc80 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -84,22 +84,17 @@ namespace dawn_native { // ShaderModuleBase - ShaderModuleBase::ShaderModuleBase(DeviceBase* device, - const ShaderModuleDescriptor* descriptor, - bool blueprint) - : ObjectBase(device), - mCode(descriptor->code, descriptor->code + descriptor->codeSize), - mIsBlueprint(blueprint) { + ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor) + : CachedObject(device), mCode(descriptor->code, descriptor->code + descriptor->codeSize) { mFragmentOutputFormatBaseTypes.fill(Format::Other); } ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : CachedObject(device, tag) { } ShaderModuleBase::~ShaderModuleBase() { - // Do not uncache the actual cached object if we are a blueprint - if (!mIsBlueprint && !IsError()) { + if (IsCachedReference()) { GetDevice()->UncacheShaderModule(this); } } diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index a7c41bc677..b6dd68a76a 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -16,10 +16,10 @@ #define DAWNNATIVE_SHADERMODULE_H_ #include "common/Constants.h" +#include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" #include "dawn_native/Format.h" #include "dawn_native/Forward.h" -#include "dawn_native/ObjectBase.h" #include "dawn_native/PerStage.h" #include "dawn_native/dawn_platform.h" @@ -37,11 +37,9 @@ namespace dawn_native { MaybeError ValidateShaderModuleDescriptor(DeviceBase* device, const ShaderModuleDescriptor* descriptor); - class ShaderModuleBase : public ObjectBase { + class ShaderModuleBase : public CachedObject { public: - ShaderModuleBase(DeviceBase* device, - const ShaderModuleDescriptor* descriptor, - bool blueprint = false); + ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor); ~ShaderModuleBase() override; static ShaderModuleBase* MakeError(DeviceBase* device); @@ -85,7 +83,6 @@ namespace dawn_native { // TODO(cwallez@chromium.org): The code is only stored for deduplication. We could maybe // store a cryptographic hash of the code instead? std::vector mCode; - bool mIsBlueprint = false; ModuleBindingInfo mBindingInfo; std::bitset mUsedVertexAttributes;