2022-02-21 18:21:16 +00:00
|
|
|
#include "precompiled.h"
|
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#include "BindingCache.h"
|
|
|
|
|
|
|
|
void BindingCache::Init( nvrhi::IDevice* _device )
|
|
|
|
{
|
|
|
|
device = _device;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvrhi::BindingSetHandle BindingCache::GetCachedBindingSet( const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout )
|
|
|
|
{
|
|
|
|
size_t hash = 0;
|
|
|
|
nvrhi::hash_combine( hash, desc );
|
|
|
|
nvrhi::hash_combine( hash, layout );
|
|
|
|
|
|
|
|
mutex.Lock();
|
|
|
|
|
|
|
|
nvrhi::BindingSetHandle result = nullptr;
|
|
|
|
for( int i = bindingHash.First( hash ); i != -1; i = bindingHash.Next( i ) )
|
|
|
|
{
|
|
|
|
nvrhi::BindingSetHandle bindingSet = bindingSets[i];
|
|
|
|
if( *bindingSet->getDesc() == desc )
|
|
|
|
{
|
|
|
|
result = bindingSet;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex.Unlock();
|
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
assert( result->getDesc() && *result->getDesc() == desc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvrhi::BindingSetHandle BindingCache::GetOrCreateBindingSet( const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout )
|
|
|
|
{
|
2022-03-15 10:41:56 +00:00
|
|
|
#if 1
|
2022-02-21 18:21:16 +00:00
|
|
|
size_t hash = 0;
|
|
|
|
nvrhi::hash_combine( hash, desc );
|
|
|
|
nvrhi::hash_combine( hash, layout );
|
|
|
|
|
|
|
|
mutex.Lock();
|
|
|
|
|
|
|
|
nvrhi::BindingSetHandle result = nullptr;
|
|
|
|
for( int i = bindingHash.First( hash ); i != -1; i = bindingHash.Next( i ) )
|
|
|
|
{
|
|
|
|
nvrhi::BindingSetHandle bindingSet = bindingSets[i];
|
|
|
|
if( *bindingSet->getDesc() == desc )
|
|
|
|
{
|
|
|
|
result = bindingSet;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex.Unlock();
|
|
|
|
|
|
|
|
if( !result )
|
|
|
|
{
|
2022-03-11 17:17:31 +00:00
|
|
|
mutex.Lock();
|
|
|
|
|
|
|
|
result = device->createBindingSet( desc, layout );
|
|
|
|
|
|
|
|
int entryIndex = bindingSets.Append( result );
|
|
|
|
bindingHash.Add( hash, entryIndex );
|
|
|
|
|
2022-02-21 18:21:16 +00:00
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
assert( result->getDesc() && *result->getDesc() == desc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2022-03-12 09:14:05 +00:00
|
|
|
#else
|
|
|
|
return device->createBindingSet( desc, layout );
|
|
|
|
#endif
|
2022-02-21 18:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BindingCache::Clear()
|
|
|
|
{
|
|
|
|
mutex.Lock();
|
|
|
|
bindingSets.Clear();
|
|
|
|
bindingHash.Clear();
|
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SamplerCache::Init( nvrhi::IDevice* _device )
|
|
|
|
{
|
|
|
|
device = _device;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SamplerCache::Clear()
|
|
|
|
{
|
|
|
|
mutex.Lock();
|
|
|
|
samplers.Clear();
|
|
|
|
samplerHash.Clear();
|
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
nvrhi::SamplerHandle SamplerCache::GetOrCreateSampler( nvrhi::SamplerDesc desc )
|
|
|
|
{
|
2022-03-12 09:14:05 +00:00
|
|
|
#if 1
|
2022-02-21 18:21:16 +00:00
|
|
|
size_t hash = std::hash<nvrhi::SamplerDesc> {}( desc );
|
|
|
|
|
|
|
|
mutex.Lock();
|
|
|
|
|
|
|
|
nvrhi::SamplerHandle result = nullptr;
|
|
|
|
for( int i = samplerHash.First( hash ); i != -1; i = samplerHash.Next( i ) )
|
|
|
|
{
|
|
|
|
nvrhi::SamplerHandle sampler = samplers[i];
|
|
|
|
if( sampler->getDesc() == desc )
|
|
|
|
{
|
|
|
|
result = sampler;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex.Unlock();
|
|
|
|
|
|
|
|
if( !result )
|
|
|
|
{
|
2022-03-11 17:17:31 +00:00
|
|
|
mutex.Lock();
|
|
|
|
|
|
|
|
result = device->createSampler( desc );
|
|
|
|
|
|
|
|
int entryIndex = samplers.Append( result );
|
|
|
|
samplerHash.Add( hash, entryIndex );
|
|
|
|
|
2022-02-21 18:21:16 +00:00
|
|
|
mutex.Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
assert( result->getDesc() == desc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2022-03-12 09:14:05 +00:00
|
|
|
#else
|
|
|
|
return device->createSampler( desc );
|
|
|
|
#endif
|
2022-02-21 18:21:16 +00:00
|
|
|
}
|