From 5962605abb89bc0afa2d17a8055ed18e66960d82 Mon Sep 17 00:00:00 2001 From: Ben Fletcher Date: Mon, 31 Jan 2022 12:23:25 -0800 Subject: [PATCH] rhi: Code quality - remove defaults from switch enums On code review of previous RHI patches it was noted that many switch on enum statements contain a default. This is discouraged as it prevents the compiler from automatically identifying switch statements that do not cover all enum cases. This patch addresses rhi base classes. Further patches required for specific backend implementations. Change-Id: Ib2bb30c66fd214b65a4ca7b787c7c610f3c313f5 Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhi.cpp | 33 ++++++++------------------------- src/gui/rhi/qrhinull.cpp | 6 +++--- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 571c5e95b42..6058dd3a558 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -3907,9 +3907,7 @@ bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind return false; break; case QRhiShaderResourceBinding::ImageLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageLoadStore: if (da->u.simage.tex != db->u.simage.tex || da->u.simage.level != db->u.simage.level) @@ -3918,9 +3916,7 @@ bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind } break; case QRhiShaderResourceBinding::BufferLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferLoadStore: if (da->u.sbuf.buf != db->u.sbuf.buf || da->u.sbuf.offset != db->u.sbuf.offset @@ -3972,21 +3968,15 @@ size_t qHash(const QRhiShaderResourceBinding &b, size_t seed) noexcept h ^= qHash(reinterpret_cast(d->u.stex.texSamplers[0].sampler)); break; case QRhiShaderResourceBinding::ImageLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageLoadStore: h ^= qHash(reinterpret_cast(d->u.simage.tex)); break; case QRhiShaderResourceBinding::BufferLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferLoadStore: h ^= qHash(reinterpret_cast(d->u.sbuf.buf)); break; - default: - break; } return h; } @@ -4769,8 +4759,6 @@ QDebug operator<<(QDebug dbg, const QRhiSwapChainHdrInfo &info) case QRhiSwapChainHdrInfo::ColorComponentValue: dbg.nospace() << " maxColorComponentValue=" << info.limits.colorComponentValue.maxColorComponentValue; break; - default: - break; } dbg.nospace() << ')'; return dbg; @@ -4913,10 +4901,9 @@ static const char *resourceTypeStr(QRhiResource *res) return "ComputePipeline"; case QRhiResource::CommandBuffer: return "CommandBuffer"; - default: - Q_UNREACHABLE(); - break; } + + Q_UNREACHABLE(); return ""; } @@ -5233,9 +5220,7 @@ bool QRhiImplementation::sanityCheckShaderResourceBindings(QRhiShaderResourceBin } break; case QRhiShaderResourceBinding::ImageLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::ImageLoadStore: if (!bindingSeen[binding]) { bindingSeen[binding] = true; @@ -5245,9 +5230,7 @@ bool QRhiImplementation::sanityCheckShaderResourceBindings(QRhiShaderResourceBin } break; case QRhiShaderResourceBinding::BufferLoad: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferStore: - Q_FALLTHROUGH(); case QRhiShaderResourceBinding::BufferLoadStore: if (!bindingSeen[binding]) { bindingSeen[binding] = true; @@ -5351,8 +5334,6 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh qWarning("This platform has no Metal support"); break; #endif - default: - break; } if (r->d) { @@ -5400,9 +5381,10 @@ const char *QRhi::backendName() const return "D3D11"; case QRhi::Metal: return "Metal"; - default: - return "Unknown"; } + + Q_UNREACHABLE(); + return nullptr; } /*! @@ -5453,9 +5435,10 @@ static inline const char *deviceTypeStr(QRhiDriverInfo::DeviceType type) return "Virtual"; case QRhiDriverInfo::CpuDevice: return "Cpu"; - default: - return ""; } + + Q_UNREACHABLE(); + return nullptr; } QDebug operator<<(QDebug dbg, const QRhiDriverInfo &info) { diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp index 2790b19ebcd..7136c7e73fb 100644 --- a/src/gui/rhi/qrhinull.cpp +++ b/src/gui/rhi/qrhinull.cpp @@ -169,10 +169,10 @@ int QRhiNull::resourceLimit(QRhi::ResourceLimit limit) const return 32; case QRhi::MaxVertexOutputs: return 32; - default: - Q_UNREACHABLE(); - return 0; } + + Q_UNREACHABLE(); + return 0; } const QRhiNativeHandles *QRhiNull::nativeHandles()