some refactoring
This commit is contained in:
parent
bbff0d9929
commit
43ae43e8b8
1 changed files with 49 additions and 20 deletions
|
@ -16,23 +16,15 @@ use winit::window::Window;
|
||||||
const SHADER: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/shader.spv"));
|
const SHADER: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/shader.spv"));
|
||||||
|
|
||||||
pub struct WindowData {
|
pub struct WindowData {
|
||||||
scale_factor: u32,
|
|
||||||
|
|
||||||
// entry: Entry,
|
|
||||||
instance: Instance,
|
instance: Instance,
|
||||||
device: Device,
|
device: Device,
|
||||||
surface_loader: Surface,
|
surface_loader: Surface,
|
||||||
swapchain_loader: Swapchain,
|
swapchain_loader: Swapchain,
|
||||||
// pdevice: vk::PhysicalDevice,
|
|
||||||
// device_memory_properties: vk::PhysicalDeviceMemoryProperties,
|
|
||||||
// queue_family_index: u32,
|
|
||||||
present_queue: vk::Queue,
|
present_queue: vk::Queue,
|
||||||
|
|
||||||
surface: vk::SurfaceKHR,
|
surface: vk::SurfaceKHR,
|
||||||
// surface_format: vk::SurfaceFormatKHR,
|
|
||||||
surface_resolution: vk::Extent2D,
|
surface_resolution: vk::Extent2D,
|
||||||
swapchain: vk::SwapchainKHR,
|
swapchain: vk::SwapchainKHR,
|
||||||
// present_images: Vec<vk::Image>,
|
|
||||||
present_image_views: Vec<vk::ImageView>,
|
present_image_views: Vec<vk::ImageView>,
|
||||||
|
|
||||||
pool: vk::CommandPool,
|
pool: vk::CommandPool,
|
||||||
|
@ -54,12 +46,21 @@ pub struct WindowData {
|
||||||
framebuffers: Vec<vk::Framebuffer>,
|
framebuffers: Vec<vk::Framebuffer>,
|
||||||
pipeline_layout: vk::PipelineLayout,
|
pipeline_layout: vk::PipelineLayout,
|
||||||
descriptor_sets: Vec<vk::DescriptorSet>,
|
descriptor_sets: Vec<vk::DescriptorSet>,
|
||||||
graphic_pipeline: vk::Pipeline,
|
graphics_pipelines: Vec<vk::Pipeline>,
|
||||||
viewports: [vk::Viewport; 1],
|
viewports: [vk::Viewport; 1],
|
||||||
scissors: [vk::Rect2D; 1],
|
scissors: [vk::Rect2D; 1],
|
||||||
index_buffer: vk::Buffer,
|
index_buffer: vk::Buffer,
|
||||||
index_buffer_data: [u32; 6],
|
index_buffer_data: [u32; 6],
|
||||||
|
|
||||||
|
shader_module: vk::ShaderModule,
|
||||||
|
vertex_input_buffer_memory: vk::DeviceMemory,
|
||||||
|
texture_memory: vk::DeviceMemory,
|
||||||
|
index_buffer_memory: vk::DeviceMemory,
|
||||||
|
tex_image_view: vk::ImageView,
|
||||||
|
desc_set_layouts: [vk::DescriptorSetLayout; 1],
|
||||||
|
descriptor_pool: vk::DescriptorPool,
|
||||||
|
sampler: vk::Sampler,
|
||||||
|
|
||||||
image_buffer: vk::Buffer,
|
image_buffer: vk::Buffer,
|
||||||
image_buffer_memory: vk::DeviceMemory,
|
image_buffer_memory: vk::DeviceMemory,
|
||||||
image_buffer_memory_req: vk::MemoryRequirements,
|
image_buffer_memory_req: vk::MemoryRequirements,
|
||||||
|
@ -877,24 +878,15 @@ impl WindowData {
|
||||||
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_infos], None)
|
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_infos], None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let graphic_pipeline = graphics_pipelines[0];
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
scale_factor: factor,
|
|
||||||
// entry,
|
|
||||||
instance,
|
instance,
|
||||||
device,
|
device,
|
||||||
surface_loader,
|
surface_loader,
|
||||||
swapchain_loader,
|
swapchain_loader,
|
||||||
// pdevice,
|
|
||||||
// device_memory_properties,
|
|
||||||
// queue_family_index,
|
|
||||||
present_queue,
|
present_queue,
|
||||||
surface,
|
surface,
|
||||||
// surface_format,
|
|
||||||
surface_resolution,
|
surface_resolution,
|
||||||
swapchain,
|
swapchain,
|
||||||
// present_images,
|
|
||||||
present_image_views,
|
present_image_views,
|
||||||
pool,
|
pool,
|
||||||
draw_command_buffer,
|
draw_command_buffer,
|
||||||
|
@ -911,11 +903,19 @@ impl WindowData {
|
||||||
framebuffers,
|
framebuffers,
|
||||||
pipeline_layout,
|
pipeline_layout,
|
||||||
descriptor_sets,
|
descriptor_sets,
|
||||||
graphic_pipeline,
|
graphics_pipelines,
|
||||||
viewports,
|
viewports,
|
||||||
scissors,
|
scissors,
|
||||||
index_buffer,
|
index_buffer,
|
||||||
index_buffer_data,
|
index_buffer_data,
|
||||||
|
shader_module,
|
||||||
|
vertex_input_buffer_memory,
|
||||||
|
texture_memory,
|
||||||
|
index_buffer_memory,
|
||||||
|
tex_image_view,
|
||||||
|
desc_set_layouts,
|
||||||
|
descriptor_pool,
|
||||||
|
sampler,
|
||||||
image_buffer,
|
image_buffer,
|
||||||
image_buffer_memory,
|
image_buffer_memory,
|
||||||
image_buffer_memory_req,
|
image_buffer_memory_req,
|
||||||
|
@ -1081,7 +1081,7 @@ impl WindowData {
|
||||||
device.cmd_bind_pipeline(
|
device.cmd_bind_pipeline(
|
||||||
draw_command_buffer,
|
draw_command_buffer,
|
||||||
vk::PipelineBindPoint::GRAPHICS,
|
vk::PipelineBindPoint::GRAPHICS,
|
||||||
self.graphic_pipeline,
|
self.graphics_pipelines[0],
|
||||||
);
|
);
|
||||||
device.cmd_set_viewport(draw_command_buffer, 0, &self.viewports);
|
device.cmd_set_viewport(draw_command_buffer, 0, &self.viewports);
|
||||||
device.cmd_set_scissor(draw_command_buffer, 0, &self.scissors);
|
device.cmd_set_scissor(draw_command_buffer, 0, &self.scissors);
|
||||||
|
@ -1127,6 +1127,35 @@ impl Drop for WindowData {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.device.device_wait_idle().unwrap();
|
self.device.device_wait_idle().unwrap();
|
||||||
|
|
||||||
|
for pipeline in &self.graphics_pipelines {
|
||||||
|
self.device.destroy_pipeline(*pipeline, None);
|
||||||
|
}
|
||||||
|
self.device
|
||||||
|
.destroy_pipeline_layout(self.pipeline_layout, None);
|
||||||
|
self.device.destroy_shader_module(self.shader_module, None);
|
||||||
|
self.device.free_memory(self.image_buffer_memory, None);
|
||||||
|
self.device.destroy_buffer(self.image_buffer, None);
|
||||||
|
self.device.free_memory(self.texture_memory, None);
|
||||||
|
self.device.destroy_image_view(self.tex_image_view, None);
|
||||||
|
self.device.destroy_image(self.texture_image, None);
|
||||||
|
self.device.free_memory(self.index_buffer_memory, None);
|
||||||
|
self.device.destroy_buffer(self.index_buffer, None);
|
||||||
|
self.device
|
||||||
|
.free_memory(self.vertex_input_buffer_memory, None);
|
||||||
|
self.device.destroy_buffer(self.vertex_input_buffer, None);
|
||||||
|
for &descriptor_set_layout in self.desc_set_layouts.iter() {
|
||||||
|
self.device
|
||||||
|
.destroy_descriptor_set_layout(descriptor_set_layout, None);
|
||||||
|
}
|
||||||
|
self.device
|
||||||
|
.destroy_descriptor_pool(self.descriptor_pool, None);
|
||||||
|
self.device.destroy_sampler(self.sampler, None);
|
||||||
|
for framebuffer in &self.framebuffers {
|
||||||
|
self.device.destroy_framebuffer(*framebuffer, None);
|
||||||
|
}
|
||||||
|
self.device.destroy_render_pass(self.renderpass, None);
|
||||||
|
|
||||||
self.device
|
self.device
|
||||||
.destroy_semaphore(self.present_complete_semaphore, None);
|
.destroy_semaphore(self.present_complete_semaphore, None);
|
||||||
self.device
|
self.device
|
||||||
|
|
Loading…
Add table
Reference in a new issue