diff options
Diffstat (limited to 'tests/manual/rhi')
24 files changed, 353 insertions, 70 deletions
diff --git a/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp b/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp index 27dd8097ad..af454c2487 100644 --- a/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp +++ b/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp @@ -165,11 +165,13 @@ void Window::customRender() u->updateDynamicBuffer(d.ubuf, 64, 4, &flip); } if (!d.compressedData.isEmpty()) { - QRhiTextureUploadDescription desc; + QVarLengthArray<QRhiTextureUploadEntry, 16> descEntries; for (int i = 0; i < d.compressedData.count(); ++i) { QRhiTextureSubresourceUploadDescription image(d.compressedData[i].constData(), d.compressedData[i].size()); - desc.append({ 0, i, image }); + descEntries.append({ 0, i, image }); } + QRhiTextureUploadDescription desc; + desc.setEntries(descEntries.cbegin(), descEntries.cend()); u->uploadTexture(d.tex, desc); d.compressedData.clear(); } @@ -182,7 +184,7 @@ void Window::customRender() QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer(); const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); diff --git a/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp b/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp index 87d1e7646a..4931c8eaa1 100644 --- a/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp +++ b/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp @@ -197,7 +197,7 @@ void Window::customRender() QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer(); const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); diff --git a/tests/manual/rhi/computebuffer/computebuffer.cpp b/tests/manual/rhi/computebuffer/computebuffer.cpp index 2a3e0b92b5..c991a11438 100644 --- a/tests/manual/rhi/computebuffer/computebuffer.cpp +++ b/tests/manual/rhi/computebuffer/computebuffer.cpp @@ -195,7 +195,7 @@ void Window::customRender() cb->endComputePass(); // graphics pass - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }); cb->setGraphicsPipeline(d.graphicsPipeline); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); QRhiCommandBuffer::VertexInput vbufBinding(d.sbuf, 0); diff --git a/tests/manual/rhi/computeimage/computeimage.cpp b/tests/manual/rhi/computeimage/computeimage.cpp index 51bf216c5a..a6c860f8ee 100644 --- a/tests/manual/rhi/computeimage/computeimage.cpp +++ b/tests/manual/rhi/computeimage/computeimage.cpp @@ -217,7 +217,7 @@ void Window::customRender() cb->dispatch(d.imageSize.width() / 16, d.imageSize.height() / 16, 1); cb->endComputePass(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); cb->setShaderResources(); diff --git a/tests/manual/rhi/cubemap/cubemap.cpp b/tests/manual/rhi/cubemap/cubemap.cpp index df302736a2..fe6ac9762e 100644 --- a/tests/manual/rhi/cubemap/cubemap.cpp +++ b/tests/manual/rhi/cubemap/cubemap.cpp @@ -168,7 +168,7 @@ void Window::customRender() // no translation u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData()); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height())); cb->setShaderResources(); diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp new file mode 100644 index 0000000000..25a7c64c8a --- /dev/null +++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// This is a test for scissoring. Based on the cubemap test (because there the +// rendering covers the entire viewport which is what we need here). The +// scissor rectangle moves first up, then down, then from the center to the +// left and then to right. The important part is to ensure that the behavior +// identical between all backends, especially when the rectangle is partly or +// fully off window. + +#include "../shared/examplefw.h" +#include "../shared/cube.h" + +struct { + QVector<QRhiResource *> releasePool; + QRhiBuffer *vbuf = nullptr; + QRhiBuffer *ubuf = nullptr; + QRhiTexture *tex = nullptr; + QRhiSampler *sampler = nullptr; + QRhiShaderResourceBindings *srb = nullptr; + QRhiGraphicsPipeline *ps = nullptr; + QRhiResourceUpdateBatch *initialUpdates = nullptr; + + QPoint scissorBottomLeft; + QSize scissorSize; + int scissorAnimState = 0; + QSize outputSize; +} d; + +void Window::customInit() +{ + d.vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube)); + d.vbuf->build(); + d.releasePool << d.vbuf; + + d.ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64); + d.ubuf->build(); + d.releasePool << d.ubuf; + + const QSize cubeMapSize(512, 512); + d.tex = m_r->newTexture(QRhiTexture::RGBA8, cubeMapSize, 1, QRhiTexture::CubeMap); + d.releasePool << d.tex; + d.tex->build(); + + d.initialUpdates = m_r->nextResourceUpdateBatch(); + d.initialUpdates->uploadStaticBuffer(d.vbuf, cube); + + QImage img = QImage(":/c.png").mirrored().convertToFormat(QImage::Format_RGBA8888); + // just use the same image for all faces for now + QRhiTextureSubresourceUploadDescription subresDesc(img); + QRhiTextureUploadDescription desc({ + { 0, 0, subresDesc }, // +X + { 1, 0, subresDesc }, // -X + { 2, 0, subresDesc }, // +Y + { 3, 0, subresDesc }, // -Y + { 4, 0, subresDesc }, // +Z + { 5, 0, subresDesc } // -Z + }); + d.initialUpdates->uploadTexture(d.tex, desc); + + d.sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, + QRhiSampler::Repeat, QRhiSampler::Repeat); + d.releasePool << d.sampler; + d.sampler->build(); + + d.srb = m_r->newShaderResourceBindings(); + d.releasePool << d.srb; + d.srb->setBindings({ + QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf), + QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler) + }); + d.srb->build(); + + d.ps = m_r->newGraphicsPipeline(); + d.releasePool << d.ps; + + d.ps->setFlags(QRhiGraphicsPipeline::UsesScissor); + + d.ps->setDepthTest(true); + d.ps->setDepthWrite(true); + d.ps->setDepthOp(QRhiGraphicsPipeline::LessOrEqual); + + d.ps->setCullMode(QRhiGraphicsPipeline::Front); // we are inside the cube so cull front, not back + d.ps->setFrontFace(QRhiGraphicsPipeline::CCW); // front is ccw in the cube data + + QShader vs = getShader(QLatin1String(":/cubemap.vert.qsb")); + Q_ASSERT(vs.isValid()); + QShader fs = getShader(QLatin1String(":/cubemap.frag.qsb")); + Q_ASSERT(fs.isValid()); + d.ps->setShaderStages({ + { QRhiShaderStage::Vertex, vs }, + { QRhiShaderStage::Fragment, fs } + }); + + QRhiVertexInputLayout inputLayout; + inputLayout.setBindings({ + { 3 * sizeof(float) } + }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float3, 0 } + }); + + d.ps->setVertexInputLayout(inputLayout); + d.ps->setShaderResourceBindings(d.srb); + d.ps->setRenderPassDescriptor(m_rp); + + d.ps->build(); + + d.scissorAnimState = 0; +} + +void Window::customRelease() +{ + qDeleteAll(d.releasePool); + d.releasePool.clear(); +} + +static void advanceScissor() +{ + switch (d.scissorAnimState) { + case 1: // up + d.scissorBottomLeft.setX(d.outputSize.width() / 4); + d.scissorBottomLeft.ry() += 1; + if (d.scissorBottomLeft.y() > d.outputSize.height() + 100) + d.scissorAnimState = 2; + break; + case 2: // down + d.scissorBottomLeft.ry() -= 1; + if (d.scissorBottomLeft.y() < -d.scissorSize.height() - 100) + d.scissorAnimState = 3; + break; + case 3: // left + d.scissorBottomLeft.setY(d.outputSize.height() / 4); + d.scissorBottomLeft.rx() += 1; + if (d.scissorBottomLeft.x() > d.outputSize.width() + 100) + d.scissorAnimState = 4; + break; + case 4: // right + d.scissorBottomLeft.rx() -= 1; + if (d.scissorBottomLeft.x() < -d.scissorSize.width() - 100) + d.scissorAnimState = 1; + break; + } + + qDebug() << "scissor bottom-left" << d.scissorBottomLeft << "size" << d.scissorSize; +} + +void Window::customRender() +{ + const QSize outputSizeInPixels = m_sc->currentPixelSize(); + QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer(); + QRhiResourceUpdateBatch *u = m_r->nextResourceUpdateBatch(); + + if (d.initialUpdates) { + u->merge(d.initialUpdates); + d.initialUpdates->release(); + d.initialUpdates = nullptr; + } + + d.outputSize = outputSizeInPixels; + if (d.scissorAnimState == 0) { + d.scissorBottomLeft = QPoint(outputSizeInPixels.width() / 4, 0); + d.scissorSize = QSize(outputSizeInPixels.width() / 2, outputSizeInPixels.height() / 2); + d.scissorAnimState = 1; + } + + QMatrix4x4 mvp = m_r->clipSpaceCorrMatrix(); + mvp.perspective(90.0f, outputSizeInPixels.width() / (float) outputSizeInPixels.height(), 0.01f, 1000.0f); + // cube vertices go from -1..1 + mvp.scale(10); + static float rx = 0; + mvp.rotate(rx, 1, 0, 0); + rx += 0.5f; + // no translation + u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData()); + + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); + cb->setGraphicsPipeline(d.ps); + cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height())); + + // Apply a scissor rectangle that moves around on the screen, also + // exercising the out of screen (negative x or y) case. + cb->setScissor(QRhiScissor(d.scissorBottomLeft.x(), d.scissorBottomLeft.y(), + d.scissorSize.width(), d.scissorSize.height())); + + cb->setShaderResources(); + + const QRhiCommandBuffer::VertexInput vbufBinding(d.vbuf, 0); + cb->setVertexInput(0, 1, &vbufBinding); + cb->draw(36); + cb->endPass(); + + advanceScissor(); +} diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro new file mode 100644 index 0000000000..1f02bda87a --- /dev/null +++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro @@ -0,0 +1,8 @@ +TEMPLATE = app + +QT += gui-private + +SOURCES = \ + cubemap_scissor.cpp + +RESOURCES = cubemap_scissor.qrc diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc new file mode 100644 index 0000000000..8a0ae17dc8 --- /dev/null +++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file alias="cubemap.vert.qsb">../cubemap/cubemap.vert.qsb</file> + <file alias="cubemap.frag.qsb">../cubemap/cubemap.frag.qsb</file> + <file alias="c.png">../cubemap/c.png</file> +</qresource> +</RCC> diff --git a/tests/manual/rhi/floattexture/floattexture.cpp b/tests/manual/rhi/floattexture/floattexture.cpp index 16e58ff00f..0d24860c78 100644 --- a/tests/manual/rhi/floattexture/floattexture.cpp +++ b/tests/manual/rhi/floattexture/floattexture.cpp @@ -317,7 +317,7 @@ void Window::customRender() } const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); cb->setShaderResources(); diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp index 3c39ff1719..ea1fefc308 100644 --- a/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp +++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp @@ -298,7 +298,7 @@ void Window::init() m_sc = m_r->newSwapChain(); // allow depth-stencil, although we do not actually enable depth test/write for the triangle m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(), // no need to set the size yet + QSize(), // no need to set the size here, due to UsedWithSwapChainOnly 1, QRhiRenderBuffer::UsedWithSwapChainOnly); releasePool << m_ds; @@ -376,16 +376,12 @@ void Window::releaseResources() void Window::resizeSwapChain() { - const QSize outputSize = m_sc->surfacePixelSize(); - - m_ds->setPixelSize(outputSize); - m_ds->build(); // == m_ds->release(); m_ds->build(); - - m_hasSwapChain = m_sc->buildOrResize(); + m_hasSwapChain = m_sc->buildOrResize(); // also handles m_ds m_elapsedMs = 0; m_elapsedCount = 0; + const QSize outputSize = m_sc->currentPixelSize(); m_proj = m_r->clipSpaceCorrMatrix(); m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 100.0f); m_proj.translate(0, 0, -4); diff --git a/tests/manual/rhi/instancing/instancing.cpp b/tests/manual/rhi/instancing/instancing.cpp index 87029e541c..bdafbd81bc 100644 --- a/tests/manual/rhi/instancing/instancing.cpp +++ b/tests/manual/rhi/instancing/instancing.cpp @@ -161,7 +161,7 @@ void Window::customRender() u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData()); } - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); cb->setShaderResources(); diff --git a/tests/manual/rhi/mrt/mrt.cpp b/tests/manual/rhi/mrt/mrt.cpp index b80af7ac87..dfec5bb1d1 100644 --- a/tests/manual/rhi/mrt/mrt.cpp +++ b/tests/manual/rhi/mrt/mrt.cpp @@ -143,10 +143,10 @@ void Window::customInit() } QRhiTextureRenderTargetDescription rtDesc; - QVector<QRhiColorAttachment> att; + QRhiColorAttachment att[ATTCOUNT]; for (int i = 0; i < ATTCOUNT; ++i) - att.append(QRhiColorAttachment(d.colData[i].tex)); - rtDesc.setColorAttachments(att); + att[i] = QRhiColorAttachment(d.colData[i].tex); + rtDesc.setColorAttachments(att, att + ATTCOUNT); d.rt = m_r->newTextureRenderTarget(rtDesc); d.releasePool << d.rt; d.rtRp = d.rt->newCompatibleRenderPassDescriptor(); @@ -200,12 +200,10 @@ void Window::customInit() { QRhiShaderStage::Vertex, getShader(QLatin1String(":/mrt.vert.qsb")) }, { QRhiShaderStage::Fragment, getShader(QLatin1String(":/mrt.frag.qsb")) } }); - QVector<QRhiGraphicsPipeline::TargetBlend> blends; - for (int i = 0; i < ATTCOUNT; ++i) { - QRhiGraphicsPipeline::TargetBlend blend; - blends.append(blend); - } - d.triPs->setTargetBlends(blends); + + QRhiGraphicsPipeline::TargetBlend blends[ATTCOUNT]; // defaults to blending == false + d.triPs->setTargetBlends(blends, blends + ATTCOUNT); + inputLayout.setBindings({ { 5 * sizeof(float) } }); @@ -283,7 +281,7 @@ void Window::customRender() } const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); vbufBinding.second = 0; diff --git a/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp b/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp index b77a27b1b5..27dabb2276 100644 --- a/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp +++ b/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp @@ -248,7 +248,7 @@ void Window::customRender() // onscreen (quad) const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); cb->setShaderResources(); diff --git a/tests/manual/rhi/msaatexture/msaatexture.cpp b/tests/manual/rhi/msaatexture/msaatexture.cpp index 46a9b2830c..2fb466c8d6 100644 --- a/tests/manual/rhi/msaatexture/msaatexture.cpp +++ b/tests/manual/rhi/msaatexture/msaatexture.cpp @@ -240,7 +240,7 @@ void Window::customInit() #else d.msaaTriPs->setSampleCount(1); #endif - d.msaaTriPs->setShaderStages(d.triPs->shaderStages()); + d.msaaTriPs->setShaderStages(d.triPs->cbeginShaderStages(), d.triPs->cendShaderStages()); d.msaaTriPs->setVertexInputLayout(d.triPs->vertexInputLayout()); d.msaaTriPs->setShaderResourceBindings(d.triSrb); d.msaaTriPs->setRenderPassDescriptor(d.msaaRtRp); @@ -315,7 +315,7 @@ void Window::customRender() // onscreen const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }); cb->setGraphicsPipeline(d.psLeft); // showing the non-msaa version cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); cb->setShaderResources(); diff --git a/tests/manual/rhi/multiwindow/multiwindow.cpp b/tests/manual/rhi/multiwindow/multiwindow.cpp index 4c5d5c345a..4d5de16a58 100644 --- a/tests/manual/rhi/multiwindow/multiwindow.cpp +++ b/tests/manual/rhi/multiwindow/multiwindow.cpp @@ -400,7 +400,7 @@ void Window::init() { m_sc = r.r->newSwapChain(); m_ds = r.r->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(), // no need to set the size yet + QSize(), 1, QRhiRenderBuffer::UsedWithSwapChainOnly); m_releasePool << m_ds; @@ -427,13 +427,9 @@ void Window::releaseResources() void Window::resizeSwapChain() { - const QSize outputSize = m_sc->surfacePixelSize(); - - m_ds->setPixelSize(outputSize); - m_ds->build(); - m_hasSwapChain = m_sc->buildOrResize(); + const QSize outputSize = m_sc->currentPixelSize(); m_proj = r.r->clipSpaceCorrMatrix(); m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f); m_proj.translate(0, 0, -4); diff --git a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp index 53185bddb2..37c6cd04c3 100644 --- a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp +++ b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp @@ -441,7 +441,7 @@ void Renderer::init() { m_sc = r->newSwapChain(); m_ds = r->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(), // no need to set the size yet + QSize(), 1, QRhiRenderBuffer::UsedWithSwapChainOnly); m_releasePool << m_ds; @@ -543,11 +543,9 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent) auto buildOrResizeSwapChain = [this] { qDebug() << "renderer" << this << "build or resize swapchain for window" << window; - const QSize outputSize = m_sc->surfacePixelSize(); - qDebug() << " size is" << outputSize; - m_ds->setPixelSize(outputSize); - m_ds->build(); m_hasSwapChain = m_sc->buildOrResize(); + const QSize outputSize = m_sc->currentPixelSize(); + qDebug() << " size is" << outputSize; m_proj = r->clipSpaceCorrMatrix(); m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 100.0f); m_proj.translate(0, 0, -4); diff --git a/tests/manual/rhi/rhi.pro b/tests/manual/rhi/rhi.pro index d3661ff169..4768ee1c6d 100644 --- a/tests/manual/rhi/rhi.pro +++ b/tests/manual/rhi/rhi.pro @@ -8,6 +8,7 @@ SUBDIRS += \ msaatexture \ msaarenderbuffer \ cubemap \ + cubemap_scissor \ multiwindow \ multiwindow_threaded \ triquadcube \ diff --git a/tests/manual/rhi/shadowmap/buildshaders.sh b/tests/manual/rhi/shadowmap/buildshaders.sh index c4d17841e6..8991bb074a 100755 --- a/tests/manual/rhi/shadowmap/buildshaders.sh +++ b/tests/manual/rhi/shadowmap/buildshaders.sh @@ -1,3 +1,4 @@ +#!/bin/sh qsb --glsl "120,300 es" --hlsl 50 --msl 12 shadowmap.vert -o shadowmap.vert.qsb qsb --glsl "120,300 es" --hlsl 50 --msl 12 shadowmap.frag -o shadowmap.frag.qsb qsb --glsl "120,300 es" --hlsl 50 --msl 12 main.vert -o main.vert.qsb diff --git a/tests/manual/rhi/shadowmap/shadowmap.cpp b/tests/manual/rhi/shadowmap/shadowmap.cpp index 9146be5cc9..424a8b3783 100644 --- a/tests/manual/rhi/shadowmap/shadowmap.cpp +++ b/tests/manual/rhi/shadowmap/shadowmap.cpp @@ -296,7 +296,7 @@ void Window::customRender() cb->endPass(); // main pass - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); enqueueScene(cb, d.srb, oneRoundedUniformBlockSize, 0); diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 1a29ef5f7e..d28bbea0a8 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -58,6 +58,7 @@ #include <QPlatformSurfaceEvent> #include <QElapsedTimer> #include <QTimer> +#include <QLoggingCategory> #include <QtGui/private/qshader_p.h> #include <QFile> @@ -70,7 +71,6 @@ #endif #if QT_CONFIG(vulkan) -#include <QLoggingCategory> #include <QtGui/private/qrhivulkan_p.h> #endif @@ -126,6 +126,8 @@ int sampleCount = 1; QRhiSwapChain::Flags scFlags = 0; QRhi::BeginFrameFlags beginFrameFlags = 0; QRhi::EndFrameFlags endFrameFlags = 0; +int framesUntilTdr = -1; +bool transparentBackground = false; class Window : public QWindow { @@ -166,6 +168,8 @@ protected: QOffscreenSurface *m_fallbackSurface = nullptr; #endif + QColor m_clearColor; + friend int main(int, char**); }; @@ -193,6 +197,8 @@ Window::Window() default: break; } + + m_clearColor = transparentBackground ? Qt::transparent : QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f); } Window::~Window() @@ -278,6 +284,10 @@ void Window::init() if (graphicsApi == D3D11) { QRhiD3D11InitParams params; params.enableDebugLayer = true; + if (framesUntilTdr > 0) { + params.framesUntilKillingDeviceViaTdr = framesUntilTdr; + params.repeatDeviceKill = true; + } m_r = QRhi::create(QRhi::D3D11, ¶ms, rhiFlags); } #endif @@ -297,7 +307,7 @@ void Window::init() m_sc = m_r->newSwapChain(); // allow depth-stencil, although we do not actually enable depth test/write for the triangle m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(), // no need to set the size yet + QSize(), // no need to set the size here, due to UsedWithSwapChainOnly sampleCount, QRhiRenderBuffer::UsedWithSwapChainOnly); m_sc->setWindow(this); @@ -334,16 +344,12 @@ void Window::releaseResources() void Window::resizeSwapChain() { - const QSize outputSize = m_sc->surfacePixelSize(); - - m_ds->setPixelSize(outputSize); - m_ds->build(); // == m_ds->release(); m_ds->build(); - - m_hasSwapChain = m_sc->buildOrResize(); + m_hasSwapChain = m_sc->buildOrResize(); // also handles m_ds m_frameCount = 0; m_timer.restart(); + const QSize outputSize = m_sc->currentPixelSize(); m_proj = m_r->clipSpaceCorrMatrix(); m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f); m_proj.translate(0, 0, -4); @@ -434,6 +440,8 @@ int main(int argc, char **argv) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + QLoggingCategory::setFilterRules(QLatin1String("qt.rhi.*=true")); + // Defaults. #if defined(Q_OS_WIN) graphicsApi = D3D11; @@ -461,8 +469,20 @@ int main(int argc, char **argv) // Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and // QCoreApplication::quit() (e.g. what a menu widget would do) is important. // Use this parameter for the latter. - QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self destruct after 5 seconds")); + QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds.")); cmdLineParser.addOption(sdOption); + // Attempt testing device lost situations on D3D at least. + QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. " + "(generate a device reset every <count> frames when on D3D11)"), + QLatin1String("count")); + cmdLineParser.addOption(tdrOption); + // Allow testing preferring the software adapter (D3D). + QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. " + "Only applicable with some APIs and platforms.")); + cmdLineParser.addOption(swOption); + // Allow testing having a semi-transparent window. + QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent")); + cmdLineParser.addOption(transparentOption); cmdLineParser.process(app); if (cmdLineParser.isSet(nullOption)) @@ -479,6 +499,11 @@ int main(int argc, char **argv) qDebug("Selected graphics API is %s", qPrintable(graphicsApiName())); qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText())); + if (cmdLineParser.isSet(transparentOption)) { + transparentBackground = true; + scFlags |= QRhiSwapChain::SurfaceHasPreMulAlpha; + } + #ifdef EXAMPLEFW_PREINIT void preInit(); preInit(); @@ -494,6 +519,9 @@ int main(int argc, char **argv) fmt.setSwapInterval(0); if (scFlags.testFlag(QRhiSwapChain::sRGB)) fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace); + // Exception: The alpha size is not necessarily OpenGL specific. + if (transparentBackground) + fmt.setAlphaBufferSize(8); QSurfaceFormat::setDefaultFormat(fmt); // Vulkan setup. @@ -521,6 +549,12 @@ int main(int argc, char **argv) } #endif + if (cmdLineParser.isSet(tdrOption)) + framesUntilTdr = cmdLineParser.value(tdrOption).toInt(); + + if (cmdLineParser.isSet(swOption)) + rhiFlags |= QRhi::PreferSoftwareRenderer; + // Create and show the window. Window w; #if QT_CONFIG(vulkan) diff --git a/tests/manual/rhi/texuploads/texuploads.cpp b/tests/manual/rhi/texuploads/texuploads.cpp index dc20ffb1fc..4c10a6b965 100644 --- a/tests/manual/rhi/texuploads/texuploads.cpp +++ b/tests/manual/rhi/texuploads/texuploads.cpp @@ -68,6 +68,8 @@ struct { QRhiTexture *newTex = nullptr; QRhiTexture *importedTex = nullptr; int testStage = 0; + + QRhiShaderResourceBinding bindings[2]; } d; void Window::customInit() @@ -100,10 +102,10 @@ void Window::customInit() d.srb = m_r->newShaderResourceBindings(); d.releasePool << d.srb; - d.srb->setBindings({ - QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf), - QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler) - }); + + d.bindings[0] = QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf); + d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler); + d.srb->setBindings(d.bindings, d.bindings + 2); d.srb->build(); d.ps = m_r->newGraphicsPipeline(); @@ -211,9 +213,8 @@ void Window::customRender() u->copyTexture(d.newTex, d.tex, desc); // Now replace d.tex with d.newTex as the shader resource. - auto bindings = d.srb->bindings(); - bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler); - d.srb->setBindings(bindings); + d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler); + d.srb->setBindings(d.bindings, d.bindings + 2); // "rebuild", whatever that means for a given backend. This srb is // already live as the ps in the setGraphicsPipeline references it, // but that's fine. Changes will be picked up automatically. @@ -259,9 +260,8 @@ void Window::customRender() // underneath (owned by d.tex) // switch to showing d.importedTex - auto bindings = d.srb->bindings(); - bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.importedTex, d.sampler); - d.srb->setBindings(bindings); + d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.importedTex, d.sampler); + d.srb->setBindings(d.bindings, d.bindings + 2); d.srb->build(); } else { qWarning("Accessing native texture object is not supported"); @@ -270,9 +270,8 @@ void Window::customRender() // Exercise uploading uncompressed data without a QImage. if (d.testStage == 7) { - auto bindings = d.srb->bindings(); - bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler); - d.srb->setBindings(bindings); + d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler); + d.srb->setBindings(d.bindings, d.bindings + 2); d.srb->build(); const QSize sz(221, 139); @@ -296,7 +295,7 @@ void Window::customRender() QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer(); const QSize outputSizeInPixels = m_sc->currentPixelSize(); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->setGraphicsPipeline(d.ps); cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) }); diff --git a/tests/manual/rhi/triquadcube/texturedcuberenderer.cpp b/tests/manual/rhi/triquadcube/texturedcuberenderer.cpp index 3f15881e2d..8c5845d4fc 100644 --- a/tests/manual/rhi/triquadcube/texturedcuberenderer.cpp +++ b/tests/manual/rhi/triquadcube/texturedcuberenderer.cpp @@ -181,16 +181,18 @@ void TexturedCubeRenderer::queueResourceUpdates(QRhiResourceUpdateBatch *resourc if (!m_image.isNull()) { if (MIPMAP) { - QRhiTextureUploadDescription desc; + QVarLengthArray<QRhiTextureUploadEntry, 16> descEntries; if (!AUTOGENMIPMAP) { // the ghetto mipmap generator... for (int i = 0, ie = m_r->mipLevelsForSize(m_image.size()); i != ie; ++i) { QImage image = m_image.scaled(m_r->sizeForMipLevel(i, m_image.size())); - desc.append({ 0, i, image }); + descEntries.append({ 0, i, image }); } } else { - desc.append({ 0, 0, m_image }); + descEntries.append({ 0, 0, m_image }); } + QRhiTextureUploadDescription desc; + desc.setEntries(descEntries.cbegin(), descEntries.cend()); resourceUpdates->uploadTexture(m_tex, desc); if (AUTOGENMIPMAP) resourceUpdates->generateMips(m_tex); diff --git a/tests/manual/rhi/triquadcube/trianglerenderer.cpp b/tests/manual/rhi/triquadcube/trianglerenderer.cpp index 0980acca49..5d932aea52 100644 --- a/tests/manual/rhi/triquadcube/trianglerenderer.cpp +++ b/tests/manual/rhi/triquadcube/trianglerenderer.cpp @@ -94,11 +94,11 @@ void TriangleRenderer::initResources(QRhiRenderPassDescriptor *rp) QRhiGraphicsPipeline::TargetBlend premulAlphaBlend; // convenient defaults... premulAlphaBlend.enable = true; - QVector<QRhiGraphicsPipeline::TargetBlend> rtblends; + QVarLengthArray<QRhiGraphicsPipeline::TargetBlend, 4> rtblends; for (int i = 0; i < m_colorAttCount; ++i) rtblends << premulAlphaBlend; - m_ps->setTargetBlends(rtblends); + m_ps->setTargetBlends(rtblends.cbegin(), rtblends.cend()); m_ps->setSampleCount(m_sampleCount); if (m_depthWrite) { // TriangleOnCube may want to exercise this diff --git a/tests/manual/rhi/triquadcube/triquadcube.cpp b/tests/manual/rhi/triquadcube/triquadcube.cpp index 76dbe558ab..252ec63e21 100644 --- a/tests/manual/rhi/triquadcube/triquadcube.cpp +++ b/tests/manual/rhi/triquadcube/triquadcube.cpp @@ -230,7 +230,7 @@ void Window::customRender() if (!d.onScreenOnly) d.liveTexCubeRenderer.queueResourceUpdates(u); - cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u); + cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u); cb->debugMarkBegin(QByteArrayLiteral("Triangle")); d.triRenderer.queueDraw(cb, outputSize); cb->debugMarkEnd(); |