Index: src/gpu/vk/GrVkResourceProvider.cpp |
diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp |
index 19bda4152514af6e38c3cd6788740cd52886c25d..44410eed0d48105073963f4d94ea1483318aeaa6 100644 |
--- a/src/gpu/vk/GrVkResourceProvider.cpp |
+++ b/src/gpu/vk/GrVkResourceProvider.cpp |
@@ -7,9 +7,11 @@ |
#include "GrVkResourceProvider.h" |
+#include "GrTextureParams.h" |
#include "GrVkCommandBuffer.h" |
#include "GrVkPipeline.h" |
#include "GrVkRenderPass.h" |
+#include "GrVkSampler.h" |
#include "GrVkUtil.h" |
#ifdef SK_TRACE_VK_RESOURCES |
@@ -81,6 +83,17 @@ GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool( |
return new GrVkDescriptorPool(fGpu, typeCounts); |
} |
+GrVkSampler* GrVkResourceProvider::findOrCreateCompatibleSampler(const GrTextureParams& params) { |
+ GrVkSampler* sampler = fSamplers.find(GrVkSampler::GenerateKey(params)); |
+ if (!sampler) { |
+ sampler = GrVkSampler::Create(fGpu, params); |
+ fSamplers.add(sampler); |
+ } |
+ SkASSERT(sampler); |
+ sampler->ref(); |
+ return sampler; |
+} |
+ |
GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() { |
GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool()); |
fActiveCommandBuffers.push_back(cmdBuffer); |
@@ -112,6 +125,13 @@ void GrVkResourceProvider::destroyResources() { |
} |
fSimpleRenderPasses.reset(); |
+ // Iterate through all store GrVkSamplers and unref them before resetting the hash. |
+ SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); |
+ for (; !iter.done(); ++iter) { |
+ (*iter).unref(fGpu); |
+ } |
+ fSamplers.reset(); |
+ |
#ifdef SK_TRACE_VK_RESOURCES |
SkASSERT(0 == GrVkResource::fTrace.count()); |
#endif |
@@ -133,6 +153,13 @@ void GrVkResourceProvider::abandonResources() { |
} |
fSimpleRenderPasses.reset(); |
+ // Iterate through all store GrVkSamplers and unrefAndAbandon them before resetting the hash. |
+ SkTDynamicHash<GrVkSampler, uint8_t>::Iter iter(&fSamplers); |
+ for (; !iter.done(); ++iter) { |
+ (*iter).unrefAndAbandon(); |
+ } |
+ fSamplers.reset(); |
+ |
#ifdef SK_TRACE_VK_RESOURCES |
SkASSERT(0 == GrVkResource::fTrace.count()); |
#endif |