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

Method MapForWriting

trinityal/dx11/Tr2BufferALDx11.cpp:321–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321ALResult Tr2BufferAL::MapForWriting( void*& data, Tr2RenderContextAL& renderContext )
322{
323 data = nullptr;
324 if( !renderContext.IsValid() || !IsValid() )
325 {
326 return E_INVALIDCALL;
327 }
328
329 if( HasFlag( m_desc.cpuUsage, Tr2CpuUsage::WRITE_OFTEN ) )
330 {
331 D3D11_MAPPED_SUBRESOURCE ms = { nullptr, 0, 0 };
332 auto mapType = HasFlag( m_desc.cpuUsage, Tr2CpuUsage::NON_SYNCRONIZED_WRITE ) ? D3D11_MAP_WRITE_NO_OVERWRITE : D3D11_MAP_WRITE_DISCARD;
333 auto hr = renderContext.m_context->Map( m_buffer, 0, mapType, 0, &ms );
334 if( FAILED( hr ) )
335 {
336 return hr;
337 }
338 if( !ms.pData )
339 {
340 return E_FAIL;
341 }
342#if TRINITY_AL_GUARD_LOCKS
343 if( noSyncronization )
344 {
345 data = ms.pData;
346 }
347 else
348 {
349 m_lockGuard.Lock( m_desc.count * m_desc.stride, ms.pData );
350 data = m_lockGuard.GetMemory();
351 }
352#else
353 data = ms.pData;
354#endif
355 return hr;
356 }
357 else if( HasFlag( m_desc.cpuUsage, Tr2CpuUsage::WRITE ) )
358 {
359 if( m_writeLockMemory.empty() )
360 {
361 CcpAlignedMallocBuffer buffer( "Tr2BufferAL::m_writeLockMemory", m_desc.stride * m_desc.count, 16 );
362 m_writeLockMemory.swap( buffer );
363 }
364 if( m_writeLockMemory.empty() )
365 {
366 return E_OUTOFMEMORY;
367 }
368
369 data = m_writeLockMemory.get();
370 return S_OK;
371 }
372 else
373 {
374 return E_INVALIDCALL;
375 }
376}
377
378void Tr2BufferAL::UnmapForWriting( Tr2RenderContextAL& renderContext )

Callers

nothing calls this directly

Calls 8

GetMemoryMethod · 0.80
emptyMethod · 0.80
getMethod · 0.80
IsValidFunction · 0.70
HasFlagFunction · 0.70
IsValidMethod · 0.45
MapMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected