Commit 89c843d9 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

vk: minimal sendVMemStatsToProfiler implementation

parent 4a2d50c2
......@@ -53,6 +53,14 @@
#include <QRhiVulkanInitParams>
#include "examplewindow.h"
#define PROFILE
#ifdef PROFILE
#include <QRhiProfiler>
#include <QFile>
QFile profOut;
#endif
class VWindow : public ExampleWindow
{
public:
......@@ -69,7 +77,16 @@ void VWindow::init()
params.inst = vulkanInstance();
params.importExistingDevice = false;
params.window = this;
m_r = QRhi::create(QRhi::Vulkan, &params);
QRhi::Flags flags = QRhi::EnableDebugMarkers;
#ifdef PROFILE
flags |= QRhi::EnableProfiling;
#endif
m_r = QRhi::create(QRhi::Vulkan, &params, flags);
#ifdef PROFILE
m_r->profiler()->setDevice(&profOut);
#endif
//setSampleCount(4); // enable 4x MSAA (except for the render-to-texture pass)
......@@ -100,6 +117,10 @@ int main(int argc, char **argv)
VWindow w;
if (inst.create()) {
#ifdef PROFILE
profOut.setFileName("rhiprof.cbor");
profOut.open(QIODevice::WriteOnly);
#endif
w.setVulkanInstance(&inst);
w.resize(1280, 720);
w.setTitle(QLatin1String("Vulkan"));
......
......@@ -50,6 +50,7 @@
#include "examplewindow.h"
#include <QFileInfo>
#include <QRhiProfiler>
//#define USE_SRGB_SWAPCHAIN
//#define READBACK_SWAPCHAIN
......@@ -151,6 +152,10 @@ void ExampleWindow::init()
m_liveTexCubeRenderer.initResources(m_scrp);
m_liveTexCubeRenderer.setTranslation(QVector3D(-2.0f, 0, 0));
}
// Put the gpu mem allocator statistics to the profiling stream after doing
// all the init. (where applicable)
m_r->profiler()->addVMemAllocatorStats();
}
void ExampleWindow::releaseResources()
......
......@@ -304,4 +304,19 @@ void QRhiProfilerPrivate::releaseSwapChain(QRhiSwapChain *sc)
writer->endMap();
}
void QRhiProfilerPrivate::vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize)
{
if (!ensureStream())
return;
writer->startMap();
WRITE_OP(VMemAllocStats);
WRITE_TIMESTAMP;
WRITE_PAIR(QLatin1String("realAllocCount"), realAllocCount);
WRITE_PAIR(QLatin1String("subAllocCount"), subAllocCount);
WRITE_PAIR(QLatin1String("totalSize"), totalSize);
WRITE_PAIR(QLatin1String("unusedSize"), unusedSize);
writer->endMap();
}
QT_END_NAMESPACE
......@@ -59,7 +59,8 @@ public:
NewTextureStagingArea,
ReleaseTextureStagingArea,
ResizeSwapChain,
ReleaseSwapChain
ReleaseSwapChain,
VMemAllocStats
};
QRhiProfiler();
......
......@@ -72,6 +72,8 @@ public:
void resizeSwapChain(QRhiSwapChain *sc, int bufferCount, int msaaBufferCount, int sampleCount);
void releaseSwapChain(QRhiSwapChain *sc);
void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize);
bool ensureStream();
void flushStream();
......
......@@ -2648,9 +2648,14 @@ const QRhiNativeHandles *QRhiVulkan::nativeHandles()
void QRhiVulkan::sendVMemStatsToProfiler()
{
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
if (!rhiP)
return;
VmaStats stats;
vmaCalculateStats(toVmaAllocator(allocator), &stats);
// ###
QRHI_PROF_F(vmemStat(stats.total.blockCount, stats.total.allocationCount,
stats.total.usedBytes, stats.total.unusedBytes));
}
QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
......
d3d: texture import/export
prof api
vk, d3d, gl: tex and other prof
vk: memalloc stats to prof
vk, d3d, gl: debug: object names
vk, d3d, gl: debug: markers (begin, end, msg)
max texture size?
......@@ -54,6 +53,7 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
vk: memalloc stats to prof
mtl: debug: markers (begin, end, msg)
mtl: debug: object names
mtl: buf/tex/rb/sc prof
......
Supports Markdown
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