Reactor: Use std::shared_ptr to ref-count rr::Routines

The intrusive reference counting had no smart pointer, making it difficult to correctly manage reference counts. Most of the codebase did not call bind() and unbind() explictly, and relied on some other mechanism for keeping the routine alive.

By switching to std::shared_ptr, we automatically get guarantees that routine cache eviction will not destroy the routine while it is in use.

Bug: b/137524292
Bug: b/137649247
Change-Id: I38b5e8ba3ee084572a427a1de20f4f017ceaae5a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34168
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkDevice.cpp b/src/Vulkan/VkDevice.cpp
index a260882..230d2d0 100644
--- a/src/Vulkan/VkDevice.cpp
+++ b/src/Vulkan/VkDevice.cpp
@@ -36,18 +36,18 @@
 namespace vk
 {
 
-rr::Routine* Device::SamplingRoutineCache::query(const vk::Device::SamplingRoutineCache::Key& key) const
+std::shared_ptr<rr::Routine> Device::SamplingRoutineCache::query(const vk::Device::SamplingRoutineCache::Key& key) const
 {
 	return cache.query(hash(key));
 }
 
-void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::Key& key, rr::Routine* routine)
+void Device::SamplingRoutineCache::add(const vk::Device::SamplingRoutineCache::Key& key, const std::shared_ptr<rr::Routine>& routine)
 {
 	ASSERT(routine);
 	cache.add(hash(key), routine);
 }
 
-rr::Routine* Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key& key) const
+std::shared_ptr<rr::Routine> Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key& key) const
 {
 	return cache.queryConstCache(hash(key));
 }
@@ -251,7 +251,7 @@
 	return samplingRoutineCache.get();
 }
 
-rr::Routine* Device::findInConstCache(const SamplingRoutineCache::Key& key) const
+std::shared_ptr<rr::Routine> Device::findInConstCache(const SamplingRoutineCache::Key& key) const
 {
 	return samplingRoutineCache->queryConst(key);
 }