Rename constant cache to snapshot cache

This helps clarify that the cache is able to take snapshots of its
contents, and this snapshot can be queried without the overhead of
acquiring a mutex.

Bug: b/131246679
Change-Id: I4317628a22f70d37309908b24df62dc5ec5a946c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42568
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/LRUCache.hpp b/src/Device/LRUCache.hpp
index dedca45..848d421 100644
--- a/src/Device/LRUCache.hpp
+++ b/src/Device/LRUCache.hpp
@@ -47,30 +47,32 @@
 	Data *data;
 };
 
+// An LRU cache which can take a 'snapshot' of its current state. This is useful
+// for allowing concurrent read access without requiring a mutex to be locked.
 template<class Key, class Data, class Hasher = std::hash<Key>>
-class LRUConstCache : public LRUCache<Key, Data>
+class LRUSnapshotCache : public LRUCache<Key, Data>
 {
 	using LRUBase = LRUCache<Key, Data>;
 
 public:
-	LRUConstCache(int n)
+	LRUSnapshotCache(int n)
 	    : LRUBase(n)
 	{}
-	~LRUConstCache() { clearConstCache(); }
+	~LRUSnapshotCache() { clearSnapshot(); }
 
 	Data add(const Key &key, const Data &data) override
 	{
-		constCacheNeedsUpdate = true;
+		snapshotNeedsUpdate = true;
 		return LRUBase::add(key, data);
 	}
 
-	void updateConstCache();
-	const Data &queryConstCache(const Key &key) const;
+	void updateSnapshot();
+	const Data &querySnapshot(const Key &key) const;
 
 private:
-	void clearConstCache();
-	bool constCacheNeedsUpdate = false;
-	std::unordered_map<Key, Data, Hasher> constCache;
+	void clearSnapshot();
+	bool snapshotNeedsUpdate = false;
+	std::unordered_map<Key, Data, Hasher> snapshot;
 };
 
 }  // namespace sw
@@ -153,36 +155,36 @@
 }
 
 template<class Key, class Data, class Hasher>
-void LRUConstCache<Key, Data, Hasher>::clearConstCache()
+void LRUSnapshotCache<Key, Data, Hasher>::clearSnapshot()
 {
-	constCache.clear();
+	snapshot.clear();
 }
 
 template<class Key, class Data, class Hasher>
-void LRUConstCache<Key, Data, Hasher>::updateConstCache()
+void LRUSnapshotCache<Key, Data, Hasher>::updateSnapshot()
 {
-	if(constCacheNeedsUpdate)
+	if(snapshotNeedsUpdate)
 	{
-		clearConstCache();
+		clearSnapshot();
 
 		for(int i = 0; i < LRUBase::size; i++)
 		{
 			if(LRUBase::data[i])
 			{
-				constCache[*LRUBase::ref[i]] = LRUBase::data[i];
+				snapshot[*LRUBase::ref[i]] = LRUBase::data[i];
 			}
 		}
 
-		constCacheNeedsUpdate = false;
+		snapshotNeedsUpdate = false;
 	}
 }
 
 template<class Key, class Data, class Hasher>
-const Data &LRUConstCache<Key, Data, Hasher>::queryConstCache(const Key &key) const
+const Data &LRUSnapshotCache<Key, Data, Hasher>::querySnapshot(const Key &key) const
 {
-	auto it = constCache.find(key);
+	auto it = snapshot.find(key);
 	static Data null = {};
-	return (it != constCache.end()) ? it->second : null;
+	return (it != snapshot.end()) ? it->second : null;
 }
 
 }  // namespace sw
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 90db545..7667f96 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -555,7 +555,7 @@
 	MARL_SCOPED_EVENT("synchronize");
 	auto ticket = drawTickets.take();
 	ticket.wait();
-	device->updateSamplingRoutineConstCache();
+	device->updateSamplingRoutineSnapshotCache();
 	ticket.done();
 }
 
diff --git a/src/Pipeline/SpirvShaderSampling.cpp b/src/Pipeline/SpirvShaderSampling.cpp
index 5434645..adc465b 100644
--- a/src/Pipeline/SpirvShaderSampling.cpp
+++ b/src/Pipeline/SpirvShaderSampling.cpp
@@ -40,7 +40,7 @@
 
 	ASSERT(imageDescriptor->device);
 
-	if(auto routine = imageDescriptor->device->findInConstCache(key))
+	if(auto routine = imageDescriptor->device->querySnapshotCache(key))
 	{
 		return (ImageSampler *)(routine->getEntry());
 	}
diff --git a/src/Vulkan/VkDevice.cpp b/src/Vulkan/VkDevice.cpp
index 33c9731..492c676 100644
--- a/src/Vulkan/VkDevice.cpp
+++ b/src/Vulkan/VkDevice.cpp
@@ -49,14 +49,14 @@
 	cache.add(key, routine);
 }
 
-rr::Routine *Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key &key) const
+rr::Routine *Device::SamplingRoutineCache::querySnapshot(const vk::Device::SamplingRoutineCache::Key &key) const
 {
-	return cache.queryConstCache(key).get();
+	return cache.querySnapshot(key).get();
 }
 
-void Device::SamplingRoutineCache::updateConstCache()
+void Device::SamplingRoutineCache::updateSnapshot()
 {
-	cache.updateConstCache();
+	cache.updateSnapshot();
 }
 
 Device::SamplerIndexer::~SamplerIndexer()
@@ -302,15 +302,15 @@
 	return samplingRoutineCache.get();
 }
 
-rr::Routine *Device::findInConstCache(const SamplingRoutineCache::Key &key) const
+rr::Routine *Device::querySnapshotCache(const SamplingRoutineCache::Key &key) const
 {
-	return samplingRoutineCache->queryConst(key);
+	return samplingRoutineCache->querySnapshot(key);
 }
 
-void Device::updateSamplingRoutineConstCache()
+void Device::updateSamplingRoutineSnapshotCache()
 {
 	std::unique_lock<std::mutex> lock(samplingRoutineCacheMutex);
-	samplingRoutineCache->updateConstCache();
+	samplingRoutineCache->updateSnapshot();
 }
 
 std::mutex &Device::getSamplingRoutineCacheMutex()
diff --git a/src/Vulkan/VkDevice.hpp b/src/Vulkan/VkDevice.hpp
index c2ba927..2a52473 100644
--- a/src/Vulkan/VkDevice.hpp
+++ b/src/Vulkan/VkDevice.hpp
@@ -89,17 +89,17 @@
 		std::shared_ptr<rr::Routine> query(const Key &key) const;
 		void add(const Key &key, const std::shared_ptr<rr::Routine> &routine);
 
-		rr::Routine *queryConst(const Key &key) const;
-		void updateConstCache();
+		rr::Routine *querySnapshot(const Key &key) const;
+		void updateSnapshot();
 
 	private:
-		sw::LRUConstCache<Key, std::shared_ptr<rr::Routine>, Key::Hash> cache;
+		sw::LRUSnapshotCache<Key, std::shared_ptr<rr::Routine>, Key::Hash> cache;
 	};
 
 	SamplingRoutineCache *getSamplingRoutineCache() const;
 	std::mutex &getSamplingRoutineCacheMutex();
-	rr::Routine *findInConstCache(const SamplingRoutineCache::Key &key) const;
-	void updateSamplingRoutineConstCache();
+	rr::Routine *querySnapshotCache(const SamplingRoutineCache::Key &key) const;
+	void updateSamplingRoutineSnapshotCache();
 
 	class SamplerIndexer
 	{