Skip to content

Commit

Permalink
Remove mReleasedStagingBuffers from DynamicUploader
Browse files Browse the repository at this point in the history
This patch removes `mReleasedStagingBuffers` from DynamicUploader
as these staging buffers are only used once and can be destroyed
after the current execution serial is passed.

Bug: 42242066
Change-Id: I17f22ab52df5e6c263960b584f5dee506988c3c3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/222334
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
  • Loading branch information
Jiawei-Shao authored and Dawn LUCI CQ committed Feb 5, 2025
1 parent 83cddb9 commit 0dae3df
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/dawn/native/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ MaybeError BufferBase::UploadData(uint64_t bufferOffset, const void* data, size_

memcpy(uploadHandle.mappedBuffer, data, size);

return device->CopyFromStagingToBuffer(uploadHandle.stagingBuffer, uploadHandle.startOffset,
this, bufferOffset, size);
return device->CopyFromStagingToBuffer(uploadHandle.stagingBuffer.Get(),
uploadHandle.startOffset, this, bufferOffset, size);
}

ExecutionSerial BufferBase::OnEndAccess() {
Expand Down
15 changes: 2 additions & 13 deletions src/dawn/native/DynamicUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ namespace dawn::native {

DynamicUploader::DynamicUploader(DeviceBase* device) : mDevice(device) {}

void DynamicUploader::ReleaseStagingBuffer(Ref<BufferBase> stagingBuffer) {
mReleasedStagingBuffers.Enqueue(std::move(stagingBuffer),
mDevice->GetQueue()->GetPendingCommandSerial());
}

ResultOrError<UploadHandle> DynamicUploader::AllocateInternal(uint64_t allocationSize,
ExecutionSerial serial,
uint64_t offsetAlignment) {
Expand All @@ -60,9 +55,7 @@ ResultOrError<UploadHandle> DynamicUploader::AllocateInternal(uint64_t allocatio

UploadHandle uploadHandle;
uploadHandle.mappedBuffer = static_cast<uint8_t*>(stagingBuffer->GetMappedPointer());
uploadHandle.stagingBuffer = stagingBuffer.Get();

ReleaseStagingBuffer(std::move(stagingBuffer));
uploadHandle.stagingBuffer = std::move(stagingBuffer);
return uploadHandle;
}

Expand Down Expand Up @@ -116,7 +109,7 @@ ResultOrError<UploadHandle> DynamicUploader::AllocateInternal(uint64_t allocatio
DAWN_ASSERT(targetRingBuffer->mStagingBuffer != nullptr);

UploadHandle uploadHandle;
uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer.Get();
uploadHandle.stagingBuffer = targetRingBuffer->mStagingBuffer;
uploadHandle.mappedBuffer =
static_cast<uint8_t*>(uploadHandle.stagingBuffer->GetMappedPointer()) + startOffset;
uploadHandle.startOffset = startOffset;
Expand All @@ -140,7 +133,6 @@ void DynamicUploader::Deallocate(ExecutionSerial lastCompletedSerial, bool freeA
i++;
}
}
mReleasedStagingBuffers.ClearUpTo(lastCompletedSerial);
}

ResultOrError<UploadHandle> DynamicUploader::Allocate(uint64_t allocationSize,
Expand All @@ -159,9 +151,6 @@ bool DynamicUploader::ShouldFlush() const {

uint64_t DynamicUploader::GetTotalAllocatedSize() const {
uint64_t size = 0;
for (const auto& buffer : mReleasedStagingBuffers.IterateAll()) {
size += buffer->GetSize();
}
for (const auto& buffer : mRingBuffers) {
if (buffer->mStagingBuffer != nullptr) {
size += buffer->mStagingBuffer->GetSize();
Expand Down
5 changes: 1 addition & 4 deletions src/dawn/native/DynamicUploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BufferBase;
struct UploadHandle {
raw_ptr<uint8_t> mappedBuffer = nullptr;
uint64_t startOffset = 0;
raw_ptr<BufferBase> stagingBuffer = nullptr;
Ref<BufferBase> stagingBuffer;
};

class DynamicUploader {
Expand Down Expand Up @@ -75,10 +75,7 @@ class DynamicUploader {
ExecutionSerial serial,
uint64_t offsetAlignment);

void ReleaseStagingBuffer(Ref<BufferBase> stagingBuffer);

std::vector<std::unique_ptr<RingBuffer>> mRingBuffers;
SerialQueue<ExecutionSerial, Ref<BufferBase>> mReleasedStagingBuffers;
raw_ptr<DeviceBase> mDevice;
};
} // namespace dawn::native
Expand Down
4 changes: 2 additions & 2 deletions src/dawn/native/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ MaybeError QueueBase::WriteTextureImpl(const TexelCopyTextureInfo& destination,

DeviceBase* device = GetDevice();

return device->CopyFromStagingToTexture(uploadHandle.stagingBuffer, passDataLayout, textureCopy,
writeSizePixel);
return device->CopyFromStagingToTexture(uploadHandle.stagingBuffer.Get(), passDataLayout,
textureCopy, writeSizePixel);
}

void QueueBase::APICopyTextureForBrowser(const TexelCopyTextureInfo* source,
Expand Down
2 changes: 1 addition & 1 deletion src/dawn/native/d3d12/BufferD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ MaybeError Buffer::ClearBuffer(CommandRecordingContext* commandContext,

memset(uploadHandle.mappedBuffer, clearValue, size);

device->CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer,
device->CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer.Get(),
uploadHandle.startOffset, this, offset, size);
}

Expand Down
2 changes: 1 addition & 1 deletion src/dawn/native/d3d12/DeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ MaybeError Device::CreateZeroBuffer() {

memset(uploadHandle.mappedBuffer, 0u, kZeroBufferSize);

CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer,
CopyFromStagingToBufferHelper(commandContext, uploadHandle.stagingBuffer.Get(),
uploadHandle.startOffset, mZeroBuffer.Get(), 0, kZeroBufferSize);

mZeroBuffer->SetInitialized(true);
Expand Down

0 comments on commit 0dae3df

Please sign in to comment.