diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-02-20 11:03:16 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-02-21 09:15:18 +0100 |
commit | 2940c375e40687f5758d173adceaee212239e2ca (patch) | |
tree | 3f75011b37d9d0e205e4d11d6a85dc38fa9b8f51 /tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | |
parent | 79b605d285d006ff7434fc813effa3479138b952 (diff) |
rhi: Allow querying the native buffer objects behind a QRhiBuffer
Modeled after QRhiTexture's NativeTexture query.
This becomes valuable in advanced cases of integrating external native
rendering code with Qt Quick(3D), because it allows using (typically
vertex and index) buffers created by Quick(3D) in the custom renderer as
well, without having to duplicate the content by manually creating native
buffers with the same vertex and index data.
Change-Id: I659193345fa1dfe6221b898043f0b75ba649d296
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'tests/auto/gui/rhi/qrhi/tst_qrhi.cpp')
-rw-r--r-- | tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index ab435caa40..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(); @@ -546,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; |