Move T2B copy helpers for D3D12 backend to UtilsD3D12.h|cpp
Its counterpart functions (B2T copy helpers) are already at UtilsD3D12. BUG: dawn:547 Change-Id: Ib9b9216e0b182429ab9bd9aa10241d7ca6cdee5b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46420 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
parent
79c9d125f2
commit
3db31ef757
|
@ -85,80 +85,6 @@ namespace dawn_native { namespace d3d12 {
|
|||
copySize.depthOrArrayLayers == srcSize.depthOrArrayLayers;
|
||||
}
|
||||
|
||||
void RecordCopyTextureToBufferFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const Texture2DCopySplit& baseCopySplit,
|
||||
Buffer* buffer,
|
||||
uint64_t baseOffset,
|
||||
uint64_t bufferBytesPerRow,
|
||||
Texture* texture,
|
||||
uint32_t textureMiplevel,
|
||||
uint32_t textureSlice,
|
||||
Aspect aspect) {
|
||||
const D3D12_TEXTURE_COPY_LOCATION textureLocation =
|
||||
ComputeTextureCopyLocationForTexture(texture, textureMiplevel, textureSlice,
|
||||
aspect);
|
||||
|
||||
const uint64_t offset = baseCopySplit.offset + baseOffset;
|
||||
|
||||
for (uint32_t i = 0; i < baseCopySplit.count; ++i) {
|
||||
const Texture2DCopySplit::CopyInfo& info = baseCopySplit.copies[i];
|
||||
|
||||
// TODO(jiawei.shao@intel.com): pre-compute bufferLocation and sourceRegion as
|
||||
// members in Texture2DCopySplit::CopyInfo.
|
||||
const D3D12_TEXTURE_COPY_LOCATION bufferLocation =
|
||||
ComputeBufferLocationForCopyTextureRegion(texture, buffer->GetD3D12Resource(),
|
||||
info.bufferSize, offset,
|
||||
bufferBytesPerRow, aspect);
|
||||
const D3D12_BOX sourceRegion =
|
||||
ComputeD3D12BoxFromOffsetAndSize(info.textureOffset, info.copySize);
|
||||
|
||||
commandList->CopyTextureRegion(&bufferLocation, info.bufferOffset.x,
|
||||
info.bufferOffset.y, info.bufferOffset.z,
|
||||
&textureLocation, &sourceRegion);
|
||||
}
|
||||
}
|
||||
|
||||
void CopyTextureToBufferWithCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const TextureCopy& textureCopy,
|
||||
const BufferCopy& bufferCopy,
|
||||
Texture* texture,
|
||||
Buffer* buffer,
|
||||
const Extent3D& copySize) {
|
||||
const TexelBlockInfo& blockInfo =
|
||||
texture->GetFormat().GetAspectInfo(textureCopy.aspect).block;
|
||||
|
||||
// See comments around ComputeTextureCopySplits() for more details.
|
||||
const TextureCopySplits copySplits =
|
||||
ComputeTextureCopySplits(textureCopy.origin, copySize, blockInfo, bufferCopy.offset,
|
||||
bufferCopy.bytesPerRow, bufferCopy.rowsPerImage);
|
||||
|
||||
const uint64_t bytesPerSlice = bufferCopy.bytesPerRow * bufferCopy.rowsPerImage;
|
||||
|
||||
// copySplits.copies2D[1] is always calculated for the second copy slice with
|
||||
// extra "bytesPerSlice" copy offset compared with the first copy slice. So
|
||||
// here we use an array bufferOffsetsForNextSlice to record the extra offsets
|
||||
// for each copy slice: bufferOffsetsForNextSlice[0] is the extra offset for
|
||||
// the next copy slice that uses copySplits.copies2D[0], and
|
||||
// bufferOffsetsForNextSlice[1] is the extra offset for the next copy slice
|
||||
// that uses copySplits.copies2D[1].
|
||||
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySplits>
|
||||
bufferOffsetsForNextSlice = {{0u, 0u}};
|
||||
for (uint32_t copySlice = 0; copySlice < copySize.depthOrArrayLayers; ++copySlice) {
|
||||
const uint32_t splitIndex = copySlice % copySplits.copies2D.size();
|
||||
|
||||
const Texture2DCopySplit& copySplitPerLayerBase = copySplits.copies2D[splitIndex];
|
||||
const uint64_t bufferOffsetForNextSlice = bufferOffsetsForNextSlice[splitIndex];
|
||||
const uint32_t copyTextureLayer = copySlice + textureCopy.origin.z;
|
||||
|
||||
RecordCopyTextureToBufferFromTextureCopySplit(
|
||||
commandList, copySplitPerLayerBase, buffer, bufferOffsetForNextSlice,
|
||||
bufferCopy.bytesPerRow, texture, textureCopy.mipLevel, copyTextureLayer,
|
||||
textureCopy.aspect);
|
||||
|
||||
bufferOffsetsForNextSlice[splitIndex] += bytesPerSlice * copySplits.copies2D.size();
|
||||
}
|
||||
}
|
||||
|
||||
void RecordWriteTimestampCmd(ID3D12GraphicsCommandList* commandList,
|
||||
WriteTimestampCmd* cmd) {
|
||||
QuerySet* querySet = ToBackend(cmd->querySet.Get());
|
||||
|
|
|
@ -217,4 +217,77 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
void RecordCopyTextureToBufferFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const Texture2DCopySplit& baseCopySplit,
|
||||
Buffer* buffer,
|
||||
uint64_t baseOffset,
|
||||
uint64_t bufferBytesPerRow,
|
||||
Texture* texture,
|
||||
uint32_t textureMiplevel,
|
||||
uint32_t textureSlice,
|
||||
Aspect aspect) {
|
||||
const D3D12_TEXTURE_COPY_LOCATION textureLocation =
|
||||
ComputeTextureCopyLocationForTexture(texture, textureMiplevel, textureSlice, aspect);
|
||||
|
||||
const uint64_t offset = baseCopySplit.offset + baseOffset;
|
||||
|
||||
for (uint32_t i = 0; i < baseCopySplit.count; ++i) {
|
||||
const Texture2DCopySplit::CopyInfo& info = baseCopySplit.copies[i];
|
||||
|
||||
// TODO(jiawei.shao@intel.com): pre-compute bufferLocation and sourceRegion as
|
||||
// members in Texture2DCopySplit::CopyInfo.
|
||||
const D3D12_TEXTURE_COPY_LOCATION bufferLocation =
|
||||
ComputeBufferLocationForCopyTextureRegion(texture, buffer->GetD3D12Resource(),
|
||||
info.bufferSize, offset,
|
||||
bufferBytesPerRow, aspect);
|
||||
const D3D12_BOX sourceRegion =
|
||||
ComputeD3D12BoxFromOffsetAndSize(info.textureOffset, info.copySize);
|
||||
|
||||
commandList->CopyTextureRegion(&bufferLocation, info.bufferOffset.x,
|
||||
info.bufferOffset.y, info.bufferOffset.z,
|
||||
&textureLocation, &sourceRegion);
|
||||
}
|
||||
}
|
||||
|
||||
void CopyTextureToBufferWithCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const TextureCopy& textureCopy,
|
||||
const BufferCopy& bufferCopy,
|
||||
Texture* texture,
|
||||
Buffer* buffer,
|
||||
const Extent3D& copySize) {
|
||||
const TexelBlockInfo& blockInfo =
|
||||
texture->GetFormat().GetAspectInfo(textureCopy.aspect).block;
|
||||
|
||||
// See comments around ComputeTextureCopySplits() for more details.
|
||||
const TextureCopySplits copySplits =
|
||||
ComputeTextureCopySplits(textureCopy.origin, copySize, blockInfo, bufferCopy.offset,
|
||||
bufferCopy.bytesPerRow, bufferCopy.rowsPerImage);
|
||||
|
||||
const uint64_t bytesPerSlice = bufferCopy.bytesPerRow * bufferCopy.rowsPerImage;
|
||||
|
||||
// copySplits.copies2D[1] is always calculated for the second copy slice with
|
||||
// extra "bytesPerSlice" copy offset compared with the first copy slice. So
|
||||
// here we use an array bufferOffsetsForNextSlice to record the extra offsets
|
||||
// for each copy slice: bufferOffsetsForNextSlice[0] is the extra offset for
|
||||
// the next copy slice that uses copySplits.copies2D[0], and
|
||||
// bufferOffsetsForNextSlice[1] is the extra offset for the next copy slice
|
||||
// that uses copySplits.copies2D[1].
|
||||
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySplits> bufferOffsetsForNextSlice = {
|
||||
{0u, 0u}};
|
||||
for (uint32_t copySlice = 0; copySlice < copySize.depthOrArrayLayers; ++copySlice) {
|
||||
const uint32_t splitIndex = copySlice % copySplits.copies2D.size();
|
||||
|
||||
const Texture2DCopySplit& copySplitPerLayerBase = copySplits.copies2D[splitIndex];
|
||||
const uint64_t bufferOffsetForNextSlice = bufferOffsetsForNextSlice[splitIndex];
|
||||
const uint32_t copyTextureLayer = copySlice + textureCopy.origin.z;
|
||||
|
||||
RecordCopyTextureToBufferFromTextureCopySplit(
|
||||
commandList, copySplitPerLayerBase, buffer, bufferOffsetForNextSlice,
|
||||
bufferCopy.bytesPerRow, texture, textureCopy.mipLevel, copyTextureLayer,
|
||||
textureCopy.aspect);
|
||||
|
||||
bufferOffsetsForNextSlice[splitIndex] += bytesPerSlice * copySplits.copies2D.size();
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::d3d12
|
||||
|
|
|
@ -64,6 +64,23 @@ namespace dawn_native { namespace d3d12 {
|
|||
Texture* texture,
|
||||
Aspect aspect);
|
||||
|
||||
void RecordCopyTextureToBufferFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const Texture2DCopySplit& baseCopySplit,
|
||||
Buffer* buffer,
|
||||
uint64_t baseOffset,
|
||||
uint64_t bufferBytesPerRow,
|
||||
Texture* texture,
|
||||
uint32_t textureMiplevel,
|
||||
uint32_t textureSlice,
|
||||
Aspect aspect);
|
||||
|
||||
void CopyTextureToBufferWithCopySplit(ID3D12GraphicsCommandList* commandList,
|
||||
const TextureCopy& textureCopy,
|
||||
const BufferCopy& bufferCopy,
|
||||
Texture* texture,
|
||||
Buffer* buffer,
|
||||
const Extent3D& copySize);
|
||||
|
||||
}} // namespace dawn_native::d3d12
|
||||
|
||||
#endif // DAWNNATIVE_D3D12_UTILSD3D12_H_
|
||||
|
|
Loading…
Reference in New Issue