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

Method MapForWriting

trinityal/dx12/Tr2TextureALDx12.cpp:1361–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1359}
1360
1361ALResult Tr2TextureAL::MapForWriting( const Tr2TextureSubresource& region, void*& data, uint32_t& pitch, Tr2RenderContextAL& renderContext )
1362{
1363 if( !IsValid() || !HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE ) )
1364 {
1365 return E_INVALIDCALL;
1366 }
1367 if( !renderContext.IsValid() )
1368 {
1369 return E_INVALIDARG;
1370 }
1371 if( !region.IsValidForBitmap( m_desc ) )
1372 {
1373 return E_INVALIDARG;
1374 }
1375 if( !region.IsSingleSubresource() )
1376 {
1377 return E_INVALIDARG;
1378 }
1379 if( region.HasBox() && Tr2RenderContextEnum::IsCompressedFormat( m_desc.GetFormat() ) )
1380 {
1381 return E_INVALIDARG;
1382 }
1383
1384 uint64_t requiredSize = 0;
1385 uint32_t myPitch = 0;
1386 GetRegionSize( region, myPitch, requiredSize );
1387
1388 auto completed = m_owner->GetRenderedFrameNumber();
1389 m_mappedScratch = m_writeScratches.end();
1390 for( auto it = begin( m_writeScratches ); it != end( m_writeScratches ); ++it )
1391 {
1392 if( completed >= it->frameIndex && requiredSize <= it->size )
1393 {
1394 m_mappedScratch = it;
1395 break;
1396 }
1397 }
1398
1399 if( m_mappedScratch == m_writeScratches.end() )
1400 {
1401 auto scratchHeap = HeapDesc( D3D12_HEAP_TYPE_UPLOAD );
1402 auto scratchDesc = BufferDesc( requiredSize );
1403 WriteScratch scratch;
1404 CR_RETURN_HR( m_owner->m_device->CreateCommittedResource(
1405 &scratchHeap,
1406 D3D12_HEAP_FLAG_NONE,
1407 &scratchDesc,
1408 D3D12_RESOURCE_STATE_GENERIC_READ,
1409 nullptr,
1410 IID_PPV_ARGS( &scratch.scratch ) ) );
1411 scratch.size = requiredSize;
1412 scratch.frameIndex = m_owner->GetRecordingFrameNumber();
1413 m_writeScratches.push_back( scratch );
1414 m_mappedScratch = m_writeScratches.begin() + ( m_writeScratches.size() - 1 );
1415 }
1416
1417 D3D12_RANGE range = { 0, 0 };
1418 CR_RETURN_HR( m_mappedScratch->scratch->Map( 0, &range, &data ) );

Callers

nothing calls this directly

Calls 15

HeapDescFunction · 0.85
BufferDescFunction · 0.85
IsValidForBitmapMethod · 0.80
IsSingleSubresourceMethod · 0.80
HasBoxMethod · 0.80
sizeMethod · 0.80
IsValidFunction · 0.70
HasFlagFunction · 0.50
beginFunction · 0.50
endFunction · 0.50
IsValidMethod · 0.45
GetFormatMethod · 0.45

Tested by

no test coverage detected