From a19308a35e88cd53c0d5ac2f26c705f902804658 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 12 Mar 2026 16:23:05 +1100 Subject: Add reasonable compiler warnings and fix them --- CMakeLists.txt | 35 +++++++++++++++++++---------------- src/device_context.cc | 5 +++-- src/layer.cc | 27 +++++++++++++++------------ src/physical_device_context.cc | 5 +++-- src/queue_context.cc | 19 +++++-------------- src/timestamp_pool.cc | 30 ++++++++++++++++-------------- 6 files changed, 61 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 021f56b..2e4188a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,21 +40,24 @@ add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD "${OUTPUT_DIR}/" ) -set(SANITIZE_FLAGS - -fsanitize=address,undefined,leak - -fno-omit-frame-pointer - -fno-optimize-sibling-calls - -fno-sanitize-recover=all - -fsanitize-address-use-after-scope -) - target_compile_options(${LIBRARY_NAME} PRIVATE - #${SANITIZE_FLAGS} - -g3 - -O1 + # Inherited from Mesa. + -g + -O2 -D_GLIBCXX_ASSERTIONS -) - -target_link_options(${LIBRARY_NAME} PRIVATE - #${SANITIZE_FLAGS} -) + -D__STDC_CONSTANT_MACROS + -D__STDC_FORMAT_MACROS + -D__STDC_LIMIT_MACROS + + # Things I like. + -Wall + -Wextra + -Wundef + -Wconversion + -Wdouble-promotion + + -Wno-unused-parameter + -Wno-unused-function + -Wno-sign-conversion + -Wno-missing-field-initializers +) \ No newline at end of file diff --git a/src/device_context.cc b/src/device_context.cc index 273a958..c192ec6 100644 --- a/src/device_context.cc +++ b/src/device_context.cc @@ -12,7 +12,7 @@ DeviceContext::DeviceContext(InstanceContext& parent_instance, const bool was_antilag_requested, VkuDeviceDispatchTable&& vtable) : instance(parent_instance), physical_device(parent_physical_device), - device(device), was_antilag_requested(was_antilag_requested), + was_antilag_requested(was_antilag_requested), device(device), vtable(std::move(vtable)) { // Only create our clock if we can support creating it. @@ -78,7 +78,8 @@ DeviceContext::Clock::ticks_to_time(const std::uint64_t& ticks) const { // by GetCalibratedTimestamps. It would be more robust to use the posix // gettime that vulkan guarantees it can be compared to instead. - const auto diff_nsec = static_cast(diff * ns_tick + 0.5); + const auto diff_nsec = + static_cast(static_cast(diff) * ns_tick + 0.5); const auto delta = std::chrono::nanoseconds(this->host_ns + diff_nsec); return time_point_t{delta}; } diff --git a/src/layer.cc b/src/layer.cc index 6b91005..014ab37 100644 --- a/src/layer.cc +++ b/src/layer.cc @@ -186,9 +186,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice( std::span{pCreateInfo->ppEnabledExtensionNames, pCreateInfo->enabledExtensionCount}; - const auto requested = - enabled_extensions | - std::ranges::to>(); + const auto requested = std::unordered_set( + std::from_range, enabled_extensions); // There's the antilag extension that might be requested here - Antilag2. // Then there's the other thing we provide, which is our AntiLag1 @@ -223,9 +222,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice( return VK_ERROR_INITIALIZATION_FAILED; } - const auto gipa = create_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; const auto gdpa = create_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; - if (!gipa || !gdpa) { + if (!gdpa) { return VK_ERROR_INITIALIZATION_FAILED; } const_cast(create_info)->u.pLayerInfo = @@ -255,7 +253,8 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice( const auto next_create_info = [&]() -> VkDeviceCreateInfo { auto next_pCreateInfo = *pCreateInfo; next_pCreateInfo.ppEnabledExtensionNames = std::data(next_extensions); - next_pCreateInfo.enabledExtensionCount = std::size(next_extensions); + next_pCreateInfo.enabledExtensionCount = + static_cast(std::size(next_extensions)); return next_pCreateInfo; }(); @@ -464,12 +463,14 @@ vkQueueSubmit(VkQueue queue, std::uint32_t submit_count, auto next_submit = submit; next_submit.pCommandBuffers = std::data(*next_cbs.back()); - next_submit.commandBufferCount = std::size(*next_cbs.back()); + next_submit.commandBufferCount = + static_cast(std::size(*next_cbs.back())); return next_submit; }); - return vtable.QueueSubmit(queue, std::size(next_submits), - std::data(next_submits), fence); + return vtable.QueueSubmit( + queue, static_cast(std::size(next_submits)), + std::data(next_submits), fence); } // The logic for this function is identical to vkSubmitInfo. @@ -520,12 +521,14 @@ vkQueueSubmit2(VkQueue queue, std::uint32_t submit_count, auto next_submit = submit; next_submit.pCommandBufferInfos = std::data(*next_cbs.back()); - next_submit.commandBufferInfoCount = std::size(*next_cbs.back()); + next_submit.commandBufferInfoCount = + static_cast(std::size(*next_cbs.back())); return next_submit; }); - return vtable.QueueSubmit2(queue, std::size(next_submits), - std::data(next_submits), fence); + return vtable.QueueSubmit2( + queue, static_cast(std::size(next_submits)), + std::data(next_submits), fence); } static VKAPI_ATTR VkResult VKAPI_CALL diff --git a/src/physical_device_context.cc b/src/physical_device_context.cc index de63b3d..29b4ca3 100644 --- a/src/physical_device_context.cc +++ b/src/physical_device_context.cc @@ -1,4 +1,5 @@ #include "physical_device_context.hh" + #include #include @@ -44,7 +45,7 @@ PhysicalDeviceContext::PhysicalDeviceContext( vtable.EnumerateDeviceExtensionProperties( physical_device, nullptr, &count, std::data(supported_extensions)); - const auto supported_extension_names = + const auto supported = supported_extensions | std::views::transform( [](const auto& supported) { return supported.extensionName; }) | @@ -52,7 +53,7 @@ PhysicalDeviceContext::PhysicalDeviceContext( return std::ranges::all_of( this->required_extensions, [&](const auto& required_extension) { - return supported_extension_names.contains(required_extension); + return supported.contains(required_extension); }); }(); } diff --git a/src/queue_context.cc b/src/queue_context.cc index a3ff8a3..63615f4 100644 --- a/src/queue_context.cc +++ b/src/queue_context.cc @@ -117,7 +117,6 @@ void QueueContext::drain_submissions_to_frame() { if (start_iter == std::end(this->submissions)) { return; } - const auto last_iter = std::prev(std::end(this->submissions)); // The last submission is either in flight, already processed, or we // just happen to be the first frame and we can just set it to our start @@ -179,10 +178,6 @@ const auto debug_log_time2 = [](auto& stream, const auto& diff) { stream << ms << " " << us << " " << ns << " ago\n"; }; -const auto debug_log_time = [](const auto& diff) { - debug_log_time2(std::cerr, diff); -}; - void QueueContext::drain_frames_to_timings() { if (!std::size(this->in_flight_frames)) { return; @@ -214,11 +209,11 @@ void QueueContext::drain_frames_to_timings() { DeviceContext::Clock::time_point_t start, end; }; - const auto sorted_intervals = [&, this]() -> auto { + const auto sorted_intervals = [&]() -> auto { auto intervals = std::vector{}; std::ranges::transform( frame.submissions, std::back_inserter(intervals), - [&, this](const auto& submission) { + [&](const auto& submission) { return Interval{ .start = submission->start_handle->get_time_required(), .end = submission->end_handle->get_time_required(), @@ -286,12 +281,11 @@ void QueueContext::drain_frames_to_timings() { const auto cputime = frame.submissions.front()->enqueued_time - cpu_start; - auto timing = Timing{ + this->timings.emplace_back(std::make_unique(Timing{ .gputime = gputime, .cputime = cputime, .frame = frame, - }; - this->timings.emplace_back(std::make_unique(timing)); + })); this->in_flight_frames.pop_front(); } @@ -306,10 +300,7 @@ void QueueContext::drain_frames_to_timings() { } void QueueContext::sleep_in_present() { - const auto& device = this->device_context; - const auto& vtable = device.vtable; - - // After calling this, any remaining frames are truly *in fligh*. + // After calling this, any remaining frames are truly in flight. this->drain_frames_to_timings(); if (!std::size(this->in_flight_frames)) { return; diff --git a/src/timestamp_pool.cc b/src/timestamp_pool.cc index 7230bb9..5d2335a 100644 --- a/src/timestamp_pool.cc +++ b/src/timestamp_pool.cc @@ -30,7 +30,7 @@ TimestampPool::QueryChunk::QueryChunk(const QueueContext& queue_context) { return std::make_unique(std::from_range, KEYS); }(); - this->command_buffers = [&, this]() -> auto { + this->command_buffers = [&]() -> auto { auto cbs = std::make_unique>(CHUNK_SIZE); const auto cbai = VkCommandBufferAllocateInfo{ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, @@ -85,8 +85,8 @@ std::shared_ptr TimestampPool::acquire() { TimestampPool::Handle::Handle(const TimestampPool& timestamp_pool, const std::shared_ptr& origin_chunk, const std::uint64_t& query_index) - : timestamp_pool(timestamp_pool), query_pool(origin_chunk->query_pool), - query_index(query_index), origin_chunk(origin_chunk), + : timestamp_pool(timestamp_pool), origin_chunk(origin_chunk), + query_pool(origin_chunk->query_pool), query_index(query_index), command_buffer((*origin_chunk->command_buffers)[query_index]) {} TimestampPool::Handle::~Handle() { @@ -108,21 +108,21 @@ void TimestampPool::Handle::setup_command_buffers( const auto& vtable = device_context.vtable; vtable.ResetQueryPoolEXT(device_context.device, this->query_pool, - this->query_index, 1); + static_cast(this->query_index), 1); vtable.BeginCommandBuffer(this->command_buffer, &cbbi); - vtable.CmdWriteTimestamp2KHR(this->command_buffer, - VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT, - this->query_pool, this->query_index); + vtable.CmdWriteTimestamp2KHR( + this->command_buffer, VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT, + this->query_pool, static_cast(this->query_index)); vtable.EndCommandBuffer(this->command_buffer); vtable.ResetQueryPoolEXT(device_context.device, tail.query_pool, - tail.query_index, 1); + static_cast(tail.query_index), 1); vtable.ResetCommandBuffer(tail.command_buffer, 0); vtable.BeginCommandBuffer(tail.command_buffer, &cbbi); - vtable.CmdWriteTimestamp2KHR(tail.command_buffer, - VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, - tail.query_pool, tail.query_index); + vtable.CmdWriteTimestamp2KHR( + tail.command_buffer, VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, + tail.query_pool, static_cast(tail.query_index)); vtable.EndCommandBuffer(tail.command_buffer); } @@ -138,8 +138,9 @@ TimestampPool::Handle::get_time() { auto query_result = QueryResult{}; const auto r = vtable.GetQueryPoolResults( - device_ctx.device, query_pool, this->query_index, 1, - sizeof(query_result), &query_result, sizeof(query_result), + device_ctx.device, query_pool, + static_cast(this->query_index), 1, sizeof(query_result), + &query_result, sizeof(query_result), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT); assert(r == VK_SUCCESS || r == VK_NOT_READY); @@ -182,7 +183,8 @@ TimestampPool::~TimestampPool() { const auto& vtable = this->queue_context.device_context.vtable; for (const auto& query_chunk : this->query_chunks) { vtable.FreeCommandBuffers(device, this->queue_context.command_pool, - std::size(*query_chunk->command_buffers), + static_cast( + std::size(*query_chunk->command_buffers)), std::data(*query_chunk->command_buffers)); vtable.DestroyQueryPool(device, query_chunk->query_pool, nullptr); } -- cgit v1.2.3