diff --git a/pxr/imaging/hgiVulkan/blitCmds.cpp b/pxr/imaging/hgiVulkan/blitCmds.cpp index 583d80249a7..9ef164094ac 100644 --- a/pxr/imaging/hgiVulkan/blitCmds.cpp +++ b/pxr/imaging/hgiVulkan/blitCmds.cpp @@ -283,15 +283,15 @@ void HgiVulkanBlitCmds::CopyBufferCpuToGpu( if (!buffer->IsCPUStagingAddress(copyOp.cpuSourceBuffer) || copyOp.sourceByteOffset != copyOp.destinationByteOffset) { - uint8_t* dst = static_cast(buffer->GetCPUStagingAddress()); - size_t dstOffset = copyOp.destinationByteOffset; - // Offset into the src buffer - uint8_t* src = ((uint8_t*) copyOp.cpuSourceBuffer) + + const uint8_t* src = static_cast(copyOp.cpuSourceBuffer) + copyOp.sourceByteOffset; - // Offset into the dst buffer - memcpy(dst + dstOffset, src, copyOp.byteSize); + // Offset into the dst buffer. + uint8_t* dst = static_cast(buffer->GetCPUStagingAddress()) + + copyOp.destinationByteOffset; + + memcpy(dst, src, copyOp.byteSize); } // Schedule copy data from staging buffer to device-local buffer. @@ -299,7 +299,9 @@ void HgiVulkanBlitCmds::CopyBufferCpuToGpu( if (TF_VERIFY(stagingBuffer)) { VkBufferCopy copyRegion = {}; - copyRegion.srcOffset = copyOp.sourceByteOffset; + // Note we use the destinationByteOffset as the srcOffset here. The staging buffer + // should be prepared with the same data layout of the destination buffer. + copyRegion.srcOffset = copyOp.destinationByteOffset; copyRegion.dstOffset = copyOp.destinationByteOffset; copyRegion.size = copyOp.byteSize;