MCPcopy Create free account
hub / github.com/carbonengine/trinity / MapForReading

Method MapForReading

trinityal/dx12/Tr2TextureALDx12.cpp:1485–1550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1483}
1484
1485ALResult Tr2TextureAL::MapForReading( const Tr2TextureSubresource& region, bool synchronize, const void*& data, uint32_t& pitch, Tr2RenderContextAL& renderContext )
1486{
1487 if( !IsValid() )
1488 {
1489 return E_INVALIDCALL;
1490 }
1491 if( !renderContext.IsValid() )
1492 {
1493 return E_INVALIDARG;
1494 }
1495 if( !HasFlag( m_cpuUsage, Tr2CpuUsage::READ ) )
1496 {
1497 return E_INVALIDCALL;
1498 }
1499
1500 auto texture = GetResourceDx12();
1501
1502 CComPtr<ID3D12Resource> scratch = m_readScratch;
1503 if( !scratch )
1504 {
1505 auto totalSize = GetRequiredIntermediateSize( texture, 0, 1 );
1506 auto scratchHeap = HeapDesc( D3D12_HEAP_TYPE_READBACK );
1507 auto scratchDesc = BufferDesc( totalSize );
1508 CR_RETURN_HR( m_owner->m_device->CreateCommittedResource(
1509 &scratchHeap,
1510 D3D12_HEAP_FLAG_NONE,
1511 &scratchDesc,
1512 D3D12_RESOURCE_STATE_COPY_DEST,
1513 nullptr,
1514 IID_PPV_ARGS( &scratch ) ) );
1515 }
1516
1517 renderContext.ResourceBarrierDx12( Transition( texture, m_defaultState, D3D12_RESOURCE_STATE_COPY_SOURCE ) );
1518 renderContext.FlushBarriersDx12( texture );
1519
1520 auto subresource = region.m_startFace * m_desc.GetTrueMipCount() + region.m_startMipLevel;
1521 D3D12_RESOURCE_DESC desc = texture->GetDesc();
1522 D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout;
1523 m_owner->m_device->GetCopyableFootprints( &desc, subresource, 1, 0, &layout, nullptr, nullptr, nullptr );
1524 layout.Offset = 0;
1525 D3D12_TEXTURE_COPY_LOCATION Src = { texture, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, subresource };
1526 D3D12_TEXTURE_COPY_LOCATION Dst = { scratch, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, layout };
1527
1528 renderContext.m_commandList->CopyTextureRegion( &Dst, 0, 0, 0, &Src, nullptr );
1529
1530 renderContext.ResourceBarrierDx12( Transition( texture, D3D12_RESOURCE_STATE_COPY_SOURCE, m_defaultState ) );
1531 FlushBarriersMaybe( *this, renderContext );
1532
1533 if( synchronize )
1534 {
1535 auto hr = renderContext.FlushAndSyncDx12();
1536 if( FAILED( hr ) )
1537 {
1538 RELEASE_LATER( m_owner, scratch );
1539 scratch = nullptr;
1540 return hr;
1541 }
1542 }

Callers

nothing calls this directly

Calls 13

HeapDescFunction · 0.85
BufferDescFunction · 0.85
TransitionFunction · 0.85
FlushBarriersMaybeFunction · 0.85
ResourceBarrierDx12Method · 0.80
FlushBarriersDx12Method · 0.80
GetTrueMipCountMethod · 0.80
IsValidFunction · 0.70
HasFlagFunction · 0.50
IsValidMethod · 0.45
FlushAndSyncDx12Method · 0.45

Tested by

no test coverage detected