summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-06-30 09:28:38 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-06-30 15:24:43 +0200
commitbed8c5d678bc73bede59bbddf5e8b6af05185780 (patch)
tree3becd8c3cc73115fe0c5746f0dc652c876cab20e
parent60666ed2fa20fa64ca9ad02c2124876a1d11b42a (diff)
Switch to qvla where it makes sense in rhi
For all of these we know in advance that the vast majority of usages will not exceed a certain number of elements. Also, none of these are copied or moved ever. Change-Id: I48aedf143e221dc178d661e23454d1e4fb7a271b Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/gui/rhi/qrhi_p_p.h2
-rw-r--r--src/gui/rhi/qrhid3d11.cpp4
-rw-r--r--src/gui/rhi/qrhid3d11_p_p.h12
-rw-r--r--src/gui/rhi/qrhigles2.cpp17
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h25
-rw-r--r--src/gui/rhi/qrhimetal.mm4
-rw-r--r--src/gui/rhi/qrhivulkan.cpp10
-rw-r--r--src/gui/rhi/qrhivulkan_p_p.h8
8 files changed, 43 insertions, 39 deletions
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h
index 552e2695ce..b5cf660409 100644
--- a/src/gui/rhi/qrhi_p_p.h
+++ b/src/gui/rhi/qrhi_p_p.h
@@ -228,7 +228,7 @@ private:
QBitArray resUpdPoolMap;
QSet<QRhiResource *> resources;
QSet<QRhiResource *> pendingDeleteResources;
- QList<QRhi::CleanupCallback> cleanupCallbacks;
+ QVarLengthArray<QRhi::CleanupCallback, 4> cleanupCallbacks;
friend class QRhi;
friend class QRhiResourceUpdateBatchPrivate;
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index 6157381acb..e5b03e1d0e 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -1641,7 +1641,7 @@ void QRhiD3D11::finishActiveReadbacks()
if (readback.result->completed)
completedCallbacks.append(readback.result->completed);
- activeTextureReadbacks.removeAt(i);
+ activeTextureReadbacks.removeLast();
}
for (int i = activeBufferReadbacks.count() - 1; i >= 0; --i) {
@@ -1663,7 +1663,7 @@ void QRhiD3D11::finishActiveReadbacks()
if (readback.result->completed)
completedCallbacks.append(readback.result->completed);
- activeBufferReadbacks.removeAt(i);
+ activeBufferReadbacks.removeLast();
}
for (auto f : completedCallbacks)
diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h
index baecc2fe21..c6890ca353 100644
--- a/src/gui/rhi/qrhid3d11_p_p.h
+++ b/src/gui/rhi/qrhid3d11_p_p.h
@@ -469,17 +469,17 @@ struct QD3D11CommandBuffer : public QRhiCommandBuffer
ID3D11Buffer *currentVertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
quint32 currentVertexOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
- QList<QByteArray> dataRetainPool;
- QList<QImage> imageRetainPool;
+ QVarLengthArray<QByteArray, 4> dataRetainPool;
+ QVarLengthArray<QImage, 4> imageRetainPool;
// relies heavily on implicit sharing (no copies of the actual data will be made)
const uchar *retainData(const QByteArray &data) {
dataRetainPool.append(data);
- return reinterpret_cast<const uchar *>(dataRetainPool.constLast().constData());
+ return reinterpret_cast<const uchar *>(dataRetainPool.last().constData());
}
const uchar *retainImage(const QImage &image) {
imageRetainPool.append(image);
- return imageRetainPool.constLast().constBits();
+ return imageRetainPool.last().constBits();
}
void resetCommands() {
commands.clear();
@@ -707,13 +707,13 @@ public:
QSize pixelSize;
QRhiTexture::Format format;
};
- QList<TextureReadback> activeTextureReadbacks;
+ QVarLengthArray<TextureReadback, 2> activeTextureReadbacks;
struct BufferReadback {
QRhiBufferReadbackResult *result;
quint32 byteSize;
ID3D11Buffer *stagingBuf;
};
- QList<BufferReadback> activeBufferReadbacks;
+ QVarLengthArray<BufferReadback, 2> activeBufferReadbacks;
struct Shader {
Shader() = default;
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 9a311101e1..9196a88199 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -2746,8 +2746,8 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.ubuf.buf);
const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf.constData() + viewOffset,
b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
- QVector<QGles2UniformDescription> &uniforms(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->uniforms
- : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->uniforms);
+ QGles2UniformDescriptionVector &uniforms(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->uniforms
+ : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->uniforms);
for (QGles2UniformDescription &uniform : uniforms) {
if (uniform.binding == b->binding) {
// in a uniform buffer everything is at least 4 byte aligned
@@ -2877,8 +2877,8 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
break;
case QRhiShaderResourceBinding::SampledTexture:
{
- QVector<QGles2SamplerDescription> &samplers(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->samplers
- : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->samplers);
+ QGles2SamplerDescriptionVector &samplers(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->samplers
+ : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->samplers);
for (int elem = 0; elem < b->u.stex.count; ++elem) {
QGles2Texture *texD = QRHI_RES(QGles2Texture, b->u.stex.texSamplers[elem].tex);
QGles2Sampler *samplerD = QRHI_RES(QGles2Sampler, b->u.stex.texSamplers[elem].sampler);
@@ -3404,7 +3404,7 @@ void QRhiGles2::registerUniformIfActive(const QShaderDescription::BlockVariable
int binding,
int baseOffset,
GLuint program,
- QVector<QGles2UniformDescription> *dst)
+ QGles2UniformDescriptionVector *dst)
{
if (var.type == QShaderDescription::Struct) {
qWarning("Nested structs are not supported at the moment. '%s' ignored.",
@@ -3431,7 +3431,7 @@ void QRhiGles2::registerUniformIfActive(const QShaderDescription::BlockVariable
void QRhiGles2::gatherUniforms(GLuint program,
const QShaderDescription::UniformBlock &ub,
- QVector<QGles2UniformDescription> *dst)
+ QGles2UniformDescriptionVector *dst)
{
QByteArray prefix = ub.structName + '.';
for (const QShaderDescription::BlockVariable &blockMember : ub.members) {
@@ -3464,8 +3464,9 @@ void QRhiGles2::gatherUniforms(GLuint program,
}
}
-void QRhiGles2::gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v,
- QVector<QGles2SamplerDescription> *dst)
+void QRhiGles2::gatherSamplers(GLuint program,
+ const QShaderDescription::InOutVariable &v,
+ QGles2SamplerDescriptionVector *dst)
{
QGles2SamplerDescription sampler;
sampler.glslLocation = f->glGetUniformLocation(program, v.name.constData());
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index 26a0925dee..32e7d1185d 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -266,6 +266,9 @@ struct QGles2SamplerDescription
Q_DECLARE_TYPEINFO(QGles2SamplerDescription, Q_MOVABLE_TYPE);
+using QGles2UniformDescriptionVector = QVarLengthArray<QGles2UniformDescription, 8>;
+using QGles2SamplerDescriptionVector = QVarLengthArray<QGles2SamplerDescription, 4>;
+
struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
{
QGles2GraphicsPipeline(QRhiImplementation *rhi);
@@ -275,8 +278,8 @@ struct QGles2GraphicsPipeline : public QRhiGraphicsPipeline
GLuint program = 0;
GLenum drawMode = GL_TRIANGLES;
- QList<QGles2UniformDescription> uniforms;
- QList<QGles2SamplerDescription> samplers;
+ QGles2UniformDescriptionVector uniforms;
+ QGles2SamplerDescriptionVector samplers;
uint generation = 0;
friend class QRhiGles2;
};
@@ -289,8 +292,8 @@ struct QGles2ComputePipeline : public QRhiComputePipeline
bool create() override;
GLuint program = 0;
- QList<QGles2UniformDescription> uniforms;
- QList<QGles2SamplerDescription> samplers;
+ QGles2UniformDescriptionVector uniforms;
+ QGles2SamplerDescriptionVector samplers;
uint generation = 0;
friend class QRhiGles2;
};
@@ -574,17 +577,17 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer
}
} computePassState;
- QList<QByteArray> dataRetainPool;
- QList<QImage> imageRetainPool;
+ QVarLengthArray<QByteArray, 4> dataRetainPool;
+ QVarLengthArray<QImage, 4> imageRetainPool;
// relies heavily on implicit sharing (no copies of the actual data will be made)
const void *retainData(const QByteArray &data) {
dataRetainPool.append(data);
- return dataRetainPool.constLast().constData();
+ return dataRetainPool.last().constData();
}
const void *retainImage(const QImage &image) {
imageRetainPool.append(image);
- return imageRetainPool.constLast().constBits();
+ return imageRetainPool.last().constBits();
}
void resetCommands() {
commands.clear();
@@ -810,11 +813,11 @@ public:
bool linkProgram(GLuint program);
void registerUniformIfActive(const QShaderDescription::BlockVariable &var,
const QByteArray &namePrefix, int binding, int baseOffset,
- GLuint program, QList<QGles2UniformDescription> *dst);
+ GLuint program, QGles2UniformDescriptionVector *dst);
void gatherUniforms(GLuint program, const QShaderDescription::UniformBlock &ub,
- QList<QGles2UniformDescription> *dst);
+ QGles2UniformDescriptionVector *dst);
void gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v,
- QList<QGles2SamplerDescription> *dst);
+ QGles2SamplerDescriptionVector *dst);
bool isProgramBinaryDiskCacheEnabled() const;
enum DiskCacheResult {
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index 357e9e792d..6998c55bf9 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -203,7 +203,7 @@ struct QRhiMetalData
QSize pixelSize;
QRhiTexture::Format format;
};
- QVector<TextureReadback> activeTextureReadbacks;
+ QVarLengthArray<TextureReadback, 2> activeTextureReadbacks;
API_AVAILABLE(macos(10.13), ios(11.0)) MTLCaptureManager *captureMgr;
API_AVAILABLE(macos(10.13), ios(11.0)) id<MTLCaptureScope> captureScope = nil;
@@ -2123,7 +2123,7 @@ void QRhiMetal::finishActiveReadbacks(bool forced)
if (readback.result->completed)
completedCallbacks.append(readback.result->completed);
- d->activeTextureReadbacks.removeAt(i);
+ d->activeTextureReadbacks.removeLast();
}
}
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index 06fd6dc719..919f4f039f 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -3525,7 +3525,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced)
if (readback.result->completed)
completedCallbacks.append(readback.result->completed);
- activeTextureReadbacks.removeAt(i);
+ activeTextureReadbacks.removeLast();
}
}
@@ -3549,7 +3549,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced)
if (readback.result->completed)
completedCallbacks.append(readback.result->completed);
- activeBufferReadbacks.removeAt(i);
+ activeBufferReadbacks.removeLast();
}
}
@@ -6719,9 +6719,9 @@ bool QVkSwapChain::ensureSurface()
quint32 presModeCount = 0;
rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR(rhiD->physDev, surface, &presModeCount, nullptr);
- QVector<VkPresentModeKHR> presModes(presModeCount);
- rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR(rhiD->physDev, surface, &presModeCount, presModes.data());
- supportedPresentationModes = presModes;
+ supportedPresentationModes.resize(presModeCount);
+ rhiD->vkGetPhysicalDeviceSurfacePresentModesKHR(rhiD->physDev, surface, &presModeCount,
+ supportedPresentationModes.data());
return true;
}
diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h
index 3d02806033..cb21945301 100644
--- a/src/gui/rhi/qrhivulkan_p_p.h
+++ b/src/gui/rhi/qrhivulkan_p_p.h
@@ -601,7 +601,7 @@ struct QVkSwapChain : public QRhiSwapChain
VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
QVkRenderBuffer *ds = nullptr;
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
- QList<VkPresentModeKHR> supportedPresentationModes;
+ QVarLengthArray<VkPresentModeKHR, 8> supportedPresentationModes;
VkDeviceMemory msaaImageMem = VK_NULL_HANDLE;
QVkReferenceRenderTarget rtWrapper;
QVkCommandBuffer cbWrapper;
@@ -865,7 +865,7 @@ public:
int refCount = 0;
int allocedDescSets = 0;
};
- QList<DescriptorPoolData> descriptorPools;
+ QVarLengthArray<DescriptorPoolData, 8> descriptorPools;
VkQueryPool timestampQueryPool = VK_NULL_HANDLE;
QBitArray timestampQueryPoolMap;
@@ -894,7 +894,7 @@ public:
QSize pixelSize;
QRhiTexture::Format format;
};
- QList<TextureReadback> activeTextureReadbacks;
+ QVarLengthArray<TextureReadback, 2> activeTextureReadbacks;
struct BufferReadback {
int activeFrameSlot = -1;
QRhiBufferReadbackResult *result;
@@ -902,7 +902,7 @@ public:
VkBuffer stagingBuf;
QVkAlloc stagingAlloc;
};
- QList<BufferReadback> activeBufferReadbacks;
+ QVarLengthArray<BufferReadback, 2> activeBufferReadbacks;
struct DeferredReleaseEntry {
enum Type {