From 4158fed109ae789cb3ca7ff53c2790797a3b4087 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 9 Aug 2026 17:10:03 -0700 Subject: refactor Texture into its own thing as part of this, the command pools are moved from window dressing to permanent note also how mip count is a value computed by loading the texture, and used when creating the sampler, which is part of the window dressing. the assumption about how it's computed will have to change when we support multiple textures, but for now we settle for just pushing the assumption to the top level. Force-Push: yes Change-Id: I545c53feedc99628fbe943120798fe66fe9e065b --- src/graphics/render_state.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/graphics/render_state.rs') diff --git a/src/graphics/render_state.rs b/src/graphics/render_state.rs index d918e9a..5848ac8 100644 --- a/src/graphics/render_state.rs +++ b/src/graphics/render_state.rs @@ -4,6 +4,7 @@ use crate::graphics::permanent::{ PermanentGraphicsState, GraphicsStateForReinit }; use crate::graphics::model::Model; +use crate::graphics::texture::Texture; use crate::graphics::window_dressing::WindowDressing; use crate::shader_data::{ Vertex, UniformBlock, VertexPushBlock }; @@ -34,18 +35,17 @@ pub struct RenderState { impl RenderState { pub fn new(permanent: &PermanentGraphicsState, for_reinit: &GraphicsStateForReinit, - window_dressing: &WindowDressing) + window_dressing: &WindowDressing, texture: &Texture) -> Result { let device = &permanent.device; + let primary_command_pool = &permanent.primary_command_pool; let sample_count = for_reinit.sample_count; let descriptor_set_layout = &for_reinit.descriptor_set_layout; - let primary_command_pool = &window_dressing.primary_command_pool; let swapchain = &window_dressing.swapchain; let depth_format = &window_dressing.depth_format; let color_image_view = &window_dressing.color_image_view; let depth_image_view = &window_dressing.depth_image_view; - let texture_image_view = &window_dressing.texture_image_view; let uniform_buffers = &window_dressing.uniform_buffers; let descriptor_pool = &window_dressing.descriptor_pool; let sampler = &window_dressing.sampler; @@ -68,7 +68,7 @@ impl RenderState { = init_descriptor_sets(device, descriptor_set_layout, &uniform_buffers, &descriptor_pool, swapchain.images.len(), - &texture_image_view, &sampler)?; + &texture.image_view, &sampler)?; let model = None; @@ -87,24 +87,23 @@ impl RenderState { // idle. pub fn reinit(&mut self, permanent: &PermanentGraphicsState, for_reinit: &GraphicsStateForReinit, - window_dressing: &WindowDressing) + window_dressing: &WindowDressing, texture: &Texture) -> Result<()> { + self.destroy_replaceable(permanent); + let device = &permanent.device; + let primary_command_pool = &permanent.primary_command_pool; let sample_count = for_reinit.sample_count; let descriptor_set_layout = &for_reinit.descriptor_set_layout; - let primary_command_pool = &window_dressing.primary_command_pool; let swapchain = &window_dressing.swapchain; let depth_format = &window_dressing.depth_format; let color_image_view = &window_dressing.color_image_view; let depth_image_view = &window_dressing.depth_image_view; - let texture_image_view = &window_dressing.texture_image_view; let uniform_buffers = &window_dressing.uniform_buffers; let descriptor_pool = &window_dressing.descriptor_pool; let sampler = &window_dressing.sampler; - self.destroy_replaceable(device, primary_command_pool); - let render_pass = init_render_pass(device, sample_count, &swapchain.format, &depth_format)?; @@ -124,7 +123,7 @@ impl RenderState { = init_descriptor_sets(device, descriptor_set_layout, &uniform_buffers, &descriptor_pool, swapchain.images.len(), - texture_image_view, sampler)?; + &texture.image_view, sampler)?; self.render_pass = render_pass; self.pipeline = pipeline; @@ -139,20 +138,20 @@ impl RenderState { // This relies on its caller to have already waited for the device to be // idle. #[allow(unsafe_code)] - pub fn destroy(mut self, device: &Device, - window_dressing: &WindowDressing) + pub fn destroy(mut self, permanent: &PermanentGraphicsState) { - self.destroy_replaceable(device, &window_dressing.primary_command_pool); + self.destroy_replaceable(permanent); if let Some(model) = self.model { - model.destroy(device); + model.destroy(&permanent.device); } } #[allow(unsafe_code)] - fn destroy_replaceable(&mut self, device: &Device, - primary_command_pool: &vk::CommandPool) + fn destroy_replaceable(&mut self, permanent: &PermanentGraphicsState) { + let device = &permanent.device; + for framebuffer in &self.framebuffers { unsafe { device.destroy_framebuffer(*framebuffer, None) }; } @@ -163,7 +162,7 @@ impl RenderState { // buffers. We promise ourselves to free buffers in the transient pool // immediately after using them. unsafe { - device.free_command_buffers(*primary_command_pool, + device.free_command_buffers(permanent.primary_command_pool, &self.command_buffers) }; -- cgit 1.4.1