non working update, about to cargo fix

main
Nathan Buck 11 months ago
parent 2ac0ae1bcc
commit 8801d9268d

@ -20,7 +20,10 @@ fn main() -> std::io::Result<()> {
let shader_path_string: String = "./target/shaders/".to_string() let shader_path_string: String = "./target/shaders/".to_string()
+ shader_path.file_name().unwrap().to_str().unwrap() + shader_path.file_name().unwrap().to_str().unwrap()
+ ".spv"; + ".spv";
println!("cargo:warning=compiling destination: {:?}", shader_path_string); println!(
"cargo:warning=compiling destination: {:?}",
shader_path_string
);
let shader_file: &OsStr = OsStr::new::<str>(shader_path_string.as_str()); let shader_file: &OsStr = OsStr::new::<str>(shader_path_string.as_str());
Command::new("glslc") Command::new("glslc")
.arg("-c") .arg("-c")
@ -41,17 +44,16 @@ fn main() -> std::io::Result<()> {
let bin_path = entry.path(); let bin_path = entry.path();
let bin_path_string = bin_path.file_name().unwrap().to_str().unwrap().to_string(); let bin_path_string = bin_path.file_name().unwrap().to_str().unwrap().to_string();
let shader_type = ( let shader_type = (match bin_path_string.split(".").nth(1).unwrap() {
match bin_path_string.split(".").nth(1).unwrap() { "vert" => "VERTEX",
"vert" => "VERTEX", "frag" => "FRAGMENT",
"frag" => "FRAGMENT", "comp" => "COMPUTE",
"comp" => "COMPUTE", "tesc" => "TESSELLATION_CONTROL",
"tesc" => "TESSELLATION_CONTROL", "tese" => "TESSELLATION_EVALUATION",
"tese" => "TESSELLATION_EVALUATION", "geom" => "GEOMETRY",
"geom" => "GEOMETRY", _ => panic!("unknown shader type"),
_ => panic!("unknown shader type"), })
} .to_string();
).to_string();
txt += &("(include_bytes!(\"../target/shaders/".to_owned() txt += &("(include_bytes!(\"../target/shaders/".to_owned()
+ &bin_path_string + &bin_path_string
+ "\").to_vec(), ShaderStageFlags::" + "\").to_vec(), ShaderStageFlags::"

@ -1,7 +1,10 @@
use memoffset::offset_of;
use ash::vk; use ash::vk;
use rand::{thread_rng, distributions::{Distribution, Uniform}};
use cgmath::{InnerSpace, Vector2, Vector4}; use cgmath::{InnerSpace, Vector2, Vector4};
use memoffset::offset_of;
use rand::{
distributions::{Distribution, Uniform},
thread_rng,
};
use crate::utility::constants::*; use crate::utility::constants::*;
use std::f32::consts::PI; use std::f32::consts::PI;
@ -28,13 +31,16 @@ impl Particle {
let theta = between.sample(&mut rng) * 2.0 * PI; let theta = between.sample(&mut rng) * 2.0 * PI;
let x = r * theta.cos() * WINDOW_HEIGHT as f32 * WINDOW_WIDTH as f32; let x = r * theta.cos() * WINDOW_HEIGHT as f32 * WINDOW_WIDTH as f32;
let y = r * theta.sin(); let y = r * theta.sin();
res.push( res.push(Particle {
Particle { pos: Vector2::new(x, y),
pos: Vector2::new(x, y), vel: Vector2::new(x, y).normalize() * 0.00025,
vel: Vector2::new(x, y).normalize() * 0.00025, color: Vector4::new(
color: Vector4::new(between.sample(&mut rng), between.sample(&mut rng), between.sample(&mut rng), 1.0), between.sample(&mut rng),
} between.sample(&mut rng),
) between.sample(&mut rng),
1.0,
),
})
} }
res res
} }

@ -1,10 +1,10 @@
pub mod entities;
pub mod render;
pub mod shaders; pub mod shaders;
pub mod utility; pub mod utility;
pub mod render;
pub mod entities;
use winit::event_loop::EventLoop;
use render::VulkanApp; use render::VulkanApp;
use winit::event_loop::EventLoop;
fn main() { fn main() {
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();

@ -1,10 +1,10 @@
use crate::{ use crate::{
shaders::*, entities::*, utility, utility::constants::*, utility::debug::*, utility::share, utility::structures::*, entities::*, shaders::*, utility, utility::constants::*, utility::debug::*, utility::share,
utility::structures::*,
}; };
use ash::{vk, Entry}; use ash::{vk, Entry};
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
@ -362,8 +362,7 @@ impl VulkanApp {
let mut shader_modules: Vec<vk::PipelineShaderStageCreateInfo> = vec![]; let mut shader_modules: Vec<vk::PipelineShaderStageCreateInfo> = vec![];
let main_function = CString::new("main").unwrap(); let main_function = CString::new("main").unwrap();
for (shader, stage_i) in shaders() { for (shader, stage_i) in shaders() {
shader_modules.push( shader_modules.push(vk::PipelineShaderStageCreateInfo {
vk::PipelineShaderStageCreateInfo {
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO, s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: vk::PipelineShaderStageCreateFlags::empty(), flags: vk::PipelineShaderStageCreateFlags::empty(),
@ -371,9 +370,7 @@ impl VulkanApp {
p_name: main_function.as_ptr(), p_name: main_function.as_ptr(),
stage: stage_i, stage: stage_i,
p_specialization_info: ptr::null(), p_specialization_info: ptr::null(),
})
}
)
} }
let binding_description = Vertex::get_binding_description(); let binding_description = Vertex::get_binding_description();
@ -674,11 +671,8 @@ impl VulkanApp {
self.swapchain_format = swapchain_stuff.swapchain_format; self.swapchain_format = swapchain_stuff.swapchain_format;
self.swapchain_extent = swapchain_stuff.swapchain_extent; self.swapchain_extent = swapchain_stuff.swapchain_extent;
self.swapchain_imageviews = share::create_image_views( self.swapchain_imageviews =
&self.device, share::create_image_views(&self.device, self.swapchain_format, &self.swapchain_images);
self.swapchain_format,
&self.swapchain_images,
);
self.render_pass = share::create_render_pass(&self.device, self.swapchain_format); self.render_pass = share::create_render_pass(&self.device, self.swapchain_format);
let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline( let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline(
&self.device, &self.device,
@ -798,4 +792,3 @@ impl VulkanApp {
}) })
} }
} }

@ -1,6 +1,5 @@
use ash::vk; use ash::vk;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::c_void; use std::os::raw::c_void;
use std::ptr; use std::ptr;

@ -2,16 +2,14 @@ use ash::vk;
use image; use image;
use image::GenericImageView; use image::GenericImageView;
use crate::utility::constants::*;
use crate::utility::structures::*;
use crate::utility::{debug, platforms};
use std::cmp::max; use std::cmp::max;
use std::ffi::CString; use std::ffi::CString;
use std::path::Path;
use std::ptr;
use std::os::raw::{c_char, c_void}; use std::os::raw::{c_char, c_void};
use crate::utility::constants::*; use std::path::Path;
use crate::utility::{debug, platforms}; use std::{ptr, mem::size_of};
use crate::utility::structures::*;
pub fn create_render_pass(device: &ash::Device, surface_format: vk::Format) -> vk::RenderPass { pub fn create_render_pass(device: &ash::Device, surface_format: vk::Format) -> vk::RenderPass {
let color_attachment = vk::AttachmentDescription { let color_attachment = vk::AttachmentDescription {
@ -337,7 +335,8 @@ pub fn create_descriptor_sets(
device: &ash::Device, device: &ash::Device,
descriptor_pool: vk::DescriptorPool, descriptor_pool: vk::DescriptorPool,
descriptor_set_layout: vk::DescriptorSetLayout, descriptor_set_layout: vk::DescriptorSetLayout,
uniforms_buffers: &Vec<vk::Buffer>, uniform_buffers: Option<&Vec<vk::Buffer>>,
compute_buffers: Option<&Vec<vk::Buffer>>,
swapchain_images_size: usize, swapchain_images_size: usize,
) -> Vec<vk::DescriptorSet> { ) -> Vec<vk::DescriptorSet> {
let mut layouts: Vec<vk::DescriptorSetLayout> = vec![]; let mut layouts: Vec<vk::DescriptorSetLayout> = vec![];
@ -360,24 +359,68 @@ pub fn create_descriptor_sets(
}; };
for (i, &descritptor_set) in descriptor_sets.iter().enumerate() { for (i, &descritptor_set) in descriptor_sets.iter().enumerate() {
let descriptor_buffer_info = [vk::DescriptorBufferInfo { let uniform_descriptor_info = vec![];
buffer: uniforms_buffers[i], let compute_descriptor_info = vec![];
offset: 0,
range: ::std::mem::size_of::<UniformBufferObject>() as u64, let uniform_buffers_inner = uniform_buffers.unwrap();
}]; let compute_buffers_inner = compute_buffers.unwrap();
let descriptor_write_sets = [vk::WriteDescriptorSet { for (i, buffer) in uniform_buffers_inner.iter().enumerate() {
s_type: vk::StructureType::WRITE_DESCRIPTOR_SET, uniform_descriptor_info.push(
p_next: ptr::null(), vk::DescriptorBufferInfo {
dst_set: descritptor_set, buffer: uniform_buffers.unwrap()[i as usize],
dst_binding: 0, offset: i as u64,
dst_array_element: 0, range: size_of::<UniformBufferObject> as u64,
descriptor_count: 1, }
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, );
p_image_info: ptr::null(), }
p_buffer_info: descriptor_buffer_info.as_ptr(), for (i, buffer) in compute_buffers_inner.iter().enumerate() {
p_texel_buffer_view: ptr::null(), compute_descriptor_info.push(
}]; vk::DescriptorBufferInfo {
buffer: compute_buffers.unwrap()[i as usize],
offset: i as u64,
range: size_of::<UniformBufferObject> as u64,
}
);
}
let mut descriptor_write_sets = vec![];
let mut descriptor_count = 0;
for info in &uniform_descriptor_info {
descriptor_write_sets.push(
vk::WriteDescriptorSet {
s_type: vk::StructureType::WRITE_DESCRIPTOR_SET,
p_next: ptr::null(),
dst_set: descritptor_set,
dst_binding: descriptor_count,
dst_array_element: 0,
descriptor_count: uniform_descriptor_info.len() as u32,
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
p_image_info: ptr::null(),
p_buffer_info: uniform_descriptor_info.as_ptr(),
p_texel_buffer_view: ptr::null(),
}
);
descriptor_count += 1;
}
for info in &compute_descriptor_info {
descriptor_write_sets.push(
vk::WriteDescriptorSet {
s_type: vk::StructureType::WRITE_DESCRIPTOR_SET,
p_next: ptr::null(),
dst_set: descritptor_set,
dst_binding: descriptor_count,
dst_array_element: 0,
descriptor_count: compute_descriptor_info.len() as u32,
descriptor_type: vk::DescriptorType::STORAGE_BUFFER,
p_image_info: ptr::null(),
p_buffer_info: compute_descriptor_info.as_ptr(),
p_texel_buffer_view: ptr::null(),
}
);
descriptor_count += 1;
}
unsafe { unsafe {
device.update_descriptor_sets(&descriptor_write_sets, &[]); device.update_descriptor_sets(&descriptor_write_sets, &[]);
@ -388,13 +431,29 @@ pub fn create_descriptor_sets(
} }
pub fn create_descriptor_set_layout(device: &ash::Device) -> vk::DescriptorSetLayout { pub fn create_descriptor_set_layout(device: &ash::Device) -> vk::DescriptorSetLayout {
let ubo_layout_bindings = [vk::DescriptorSetLayoutBinding { let ubo_layout_bindings = [
binding: 0, vk::DescriptorSetLayoutBinding {
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, binding: 0,
descriptor_count: 1, descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
stage_flags: vk::ShaderStageFlags::VERTEX, descriptor_count: 1,
p_immutable_samplers: ptr::null(), stage_flags: vk::ShaderStageFlags::VERTEX,
}]; p_immutable_samplers: ptr::null(),
},
vk::DescriptorSetLayoutBinding {
binding: 1,
descriptor_type: vk::DescriptorType::STORAGE_BUFFER,
descriptor_count: 1,
stage_flags: vk::ShaderStageFlags::COMPUTE,
p_immutable_samplers: ptr::null(),
},
vk::DescriptorSetLayoutBinding {
binding: 2,
descriptor_type: vk::DescriptorType::STORAGE_BUFFER,
descriptor_count: 1,
stage_flags: vk::ShaderStageFlags::COMPUTE,
p_immutable_samplers: ptr::null(),
},
];
let ubo_layout_create_info = vk::DescriptorSetLayoutCreateInfo { let ubo_layout_create_info = vk::DescriptorSetLayoutCreateInfo {
s_type: vk::StructureType::DESCRIPTOR_SET_LAYOUT_CREATE_INFO, s_type: vk::StructureType::DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
@ -476,8 +535,7 @@ pub fn create_image(
.expect("Failed to create Texture Image!") .expect("Failed to create Texture Image!")
}; };
let image_memory_requirement = let image_memory_requirement = unsafe { device.get_image_memory_requirements(texture_image) };
unsafe { device.get_image_memory_requirements(texture_image) };
let memory_allocate_info = vk::MemoryAllocateInfo { let memory_allocate_info = vk::MemoryAllocateInfo {
s_type: vk::StructureType::MEMORY_ALLOCATE_INFO, s_type: vk::StructureType::MEMORY_ALLOCATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),

Loading…
Cancel
Save