diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-07-09 11:47:33 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-07-09 11:47:33 -0700 |
| commit | 701fc455953af6bb7967df40d22aad596e7306d0 (patch) | |
| tree | a8d0d77d66f09f4aabbe47cd09fb0ca1a3c39c2d /src | |
| parent | 399c1db1424f51d5897b839b2d11cbfa6f4a6205 (diff) | |
combine init_vulkan_entry and init_vulkan_instance into init_vulkan
yay Force-Push: yes Change-Id: I65bef1f64c8e1eaef0897d9a01a2bf09cdef47f1
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/src/main.rs b/src/main.rs index 44e92bd..eb9c5d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,19 +202,17 @@ impl Surreality { fn init(&mut self, event_loop: &ActiveEventLoop) -> Result<()> { let window = Self::init_window(event_loop)?; - let entry = Self::init_vulkan_entry()?; - let (instance, - debug_messager, - - // There are a few Vulkan features (in the informal sense of - // "feature") that we want to be able to run both with and without. - // Here, we have booleans describing which we're doing. - // - // These are only used to communicate between initialization - // phases; we don't keep them around after that. + // There are a few Vulkan features (in the informal sense of + // "feature") that we want to be able to run both with and without. + // The enable_* values, here and below, are wrapped booleans that describe + // those choices. + // + // These are only used to communicate between initialization + // phases; we don't keep them around after that. + let (entry, instance, debug_messager, enable_portability, enable_validation) - = Self::init_vulkan_instance(&window, &entry)?; + = Self::init_vulkan(&window)?; let surface = Self::init_surface(&window, &instance)?; @@ -273,7 +271,7 @@ impl Surreality { fn init_window(event_loop: &ActiveEventLoop) -> Result<Window> { // Notice that we do this before having a Vulkan instance. The window is // actually a parameter needed to create the instance; see - // init_vulkan_instance(), below. + // init_vulkan(), below. let window_attributes = WindowAttributes::default() .with_title("Love, Curiosity, Justice") .with_inner_size(LogicalSize::new(1024, 768)); @@ -281,10 +279,14 @@ impl Surreality { Ok(event_loop.create_window(window_attributes)?) } - // TODO this is another candidate for rolling into its parent - // (in addition to init_surface, which is below. what is time) #[allow(unsafe_code)] - fn init_vulkan_entry() -> Result<Entry> { + fn init_vulkan(window: &Window) + -> Result<(Entry, Instance, Option<vk::DebugUtilsMessengerEXT>, + EnablePortability, EnableValidation)> + { + let enable_validation = cfg!(feature = "vulkan-validation") + || cfg!(debug_assertions); + // Okay, so, a Vulkan "entry" is a small set of functions which are used // to dynamically load all the rest of Vulkan. It's our responsibility to // know how to load the entry, then it will take care of the rest. At @@ -297,17 +299,6 @@ impl Surreality { let loader = unsafe { LibloadingLoader::new(LIBRARY) }?; let entry = unsafe { Entry::new(loader) }?; - Ok(entry) - } - - #[allow(unsafe_code)] - fn init_vulkan_instance(window: &Window, entry: &Entry) - -> Result<(Instance, Option<vk::DebugUtilsMessengerEXT>, - EnablePortability, EnableValidation)> - { - let enable_validation = cfg!(feature = "vulkan-validation") - || cfg!(debug_assertions); - // Since there's a lot of factors going into our instance creation // request, we'll build up the parameters mutably. let mut flags = vk::InstanceCreateFlags::empty(); @@ -451,7 +442,8 @@ impl Surreality { None }; - Ok((instance, debug_messager, enable_portability, enable_validation)) + Ok((entry, instance, debug_messager, + enable_portability, enable_validation)) } // TODO this is so short that it can likely be eliminated |