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()
+ shader_path.file_name().unwrap().to_str().unwrap()
+ ".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());
Command::new("glslc")
.arg("-c")
@ -41,17 +44,16 @@ fn main() -> std::io::Result<()> {
let bin_path = entry.path();
let bin_path_string = bin_path.file_name().unwrap().to_str().unwrap().to_string();
let shader_type = (
match bin_path_string.split(".").nth(1).unwrap() {
"vert" => "VERTEX",
"frag" => "FRAGMENT",
"comp" => "COMPUTE",
"tesc" => "TESSELLATION_CONTROL",
"tese" => "TESSELLATION_EVALUATION",
"geom" => "GEOMETRY",
_ => panic!("unknown shader type"),
}
).to_string();
let shader_type = (match bin_path_string.split(".").nth(1).unwrap() {
"vert" => "VERTEX",
"frag" => "FRAGMENT",
"comp" => "COMPUTE",
"tesc" => "TESSELLATION_CONTROL",
"tese" => "TESSELLATION_EVALUATION",
"geom" => "GEOMETRY",
_ => panic!("unknown shader type"),
})
.to_string();
txt += &("(include_bytes!(\"../target/shaders/".to_owned()
+ &bin_path_string
+ "\").to_vec(), ShaderStageFlags::"

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

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

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

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

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

Loading…
Cancel
Save