1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[dxvk] Add stat counter for samplers

This commit is contained in:
Philip Rebohle 2024-09-27 17:04:37 +02:00 committed by Philip Rebohle
parent 4635397bb1
commit 707ddd63a1
3 changed files with 47 additions and 2 deletions

View File

@ -401,6 +401,14 @@ namespace dxvk {
*/
DxvkSharedAllocationCacheStats getMemoryAllocationStats(DxvkMemoryAllocationStats& stats);
/**
* \brief Queries sampler statistics
* \returns Sampler stats
*/
DxvkSamplerStats getSamplerStats() {
return m_objects.samplerPool().getStats();
}
/**
* \brief Retreves current frame ID
* \returns Current frame ID

View File

@ -151,6 +151,8 @@ namespace dxvk {
sampler->m_lruPrev = nullptr;
sampler->m_lruNext = nullptr;
m_samplersLive.store(m_samplersLive.load() + 1u);
}
// We already took a reference, forward the pointer as-is
@ -163,9 +165,13 @@ namespace dxvk {
destroyLeastRecentlyUsedSampler();
// Create new sampler object
return &m_samplers.emplace(std::piecewise_construct,
DxvkSampler* sampler = &m_samplers.emplace(std::piecewise_construct,
std::forward_as_tuple(key),
std::forward_as_tuple(this, key)).first->second;
m_samplersTotal.store(m_samplers.size());
m_samplersLive.store(m_samplersLive.load() + 1u);
return sampler;
}
@ -195,6 +201,9 @@ namespace dxvk {
m_lruTail = sampler;
// Don't need an atomic add for these
m_samplersLive.store(m_samplersLive.load() - 1u);
// Try to keep some samplers available for subsequent allocations
if (m_samplers.size() > MinSamplerCount)
destroyLeastRecentlyUsedSampler();
@ -213,6 +222,7 @@ namespace dxvk {
m_lruTail = nullptr;
m_samplers.erase(sampler->key());
m_samplersTotal.store(m_samplers.size());
}
}

View File

@ -195,7 +195,18 @@ namespace dxvk {
VkBorderColor determineBorderColorType() const;
};
/**
* \brief Sampler statistics
*/
struct DxvkSamplerStats {
/// Number of sampler objects created
uint32_t totalCount = 0u;
/// Number of samplers currently in use
uint32_t liveCount = 0u;
};
/**
* \brief Sampler pool
@ -225,6 +236,19 @@ namespace dxvk {
*/
Rc<DxvkSampler> createSampler(const DxvkSamplerKey& key);
/**
* \brief Retrieves sampler statistics
*
* Note that these might be out of date immediately.
* \returns Sampler counts
*/
DxvkSamplerStats getStats() const {
DxvkSamplerStats stats = { };
stats.totalCount = m_samplersTotal.load();
stats.liveCount = m_samplersLive.load();
return stats;
}
private:
DxvkDevice* m_device;
@ -236,6 +260,9 @@ namespace dxvk {
DxvkSampler* m_lruHead = nullptr;
DxvkSampler* m_lruTail = nullptr;
std::atomic<uint32_t> m_samplersLive = { 0u };
std::atomic<uint32_t> m_samplersTotal = { 0u };
void releaseSampler(DxvkSampler* sampler);
void destroyLeastRecentlyUsedSampler();