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>
This commit is contained in:
Laszlo Agocs 2020-06-30 09:28:38 +02:00
parent 60666ed2fa
commit bed8c5d678
8 changed files with 43 additions and 39 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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());

View File

@ -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 {

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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 {