Commit 03c2aea0 by Ben Clayton

Use raw pointers for the routine const cache.

As these are touched by pixel shaders, this is extraordinarily hot code, and the cost of ref-counting by shared_ptr can really impact performance. As the const cache is updated at well known sync points, the queryConstCache method is safe to return a raw pointer to the routine. Bug: b/137524292 Bug: b/137649247 Change-Id: I2ae1f159467eb27b918344714cef1963f3b24a45 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34453 Presubmit-Ready: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 0eb5c839
...@@ -63,7 +63,7 @@ namespace sw ...@@ -63,7 +63,7 @@ namespace sw
} }
void updateConstCache(); void updateConstCache();
Data queryConstCache(const Key &key) const; const Data& queryConstCache(const Key &key) const;
private: private:
void clearConstCache(); void clearConstCache();
...@@ -215,10 +215,11 @@ namespace sw ...@@ -215,10 +215,11 @@ namespace sw
} }
template<class Key, class Data> template<class Key, class Data>
Data LRUConstCache<Key, Data>::queryConstCache(const Key &key) const const Data& LRUConstCache<Key, Data>::queryConstCache(const Key &key) const
{ {
auto it = constCache.find(key); auto it = constCache.find(key);
return (it != constCache.end()) ? it->second : nullptr; static Data null = {};
return (it != constCache.end()) ? it->second : null;
} }
} }
......
...@@ -40,8 +40,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl ...@@ -40,8 +40,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
ASSERT(imageDescriptor->device); ASSERT(imageDescriptor->device);
auto routine = imageDescriptor->device->findInConstCache(key); if(auto routine = imageDescriptor->device->findInConstCache(key))
if(routine)
{ {
return (ImageSampler*)(routine->getEntry()); return (ImageSampler*)(routine->getEntry());
} }
...@@ -49,7 +48,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl ...@@ -49,7 +48,7 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
std::unique_lock<std::mutex> lock(imageDescriptor->device->getSamplingRoutineCacheMutex()); std::unique_lock<std::mutex> lock(imageDescriptor->device->getSamplingRoutineCacheMutex());
vk::Device::SamplingRoutineCache* cache = imageDescriptor->device->getSamplingRoutineCache(); vk::Device::SamplingRoutineCache* cache = imageDescriptor->device->getSamplingRoutineCache();
routine = cache->query(key); auto routine = cache->query(key);
if(routine) if(routine)
{ {
return (ImageSampler*)(routine->getEntry()); return (ImageSampler*)(routine->getEntry());
......
...@@ -47,9 +47,9 @@ void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::K ...@@ -47,9 +47,9 @@ void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::K
cache.add(hash(key), routine); cache.add(hash(key), routine);
} }
std::shared_ptr<rr::Routine> Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key& key) const rr::Routine* Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key& key) const
{ {
return cache.queryConstCache(hash(key)); return cache.queryConstCache(hash(key)).get();
} }
void Device::SamplingRoutineCache::updateConstCache() void Device::SamplingRoutineCache::updateConstCache()
...@@ -251,7 +251,7 @@ Device::SamplingRoutineCache* Device::getSamplingRoutineCache() const ...@@ -251,7 +251,7 @@ Device::SamplingRoutineCache* Device::getSamplingRoutineCache() const
return samplingRoutineCache.get(); return samplingRoutineCache.get();
} }
std::shared_ptr<rr::Routine> Device::findInConstCache(const SamplingRoutineCache::Key& key) const rr::Routine* Device::findInConstCache(const SamplingRoutineCache::Key& key) const
{ {
return samplingRoutineCache->queryConst(key); return samplingRoutineCache->queryConst(key);
} }
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
std::shared_ptr<rr::Routine> query(const Key& key) const; std::shared_ptr<rr::Routine> query(const Key& key) const;
void add(const Key& key, const std::shared_ptr<rr::Routine>& routine); void add(const Key& key, const std::shared_ptr<rr::Routine>& routine);
std::shared_ptr<rr::Routine> queryConst(const Key& key) const; rr::Routine* queryConst(const Key& key) const;
void updateConstCache(); void updateConstCache();
static std::size_t hash(const Key &key); static std::size_t hash(const Key &key);
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
SamplingRoutineCache* getSamplingRoutineCache() const; SamplingRoutineCache* getSamplingRoutineCache() const;
std::mutex& getSamplingRoutineCacheMutex(); std::mutex& getSamplingRoutineCacheMutex();
std::shared_ptr<rr::Routine> findInConstCache(const SamplingRoutineCache::Key& key) const; rr::Routine* findInConstCache(const SamplingRoutineCache::Key& key) const;
void updateSamplingRoutineConstCache(); void updateSamplingRoutineConstCache();
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment