Commit 492ec932 by Jamie Madill Committed by Commit Bot

Vulkan: Track allocated sampler counts.

Helps to diagnose perf bugs where resources are over-allocated. Also can be useful to evaluate caching strategies. Bug: angleproject:4517 Change-Id: I48df5a09fbc394fa0b1712fa8cf28a179665e6e7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2159293 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com>
parent 6fc0066a
...@@ -632,7 +632,7 @@ void RendererVk::onDestroy() ...@@ -632,7 +632,7 @@ void RendererVk::onDestroy()
mDescriptorSetLayoutCache.destroy(mDevice); mDescriptorSetLayoutCache.destroy(mDevice);
mPipelineCache.destroy(mDevice); mPipelineCache.destroy(mDevice);
mSamplerCache.destroy(mDevice); mSamplerCache.destroy(this);
vma::DestroyAllocator(mAllocator); vma::DestroyAllocator(mAllocator);
......
...@@ -246,6 +246,7 @@ class RendererVk : angle::NonCopyable ...@@ -246,6 +246,7 @@ class RendererVk : angle::NonCopyable
bool enableDebugUtils() const { return mEnableDebugUtils; } bool enableDebugUtils() const { return mEnableDebugUtils; }
SamplerCache &getSamplerCache() { return mSamplerCache; } SamplerCache &getSamplerCache() { return mSamplerCache; }
vk::ActiveHandleCounter &getActiveHandleCounts() { return mActiveHandleCounts; }
private: private:
angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex); angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex);
...@@ -363,6 +364,7 @@ class RendererVk : angle::NonCopyable ...@@ -363,6 +364,7 @@ class RendererVk : angle::NonCopyable
VmaAllocator mAllocator; VmaAllocator mAllocator;
SamplerCache mSamplerCache; SamplerCache mSamplerCache;
vk::ActiveHandleCounter mActiveHandleCounts;
}; };
} // namespace rx } // namespace rx
......
...@@ -2121,13 +2121,17 @@ SamplerCache::~SamplerCache() ...@@ -2121,13 +2121,17 @@ SamplerCache::~SamplerCache()
ASSERT(mPayload.empty()); ASSERT(mPayload.empty());
} }
void SamplerCache::destroy(VkDevice device) void SamplerCache::destroy(RendererVk *renderer)
{ {
VkDevice device = renderer->getDevice();
for (auto &iter : mPayload) for (auto &iter : mPayload)
{ {
vk::RefCountedSampler &sampler = iter.second; vk::RefCountedSampler &sampler = iter.second;
ASSERT(!sampler.isReferenced()); ASSERT(!sampler.isReferenced());
sampler.get().destroy(device); sampler.get().destroy(device);
renderer->getActiveHandleCounts().onDeallocate(vk::HandleType::Sampler);
} }
mPayload.clear(); mPayload.clear();
...@@ -2154,6 +2158,8 @@ angle::Result SamplerCache::getSampler(ContextVk *contextVk, ...@@ -2154,6 +2158,8 @@ angle::Result SamplerCache::getSampler(ContextVk *contextVk,
vk::RefCountedSampler &insertedSampler = insertedItem.first->second; vk::RefCountedSampler &insertedSampler = insertedItem.first->second;
samplerOut->set(&insertedSampler); samplerOut->set(&insertedSampler);
contextVk->getRenderer()->getActiveHandleCounts().onAllocate(vk::HandleType::Sampler);
return angle::Result::Continue; return angle::Result::Continue;
} }
} // namespace rx } // namespace rx
...@@ -1016,7 +1016,7 @@ class SamplerCache final : angle::NonCopyable ...@@ -1016,7 +1016,7 @@ class SamplerCache final : angle::NonCopyable
SamplerCache(); SamplerCache();
~SamplerCache(); ~SamplerCache();
void destroy(VkDevice device); void destroy(RendererVk *renderer);
angle::Result getSampler(ContextVk *contextVk, angle::Result getSampler(ContextVk *contextVk,
const vk::SamplerDesc &desc, const vk::SamplerDesc &desc,
......
...@@ -4018,6 +4018,14 @@ void SamplerHelper::release(RendererVk *renderer) ...@@ -4018,6 +4018,14 @@ void SamplerHelper::release(RendererVk *renderer)
renderer->collectGarbageAndReinit(&mUse, &mSampler); renderer->collectGarbageAndReinit(&mUse, &mSampler);
} }
angle::Result SamplerHelper::init(Context *context, const VkSamplerCreateInfo &createInfo)
{
RendererVk *renderer = context->getRenderer();
ANGLE_VK_TRY(context, mSampler.init(renderer->getDevice(), createInfo));
renderer->getActiveHandleCounts().onAllocate(HandleType::Sampler);
return angle::Result::Continue;
}
// DispatchHelper implementation. // DispatchHelper implementation.
DispatchHelper::DispatchHelper() = default; DispatchHelper::DispatchHelper() = default;
...@@ -4102,5 +4110,11 @@ angle::Result ShaderProgramHelper::getComputePipeline(Context *context, ...@@ -4102,5 +4110,11 @@ angle::Result ShaderProgramHelper::getComputePipeline(Context *context,
*pipelineOut = &mComputePipeline; *pipelineOut = &mComputePipeline;
return angle::Result::Continue; return angle::Result::Continue;
} }
// ActiveHandleCounter implementation.
ActiveHandleCounter::ActiveHandleCounter() : mActiveCounts{}, mAllocatedCounts{} {}
ActiveHandleCounter::~ActiveHandleCounter() = default;
} // namespace vk } // namespace vk
} // namespace rx } // namespace rx
...@@ -1215,10 +1215,10 @@ class SamplerHelper final : angle::NonCopyable ...@@ -1215,10 +1215,10 @@ class SamplerHelper final : angle::NonCopyable
SamplerHelper(); SamplerHelper();
~SamplerHelper(); ~SamplerHelper();
angle::Result init(Context *context, const VkSamplerCreateInfo &createInfo);
void release(RendererVk *renderer); void release(RendererVk *renderer);
bool valid() const { return mSampler.valid(); } bool valid() const { return mSampler.valid(); }
Sampler &get() { return mSampler; }
const Sampler &get() const { return mSampler; } const Sampler &get() const { return mSampler; }
void retain(ResourceUseList *resourceUseList) { resourceUseList->add(mUse); } void retain(ResourceUseList *resourceUseList) { resourceUseList->add(mUse); }
...@@ -1330,6 +1330,30 @@ class ShaderProgramHelper : angle::NonCopyable ...@@ -1330,6 +1330,30 @@ class ShaderProgramHelper : angle::NonCopyable
// Specialization constants, currently only used by the graphics queue. // Specialization constants, currently only used by the graphics queue.
vk::SpecializationConstantBitSet mSpecializationConstants; vk::SpecializationConstantBitSet mSpecializationConstants;
}; };
// Tracks current handle allocation counts in the back-end. Useful for debugging and profiling.
// Note: not all handle types are currently implemented.
class ActiveHandleCounter final : angle::NonCopyable
{
public:
ActiveHandleCounter();
~ActiveHandleCounter();
void onAllocate(HandleType handleType)
{
mActiveCounts[handleType]++;
mAllocatedCounts[handleType]++;
}
void onDeallocate(HandleType handleType) { mActiveCounts[handleType]--; }
uint32_t getActive(HandleType handleType) const { return mActiveCounts[handleType]; }
uint32_t getAllocated(HandleType handleType) const { return mAllocatedCounts[handleType]; }
private:
angle::PackedEnumMap<HandleType, uint32_t> mActiveCounts;
angle::PackedEnumMap<HandleType, uint32_t> mAllocatedCounts;
};
} // namespace vk } // namespace vk
} // namespace rx } // namespace rx
......
...@@ -659,6 +659,8 @@ void GarbageObject::destroy(RendererVk *renderer) ...@@ -659,6 +659,8 @@ void GarbageObject::destroy(RendererVk *renderer)
UNREACHABLE(); UNREACHABLE();
break; break;
} }
renderer->getActiveHandleCounts().onDeallocate(mHandleType);
} }
void MakeDebugUtilsLabel(GLenum source, const char *marker, VkDebugUtilsLabelEXT *label) void MakeDebugUtilsLabel(GLenum source, const char *marker, VkDebugUtilsLabelEXT *label)
......
...@@ -56,7 +56,7 @@ enum class HandleType ...@@ -56,7 +56,7 @@ enum class HandleType
{ {
Invalid, Invalid,
CommandBuffer, CommandBuffer,
ANGLE_HANDLE_TYPES_X(ANGLE_COMMA_SEP_FUNC) ANGLE_HANDLE_TYPES_X(ANGLE_COMMA_SEP_FUNC) EnumCount
}; };
#undef ANGLE_COMMA_SEP_FUNC #undef ANGLE_COMMA_SEP_FUNC
......
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