diff --git a/src/dxvk/dxvk_stats.cpp b/src/dxvk/dxvk_stats.cpp new file mode 100644 index 000000000..4441f537f --- /dev/null +++ b/src/dxvk/dxvk_stats.cpp @@ -0,0 +1,27 @@ +#include "dxvk_stats.h" + +namespace dxvk { + + DxvkStatCounters::DxvkStatCounters() { + this->reset(); + } + + + DxvkStatCounters::~DxvkStatCounters() { + + } + + + void DxvkStatCounters::merge(const DxvkStatCounters& other) { + for (size_t i = 0; i < m_counters.size(); i++) { + m_counters[i] += other.m_counters[i]; + } + } + + + void DxvkStatCounters::reset() { + for (size_t i = 0; i < m_counters.size(); i++) + m_counters[i] = 0; + } + +} diff --git a/src/dxvk/dxvk_stats.h b/src/dxvk/dxvk_stats.h new file mode 100644 index 000000000..4a549131a --- /dev/null +++ b/src/dxvk/dxvk_stats.h @@ -0,0 +1,102 @@ +#pragma once + +#include "dxvk_include.h" + +namespace dxvk { + + /** + * \brief Named stat counters + * + * Enumerates available stat counters. Used + * thogether with \ref DxvkStatCounters. + */ + enum class DxvkStatCounter : uint32_t { + CmdDrawCalls, ///< Number of draw calls + CmdDispatchCalls, ///< Number of compute calls + CmdRenderPassCount, ///< Number of render passes + MemoryAllocationCount, ///< Number of memory allocations + MemoryAllocated, ///< Amount of memory allocated + MemoryUsed, ///< Amount of memory used + PipeCountGraphics, ///< Number of graphics pipelines + PipeCountCompute, ///< Number of compute pipelines + PipeCacheSize, ///< Pipeline cache size + QueueSubmitCount, ///< Number of command buffer submissions + QueuePresentCount, ///< Number of present calls / frames + NumCounters, ///< Number of counters available + }; + + + /** + * \brief Stat counters + * + * Collects various statistics that may be + * useful to identify performance bottlenecks. + */ + class DxvkStatCounters { + + public: + + DxvkStatCounters(); + ~DxvkStatCounters(); + + /** + * \brief Retrieves a counter value + * + * \param [in] ctr The counter + * \returns Counter value + */ + uint32_t getCtr(DxvkStatCounter ctr) const { + return m_counters[uint32_t(ctr)]; + } + + /** + * \brief Sets a counter value + * + * \param [in] ctr The counter + * \param [in] val Counter value + */ + void setCtr(DxvkStatCounter ctr, uint32_t val) { + m_counters[uint32_t(ctr)] = val; + } + + /** + * \brief Increments a counter value + * + * \param [in] ctr Counter to increment + * \param [in] val Number to add to counter value + */ + void addCtr(DxvkStatCounter ctr, uint32_t val) { + m_counters[uint32_t(ctr)] += val; + } + + /** + * \brief Resets a counter + * \param [in] ctr The counter + */ + void clrCtr(DxvkStatCounter ctr) { + m_counters[uint32_t(ctr)] = 0; + } + + /** + * \brief Merges counters + * + * Adds counter values from another set + * of counters to this set of counters. + * \param [in] other Counters to add + */ + void merge(const DxvkStatCounters& other); + + /** + * \brief Resets counters + * + * Sets all counters to zero. + */ + void reset(); + + private: + + std::array m_counters; + + }; + +} diff --git a/src/dxvk/meson.build b/src/dxvk/meson.build index a5ccfb417..1a5e54d61 100644 --- a/src/dxvk/meson.build +++ b/src/dxvk/meson.build @@ -40,6 +40,7 @@ dxvk_src = files([ 'dxvk_sampler.cpp', 'dxvk_shader.cpp', 'dxvk_staging.cpp', + 'dxvk_stats.cpp', 'dxvk_surface.cpp', 'dxvk_swapchain.cpp', 'dxvk_sync.cpp',