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

Method UpdateSubresource

trinityal/dx12/Tr2TextureALDx12.cpp:1566–1621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1564}
1565
1566ALResult Tr2TextureAL::UpdateSubresource( const Tr2TextureSubresource& region, const void* source, uint32_t pitch, uint32_t depthPitch, Tr2RenderContextAL& renderContext )
1567{
1568 if( !IsValid() )
1569 {
1570 return E_INVALIDCALL;
1571 }
1572 if( !renderContext.IsValid() )
1573 {
1574 return E_INVALIDARG;
1575 }
1576
1577 if( HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE_OFTEN ) )
1578 {
1579 return E_INVALIDCALL;
1580 }
1581 if( !HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE ) && !IsWritable( m_gpuUsage ) )
1582 {
1583 return E_INVALIDCALL;
1584 }
1585
1586 if( !region.IsValidForBitmap( m_desc ) )
1587 {
1588 return E_INVALIDARG;
1589 }
1590 if( !region.IsSingleSubresource() )
1591 {
1592 return E_INVALIDARG;
1593 }
1594
1595 void* dest;
1596 uint32_t destPitch;
1597 FORWARD_HR( MapForWriting( region, dest, destPitch, renderContext ) );
1598
1599 auto clamped = region;
1600 clamped.ClampToTexture( m_desc );
1601
1602 auto bpp = Tr2RenderContextEnum::GetBytesPerPixel( m_desc.GetFormat() );
1603 auto width = clamped.m_box.GetWidth();
1604 width *= bpp;
1605 auto depthSlice = static_cast<const uint8_t*>( source );
1606
1607 for( uint32_t j = clamped.m_box.front; j != clamped.m_box.back; ++j )
1608 {
1609 auto src = depthSlice;
1610 for( uint32_t i = clamped.m_box.top; i != clamped.m_box.bottom; ++i )
1611 {
1612 memcpy( dest, src, width );
1613 dest = static_cast<uint8_t*>( dest ) + destPitch;
1614 src += pitch;
1615 }
1616 depthSlice += depthPitch;
1617 }
1618 UnmapForWriting( renderContext );
1619
1620 return S_OK;
1621}
1622
1623

Callers

nothing calls this directly

Calls 9

IsWritableFunction · 0.85
IsValidForBitmapMethod · 0.80
IsSingleSubresourceMethod · 0.80
ClampToTextureMethod · 0.80
IsValidFunction · 0.70
HasFlagFunction · 0.50
IsValidMethod · 0.45
GetFormatMethod · 0.45
GetWidthMethod · 0.45

Tested by

no test coverage detected