| 15 | |
| 16 | |
| 17 | std::pair<Tr2SharedConstantBuffers::Key, Tr2ConstantBufferAL> Tr2SharedConstantBuffers::GetBuffer( const void* contents, uint32_t size ) |
| 18 | { |
| 19 | if( !size || !contents ) |
| 20 | { |
| 21 | return std::make_pair( Key(), Tr2ConstantBufferAL() ); |
| 22 | } |
| 23 | Key key; |
| 24 | key.size = size; |
| 25 | key.hash = CcpHashFNV1( contents, size ); |
| 26 | key.contents = contents; |
| 27 | |
| 28 | auto found = m_buffers.find( key ); |
| 29 | if( found != m_buffers.end() ) |
| 30 | { |
| 31 | auto& value = found->second; |
| 32 | if( !value.buffer.IsValid() ) |
| 33 | { |
| 34 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 35 | if( FAILED( value.buffer.Create( size, Tr2ConstantUsageAL::ONE_SHOT, contents, renderContext ) ) ) |
| 36 | { |
| 37 | return std::make_pair( Key(), Tr2ConstantBufferAL() ); |
| 38 | } |
| 39 | } |
| 40 | ++value.refCount; |
| 41 | return std::make_pair( found->first, value.buffer ); |
| 42 | } |
| 43 | |
| 44 | if( size % sizeof( Vector4 ) ) |
| 45 | { |
| 46 | size += sizeof( Vector4 ) - size % sizeof( Vector4 ); |
| 47 | } |
| 48 | |
| 49 | Value value; |
| 50 | { |
| 51 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 52 | if( FAILED( value.buffer.Create( size, Tr2ConstantUsageAL::ONE_SHOT, contents, renderContext ) ) ) |
| 53 | { |
| 54 | return std::make_pair( Key(), Tr2ConstantBufferAL() ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | value.refCount = 1; |
| 59 | |
| 60 | auto copy = new uint8_t[size]; |
| 61 | memcpy( copy, contents, size ); |
| 62 | key.contents = copy; |
| 63 | |
| 64 | m_buffers[key] = value; |
| 65 | return std::make_pair( key, value.buffer ); |
| 66 | } |
| 67 | |
| 68 | void Tr2SharedConstantBuffers::ReleaseBuffer( const Key& key ) |
| 69 | { |
no test coverage detected