diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 78f95dc56a..b0651ead69 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -319,8 +319,6 @@ source_set("sources") { "Serializable.h", "ShaderModule.cpp", "ShaderModule.h", - "StagingBuffer.cpp", - "StagingBuffer.h", "StreamImplTint.cpp", "Subresource.cpp", "Subresource.h", @@ -460,8 +458,6 @@ source_set("sources") { "d3d12/ShaderModuleD3D12.h", "d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp", "d3d12/ShaderVisibleDescriptorAllocatorD3D12.h", - "d3d12/StagingBufferD3D12.cpp", - "d3d12/StagingBufferD3D12.h", "d3d12/StagingDescriptorAllocatorD3D12.cpp", "d3d12/StagingDescriptorAllocatorD3D12.h", "d3d12/StreamImplD3D12.cpp", @@ -515,8 +511,6 @@ source_set("sources") { "metal/SamplerMTL.mm", "metal/ShaderModuleMTL.h", "metal/ShaderModuleMTL.mm", - "metal/StagingBufferMTL.h", - "metal/StagingBufferMTL.mm", "metal/SwapChainMTL.h", "metal/SwapChainMTL.mm", "metal/TextureMTL.h", @@ -656,8 +650,6 @@ source_set("sources") { "vulkan/SamplerVk.h", "vulkan/ShaderModuleVk.cpp", "vulkan/ShaderModuleVk.h", - "vulkan/StagingBufferVk.cpp", - "vulkan/StagingBufferVk.h", "vulkan/StreamImplVk.cpp", "vulkan/SwapChainVk.cpp", "vulkan/SwapChainVk.h", diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp index ace079344b..cd796560c0 100644 --- a/src/dawn/native/Buffer.cpp +++ b/src/dawn/native/Buffer.cpp @@ -88,7 +88,7 @@ class ErrorBuffer final : public BufferBase { UNREACHABLE(); } - void* GetMappedPointerImpl() override { return mFakeMappedData.get(); } + void* GetMappedPointer() override { return mFakeMappedData.get(); } void UnmapImpl() override { mFakeMappedData.reset(); } @@ -238,7 +238,7 @@ void BufferBase::DestroyImpl() { toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); } else if (mState == BufferState::MappedAtCreation) { if (mStagingBuffer != nullptr) { - mStagingBuffer.reset(); + mStagingBuffer = nullptr; } else if (mSize != 0) { toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); } @@ -303,7 +303,7 @@ MaybeError BufferBase::MapAtCreation() { size_t size; if (mSize == 0) { return {}; - } else if (mStagingBuffer) { + } else if (mStagingBuffer != nullptr) { // If there is a staging buffer for initialization, clear its contents directly. // It should be exactly as large as the buffer allocation. ptr = mStagingBuffer->GetMappedPointer(); @@ -311,7 +311,7 @@ MaybeError BufferBase::MapAtCreation() { ASSERT(size == GetAllocatedSize()); } else { // Otherwise, the buffer is directly mappable on the CPU. - ptr = GetMappedPointerImpl(); + ptr = GetMappedPointer(); size = GetAllocatedSize(); } @@ -346,7 +346,14 @@ MaybeError BufferBase::MapAtCreationInternal() { // is initialized. // TODO(crbug.com/dawn/828): Suballocate and reuse memory from a larger staging // buffer so we don't create many small buffers. - DAWN_TRY_ASSIGN(mStagingBuffer, GetDevice()->CreateStagingBuffer(GetAllocatedSize())); + BufferDescriptor stagingBufferDesc = {}; + stagingBufferDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite; + stagingBufferDesc.size = Align(GetAllocatedSize(), 4); + stagingBufferDesc.mappedAtCreation = true; + stagingBufferDesc.label = "Dawn_MappedAtCreationStaging"; + + IgnoreLazyClearCountScope scope(GetDevice()); + DAWN_TRY_ASSIGN(mStagingBuffer, GetDevice()->CreateBuffer(&stagingBufferDesc)); } } @@ -471,7 +478,7 @@ void* BufferBase::GetMappedRange(size_t offset, size_t size, bool writable) { if (mSize == 0) { return reinterpret_cast(intptr_t(0xCAFED00D)); } - uint8_t* start = static_cast(GetMappedPointerImpl()); + uint8_t* start = static_cast(GetMappedPointer()); return start == nullptr ? nullptr : start + offset; } @@ -484,7 +491,7 @@ uint64_t BufferBase::APIGetSize() const { } MaybeError BufferBase::CopyFromStagingBuffer() { - ASSERT(mStagingBuffer); + ASSERT(mStagingBuffer != nullptr); if (mSize == 0) { // Staging buffer is not created if zero size. ASSERT(mStagingBuffer == nullptr); @@ -492,7 +499,7 @@ MaybeError BufferBase::CopyFromStagingBuffer() { } DAWN_TRY( - GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.get(), 0, this, 0, GetAllocatedSize())); + GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.Get(), 0, this, 0, GetAllocatedSize())); DynamicUploader* uploader = GetDevice()->GetDynamicUploader(); uploader->ReleaseStagingBuffer(std::move(mStagingBuffer)); diff --git a/src/dawn/native/Buffer.h b/src/dawn/native/Buffer.h index 130cd37061..729767f343 100644 --- a/src/dawn/native/Buffer.h +++ b/src/dawn/native/Buffer.h @@ -74,6 +74,7 @@ class BufferBase : public ApiObjectBase { bool IsDataInitialized() const; void SetIsDataInitialized(); + virtual void* GetMappedPointer() = 0; void* GetMappedRange(size_t offset, size_t size, bool writable = true); void Unmap(); @@ -128,7 +129,6 @@ class BufferBase : public ApiObjectBase { virtual MaybeError MapAtCreationImpl() = 0; virtual MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) = 0; virtual void UnmapImpl() = 0; - virtual void* GetMappedPointerImpl() = 0; virtual bool IsCPUWritableAtCreation() const = 0; MaybeError CopyFromStagingBuffer(); @@ -146,7 +146,13 @@ class BufferBase : public ApiObjectBase { BufferState mState; bool mIsDataInitialized = false; - std::unique_ptr mStagingBuffer; + // mStagingBuffer is used to implement mappedAtCreation for + // buffers with non-mappable usage. It is transiently allocated + // and released when the mappedAtCreation-buffer is unmapped. + // Because `mStagingBuffer` itself is directly mappable, it will + // not create another staging buffer. + // i.e. buffer->mStagingBuffer->mStagingBuffer... is not possible. + Ref mStagingBuffer; WGPUBufferMapCallback mMapCallback = nullptr; void* mMapUserdata = nullptr; diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index ec2e9906c3..7f5eb2e30b 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -173,8 +173,6 @@ target_sources(dawn_native PRIVATE "Serializable.h" "ShaderModule.cpp" "ShaderModule.h" - "StagingBuffer.cpp" - "StagingBuffer.h" "StreamImplTint.cpp" "Subresource.cpp" "Subresource.h" @@ -324,8 +322,6 @@ if (DAWN_ENABLE_D3D12) "d3d12/ShaderModuleD3D12.h" "d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp" "d3d12/ShaderVisibleDescriptorAllocatorD3D12.h" - "d3d12/StagingBufferD3D12.cpp" - "d3d12/StagingBufferD3D12.h" "d3d12/StagingDescriptorAllocatorD3D12.cpp" "d3d12/StagingDescriptorAllocatorD3D12.h" "d3d12/StreamImplD3D12.cpp" @@ -375,8 +371,6 @@ if (DAWN_ENABLE_METAL) "metal/SamplerMTL.mm" "metal/ShaderModuleMTL.h" "metal/ShaderModuleMTL.mm" - "metal/StagingBufferMTL.h" - "metal/StagingBufferMTL.mm" "metal/SwapChainMTL.h" "metal/SwapChainMTL.mm" "metal/TextureMTL.h" @@ -535,8 +529,6 @@ if (DAWN_ENABLE_VULKAN) "vulkan/SamplerVk.h" "vulkan/ShaderModuleVk.cpp" "vulkan/ShaderModuleVk.h" - "vulkan/StagingBufferVk.cpp" - "vulkan/StagingBufferVk.h" "vulkan/StreamImplVk.cpp" "vulkan/SwapChainVk.cpp" "vulkan/SwapChainVk.h" diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp index 97619357a2..a0d096a1f1 100644 --- a/src/dawn/native/Device.cpp +++ b/src/dawn/native/Device.cpp @@ -1924,7 +1924,7 @@ ExecutionSerial DeviceBase::GetScheduledWorkDoneSerial() const { return HasPendingCommands() ? GetPendingCommandSerial() : GetLastSubmittedCommandSerial(); } -MaybeError DeviceBase::CopyFromStagingToBuffer(StagingBufferBase* source, +MaybeError DeviceBase::CopyFromStagingToBuffer(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -1937,7 +1937,7 @@ MaybeError DeviceBase::CopyFromStagingToBuffer(StagingBufferBase* source, return {}; } -MaybeError DeviceBase::CopyFromStagingToTexture(const StagingBufferBase* source, +MaybeError DeviceBase::CopyFromStagingToTexture(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) { @@ -1948,4 +1948,11 @@ MaybeError DeviceBase::CopyFromStagingToTexture(const StagingBufferBase* source, return {}; } +IgnoreLazyClearCountScope::IgnoreLazyClearCountScope(DeviceBase* device) + : mDevice(device), mLazyClearCountForTesting(device->mLazyClearCountForTesting) {} + +IgnoreLazyClearCountScope::~IgnoreLazyClearCountScope() { + mDevice->mLazyClearCountForTesting = mLazyClearCountForTesting; +} + } // namespace dawn::native diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h index 467a4f80b2..ac8fd447c8 100644 --- a/src/dawn/native/Device.h +++ b/src/dawn/native/Device.h @@ -33,7 +33,6 @@ #include "dawn/native/ObjectBase.h" #include "dawn/native/ObjectType_autogen.h" #include "dawn/native/RefCountedWithExternalCount.h" -#include "dawn/native/StagingBuffer.h" #include "dawn/native/Toggles.h" #include "dawn/native/UsageValidationMode.h" @@ -298,13 +297,12 @@ class DeviceBase : public RefCountedWithExternalCount { Blob LoadCachedBlob(const CacheKey& key); void StoreCachedBlob(const CacheKey& key, const Blob& blob); - virtual ResultOrError> CreateStagingBuffer(size_t size) = 0; - MaybeError CopyFromStagingToBuffer(StagingBufferBase* source, + MaybeError CopyFromStagingToBuffer(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size); - MaybeError CopyFromStagingToTexture(const StagingBufferBase* source, + MaybeError CopyFromStagingToTexture(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels); @@ -349,6 +347,8 @@ class DeviceBase : public RefCountedWithExternalCount { void APIForceLoss(wgpu::DeviceLostReason reason, const char* message); QueueBase* GetQueue() const; + friend class IgnoreLazyClearCountScope; + // Check for passed fences and set the new completed serial MaybeError CheckPassedSerials(); @@ -525,12 +525,12 @@ class DeviceBase : public RefCountedWithExternalCount { // Indicates whether the backend has pending commands to be submitted as soon as possible. virtual bool HasPendingCommands() const = 0; - virtual MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + virtual MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) = 0; - virtual MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + virtual MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) = 0; @@ -587,6 +587,19 @@ class DeviceBase : public RefCountedWithExternalCount { CacheKey mDeviceCacheKey; }; +class IgnoreLazyClearCountScope : public NonMovable { + public: + explicit IgnoreLazyClearCountScope(DeviceBase* device); + ~IgnoreLazyClearCountScope(); + + private: + // Disable heap allocation + void* operator new(size_t) = delete; + + DeviceBase* mDevice; + size_t mLazyClearCountForTesting; +}; + } // namespace dawn::native #endif // SRC_DAWN_NATIVE_DEVICE_H_ diff --git a/src/dawn/native/DynamicUploader.cpp b/src/dawn/native/DynamicUploader.cpp index 9dca0577c5..b4681cc3ba 100644 --- a/src/dawn/native/DynamicUploader.cpp +++ b/src/dawn/native/DynamicUploader.cpp @@ -17,6 +17,7 @@ #include #include "dawn/common/Math.h" +#include "dawn/native/Buffer.h" #include "dawn/native/Device.h" namespace dawn::native { @@ -26,7 +27,7 @@ DynamicUploader::DynamicUploader(DeviceBase* device) : mDevice(device) { std::unique_ptr(new RingBuffer{nullptr, RingBufferAllocator(kRingBufferSize)})); } -void DynamicUploader::ReleaseStagingBuffer(std::unique_ptr stagingBuffer) { +void DynamicUploader::ReleaseStagingBuffer(Ref stagingBuffer) { mReleasedStagingBuffers.Enqueue(std::move(stagingBuffer), mDevice->GetPendingCommandSerial()); } @@ -34,12 +35,19 @@ ResultOrError DynamicUploader::AllocateInternal(uint64_t allocatio ExecutionSerial serial) { // Disable further sub-allocation should the request be too large. if (allocationSize > kRingBufferSize) { - std::unique_ptr stagingBuffer; - DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateStagingBuffer(allocationSize)); + BufferDescriptor bufferDesc = {}; + bufferDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite; + bufferDesc.size = Align(allocationSize, 4); + bufferDesc.mappedAtCreation = true; + bufferDesc.label = "Dawn_DynamicUploaderStaging"; + + IgnoreLazyClearCountScope scope(mDevice); + Ref stagingBuffer; + DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateBuffer(&bufferDesc)); UploadHandle uploadHandle; uploadHandle.mappedBuffer = static_cast(stagingBuffer->GetMappedPointer()); - uploadHandle.stagingBuffer = stagingBuffer.get(); + uploadHandle.stagingBuffer = stagingBuffer.Get(); ReleaseStagingBuffer(std::move(stagingBuffer)); return uploadHandle; @@ -80,16 +88,22 @@ ResultOrError DynamicUploader::AllocateInternal(uint64_t allocatio // Allocate the staging buffer backing the ringbuffer. // Note: the first ringbuffer will be lazily created. if (targetRingBuffer->mStagingBuffer == nullptr) { - std::unique_ptr stagingBuffer; - DAWN_TRY_ASSIGN(stagingBuffer, - mDevice->CreateStagingBuffer(targetRingBuffer->mAllocator.GetSize())); + BufferDescriptor bufferDesc = {}; + bufferDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite; + bufferDesc.size = Align(targetRingBuffer->mAllocator.GetSize(), 4); + bufferDesc.mappedAtCreation = true; + bufferDesc.label = "Dawn_DynamicUploaderStaging"; + + IgnoreLazyClearCountScope scope(mDevice); + Ref stagingBuffer; + DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateBuffer(&bufferDesc)); targetRingBuffer->mStagingBuffer = std::move(stagingBuffer); } ASSERT(targetRingBuffer->mStagingBuffer != nullptr); UploadHandle uploadHandle; - uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer.get(); + uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer.Get(); uploadHandle.mappedBuffer = static_cast(uploadHandle.stagingBuffer->GetMappedPointer()) + startOffset; uploadHandle.startOffset = startOffset; diff --git a/src/dawn/native/DynamicUploader.h b/src/dawn/native/DynamicUploader.h index 9cc6a831c1..0b07bdc3e4 100644 --- a/src/dawn/native/DynamicUploader.h +++ b/src/dawn/native/DynamicUploader.h @@ -18,19 +18,22 @@ #include #include +#include "dawn/common/RefCounted.h" +#include "dawn/native/Error.h" #include "dawn/native/Forward.h" #include "dawn/native/IntegerTypes.h" #include "dawn/native/RingBufferAllocator.h" -#include "dawn/native/StagingBuffer.h" // DynamicUploader is the front-end implementation used to manage multiple ring buffers for upload // usage. namespace dawn::native { +class BufferBase; + struct UploadHandle { uint8_t* mappedBuffer = nullptr; uint64_t startOffset = 0; - StagingBufferBase* stagingBuffer = nullptr; + BufferBase* stagingBuffer = nullptr; }; class DynamicUploader { @@ -42,7 +45,7 @@ class DynamicUploader { // currently no place to track the allocated staging buffers such that they're freed after // pending commands are finished. This should be changed when better resource allocation is // implemented. - void ReleaseStagingBuffer(std::unique_ptr stagingBuffer); + void ReleaseStagingBuffer(Ref stagingBuffer); ResultOrError Allocate(uint64_t allocationSize, ExecutionSerial serial, @@ -56,14 +59,14 @@ class DynamicUploader { uint64_t GetTotalAllocatedSize(); struct RingBuffer { - std::unique_ptr mStagingBuffer; + Ref mStagingBuffer; RingBufferAllocator mAllocator; }; ResultOrError AllocateInternal(uint64_t allocationSize, ExecutionSerial serial); std::vector> mRingBuffers; - SerialQueue> mReleasedStagingBuffers; + SerialQueue> mReleasedStagingBuffers; DeviceBase* mDevice; }; } // namespace dawn::native diff --git a/src/dawn/native/Forward.h b/src/dawn/native/Forward.h index 541cb9c80a..72aeff1df1 100644 --- a/src/dawn/native/Forward.h +++ b/src/dawn/native/Forward.h @@ -47,7 +47,6 @@ class ResourceHeapBase; class SamplerBase; class Surface; class ShaderModuleBase; -class StagingBufferBase; class SwapChainBase; class NewSwapChainBase; class TextureBase; diff --git a/src/dawn/native/StagingBuffer.cpp b/src/dawn/native/StagingBuffer.cpp deleted file mode 100644 index 2b40323c60..0000000000 --- a/src/dawn/native/StagingBuffer.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 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/StagingBuffer.h" - -namespace dawn::native { - -StagingBufferBase::StagingBufferBase(size_t size) : mBufferSize(size) {} - -size_t StagingBufferBase::GetSize() const { - return mBufferSize; -} - -void* StagingBufferBase::GetMappedPointer() const { - return mMappedPointer; -} -} // namespace dawn::native diff --git a/src/dawn/native/StagingBuffer.h b/src/dawn/native/StagingBuffer.h deleted file mode 100644 index 741d2134c0..0000000000 --- a/src/dawn/native/StagingBuffer.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 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 SRC_DAWN_NATIVE_STAGINGBUFFER_H_ -#define SRC_DAWN_NATIVE_STAGINGBUFFER_H_ - -#include "dawn/native/Error.h" - -namespace dawn::native { - -class StagingBufferBase { - public: - explicit StagingBufferBase(size_t size); - virtual ~StagingBufferBase() = default; - - virtual MaybeError Initialize() = 0; - - void* GetMappedPointer() const; - size_t GetSize() const; - - protected: - void* mMappedPointer = nullptr; - - private: - const size_t mBufferSize; -}; - -} // namespace dawn::native - -#endif // SRC_DAWN_NATIVE_STAGINGBUFFER_H_ diff --git a/src/dawn/native/ToBackend.h b/src/dawn/native/ToBackend.h index 89bddc1dc5..9b40c662c6 100644 --- a/src/dawn/native/ToBackend.h +++ b/src/dawn/native/ToBackend.h @@ -98,11 +98,6 @@ struct ToBackendTraits { using BackendType = typename BackendTraits::ShaderModuleType; }; -template -struct ToBackendTraits { - using BackendType = typename BackendTraits::StagingBufferType; -}; - template struct ToBackendTraits { using BackendType = typename BackendTraits::TextureType; diff --git a/src/dawn/native/d3d12/BufferD3D12.cpp b/src/dawn/native/d3d12/BufferD3D12.cpp index eeb19c351f..7ee1103f9d 100644 --- a/src/dawn/native/d3d12/BufferD3D12.cpp +++ b/src/dawn/native/d3d12/BufferD3D12.cpp @@ -377,7 +377,7 @@ void Buffer::UnmapImpl() { ToBackend(GetDevice())->GetResidencyManager()->UnlockAllocation(heap); } -void* Buffer::GetMappedPointerImpl() { +void* Buffer::GetMappedPointer() { // The frontend asks that the pointer returned is from the start of the resource // irrespective of the offset passed in MapAsyncImpl, which is what mMappedData is. return mMappedData; diff --git a/src/dawn/native/d3d12/BufferD3D12.h b/src/dawn/native/d3d12/BufferD3D12.h index cb36a851a1..85c4227e8b 100644 --- a/src/dawn/native/d3d12/BufferD3D12.h +++ b/src/dawn/native/d3d12/BufferD3D12.h @@ -63,7 +63,7 @@ class Buffer final : public BufferBase { void DestroyImpl() override; bool IsCPUWritableAtCreation() const override; MaybeError MapAtCreationImpl() override; - void* GetMappedPointerImpl() override; + void* GetMappedPointer() override; MaybeError MapInternal(bool isWrite, size_t start, size_t end, const char* contextInfo); diff --git a/src/dawn/native/d3d12/CommandBufferD3D12.cpp b/src/dawn/native/d3d12/CommandBufferD3D12.cpp index 08aad3418e..452273e458 100644 --- a/src/dawn/native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp @@ -33,7 +33,6 @@ #include "dawn/native/d3d12/RenderPassBuilderD3D12.h" #include "dawn/native/d3d12/RenderPipelineD3D12.h" #include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h" -#include "dawn/native/d3d12/StagingBufferD3D12.h" #include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h" #include "dawn/native/d3d12/UtilsD3D12.h" @@ -1103,9 +1102,10 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* commandContext commandContext, offset, size)); DAWN_UNUSED(cleared); dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst); - commandList->CopyBufferRegion(dstBuffer->GetD3D12Resource(), offset, - ToBackend(uploadHandle.stagingBuffer)->GetResource(), - uploadHandle.startOffset, size); + commandList->CopyBufferRegion( + dstBuffer->GetD3D12Resource(), offset, + ToBackend(uploadHandle.stagingBuffer)->GetD3D12Resource(), + uploadHandle.startOffset, size); break; } diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index 8ee99cfab2..e2752b51d3 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -44,7 +44,6 @@ #include "dawn/native/d3d12/SamplerHeapCacheD3D12.h" #include "dawn/native/d3d12/ShaderModuleD3D12.h" #include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h" -#include "dawn/native/d3d12/StagingBufferD3D12.h" #include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h" #include "dawn/native/d3d12/SwapChainD3D12.h" #include "dawn/native/d3d12/UtilsD3D12.h" @@ -486,13 +485,7 @@ void Device::InitializeRenderPipelineAsyncImpl(Ref renderPip RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata); } -ResultOrError> Device::CreateStagingBuffer(size_t size) { - std::unique_ptr stagingBuffer = std::make_unique(size, this); - DAWN_TRY(stagingBuffer->Initialize()); - return std::move(stagingBuffer); -} - -MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, +MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -514,22 +507,22 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, } void Device::CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext, - StagingBufferBase* source, + BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) { ASSERT(commandContext != nullptr); Buffer* dstBuffer = ToBackend(destination); - StagingBuffer* srcBuffer = ToBackend(source); + Buffer* srcBuffer = ToBackend(source); dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst); - commandContext->GetCommandList()->CopyBufferRegion(dstBuffer->GetD3D12Resource(), - destinationOffset, srcBuffer->GetResource(), - sourceOffset, size); + commandContext->GetCommandList()->CopyBufferRegion( + dstBuffer->GetD3D12Resource(), destinationOffset, srcBuffer->GetD3D12Resource(), + sourceOffset, size); } -MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, +MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) { @@ -549,7 +542,7 @@ MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, RecordBufferTextureCopyWithBufferHandle( BufferTextureCopyDirection::B2T, commandContext->GetCommandList(), - ToBackend(source)->GetResource(), src.offset, src.bytesPerRow, src.rowsPerImage, *dst, + ToBackend(source)->GetD3D12Resource(), src.offset, src.bytesPerRow, src.rowsPerImage, *dst, copySizePixels); return {}; diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h index a5255edccf..f053ede58d 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.h +++ b/src/dawn/native/d3d12/DeviceD3D12.h @@ -96,21 +96,20 @@ class Device final : public DeviceBase { MaybeError ExecutePendingCommandContext(); - ResultOrError> CreateStagingBuffer(size_t size) override; - MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) override; void CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext, - StagingBufferBase* source, + BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size); - MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) override; diff --git a/src/dawn/native/d3d12/Forward.h b/src/dawn/native/d3d12/Forward.h index 13f7c81e4a..a1bece44c4 100644 --- a/src/dawn/native/d3d12/Forward.h +++ b/src/dawn/native/d3d12/Forward.h @@ -34,7 +34,6 @@ class Queue; class RenderPipeline; class Sampler; class ShaderModule; -class StagingBuffer; class SwapChain; class Texture; class TextureView; @@ -55,7 +54,6 @@ struct D3D12BackendTraits { using ResourceHeapType = Heap; using SamplerType = Sampler; using ShaderModuleType = ShaderModule; - using StagingBufferType = StagingBuffer; using SwapChainType = SwapChain; using TextureType = Texture; using TextureViewType = TextureView; diff --git a/src/dawn/native/d3d12/StagingBufferD3D12.cpp b/src/dawn/native/d3d12/StagingBufferD3D12.cpp deleted file mode 100644 index 989a615990..0000000000 --- a/src/dawn/native/d3d12/StagingBufferD3D12.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2018 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/d3d12/StagingBufferD3D12.h" -#include "dawn/native/d3d12/D3D12Error.h" -#include "dawn/native/d3d12/DeviceD3D12.h" -#include "dawn/native/d3d12/HeapD3D12.h" -#include "dawn/native/d3d12/ResidencyManagerD3D12.h" -#include "dawn/native/d3d12/UtilsD3D12.h" - -namespace dawn::native::d3d12 { - -StagingBuffer::StagingBuffer(size_t size, Device* device) - : StagingBufferBase(size), mDevice(device) {} - -MaybeError StagingBuffer::Initialize() { - D3D12_RESOURCE_DESC resourceDescriptor; - resourceDescriptor.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; - resourceDescriptor.Alignment = 0; - resourceDescriptor.Width = GetSize(); - resourceDescriptor.Height = 1; - resourceDescriptor.DepthOrArraySize = 1; - resourceDescriptor.MipLevels = 1; - resourceDescriptor.Format = DXGI_FORMAT_UNKNOWN; - resourceDescriptor.SampleDesc.Count = 1; - resourceDescriptor.SampleDesc.Quality = 0; - resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; - resourceDescriptor.Flags = D3D12_RESOURCE_FLAG_NONE; - - DAWN_TRY_ASSIGN(mUploadHeap, mDevice->AllocateMemory(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, - D3D12_RESOURCE_STATE_GENERIC_READ, 0)); - - // The mapped buffer can be accessed at any time, so it must be locked to ensure it is never - // evicted. This buffer should already have been made resident when it was created. - DAWN_TRY( - mDevice->GetResidencyManager()->LockAllocation(ToBackend(mUploadHeap.GetResourceHeap()))); - - SetDebugName(mDevice, GetResource(), "Dawn_StagingBuffer"); - - return CheckHRESULT(GetResource()->Map(0, nullptr, &mMappedPointer), "ID3D12Resource::Map"); -} - -StagingBuffer::~StagingBuffer() { - // Always check if the allocation is valid before Unmap. - // The resource would not exist had it failed to allocate. - if (mUploadHeap.GetInfo().mMethod == AllocationMethod::kInvalid) { - return; - } - - // The underlying heap was locked in residency upon creation. We must unlock it when this - // buffer becomes unmapped. - mDevice->GetResidencyManager()->UnlockAllocation(ToBackend(mUploadHeap.GetResourceHeap())); - - // Invalidate the CPU virtual address & flush cache (if needed). - GetResource()->Unmap(0, nullptr); - mMappedPointer = nullptr; - - mDevice->DeallocateMemory(mUploadHeap); -} - -ID3D12Resource* StagingBuffer::GetResource() const { - return mUploadHeap.GetD3D12Resource(); -} -} // namespace dawn::native::d3d12 diff --git a/src/dawn/native/d3d12/StagingBufferD3D12.h b/src/dawn/native/d3d12/StagingBufferD3D12.h deleted file mode 100644 index dcbe7dfedf..0000000000 --- a/src/dawn/native/d3d12/StagingBufferD3D12.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 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 SRC_DAWN_NATIVE_D3D12_STAGINGBUFFERD3D12_H_ -#define SRC_DAWN_NATIVE_D3D12_STAGINGBUFFERD3D12_H_ - -#include "dawn/native/StagingBuffer.h" -#include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h" -#include "dawn/native/d3d12/d3d12_platform.h" - -namespace dawn::native::d3d12 { - -class Device; - -class StagingBuffer : public StagingBufferBase { - public: - StagingBuffer(size_t size, Device* device); - ~StagingBuffer() override; - - ID3D12Resource* GetResource() const; - - MaybeError Initialize() override; - - private: - Device* mDevice; - ResourceHeapAllocation mUploadHeap; -}; -} // namespace dawn::native::d3d12 - -#endif // SRC_DAWN_NATIVE_D3D12_STAGINGBUFFERD3D12_H_ diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp index 9736bf6e07..0d83cb74ed 100644 --- a/src/dawn/native/d3d12/TextureD3D12.cpp +++ b/src/dawn/native/d3d12/TextureD3D12.cpp @@ -33,7 +33,6 @@ #include "dawn/native/d3d12/Forward.h" #include "dawn/native/d3d12/HeapD3D12.h" #include "dawn/native/d3d12/ResourceAllocatorManagerD3D12.h" -#include "dawn/native/d3d12/StagingBufferD3D12.h" #include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h" #include "dawn/native/d3d12/TextureCopySplitter.h" #include "dawn/native/d3d12/UtilsD3D12.h" @@ -1189,7 +1188,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, textureCopy.aspect = aspect; RecordBufferTextureCopyWithBufferHandle( BufferTextureCopyDirection::B2T, commandList, - ToBackend(uploadHandle.stagingBuffer)->GetResource(), + ToBackend(uploadHandle.stagingBuffer)->GetD3D12Resource(), uploadHandle.startOffset, bytesPerRow, largestMipSize.height, textureCopy, copySize); } diff --git a/src/dawn/native/metal/BufferMTL.h b/src/dawn/native/metal/BufferMTL.h index f36ebe8948..3c6333d3ee 100644 --- a/src/dawn/native/metal/BufferMTL.h +++ b/src/dawn/native/metal/BufferMTL.h @@ -52,7 +52,7 @@ class Buffer final : public BufferBase { MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override; void UnmapImpl() override; void DestroyImpl() override; - void* GetMappedPointerImpl() override; + void* GetMappedPointer() override; bool IsCPUWritableAtCreation() const override; MaybeError MapAtCreationImpl() override; diff --git a/src/dawn/native/metal/BufferMTL.mm b/src/dawn/native/metal/BufferMTL.mm index 92a808841f..7800969830 100644 --- a/src/dawn/native/metal/BufferMTL.mm +++ b/src/dawn/native/metal/BufferMTL.mm @@ -165,7 +165,7 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) return {}; } -void* Buffer::GetMappedPointerImpl() { +void* Buffer::GetMappedPointer() { return [*mMtlBuffer contents]; } diff --git a/src/dawn/native/metal/CommandBufferMTL.mm b/src/dawn/native/metal/CommandBufferMTL.mm index 5c37721b40..214ef2c03b 100644 --- a/src/dawn/native/metal/CommandBufferMTL.mm +++ b/src/dawn/native/metal/CommandBufferMTL.mm @@ -28,7 +28,6 @@ #include "dawn/native/metal/QuerySetMTL.h" #include "dawn/native/metal/RenderPipelineMTL.h" #include "dawn/native/metal/SamplerMTL.h" -#include "dawn/native/metal/StagingBufferMTL.h" #include "dawn/native/metal/TextureMTL.h" #include "dawn/native/metal/UtilsMetal.h" @@ -1144,7 +1143,7 @@ MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext) dstBuffer->EnsureDataInitializedAsDestination(commandContext, offset, size); [commandContext->EnsureBlit() - copyFromBuffer:ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle() + copyFromBuffer:ToBackend(uploadHandle.stagingBuffer)->GetMTLBuffer() sourceOffset:uploadHandle.startOffset toBuffer:dstBuffer->GetMTLBuffer() destinationOffset:offset diff --git a/src/dawn/native/metal/DeviceMTL.h b/src/dawn/native/metal/DeviceMTL.h index 529abb6713..2bfa3bb886 100644 --- a/src/dawn/native/metal/DeviceMTL.h +++ b/src/dawn/native/metal/DeviceMTL.h @@ -63,13 +63,12 @@ class Device final : public DeviceBase { std::vector waitEvents); void WaitForCommandsToBeScheduled(); - ResultOrError> CreateStagingBuffer(size_t size) override; - MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) override; - MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& dataLayout, TextureCopy* dst, const Extent3D& copySizePixels) override; diff --git a/src/dawn/native/metal/DeviceMTL.mm b/src/dawn/native/metal/DeviceMTL.mm index 10448d0233..7fd6f0c11d 100644 --- a/src/dawn/native/metal/DeviceMTL.mm +++ b/src/dawn/native/metal/DeviceMTL.mm @@ -31,7 +31,6 @@ #include "dawn/native/metal/RenderPipelineMTL.h" #include "dawn/native/metal/SamplerMTL.h" #include "dawn/native/metal/ShaderModuleMTL.h" -#include "dawn/native/metal/StagingBufferMTL.h" #include "dawn/native/metal/SwapChainMTL.h" #include "dawn/native/metal/TextureMTL.h" #include "dawn/native/metal/UtilsMetal.h" @@ -465,13 +464,7 @@ void Device::ExportLastSignaledEvent(ExternalImageMTLSharedEventDescriptor* desc desc->signaledValue = static_cast(GetLastSubmittedCommandSerial()); } -ResultOrError> Device::CreateStagingBuffer(size_t size) { - std::unique_ptr stagingBuffer = std::make_unique(size, this); - DAWN_TRY(stagingBuffer->Initialize()); - return std::move(stagingBuffer); -} - -MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, +MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -484,7 +477,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, ->EnsureDataInitializedAsDestination( GetPendingCommandContext(DeviceBase::SubmitMode::Passive), destinationOffset, size); - id uploadBuffer = ToBackend(source)->GetBufferHandle(); + id uploadBuffer = ToBackend(source)->GetMTLBuffer(); id buffer = ToBackend(destination)->GetMTLBuffer(); [GetPendingCommandContext(DeviceBase::SubmitMode::Passive)->EnsureBlit() copyFromBuffer:uploadBuffer @@ -498,7 +491,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, // In Metal we don't write from the CPU to the texture directly which can be done using the // replaceRegion function, because the function requires a non-private storage mode and Dawn // sets the private storage mode by default for all textures except IOSurfaces on macOS. -MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, +MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& dataLayout, TextureCopy* dst, const Extent3D& copySizePixels) { @@ -508,7 +501,7 @@ MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, texture, *dst, copySizePixels); RecordCopyBufferToTexture(GetPendingCommandContext(DeviceBase::SubmitMode::Passive), - ToBackend(source)->GetBufferHandle(), source->GetSize(), + ToBackend(source)->GetMTLBuffer(), source->GetSize(), dataLayout.offset, dataLayout.bytesPerRow, dataLayout.rowsPerImage, texture, dst->mipLevel, dst->origin, dst->aspect, copySizePixels); return {}; diff --git a/src/dawn/native/metal/Forward.h b/src/dawn/native/metal/Forward.h index 44f780414f..0f42900865 100644 --- a/src/dawn/native/metal/Forward.h +++ b/src/dawn/native/metal/Forward.h @@ -33,7 +33,6 @@ class Queue; class RenderPipeline; class Sampler; class ShaderModule; -class StagingBuffer; class SwapChain; class Texture; class TextureView; @@ -52,7 +51,6 @@ struct MetalBackendTraits { using RenderPipelineType = RenderPipeline; using SamplerType = Sampler; using ShaderModuleType = ShaderModule; - using StagingBufferType = StagingBuffer; using SwapChainType = SwapChain; using TextureType = Texture; using TextureViewType = TextureView; diff --git a/src/dawn/native/metal/StagingBufferMTL.h b/src/dawn/native/metal/StagingBufferMTL.h deleted file mode 100644 index bbad022d5a..0000000000 --- a/src/dawn/native/metal/StagingBufferMTL.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2018 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 SRC_DAWN_NATIVE_METAL_STAGINGBUFFERMTL_H_ -#define SRC_DAWN_NATIVE_METAL_STAGINGBUFFERMTL_H_ - -#include "dawn/native/StagingBuffer.h" - -#include "dawn/common/NSRef.h" - -#import - -namespace dawn::native::metal { - -class Device; - -class StagingBuffer : public StagingBufferBase { - public: - StagingBuffer(size_t size, Device* device); - ~StagingBuffer() override; - - id GetBufferHandle() const; - - MaybeError Initialize() override; - - private: - Device* mDevice; - NSPRef> mBuffer; -}; -} // namespace dawn::native::metal - -#endif // SRC_DAWN_NATIVE_METAL_STAGINGBUFFERMTL_H_ diff --git a/src/dawn/native/metal/StagingBufferMTL.mm b/src/dawn/native/metal/StagingBufferMTL.mm deleted file mode 100644 index f4255f1324..0000000000 --- a/src/dawn/native/metal/StagingBufferMTL.mm +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2018 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/metal/StagingBufferMTL.h" -#include "dawn/native/metal/DeviceMTL.h" - -namespace dawn::native::metal { - -StagingBuffer::StagingBuffer(size_t size, Device* device) - : StagingBufferBase(size), mDevice(device) {} - -StagingBuffer::~StagingBuffer() = default; - -MaybeError StagingBuffer::Initialize() { - const size_t bufferSize = GetSize(); - mBuffer = - AcquireNSPRef([mDevice->GetMTLDevice() newBufferWithLength:bufferSize - options:MTLResourceStorageModeShared]); - - if (mBuffer == nullptr) { - return DAWN_OUT_OF_MEMORY_ERROR("Unable to allocate buffer."); - } - - mMappedPointer = [*mBuffer contents]; - if (mMappedPointer == nullptr) { - return DAWN_INTERNAL_ERROR("Unable to map staging buffer."); - } - - return {}; -} - -id StagingBuffer::GetBufferHandle() const { - return mBuffer.Get(); -} - -} // namespace dawn::native::metal diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm index 4dc6a94d56..7e511d88fd 100644 --- a/src/dawn/native/metal/TextureMTL.mm +++ b/src/dawn/native/metal/TextureMTL.mm @@ -19,8 +19,8 @@ #include "dawn/common/Platform.h" #include "dawn/native/DynamicUploader.h" #include "dawn/native/EnumMaskIterator.h" +#include "dawn/native/metal/BufferMTL.h" #include "dawn/native/metal/DeviceMTL.h" -#include "dawn/native/metal/StagingBufferMTL.h" #include "dawn/native/metal/UtilsMetal.h" #include @@ -989,7 +989,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, blockInfo.byteSize)); memset(uploadHandle.mappedBuffer, clearColor, bufferSize); - id uploadBuffer = ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle(); + id uploadBuffer = ToBackend(uploadHandle.stagingBuffer)->GetMTLBuffer(); for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp index e5b84d8faa..0d191abd6b 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp @@ -104,7 +104,7 @@ struct CopyFromStagingToBufferOperation : PendingOperation { destination->CopyFromStaging(staging, sourceOffset, destinationOffset, size); } - StagingBufferBase* staging; + BufferBase* staging; Ref destination; uint64_t sourceOffset; uint64_t destinationOffset; @@ -193,12 +193,6 @@ ResultOrError> Device::CreateTextureViewImpl( return AcquireRef(new TextureView(texture, descriptor)); } -ResultOrError> Device::CreateStagingBuffer(size_t size) { - std::unique_ptr stagingBuffer = std::make_unique(size, this); - DAWN_TRY(stagingBuffer->Initialize()); - return std::move(stagingBuffer); -} - void Device::DestroyImpl() { ASSERT(GetState() == State::Disconnected); @@ -217,7 +211,7 @@ bool Device::HasPendingCommands() const { return false; } -MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, +MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -238,7 +232,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, return {}; } -MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, +MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) { @@ -325,7 +319,7 @@ MaybeError Buffer::MapAtCreationImpl() { return {}; } -void Buffer::CopyFromStaging(StagingBufferBase* staging, +void Buffer::CopyFromStaging(BufferBase* staging, uint64_t sourceOffset, uint64_t destinationOffset, uint64_t size) { @@ -343,7 +337,7 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) return {}; } -void* Buffer::GetMappedPointerImpl() { +void* Buffer::GetMappedPointer() { return mBackingData.get(); } @@ -526,24 +520,6 @@ wgpu::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const { return wgpu::TextureFormat::RGBA8Unorm; } -// StagingBuffer - -StagingBuffer::StagingBuffer(size_t size, Device* device) - : StagingBufferBase(size), mDevice(device) {} - -StagingBuffer::~StagingBuffer() { - if (mBuffer) { - mDevice->DecrementMemoryUsage(GetSize()); - } -} - -MaybeError StagingBuffer::Initialize() { - DAWN_TRY(mDevice->IncrementMemoryUsage(GetSize())); - mBuffer = std::make_unique(GetSize()); - mMappedPointer = mBuffer.get(); - return {}; -} - uint32_t Device::GetOptimalBytesPerRowAlignment() const { return 1; } diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h index 51274ab79c..6d5fb15548 100644 --- a/src/dawn/native/null/DeviceNull.h +++ b/src/dawn/native/null/DeviceNull.h @@ -33,7 +33,6 @@ #include "dawn/native/RingBufferAllocator.h" #include "dawn/native/Sampler.h" #include "dawn/native/ShaderModule.h" -#include "dawn/native/StagingBuffer.h" #include "dawn/native/SwapChain.h" #include "dawn/native/Texture.h" #include "dawn/native/ToBackend.h" @@ -105,13 +104,12 @@ class Device final : public DeviceBase { void AddPendingOperation(std::unique_ptr operation); MaybeError SubmitPendingOperations(); - ResultOrError> CreateStagingBuffer(size_t size) override; - MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) override; - MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) override; @@ -230,7 +228,7 @@ class Buffer final : public BufferBase { public: Buffer(Device* device, const BufferDescriptor* descriptor); - void CopyFromStaging(StagingBufferBase* staging, + void CopyFromStaging(BufferBase* staging, uint64_t sourceOffset, uint64_t destinationOffset, uint64_t size); @@ -243,7 +241,7 @@ class Buffer final : public BufferBase { void DestroyImpl() override; bool IsCPUWritableAtCreation() const override; MaybeError MapAtCreationImpl() override; - void* GetMappedPointerImpl() override; + void* GetMappedPointer() override; std::unique_ptr mBackingData; }; @@ -335,17 +333,6 @@ class NativeSwapChainImpl { wgpu::TextureFormat GetPreferredFormat() const; }; -class StagingBuffer : public StagingBufferBase { - public: - StagingBuffer(size_t size, Device* device); - ~StagingBuffer() override; - MaybeError Initialize() override; - - private: - Device* mDevice; - std::unique_ptr mBuffer; -}; - class Texture : public TextureBase { public: Texture(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state); diff --git a/src/dawn/native/opengl/BufferGL.cpp b/src/dawn/native/opengl/BufferGL.cpp index 5fce54f6dd..1b6046c66c 100644 --- a/src/dawn/native/opengl/BufferGL.cpp +++ b/src/dawn/native/opengl/BufferGL.cpp @@ -161,13 +161,13 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) mappedData = gl.MapBufferRange(GL_ARRAY_BUFFER, offset, size, GL_MAP_WRITE_BIT); } - // The frontend asks that the pointer returned by GetMappedPointerImpl is from the start of + // The frontend asks that the pointer returned by GetMappedPointer is from the start of // the resource but OpenGL gives us the pointer at offset. Remove the offset. mMappedData = static_cast(mappedData) - offset; return {}; } -void* Buffer::GetMappedPointerImpl() { +void* Buffer::GetMappedPointer() { // The mapping offset has already been removed. return mMappedData; } diff --git a/src/dawn/native/opengl/BufferGL.h b/src/dawn/native/opengl/BufferGL.h index a86c84157f..2e1cf22581 100644 --- a/src/dawn/native/opengl/BufferGL.h +++ b/src/dawn/native/opengl/BufferGL.h @@ -45,7 +45,7 @@ class Buffer final : public BufferBase { void DestroyImpl() override; bool IsCPUWritableAtCreation() const override; MaybeError MapAtCreationImpl() override; - void* GetMappedPointerImpl() override; + void* GetMappedPointer() override; void InitializeToZero(); diff --git a/src/dawn/native/opengl/DeviceGL.cpp b/src/dawn/native/opengl/DeviceGL.cpp index b663841076..fabfd84465 100644 --- a/src/dawn/native/opengl/DeviceGL.cpp +++ b/src/dawn/native/opengl/DeviceGL.cpp @@ -20,7 +20,6 @@ #include "dawn/native/BindGroupLayout.h" #include "dawn/native/ErrorData.h" #include "dawn/native/Instance.h" -#include "dawn/native/StagingBuffer.h" #include "dawn/native/opengl/BindGroupGL.h" #include "dawn/native/opengl/BindGroupLayoutGL.h" #include "dawn/native/opengl/BufferGL.h" @@ -414,11 +413,7 @@ ResultOrError Device::CheckAndUpdateCompletedSerials() { return fenceSerial; } -ResultOrError> Device::CreateStagingBuffer(size_t size) { - return DAWN_UNIMPLEMENTED_ERROR("Device unable to create staging buffer."); -} - -MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, +MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -426,7 +421,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, return DAWN_UNIMPLEMENTED_ERROR("Device unable to copy from staging buffer."); } -MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, +MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) { diff --git a/src/dawn/native/opengl/DeviceGL.h b/src/dawn/native/opengl/DeviceGL.h index 8c544f5d10..207ffe69c3 100644 --- a/src/dawn/native/opengl/DeviceGL.h +++ b/src/dawn/native/opengl/DeviceGL.h @@ -67,14 +67,13 @@ class Device final : public DeviceBase { MaybeError TickImpl() override; - ResultOrError> CreateStagingBuffer(size_t size) override; - MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) override; - MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) override; diff --git a/src/dawn/native/vulkan/BufferVk.cpp b/src/dawn/native/vulkan/BufferVk.cpp index 8e0811cc26..5029928708 100644 --- a/src/dawn/native/vulkan/BufferVk.cpp +++ b/src/dawn/native/vulkan/BufferVk.cpp @@ -325,7 +325,7 @@ void Buffer::UnmapImpl() { // No need to do anything, we keep CPU-visible memory mapped at all time. } -void* Buffer::GetMappedPointerImpl() { +void* Buffer::GetMappedPointer() { uint8_t* memory = mMemoryAllocation.GetMappedPointer(); ASSERT(memory != nullptr); return memory; diff --git a/src/dawn/native/vulkan/BufferVk.h b/src/dawn/native/vulkan/BufferVk.h index 8e955085da..6e8ef6405f 100644 --- a/src/dawn/native/vulkan/BufferVk.h +++ b/src/dawn/native/vulkan/BufferVk.h @@ -68,7 +68,7 @@ class Buffer final : public BufferBase { void DestroyImpl() override; bool IsCPUWritableAtCreation() const override; MaybeError MapAtCreationImpl() override; - void* GetMappedPointerImpl() override; + void* GetMappedPointer() override; VkBuffer mHandle = VK_NULL_HANDLE; ResourceMemoryAllocation mMemoryAllocation; diff --git a/src/dawn/native/vulkan/CommandBufferVk.cpp b/src/dawn/native/vulkan/CommandBufferVk.cpp index b67b0df035..ddd92059bc 100644 --- a/src/dawn/native/vulkan/CommandBufferVk.cpp +++ b/src/dawn/native/vulkan/CommandBufferVk.cpp @@ -35,7 +35,6 @@ #include "dawn/native/vulkan/QuerySetVk.h" #include "dawn/native/vulkan/RenderPassCache.h" #include "dawn/native/vulkan/RenderPipelineVk.h" -#include "dawn/native/vulkan/StagingBufferVk.h" #include "dawn/native/vulkan/TextureVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" @@ -870,7 +869,7 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* recordingConte copy.size = size; device->fn.CmdCopyBuffer(commands, - ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle(), + ToBackend(uploadHandle.stagingBuffer)->GetHandle(), dstBuffer->GetHandle(), 1, ©); break; } diff --git a/src/dawn/native/vulkan/DeviceVk.cpp b/src/dawn/native/vulkan/DeviceVk.cpp index c71ce86955..9bc942bd0a 100644 --- a/src/dawn/native/vulkan/DeviceVk.cpp +++ b/src/dawn/native/vulkan/DeviceVk.cpp @@ -40,7 +40,6 @@ #include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h" #include "dawn/native/vulkan/SamplerVk.h" #include "dawn/native/vulkan/ShaderModuleVk.h" -#include "dawn/native/vulkan/StagingBufferVk.h" #include "dawn/native/vulkan/SwapChainVk.h" #include "dawn/native/vulkan/TextureVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" @@ -823,13 +822,7 @@ void Device::RecycleCompletedCommands() { mCommandsInFlight.ClearUpTo(GetCompletedCommandSerial()); } -ResultOrError> Device::CreateStagingBuffer(size_t size) { - std::unique_ptr stagingBuffer = std::make_unique(size, this); - DAWN_TRY(stagingBuffer->Initialize()); - return std::move(stagingBuffer); -} - -MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, +MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, @@ -857,13 +850,13 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source, copy.dstOffset = destinationOffset; copy.size = size; - this->fn.CmdCopyBuffer(recordingContext->commandBuffer, ToBackend(source)->GetBufferHandle(), + this->fn.CmdCopyBuffer(recordingContext->commandBuffer, ToBackend(source)->GetHandle(), ToBackend(destination)->GetHandle(), 1, ©); return {}; } -MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, +MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) { @@ -893,9 +886,8 @@ MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source, // Dawn guarantees dstImage be in the TRANSFER_DST_OPTIMAL layout after the // copy command. - this->fn.CmdCopyBufferToImage(recordingContext->commandBuffer, - ToBackend(source)->GetBufferHandle(), dstImage, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + this->fn.CmdCopyBufferToImage(recordingContext->commandBuffer, ToBackend(source)->GetHandle(), + dstImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); return {}; } diff --git a/src/dawn/native/vulkan/DeviceVk.h b/src/dawn/native/vulkan/DeviceVk.h index 2b49a2ed4b..e6011a62ca 100644 --- a/src/dawn/native/vulkan/DeviceVk.h +++ b/src/dawn/native/vulkan/DeviceVk.h @@ -89,13 +89,12 @@ class Device final : public DeviceBase { MaybeError TickImpl() override; - ResultOrError> CreateStagingBuffer(size_t size) override; - MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source, + MaybeError CopyFromStagingToBufferImpl(BufferBase* source, uint64_t sourceOffset, BufferBase* destination, uint64_t destinationOffset, uint64_t size) override; - MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source, + MaybeError CopyFromStagingToTextureImpl(const BufferBase* source, const TextureDataLayout& src, TextureCopy* dst, const Extent3D& copySizePixels) override; diff --git a/src/dawn/native/vulkan/Forward.h b/src/dawn/native/vulkan/Forward.h index f541ebb3ab..41c2721f38 100644 --- a/src/dawn/native/vulkan/Forward.h +++ b/src/dawn/native/vulkan/Forward.h @@ -34,7 +34,6 @@ class RenderPipeline; class ResourceHeap; class Sampler; class ShaderModule; -class StagingBuffer; class SwapChain; class Texture; class TextureView; @@ -55,7 +54,6 @@ struct VulkanBackendTraits { using ResourceHeapType = ResourceHeap; using SamplerType = Sampler; using ShaderModuleType = ShaderModule; - using StagingBufferType = StagingBuffer; using SwapChainType = SwapChain; using TextureType = Texture; using TextureViewType = TextureView; diff --git a/src/dawn/native/vulkan/StagingBufferVk.cpp b/src/dawn/native/vulkan/StagingBufferVk.cpp deleted file mode 100644 index f5b35bd54d..0000000000 --- a/src/dawn/native/vulkan/StagingBufferVk.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2018 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/vulkan/StagingBufferVk.h" -#include "dawn/native/vulkan/DeviceVk.h" -#include "dawn/native/vulkan/FencedDeleter.h" -#include "dawn/native/vulkan/ResourceHeapVk.h" -#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h" -#include "dawn/native/vulkan/UtilsVulkan.h" -#include "dawn/native/vulkan/VulkanError.h" - -namespace dawn::native::vulkan { - -StagingBuffer::StagingBuffer(size_t size, Device* device) - : StagingBufferBase(size), mDevice(device) {} - -MaybeError StagingBuffer::Initialize() { - VkBufferCreateInfo createInfo; - createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - createInfo.pNext = nullptr; - createInfo.flags = 0; - createInfo.size = GetSize(); - createInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - createInfo.queueFamilyIndexCount = 0; - createInfo.pQueueFamilyIndices = 0; - - DAWN_TRY(CheckVkSuccess( - mDevice->fn.CreateBuffer(mDevice->GetVkDevice(), &createInfo, nullptr, &*mBuffer), - "vkCreateBuffer")); - - VkMemoryRequirements requirements; - mDevice->fn.GetBufferMemoryRequirements(mDevice->GetVkDevice(), mBuffer, &requirements); - - DAWN_TRY_ASSIGN(mAllocation, mDevice->GetResourceMemoryAllocator()->Allocate( - requirements, MemoryKind::LinearMappable)); - - DAWN_TRY(CheckVkSuccess( - mDevice->fn.BindBufferMemory(mDevice->GetVkDevice(), mBuffer, - ToBackend(mAllocation.GetResourceHeap())->GetMemory(), - mAllocation.GetOffset()), - "vkBindBufferMemory")); - - mMappedPointer = mAllocation.GetMappedPointer(); - if (mMappedPointer == nullptr) { - return DAWN_INTERNAL_ERROR("Unable to map staging buffer."); - } - - SetDebugName(mDevice, mBuffer, "Dawn_StagingBuffer"); - - return {}; -} - -StagingBuffer::~StagingBuffer() { - mMappedPointer = nullptr; - mDevice->GetFencedDeleter()->DeleteWhenUnused(mBuffer); - mDevice->GetResourceMemoryAllocator()->Deallocate(&mAllocation); -} - -VkBuffer StagingBuffer::GetBufferHandle() const { - return mBuffer; -} - -} // namespace dawn::native::vulkan diff --git a/src/dawn/native/vulkan/StagingBufferVk.h b/src/dawn/native/vulkan/StagingBufferVk.h deleted file mode 100644 index dbd48ed2aa..0000000000 --- a/src/dawn/native/vulkan/StagingBufferVk.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2018 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 SRC_DAWN_NATIVE_VULKAN_STAGINGBUFFERVK_H_ -#define SRC_DAWN_NATIVE_VULKAN_STAGINGBUFFERVK_H_ - -#include "dawn/common/vulkan_platform.h" -#include "dawn/native/ResourceMemoryAllocation.h" -#include "dawn/native/StagingBuffer.h" - -namespace dawn::native::vulkan { - -class Device; - -class StagingBuffer : public StagingBufferBase { - public: - StagingBuffer(size_t size, Device* device); - ~StagingBuffer() override; - - VkBuffer GetBufferHandle() const; - - MaybeError Initialize() override; - - private: - Device* mDevice; - VkBuffer mBuffer; - ResourceMemoryAllocation mAllocation; -}; -} // namespace dawn::native::vulkan - -#endif // SRC_DAWN_NATIVE_VULKAN_STAGINGBUFFERVK_H_ diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp index 89e036b32b..6bec0a979d 100644 --- a/src/dawn/native/vulkan/TextureVk.cpp +++ b/src/dawn/native/vulkan/TextureVk.cpp @@ -29,7 +29,6 @@ #include "dawn/native/vulkan/FencedDeleter.h" #include "dawn/native/vulkan/ResourceHeapVk.h" #include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h" -#include "dawn/native/vulkan/StagingBufferVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" @@ -1255,10 +1254,9 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* recordingContext, regions.push_back(ComputeBufferImageCopyRegion(dataLayout, textureCopy, copySize)); } } - device->fn.CmdCopyBufferToImage(recordingContext->commandBuffer, - ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle(), - GetHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - regions.size(), regions.data()); + device->fn.CmdCopyBufferToImage( + recordingContext->commandBuffer, ToBackend(uploadHandle.stagingBuffer)->GetHandle(), + GetHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, regions.size(), regions.data()); } else { for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount; ++level) { diff --git a/src/dawn/tests/unittests/native/mocks/BufferMock.h b/src/dawn/tests/unittests/native/mocks/BufferMock.h index 5bb67a575d..d98f31daf9 100644 --- a/src/dawn/tests/unittests/native/mocks/BufferMock.h +++ b/src/dawn/tests/unittests/native/mocks/BufferMock.h @@ -35,7 +35,7 @@ class BufferMock : public BufferBase { (wgpu::MapMode mode, size_t offset, size_t size), (override)); MOCK_METHOD(void, UnmapImpl, (), (override)); - MOCK_METHOD(void*, GetMappedPointerImpl, (), (override)); + MOCK_METHOD(void*, GetMappedPointer, (), (override)); MOCK_METHOD(bool, IsCPUWritableAtCreation, (), (const, override)); }; diff --git a/src/dawn/tests/unittests/native/mocks/DeviceMock.h b/src/dawn/tests/unittests/native/mocks/DeviceMock.h index d3a3a84d51..92c4883c7c 100644 --- a/src/dawn/tests/unittests/native/mocks/DeviceMock.h +++ b/src/dawn/tests/unittests/native/mocks/DeviceMock.h @@ -34,17 +34,13 @@ class DeviceMock : public DeviceBase { (CommandEncoder*, const CommandBufferDescriptor*), (override)); - MOCK_METHOD(ResultOrError>, - CreateStagingBuffer, - (size_t), - (override)); MOCK_METHOD(MaybeError, CopyFromStagingToBufferImpl, - (StagingBufferBase*, uint64_t, BufferBase*, uint64_t, uint64_t), + (BufferBase*, uint64_t, BufferBase*, uint64_t, uint64_t), (override)); MOCK_METHOD(MaybeError, CopyFromStagingToTextureImpl, - (const StagingBufferBase*, const TextureDataLayout&, TextureCopy*, const Extent3D&), + (const BufferBase*, const TextureDataLayout&, TextureCopy*, const Extent3D&), (override)); MOCK_METHOD(uint32_t, GetOptimalBytesPerRowAlignment, (), (const, override));