|
|
|
@ -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 uniform_descriptor_info = vec![];
|
|
|
|
|
let compute_descriptor_info = vec![];
|
|
|
|
|
|
|
|
|
|
let descriptor_write_sets = [vk::WriteDescriptorSet {
|
|
|
|
|
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: 0,
|
|
|
|
|
dst_binding: descriptor_count,
|
|
|
|
|
dst_array_element: 0,
|
|
|
|
|
descriptor_count: 1,
|
|
|
|
|
descriptor_count: uniform_descriptor_info.len() as u32,
|
|
|
|
|
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
|
|
|
|
|
p_image_info: ptr::null(),
|
|
|
|
|
p_buffer_info: descriptor_buffer_info.as_ptr(),
|
|
|
|
|
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 {
|
|
|
|
|
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(),
|
|
|
|
|