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

Merge remote-tracking branch 'qvk6/master'

parents 241ff2a6 be2cb97c
load(qt_build_config)
# CONFIG += warning_clean
CONFIG += warning_clean
DEFINES += QT_NO_FOREACH
MODULE_VERSION = 5.12.0
......@@ -200,6 +200,7 @@ void Window::customRender()
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 }, { d.vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
......
......@@ -216,6 +216,7 @@ void Window::customRender()
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 }, { d.vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
......
......@@ -172,6 +172,7 @@ void Window::customRender()
cb->beginPass(m_sc->currentFrameRenderTarget(), { 0.4f, 0.7f, 0.0f, 1.0f }, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 } });
cb->draw(36);
cb->endPass();
......
......@@ -453,6 +453,7 @@ void Window::render()
cb->setGraphicsPipeline(m_ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { m_vbuf, 0 } });
cb->draw(3);
......
......@@ -157,6 +157,7 @@ void Window::customRender()
cb->setGraphicsPipeline(d.ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 } });
cb->draw(3);
......
......@@ -271,7 +271,8 @@ void QRhiImgui::queueFrame(QRhiCommandBuffer *cb)
const QPointF scissorPixelBottomLeft = QPointF(cmd->ClipRect.x, d->lastOutputSize.height() - cmd->ClipRect.w);
const QSizeF scissorPixelSize = QSizeF(cmd->ClipRect.z - cmd->ClipRect.x, cmd->ClipRect.w - cmd->ClipRect.y);
const int textureIndex = int(reinterpret_cast<qintptr>(cmd->TextureId));
cb->setGraphicsPipeline(d->ps, d->textures[textureIndex].srb);
cb->setGraphicsPipeline(d->ps);
cb->setShaderResources(d->textures[textureIndex].srb);
cb->setScissor({ int(scissorPixelBottomLeft.x()), int(scissorPixelBottomLeft.y()),
int(scissorPixelSize.width()), int(scissorPixelSize.height()) });
cb->setVertexInput(0, vertexInput, d->ibuf, indexOffset, QRhiCommandBuffer::IndexUInt32);
......
......@@ -241,6 +241,7 @@ void Window::customRender()
cb->beginPass(d.rt, { 0.5f, 0.2f, 0, 1 }, { 1, 0 }, u);
cb->setGraphicsPipeline(d.triPs);
cb->setViewport({ 0, 0, float(d.rb->pixelSize().width()), float(d.rb->pixelSize().height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, sizeof(vertexData) } });
cb->draw(3);
cb->endPass();
......@@ -250,6 +251,7 @@ void Window::customRender()
cb->beginPass(m_sc->currentFrameRenderTarget(), { 0.4f, 0.7f, 0.0f, 1.0f }, { 1.0f, 0 });
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 } }, d.ibuf, 0, QRhiCommandBuffer::IndexUInt16);
cb->drawIndexed(6);
cb->endPass();
......
......@@ -299,6 +299,7 @@ void Window::customRender()
cb->beginPass(d.rt, { 0.5f, 0.2f, 0, 1 }, { 1, 0 });
cb->setGraphicsPipeline(d.triPs);
cb->setViewport({ 0, 0, float(d.msaaTex->pixelSize().width()), float(d.msaaTex->pixelSize().height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, sizeof(vertexData) } });
cb->draw(3);
cb->endPass();
......@@ -307,6 +308,7 @@ void Window::customRender()
cb->beginPass(d.msaaRt, { 0.5f, 0.2f, 0, 1 }, { 1, 0 });
cb->setGraphicsPipeline(d.msaaTriPs);
cb->setViewport({ 0, 0, float(d.msaaTex->pixelSize().width()), float(d.msaaTex->pixelSize().height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, sizeof(vertexData) } });
cb->draw(3);
cb->endPass();
......@@ -316,9 +318,11 @@ void Window::customRender()
cb->beginPass(m_sc->currentFrameRenderTarget(), { 0.4f, 0.7f, 0.0f, 1.0f }, { 1.0f, 0 });
cb->setGraphicsPipeline(d.psLeft); // showing the non-msaa version
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 } }, d.ibuf, 0, QRhiCommandBuffer::IndexUInt16);
cb->drawIndexed(6);
cb->setGraphicsPipeline(d.psRight); // showing the msaa version, resolved in the shader
cb->setShaderResources();
cb->drawIndexed(6);
cb->endPass();
}
......@@ -53,6 +53,7 @@
#include <QLabel>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QCommandLineParser>
......@@ -277,7 +278,7 @@ void destroySharedResources()
class Window : public QWindow
{
public:
Window(const QString &title, const QColor &bgColor, int axis);
Window(const QString &title, const QColor &bgColor, int axis, bool noVSync);
~Window();
protected:
......@@ -291,7 +292,8 @@ protected:
bool event(QEvent *) override;
QColor m_bgColor;
int m_rotationAxis = 0;
int m_rotationAxis;
bool m_noVSync;
bool m_running = false;
bool m_notExposed = false;
......@@ -310,9 +312,10 @@ protected:
int m_opacityDir = -1;
};
Window::Window(const QString &title, const QColor &bgColor, int axis)
Window::Window(const QString &title, const QColor &bgColor, int axis, bool noVSync)
: m_bgColor(bgColor),
m_rotationAxis(axis)
m_rotationAxis(axis),
m_noVSync(noVSync)
{
switch (graphicsApi) {
case OpenGL:
......@@ -334,6 +337,12 @@ Window::Window(const QString &title, const QColor &bgColor, int axis)
break;
}
if (graphicsApi == OpenGL) {
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
fmt.setSwapInterval(noVSync ? 0 : 1);
setFormat(fmt);
}
resize(800, 600);
setTitle(title);
}
......@@ -396,6 +405,9 @@ void Window::init()
m_releasePool << m_ds;
m_sc->setWindow(this);
m_sc->setDepthStencil(m_ds);
if (m_noVSync)
m_sc->setFlags(QRhiSwapChain::NoVSync);
m_rp = m_sc->newCompatibleRenderPassDescriptor();
m_releasePool << m_rp;
m_sc->setRenderPassDescriptor(m_rp);
......@@ -493,6 +505,7 @@ void Window::render()
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 } });
cb->draw(3);
......@@ -503,11 +516,11 @@ void Window::render()
requestUpdate();
}
void createWindow()
void createWindow(bool noVSync)
{
static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::yellow, Qt::cyan, Qt::gray };
const int n = d.windows.count();
d.windows.append(new Window(QString::asprintf("Window #%d", n), colors[n % 6], n % 3));
d.windows.append(new Window(QString::asprintf("Window #%d%s", n, noVSync ? " (no vsync)" : ""), colors[n % 6], n % 3, noVSync));
d.windows.last()->show();
}
......@@ -586,18 +599,25 @@ int main(int argc, char **argv)
QPlainTextEdit *info = new QPlainTextEdit(
QLatin1String("This application tests rendering with the same QRhi instance (and so the same Vulkan/Metal/D3D device or OpenGL context) "
"to multiple windows via multiple QRhiSwapChain objects, from the same one thread. Some resources are shared across all windows."
"\n\nNote that the behavior may differ depending on the underlying graphics API implementation and the number of windows.\n"
"to multiple windows via multiple QRhiSwapChain objects, from the same one thread. Some resources are shared across all windows.\n"
"\nNote that the behavior may differ depending on the underlying graphics API implementation and the number of windows. "
"One challenge here is the vsync throttling: with the default vsync/fifo presentation mode the behavior may differ between "
"platforms, drivers, and APIs as we present different swapchains' images in a row on the same thread. As a potential solution, "
"setting NoVSync on the second, third, and later window swapchains is offered as an option.\n"
"\n\nUsing API: ") + graphicsApiName());
info->setReadOnly(true);
layout->addWidget(info);
QLabel *label = new QLabel(QLatin1String("Window count: 0"));
layout->addWidget(label);
QCheckBox *vsCb = new QCheckBox(QLatin1String("Set NoVSync on all swapchains except the first"));
vsCb->setChecked(false);
layout->addWidget(vsCb);
QPushButton *btn = new QPushButton(QLatin1String("New window"));
QObject::connect(btn, &QPushButton::clicked, btn, [label, &winCount] {
QObject::connect(btn, &QPushButton::clicked, btn, [label, vsCb, &winCount] {
winCount += 1;
label->setText(QString::asprintf("Window count: %d", winCount));
createWindow();
const bool noVSync = vsCb->isChecked() && winCount > 1;
createWindow(noVSync);
});
layout->addWidget(btn);
btn = new QPushButton(QLatin1String("Close window"));
......
......@@ -629,6 +629,7 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
cb->setGraphicsPipeline(m_ps);
cb->setViewport(QRhiViewport(0, 0, outputSize.width(), outputSize.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { m_vbuf, 0 }, { m_vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
......
......@@ -297,6 +297,7 @@ int main(int argc, char **argv)
cb->beginPass(rt, { 0, 1, 0, 1 }, { 1, 0 }, u);
cb->setGraphicsPipeline(ps);
cb->setViewport({ 0, 0, 1280, 720 });
cb->setShaderResources();
cb->setVertexInput(0, { { vbuf, 0 } });
cb->draw(3);
......
......@@ -124,6 +124,7 @@ QString graphicsApiName()
QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers;
int sampleCount = 1;
QRhiSwapChain::Flags scFlags = 0;
QRhi::EndFrameFlags endFrameFlags = 0;
class Window : public QWindow
{
......@@ -413,7 +414,7 @@ void Window::render()
customRender();
m_r->endFrame(m_sc);
m_r->endFrame(m_sc, endFrameFlags);
#ifdef Q_OS_DARWIN
if (!scFlags.testFlag(QRhiSwapChain::NoVSync))
......@@ -482,6 +483,8 @@ int main(int argc, char **argv)
fmt.setSamples(sampleCount);
if (scFlags.testFlag(QRhiSwapChain::NoVSync))
fmt.setSwapInterval(0);
if (scFlags.testFlag(QRhiSwapChain::sRGB))
fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace);
QSurfaceFormat::setDefaultFormat(fmt);
// Vulkan setup.
......
......@@ -481,6 +481,7 @@ void Window::render()
cb->setGraphicsPipeline(ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { vbuf, 0 } }, ibuf, 0, QRhiCommandBuffer::IndexUInt16);
cb->drawIndexed(6);
......
......@@ -280,6 +280,7 @@ void Window::customRender()
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
cb->setVertexInput(0, { { d.vbuf, 0 }, { d.vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
......
......@@ -147,8 +147,9 @@ void QuadRenderer::queueResourceUpdates(QRhiResourceUpdateBatch *resourceUpdates
void QuadRenderer::queueDraw(QRhiCommandBuffer *cb, const QSize &/*outputSizeInPixels*/)
{
cb->setGraphicsPipeline(m_ps, m_srb);
cb->setGraphicsPipeline(m_ps);
//cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources(m_srb);
cb->setVertexInput(0, { { m_vbuf, 0 } }, m_ibuf, 0, QRhiCommandBuffer::IndexUInt16);
cb->drawIndexed(6);
}
......@@ -227,6 +227,7 @@ void TexturedCubeRenderer::queueDraw(QRhiCommandBuffer *cb, const QSize &outputS
{
cb->setGraphicsPipeline(m_ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { m_vbuf, 0 }, { m_vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
}
......@@ -304,6 +304,7 @@ void TriangleOnCubeRenderer::queueDraw(QRhiCommandBuffer *cb, const QSize &outpu
{
cb->setGraphicsPipeline(m_ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { m_vbuf, 0 }, { m_vbuf, 36 * 3 * sizeof(float) } });
cb->draw(36);
}
......@@ -167,7 +167,7 @@ void TriangleRenderer::queueResourceUpdates(QRhiResourceUpdateBatch *resourceUpd
#if 0
static int messWithBufferTrigger = 0;
// recreate the underlying VkBuffer every second frame
// to exercise setGraphicsPipeline's built-in smartness
// to exercise setShaderResources' built-in smartness
if (!(messWithBufferTrigger & 1)) {
m_ubuf->release();
m_ubuf->build();
......@@ -203,6 +203,7 @@ void TriangleRenderer::queueDraw(QRhiCommandBuffer *cb, const QSize &outputSizeI
{
cb->setGraphicsPipeline(m_ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
cb->setVertexInput(0, { { m_vbuf, 0 } });
cb->draw(3);
}
......@@ -65,6 +65,7 @@
#include <QRhiProfiler>
#define PROFILE_TO_FILE
//#define SKIP_PRESENT
//#define USE_MSAA
//#define USE_SRGB_SWAPCHAIN
//#define READBACK_SWAPCHAIN
......@@ -92,6 +93,10 @@ void preInit()
d.profOut.open(QIODevice::WriteOnly);
#endif
#ifdef SKIP_PRESENT
endFrameFlags |= QRhi::SkipPresent;
#endif
#ifdef USE_MSAA
sampleCount = 4; // enable 4x MSAA (except for the render-to-texture pass)
#endif
......@@ -156,6 +161,11 @@ void Window::customInit()
qDebug("isFeatureSupported(Instancing): %d", m_r->isFeatureSupported(QRhi::Instancing));
qDebug("isFeatureSupported(CustomInstanceStepRate): %d", m_r->isFeatureSupported(QRhi::CustomInstanceStepRate));
qDebug("isFeatureSupported(PrimitiveRestart): %d", m_r->isFeatureSupported(QRhi::PrimitiveRestart));
qDebug("isFeatureSupported(GeometryShaders): %d", m_r->isFeatureSupported(QRhi::GeometryShaders));
qDebug("isFeatureSupported(TessellationShaders): %d", m_r->isFeatureSupported(QRhi::TessellationShaders));
qDebug("isFeatureSupported(NonDynamicUniformBuffers): %d", m_r->isFeatureSupported(QRhi::NonDynamicUniformBuffers));
qDebug("isFeatureSupported(NonFourAlignedEffectiveIndexBufferOffset): %d", m_r->isFeatureSupported(QRhi::NonFourAlignedEffectiveIndexBufferOffset));
qDebug("isFeatureSupported(NPOTTextureRepeat): %d", m_r->isFeatureSupported(QRhi::NPOTTextureRepeat));
qDebug("Min 2D texture width/height: %d", m_r->resourceSizeLimit(QRhi::TextureSizeMin));
qDebug("Max 2D texture width/height: %d", m_r->resourceSizeLimit(QRhi::TextureSizeMax));
}
......
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