|
|
|
@ -72,216 +72,6 @@ pub mod v1 {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn create_graphics_pipeline(
|
|
|
|
|
device: &ash::Device,
|
|
|
|
|
render_pass: vk::RenderPass,
|
|
|
|
|
swapchain_extent: vk::Extent2D,
|
|
|
|
|
) -> (vk::Pipeline, vk::PipelineLayout) {
|
|
|
|
|
let vert_shader_module = create_shader_module(
|
|
|
|
|
device,
|
|
|
|
|
include_bytes!("../../target/shaders/tri.vert.spv").to_vec(),
|
|
|
|
|
);
|
|
|
|
|
let frag_shader_module = create_shader_module(
|
|
|
|
|
device,
|
|
|
|
|
include_bytes!("../../target/shaders/tri.frag.spv").to_vec(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let main_function_name = CString::new("main").unwrap(); // the beginning function name in shader code.
|
|
|
|
|
|
|
|
|
|
let shader_stages = [
|
|
|
|
|
vk::PipelineShaderStageCreateInfo {
|
|
|
|
|
// Vertex Shader
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineShaderStageCreateFlags::empty(),
|
|
|
|
|
module: vert_shader_module,
|
|
|
|
|
p_name: main_function_name.as_ptr(),
|
|
|
|
|
p_specialization_info: ptr::null(),
|
|
|
|
|
stage: vk::ShaderStageFlags::VERTEX,
|
|
|
|
|
},
|
|
|
|
|
vk::PipelineShaderStageCreateInfo {
|
|
|
|
|
// Fragment Shader
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineShaderStageCreateFlags::empty(),
|
|
|
|
|
module: frag_shader_module,
|
|
|
|
|
p_name: main_function_name.as_ptr(),
|
|
|
|
|
p_specialization_info: ptr::null(),
|
|
|
|
|
stage: vk::ShaderStageFlags::FRAGMENT,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let vertex_input_state_create_info = vk::PipelineVertexInputStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineVertexInputStateCreateFlags::empty(),
|
|
|
|
|
vertex_attribute_description_count: 0,
|
|
|
|
|
p_vertex_attribute_descriptions: ptr::null(),
|
|
|
|
|
vertex_binding_description_count: 0,
|
|
|
|
|
p_vertex_binding_descriptions: ptr::null(),
|
|
|
|
|
};
|
|
|
|
|
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
|
|
|
|
flags: vk::PipelineInputAssemblyStateCreateFlags::empty(),
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
primitive_restart_enable: vk::FALSE,
|
|
|
|
|
topology: vk::PrimitiveTopology::TRIANGLE_LIST,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let viewports = [vk::Viewport {
|
|
|
|
|
x: 0.0,
|
|
|
|
|
y: 0.0,
|
|
|
|
|
width: swapchain_extent.width as f32,
|
|
|
|
|
height: swapchain_extent.height as f32,
|
|
|
|
|
min_depth: 0.0,
|
|
|
|
|
max_depth: 1.0,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
let scissors = [vk::Rect2D {
|
|
|
|
|
offset: vk::Offset2D { x: 0, y: 0 },
|
|
|
|
|
extent: swapchain_extent,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
let viewport_state_create_info = vk::PipelineViewportStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineViewportStateCreateFlags::empty(),
|
|
|
|
|
scissor_count: scissors.len() as u32,
|
|
|
|
|
p_scissors: scissors.as_ptr(),
|
|
|
|
|
viewport_count: viewports.len() as u32,
|
|
|
|
|
p_viewports: viewports.as_ptr(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let rasterization_statue_create_info = vk::PipelineRasterizationStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineRasterizationStateCreateFlags::empty(),
|
|
|
|
|
depth_clamp_enable: vk::FALSE,
|
|
|
|
|
cull_mode: vk::CullModeFlags::BACK,
|
|
|
|
|
front_face: vk::FrontFace::CLOCKWISE,
|
|
|
|
|
line_width: 1.0,
|
|
|
|
|
polygon_mode: vk::PolygonMode::FILL,
|
|
|
|
|
rasterizer_discard_enable: vk::FALSE,
|
|
|
|
|
depth_bias_clamp: 0.0,
|
|
|
|
|
depth_bias_constant_factor: 0.0,
|
|
|
|
|
depth_bias_enable: vk::FALSE,
|
|
|
|
|
depth_bias_slope_factor: 0.0,
|
|
|
|
|
};
|
|
|
|
|
let multisample_state_create_info = vk::PipelineMultisampleStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
|
|
|
|
flags: vk::PipelineMultisampleStateCreateFlags::empty(),
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
rasterization_samples: vk::SampleCountFlags::TYPE_1,
|
|
|
|
|
sample_shading_enable: vk::FALSE,
|
|
|
|
|
min_sample_shading: 0.0,
|
|
|
|
|
p_sample_mask: ptr::null(),
|
|
|
|
|
alpha_to_one_enable: vk::FALSE,
|
|
|
|
|
alpha_to_coverage_enable: vk::FALSE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let stencil_state = vk::StencilOpState {
|
|
|
|
|
fail_op: vk::StencilOp::KEEP,
|
|
|
|
|
pass_op: vk::StencilOp::KEEP,
|
|
|
|
|
depth_fail_op: vk::StencilOp::KEEP,
|
|
|
|
|
compare_op: vk::CompareOp::ALWAYS,
|
|
|
|
|
compare_mask: 0,
|
|
|
|
|
write_mask: 0,
|
|
|
|
|
reference: 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let depth_state_create_info = vk::PipelineDepthStencilStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineDepthStencilStateCreateFlags::empty(),
|
|
|
|
|
depth_test_enable: vk::FALSE,
|
|
|
|
|
depth_write_enable: vk::FALSE,
|
|
|
|
|
depth_compare_op: vk::CompareOp::LESS_OR_EQUAL,
|
|
|
|
|
depth_bounds_test_enable: vk::FALSE,
|
|
|
|
|
stencil_test_enable: vk::FALSE,
|
|
|
|
|
front: stencil_state,
|
|
|
|
|
back: stencil_state,
|
|
|
|
|
max_depth_bounds: 1.0,
|
|
|
|
|
min_depth_bounds: 0.0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
|
|
|
|
|
blend_enable: vk::FALSE,
|
|
|
|
|
color_write_mask: vk::ColorComponentFlags::all(),
|
|
|
|
|
src_color_blend_factor: vk::BlendFactor::ONE,
|
|
|
|
|
dst_color_blend_factor: vk::BlendFactor::ZERO,
|
|
|
|
|
color_blend_op: vk::BlendOp::ADD,
|
|
|
|
|
src_alpha_blend_factor: vk::BlendFactor::ONE,
|
|
|
|
|
dst_alpha_blend_factor: vk::BlendFactor::ZERO,
|
|
|
|
|
alpha_blend_op: vk::BlendOp::ADD,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
let color_blend_state = vk::PipelineColorBlendStateCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineColorBlendStateCreateFlags::empty(),
|
|
|
|
|
logic_op_enable: vk::FALSE,
|
|
|
|
|
logic_op: vk::LogicOp::COPY,
|
|
|
|
|
attachment_count: color_blend_attachment_states.len() as u32,
|
|
|
|
|
p_attachments: color_blend_attachment_states.as_ptr(),
|
|
|
|
|
blend_constants: [0.0, 0.0, 0.0, 0.0],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let pipeline_layout_create_info = vk::PipelineLayoutCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::PIPELINE_LAYOUT_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineLayoutCreateFlags::empty(),
|
|
|
|
|
set_layout_count: 0,
|
|
|
|
|
p_set_layouts: ptr::null(),
|
|
|
|
|
push_constant_range_count: 0,
|
|
|
|
|
p_push_constant_ranges: ptr::null(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let pipeline_layout = unsafe {
|
|
|
|
|
device
|
|
|
|
|
.create_pipeline_layout(&pipeline_layout_create_info, None)
|
|
|
|
|
.expect("Failed to create pipeline layout!")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let graphic_pipeline_create_infos = [vk::GraphicsPipelineCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::GRAPHICS_PIPELINE_CREATE_INFO,
|
|
|
|
|
p_next: ptr::null(),
|
|
|
|
|
flags: vk::PipelineCreateFlags::empty(),
|
|
|
|
|
stage_count: shader_stages.len() as u32,
|
|
|
|
|
p_stages: shader_stages.as_ptr(),
|
|
|
|
|
p_vertex_input_state: &vertex_input_state_create_info,
|
|
|
|
|
p_input_assembly_state: &vertex_input_assembly_state_info,
|
|
|
|
|
p_tessellation_state: ptr::null(),
|
|
|
|
|
p_viewport_state: &viewport_state_create_info,
|
|
|
|
|
p_rasterization_state: &rasterization_statue_create_info,
|
|
|
|
|
p_multisample_state: &multisample_state_create_info,
|
|
|
|
|
p_depth_stencil_state: &depth_state_create_info,
|
|
|
|
|
p_color_blend_state: &color_blend_state,
|
|
|
|
|
p_dynamic_state: ptr::null(),
|
|
|
|
|
layout: pipeline_layout,
|
|
|
|
|
render_pass,
|
|
|
|
|
subpass: 0,
|
|
|
|
|
base_pipeline_handle: vk::Pipeline::null(),
|
|
|
|
|
base_pipeline_index: -1,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
let graphics_pipelines = unsafe {
|
|
|
|
|
device
|
|
|
|
|
.create_graphics_pipelines(
|
|
|
|
|
vk::PipelineCache::null(),
|
|
|
|
|
&graphic_pipeline_create_infos,
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.expect("Failed to create Graphics Pipeline!.")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
device.destroy_shader_module(vert_shader_module, None);
|
|
|
|
|
device.destroy_shader_module(frag_shader_module, None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(graphics_pipelines[0], pipeline_layout)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn create_framebuffers(
|
|
|
|
|
device: &ash::Device,
|
|
|
|
|
render_pass: vk::RenderPass,
|
|
|
|
@ -740,7 +530,8 @@ pub mod v1 {
|
|
|
|
|
.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(),
|
|
|
|
@ -1371,9 +1162,6 @@ pub mod v2 {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use ash::version::DeviceV1_0;
|
|
|
|
|
use ash::version::EntryV1_0;
|
|
|
|
|
use ash::version::InstanceV1_0;
|
|
|
|
|
use ash::vk;
|
|
|
|
|
|
|
|
|
|
use std::ffi::CString;
|
|
|
|
@ -1382,7 +1170,6 @@ use std::os::raw::c_void;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::ptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use crate::utility::constants::*;
|
|
|
|
|
use crate::utility::debug;
|
|
|
|
|
use crate::utility::platforms;
|
|
|
|
@ -1430,8 +1217,7 @@ pub fn create_instance(
|
|
|
|
|
let create_info = vk::InstanceCreateInfo {
|
|
|
|
|
s_type: vk::StructureType::INSTANCE_CREATE_INFO,
|
|
|
|
|
p_next: if VALIDATION.is_enable {
|
|
|
|
|
&debug_utils_create_info as *const vk::DebugUtilsMessengerCreateInfoEXT
|
|
|
|
|
as *const c_void
|
|
|
|
|
&debug_utils_create_info as *const vk::DebugUtilsMessengerCreateInfoEXT as *const c_void
|
|
|
|
|
} else {
|
|
|
|
|
ptr::null()
|
|
|
|
|
},
|
|
|
|
@ -1642,6 +1428,7 @@ pub fn find_queue_family(
|
|
|
|
|
index as u32,
|
|
|
|
|
surface_stuff.surface,
|
|
|
|
|
)
|
|
|
|
|
.unwrap()
|
|
|
|
|
};
|
|
|
|
|
if queue_family.queue_count > 0 && is_present_support {
|
|
|
|
|
queue_family_indices.present_family = Some(index);
|
|
|
|
@ -1796,7 +1583,6 @@ pub fn create_swapchain(
|
|
|
|
|
pub fn choose_swapchain_format(
|
|
|
|
|
available_formats: &Vec<vk::SurfaceFormatKHR>,
|
|
|
|
|
) -> vk::SurfaceFormatKHR {
|
|
|
|
|
|
|
|
|
|
for available_format in available_formats {
|
|
|
|
|
if available_format.format == vk::Format::B8G8R8A8_SRGB
|
|
|
|
|
&& available_format.color_space == vk::ColorSpaceKHR::SRGB_NONLINEAR
|
|
|
|
@ -1829,8 +1615,7 @@ pub fn choose_swapchain_extent(
|
|
|
|
|
} else {
|
|
|
|
|
use num::clamp;
|
|
|
|
|
|
|
|
|
|
let window_size = window
|
|
|
|
|
.inner_size();
|
|
|
|
|
let window_size = window.inner_size();
|
|
|
|
|
println!(
|
|
|
|
|
"\t\tInner Window Size: ({}, {})",
|
|
|
|
|
window_size.width, window_size.height
|
|
|
|
|