summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/rhi/qrhi/tst_qrhi.cpp')
-rw-r--r--tests/auto/gui/rhi/qrhi/tst_qrhi.cpp319
1 files changed, 318 insertions, 1 deletions
diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
index 533d6b17b1..302630ae15 100644
--- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
+++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
@@ -52,7 +52,7 @@
# define TST_D3D11
#endif
-#ifdef Q_OS_DARWIN
+#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
# include <QtGui/private/qrhimetal_p.h>
# define TST_MTL
#endif
@@ -91,6 +91,10 @@ private slots:
void renderToTextureTexturedQuadAndUniformBuffer();
void renderToWindowSimple_data();
void renderToWindowSimple();
+ void srbLayoutCompatibility_data();
+ void srbLayoutCompatibility();
+ void renderPassDescriptorCompatibility_data();
+ void renderPassDescriptorCompatibility();
private:
struct {
@@ -1728,5 +1732,318 @@ void tst_QRhi::renderToWindowSimple()
QVERIFY(redCount < blueCount);
}
+void tst_QRhi::srbLayoutCompatibility_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::srbLayoutCompatibility()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing texture resource updates");
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512)));
+ QVERIFY(texture->build());
+ QScopedPointer<QRhiSampler> sampler(rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ QVERIFY(sampler->build());
+ QScopedPointer<QRhiSampler> otherSampler(rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ QVERIFY(otherSampler->build());
+ QScopedPointer<QRhiBuffer> buf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 1024));
+ QVERIFY(buf->build());
+ QScopedPointer<QRhiBuffer> otherBuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 256));
+ QVERIFY(otherBuf->build());
+
+ // empty (compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ QVERIFY(srb2->build());
+
+ QVERIFY(srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // different count (not compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::sampledTexture(0, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(!srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(!srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // full match (compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ srb1->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // different visibility (not compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ srb1->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, buf.data()),
+ });
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(!srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(!srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // different binding points (not compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ srb1->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ });
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(1, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(!srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(!srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // different buffer region offset and size (compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ srb1->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data(), rhi->ubufAligned(1), 128),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(srb2->isLayoutCompatible(srb1.data()));
+ }
+
+ // different resources (compatible)
+ {
+ QScopedPointer<QRhiShaderResourceBindings> srb1(rhi->newShaderResourceBindings());
+ srb1->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, otherBuf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), otherSampler.data())
+ });
+ QVERIFY(srb1->build());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb2(rhi->newShaderResourceBindings());
+ srb2->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage, buf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, texture.data(), sampler.data())
+ });
+ QVERIFY(srb2->build());
+
+ QVERIFY(srb1->isLayoutCompatible(srb2.data()));
+ QVERIFY(srb2->isLayoutCompatible(srb1.data()));
+ }
+}
+
+void tst_QRhi::renderPassDescriptorCompatibility_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderPassDescriptorCompatibility()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing texture resource updates");
+
+ // Note that checking compatibility is only relevant with backends where
+ // there is a concept of renderpass descriptions (Vulkan, and partially
+ // Metal). It is perfectly fine for isCompatible() to always return true
+ // when that is not the case (D3D11, OpenGL). Hence the 'if (Vulkan or
+ // Metal)' for all the negative tests. Also note "partial" for Metal:
+ // resolve textures for examples have no effect on compatibility with Metal.
+
+ // tex and tex2 have the same format
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget));
+ QVERIFY(tex->build());
+ QScopedPointer<QRhiTexture> tex2(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget));
+ QVERIFY(tex2->build());
+
+ QScopedPointer<QRhiRenderBuffer> ds(rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(512, 512)));
+ QVERIFY(ds->build());
+
+ // two texture rendertargets with tex and tex2 as color0 (compatible)
+ {
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ tex.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget({ tex2.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ QVERIFY(rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(rpDesc2->isCompatible(rpDesc.data()));
+ }
+
+ // two texture rendertargets with tex and tex2 as color0, and a depth-stencil attachment as well (compatible)
+ {
+ QRhiTextureRenderTargetDescription desc({ tex.data() }, ds.data());
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(desc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget(desc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ QVERIFY(rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(rpDesc2->isCompatible(rpDesc.data()));
+ }
+
+ // now one of them does not have the ds attachment (not compatible)
+ {
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ { tex.data() }, ds.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget({ tex.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ if (impl == QRhi::Vulkan || impl == QRhi::Metal) {
+ QVERIFY(!rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(!rpDesc2->isCompatible(rpDesc.data()));
+ }
+ }
+
+ if (rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer)) {
+ // resolve attachments (compatible)
+ {
+ QScopedPointer<QRhiRenderBuffer> msaaRenderBuffer(rhi->newRenderBuffer(QRhiRenderBuffer::Color, QSize(512, 512), 4));
+ QVERIFY(msaaRenderBuffer->build());
+ QScopedPointer<QRhiRenderBuffer> msaaRenderBuffer2(rhi->newRenderBuffer(QRhiRenderBuffer::Color, QSize(512, 512), 4));
+ QVERIFY(msaaRenderBuffer2->build());
+
+ QRhiColorAttachment colorAtt(msaaRenderBuffer.data()); // color0, multisample
+ colorAtt.setResolveTexture(tex.data()); // resolved into a non-msaa texture
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ colorAtt }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QRhiColorAttachment colorAtt2(msaaRenderBuffer2.data()); // color0, multisample
+ colorAtt2.setResolveTexture(tex2.data()); // resolved into a non-msaa texture
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget({ colorAtt2 }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ QVERIFY(rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(rpDesc2->isCompatible(rpDesc.data()));
+ }
+
+ // missing resolve for one of them (not compatible)
+ {
+ QScopedPointer<QRhiRenderBuffer> msaaRenderBuffer(rhi->newRenderBuffer(QRhiRenderBuffer::Color, QSize(512, 512), 4));
+ QVERIFY(msaaRenderBuffer->build());
+ QScopedPointer<QRhiRenderBuffer> msaaRenderBuffer2(rhi->newRenderBuffer(QRhiRenderBuffer::Color, QSize(512, 512), 4));
+ QVERIFY(msaaRenderBuffer2->build());
+
+ QRhiColorAttachment colorAtt(msaaRenderBuffer.data()); // color0, multisample
+ colorAtt.setResolveTexture(tex.data()); // resolved into a non-msaa texture
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ colorAtt }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QRhiColorAttachment colorAtt2(msaaRenderBuffer2.data()); // color0, multisample
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget({ colorAtt2 }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ if (impl == QRhi::Vulkan) { // no Metal here
+ QVERIFY(!rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(!rpDesc2->isCompatible(rpDesc.data()));
+ }
+ }
+ } else {
+ qDebug("Skipping multisample renderbuffer dependent tests");
+ }
+
+ if (rhi->isTextureFormatSupported(QRhiTexture::RGBA32F)) {
+ QScopedPointer<QRhiTexture> tex3(rhi->newTexture(QRhiTexture::RGBA32F, QSize(512, 512), 1, QRhiTexture::RenderTarget));
+ QVERIFY(tex3->build());
+
+ // different texture formats (not compatible)
+ {
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ tex.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->build());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget({ tex3.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->build());
+
+ if (impl == QRhi::Vulkan || impl == QRhi::Metal) {
+ QVERIFY(!rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(!rpDesc2->isCompatible(rpDesc.data()));
+ }
+ }
+ } else {
+ qDebug("Skipping texture format dependent tests");
+ }
+}
+
#include <tst_qrhi.moc>
QTEST_MAIN(tst_QRhi)