chore(renderer): add reasons to expect attributes
This commit is contained in:
parent
8a5c662e10
commit
6b3ae06031
|
|
@ -67,7 +67,10 @@ pub fn find_graphics_queue_family(
|
||||||
let props = unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
|
let props = unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
|
||||||
|
|
||||||
for (index, prop) in props.iter().enumerate() {
|
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 index = u32::try_from(index).expect("Queue family index exceeds u32 range");
|
||||||
let graphics = prop.queue_flags.contains(vk::QueueFlags::GRAPHICS);
|
let graphics = prop.queue_flags.contains(vk::QueueFlags::GRAPHICS);
|
||||||
let present = unsafe {
|
let present = unsafe {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,10 @@ impl Renderer {
|
||||||
let command_pool = unsafe { device.create_command_pool(&pool_create_info, None)? };
|
let command_pool = unsafe { device.create_command_pool(&pool_create_info, None)? };
|
||||||
|
|
||||||
// 9. Command Buffers
|
// 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()
|
let alloc_info = vk::CommandBufferAllocateInfo::default()
|
||||||
.command_pool(command_pool)
|
.command_pool(command_pool)
|
||||||
.level(vk::CommandBufferLevel::PRIMARY)
|
.level(vk::CommandBufferLevel::PRIMARY)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,10 @@ impl Vertex {
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if the size of the vertex structure exceeds the maximum value of a 32-bit unsigned integer.
|
/// 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 {
|
pub fn get_binding_description() -> ash::vk::VertexInputBindingDescription {
|
||||||
ash::vk::VertexInputBindingDescription::default()
|
ash::vk::VertexInputBindingDescription::default()
|
||||||
.binding(0)
|
.binding(0)
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// 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> {
|
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.
|
// 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()
|
let push_constant_range = vk::PushConstantRange::default()
|
||||||
.stage_flags(vk::ShaderStageFlags::VERTEX)
|
.stage_flags(vk::ShaderStageFlags::VERTEX)
|
||||||
.offset(0)
|
.offset(0)
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,17 @@ pub struct Renderer {
|
||||||
/// The debug messenger for validation layer output.
|
/// The debug messenger for validation layer output.
|
||||||
pub(crate) debug_messenger: vk::DebugUtilsMessengerEXT,
|
pub(crate) debug_messenger: vk::DebugUtilsMessengerEXT,
|
||||||
/// Handle to the selected physical device (GPU).
|
/// 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,
|
pub(crate) physical_device: vk::PhysicalDevice,
|
||||||
/// The logical Vulkan device.
|
/// The logical Vulkan device.
|
||||||
pub(crate) device: Device,
|
pub(crate) device: Device,
|
||||||
/// The queue used for graphics operations.
|
/// The queue used for graphics operations.
|
||||||
pub(crate) graphics_queue: vk::Queue,
|
pub(crate) graphics_queue: vk::Queue,
|
||||||
/// Index of the graphics queue family.
|
/// 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,
|
pub(crate) graphics_queue_index: u32,
|
||||||
/// Surface extension loader.
|
/// Surface extension loader.
|
||||||
pub(crate) surface_loader: khr::surface::Instance,
|
pub(crate) surface_loader: khr::surface::Instance,
|
||||||
|
|
@ -37,7 +40,7 @@ pub struct Renderer {
|
||||||
/// Images acquired from the swapchain.
|
/// Images acquired from the swapchain.
|
||||||
pub(crate) swapchain_images: Vec<vk::Image>,
|
pub(crate) swapchain_images: Vec<vk::Image>,
|
||||||
/// The pixel format of the swapchain images.
|
/// 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,
|
pub(crate) swapchain_format: vk::Format,
|
||||||
/// The dimensions of the swapchain images.
|
/// The dimensions of the swapchain images.
|
||||||
pub(crate) swapchain_extent: vk::Extent2D,
|
pub(crate) swapchain_extent: vk::Extent2D,
|
||||||
|
|
@ -262,7 +265,10 @@ impl Renderer {
|
||||||
self.graphics_pipeline,
|
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 {
|
let viewport = vk::Viewport {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
|
|
@ -287,7 +293,10 @@ impl Renderer {
|
||||||
let aspect =
|
let aspect =
|
||||||
f64::from(self.swapchain_extent.width) / f64::from(self.swapchain_extent.height);
|
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(
|
let projection = glam::camera::rh::proj::vulkan::perspective(
|
||||||
45.0_f32.to_radians(),
|
45.0_f32.to_radians(),
|
||||||
aspect as f32,
|
aspect as f32,
|
||||||
|
|
@ -351,7 +360,10 @@ impl Renderer {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns a `RendererError` if new Vulkan buffers cannot be allocated or created.
|
/// 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(
|
pub fn update_mesh(
|
||||||
&mut self,
|
&mut self,
|
||||||
vertices: &[Vertex],
|
vertices: &[Vertex],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue