Cleanup CopyBufferToBufferCmd

This command internally used a BufferCopy struct which is meant for
Buffer->Texture / Texture->Buffer copies. It contained unnecessary rowPitch
and imageHeight. This patch changes the members of CopyBufferToBufferCmd to
match the CopyBufferToBuffer api call.

Bug: dawn:164
Change-Id: I4737eb4ceb655e8282964c438242627070e355dc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6320
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2019-06-07 03:06:47 +00:00 committed by Commit Bot service account
parent 2d4b529443
commit fa7228a1fa
6 changed files with 48 additions and 47 deletions

View File

@ -62,19 +62,22 @@ namespace dawn_native {
return {};
}
bool FitsInBuffer(const BufferBase* buffer, uint64_t offset, uint64_t size) {
MaybeError ValidateCopySizeFitsInBuffer(const Ref<BufferBase>& buffer,
uint64_t offset,
uint64_t size) {
uint64_t bufferSize = buffer->GetSize();
return offset <= bufferSize && (size <= (bufferSize - offset));
}
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopy& bufferCopy, uint64_t dataSize) {
if (!FitsInBuffer(bufferCopy.buffer.Get(), bufferCopy.offset, dataSize)) {
bool fitsInBuffer = offset <= bufferSize && (size <= (bufferSize - offset));
if (!fitsInBuffer) {
return DAWN_VALIDATION_ERROR("Copy would overflow the buffer");
}
return {};
}
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopy& bufferCopy, uint64_t dataSize) {
return ValidateCopySizeFitsInBuffer(bufferCopy.buffer, bufferCopy.offset, dataSize);
}
MaybeError ValidateB2BCopySizeAlignment(uint64_t dataSize,
uint64_t srcOffset,
uint64_t dstOffset) {
@ -690,10 +693,10 @@ namespace dawn_native {
CopyBufferToBufferCmd* copy =
mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
copy->source.buffer = source;
copy->source.offset = sourceOffset;
copy->destination.buffer = destination;
copy->destination.offset = destinationOffset;
copy->source = source;
copy->sourceOffset = sourceOffset;
copy->destination = destination;
copy->destinationOffset = destinationOffset;
copy->size = size;
}
@ -877,18 +880,20 @@ namespace dawn_native {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>();
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, copy->size));
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size));
DAWN_TRY(ValidateB2BCopySizeAlignment(copy->size, copy->source.offset,
copy->destination.offset));
DAWN_TRY(
ValidateCopySizeFitsInBuffer(copy->source, copy->sourceOffset, copy->size));
DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination,
copy->destinationOffset, copy->size));
DAWN_TRY(ValidateB2BCopySizeAlignment(copy->size, copy->sourceOffset,
copy->destinationOffset));
DAWN_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
dawn::BufferUsageBit::TransferSrc));
DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
DAWN_TRY(
ValidateCanUseAs(copy->source.Get(), dawn::BufferUsageBit::TransferSrc));
DAWN_TRY(ValidateCanUseAs(copy->destination.Get(),
dawn::BufferUsageBit::TransferDst));
mResourceUsages.topLevelBuffers.insert(copy->source.buffer.Get());
mResourceUsages.topLevelBuffers.insert(copy->destination.buffer.Get());
mResourceUsages.topLevelBuffers.insert(copy->source.Get());
mResourceUsages.topLevelBuffers.insert(copy->destination.Get());
} break;
case Command::CopyBufferToTexture: {

View File

@ -102,8 +102,10 @@ namespace dawn_native {
};
struct CopyBufferToBufferCmd {
BufferCopy source;
BufferCopy destination;
Ref<BufferBase> source;
uint64_t sourceOffset;
Ref<BufferBase> destination;
uint64_t destinationOffset;
uint64_t size;
};

View File

@ -469,15 +469,15 @@ namespace dawn_native { namespace d3d12 {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
Buffer* srcBuffer = ToBackend(copy->source.buffer.Get());
Buffer* dstBuffer = ToBackend(copy->destination.buffer.Get());
Buffer* srcBuffer = ToBackend(copy->source.Get());
Buffer* dstBuffer = ToBackend(copy->destination.Get());
srcBuffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferSrc);
dstBuffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferDst);
commandList->CopyBufferRegion(
dstBuffer->GetD3D12Resource().Get(), copy->destination.offset,
srcBuffer->GetD3D12Resource().Get(), copy->source.offset, copy->size);
dstBuffer->GetD3D12Resource().Get(), copy->destinationOffset,
srcBuffer->GetD3D12Resource().Get(), copy->sourceOffset, copy->size);
} break;
case Command::CopyBufferToTexture: {

View File

@ -348,14 +348,12 @@ namespace dawn_native { namespace metal {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
auto& src = copy->source;
auto& dst = copy->destination;
encoders.EnsureBlit(commandBuffer);
[encoders.blit copyFromBuffer:ToBackend(src.buffer)->GetMTLBuffer()
sourceOffset:src.offset
toBuffer:ToBackend(dst.buffer)->GetMTLBuffer()
destinationOffset:dst.offset
[encoders.blit copyFromBuffer:ToBackend(copy->source)->GetMTLBuffer()
sourceOffset:copy->sourceOffset
toBuffer:ToBackend(copy->destination)->GetMTLBuffer()
destinationOffset:copy->destinationOffset
size:copy->size];
} break;

View File

@ -360,13 +360,11 @@ namespace dawn_native { namespace opengl {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
auto& src = copy->source;
auto& dst = copy->destination;
glBindBuffer(GL_PIXEL_PACK_BUFFER, ToBackend(src.buffer)->GetHandle());
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, ToBackend(dst.buffer)->GetHandle());
glCopyBufferSubData(GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER, src.offset,
dst.offset, copy->size);
glBindBuffer(GL_PIXEL_PACK_BUFFER, ToBackend(copy->source)->GetHandle());
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, ToBackend(copy->destination)->GetHandle());
glCopyBufferSubData(GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,
copy->sourceOffset, copy->destinationOffset, copy->size);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

View File

@ -301,21 +301,19 @@ namespace dawn_native { namespace vulkan {
switch (type) {
case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
auto& src = copy->source;
auto& dst = copy->destination;
Buffer* srcBuffer = ToBackend(copy->source.Get());
Buffer* dstBuffer = ToBackend(copy->destination.Get());
ToBackend(src.buffer)
->TransitionUsageNow(commands, dawn::BufferUsageBit::TransferSrc);
ToBackend(dst.buffer)
->TransitionUsageNow(commands, dawn::BufferUsageBit::TransferDst);
srcBuffer->TransitionUsageNow(commands, dawn::BufferUsageBit::TransferSrc);
dstBuffer->TransitionUsageNow(commands, dawn::BufferUsageBit::TransferDst);
VkBufferCopy region;
region.srcOffset = src.offset;
region.dstOffset = dst.offset;
region.srcOffset = copy->sourceOffset;
region.dstOffset = copy->destinationOffset;
region.size = copy->size;
VkBuffer srcHandle = ToBackend(src.buffer)->GetHandle();
VkBuffer dstHandle = ToBackend(dst.buffer)->GetHandle();
VkBuffer srcHandle = srcBuffer->GetHandle();
VkBuffer dstHandle = dstBuffer->GetHandle();
device->fn.CmdCopyBuffer(commands, srcHandle, dstHandle, 1, &region);
} break;