From 313fafa8c45efc41a33802f47173c395d1eb9117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santeri=20Salmij=C3=A4rvi?= Date: Sat, 23 Nov 2024 19:53:45 +0200 Subject: [PATCH] Fix new clang-tidy nags --- src/Window.cpp | 2 +- src/gfx/DescriptorAllocator.cpp | 3 +-- src/gfx/Resources.hpp | 5 ++++- src/render/DebugRenderer.cpp | 2 +- src/render/DeferredShading.cpp | 8 +++----- src/render/ForwardRenderer.cpp | 2 +- src/render/GBufferRenderer.cpp | 2 +- src/render/LightClustering.cpp | 2 +- src/render/MeshletCuller.cpp | 7 +++---- src/render/MeshletCuller.hpp | 2 +- src/render/RtReference.cpp | 6 +++--- src/render/SkyboxRenderer.cpp | 2 +- src/render/TemporalAntiAliasing.cpp | 2 +- src/render/TemporalAntiAliasing.hpp | 4 ++-- src/render/TextureDebug.hpp | 2 +- src/render/dof/DepthOfFieldGather.hpp | 2 +- src/render/dof/DepthOfFieldSetup.cpp | 2 +- src/render/rtdi/RtDiInitialReservoirs.cpp | 8 +++----- src/render/rtdi/RtDiSpatialReuse.cpp | 8 +++----- src/render/rtdi/RtDiTrace.cpp | 6 +++--- src/scene/Animations.hpp | 2 +- src/scene/DeferredLoadingContext.hpp | 2 +- src/scene/DrawType.hpp | 2 +- src/scene/World.cpp | 2 +- src/scene/WorldData.cpp | 11 ++++------- src/utils/Dds.cpp | 15 ++++++++++----- src/utils/Dds.hpp | 1 + src/utils/InputHandler.hpp | 4 ++-- src/utils/Profiler.hpp | 2 +- src/utils/Ui.hpp | 7 +++++-- src/utils/Utils.cpp | 4 +--- 31 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 674f382b..09c4d92b 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -41,7 +41,7 @@ void deallocatefun(void *block, void *user) { WHEELS_ASSERT(user != nullptr); TlsfAllocator *alloc = static_cast(user); - return alloc->deallocate(block); + alloc->deallocate(block); } } // namespace diff --git a/src/gfx/DescriptorAllocator.cpp b/src/gfx/DescriptorAllocator.cpp index e4ef5eb5..eae54cd7 100644 --- a/src/gfx/DescriptorAllocator.cpp +++ b/src/gfx/DescriptorAllocator.cpp @@ -142,8 +142,7 @@ void DescriptorAllocator::allocate( Span debugNames, Span output) { WHEELS_ASSERT(m_initialized); - - return allocate(layouts, debugNames, output, nullptr); + allocate(layouts, debugNames, output, nullptr); } void DescriptorAllocator::nextPool() diff --git a/src/gfx/Resources.hpp b/src/gfx/Resources.hpp index 5f9313ff..d0271aaa 100644 --- a/src/gfx/Resources.hpp +++ b/src/gfx/Resources.hpp @@ -8,7 +8,7 @@ // TODO: // Tighter transfer, shader access flags -enum class BufferState : uint32_t +enum class BufferState : uint16_t { Unknown = 0, @@ -133,6 +133,9 @@ template requires(wheels::SameAs || wheels::SameAs) constexpr T operator|(T lhs, T rhs) { + // TODO: + // Could the valid combinations be easily enumerated? + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) return static_cast( static_cast(lhs) | static_cast(rhs)); } diff --git a/src/render/DebugRenderer.cpp b/src/render/DebugRenderer.cpp index 534b1677..4939a540 100644 --- a/src/render/DebugRenderer.cpp +++ b/src/render/DebugRenderer.cpp @@ -19,7 +19,7 @@ using namespace wheels; namespace { -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, GeometryBuffersBindingSet, diff --git a/src/render/DeferredShading.cpp b/src/render/DeferredShading.cpp index e4df9b9b..b6ff12f4 100644 --- a/src/render/DeferredShading.cpp +++ b/src/render/DeferredShading.cpp @@ -21,7 +21,7 @@ using namespace wheels; namespace { -enum BindingSet : uint32_t +enum BindingSet : uint8_t { LightsBindingSet, LightClustersBindingSet, @@ -85,8 +85,7 @@ void DeferredShading::init( WHEELS_ASSERT(!m_initialized); m_computePass.init( - WHEELS_MOV(scopeAlloc), - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, ComputePassOptions{ .storageSetIndex = StorageBindingSet, @@ -104,8 +103,7 @@ void DeferredShading::recompileShaders( WHEELS_ASSERT(m_initialized); m_computePass.recompileShader( - WHEELS_MOV(scopeAlloc), changedFiles, - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), changedFiles, [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, externalDsLayouts(dsLayouts)); } diff --git a/src/render/ForwardRenderer.cpp b/src/render/ForwardRenderer.cpp index 617ec6bb..43d1a91b 100644 --- a/src/render/ForwardRenderer.cpp +++ b/src/render/ForwardRenderer.cpp @@ -28,7 +28,7 @@ using namespace wheels; namespace { -enum BindingSet : uint32_t +enum BindingSet : uint8_t { LightsBindingSet, LightClustersBindingSet, diff --git a/src/render/GBufferRenderer.cpp b/src/render/GBufferRenderer.cpp index 06b2c5ab..4eb4e6a1 100644 --- a/src/render/GBufferRenderer.cpp +++ b/src/render/GBufferRenderer.cpp @@ -28,7 +28,7 @@ namespace const vk::Format sAlbedoRoughnessFormat = vk::Format::eR8G8B8A8Unorm; const vk::Format sNormalMetalnessFormat = vk::Format::eA2B10G10R10UnormPack32; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, MaterialDatasBindingSet, diff --git a/src/render/LightClustering.cpp b/src/render/LightClustering.cpp index 0e8e3838..dcfe6b94 100644 --- a/src/render/LightClustering.cpp +++ b/src/render/LightClustering.cpp @@ -22,7 +22,7 @@ constexpr uint32_t sGroupDim = 16; constexpr uint32_t maxPointIndicesPerTile = 128; constexpr uint32_t maxSpotIndicesPerTile = 128; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { LightsBindingSet, CameraBindingSet, diff --git a/src/render/MeshletCuller.cpp b/src/render/MeshletCuller.cpp index eeb5ec14..d94c593b 100644 --- a/src/render/MeshletCuller.cpp +++ b/src/render/MeshletCuller.cpp @@ -32,7 +32,7 @@ const uint32_t sMaxRecordsPerFrame = 2; const uint32_t sMaxHierarchicalDepthMips = 12; -enum GeneratorBindingSet : uint32_t +enum GeneratorBindingSet : uint8_t { GeneratorGeometryBindingSet, GeneratorSceneInstancesBindingSet, @@ -42,7 +42,7 @@ enum GeneratorBindingSet : uint32_t GeneratorBindingSetCount, }; -enum CullerBindingSet : uint32_t +enum CullerBindingSet : uint8_t { CullerCameraBindingSet, CullerGeometryBindingSet, @@ -146,8 +146,7 @@ void MeshletCuller::init( WHEELS_ASSERT(!m_initialized); m_drawListGenerator.init( - scopeAlloc.child_scope(), - [&worldDsLayouts](Allocator &alloc) + scopeAlloc.child_scope(), [&worldDsLayouts](Allocator &alloc) { return generatorDefinitionCallback(alloc, worldDsLayouts); }, ComputePassOptions{ .storageSetIndex = GeneratorStorageBindingSet, diff --git a/src/render/MeshletCuller.hpp b/src/render/MeshletCuller.hpp index 0aaac14b..04ff9863 100644 --- a/src/render/MeshletCuller.hpp +++ b/src/render/MeshletCuller.hpp @@ -48,7 +48,7 @@ class MeshletCuller void startFrame(); - enum class Mode + enum class Mode : uint8_t { Opaque, Transparent, diff --git a/src/render/RtReference.cpp b/src/render/RtReference.cpp index 297179e5..171631db 100644 --- a/src/render/RtReference.cpp +++ b/src/render/RtReference.cpp @@ -27,7 +27,7 @@ namespace constexpr uint32_t sFramePeriod = 4096; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, RTBindingSet, @@ -47,7 +47,7 @@ constexpr vk::ShaderStageFlags sVkShaderStageFlagsAllRt = vk::ShaderStageFlagBits::eMissKHR | vk::ShaderStageFlagBits::eIntersectionKHR; -enum class StageIndex : uint32_t +enum class StageIndex : uint8_t { RayGen, ClosestHit, @@ -55,7 +55,7 @@ enum class StageIndex : uint32_t Miss, }; -enum class GroupIndex : uint32_t +enum class GroupIndex : uint8_t { RayGen, Hit, diff --git a/src/render/SkyboxRenderer.cpp b/src/render/SkyboxRenderer.cpp index c57f0e60..094b829e 100644 --- a/src/render/SkyboxRenderer.cpp +++ b/src/render/SkyboxRenderer.cpp @@ -18,7 +18,7 @@ using namespace wheels; namespace { -enum BindingSet : uint32_t +enum BindingSet : uint8_t { SkyboxBindingSet, CameraBindingSet, diff --git a/src/render/TemporalAntiAliasing.cpp b/src/render/TemporalAntiAliasing.cpp index 34456cda..ef8cbdb4 100644 --- a/src/render/TemporalAntiAliasing.cpp +++ b/src/render/TemporalAntiAliasing.cpp @@ -27,7 +27,7 @@ constexpr StaticArray< static_cast(TemporalAntiAliasing::VelocitySamplingType::Count)> sVelocitySamplingTypeNames{{VELOCITY_SAMPLING_TYPE_STRS}}; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, StorageBindingSet, diff --git a/src/render/TemporalAntiAliasing.hpp b/src/render/TemporalAntiAliasing.hpp index 1dbc8a99..3b5f12e9 100644 --- a/src/render/TemporalAntiAliasing.hpp +++ b/src/render/TemporalAntiAliasing.hpp @@ -25,12 +25,12 @@ class TemporalAntiAliasing { public: - enum class ColorClippingType : uint32_t + enum class ColorClippingType : uint8_t { COLOR_CLIPPING_TYPES_AND_COUNT }; - enum class VelocitySamplingType : uint32_t + enum class VelocitySamplingType : uint8_t { VELOCITY_SAMPLING_TYPES_AND_COUNT }; diff --git a/src/render/TextureDebug.hpp b/src/render/TextureDebug.hpp index 0d028675..63a6b143 100644 --- a/src/render/TextureDebug.hpp +++ b/src/render/TextureDebug.hpp @@ -27,7 +27,7 @@ class TextureDebug { public: - enum class ChannelType : uint32_t + enum class ChannelType : uint8_t { TEXTURE_DEBUG_CHANNEL_TYPES_AND_COUNT }; diff --git a/src/render/dof/DepthOfFieldGather.hpp b/src/render/dof/DepthOfFieldGather.hpp index 66e3b973..6b56ae64 100644 --- a/src/render/dof/DepthOfFieldGather.hpp +++ b/src/render/dof/DepthOfFieldGather.hpp @@ -14,7 +14,7 @@ class DepthOfFieldGather { public: - enum GatherType : uint32_t + enum GatherType : uint8_t { GatherType_Foreground, GatherType_Background, diff --git a/src/render/dof/DepthOfFieldSetup.cpp b/src/render/dof/DepthOfFieldSetup.cpp index 00d1ced2..2bcb2626 100644 --- a/src/render/dof/DepthOfFieldSetup.cpp +++ b/src/render/dof/DepthOfFieldSetup.cpp @@ -17,7 +17,7 @@ using namespace wheels; namespace { -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, StorageBindingSet, diff --git a/src/render/rtdi/RtDiInitialReservoirs.cpp b/src/render/rtdi/RtDiInitialReservoirs.cpp index 8d12ec05..9a37187a 100644 --- a/src/render/rtdi/RtDiInitialReservoirs.cpp +++ b/src/render/rtdi/RtDiInitialReservoirs.cpp @@ -20,7 +20,7 @@ namespace constexpr uint32_t sFramePeriod = 4096; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { LightsBindingSet, CameraBindingSet, @@ -67,8 +67,7 @@ void RtDiInitialReservoirs::init( WHEELS_ASSERT(!m_initialized); m_computePass.init( - WHEELS_MOV(scopeAlloc), - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, ComputePassOptions{ .storageSetIndex = StorageBindingSet, @@ -86,8 +85,7 @@ bool RtDiInitialReservoirs::recompileShaders( WHEELS_ASSERT(m_initialized); return m_computePass.recompileShader( - WHEELS_MOV(scopeAlloc), changedFiles, - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), changedFiles, [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, externalDsLayouts(dsLayouts)); } diff --git a/src/render/rtdi/RtDiSpatialReuse.cpp b/src/render/rtdi/RtDiSpatialReuse.cpp index 490d1065..7d130a76 100644 --- a/src/render/rtdi/RtDiSpatialReuse.cpp +++ b/src/render/rtdi/RtDiSpatialReuse.cpp @@ -20,7 +20,7 @@ namespace constexpr uint32_t sFramePeriod = 4096; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { LightsBindingSet, CameraBindingSet, @@ -67,8 +67,7 @@ void RtDiSpatialReuse::init( WHEELS_ASSERT(!m_initialized); m_computePass.init( - WHEELS_MOV(scopeAlloc), - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, ComputePassOptions{ .storageSetIndex = StorageBindingSet, @@ -86,8 +85,7 @@ bool RtDiSpatialReuse::recompileShaders( WHEELS_ASSERT(m_initialized); return m_computePass.recompileShader( - WHEELS_MOV(scopeAlloc), changedFiles, - [&dsLayouts](Allocator &alloc) + WHEELS_MOV(scopeAlloc), changedFiles, [&dsLayouts](Allocator &alloc) { return shaderDefinitionCallback(alloc, dsLayouts.world); }, externalDsLayouts(dsLayouts)); } diff --git a/src/render/rtdi/RtDiTrace.cpp b/src/render/rtdi/RtDiTrace.cpp index 4ee05d7e..8a32c7d8 100644 --- a/src/render/rtdi/RtDiTrace.cpp +++ b/src/render/rtdi/RtDiTrace.cpp @@ -27,7 +27,7 @@ namespace constexpr uint32_t sFramePeriod = 4096; -enum BindingSet : uint32_t +enum BindingSet : uint8_t { CameraBindingSet, RTBindingSet, @@ -47,7 +47,7 @@ constexpr vk::ShaderStageFlags sVkShaderStageFlagsAllRt = vk::ShaderStageFlagBits::eMissKHR | vk::ShaderStageFlagBits::eIntersectionKHR; -enum class StageIndex : uint32_t +enum class StageIndex : uint8_t { RayGen, ClosestHit, @@ -55,7 +55,7 @@ enum class StageIndex : uint32_t Miss, }; -enum class GroupIndex : uint32_t +enum class GroupIndex : uint8_t { RayGen, Hit, diff --git a/src/scene/Animations.hpp b/src/scene/Animations.hpp index 9eb87868..9c81cb2c 100644 --- a/src/scene/Animations.hpp +++ b/src/scene/Animations.hpp @@ -10,7 +10,7 @@ #include #include -enum class InterpolationType +enum class InterpolationType : uint8_t { Step, Linear, diff --git a/src/scene/DeferredLoadingContext.hpp b/src/scene/DeferredLoadingContext.hpp index 4c822829..d4997b53 100644 --- a/src/scene/DeferredLoadingContext.hpp +++ b/src/scene/DeferredLoadingContext.hpp @@ -24,7 +24,7 @@ #include #include -enum class IndicesType +enum class IndicesType : uint8_t { Uint8, Uint16, diff --git a/src/scene/DrawType.hpp b/src/scene/DrawType.hpp index 5daa2d3b..a108f176 100644 --- a/src/scene/DrawType.hpp +++ b/src/scene/DrawType.hpp @@ -15,7 +15,7 @@ #define DRAW_TYPES_STRS FOR_EACH(DRAW_TYPES_STRINGIFY, DRAW_TYPES) -enum class DrawType : uint32_t +enum class DrawType : uint8_t { DRAW_TYPES_AND_COUNT }; diff --git a/src/scene/World.cpp b/src/scene/World.cpp index 9cc73456..954c3428 100644 --- a/src/scene/World.cpp +++ b/src/scene/World.cpp @@ -982,7 +982,7 @@ bool World::unbuiltBlases() const void World::drawDeferredLoadingUi() const { WHEELS_ASSERT(m_initialized); - return m_impl->m_data.drawDeferredLoadingUi(); + m_impl->m_data.drawDeferredLoadingUi(); } bool World::drawSceneUi() diff --git a/src/scene/WorldData.cpp b/src/scene/WorldData.cpp index a037119f..8b9ef598 100644 --- a/src/scene/WorldData.cpp +++ b/src/scene/WorldData.cpp @@ -47,7 +47,7 @@ void *cgltf_alloc_func(void *user, cgltf_size size) void cgltf_free_func(void *user, void *ptr) { Allocator *alloc = static_cast(user); - return alloc->deallocate(ptr); + alloc->deallocate(ptr); } const StaticArray sCgltfResultStr{{ @@ -1488,13 +1488,10 @@ void WorldData::gatherScene( // Angular attenuation rom gltf spec const auto angleScale = - 1.f / - max(0.001f, static_cast( - cos(light.spot_inner_cone_angle) - - cos(light.spot_outer_cone_angle))); + 1.f / max(0.001f, cos(light.spot_inner_cone_angle) - + cos(light.spot_outer_cone_angle)); const auto angleOffset = - static_cast(-cos(light.spot_outer_cone_angle)) * - angleScale; + -cos(light.spot_outer_cone_angle) * angleScale; sceneLight.radianceAndAngleScale = vec4{ diff --git a/src/utils/Dds.cpp b/src/utils/Dds.cpp index ed993a96..9cf39079 100644 --- a/src/utils/Dds.cpp +++ b/src/utils/Dds.cpp @@ -44,6 +44,7 @@ struct DdsHeader }; // https://learn.microsoft.com/en-us/windows/win32/api/d3d10/ne-d3d10-d3d10_resource_dimension +// NOLINTNEXTLINE(performance-enum-size) matches the format enum class D3d10ResourceDimension { Unknown = 0, @@ -165,11 +166,15 @@ void writeDds(const Dds &dds, const std::filesystem::path &path) const bool isCompressed = isFormatCompressed(dds.format); const uint32_t pixelStride = isCompressed ? 0 : 4; const uint32_t pixelBits = isCompressed ? 0 : 32; - const uint32_t pitchOrLinearSize = - isCompressed ? (dds.mipLevelCount == 1 - ? dds.levelByteOffsets[0] - : dds.levelByteOffsets[1] - dds.levelByteOffsets[0]) - : dds.width * dds.height * pixelStride; + uint32_t pitchOrLinearSize = dds.width * dds.height * pixelStride; + if (isCompressed) + { + if (dds.mipLevelCount == 1) + pitchOrLinearSize = dds.levelByteOffsets[0]; + else + pitchOrLinearSize = + dds.levelByteOffsets[1] - dds.levelByteOffsets[0]; + } // clang-format off const uint32_t flags = isCompressed ? diff --git a/src/utils/Dds.hpp b/src/utils/Dds.hpp index 1b413959..09656f8b 100644 --- a/src/utils/Dds.hpp +++ b/src/utils/Dds.hpp @@ -7,6 +7,7 @@ #include // https://learn.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format +// NOLINTNEXTLINE(performance-enum-size) matches the format enum class DxgiFormat { Unknown = 0, diff --git a/src/utils/InputHandler.hpp b/src/utils/InputHandler.hpp index 23b1f6f6..ada194ff 100644 --- a/src/utils/InputHandler.hpp +++ b/src/utils/InputHandler.hpp @@ -5,7 +5,7 @@ #include #include -enum class KeyState +enum class KeyState : uint8_t { Neutral, // Key is just hangin' Pressed, // Key was pressed between previous and current frame @@ -36,7 +36,7 @@ struct CursorState bool shown{true}; }; -enum class MouseGestureType +enum class MouseGestureType : uint8_t { TrackBall, TrackPlane, diff --git a/src/utils/Profiler.hpp b/src/utils/Profiler.hpp index d79f3759..b8815d2a 100644 --- a/src/utils/Profiler.hpp +++ b/src/utils/Profiler.hpp @@ -252,7 +252,7 @@ class Profiler private: // Do validation of the calls as it's easy to do things in the wrong order - enum class DebugState + enum class DebugState : uint8_t { NewFrame, StartCpuCalled, diff --git a/src/utils/Ui.hpp b/src/utils/Ui.hpp index f004dc90..536d55ba 100644 --- a/src/utils/Ui.hpp +++ b/src/utils/Ui.hpp @@ -2,6 +2,7 @@ #define WHEELS_UTILS_UI_HPP #include +#include #include // Creates a dropdown for the value and returns true if it was changed @@ -10,11 +11,13 @@ bool enumDropdown( const char *label, Enum &value, const wheels::StaticArray &variantNames) { + using EnumType = std::underlying_type_t; + bool changed = false; - auto *currentType = reinterpret_cast(&value); + auto *currentType = reinterpret_cast(&value); if (ImGui::BeginCombo(label, variantNames[*currentType])) { - for (auto i = 0u; i < static_cast(Enum::Count); ++i) + for (EnumType i = 0; i < static_cast(Enum::Count); ++i) { bool selected = *currentType == i; if (ImGui::Selectable(variantNames[i], &selected)) diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index c0794322..51fe12ed 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -61,9 +61,7 @@ String readFileString(Allocator &alloc, const std::filesystem::path &path) buffer.resize(fileSize); file.seekg(0); - file.read( - reinterpret_cast(buffer.data()), - asserted_cast(fileSize)); + file.read(buffer.data(), asserted_cast(fileSize)); file.close(); return buffer;