diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-01-19 16:34:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-19 16:34:58 -0800 |
| commit | 11d248293f1b56a790faadead1e3d94de81f29a2 (patch) | |
| tree | ad28b0106fcaf98321447e10660435b1f00f7385 /tools/gfx/d3d12 | |
| parent | b40cd149c2038b0a429e46d60ddee5610e08b0ba (diff) | |
Vulkan implementations for copyTexture, copyTextureToBuffer, and textureSubresourceBarrier (#2080)
* Added preliminary implementations for Vulkan's copyTexture, copyTextureToBuffer, and textureSubresourceBarrier
* Simple copyTexture test working
* Expanded test to use textureSubresourceBarrier() to change resource states before copying out to a buffer; Changed copyTextureToBuffer() to assert that only a single mip level is being copied; Test passes on Vulkan only
* Fixed an incorrect loop condition in D3D12's textureSubresourceBarrier and changed the size of the results buffer to pre-account for padding; Test runs in D3D12 but does not pass
* D3D12 test working, compareComputeResult for buffers now takes an offset into the results
* Refactored texture copying tests
* Second test written but does not copy correctly
* Fixed texture creation in D3D12 to take into account the subresource index when copying texture data so it actually copies all slices instead of just the ones in the first array layer; Second test working on both D3D12 and Vulkan
* Added a note for future tests to be added for texture copying; Fixed build errors in CUDA
Co-authored-by: Yong He <yhe@nvidia.com>
Co-authored-by: Theresa Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools/gfx/d3d12')
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 138 |
1 files changed, 70 insertions, 68 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 8005f6d15..634fca03e 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -3954,9 +3954,11 @@ public: } virtual SLANG_NO_THROW void SLANG_MCALL copyTexture( ITextureResource* dst, + ResourceState dstState, SubresourceRange dstSubresource, ITextureResource::Offset3D dstOffset, ITextureResource* src, + ResourceState srcState, SubresourceRange srcSubresource, ITextureResource::Offset3D srcOffset, ITextureResource::Size extent) override @@ -4247,10 +4249,13 @@ public: size_t dstOffset, size_t dstSize, ITextureResource* src, + ResourceState srcState, SubresourceRange srcSubresource, ITextureResource::Offset3D srcOffset, ITextureResource::Size extent) override { + assert(srcSubresource.mipLevelCount <= 1); + auto srcTexture = static_cast<TextureResourceImpl*>(src); auto dstBuffer = static_cast<BufferResourceImpl*>(dst); auto baseSubresourceIndex = D3DUtil::getSubresourceIndex( @@ -4269,74 +4274,71 @@ public: for (uint32_t layer = 0; layer < srcSubresource.layerCount; layer++) { - for (uint32_t mipId = 0; mipId < srcSubresource.mipLevelCount; mipId++) + // Get the footprint + D3D12_RESOURCE_DESC texDesc = + srcTexture->m_resource.getResource()->GetDesc(); + + D3D12_TEXTURE_COPY_LOCATION dstRegion = {}; + dstRegion.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + dstRegion.pResource = dstBuffer->m_resource.getResource(); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT& footprint = dstRegion.PlacedFootprint; + + D3D12_TEXTURE_COPY_LOCATION srcRegion = {}; + srcRegion.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + srcRegion.SubresourceIndex = D3DUtil::getSubresourceIndex( + srcSubresource.mipLevel, + layer + srcSubresource.baseArrayLayer, + 0, + srcTexture->getDesc()->numMipLevels, + srcTexture->getDesc()->arraySize); + srcRegion.pResource = srcTexture->m_resource.getResource(); + + footprint.Offset = dstOffset; + footprint.Footprint.Format = texDesc.Format; + uint32_t mipLevel = srcSubresource.mipLevel; + if (extent.width != 0xFFFFFFFF) { - // Get the footprint - D3D12_RESOURCE_DESC texDesc = - srcTexture->m_resource.getResource()->GetDesc(); - - D3D12_TEXTURE_COPY_LOCATION dstRegion = {}; - dstRegion.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; - dstRegion.pResource = dstBuffer->m_resource.getResource(); - D3D12_PLACED_SUBRESOURCE_FOOTPRINT& footprint = dstRegion.PlacedFootprint; - - D3D12_TEXTURE_COPY_LOCATION srcRegion = {}; - srcRegion.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; - srcRegion.SubresourceIndex = D3DUtil::getSubresourceIndex( - mipId + srcSubresource.mipLevel, - layer + srcSubresource.baseArrayLayer, - 0, - srcTexture->getDesc()->numMipLevels, - srcTexture->getDesc()->arraySize); - srcRegion.pResource = srcTexture->m_resource.getResource(); - - footprint.Offset = 0; - footprint.Footprint.Format = texDesc.Format; - uint32_t mipLevel = mipId + srcSubresource.mipLevel; - if (extent.width != 0xFFFFFFFF) - { - footprint.Footprint.Width = extent.width; - } - else - { - footprint.Footprint.Width = - Math::Max(1, (textureSize.width >> mipLevel)) - srcOffset.x; - } - if (extent.height != 0xFFFFFFFF) - { - footprint.Footprint.Height = extent.height; - } - else - { - footprint.Footprint.Height = - Math::Max(1, (textureSize.height >> mipLevel)) - srcOffset.y; - } - if (extent.depth != 0xFFFFFFFF) - { - footprint.Footprint.Depth = extent.depth; - } - else - { - footprint.Footprint.Depth = - Math::Max(1, (textureSize.depth >> mipLevel)) - srcOffset.z; - } - footprint.Footprint.RowPitch = (UINT)D3DUtil::calcAligned( - footprint.Footprint.Width * (UInt)formatInfo.blockSizeInBytes, - (uint32_t)D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); - - auto bufferSize = footprint.Footprint.RowPitch * - footprint.Footprint.Height * footprint.Footprint.Depth; - - D3D12_BOX srcBox = {}; - srcBox.left = srcOffset.x; - srcBox.top = srcOffset.y; - srcBox.front = srcOffset.z; - srcBox.right = srcOffset.x + extent.width; - srcBox.bottom = srcOffset.y + extent.height; - srcBox.back = srcOffset.z + extent.depth; - m_commandBuffer->m_cmdList->CopyTextureRegion( - &dstRegion, (UINT)dstOffset, 0, 0, &srcRegion, &srcBox); + footprint.Footprint.Width = extent.width; + } + else + { + footprint.Footprint.Width = + Math::Max(1, (textureSize.width >> mipLevel)) - srcOffset.x; + } + if (extent.height != 0xFFFFFFFF) + { + footprint.Footprint.Height = extent.height; + } + else + { + footprint.Footprint.Height = + Math::Max(1, (textureSize.height >> mipLevel)) - srcOffset.y; + } + if (extent.depth != 0xFFFFFFFF) + { + footprint.Footprint.Depth = extent.depth; } + else + { + footprint.Footprint.Depth = + Math::Max(1, (textureSize.depth >> mipLevel)) - srcOffset.z; + } + footprint.Footprint.RowPitch = (UINT)D3DUtil::calcAligned( + footprint.Footprint.Width * (UInt)formatInfo.blockSizeInBytes, + (uint32_t)D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); + + auto bufferSize = footprint.Footprint.RowPitch * + footprint.Footprint.Height * footprint.Footprint.Depth; + + D3D12_BOX srcBox = {}; + srcBox.left = srcOffset.x; + srcBox.top = srcOffset.y; + srcBox.front = srcOffset.z; + srcBox.right = srcOffset.x + extent.width; + srcBox.bottom = srcOffset.y + extent.height; + srcBox.back = srcOffset.z + extent.depth; + m_commandBuffer->m_cmdList->CopyTextureRegion( + &dstRegion, 0, 0, 0, &srcRegion, &srcBox); } } @@ -4377,7 +4379,7 @@ public: auto aspect = Math::getLowestBit((int32_t)aspectMask); aspectMask &= ~aspect; auto planeIndex = D3DUtil::getPlaneSlice(d3dFormat, (TextureAspect)aspect); - for (uint32_t layer = 0; layer < subresourceRange.baseArrayLayer; layer++) + for (uint32_t layer = 0; layer < subresourceRange.layerCount; layer++) { for (uint32_t mip = 0; mip < subresourceRange.mipLevelCount; mip++) { @@ -6046,7 +6048,7 @@ Result D3D12Device::createTextureResource(const ITextureResource::Desc& descIn, for (int j = 0; j < numMipMaps; ++j) { - auto srcSubresource = initData[j]; + auto srcSubresource = initData[subResourceIndex + j]; const D3D12_PLACED_SUBRESOURCE_FOOTPRINT& layout = layouts[j]; const D3D12_SUBRESOURCE_FOOTPRINT& footprint = layout.Footprint; |
