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

Function UpdateSubresources

trinityal/dx12/Utilities.cpp:1417–1472  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ All arrays must be populated (e.g. by calling GetCopyableFootprints)

Source from the content-addressed store, hash-verified

1415//------------------------------------------------------------------------------------------------
1416// All arrays must be populated (e.g. by calling GetCopyableFootprints)
1417UINT64 UpdateSubresources(
1418 _In_ ID3D12GraphicsCommandList* pCmdList,
1419 _In_ ID3D12Resource* pDestinationResource,
1420 _In_ ID3D12Resource* pIntermediate,
1421 _In_range_( 0, D3D12_REQ_SUBRESOURCES ) UINT FirstSubresource,
1422 _In_range_( 0, D3D12_REQ_SUBRESOURCES - FirstSubresource ) UINT NumSubresources,
1423 UINT64 RequiredSize,
1424 _In_reads_( NumSubresources ) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
1425 _In_reads_( NumSubresources ) const UINT* pNumRows,
1426 _In_reads_( NumSubresources ) const UINT64* pRowSizesInBytes,
1427 _In_reads_( NumSubresources ) const D3D12_SUBRESOURCE_DATA* pSrcData )
1428{
1429 // Minor validation
1430 D3D12_RESOURCE_DESC IntermediateDesc = pIntermediate->GetDesc();
1431 D3D12_RESOURCE_DESC DestinationDesc = pDestinationResource->GetDesc();
1432 if( IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
1433 IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
1434 RequiredSize > (SIZE_T)-1 ||
1435 ( DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
1436 ( FirstSubresource != 0 || NumSubresources != 1 ) ) )
1437 {
1438 return 0;
1439 }
1440
1441 BYTE* pData;
1442 HRESULT hr = pIntermediate->Map( 0, NULL, reinterpret_cast<void**>( &pData ) );
1443 if( FAILED( hr ) )
1444 {
1445 return 0;
1446 }
1447
1448 for( UINT i = 0; i < NumSubresources; ++i )
1449 {
1450 if( pRowSizesInBytes[i] > (SIZE_T)-1 )
1451 return 0;
1452 D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, pLayouts[i].Footprint.RowPitch * pNumRows[i] };
1453 MemcpySubresource( &DestData, &pSrcData[i], (SIZE_T)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth );
1454 }
1455 pIntermediate->Unmap( 0, NULL );
1456
1457 if( DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER )
1458 {
1459 pCmdList->CopyBufferRegion(
1460 pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width );
1461 }
1462 else
1463 {
1464 for( UINT i = 0; i < NumSubresources; ++i )
1465 {
1466 D3D12_TEXTURE_COPY_LOCATION Dst = { pDestinationResource, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, i + FirstSubresource };
1467 D3D12_TEXTURE_COPY_LOCATION Src = { pIntermediate, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, pLayouts[i] };
1468 pCmdList->CopyTextureRegion( &Dst, 0, 0, 0, &Src, nullptr );
1469 }
1470 }
1471 return RequiredSize;
1472}
1473
1474//------------------------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 5

MemcpySubresourceFunction · 0.85
GetDeviceMethod · 0.80
ReleaseMethod · 0.80
MapMethod · 0.45
UnmapMethod · 0.45

Tested by

no test coverage detected