diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-28 15:19:09 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-30 20:07:43 +0200 |
commit | 7000b66f7e85e58d267b71322fbb3d5a0fc356b8 (patch) | |
tree | 77d098a0f7d759686fb43942a881dcc9718ebba4 /tests/manual/rhi | |
parent | d4c17725abe381d247d6c453dafe87b8e17e80de (diff) |
Remove QVector in the API of QRhiResource subclasses
Forcing users to go through a QVector, when in practice they almost
always want to source the data from an initializer list, a QVarLengthArray,
or a plain C array, is not ideal. Especially since we can reason about
the maximum number of elements in the vast majority of use cases for all
the affected lists. QRhiResource is also not copyable so we do not need
the usual machinery offered by containers. So switch to a
QVarLengthArray.
Note that a resource is not a container. The only operations we are
interested in is to be able to source data either via an initializer
list or by iterating on something, and to be able to extract the data,
in case a user wishes to set up another resource based on the existing
one.
In some cases a QVector overload is kept for source compatibility with
other modules (Qt Quick). These may be removed in the future.
Also do a similar QVector->QVarLengthArray change in the srb-related
data in the backends.
Change-Id: I6f5b2ebd8e75416ce0cca0817bb529446a4cb664
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'tests/manual/rhi')
-rw-r--r-- | tests/manual/rhi/mrt/mrt.cpp | 10 | ||||
-rw-r--r-- | tests/manual/rhi/msaatexture/msaatexture.cpp | 2 | ||||
-rw-r--r-- | tests/manual/rhi/texuploads/texuploads.cpp | 25 | ||||
-rw-r--r-- | tests/manual/rhi/triquadcube/trianglerenderer.cpp | 4 |
4 files changed, 19 insertions, 22 deletions
diff --git a/tests/manual/rhi/mrt/mrt.cpp b/tests/manual/rhi/mrt/mrt.cpp index 258871f9b3..dc72c7d194 100644 --- a/tests/manual/rhi/mrt/mrt.cpp +++ b/tests/manual/rhi/mrt/mrt.cpp @@ -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) } }); diff --git a/tests/manual/rhi/msaatexture/msaatexture.cpp b/tests/manual/rhi/msaatexture/msaatexture.cpp index d23a4a8d47..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); diff --git a/tests/manual/rhi/texuploads/texuploads.cpp b/tests/manual/rhi/texuploads/texuploads.cpp index f29a989187..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); 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 |