Commit b20d9229 authored by Laszlo Agocs's avatar Laszlo Agocs

vk: Make gpu timestamps work with rsh

Also enable and print some timings in multiwindow_threaded.

The included rsh doc update comes after varying experiences with
Vulkan implementations (e.g. NVIDIA 411, 417, and AMD something recent
all behaving slightly differently)
parent 3c397d2c
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include <QBakedShader> #include <QBakedShader>
#include <QFile> #include <QFile>
#include <QRhiProfiler>
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
#include <QRhiGles2InitParams> #include <QRhiGles2InitParams>
...@@ -283,6 +284,7 @@ struct Renderer ...@@ -283,6 +284,7 @@ struct Renderer
QMatrix4x4 m_proj; QMatrix4x4 m_proj;
float m_rotation = 0; float m_rotation = 0;
int m_frameCount = 0;
}; };
void Thread::run() void Thread::run()
...@@ -345,6 +347,7 @@ void Renderer::createRhi() ...@@ -345,6 +347,7 @@ void Renderer::createRhi()
return; return;
qDebug() << "renderer" << this << "creating rhi"; qDebug() << "renderer" << this << "creating rhi";
QRhi::Flags rhiFlags = QRhi::EnableProfiling;
if (useRsh) { if (useRsh) {
qDebug("Using QRhiResourceSharingHost"); qDebug("Using QRhiResourceSharingHost");
...@@ -359,7 +362,7 @@ void Renderer::createRhi() ...@@ -359,7 +362,7 @@ void Renderer::createRhi()
params.resourceSharingHost = rsh; params.resourceSharingHost = rsh;
params.fallbackSurface = fallbackSurface; params.fallbackSurface = fallbackSurface;
params.window = window; params.window = window;
r = QRhi::create(QRhi::OpenGLES2, &params); r = QRhi::create(QRhi::OpenGLES2, &params, rhiFlags);
} }
#endif #endif
...@@ -370,7 +373,7 @@ void Renderer::createRhi() ...@@ -370,7 +373,7 @@ void Renderer::createRhi()
params.resourceSharingHost = rsh; params.resourceSharingHost = rsh;
params.inst = instance; params.inst = instance;
params.window = window; params.window = window;
r = QRhi::create(QRhi::Vulkan, &params); r = QRhi::create(QRhi::Vulkan, &params, rhiFlags);
} }
#endif #endif
...@@ -380,7 +383,7 @@ void Renderer::createRhi() ...@@ -380,7 +383,7 @@ void Renderer::createRhi()
if (useRsh) if (useRsh)
params.resourceSharingHost = rsh; params.resourceSharingHost = rsh;
params.enableDebugLayer = true; params.enableDebugLayer = true;
r = QRhi::create(QRhi::D3D11, &params); r = QRhi::create(QRhi::D3D11, &params, rhiFlags);
} }
#endif #endif
...@@ -389,7 +392,7 @@ void Renderer::createRhi() ...@@ -389,7 +392,7 @@ void Renderer::createRhi()
QRhiMetalInitParams params; QRhiMetalInitParams params;
if (useRsh) if (useRsh)
params.resourceSharingHost = rsh; params.resourceSharingHost = rsh;
r = QRhi::create(QRhi::Metal, &params); r = QRhi::create(QRhi::Metal, &params, rhiFlags);
} }
#endif #endif
...@@ -634,6 +637,28 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent) ...@@ -634,6 +637,28 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
wakeUpIfNeeded(); wakeUpIfNeeded();
r->endFrame(m_sc); r->endFrame(m_sc);
m_frameCount += 1;
if ((m_frameCount % 300) == 0) {
const QRhiProfiler::CpuTime ff = r->profiler()->frameToFrameTimes(m_sc);
const QRhiProfiler::CpuTime be = r->profiler()->frameBuildTimes(m_sc);
const QRhiProfiler::GpuTime gp = r->profiler()->gpuFrameTimes(m_sc);
if (r->isFeatureSupported(QRhi::Timestamps)) {
qDebug("[renderer %p] frame-to-frame: min %lld max %lld avg %f. "
"frame build: min %lld max %lld avg %f. "
"gpu frame time: min %f max %f avg %f",
this,
ff.minTime, ff.maxTime, ff.avgTime,
be.minTime, be.maxTime, be.avgTime,
gp.minTime, gp.maxTime, gp.avgTime);
} else {
qDebug("[renderer %p] frame-to-frame: min %lld max %lld avg %f. "
"frame build: min %lld max %lld avg %f. ",
this,
ff.minTime, ff.maxTime, ff.avgTime,
be.minTime, be.maxTime, be.avgTime);
}
}
} }
void Renderer::sendInit() void Renderer::sendInit()
......
...@@ -2630,6 +2630,15 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format, ...@@ -2630,6 +2630,15 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format,
QRhiResourceSharingHost and so sharing the same device, queue, or device QRhiResourceSharingHost and so sharing the same device, queue, or device
context. context.
\note Resource sharing increases the chance of contention and inconsistent
frame rate due to sharing the same device and possibly command queue, and
due to the need for synchronization inside various QRhi calls. The results
can also vary based on the implementation of the underlying graphics API,
with potentially different results from different vendor's drivers or
different driver versions. Applications and libraries are advised to
consider offering resource sharing as an opt-in feature, combined with a
design that allows operating with fully independent QRhi instances as well.
To illustrate resource sharing, take the following code snippets. To illustrate resource sharing, take the following code snippets.
In many cases an application will use a single QRhi. Resources created from it In many cases an application will use a single QRhi. Resources created from it
......
...@@ -312,6 +312,14 @@ bool QRhiVulkan::create(QRhi::Flags flags) ...@@ -312,6 +312,14 @@ bool QRhiVulkan::create(QRhi::Flags flags)
} }
} }
QVector<VkQueueFamilyProperties> queueFamilyProps;
auto queryQueueFamilyProps = [this, &queueFamilyProps] {
uint32_t queueCount = 0;
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
queueFamilyProps.resize(queueCount);
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueFamilyProps.data());
};
if (!importedDevice && (!rsh || rshWantsDevice)) { if (!importedDevice && (!rsh || rshWantsDevice)) {
uint32_t devCount = 0; uint32_t devCount = 0;
f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr); f->vkEnumeratePhysicalDevices(inst->vkInstance(), &devCount, nullptr);
...@@ -329,10 +337,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) ...@@ -329,10 +337,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
return false; return false;
} }
uint32_t queueCount = 0; queryQueueFamilyProps();
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
QVector<VkQueueFamilyProperties> queueFamilyProps(queueCount);
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueFamilyProps.data());
gfxQueue = VK_NULL_HANDLE; gfxQueue = VK_NULL_HANDLE;
gfxQueueFamilyIdx = -1; gfxQueueFamilyIdx = -1;
...@@ -361,8 +366,6 @@ bool QRhiVulkan::create(QRhi::Flags flags) ...@@ -361,8 +366,6 @@ bool QRhiVulkan::create(QRhi::Flags flags)
return false; return false;
} }
timestampValidBits = queueFamilyProps[gfxQueueFamilyIdx].timestampValidBits;
VkDeviceQueueCreateInfo queueInfo[2]; VkDeviceQueueCreateInfo queueInfo[2];
const float prio[] = { 0 }; const float prio[] = { 0 };
memset(queueInfo, 0, sizeof(queueInfo)); memset(queueInfo, 0, sizeof(queueInfo));
...@@ -435,8 +438,15 @@ bool QRhiVulkan::create(QRhi::Flags flags) ...@@ -435,8 +438,15 @@ bool QRhiVulkan::create(QRhi::Flags flags)
} }
} }
if (gfxQueueFamilyIdx != -1 && !gfxQueue) if (gfxQueueFamilyIdx != -1) {
df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, 0, &gfxQueue); if (!gfxQueue)
df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, 0, &gfxQueue);
if (queueFamilyProps.isEmpty())
queryQueueFamilyProps();
timestampValidBits = queueFamilyProps[gfxQueueFamilyIdx].timestampValidBits;
}
f->vkGetPhysicalDeviceProperties(physDev, &physDevProperties); f->vkGetPhysicalDeviceProperties(physDev, &physDevProperties);
ubufAlign = physDevProperties.limits.minUniformBufferOffsetAlignment; ubufAlign = physDevProperties.limits.minUniformBufferOffsetAlignment;
......
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