Repository navigation
Support texture readback through copyTextureRegion #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3022,6 +3022,37 @@ namespace plume { | |||||||
| dstOrigin | ||||||||
| ); | ||||||||
| activeBlitEncoder->popDebugGroup(); | ||||||||
| } else if (dstLocation.type == RenderTextureCopyType::PLACED_FOOTPRINT && srcLocation.type == RenderTextureCopyType::SUBRESOURCE) { | ||||||||
| assert(dstBuffer != nullptr); | ||||||||
| assert(srcTexture != nullptr); | ||||||||
|
|
||||||||
| // Calculate block size based on source texture format | ||||||||
| const uint32_t blockWidth = RenderFormatBlockWidth(srcTexture->desc.format); | ||||||||
|
|
||||||||
| const MTL::Size size = { dstLocation.placedFootprint.width, dstLocation.placedFootprint.height, dstLocation.placedFootprint.depth }; | ||||||||
|
|
||||||||
| const uint32_t horizontalBlocks = (dstLocation.placedFootprint.rowWidth + blockWidth - 1) / blockWidth; | ||||||||
| const uint32_t verticalBlocks = (dstLocation.placedFootprint.height + blockWidth - 1) / blockWidth; | ||||||||
| const uint32_t bytesPerRow = horizontalBlocks * RenderFormatSize(srcTexture->desc.format); | ||||||||
| const uint32_t bytesPerImage = bytesPerRow * verticalBlocks; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| const MTL::Origin srcOrigin = (srcBox != nullptr) | ||||||||
| ? MTL::Origin { NS::UInteger(srcBox->left), NS::UInteger(srcBox->top), NS::UInteger(srcBox->front) } | ||||||||
| : MTL::Origin { 0, 0, 0 }; | ||||||||
|
|
||||||||
| activeBlitEncoder->pushDebugGroup(MTLSTR("CopyTextureRegion")); | ||||||||
| activeBlitEncoder->copyFromTexture( | ||||||||
| srcTexture->mtl, | ||||||||
| srcLocation.subresource.arrayIndex, | ||||||||
| srcLocation.subresource.mipLevel, | ||||||||
| srcOrigin, | ||||||||
| size, | ||||||||
| dstBuffer->mtl, | ||||||||
| dstLocation.placedFootprint.offset, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| bytesPerRow, | ||||||||
| bytesPerImage | ||||||||
| ); | ||||||||
| activeBlitEncoder->popDebugGroup(); | ||||||||
| } else { | ||||||||
| assert(dstTexture != nullptr); | ||||||||
| assert(srcTexture != nullptr); | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3229,6 +3229,27 @@ namespace plume { | |||||||||||||||||
| imageCopy.imageExtent.depth = srcLocation.placedFootprint.depth; | ||||||||||||||||||
| vkCmdCopyBufferToImage(vk, srcBuffer->vk, dstTexture->vk, toImageLayout(dstTexture->textureLayout), 1, &imageCopy); | ||||||||||||||||||
| } | ||||||||||||||||||
| else if ((dstLocation.type == RenderTextureCopyType::PLACED_FOOTPRINT) && (srcLocation.type == RenderTextureCopyType::SUBRESOURCE)) { | ||||||||||||||||||
| assert(dstBuffer != nullptr); | ||||||||||||||||||
| assert(srcTexture != nullptr); | ||||||||||||||||||
|
|
||||||||||||||||||
| const uint32_t blockWidth = RenderFormatBlockWidth(srcTexture->desc.format); | ||||||||||||||||||
| VkBufferImageCopy imageCopy = {}; | ||||||||||||||||||
| imageCopy.bufferOffset = dstLocation.placedFootprint.offset; | ||||||||||||||||||
|
Comment on lines
+3237
to
+3238
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same two things on Vulkan, the offset:
Suggested change
|
||||||||||||||||||
| imageCopy.bufferRowLength = ((dstLocation.placedFootprint.rowWidth + blockWidth - 1) / blockWidth) * blockWidth; | ||||||||||||||||||
| imageCopy.bufferImageHeight = ((dstLocation.placedFootprint.height + blockWidth - 1) / blockWidth) * blockWidth; | ||||||||||||||||||
| imageCopy.imageSubresource.aspectMask = toAspectFlags(srcTexture->desc.format, srcTexture->desc.flags); | ||||||||||||||||||
| imageCopy.imageSubresource.baseArrayLayer = srcLocation.subresource.arrayIndex; | ||||||||||||||||||
| imageCopy.imageSubresource.layerCount = 1; | ||||||||||||||||||
| imageCopy.imageSubresource.mipLevel = srcLocation.subresource.mipLevel; | ||||||||||||||||||
| imageCopy.imageOffset.x = srcBox != nullptr ? srcBox->left : 0; | ||||||||||||||||||
| imageCopy.imageOffset.y = srcBox != nullptr ? srcBox->top : 0; | ||||||||||||||||||
| imageCopy.imageOffset.z = srcBox != nullptr ? srcBox->front : 0; | ||||||||||||||||||
| imageCopy.imageExtent.width = dstLocation.placedFootprint.width; | ||||||||||||||||||
| imageCopy.imageExtent.height = dstLocation.placedFootprint.height; | ||||||||||||||||||
| imageCopy.imageExtent.depth = dstLocation.placedFootprint.depth; | ||||||||||||||||||
|
Comment on lines
+3248
to
+3250
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and the size:
Suggested change
|
||||||||||||||||||
| vkCmdCopyImageToBuffer(vk, srcTexture->vk, toImageLayout(srcTexture->textureLayout), dstBuffer->vk, 1, &imageCopy); | ||||||||||||||||||
| } | ||||||||||||||||||
| else { | ||||||||||||||||||
| VkImageCopy imageCopy = {}; | ||||||||||||||||||
| imageCopy.srcSubresource.aspectMask = toAspectFlags(srcTexture->desc.format, srcTexture->desc.flags); | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes the copy size from the footprint, D3D12 uses
srcBoxor the whole subresource when there's no box: