Commit cfe6c8cb authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Add a QRhiSwapChain::NoVSync flag

parent 5beee8cb
......@@ -449,6 +449,8 @@ int main(int argc, char **argv)
fmt.setStencilBufferSize(8);
if (sampleCount > 1)
fmt.setSamples(sampleCount);
if (scFlags.testFlag(QRhiSwapChain::NoVSync))
fmt.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(fmt);
// Vulkan setup.
......
......@@ -68,6 +68,7 @@
//#define USE_MSAA
//#define USE_SRGB_SWAPCHAIN
//#define READBACK_SWAPCHAIN
//#define NO_VSYNC
struct {
TriangleRenderer triRenderer;
......@@ -104,6 +105,13 @@ void preInit()
#ifdef USE_SRGB_SWAPCHAIN
scFlags |= QRhiSwapChain::sRGB;
#endif
#ifdef NO_VSYNC
scFlags |= QRhiSwapChain::NoVSync;
#endif
// For OpenGL some of these are incorporated into the QSurfaceFormat by
// examplefw.h after returning from here as that is out of the RHI's control.
}
void Window::customInit()
......
......@@ -871,7 +871,8 @@ public:
SurfaceHasPreMulAlpha = 1 << 0,
SurfaceHasNonPreMulAlpha = 1 << 1,
sRGB = 1 << 2,
UsedAsTransferSource = 1 << 3 // will be read back
UsedAsTransferSource = 1 << 3, // will be read back
NoVSync = 1 << 4
};
Q_DECLARE_FLAGS(Flags, Flag)
......
......@@ -620,9 +620,8 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain)
// this must be done before the Present
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount + 1));
const UINT swapInterval = 1;
const UINT presentFlags = 0;
HRESULT hr = swapChainD->swapChain->Present(swapInterval, presentFlags);
HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags);
if (FAILED(hr))
qWarning("Failed to present: %s", qPrintable(comErrorMessage(hr)));
......@@ -2820,6 +2819,7 @@ bool QD3D11SwapChain::buildOrResize()
currentFrameSlot = 0;
frameCount = 0;
ds = m_depthStencil ? QRHI_RES(QD3D11RenderBuffer, m_depthStencil) : nullptr;
swapInterval = m_flags.testFlag(QRhiSwapChain::NoVSync) ? 0 : 1;
QD3D11ReferenceRenderTarget *rtD = QRHI_RES(QD3D11ReferenceRenderTarget, &rt);
rtD->d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc);
......
......@@ -428,6 +428,7 @@ struct QD3D11SwapChain : public QRhiSwapChain
QD3D11RenderBuffer *ds = nullptr;
ID3D11Query *timestampDisjointQuery[BUFFER_COUNT];
ID3D11Query *timestampQuery[BUFFER_COUNT * 2];
UINT swapInterval = 1;
};
class QRhiD3D11 : public QRhiImplementation
......
......@@ -2557,6 +2557,9 @@ bool QMetalSwapChain::buildOrResize()
if (m_flags.testFlag(UsedAsTransferSource))
d->layer.framebufferOnly = NO;
if (m_flags.testFlag(NoVSync))
d->layer.displaySyncEnabled = NO;
m_currentPixelSize = surfacePixelSize();
pixelSize = m_currentPixelSize;
......
......@@ -744,8 +744,6 @@ bool QRhiVulkan::createTransientImage(VkFormat format,
return true;
}
static const VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkFormat QRhiVulkan::optimalDepthStencilFormat()
{
if (optimalDsFormat != VK_FORMAT_UNDEFINED)
......@@ -1010,8 +1008,14 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain)
if (swapChainD->supportsReadback && swapChainD->m_flags.testFlag(QRhiSwapChain::UsedAsTransferSource))
usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
qDebug("Creating new swapchain of %d buffers, size %dx%d",
reqBufferCount, swapChainD->pixelSize.width(), swapChainD->pixelSize.height());
VkPresentModeKHR presentMode = swapChainD->m_flags.testFlag(QRhiSwapChain::NoVSync)
? VK_PRESENT_MODE_IMMEDIATE_KHR
: VK_PRESENT_MODE_FIFO_KHR;
if (!swapChainD->supportedPresentationModes.contains(presentMode))
presentMode = VK_PRESENT_MODE_FIFO_KHR;
qDebug("Creating new swapchain of %d buffers, size %dx%d, presentation mode %d",
reqBufferCount, swapChainD->pixelSize.width(), swapChainD->pixelSize.height(), presentMode);
VkSwapchainKHR oldSwapChain = swapChainD->sc;
VkSwapchainCreateInfoKHR swapChainInfo;
......@@ -4494,7 +4498,12 @@ bool QVkSwapChain::ensureSurface()
rhiD->inst->getInstanceProcAddr("vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
rhiD->vkGetPhysicalDeviceSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(
rhiD->inst->getInstanceProcAddr("vkGetPhysicalDeviceSurfaceFormatsKHR"));
if (!rhiD->vkGetPhysicalDeviceSurfaceCapabilitiesKHR || !rhiD->vkGetPhysicalDeviceSurfaceFormatsKHR) {
rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>(
rhiD->inst->getInstanceProcAddr("vkGetPhysicalDeviceSurfacePresentModesKHR"));
if (!rhiD->vkGetPhysicalDeviceSurfaceCapabilitiesKHR
|| !rhiD->vkGetPhysicalDeviceSurfaceFormatsKHR
|| !rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR)
{
qWarning("Physical device surface queries not available");
return false;
}
......@@ -4525,6 +4534,12 @@ bool QVkSwapChain::ensureSurface()
samples = rhiD->effectiveSampleCount(m_sampleCount);
quint32 presModeCount = 0;
rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR(rhiD->physDev, surface, &presModeCount, nullptr);
QVector<VkPresentModeKHR> presModes(presModeCount);
rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR(rhiD->physDev, surface, &presModeCount, presModes.data());
supportedPresentationModes = presModes;
return true;
}
......
......@@ -292,6 +292,7 @@ struct QVkSwapChain : public QRhiSwapChain
VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
QVkRenderBuffer *ds = nullptr;
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
QVector<VkPresentModeKHR> supportedPresentationModes;
VkDeviceMemory msaaImageMem = VK_NULL_HANDLE;
QVkReferenceRenderTarget rtWrapper;
QVkCommandBuffer cbWrapper;
......@@ -497,6 +498,7 @@ public:
PFN_vkQueuePresentKHR vkQueuePresentKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
VkPipelineCache pipelineCache = VK_NULL_HANDLE;
struct DescriptorPoolData {
......
d3d: timestamp query
prof report api (fed by a cbor stream)
mtl: report readback temp buf
multiwindow_threaded should demo pulling out the device and importing to another rhi
......@@ -52,6 +51,8 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
allow requesting no-vsync present mode where applicable
d3d: timestamp query
vk: timestamp query
prof: report readback temp buf
merge offscreen examples into one
......
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