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.cpp95
1 files changed, 89 insertions, 6 deletions
diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
index 191260fd41..549481aa21 100644
--- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
+++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
@@ -75,6 +75,8 @@ private slots:
void nativeHandles();
void nativeTexture_data();
void nativeTexture();
+ void nativeBuffer_data();
+ void nativeBuffer();
void resourceUpdateBatchBuffer_data();
void resourceUpdateBatchBuffer();
void resourceUpdateBatchRGBATextureUpload_data();
@@ -294,7 +296,8 @@ void tst_QRhi::create()
QRhi::BaseInstance,
QRhi::TriangleFanTopology,
QRhi::ReadBackNonUniformBuffer,
- QRhi::ReadBackNonBaseMipLevel
+ QRhi::ReadBackNonBaseMipLevel,
+ QRhi::TexelFetch
};
for (size_t i = 0; i <sizeof(features) / sizeof(QRhi::Feature); ++i)
rhi->isFeatureSupported(features[i]);
@@ -545,6 +548,86 @@ void tst_QRhi::nativeTexture()
}
}
+void tst_QRhi::nativeBuffer_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::nativeBuffer()
+{
+ 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 native buffer query");
+
+ const QRhiBuffer::Type types[3] = { QRhiBuffer::Immutable, QRhiBuffer::Static, QRhiBuffer::Dynamic };
+ const QRhiBuffer::UsageFlags usages[3] = { QRhiBuffer::VertexBuffer, QRhiBuffer::IndexBuffer, QRhiBuffer::UniformBuffer };
+ for (int typeUsageIdx = 0; typeUsageIdx < 3; ++typeUsageIdx) {
+ QScopedPointer<QRhiBuffer> buf(rhi->newBuffer(types[typeUsageIdx], usages[typeUsageIdx], 256));
+ QVERIFY(buf->build());
+
+ const QRhiBuffer::NativeBuffer nativeBuf = buf->nativeBuffer();
+ QVERIFY(nativeBuf.slotCount <= rhi->resourceLimit(QRhi::FramesInFlight));
+
+ switch (impl) {
+ case QRhi::Null:
+ break;
+ #ifdef TST_VK
+ case QRhi::Vulkan:
+ {
+ QVERIFY(nativeBuf.slotCount >= 1); // always backed by native buffers
+ for (int i = 0; i < nativeBuf.slotCount; ++i) {
+ auto *buffer = static_cast<const VkBuffer *>(nativeBuf.objects[i]);
+ QVERIFY(buffer);
+ QVERIFY(*buffer);
+ }
+ }
+ break;
+ #endif
+ #ifdef TST_GL
+ case QRhi::OpenGLES2:
+ {
+ QVERIFY(nativeBuf.slotCount >= 0); // UniformBuffers are not backed by native buffers, so 0 is perfectly valid
+ for (int i = 0; i < nativeBuf.slotCount; ++i) {
+ auto *bufferId = static_cast<const uint *>(nativeBuf.objects[i]);
+ QVERIFY(bufferId);
+ QVERIFY(*bufferId);
+ }
+ }
+ break;
+ #endif
+ #ifdef TST_D3D11
+ case QRhi::D3D11:
+ {
+ QVERIFY(nativeBuf.slotCount >= 1); // always backed by native buffers
+ for (int i = 0; i < nativeBuf.slotCount; ++i) {
+ auto *buffer = static_cast<void * const *>(nativeBuf.objects[i]);
+ QVERIFY(buffer);
+ QVERIFY(*buffer);
+ }
+ }
+ break;
+ #endif
+ #ifdef TST_MTL
+ case QRhi::Metal:
+ {
+ QVERIFY(nativeBuf.slotCount >= 1); // always backed by native buffers
+ for (int i = 0; i < nativeBuf.slotCount; ++i) {
+ void * const * buffer = (void * const *) nativeBuf.objects[i];
+ QVERIFY(buffer);
+ QVERIFY(*buffer);
+ }
+ }
+ break;
+ #endif
+ default:
+ Q_ASSERT(false);
+ }
+ }
+}
+
static bool submitResourceUpdates(QRhi *rhi, QRhiResourceUpdateBatch *batch)
{
QRhiCommandBuffer *cb = nullptr;
@@ -1671,9 +1754,9 @@ void tst_QRhi::renderToWindowSimple()
QVERIFY(pipeline->build());
- const int framesInFlight = rhi->resourceLimit(QRhi::FramesInFlight);
- QVERIFY(framesInFlight >= 1);
- const int FRAME_COUNT = framesInFlight + 1;
+ const int asyncReadbackFrames = rhi->resourceLimit(QRhi::MaxAsyncReadbackFrames);
+ // one frame issues the readback, then we do MaxAsyncReadbackFrames more to ensure the readback completes
+ const int FRAME_COUNT = asyncReadbackFrames + 1;
bool readCompleted = false;
QRhiReadbackResult readResult;
QImage result;
@@ -1720,8 +1803,8 @@ void tst_QRhi::renderToWindowSimple()
}
// The readback is asynchronous here. However it is guaranteed that it
- // finished at latest after rendering QRhi::FramesInFlight frames after the
- // one that enqueues the readback.
+ // finished at latest after rendering QRhi::MaxAsyncReadbackFrames frames
+ // after the one that enqueues the readback.
QVERIFY(readCompleted);
QVERIFY(readbackWidth > 0);