@@ -891,15 +891,20 @@ class DXComputeEncoder : public offloadtest::ComputeEncoder {
891891 D3D12_RESOURCE_STATE_COPY_DEST );
892892 CB .flushBarrier ();
893893
894- const uint32_t ElementSize = getFormatSizeInBytes (DXDst.Desc .Fmt );
895- const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
896- 0 ,
897- CD3DX12_SUBRESOURCE_FOOTPRINT (
898- getDXGIFormat (DXDst.Desc .Fmt ), DXDst.Desc .Width , DXDst.Desc .Height ,
899- 1 , getAlignedTexturePitch (DXDst.Desc .Width , ElementSize))};
900- const CD3DX12_TEXTURE_COPY_LOCATION DstLoc (DXDst.Resource .Get (), 0 );
901- const CD3DX12_TEXTURE_COPY_LOCATION SrcLoc (DXSrc.Buffer .Get (), Footprint);
902- CB .CmdList ->CopyTextureRegion (&DstLoc, 0 , 0 , 0 , &SrcLoc, nullptr );
894+ const D3D12_RESOURCE_DESC TexDesc = DXDst.Resource ->GetDesc ();
895+ const uint32_t NumSubresources = TexDesc.MipLevels ;
896+ llvm::SmallVector<D3D12_PLACED_SUBRESOURCE_FOOTPRINT > Layouts (
897+ NumSubresources);
898+ ComPtr<ID3D12DeviceX> Device;
899+ DXDst.Resource ->GetDevice (IID_PPV_ARGS (&Device));
900+ Device->GetCopyableFootprints (&TexDesc, 0 , NumSubresources, 0 ,
901+ Layouts.data (), nullptr , nullptr , nullptr );
902+ for (uint32_t Sub = 0 ; Sub < NumSubresources; ++Sub) {
903+ const CD3DX12_TEXTURE_COPY_LOCATION DstLoc (DXDst.Resource .Get (), Sub);
904+ const CD3DX12_TEXTURE_COPY_LOCATION SrcLoc (DXSrc.Buffer .Get (),
905+ Layouts[Sub]);
906+ CB .CmdList ->CopyTextureRegion (&DstLoc, 0 , 0 , 0 , &SrcLoc, nullptr );
907+ }
903908
904909 if (DXSrc.PreferredState != D3D12_RESOURCE_STATE_COPY_SOURCE )
905910 CB .addResourceTransition (DXSrc.Buffer .Get (),
@@ -2300,6 +2305,43 @@ class DXDevice : public offloadtest::Device {
23002305 return getAlignedTexturePitch (Desc.Width , getFormatSizeInBytes (Desc.Fmt ));
23012306 }
23022307
2308+ TextureUploadLayout
2309+ getTextureUploadLayout (const TextureCreateDesc &Desc) const override {
2310+ // Only the fields GetCopyableFootprints consults are needed here; layout,
2311+ // flags, and clear value do not affect the copyable footprint.
2312+ D3D12_RESOURCE_DESC TexDesc = {};
2313+ TexDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D ;
2314+ TexDesc.Width = Desc.Width ;
2315+ TexDesc.Height = Desc.Height ;
2316+ TexDesc.DepthOrArraySize = 1 ;
2317+ TexDesc.MipLevels = static_cast <UINT16 >(Desc.MipLevels );
2318+ TexDesc.Format = getDXGIFormat (Desc.Fmt );
2319+ TexDesc.SampleDesc .Count = 1 ;
2320+
2321+ const uint32_t NumSubresources = Desc.MipLevels ;
2322+ llvm::SmallVector<D3D12_PLACED_SUBRESOURCE_FOOTPRINT > Footprints (
2323+ NumSubresources);
2324+ llvm::SmallVector<UINT > NumRows (NumSubresources);
2325+ llvm::SmallVector<UINT64 > RowSizes (NumSubresources);
2326+ UINT64 TotalBytes = 0 ;
2327+ Device->GetCopyableFootprints (&TexDesc, 0 , NumSubresources, 0 ,
2328+ Footprints.data (), NumRows.data (),
2329+ RowSizes.data (), &TotalBytes);
2330+
2331+ TextureUploadLayout Layout;
2332+ Layout.TotalSizeInBytes = TotalBytes;
2333+ Layout.Subresources .reserve (NumSubresources);
2334+ for (uint32_t I = 0 ; I < NumSubresources; ++I) {
2335+ SubresourceFootprint Sub;
2336+ Sub.Offset = Footprints[I].Offset ;
2337+ Sub.RowPitchInBytes = Footprints[I].Footprint .RowPitch ;
2338+ Sub.RowSizeInBytes = static_cast <uint32_t >(RowSizes[I]);
2339+ Sub.NumRows = NumRows[I];
2340+ Layout.Subresources .push_back (Sub);
2341+ }
2342+ return Layout;
2343+ }
2344+
23032345 static llvm::Expected<std::unique_ptr<offloadtest::Device>>
23042346 create (ComPtr<IDXCoreAdapter> Adapter, const DeviceConfig &Config) {
23052347 ComPtr<ID3D12DeviceX> Device;
0 commit comments