summary refs log tree commit diff
path: root/src/graphics/window_dressing.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-08-08 05:32:41 -0700
committerIrene Knapp <ireneista@irenes.space>2026-08-08 05:32:41 -0700
commitd56eb5e4c223f5c89117cda8dfb1527e02b6a90c (patch)
tree18e02395408c2dd12e15bdaf13af7c8a54582c9a /src/graphics/window_dressing.rs
parentecee10d87f5f2c8b56647ce2a2790f03880f573c (diff)
remove physical_device from ForReinit
Vulkanalia tracks it for us in Device. it's used in Model, so it wasn't strictly in-scope for ForReinit; this solves the problem and simplifies some stuff.

Force-Push: yes
Change-Id: I8e38c236b3dc4c112671382a062c9ada2f34fbb1
Diffstat (limited to 'src/graphics/window_dressing.rs')
-rw-r--r--src/graphics/window_dressing.rs80
1 files changed, 38 insertions, 42 deletions
diff --git a/src/graphics/window_dressing.rs b/src/graphics/window_dressing.rs
index 065bd53..09410bc 100644
--- a/src/graphics/window_dressing.rs
+++ b/src/graphics/window_dressing.rs
@@ -109,33 +109,30 @@ impl WindowDressing {
     let surface = &permanent.surface;
     let device = &permanent.device;
     let graphics_queue = &permanent.graphics_queue;
-    let physical_device = &for_reinit.physical_device;
     let sample_count = for_reinit.sample_count;
     let indices = &for_reinit.indices;
 
     let swapchain = init_swapchain(
-            window, instance, surface, &physical_device, device, &indices)?;
+            window, instance, surface, device, &indices)?;
 
     let (color_image, color_image_memory, color_image_view)
-            = init_color(instance, &physical_device, device,
-                         &swapchain.extent, sample_count, swapchain.format)?;
+            = init_color(instance, device, &swapchain.extent, sample_count,
+                         swapchain.format)?;
 
     let (depth_image, depth_image_memory, depth_image_view, depth_format)
-            = init_depth(instance, &physical_device, device,
-                         &swapchain.extent, sample_count)?;
+            = init_depth(instance, device, &swapchain.extent, sample_count)?;
 
     let (primary_command_pool, transient_command_pool)
             = init_command_pools(device, indices)?;
 
     let (texture_image, texture_image_memory, texture_image_view, mip_count)
-            = init_texture(instance, physical_device, device,
-                           graphics_queue, &transient_command_pool)?;
+            = init_texture(instance, device, graphics_queue,
+                           &transient_command_pool)?;
 
     let sampler = init_sampler(&device, &enable_anisotropy, mip_count)?;
 
     let (uniform_buffers, uniform_buffer_memory)
-            = init_uniform_buffers(instance, physical_device, device,
-                                   swapchain.images.len())?;
+            = init_uniform_buffers(instance, device, swapchain.images.len())?;
 
     let descriptor_pool
             = init_descriptor_pool(device, swapchain.images.len())?;
@@ -174,7 +171,6 @@ impl WindowDressing {
     let instance = &permanent.instance;
     let surface = &permanent.surface;
     let device = &permanent.device;
-    let physical_device = &for_reinit.physical_device;
     let sample_count = for_reinit.sample_count;
     let indices = &for_reinit.indices;
 
@@ -182,20 +178,18 @@ impl WindowDressing {
 
     self.destroy_replaceable(device);
 
-    let swapchain = init_swapchain(
-            window, instance, surface, &physical_device, device, &indices)?;
+    let swapchain
+            = init_swapchain(window, instance, surface, device, &indices)?;
 
     let (color_image, color_image_memory, color_image_view)
-            = init_color(instance, &physical_device, device,
-                         &swapchain.extent, sample_count, swapchain.format)?;
+            = init_color(instance, device, &swapchain.extent, sample_count,
+                         swapchain.format)?;
 
     let (depth_image, depth_image_memory, depth_image_view, depth_format)
-            = init_depth(instance, &physical_device, device,
-                         &swapchain.extent, sample_count)?;
+            = init_depth(instance, device, &swapchain.extent, sample_count)?;
 
     let (uniform_buffers, uniform_buffer_memory)
-            = init_uniform_buffers(instance, physical_device, device,
-                                   swapchain.images.len())?;
+            = init_uniform_buffers(instance, device, swapchain.images.len())?;
 
     // Notice that we did NOT reuse the descriptor pool.
     let descriptor_pool
@@ -284,14 +278,15 @@ impl WindowDressing {
 
 #[allow(unsafe_code)]
 fn init_swapchain(window: &Window, instance: &Instance,
-                  surface: &vk::SurfaceKHR,
-                  physical_device: &vk::PhysicalDevice, device: &Device,
+                  surface: &vk::SurfaceKHR, device: &Device,
                   indices: &QueueFamilyIndices)
     -> Result<Swapchain>
 {
+  let physical_device = device.physical_device();
+
   let (capabilities, formats, presentation_modes)
           = PermanentGraphicsState::find_device_swapchain_features(
-                instance, surface, physical_device)?.require()?;
+                instance, surface, &physical_device)?.require()?;
 
   let format = pick_surface_format(&formats)?;
 
@@ -361,13 +356,12 @@ fn init_swapchain(window: &Window, instance: &Instance,
 
 
 #[allow(unsafe_code)]
-fn init_color(instance: &Instance, physical_device: &vk::PhysicalDevice,
-              device: &Device, extent: &vk::Extent2D,
+fn init_color(instance: &Instance, device: &Device, extent: &vk::Extent2D,
               sample_count: vk::SampleCountFlags, format: vk::Format)
     -> Result<(vk::Image, vk::DeviceMemory, vk::ImageView)>
 {
   let (image, image_memory)
-          = allocate_image(instance, physical_device, device,
+          = allocate_image(instance, device,
                            extent.width, extent.height, 1, sample_count,
                            format,
                            vk::ImageTiling::OPTIMAL,
@@ -383,15 +377,16 @@ fn init_color(instance: &Instance, physical_device: &vk::PhysicalDevice,
 
 
 #[allow(unsafe_code)]
-fn init_depth(instance: &Instance, physical_device: &vk::PhysicalDevice,
-              device: &Device, extent: &vk::Extent2D,
+fn init_depth(instance: &Instance, device: &Device, extent: &vk::Extent2D,
               sample_count: vk::SampleCountFlags)
     -> Result<(vk::Image, vk::DeviceMemory, vk::ImageView, vk::Format)>
 {
-  let format = pick_depth_format(instance, physical_device)?;
+  let physical_device = device.physical_device();
+
+  let format = pick_depth_format(instance, &physical_device)?;
 
   let (image, image_memory)
-          = allocate_image(instance, physical_device, device,
+          = allocate_image(instance, device,
                            extent.width, extent.height, 1, sample_count,
                            format,
                            vk::ImageTiling::OPTIMAL,
@@ -406,11 +401,12 @@ fn init_depth(instance: &Instance, physical_device: &vk::PhysicalDevice,
 
 
 #[allow(unsafe_code)]
-fn init_texture(instance: &Instance,
-                physical_device: &vk::PhysicalDevice, device: &Device,
-                queue: &vk::Queue, command_pool: &vk::CommandPool)
+fn init_texture(instance: &Instance, device: &Device, queue: &vk::Queue,
+                command_pool: &vk::CommandPool)
     -> Result<(vk::Image, vk::DeviceMemory, vk::ImageView, u32)>
 {
+  let physical_device = device.physical_device();
+
   let png = include_bytes!("../../textures/forest_leaves_04_diff.png");
 
   let decoder = Decoder::new(Cursor::new(png));
@@ -419,7 +415,7 @@ fn init_texture(instance: &Instance,
   let (width, height) = reader.info().size();
 
   let format_properties = unsafe {
-    instance.get_physical_device_format_properties(*physical_device,
+    instance.get_physical_device_format_properties(physical_device,
                                                    vk::Format::R8G8B8A8_SRGB)
   };
   let has_linear_filter = format_properties
@@ -437,10 +433,10 @@ fn init_texture(instance: &Instance,
   reader.next_frame(&mut pixels)?;
 
   let (staging_buffer, staging_memory, _byte_size)
-          = stage_in_buffer(instance, physical_device, device, &pixels)?;
+          = stage_in_buffer(instance, device, &pixels)?;
 
   let (image, image_memory)
-          = allocate_image(instance, physical_device, device,
+          = allocate_image(instance, device,
                            width, height, mip_count, vk::SampleCountFlags::_1,
                            vk::Format::R8G8B8A8_SRGB,
                            vk::ImageTiling::OPTIMAL,
@@ -472,9 +468,7 @@ fn init_texture(instance: &Instance,
 }
 
 
-fn init_uniform_buffers(instance: &Instance,
-                        physical_device: &vk::PhysicalDevice, device: &Device,
-                        count: usize)
+fn init_uniform_buffers(instance: &Instance, device: &Device, count: usize)
     -> Result<(Vec<vk::Buffer>, Vec<vk::DeviceMemory>)>
 {
   let mut buffers = Vec::new();
@@ -482,7 +476,7 @@ fn init_uniform_buffers(instance: &Instance,
 
   for _ in 0 .. count {
     let (buffer, memory) = allocate_buffer(
-            instance, physical_device, device,
+            instance, device,
             size_of::<UniformBlock<f32>>() as vk::DeviceSize,
             vk::BufferUsageFlags::UNIFORM_BUFFER,
             vk::MemoryPropertyFlags::HOST_COHERENT
@@ -721,13 +715,15 @@ fn pick_image_extent(window: &Window,
 
 
 #[allow(unsafe_code)]
-fn allocate_image(instance: &Instance, physical_device: &vk::PhysicalDevice,
-                  device: &Device, width: u32, height: u32, mip_count: u32,
+fn allocate_image(instance: &Instance, device: &Device, width: u32,
+                  height: u32, mip_count: u32,
                   sample_count: vk::SampleCountFlags, format: vk::Format,
                   tiling: vk::ImageTiling, usage: vk::ImageUsageFlags,
                   memory_flags: vk::MemoryPropertyFlags)
     -> Result<(vk::Image, vk::DeviceMemory)>
 {
+  let physical_device = device.physical_device();
+
   let image_info = vk::ImageCreateInfo::builder()
           .image_type(vk::ImageType::_2D)
           .extent(vk::Extent3D { width, height, depth: 1 })
@@ -744,7 +740,7 @@ fn allocate_image(instance: &Instance, physical_device: &vk::PhysicalDevice,
 
   let requirements = unsafe { device.get_image_memory_requirements(image) };
 
-  let type_index = pick_memory_type(instance, physical_device,
+  let type_index = pick_memory_type(instance, &physical_device,
                                     &memory_flags, &requirements)?;
 
   let image_memory_info = vk::MemoryAllocateInfo::builder()