@@ -156,9 +156,16 @@ static DXResourceKind getDXKind(offloadtest::ResourceKind RK) {
156156 llvm_unreachable (" All cases handled" );
157157}
158158
159- static D3D12_RESOURCE_DESC getResourceDescription (const Resource &R) {
159+ static llvm::Expected<D3D12_RESOURCE_DESC>
160+ getResourceDescription (const Resource &R) {
160161 const D3D12_RESOURCE_DIMENSION Dimension = getDXDimension (R.Kind );
161162 const offloadtest::Buffer &B = *R.BufferPtr ;
163+
164+ if (B.OutputProps .MipLevels != 1 )
165+ return llvm::createStringError (std::errc::not_supported,
166+ " Multiple mip levels are not yet supported "
167+ " for DirectX textures." );
168+
162169 const DXGI_FORMAT Format =
163170 R.isTexture () ? getDXFormat (B.Format , B.Channels ) : DXGI_FORMAT_UNKNOWN;
164171 const uint32_t Width =
@@ -611,7 +618,10 @@ class DXDevice : public offloadtest::Device {
611618 llvm::Expected<ResourceBundle> createSRV (Resource &R, InvocationState &IS) {
612619 ResourceBundle Bundle;
613620
614- const D3D12_RESOURCE_DESC ResDesc = getResourceDescription (R);
621+ auto ResDescOrErr = getResourceDescription (R);
622+ if (!ResDescOrErr)
623+ return ResDescOrErr.takeError ();
624+ const D3D12_RESOURCE_DESC ResDesc = *ResDescOrErr;
615625 const D3D12_HEAP_PROPERTIES UploadHeapProp =
616626 CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
617627 const D3D12_RESOURCE_DESC UploadResDesc =
@@ -708,7 +718,10 @@ class DXDevice : public offloadtest::Device {
708718 ResourceBundle Bundle;
709719 const uint32_t BufferSize = getUAVBufferSize (R);
710720
711- const D3D12_RESOURCE_DESC ResDesc = getResourceDescription (R);
721+ auto ResDescOrErr = getResourceDescription (R);
722+ if (!ResDescOrErr)
723+ return ResDescOrErr.takeError ();
724+ const D3D12_RESOURCE_DESC ResDesc = *ResDescOrErr;
712725
713726 const D3D12_HEAP_PROPERTIES ReadBackHeapProp =
714727 CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_READBACK);
@@ -1314,6 +1327,11 @@ class DXDevice : public offloadtest::Device {
13141327 std::errc::invalid_argument,
13151328 " No render target bound for graphics pipeline." );
13161329 const Buffer &OutBuf = *P.Bindings .RTargetBufferPtr ;
1330+ if (OutBuf.OutputProps .MipLevels != 1 )
1331+ return llvm::createStringError (
1332+ std::errc::not_supported,
1333+ " Multiple mip levels are not yet supported for DirectX render "
1334+ " targets." );
13171335 D3D12_RESOURCE_DESC Desc = {};
13181336 Desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
13191337 Desc.Width = OutBuf.OutputProps .Width ;
@@ -1465,13 +1483,13 @@ class DXDevice : public offloadtest::Device {
14651483 IS.RTVHeap ->GetCPUDescriptorHandleForHeapStart ();
14661484 Device->CreateRenderTargetView (IS.RT .Get (), nullptr , RTVHandle);
14671485
1486+ IS.CmdList ->SetGraphicsRootSignature (IS.RootSig .Get ());
14681487 if (IS.DescHeap ) {
14691488 ID3D12DescriptorHeap *const Heaps[] = {IS.DescHeap .Get ()};
14701489 IS.CmdList ->SetDescriptorHeaps (1 , Heaps);
14711490 IS.CmdList ->SetGraphicsRootDescriptorTable (
14721491 0 , IS.DescHeap ->GetGPUDescriptorHandleForHeapStart ());
14731492 }
1474- IS.CmdList ->SetGraphicsRootSignature (IS.RootSig .Get ());
14751493 IS.CmdList ->SetPipelineState (IS.PSO .Get ());
14761494
14771495 IS.CmdList ->OMSetRenderTargets (1 , &RTVHandle, false , nullptr );
@@ -1509,6 +1527,43 @@ class DXDevice : public offloadtest::Device {
15091527 const CD3DX12_TEXTURE_COPY_LOCATION SrcLoc (IS.RT .Get (), 0 );
15101528
15111529 IS.CmdList ->CopyTextureRegion (&DstLoc, 0 , 0 , 0 , &SrcLoc, nullptr );
1530+
1531+ auto CopyBackResource = [&IS, this ](ResourcePair &R) {
1532+ if (R.first ->isTexture ()) {
1533+ const offloadtest::Buffer &B = *R.first ->BufferPtr ;
1534+ const D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint{
1535+ 0 , CD3DX12_SUBRESOURCE_FOOTPRINT (
1536+ getDXFormat (B.Format , B.Channels ), B.OutputProps .Width ,
1537+ B.OutputProps .Height , 1 ,
1538+ B.OutputProps .Width * B.getElementSize ())};
1539+ for (const ResourceSet &RS : R.second ) {
1540+ if (RS.Readback == nullptr )
1541+ continue ;
1542+ addReadbackBeginBarrier (IS, RS.Buffer );
1543+ const CD3DX12_TEXTURE_COPY_LOCATION DstLoc (RS.Readback .Get (),
1544+ Footprint);
1545+ const CD3DX12_TEXTURE_COPY_LOCATION SrcLoc (RS.Buffer .Get (), 0 );
1546+ IS.CmdList ->CopyTextureRegion (&DstLoc, 0 , 0 , 0 , &SrcLoc, nullptr );
1547+ addReadbackEndBarrier (IS, RS.Buffer );
1548+ }
1549+ return ;
1550+ }
1551+ for (const ResourceSet &RS : R.second ) {
1552+ if (RS.Readback == nullptr )
1553+ continue ;
1554+ addReadbackBeginBarrier (IS, RS.Buffer );
1555+ IS.CmdList ->CopyResource (RS.Readback .Get (), RS.Buffer .Get ());
1556+ addReadbackEndBarrier (IS, RS.Buffer );
1557+ }
1558+ };
1559+
1560+ for (auto &Table : IS.DescTables )
1561+ for (auto &R : Table.Resources )
1562+ CopyBackResource (R);
1563+
1564+ for (auto &R : IS.RootResources )
1565+ CopyBackResource (R);
1566+
15121567 return llvm::Error::success ();
15131568 }
15141569
0 commit comments