Delete StagingBuffer in favor of mappable buffers
This CL removes StagingBuffer to start to unify implementation code paths for WriteTexture/Buffer and CopyBufferToTexture/Buffer. This will help implementing a buffer-to-stencil copy workaround. Bug: dawn:1389 Change-Id: Ieb23b8d871f14544ef01445a495dc1077274c9f2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117167 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
44e9db3866
commit
03b69ff573
|
@ -319,8 +319,6 @@ source_set("sources") {
|
||||||
"Serializable.h",
|
"Serializable.h",
|
||||||
"ShaderModule.cpp",
|
"ShaderModule.cpp",
|
||||||
"ShaderModule.h",
|
"ShaderModule.h",
|
||||||
"StagingBuffer.cpp",
|
|
||||||
"StagingBuffer.h",
|
|
||||||
"StreamImplTint.cpp",
|
"StreamImplTint.cpp",
|
||||||
"Subresource.cpp",
|
"Subresource.cpp",
|
||||||
"Subresource.h",
|
"Subresource.h",
|
||||||
|
@ -460,8 +458,6 @@ source_set("sources") {
|
||||||
"d3d12/ShaderModuleD3D12.h",
|
"d3d12/ShaderModuleD3D12.h",
|
||||||
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp",
|
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp",
|
||||||
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.h",
|
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.h",
|
||||||
"d3d12/StagingBufferD3D12.cpp",
|
|
||||||
"d3d12/StagingBufferD3D12.h",
|
|
||||||
"d3d12/StagingDescriptorAllocatorD3D12.cpp",
|
"d3d12/StagingDescriptorAllocatorD3D12.cpp",
|
||||||
"d3d12/StagingDescriptorAllocatorD3D12.h",
|
"d3d12/StagingDescriptorAllocatorD3D12.h",
|
||||||
"d3d12/StreamImplD3D12.cpp",
|
"d3d12/StreamImplD3D12.cpp",
|
||||||
|
@ -515,8 +511,6 @@ source_set("sources") {
|
||||||
"metal/SamplerMTL.mm",
|
"metal/SamplerMTL.mm",
|
||||||
"metal/ShaderModuleMTL.h",
|
"metal/ShaderModuleMTL.h",
|
||||||
"metal/ShaderModuleMTL.mm",
|
"metal/ShaderModuleMTL.mm",
|
||||||
"metal/StagingBufferMTL.h",
|
|
||||||
"metal/StagingBufferMTL.mm",
|
|
||||||
"metal/SwapChainMTL.h",
|
"metal/SwapChainMTL.h",
|
||||||
"metal/SwapChainMTL.mm",
|
"metal/SwapChainMTL.mm",
|
||||||
"metal/TextureMTL.h",
|
"metal/TextureMTL.h",
|
||||||
|
@ -656,8 +650,6 @@ source_set("sources") {
|
||||||
"vulkan/SamplerVk.h",
|
"vulkan/SamplerVk.h",
|
||||||
"vulkan/ShaderModuleVk.cpp",
|
"vulkan/ShaderModuleVk.cpp",
|
||||||
"vulkan/ShaderModuleVk.h",
|
"vulkan/ShaderModuleVk.h",
|
||||||
"vulkan/StagingBufferVk.cpp",
|
|
||||||
"vulkan/StagingBufferVk.h",
|
|
||||||
"vulkan/StreamImplVk.cpp",
|
"vulkan/StreamImplVk.cpp",
|
||||||
"vulkan/SwapChainVk.cpp",
|
"vulkan/SwapChainVk.cpp",
|
||||||
"vulkan/SwapChainVk.h",
|
"vulkan/SwapChainVk.h",
|
||||||
|
|
|
@ -88,7 +88,7 @@ class ErrorBuffer final : public BufferBase {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* GetMappedPointerImpl() override { return mFakeMappedData.get(); }
|
void* GetMappedPointer() override { return mFakeMappedData.get(); }
|
||||||
|
|
||||||
void UnmapImpl() override { mFakeMappedData.reset(); }
|
void UnmapImpl() override { mFakeMappedData.reset(); }
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void BufferBase::DestroyImpl() {
|
||||||
toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
|
toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
|
||||||
} else if (mState == BufferState::MappedAtCreation) {
|
} else if (mState == BufferState::MappedAtCreation) {
|
||||||
if (mStagingBuffer != nullptr) {
|
if (mStagingBuffer != nullptr) {
|
||||||
mStagingBuffer.reset();
|
mStagingBuffer = nullptr;
|
||||||
} else if (mSize != 0) {
|
} else if (mSize != 0) {
|
||||||
toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
|
toCall = UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ MaybeError BufferBase::MapAtCreation() {
|
||||||
size_t size;
|
size_t size;
|
||||||
if (mSize == 0) {
|
if (mSize == 0) {
|
||||||
return {};
|
return {};
|
||||||
} else if (mStagingBuffer) {
|
} else if (mStagingBuffer != nullptr) {
|
||||||
// If there is a staging buffer for initialization, clear its contents directly.
|
// If there is a staging buffer for initialization, clear its contents directly.
|
||||||
// It should be exactly as large as the buffer allocation.
|
// It should be exactly as large as the buffer allocation.
|
||||||
ptr = mStagingBuffer->GetMappedPointer();
|
ptr = mStagingBuffer->GetMappedPointer();
|
||||||
|
@ -311,7 +311,7 @@ MaybeError BufferBase::MapAtCreation() {
|
||||||
ASSERT(size == GetAllocatedSize());
|
ASSERT(size == GetAllocatedSize());
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, the buffer is directly mappable on the CPU.
|
// Otherwise, the buffer is directly mappable on the CPU.
|
||||||
ptr = GetMappedPointerImpl();
|
ptr = GetMappedPointer();
|
||||||
size = GetAllocatedSize();
|
size = GetAllocatedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +346,14 @@ MaybeError BufferBase::MapAtCreationInternal() {
|
||||||
// is initialized.
|
// is initialized.
|
||||||
// TODO(crbug.com/dawn/828): Suballocate and reuse memory from a larger staging
|
// TODO(crbug.com/dawn/828): Suballocate and reuse memory from a larger staging
|
||||||
// buffer so we don't create many small buffers.
|
// 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) {
|
if (mSize == 0) {
|
||||||
return reinterpret_cast<uint8_t*>(intptr_t(0xCAFED00D));
|
return reinterpret_cast<uint8_t*>(intptr_t(0xCAFED00D));
|
||||||
}
|
}
|
||||||
uint8_t* start = static_cast<uint8_t*>(GetMappedPointerImpl());
|
uint8_t* start = static_cast<uint8_t*>(GetMappedPointer());
|
||||||
return start == nullptr ? nullptr : start + offset;
|
return start == nullptr ? nullptr : start + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +491,7 @@ uint64_t BufferBase::APIGetSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError BufferBase::CopyFromStagingBuffer() {
|
MaybeError BufferBase::CopyFromStagingBuffer() {
|
||||||
ASSERT(mStagingBuffer);
|
ASSERT(mStagingBuffer != nullptr);
|
||||||
if (mSize == 0) {
|
if (mSize == 0) {
|
||||||
// Staging buffer is not created if zero size.
|
// Staging buffer is not created if zero size.
|
||||||
ASSERT(mStagingBuffer == nullptr);
|
ASSERT(mStagingBuffer == nullptr);
|
||||||
|
@ -492,7 +499,7 @@ MaybeError BufferBase::CopyFromStagingBuffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DAWN_TRY(
|
DAWN_TRY(
|
||||||
GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.get(), 0, this, 0, GetAllocatedSize()));
|
GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.Get(), 0, this, 0, GetAllocatedSize()));
|
||||||
|
|
||||||
DynamicUploader* uploader = GetDevice()->GetDynamicUploader();
|
DynamicUploader* uploader = GetDevice()->GetDynamicUploader();
|
||||||
uploader->ReleaseStagingBuffer(std::move(mStagingBuffer));
|
uploader->ReleaseStagingBuffer(std::move(mStagingBuffer));
|
||||||
|
|
|
@ -74,6 +74,7 @@ class BufferBase : public ApiObjectBase {
|
||||||
bool IsDataInitialized() const;
|
bool IsDataInitialized() const;
|
||||||
void SetIsDataInitialized();
|
void SetIsDataInitialized();
|
||||||
|
|
||||||
|
virtual void* GetMappedPointer() = 0;
|
||||||
void* GetMappedRange(size_t offset, size_t size, bool writable = true);
|
void* GetMappedRange(size_t offset, size_t size, bool writable = true);
|
||||||
void Unmap();
|
void Unmap();
|
||||||
|
|
||||||
|
@ -128,7 +129,6 @@ class BufferBase : public ApiObjectBase {
|
||||||
virtual MaybeError MapAtCreationImpl() = 0;
|
virtual MaybeError MapAtCreationImpl() = 0;
|
||||||
virtual MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) = 0;
|
virtual MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) = 0;
|
||||||
virtual void UnmapImpl() = 0;
|
virtual void UnmapImpl() = 0;
|
||||||
virtual void* GetMappedPointerImpl() = 0;
|
|
||||||
|
|
||||||
virtual bool IsCPUWritableAtCreation() const = 0;
|
virtual bool IsCPUWritableAtCreation() const = 0;
|
||||||
MaybeError CopyFromStagingBuffer();
|
MaybeError CopyFromStagingBuffer();
|
||||||
|
@ -146,7 +146,13 @@ class BufferBase : public ApiObjectBase {
|
||||||
BufferState mState;
|
BufferState mState;
|
||||||
bool mIsDataInitialized = false;
|
bool mIsDataInitialized = false;
|
||||||
|
|
||||||
std::unique_ptr<StagingBufferBase> 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<BufferBase> mStagingBuffer;
|
||||||
|
|
||||||
WGPUBufferMapCallback mMapCallback = nullptr;
|
WGPUBufferMapCallback mMapCallback = nullptr;
|
||||||
void* mMapUserdata = nullptr;
|
void* mMapUserdata = nullptr;
|
||||||
|
|
|
@ -173,8 +173,6 @@ target_sources(dawn_native PRIVATE
|
||||||
"Serializable.h"
|
"Serializable.h"
|
||||||
"ShaderModule.cpp"
|
"ShaderModule.cpp"
|
||||||
"ShaderModule.h"
|
"ShaderModule.h"
|
||||||
"StagingBuffer.cpp"
|
|
||||||
"StagingBuffer.h"
|
|
||||||
"StreamImplTint.cpp"
|
"StreamImplTint.cpp"
|
||||||
"Subresource.cpp"
|
"Subresource.cpp"
|
||||||
"Subresource.h"
|
"Subresource.h"
|
||||||
|
@ -324,8 +322,6 @@ if (DAWN_ENABLE_D3D12)
|
||||||
"d3d12/ShaderModuleD3D12.h"
|
"d3d12/ShaderModuleD3D12.h"
|
||||||
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp"
|
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp"
|
||||||
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
"d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
||||||
"d3d12/StagingBufferD3D12.cpp"
|
|
||||||
"d3d12/StagingBufferD3D12.h"
|
|
||||||
"d3d12/StagingDescriptorAllocatorD3D12.cpp"
|
"d3d12/StagingDescriptorAllocatorD3D12.cpp"
|
||||||
"d3d12/StagingDescriptorAllocatorD3D12.h"
|
"d3d12/StagingDescriptorAllocatorD3D12.h"
|
||||||
"d3d12/StreamImplD3D12.cpp"
|
"d3d12/StreamImplD3D12.cpp"
|
||||||
|
@ -375,8 +371,6 @@ if (DAWN_ENABLE_METAL)
|
||||||
"metal/SamplerMTL.mm"
|
"metal/SamplerMTL.mm"
|
||||||
"metal/ShaderModuleMTL.h"
|
"metal/ShaderModuleMTL.h"
|
||||||
"metal/ShaderModuleMTL.mm"
|
"metal/ShaderModuleMTL.mm"
|
||||||
"metal/StagingBufferMTL.h"
|
|
||||||
"metal/StagingBufferMTL.mm"
|
|
||||||
"metal/SwapChainMTL.h"
|
"metal/SwapChainMTL.h"
|
||||||
"metal/SwapChainMTL.mm"
|
"metal/SwapChainMTL.mm"
|
||||||
"metal/TextureMTL.h"
|
"metal/TextureMTL.h"
|
||||||
|
@ -535,8 +529,6 @@ if (DAWN_ENABLE_VULKAN)
|
||||||
"vulkan/SamplerVk.h"
|
"vulkan/SamplerVk.h"
|
||||||
"vulkan/ShaderModuleVk.cpp"
|
"vulkan/ShaderModuleVk.cpp"
|
||||||
"vulkan/ShaderModuleVk.h"
|
"vulkan/ShaderModuleVk.h"
|
||||||
"vulkan/StagingBufferVk.cpp"
|
|
||||||
"vulkan/StagingBufferVk.h"
|
|
||||||
"vulkan/StreamImplVk.cpp"
|
"vulkan/StreamImplVk.cpp"
|
||||||
"vulkan/SwapChainVk.cpp"
|
"vulkan/SwapChainVk.cpp"
|
||||||
"vulkan/SwapChainVk.h"
|
"vulkan/SwapChainVk.h"
|
||||||
|
|
|
@ -1924,7 +1924,7 @@ ExecutionSerial DeviceBase::GetScheduledWorkDoneSerial() const {
|
||||||
return HasPendingCommands() ? GetPendingCommandSerial() : GetLastSubmittedCommandSerial();
|
return HasPendingCommands() ? GetPendingCommandSerial() : GetLastSubmittedCommandSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CopyFromStagingToBuffer(StagingBufferBase* source,
|
MaybeError DeviceBase::CopyFromStagingToBuffer(BufferBase* source,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -1937,7 +1937,7 @@ MaybeError DeviceBase::CopyFromStagingToBuffer(StagingBufferBase* source,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CopyFromStagingToTexture(const StagingBufferBase* source,
|
MaybeError DeviceBase::CopyFromStagingToTexture(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
const Extent3D& copySizePixels) {
|
||||||
|
@ -1948,4 +1948,11 @@ MaybeError DeviceBase::CopyFromStagingToTexture(const StagingBufferBase* source,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IgnoreLazyClearCountScope::IgnoreLazyClearCountScope(DeviceBase* device)
|
||||||
|
: mDevice(device), mLazyClearCountForTesting(device->mLazyClearCountForTesting) {}
|
||||||
|
|
||||||
|
IgnoreLazyClearCountScope::~IgnoreLazyClearCountScope() {
|
||||||
|
mDevice->mLazyClearCountForTesting = mLazyClearCountForTesting;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn::native
|
} // namespace dawn::native
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "dawn/native/ObjectBase.h"
|
#include "dawn/native/ObjectBase.h"
|
||||||
#include "dawn/native/ObjectType_autogen.h"
|
#include "dawn/native/ObjectType_autogen.h"
|
||||||
#include "dawn/native/RefCountedWithExternalCount.h"
|
#include "dawn/native/RefCountedWithExternalCount.h"
|
||||||
#include "dawn/native/StagingBuffer.h"
|
|
||||||
#include "dawn/native/Toggles.h"
|
#include "dawn/native/Toggles.h"
|
||||||
#include "dawn/native/UsageValidationMode.h"
|
#include "dawn/native/UsageValidationMode.h"
|
||||||
|
|
||||||
|
@ -298,13 +297,12 @@ class DeviceBase : public RefCountedWithExternalCount {
|
||||||
Blob LoadCachedBlob(const CacheKey& key);
|
Blob LoadCachedBlob(const CacheKey& key);
|
||||||
void StoreCachedBlob(const CacheKey& key, const Blob& blob);
|
void StoreCachedBlob(const CacheKey& key, const Blob& blob);
|
||||||
|
|
||||||
virtual ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) = 0;
|
MaybeError CopyFromStagingToBuffer(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBuffer(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size);
|
uint64_t size);
|
||||||
MaybeError CopyFromStagingToTexture(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTexture(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels);
|
const Extent3D& copySizePixels);
|
||||||
|
@ -349,6 +347,8 @@ class DeviceBase : public RefCountedWithExternalCount {
|
||||||
void APIForceLoss(wgpu::DeviceLostReason reason, const char* message);
|
void APIForceLoss(wgpu::DeviceLostReason reason, const char* message);
|
||||||
QueueBase* GetQueue() const;
|
QueueBase* GetQueue() const;
|
||||||
|
|
||||||
|
friend class IgnoreLazyClearCountScope;
|
||||||
|
|
||||||
// Check for passed fences and set the new completed serial
|
// Check for passed fences and set the new completed serial
|
||||||
MaybeError CheckPassedSerials();
|
MaybeError CheckPassedSerials();
|
||||||
|
|
||||||
|
@ -525,12 +525,12 @@ class DeviceBase : public RefCountedWithExternalCount {
|
||||||
// Indicates whether the backend has pending commands to be submitted as soon as possible.
|
// Indicates whether the backend has pending commands to be submitted as soon as possible.
|
||||||
virtual bool HasPendingCommands() const = 0;
|
virtual bool HasPendingCommands() const = 0;
|
||||||
|
|
||||||
virtual MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
virtual MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) = 0;
|
uint64_t size) = 0;
|
||||||
virtual MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
virtual MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) = 0;
|
const Extent3D& copySizePixels) = 0;
|
||||||
|
@ -587,6 +587,19 @@ class DeviceBase : public RefCountedWithExternalCount {
|
||||||
CacheKey mDeviceCacheKey;
|
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
|
} // namespace dawn::native
|
||||||
|
|
||||||
#endif // SRC_DAWN_NATIVE_DEVICE_H_
|
#endif // SRC_DAWN_NATIVE_DEVICE_H_
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "dawn/common/Math.h"
|
#include "dawn/common/Math.h"
|
||||||
|
#include "dawn/native/Buffer.h"
|
||||||
#include "dawn/native/Device.h"
|
#include "dawn/native/Device.h"
|
||||||
|
|
||||||
namespace dawn::native {
|
namespace dawn::native {
|
||||||
|
@ -26,7 +27,7 @@ DynamicUploader::DynamicUploader(DeviceBase* device) : mDevice(device) {
|
||||||
std::unique_ptr<RingBuffer>(new RingBuffer{nullptr, RingBufferAllocator(kRingBufferSize)}));
|
std::unique_ptr<RingBuffer>(new RingBuffer{nullptr, RingBufferAllocator(kRingBufferSize)}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicUploader::ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer) {
|
void DynamicUploader::ReleaseStagingBuffer(Ref<BufferBase> stagingBuffer) {
|
||||||
mReleasedStagingBuffers.Enqueue(std::move(stagingBuffer), mDevice->GetPendingCommandSerial());
|
mReleasedStagingBuffers.Enqueue(std::move(stagingBuffer), mDevice->GetPendingCommandSerial());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +35,19 @@ ResultOrError<UploadHandle> DynamicUploader::AllocateInternal(uint64_t allocatio
|
||||||
ExecutionSerial serial) {
|
ExecutionSerial serial) {
|
||||||
// Disable further sub-allocation should the request be too large.
|
// Disable further sub-allocation should the request be too large.
|
||||||
if (allocationSize > kRingBufferSize) {
|
if (allocationSize > kRingBufferSize) {
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer;
|
BufferDescriptor bufferDesc = {};
|
||||||
DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateStagingBuffer(allocationSize));
|
bufferDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
|
||||||
|
bufferDesc.size = Align(allocationSize, 4);
|
||||||
|
bufferDesc.mappedAtCreation = true;
|
||||||
|
bufferDesc.label = "Dawn_DynamicUploaderStaging";
|
||||||
|
|
||||||
|
IgnoreLazyClearCountScope scope(mDevice);
|
||||||
|
Ref<BufferBase> stagingBuffer;
|
||||||
|
DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateBuffer(&bufferDesc));
|
||||||
|
|
||||||
UploadHandle uploadHandle;
|
UploadHandle uploadHandle;
|
||||||
uploadHandle.mappedBuffer = static_cast<uint8_t*>(stagingBuffer->GetMappedPointer());
|
uploadHandle.mappedBuffer = static_cast<uint8_t*>(stagingBuffer->GetMappedPointer());
|
||||||
uploadHandle.stagingBuffer = stagingBuffer.get();
|
uploadHandle.stagingBuffer = stagingBuffer.Get();
|
||||||
|
|
||||||
ReleaseStagingBuffer(std::move(stagingBuffer));
|
ReleaseStagingBuffer(std::move(stagingBuffer));
|
||||||
return uploadHandle;
|
return uploadHandle;
|
||||||
|
@ -80,16 +88,22 @@ ResultOrError<UploadHandle> DynamicUploader::AllocateInternal(uint64_t allocatio
|
||||||
// Allocate the staging buffer backing the ringbuffer.
|
// Allocate the staging buffer backing the ringbuffer.
|
||||||
// Note: the first ringbuffer will be lazily created.
|
// Note: the first ringbuffer will be lazily created.
|
||||||
if (targetRingBuffer->mStagingBuffer == nullptr) {
|
if (targetRingBuffer->mStagingBuffer == nullptr) {
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer;
|
BufferDescriptor bufferDesc = {};
|
||||||
DAWN_TRY_ASSIGN(stagingBuffer,
|
bufferDesc.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
|
||||||
mDevice->CreateStagingBuffer(targetRingBuffer->mAllocator.GetSize()));
|
bufferDesc.size = Align(targetRingBuffer->mAllocator.GetSize(), 4);
|
||||||
|
bufferDesc.mappedAtCreation = true;
|
||||||
|
bufferDesc.label = "Dawn_DynamicUploaderStaging";
|
||||||
|
|
||||||
|
IgnoreLazyClearCountScope scope(mDevice);
|
||||||
|
Ref<BufferBase> stagingBuffer;
|
||||||
|
DAWN_TRY_ASSIGN(stagingBuffer, mDevice->CreateBuffer(&bufferDesc));
|
||||||
targetRingBuffer->mStagingBuffer = std::move(stagingBuffer);
|
targetRingBuffer->mStagingBuffer = std::move(stagingBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(targetRingBuffer->mStagingBuffer != nullptr);
|
ASSERT(targetRingBuffer->mStagingBuffer != nullptr);
|
||||||
|
|
||||||
UploadHandle uploadHandle;
|
UploadHandle uploadHandle;
|
||||||
uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer.get();
|
uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer.Get();
|
||||||
uploadHandle.mappedBuffer =
|
uploadHandle.mappedBuffer =
|
||||||
static_cast<uint8_t*>(uploadHandle.stagingBuffer->GetMappedPointer()) + startOffset;
|
static_cast<uint8_t*>(uploadHandle.stagingBuffer->GetMappedPointer()) + startOffset;
|
||||||
uploadHandle.startOffset = startOffset;
|
uploadHandle.startOffset = startOffset;
|
||||||
|
|
|
@ -18,19 +18,22 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "dawn/common/RefCounted.h"
|
||||||
|
#include "dawn/native/Error.h"
|
||||||
#include "dawn/native/Forward.h"
|
#include "dawn/native/Forward.h"
|
||||||
#include "dawn/native/IntegerTypes.h"
|
#include "dawn/native/IntegerTypes.h"
|
||||||
#include "dawn/native/RingBufferAllocator.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
|
// DynamicUploader is the front-end implementation used to manage multiple ring buffers for upload
|
||||||
// usage.
|
// usage.
|
||||||
namespace dawn::native {
|
namespace dawn::native {
|
||||||
|
|
||||||
|
class BufferBase;
|
||||||
|
|
||||||
struct UploadHandle {
|
struct UploadHandle {
|
||||||
uint8_t* mappedBuffer = nullptr;
|
uint8_t* mappedBuffer = nullptr;
|
||||||
uint64_t startOffset = 0;
|
uint64_t startOffset = 0;
|
||||||
StagingBufferBase* stagingBuffer = nullptr;
|
BufferBase* stagingBuffer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DynamicUploader {
|
class DynamicUploader {
|
||||||
|
@ -42,7 +45,7 @@ class DynamicUploader {
|
||||||
// currently no place to track the allocated staging buffers such that they're freed after
|
// 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
|
// pending commands are finished. This should be changed when better resource allocation is
|
||||||
// implemented.
|
// implemented.
|
||||||
void ReleaseStagingBuffer(std::unique_ptr<StagingBufferBase> stagingBuffer);
|
void ReleaseStagingBuffer(Ref<BufferBase> stagingBuffer);
|
||||||
|
|
||||||
ResultOrError<UploadHandle> Allocate(uint64_t allocationSize,
|
ResultOrError<UploadHandle> Allocate(uint64_t allocationSize,
|
||||||
ExecutionSerial serial,
|
ExecutionSerial serial,
|
||||||
|
@ -56,14 +59,14 @@ class DynamicUploader {
|
||||||
uint64_t GetTotalAllocatedSize();
|
uint64_t GetTotalAllocatedSize();
|
||||||
|
|
||||||
struct RingBuffer {
|
struct RingBuffer {
|
||||||
std::unique_ptr<StagingBufferBase> mStagingBuffer;
|
Ref<BufferBase> mStagingBuffer;
|
||||||
RingBufferAllocator mAllocator;
|
RingBufferAllocator mAllocator;
|
||||||
};
|
};
|
||||||
|
|
||||||
ResultOrError<UploadHandle> AllocateInternal(uint64_t allocationSize, ExecutionSerial serial);
|
ResultOrError<UploadHandle> AllocateInternal(uint64_t allocationSize, ExecutionSerial serial);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<RingBuffer>> mRingBuffers;
|
std::vector<std::unique_ptr<RingBuffer>> mRingBuffers;
|
||||||
SerialQueue<ExecutionSerial, std::unique_ptr<StagingBufferBase>> mReleasedStagingBuffers;
|
SerialQueue<ExecutionSerial, Ref<BufferBase>> mReleasedStagingBuffers;
|
||||||
DeviceBase* mDevice;
|
DeviceBase* mDevice;
|
||||||
};
|
};
|
||||||
} // namespace dawn::native
|
} // namespace dawn::native
|
||||||
|
|
|
@ -47,7 +47,6 @@ class ResourceHeapBase;
|
||||||
class SamplerBase;
|
class SamplerBase;
|
||||||
class Surface;
|
class Surface;
|
||||||
class ShaderModuleBase;
|
class ShaderModuleBase;
|
||||||
class StagingBufferBase;
|
|
||||||
class SwapChainBase;
|
class SwapChainBase;
|
||||||
class NewSwapChainBase;
|
class NewSwapChainBase;
|
||||||
class TextureBase;
|
class TextureBase;
|
||||||
|
|
|
@ -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
|
|
|
@ -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_
|
|
|
@ -98,11 +98,6 @@ struct ToBackendTraits<ShaderModuleBase, BackendTraits> {
|
||||||
using BackendType = typename BackendTraits::ShaderModuleType;
|
using BackendType = typename BackendTraits::ShaderModuleType;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename BackendTraits>
|
|
||||||
struct ToBackendTraits<StagingBufferBase, BackendTraits> {
|
|
||||||
using BackendType = typename BackendTraits::StagingBufferType;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename BackendTraits>
|
template <typename BackendTraits>
|
||||||
struct ToBackendTraits<TextureBase, BackendTraits> {
|
struct ToBackendTraits<TextureBase, BackendTraits> {
|
||||||
using BackendType = typename BackendTraits::TextureType;
|
using BackendType = typename BackendTraits::TextureType;
|
||||||
|
|
|
@ -377,7 +377,7 @@ void Buffer::UnmapImpl() {
|
||||||
ToBackend(GetDevice())->GetResidencyManager()->UnlockAllocation(heap);
|
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
|
// 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.
|
// irrespective of the offset passed in MapAsyncImpl, which is what mMappedData is.
|
||||||
return mMappedData;
|
return mMappedData;
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Buffer final : public BufferBase {
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
void* GetMappedPointerImpl() override;
|
void* GetMappedPointer() override;
|
||||||
|
|
||||||
MaybeError MapInternal(bool isWrite, size_t start, size_t end, const char* contextInfo);
|
MaybeError MapInternal(bool isWrite, size_t start, size_t end, const char* contextInfo);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "dawn/native/d3d12/RenderPassBuilderD3D12.h"
|
#include "dawn/native/d3d12/RenderPassBuilderD3D12.h"
|
||||||
#include "dawn/native/d3d12/RenderPipelineD3D12.h"
|
#include "dawn/native/d3d12/RenderPipelineD3D12.h"
|
||||||
#include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
#include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
||||||
#include "dawn/native/d3d12/StagingBufferD3D12.h"
|
|
||||||
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
||||||
#include "dawn/native/d3d12/UtilsD3D12.h"
|
#include "dawn/native/d3d12/UtilsD3D12.h"
|
||||||
|
|
||||||
|
@ -1103,9 +1102,10 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* commandContext
|
||||||
commandContext, offset, size));
|
commandContext, offset, size));
|
||||||
DAWN_UNUSED(cleared);
|
DAWN_UNUSED(cleared);
|
||||||
dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
||||||
commandList->CopyBufferRegion(dstBuffer->GetD3D12Resource(), offset,
|
commandList->CopyBufferRegion(
|
||||||
ToBackend(uploadHandle.stagingBuffer)->GetResource(),
|
dstBuffer->GetD3D12Resource(), offset,
|
||||||
uploadHandle.startOffset, size);
|
ToBackend(uploadHandle.stagingBuffer)->GetD3D12Resource(),
|
||||||
|
uploadHandle.startOffset, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "dawn/native/d3d12/SamplerHeapCacheD3D12.h"
|
#include "dawn/native/d3d12/SamplerHeapCacheD3D12.h"
|
||||||
#include "dawn/native/d3d12/ShaderModuleD3D12.h"
|
#include "dawn/native/d3d12/ShaderModuleD3D12.h"
|
||||||
#include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
#include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
|
||||||
#include "dawn/native/d3d12/StagingBufferD3D12.h"
|
|
||||||
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
||||||
#include "dawn/native/d3d12/SwapChainD3D12.h"
|
#include "dawn/native/d3d12/SwapChainD3D12.h"
|
||||||
#include "dawn/native/d3d12/UtilsD3D12.h"
|
#include "dawn/native/d3d12/UtilsD3D12.h"
|
||||||
|
@ -486,13 +485,7 @@ void Device::InitializeRenderPipelineAsyncImpl(Ref<RenderPipelineBase> renderPip
|
||||||
RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata);
|
RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer = std::make_unique<StagingBuffer>(size, this);
|
|
||||||
DAWN_TRY(stagingBuffer->Initialize());
|
|
||||||
return std::move(stagingBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -514,22 +507,22 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext,
|
void Device::CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext,
|
||||||
StagingBufferBase* source,
|
BufferBase* source,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
ASSERT(commandContext != nullptr);
|
ASSERT(commandContext != nullptr);
|
||||||
Buffer* dstBuffer = ToBackend(destination);
|
Buffer* dstBuffer = ToBackend(destination);
|
||||||
StagingBuffer* srcBuffer = ToBackend(source);
|
Buffer* srcBuffer = ToBackend(source);
|
||||||
dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
dstBuffer->TrackUsageAndTransitionNow(commandContext, wgpu::BufferUsage::CopyDst);
|
||||||
|
|
||||||
commandContext->GetCommandList()->CopyBufferRegion(dstBuffer->GetD3D12Resource(),
|
commandContext->GetCommandList()->CopyBufferRegion(
|
||||||
destinationOffset, srcBuffer->GetResource(),
|
dstBuffer->GetD3D12Resource(), destinationOffset, srcBuffer->GetD3D12Resource(),
|
||||||
sourceOffset, size);
|
sourceOffset, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
const Extent3D& copySizePixels) {
|
||||||
|
@ -549,7 +542,7 @@ MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
||||||
|
|
||||||
RecordBufferTextureCopyWithBufferHandle(
|
RecordBufferTextureCopyWithBufferHandle(
|
||||||
BufferTextureCopyDirection::B2T, commandContext->GetCommandList(),
|
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);
|
copySizePixels);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -96,21 +96,20 @@ class Device final : public DeviceBase {
|
||||||
|
|
||||||
MaybeError ExecutePendingCommandContext();
|
MaybeError ExecutePendingCommandContext();
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
|
|
||||||
void CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext,
|
void CopyFromStagingToBufferHelper(CommandRecordingContext* commandContext,
|
||||||
StagingBufferBase* source,
|
BufferBase* source,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size);
|
uint64_t size);
|
||||||
|
|
||||||
MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) override;
|
const Extent3D& copySizePixels) override;
|
||||||
|
|
|
@ -34,7 +34,6 @@ class Queue;
|
||||||
class RenderPipeline;
|
class RenderPipeline;
|
||||||
class Sampler;
|
class Sampler;
|
||||||
class ShaderModule;
|
class ShaderModule;
|
||||||
class StagingBuffer;
|
|
||||||
class SwapChain;
|
class SwapChain;
|
||||||
class Texture;
|
class Texture;
|
||||||
class TextureView;
|
class TextureView;
|
||||||
|
@ -55,7 +54,6 @@ struct D3D12BackendTraits {
|
||||||
using ResourceHeapType = Heap;
|
using ResourceHeapType = Heap;
|
||||||
using SamplerType = Sampler;
|
using SamplerType = Sampler;
|
||||||
using ShaderModuleType = ShaderModule;
|
using ShaderModuleType = ShaderModule;
|
||||||
using StagingBufferType = StagingBuffer;
|
|
||||||
using SwapChainType = SwapChain;
|
using SwapChainType = SwapChain;
|
||||||
using TextureType = Texture;
|
using TextureType = Texture;
|
||||||
using TextureViewType = TextureView;
|
using TextureViewType = TextureView;
|
||||||
|
|
|
@ -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
|
|
|
@ -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_
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "dawn/native/d3d12/Forward.h"
|
#include "dawn/native/d3d12/Forward.h"
|
||||||
#include "dawn/native/d3d12/HeapD3D12.h"
|
#include "dawn/native/d3d12/HeapD3D12.h"
|
||||||
#include "dawn/native/d3d12/ResourceAllocatorManagerD3D12.h"
|
#include "dawn/native/d3d12/ResourceAllocatorManagerD3D12.h"
|
||||||
#include "dawn/native/d3d12/StagingBufferD3D12.h"
|
|
||||||
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
|
||||||
#include "dawn/native/d3d12/TextureCopySplitter.h"
|
#include "dawn/native/d3d12/TextureCopySplitter.h"
|
||||||
#include "dawn/native/d3d12/UtilsD3D12.h"
|
#include "dawn/native/d3d12/UtilsD3D12.h"
|
||||||
|
@ -1189,7 +1188,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
||||||
textureCopy.aspect = aspect;
|
textureCopy.aspect = aspect;
|
||||||
RecordBufferTextureCopyWithBufferHandle(
|
RecordBufferTextureCopyWithBufferHandle(
|
||||||
BufferTextureCopyDirection::B2T, commandList,
|
BufferTextureCopyDirection::B2T, commandList,
|
||||||
ToBackend(uploadHandle.stagingBuffer)->GetResource(),
|
ToBackend(uploadHandle.stagingBuffer)->GetD3D12Resource(),
|
||||||
uploadHandle.startOffset, bytesPerRow, largestMipSize.height, textureCopy,
|
uploadHandle.startOffset, bytesPerRow, largestMipSize.height, textureCopy,
|
||||||
copySize);
|
copySize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class Buffer final : public BufferBase {
|
||||||
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
|
MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override;
|
||||||
void UnmapImpl() override;
|
void UnmapImpl() override;
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
void* GetMappedPointerImpl() override;
|
void* GetMappedPointer() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Buffer::GetMappedPointerImpl() {
|
void* Buffer::GetMappedPointer() {
|
||||||
return [*mMtlBuffer contents];
|
return [*mMtlBuffer contents];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include "dawn/native/metal/QuerySetMTL.h"
|
#include "dawn/native/metal/QuerySetMTL.h"
|
||||||
#include "dawn/native/metal/RenderPipelineMTL.h"
|
#include "dawn/native/metal/RenderPipelineMTL.h"
|
||||||
#include "dawn/native/metal/SamplerMTL.h"
|
#include "dawn/native/metal/SamplerMTL.h"
|
||||||
#include "dawn/native/metal/StagingBufferMTL.h"
|
|
||||||
#include "dawn/native/metal/TextureMTL.h"
|
#include "dawn/native/metal/TextureMTL.h"
|
||||||
#include "dawn/native/metal/UtilsMetal.h"
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
|
|
||||||
|
@ -1144,7 +1143,7 @@ MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext)
|
||||||
dstBuffer->EnsureDataInitializedAsDestination(commandContext, offset, size);
|
dstBuffer->EnsureDataInitializedAsDestination(commandContext, offset, size);
|
||||||
|
|
||||||
[commandContext->EnsureBlit()
|
[commandContext->EnsureBlit()
|
||||||
copyFromBuffer:ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle()
|
copyFromBuffer:ToBackend(uploadHandle.stagingBuffer)->GetMTLBuffer()
|
||||||
sourceOffset:uploadHandle.startOffset
|
sourceOffset:uploadHandle.startOffset
|
||||||
toBuffer:dstBuffer->GetMTLBuffer()
|
toBuffer:dstBuffer->GetMTLBuffer()
|
||||||
destinationOffset:offset
|
destinationOffset:offset
|
||||||
|
|
|
@ -63,13 +63,12 @@ class Device final : public DeviceBase {
|
||||||
std::vector<MTLSharedEventAndSignalValue> waitEvents);
|
std::vector<MTLSharedEventAndSignalValue> waitEvents);
|
||||||
void WaitForCommandsToBeScheduled();
|
void WaitForCommandsToBeScheduled();
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& dataLayout,
|
const TextureDataLayout& dataLayout,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) override;
|
const Extent3D& copySizePixels) override;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "dawn/native/metal/RenderPipelineMTL.h"
|
#include "dawn/native/metal/RenderPipelineMTL.h"
|
||||||
#include "dawn/native/metal/SamplerMTL.h"
|
#include "dawn/native/metal/SamplerMTL.h"
|
||||||
#include "dawn/native/metal/ShaderModuleMTL.h"
|
#include "dawn/native/metal/ShaderModuleMTL.h"
|
||||||
#include "dawn/native/metal/StagingBufferMTL.h"
|
|
||||||
#include "dawn/native/metal/SwapChainMTL.h"
|
#include "dawn/native/metal/SwapChainMTL.h"
|
||||||
#include "dawn/native/metal/TextureMTL.h"
|
#include "dawn/native/metal/TextureMTL.h"
|
||||||
#include "dawn/native/metal/UtilsMetal.h"
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
|
@ -465,13 +464,7 @@ void Device::ExportLastSignaledEvent(ExternalImageMTLSharedEventDescriptor* desc
|
||||||
desc->signaledValue = static_cast<uint64_t>(GetLastSubmittedCommandSerial());
|
desc->signaledValue = static_cast<uint64_t>(GetLastSubmittedCommandSerial());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer = std::make_unique<StagingBuffer>(size, this);
|
|
||||||
DAWN_TRY(stagingBuffer->Initialize());
|
|
||||||
return std::move(stagingBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -484,7 +477,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
||||||
->EnsureDataInitializedAsDestination(
|
->EnsureDataInitializedAsDestination(
|
||||||
GetPendingCommandContext(DeviceBase::SubmitMode::Passive), destinationOffset, size);
|
GetPendingCommandContext(DeviceBase::SubmitMode::Passive), destinationOffset, size);
|
||||||
|
|
||||||
id<MTLBuffer> uploadBuffer = ToBackend(source)->GetBufferHandle();
|
id<MTLBuffer> uploadBuffer = ToBackend(source)->GetMTLBuffer();
|
||||||
id<MTLBuffer> buffer = ToBackend(destination)->GetMTLBuffer();
|
id<MTLBuffer> buffer = ToBackend(destination)->GetMTLBuffer();
|
||||||
[GetPendingCommandContext(DeviceBase::SubmitMode::Passive)->EnsureBlit()
|
[GetPendingCommandContext(DeviceBase::SubmitMode::Passive)->EnsureBlit()
|
||||||
copyFromBuffer:uploadBuffer
|
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
|
// 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
|
// 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.
|
// 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,
|
const TextureDataLayout& dataLayout,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
const Extent3D& copySizePixels) {
|
||||||
|
@ -508,7 +501,7 @@ MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
||||||
texture, *dst, copySizePixels);
|
texture, *dst, copySizePixels);
|
||||||
|
|
||||||
RecordCopyBufferToTexture(GetPendingCommandContext(DeviceBase::SubmitMode::Passive),
|
RecordCopyBufferToTexture(GetPendingCommandContext(DeviceBase::SubmitMode::Passive),
|
||||||
ToBackend(source)->GetBufferHandle(), source->GetSize(),
|
ToBackend(source)->GetMTLBuffer(), source->GetSize(),
|
||||||
dataLayout.offset, dataLayout.bytesPerRow, dataLayout.rowsPerImage,
|
dataLayout.offset, dataLayout.bytesPerRow, dataLayout.rowsPerImage,
|
||||||
texture, dst->mipLevel, dst->origin, dst->aspect, copySizePixels);
|
texture, dst->mipLevel, dst->origin, dst->aspect, copySizePixels);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -33,7 +33,6 @@ class Queue;
|
||||||
class RenderPipeline;
|
class RenderPipeline;
|
||||||
class Sampler;
|
class Sampler;
|
||||||
class ShaderModule;
|
class ShaderModule;
|
||||||
class StagingBuffer;
|
|
||||||
class SwapChain;
|
class SwapChain;
|
||||||
class Texture;
|
class Texture;
|
||||||
class TextureView;
|
class TextureView;
|
||||||
|
@ -52,7 +51,6 @@ struct MetalBackendTraits {
|
||||||
using RenderPipelineType = RenderPipeline;
|
using RenderPipelineType = RenderPipeline;
|
||||||
using SamplerType = Sampler;
|
using SamplerType = Sampler;
|
||||||
using ShaderModuleType = ShaderModule;
|
using ShaderModuleType = ShaderModule;
|
||||||
using StagingBufferType = StagingBuffer;
|
|
||||||
using SwapChainType = SwapChain;
|
using SwapChainType = SwapChain;
|
||||||
using TextureType = Texture;
|
using TextureType = Texture;
|
||||||
using TextureViewType = TextureView;
|
using TextureViewType = TextureView;
|
||||||
|
|
|
@ -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 <Metal/Metal.h>
|
|
||||||
|
|
||||||
namespace dawn::native::metal {
|
|
||||||
|
|
||||||
class Device;
|
|
||||||
|
|
||||||
class StagingBuffer : public StagingBufferBase {
|
|
||||||
public:
|
|
||||||
StagingBuffer(size_t size, Device* device);
|
|
||||||
~StagingBuffer() override;
|
|
||||||
|
|
||||||
id<MTLBuffer> GetBufferHandle() const;
|
|
||||||
|
|
||||||
MaybeError Initialize() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Device* mDevice;
|
|
||||||
NSPRef<id<MTLBuffer>> mBuffer;
|
|
||||||
};
|
|
||||||
} // namespace dawn::native::metal
|
|
||||||
|
|
||||||
#endif // SRC_DAWN_NATIVE_METAL_STAGINGBUFFERMTL_H_
|
|
|
@ -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<MTLBuffer> StagingBuffer::GetBufferHandle() const {
|
|
||||||
return mBuffer.Get();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace dawn::native::metal
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "dawn/common/Platform.h"
|
#include "dawn/common/Platform.h"
|
||||||
#include "dawn/native/DynamicUploader.h"
|
#include "dawn/native/DynamicUploader.h"
|
||||||
#include "dawn/native/EnumMaskIterator.h"
|
#include "dawn/native/EnumMaskIterator.h"
|
||||||
|
#include "dawn/native/metal/BufferMTL.h"
|
||||||
#include "dawn/native/metal/DeviceMTL.h"
|
#include "dawn/native/metal/DeviceMTL.h"
|
||||||
#include "dawn/native/metal/StagingBufferMTL.h"
|
|
||||||
#include "dawn/native/metal/UtilsMetal.h"
|
#include "dawn/native/metal/UtilsMetal.h"
|
||||||
|
|
||||||
#include <CoreVideo/CVPixelBuffer.h>
|
#include <CoreVideo/CVPixelBuffer.h>
|
||||||
|
@ -989,7 +989,7 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext,
|
||||||
blockInfo.byteSize));
|
blockInfo.byteSize));
|
||||||
memset(uploadHandle.mappedBuffer, clearColor, bufferSize);
|
memset(uploadHandle.mappedBuffer, clearColor, bufferSize);
|
||||||
|
|
||||||
id<MTLBuffer> uploadBuffer = ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle();
|
id<MTLBuffer> uploadBuffer = ToBackend(uploadHandle.stagingBuffer)->GetMTLBuffer();
|
||||||
|
|
||||||
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
||||||
++level) {
|
++level) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ struct CopyFromStagingToBufferOperation : PendingOperation {
|
||||||
destination->CopyFromStaging(staging, sourceOffset, destinationOffset, size);
|
destination->CopyFromStaging(staging, sourceOffset, destinationOffset, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
StagingBufferBase* staging;
|
BufferBase* staging;
|
||||||
Ref<Buffer> destination;
|
Ref<Buffer> destination;
|
||||||
uint64_t sourceOffset;
|
uint64_t sourceOffset;
|
||||||
uint64_t destinationOffset;
|
uint64_t destinationOffset;
|
||||||
|
@ -193,12 +193,6 @@ ResultOrError<Ref<TextureViewBase>> Device::CreateTextureViewImpl(
|
||||||
return AcquireRef(new TextureView(texture, descriptor));
|
return AcquireRef(new TextureView(texture, descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer = std::make_unique<StagingBuffer>(size, this);
|
|
||||||
DAWN_TRY(stagingBuffer->Initialize());
|
|
||||||
return std::move(stagingBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::DestroyImpl() {
|
void Device::DestroyImpl() {
|
||||||
ASSERT(GetState() == State::Disconnected);
|
ASSERT(GetState() == State::Disconnected);
|
||||||
|
|
||||||
|
@ -217,7 +211,7 @@ bool Device::HasPendingCommands() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -238,7 +232,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
const Extent3D& copySizePixels) {
|
||||||
|
@ -325,7 +319,7 @@ MaybeError Buffer::MapAtCreationImpl() {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::CopyFromStaging(StagingBufferBase* staging,
|
void Buffer::CopyFromStaging(BufferBase* staging,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) {
|
uint64_t size) {
|
||||||
|
@ -343,7 +337,7 @@ MaybeError Buffer::MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Buffer::GetMappedPointerImpl() {
|
void* Buffer::GetMappedPointer() {
|
||||||
return mBackingData.get();
|
return mBackingData.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,24 +520,6 @@ wgpu::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const {
|
||||||
return wgpu::TextureFormat::RGBA8Unorm;
|
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<uint8_t[]>(GetSize());
|
|
||||||
mMappedPointer = mBuffer.get();
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Device::GetOptimalBytesPerRowAlignment() const {
|
uint32_t Device::GetOptimalBytesPerRowAlignment() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "dawn/native/RingBufferAllocator.h"
|
#include "dawn/native/RingBufferAllocator.h"
|
||||||
#include "dawn/native/Sampler.h"
|
#include "dawn/native/Sampler.h"
|
||||||
#include "dawn/native/ShaderModule.h"
|
#include "dawn/native/ShaderModule.h"
|
||||||
#include "dawn/native/StagingBuffer.h"
|
|
||||||
#include "dawn/native/SwapChain.h"
|
#include "dawn/native/SwapChain.h"
|
||||||
#include "dawn/native/Texture.h"
|
#include "dawn/native/Texture.h"
|
||||||
#include "dawn/native/ToBackend.h"
|
#include "dawn/native/ToBackend.h"
|
||||||
|
@ -105,13 +104,12 @@ class Device final : public DeviceBase {
|
||||||
void AddPendingOperation(std::unique_ptr<PendingOperation> operation);
|
void AddPendingOperation(std::unique_ptr<PendingOperation> operation);
|
||||||
MaybeError SubmitPendingOperations();
|
MaybeError SubmitPendingOperations();
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) override;
|
const Extent3D& copySizePixels) override;
|
||||||
|
@ -230,7 +228,7 @@ class Buffer final : public BufferBase {
|
||||||
public:
|
public:
|
||||||
Buffer(Device* device, const BufferDescriptor* descriptor);
|
Buffer(Device* device, const BufferDescriptor* descriptor);
|
||||||
|
|
||||||
void CopyFromStaging(StagingBufferBase* staging,
|
void CopyFromStaging(BufferBase* staging,
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size);
|
uint64_t size);
|
||||||
|
@ -243,7 +241,7 @@ class Buffer final : public BufferBase {
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
void* GetMappedPointerImpl() override;
|
void* GetMappedPointer() override;
|
||||||
|
|
||||||
std::unique_ptr<uint8_t[]> mBackingData;
|
std::unique_ptr<uint8_t[]> mBackingData;
|
||||||
};
|
};
|
||||||
|
@ -335,17 +333,6 @@ class NativeSwapChainImpl {
|
||||||
wgpu::TextureFormat GetPreferredFormat() const;
|
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<uint8_t[]> mBuffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
|
Texture(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
|
||||||
|
|
|
@ -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);
|
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.
|
// the resource but OpenGL gives us the pointer at offset. Remove the offset.
|
||||||
mMappedData = static_cast<uint8_t*>(mappedData) - offset;
|
mMappedData = static_cast<uint8_t*>(mappedData) - offset;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Buffer::GetMappedPointerImpl() {
|
void* Buffer::GetMappedPointer() {
|
||||||
// The mapping offset has already been removed.
|
// The mapping offset has already been removed.
|
||||||
return mMappedData;
|
return mMappedData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Buffer final : public BufferBase {
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
void* GetMappedPointerImpl() override;
|
void* GetMappedPointer() override;
|
||||||
|
|
||||||
void InitializeToZero();
|
void InitializeToZero();
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "dawn/native/BindGroupLayout.h"
|
#include "dawn/native/BindGroupLayout.h"
|
||||||
#include "dawn/native/ErrorData.h"
|
#include "dawn/native/ErrorData.h"
|
||||||
#include "dawn/native/Instance.h"
|
#include "dawn/native/Instance.h"
|
||||||
#include "dawn/native/StagingBuffer.h"
|
|
||||||
#include "dawn/native/opengl/BindGroupGL.h"
|
#include "dawn/native/opengl/BindGroupGL.h"
|
||||||
#include "dawn/native/opengl/BindGroupLayoutGL.h"
|
#include "dawn/native/opengl/BindGroupLayoutGL.h"
|
||||||
#include "dawn/native/opengl/BufferGL.h"
|
#include "dawn/native/opengl/BufferGL.h"
|
||||||
|
@ -414,11 +413,7 @@ ResultOrError<ExecutionSerial> Device::CheckAndUpdateCompletedSerials() {
|
||||||
return fenceSerial;
|
return fenceSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
return DAWN_UNIMPLEMENTED_ERROR("Device unable to create staging buffer.");
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -426,7 +421,7 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
||||||
return DAWN_UNIMPLEMENTED_ERROR("Device unable to copy from staging buffer.");
|
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,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
const Extent3D& copySizePixels) {
|
||||||
|
|
|
@ -67,14 +67,13 @@ class Device final : public DeviceBase {
|
||||||
|
|
||||||
MaybeError TickImpl() override;
|
MaybeError TickImpl() override;
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
|
|
||||||
MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) override;
|
const Extent3D& copySizePixels) override;
|
||||||
|
|
|
@ -325,7 +325,7 @@ void Buffer::UnmapImpl() {
|
||||||
// No need to do anything, we keep CPU-visible memory mapped at all time.
|
// 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();
|
uint8_t* memory = mMemoryAllocation.GetMappedPointer();
|
||||||
ASSERT(memory != nullptr);
|
ASSERT(memory != nullptr);
|
||||||
return memory;
|
return memory;
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Buffer final : public BufferBase {
|
||||||
void DestroyImpl() override;
|
void DestroyImpl() override;
|
||||||
bool IsCPUWritableAtCreation() const override;
|
bool IsCPUWritableAtCreation() const override;
|
||||||
MaybeError MapAtCreationImpl() override;
|
MaybeError MapAtCreationImpl() override;
|
||||||
void* GetMappedPointerImpl() override;
|
void* GetMappedPointer() override;
|
||||||
|
|
||||||
VkBuffer mHandle = VK_NULL_HANDLE;
|
VkBuffer mHandle = VK_NULL_HANDLE;
|
||||||
ResourceMemoryAllocation mMemoryAllocation;
|
ResourceMemoryAllocation mMemoryAllocation;
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include "dawn/native/vulkan/QuerySetVk.h"
|
#include "dawn/native/vulkan/QuerySetVk.h"
|
||||||
#include "dawn/native/vulkan/RenderPassCache.h"
|
#include "dawn/native/vulkan/RenderPassCache.h"
|
||||||
#include "dawn/native/vulkan/RenderPipelineVk.h"
|
#include "dawn/native/vulkan/RenderPipelineVk.h"
|
||||||
#include "dawn/native/vulkan/StagingBufferVk.h"
|
|
||||||
#include "dawn/native/vulkan/TextureVk.h"
|
#include "dawn/native/vulkan/TextureVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.h"
|
#include "dawn/native/vulkan/VulkanError.h"
|
||||||
|
@ -870,7 +869,7 @@ MaybeError CommandBuffer::RecordCommands(CommandRecordingContext* recordingConte
|
||||||
copy.size = size;
|
copy.size = size;
|
||||||
|
|
||||||
device->fn.CmdCopyBuffer(commands,
|
device->fn.CmdCopyBuffer(commands,
|
||||||
ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle(),
|
ToBackend(uploadHandle.stagingBuffer)->GetHandle(),
|
||||||
dstBuffer->GetHandle(), 1, ©);
|
dstBuffer->GetHandle(), 1, ©);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
||||||
#include "dawn/native/vulkan/SamplerVk.h"
|
#include "dawn/native/vulkan/SamplerVk.h"
|
||||||
#include "dawn/native/vulkan/ShaderModuleVk.h"
|
#include "dawn/native/vulkan/ShaderModuleVk.h"
|
||||||
#include "dawn/native/vulkan/StagingBufferVk.h"
|
|
||||||
#include "dawn/native/vulkan/SwapChainVk.h"
|
#include "dawn/native/vulkan/SwapChainVk.h"
|
||||||
#include "dawn/native/vulkan/TextureVk.h"
|
#include "dawn/native/vulkan/TextureVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
|
@ -823,13 +822,7 @@ void Device::RecycleCompletedCommands() {
|
||||||
mCommandsInFlight.ClearUpTo(GetCompletedCommandSerial());
|
mCommandsInFlight.ClearUpTo(GetCompletedCommandSerial());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> Device::CreateStagingBuffer(size_t size) {
|
MaybeError Device::CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
std::unique_ptr<StagingBufferBase> stagingBuffer = std::make_unique<StagingBuffer>(size, this);
|
|
||||||
DAWN_TRY(stagingBuffer->Initialize());
|
|
||||||
return std::move(stagingBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
|
@ -857,13 +850,13 @@ MaybeError Device::CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
||||||
copy.dstOffset = destinationOffset;
|
copy.dstOffset = destinationOffset;
|
||||||
copy.size = size;
|
copy.size = size;
|
||||||
|
|
||||||
this->fn.CmdCopyBuffer(recordingContext->commandBuffer, ToBackend(source)->GetBufferHandle(),
|
this->fn.CmdCopyBuffer(recordingContext->commandBuffer, ToBackend(source)->GetHandle(),
|
||||||
ToBackend(destination)->GetHandle(), 1, ©);
|
ToBackend(destination)->GetHandle(), 1, ©);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Device::CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError Device::CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) {
|
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
|
// Dawn guarantees dstImage be in the TRANSFER_DST_OPTIMAL layout after the
|
||||||
// copy command.
|
// copy command.
|
||||||
this->fn.CmdCopyBufferToImage(recordingContext->commandBuffer,
|
this->fn.CmdCopyBufferToImage(recordingContext->commandBuffer, ToBackend(source)->GetHandle(),
|
||||||
ToBackend(source)->GetBufferHandle(), dstImage,
|
dstImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,13 +89,12 @@ class Device final : public DeviceBase {
|
||||||
|
|
||||||
MaybeError TickImpl() override;
|
MaybeError TickImpl() override;
|
||||||
|
|
||||||
ResultOrError<std::unique_ptr<StagingBufferBase>> CreateStagingBuffer(size_t size) override;
|
MaybeError CopyFromStagingToBufferImpl(BufferBase* source,
|
||||||
MaybeError CopyFromStagingToBufferImpl(StagingBufferBase* source,
|
|
||||||
uint64_t sourceOffset,
|
uint64_t sourceOffset,
|
||||||
BufferBase* destination,
|
BufferBase* destination,
|
||||||
uint64_t destinationOffset,
|
uint64_t destinationOffset,
|
||||||
uint64_t size) override;
|
uint64_t size) override;
|
||||||
MaybeError CopyFromStagingToTextureImpl(const StagingBufferBase* source,
|
MaybeError CopyFromStagingToTextureImpl(const BufferBase* source,
|
||||||
const TextureDataLayout& src,
|
const TextureDataLayout& src,
|
||||||
TextureCopy* dst,
|
TextureCopy* dst,
|
||||||
const Extent3D& copySizePixels) override;
|
const Extent3D& copySizePixels) override;
|
||||||
|
|
|
@ -34,7 +34,6 @@ class RenderPipeline;
|
||||||
class ResourceHeap;
|
class ResourceHeap;
|
||||||
class Sampler;
|
class Sampler;
|
||||||
class ShaderModule;
|
class ShaderModule;
|
||||||
class StagingBuffer;
|
|
||||||
class SwapChain;
|
class SwapChain;
|
||||||
class Texture;
|
class Texture;
|
||||||
class TextureView;
|
class TextureView;
|
||||||
|
@ -55,7 +54,6 @@ struct VulkanBackendTraits {
|
||||||
using ResourceHeapType = ResourceHeap;
|
using ResourceHeapType = ResourceHeap;
|
||||||
using SamplerType = Sampler;
|
using SamplerType = Sampler;
|
||||||
using ShaderModuleType = ShaderModule;
|
using ShaderModuleType = ShaderModule;
|
||||||
using StagingBufferType = StagingBuffer;
|
|
||||||
using SwapChainType = SwapChain;
|
using SwapChainType = SwapChain;
|
||||||
using TextureType = Texture;
|
using TextureType = Texture;
|
||||||
using TextureViewType = TextureView;
|
using TextureViewType = TextureView;
|
||||||
|
|
|
@ -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
|
|
|
@ -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_
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "dawn/native/vulkan/FencedDeleter.h"
|
#include "dawn/native/vulkan/FencedDeleter.h"
|
||||||
#include "dawn/native/vulkan/ResourceHeapVk.h"
|
#include "dawn/native/vulkan/ResourceHeapVk.h"
|
||||||
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
||||||
#include "dawn/native/vulkan/StagingBufferVk.h"
|
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.h"
|
#include "dawn/native/vulkan/VulkanError.h"
|
||||||
|
|
||||||
|
@ -1255,10 +1254,9 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* recordingContext,
|
||||||
regions.push_back(ComputeBufferImageCopyRegion(dataLayout, textureCopy, copySize));
|
regions.push_back(ComputeBufferImageCopyRegion(dataLayout, textureCopy, copySize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
device->fn.CmdCopyBufferToImage(recordingContext->commandBuffer,
|
device->fn.CmdCopyBufferToImage(
|
||||||
ToBackend(uploadHandle.stagingBuffer)->GetBufferHandle(),
|
recordingContext->commandBuffer, ToBackend(uploadHandle.stagingBuffer)->GetHandle(),
|
||||||
GetHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
GetHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, regions.size(), regions.data());
|
||||||
regions.size(), regions.data());
|
|
||||||
} else {
|
} else {
|
||||||
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
for (uint32_t level = range.baseMipLevel; level < range.baseMipLevel + range.levelCount;
|
||||||
++level) {
|
++level) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ class BufferMock : public BufferBase {
|
||||||
(wgpu::MapMode mode, size_t offset, size_t size),
|
(wgpu::MapMode mode, size_t offset, size_t size),
|
||||||
(override));
|
(override));
|
||||||
MOCK_METHOD(void, UnmapImpl, (), (override));
|
MOCK_METHOD(void, UnmapImpl, (), (override));
|
||||||
MOCK_METHOD(void*, GetMappedPointerImpl, (), (override));
|
MOCK_METHOD(void*, GetMappedPointer, (), (override));
|
||||||
|
|
||||||
MOCK_METHOD(bool, IsCPUWritableAtCreation, (), (const, override));
|
MOCK_METHOD(bool, IsCPUWritableAtCreation, (), (const, override));
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,17 +34,13 @@ class DeviceMock : public DeviceBase {
|
||||||
(CommandEncoder*, const CommandBufferDescriptor*),
|
(CommandEncoder*, const CommandBufferDescriptor*),
|
||||||
(override));
|
(override));
|
||||||
|
|
||||||
MOCK_METHOD(ResultOrError<std::unique_ptr<StagingBufferBase>>,
|
|
||||||
CreateStagingBuffer,
|
|
||||||
(size_t),
|
|
||||||
(override));
|
|
||||||
MOCK_METHOD(MaybeError,
|
MOCK_METHOD(MaybeError,
|
||||||
CopyFromStagingToBufferImpl,
|
CopyFromStagingToBufferImpl,
|
||||||
(StagingBufferBase*, uint64_t, BufferBase*, uint64_t, uint64_t),
|
(BufferBase*, uint64_t, BufferBase*, uint64_t, uint64_t),
|
||||||
(override));
|
(override));
|
||||||
MOCK_METHOD(MaybeError,
|
MOCK_METHOD(MaybeError,
|
||||||
CopyFromStagingToTextureImpl,
|
CopyFromStagingToTextureImpl,
|
||||||
(const StagingBufferBase*, const TextureDataLayout&, TextureCopy*, const Extent3D&),
|
(const BufferBase*, const TextureDataLayout&, TextureCopy*, const Extent3D&),
|
||||||
(override));
|
(override));
|
||||||
|
|
||||||
MOCK_METHOD(uint32_t, GetOptimalBytesPerRowAlignment, (), (const, override));
|
MOCK_METHOD(uint32_t, GetOptimalBytesPerRowAlignment, (), (const, override));
|
||||||
|
|
Loading…
Reference in New Issue