| 1423 | } |
| 1424 | |
| 1425 | void Tr2TextureAL::UnmapForWriting( Tr2RenderContextAL& renderContext ) |
| 1426 | { |
| 1427 | if( m_mappedScratch == m_writeScratches.end() || !renderContext.IsValid() || !m_mappedRegion.IsValid() ) |
| 1428 | { |
| 1429 | return; |
| 1430 | } |
| 1431 | |
| 1432 | uint64_t requiredSize = 0; |
| 1433 | uint32_t pitch = 0; |
| 1434 | GetRegionSize( m_mappedRegion, pitch, requiredSize ); |
| 1435 | |
| 1436 | m_mappedScratch->scratch->Unmap( 0, nullptr ); |
| 1437 | |
| 1438 | auto texture = GetResourceDx12(); |
| 1439 | auto subresource = m_mappedRegion.m_startFace * m_desc.GetTrueMipCount() + m_mappedRegion.m_startMipLevel; |
| 1440 | D3D12_RESOURCE_DESC desc = texture->GetDesc(); |
| 1441 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout; |
| 1442 | layout.Offset = 0; |
| 1443 | if( m_mappedRegion.HasBox() ) |
| 1444 | { |
| 1445 | D3D12_SUBRESOURCE_FOOTPRINT f = { desc.Format, m_mappedRegion.GetWidth(), m_mappedRegion.GetHeight(), m_mappedRegion.GetDepth(), pitch }; |
| 1446 | layout.Footprint = f; |
| 1447 | } |
| 1448 | else |
| 1449 | { |
| 1450 | auto mip = m_mappedRegion.m_startMipLevel; |
| 1451 | D3D12_SUBRESOURCE_FOOTPRINT f = { desc.Format, m_desc.GetMipWidth( mip ), m_desc.GetMipHeight( mip ), m_desc.GetMipDepth( mip ), pitch }; |
| 1452 | layout.Footprint = f; |
| 1453 | } |
| 1454 | D3D12_TEXTURE_COPY_LOCATION Dst = { texture, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, subresource }; |
| 1455 | D3D12_TEXTURE_COPY_LOCATION Src = { m_mappedScratch->scratch, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, layout }; |
| 1456 | |
| 1457 | renderContext.ResourceBarrierDx12( TrinityALImpl::Transition( texture, m_defaultState, D3D12_RESOURCE_STATE_COPY_DEST ) ); |
| 1458 | renderContext.FlushBarriersDx12( texture ); |
| 1459 | |
| 1460 | if( m_mappedRegion.HasBox() ) |
| 1461 | { |
| 1462 | D3D12_BOX box = { 0, 0, 0, m_mappedRegion.m_box.GetWidth(), m_mappedRegion.m_box.GetHeight(), m_mappedRegion.m_box.GetDepth() }; |
| 1463 | renderContext.m_commandList->CopyTextureRegion( |
| 1464 | &Dst, |
| 1465 | m_mappedRegion.m_box.left, |
| 1466 | m_mappedRegion.m_box.top, |
| 1467 | m_mappedRegion.m_box.front, |
| 1468 | &Src, |
| 1469 | &box ); |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1473 | renderContext.m_commandList->CopyTextureRegion( &Dst, 0, 0, 0, &Src, nullptr ); |
| 1474 | } |
| 1475 | |
| 1476 | renderContext.ResourceBarrierDx12( TrinityALImpl::Transition( texture, D3D12_RESOURCE_STATE_COPY_DEST, m_defaultState ) ); |
| 1477 | FlushBarriersMaybe( *this, renderContext ); |
| 1478 | |
| 1479 | m_mappedScratch->frameIndex = m_owner->GetRecordingFrameNumber(); |
| 1480 | |
| 1481 | m_mappedRegion = Tr2TextureSubresource(); |
| 1482 | m_mappedScratch = m_writeScratches.end(); |
nothing calls this directly
no test coverage detected