@@ -1581,18 +1581,14 @@ class DXDevice : public offloadtest::Device {
15811581 if (!IS.RTReadback )
15821582 return llvm::Error::success ();
15831583
1584- // Map readback and copy into host buffer, accounting for row pitch and
1585- // flipping vertical orientation. DirectX render target origin is top-left,
1586- // while our image writer expects bottom-left.
1587- const CPUBuffer &B = *P.Bindings .RTargetBufferPtr ;
15881584 void *Mapped = nullptr ;
15891585 auto &Readback = llvm::cast<DXBuffer>(*IS.RTReadback );
15901586 if (auto Err = HR::toError (Readback.Buffer ->Map (0 , nullptr , &Mapped),
15911587 " Failed to map render target readback" ))
15921588 return Err;
15931589
1594- // Query the copy footprint to get the actual padded row pitch used by the
1595- // copy operation.
1590+ // Query the copy footprint to get the actual padded row pitch used by
1591+ // the copy operation (D3D12 requires 256-byte aligned rows) .
15961592 auto &RT = llvm::cast<DXTexture>(*IS.RT );
15971593 const D3D12_RESOURCE_DESC RTDesc = RT.Resource ->GetDesc ();
15981594 D3D12_PLACED_SUBRESOURCE_FOOTPRINT Placed = {};
@@ -1602,23 +1598,8 @@ class DXDevice : public offloadtest::Device {
16021598 Device->GetCopyableFootprints (&RTDesc, 0u , 1u , 0u , &Placed, &NumRows,
16031599 &RowSizeInBytes, &TotalBytes);
16041600
1605- const uint32_t RowPitch = Placed.Footprint .RowPitch ;
1606- const uint32_t RowBytes =
1607- static_cast <uint32_t >(B.getElementSize () * B.OutputProps .Width );
1608- const uint32_t Height = static_cast <uint32_t >(B.OutputProps .Height );
1609-
1610- const uint8_t *SrcBase = reinterpret_cast <uint8_t *>(Mapped);
1611- uint8_t *DstBase =
1612- reinterpret_cast <uint8_t *>(P.Bindings .RTargetBufferPtr ->Data [0 ].get ());
1613-
1614- // Copy rows in reverse order.
1615- for (uint32_t Y = 0 ; Y < Height; ++Y) {
1616- const uint8_t *SrcRow = SrcBase + static_cast <size_t >(Y) * RowPitch;
1617- uint8_t *DstRow =
1618- DstBase + static_cast <size_t >(Height - 1 - Y) * RowBytes;
1619- memcpy (DstRow, SrcRow, RowBytes);
1620- }
1621-
1601+ P.Bindings .RTargetBufferPtr ->copyFromTexture (Mapped,
1602+ Placed.Footprint .RowPitch );
16221603 Readback.Buffer ->Unmap (0 , nullptr );
16231604 return llvm::Error::success ();
16241605 }
0 commit comments