chore(renderer): add reasons to expect attributes

This commit is contained in:
Serkyo 2026-07-13 00:39:49 +02:00
parent 8a5c662e10
commit 6b3ae06031
5 changed files with 34 additions and 10 deletions

View file

@ -67,7 +67,10 @@ pub fn find_graphics_queue_family(
let props = unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
for (index, prop) in props.iter().enumerate() {
#[expect(clippy::expect_used)]
#[expect(
clippy::expect_used,
reason = "a physical device's queue-family count never approaches u32::MAX"
)]
let index = u32::try_from(index).expect("Queue family index exceeds u32 range");
let graphics = prop.queue_flags.contains(vk::QueueFlags::GRAPHICS);
let present = unsafe {

View file

@ -96,7 +96,10 @@ impl Renderer {
let command_pool = unsafe { device.create_command_pool(&pool_create_info, None)? };
// 9. Command Buffers
#[expect(clippy::expect_used)]
#[expect(
clippy::expect_used,
reason = "MAX_FRAMES_IN_FLIGHT is a small compile-time constant"
)]
let alloc_info = vk::CommandBufferAllocateInfo::default()
.command_pool(command_pool)
.level(vk::CommandBufferLevel::PRIMARY)

View file

@ -24,7 +24,10 @@ impl Vertex {
///
/// # Panics
/// Panics if the size of the vertex structure exceeds the maximum value of a 32-bit unsigned integer.
#[expect(clippy::expect_used)]
#[expect(
clippy::expect_used,
reason = "the vertex struct size is far below u32::MAX"
)]
pub fn get_binding_description() -> ash::vk::VertexInputBindingDescription {
ash::vk::VertexInputBindingDescription::default()
.binding(0)

View file

@ -29,7 +29,10 @@ pub fn create_shader_module(
/// This layout defines any push constants or descriptor sets (textures/UBOs) accessed by the shaders during execution.
pub fn create_pipeline_layout(device: &Device) -> Result<vk::PipelineLayout, RendererError> {
// A single push constant range is defined for the MVP matrix, allowing it to be updated for every draw call with high efficiency.
#[expect(clippy::expect_used)]
#[expect(
clippy::expect_used,
reason = "size_of::<Mat4>() is 64 bytes, well within u32 range"
)]
let push_constant_range = vk::PushConstantRange::default()
.stage_flags(vk::ShaderStageFlags::VERTEX)
.offset(0)

View file

@ -17,14 +17,17 @@ pub struct Renderer {
/// The debug messenger for validation layer output.
pub(crate) debug_messenger: vk::DebugUtilsMessengerEXT,
/// Handle to the selected physical device (GPU).
#[expect(dead_code)]
#[expect(dead_code, reason = "retained for later device-capability queries")]
pub(crate) physical_device: vk::PhysicalDevice,
/// The logical Vulkan device.
pub(crate) device: Device,
/// The queue used for graphics operations.
pub(crate) graphics_queue: vk::Queue,
/// Index of the graphics queue family.
#[expect(dead_code)]
#[expect(
dead_code,
reason = "retained for later queue-family-dependent operations"
)]
pub(crate) graphics_queue_index: u32,
/// Surface extension loader.
pub(crate) surface_loader: khr::surface::Instance,
@ -37,7 +40,7 @@ pub struct Renderer {
/// Images acquired from the swapchain.
pub(crate) swapchain_images: Vec<vk::Image>,
/// The pixel format of the swapchain images.
#[expect(dead_code)]
#[expect(dead_code, reason = "retained for later swapchain recreation")]
pub(crate) swapchain_format: vk::Format,
/// The dimensions of the swapchain images.
pub(crate) swapchain_extent: vk::Extent2D,
@ -262,7 +265,10 @@ impl Renderer {
self.graphics_pipeline,
);
#[expect(clippy::cast_precision_loss)]
#[expect(
clippy::cast_precision_loss,
reason = "swapchain extents are within f32's exact-integer range"
)]
let viewport = vk::Viewport {
x: 0.0,
y: 0.0,
@ -287,7 +293,10 @@ impl Renderer {
let aspect =
f64::from(self.swapchain_extent.width) / f64::from(self.swapchain_extent.height);
#[expect(clippy::cast_possible_truncation)]
#[expect(
clippy::cast_possible_truncation,
reason = "the aspect ratio is a small value; f32 precision is sufficient"
)]
let projection = glam::camera::rh::proj::vulkan::perspective(
45.0_f32.to_radians(),
aspect as f32,
@ -351,7 +360,10 @@ impl Renderer {
///
/// # Errors
/// Returns a `RendererError` if new Vulkan buffers cannot be allocated or created.
#[expect(clippy::cast_possible_truncation)]
#[expect(
clippy::cast_possible_truncation,
reason = "a chunk mesh's index count never approaches u32::MAX"
)]
pub fn update_mesh(
&mut self,
vertices: &[Vertex],