From 5dddb64f6a2fd072f2a26d4400f9a2a84386dc4e Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 13 Jul 2026 13:25:16 -0700 Subject: it spins!!!! ahem. more formally: provide animated uniforms to the shader, and use them the tutorial just wants us to do three matrices, and to defer all the actual math to a library it recommends. that would certainly be simpler. anyway, we use quaterion+offset for everything but the projection frustum, and do all the math ourselves Change-Id: I399f432bebb1e7ca4d4342efa1d5aaf37b32f427 Force-Push: yes --- src/graphics_permanent.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/graphics_permanent.rs') diff --git a/src/graphics_permanent.rs b/src/graphics_permanent.rs index c2225a3..b58e8a4 100644 --- a/src/graphics_permanent.rs +++ b/src/graphics_permanent.rs @@ -127,11 +127,13 @@ impl PermanentGraphicsState { = init_vulkan_device(&instance, &surface, enable_validation, enable_portability)?; + let descriptor_set_layout = init_descriptor_set_layout(&device)?; + Ok((PermanentGraphicsState { window, entry, instance, debug_messager, surface, device, - graphics_queue, presentation_queue, + graphics_queue, presentation_queue }, GraphicsStateForReinit { - physical_device, indices + physical_device, indices, descriptor_set_layout }, enable_swapchain)) } @@ -214,6 +216,17 @@ impl PermanentGraphicsState { pub struct GraphicsStateForReinit { pub physical_device: vk::PhysicalDevice, pub indices: QueueFamilyIndices, + pub descriptor_set_layout: vk::DescriptorSetLayout, +} + + +impl GraphicsStateForReinit { + #[allow(unsafe_code)] + pub fn destroy(self, device: &Device) -> () { + unsafe { + device.destroy_descriptor_set_layout(self.descriptor_set_layout, None) + }; + } } @@ -517,6 +530,29 @@ fn init_vulkan_device(instance: &Instance, surface: &vk::SurfaceKHR, } +#[allow(unsafe_code)] +fn init_descriptor_set_layout(device: &Device) + -> Result +{ + let uniform_block_binding = vk::DescriptorSetLayoutBinding::builder() + .binding(0) + .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) + .descriptor_count(1) + .stage_flags(vk::ShaderStageFlags::VERTEX); + + let bindings = [uniform_block_binding]; + let descriptor_set_layout_info + = vk::DescriptorSetLayoutCreateInfo::builder() + .bindings(&bindings); + let descriptor_set_layout = unsafe { + device.create_descriptor_set_layout(&descriptor_set_layout_info, None) + }?; + + Ok(descriptor_set_layout) +} + + + // To Vulkan, a "physical" device is the actual GPU, and a "logical" // device is per-process state that represents a connection to the GPU. // Before we can create a logical device, we must choose which physical -- cgit 1.4.1