Continue vulkan c++ tutorial
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
This commit is contained in:
parent
81e4212d8e
commit
b2d28ef408
9 changed files with 156 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
use crate::vulkan::vk_shader_module::VkShaderModule;
|
||||
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain};
|
||||
use ash::vk;
|
||||
use ash::vk::PrimitiveTopology;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct VkRenderContext {
|
||||
|
@ -57,6 +60,69 @@ impl VkRenderContext {
|
|||
&physical_device,
|
||||
)?);
|
||||
|
||||
let shader_entry_name = CStr::from_bytes_with_nul(b"main\0")?;
|
||||
|
||||
let vert_shader_module =
|
||||
VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.vert.spv")?;
|
||||
|
||||
let vert_shader_info = vk::PipelineShaderStageCreateInfo::default()
|
||||
.module(vert_shader_module.handle)
|
||||
.name(shader_entry_name)
|
||||
.stage(vk::ShaderStageFlags::VERTEX);
|
||||
|
||||
let frag_shader_module =
|
||||
VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.frag.spv")?;
|
||||
|
||||
let frag_shader_info = vk::PipelineShaderStageCreateInfo::default()
|
||||
.module(frag_shader_module.handle)
|
||||
.name(shader_entry_name)
|
||||
.stage(vk::ShaderStageFlags::FRAGMENT);
|
||||
|
||||
let shader_stage_create_infos = [vert_shader_info, frag_shader_info];
|
||||
|
||||
let vertex_input_info = vk::PipelineVertexInputStateCreateInfo::default();
|
||||
|
||||
let input_assembly = vk::PipelineInputAssemblyStateCreateInfo::default()
|
||||
.topology(PrimitiveTopology::TRIANGLE_LIST);
|
||||
|
||||
let viewport = vk::Viewport::default()
|
||||
.width(swapchain.surface_resolution.width as f32)
|
||||
.height(swapchain.surface_resolution.height as f32)
|
||||
.max_depth(1.0);
|
||||
|
||||
let scissor = vk::Rect2D::default().extent(swapchain.surface_resolution);
|
||||
|
||||
let viewport_state = vk::PipelineViewportStateCreateInfo::default()
|
||||
.viewports(&[viewport])
|
||||
.scissors(&[scissor]);
|
||||
|
||||
let rasterizer = vk::PipelineRasterizationStateCreateInfo::default()
|
||||
.polygon_mode(vk::PolygonMode::FILL)
|
||||
.cull_mode(vk::CullModeFlags::BACK)
|
||||
.front_face(vk::FrontFace::CLOCKWISE);
|
||||
|
||||
let multisampling = vk::PipelineMultisampleStateCreateInfo::default()
|
||||
.rasterization_samples(vk::SampleCountFlags::TYPE_1)
|
||||
.min_sample_shading(1.0);
|
||||
|
||||
let color_blend_attachment = vk::PipelineColorBlendAttachmentState::default()
|
||||
.color_write_mask(vk::ColorComponentFlags::RGBA);
|
||||
|
||||
let color_blending =
|
||||
vk::PipelineColorBlendStateCreateInfo::default().attachments(&[color_blend_attachment]);
|
||||
|
||||
let dynamic_state = vk::PipelineDynamicStateCreateInfo::default()
|
||||
.dynamic_states(&[vk::DynamicState::VIEWPORT, vk::DynamicState::LINE_WIDTH]);
|
||||
|
||||
let pipeline_layout_info = vk::PipelineLayoutCreateInfo::default();
|
||||
let pipeline_layout = unsafe {
|
||||
device
|
||||
.handle
|
||||
.create_pipeline_layout(&pipeline_layout_info, None)?
|
||||
};
|
||||
|
||||
unsafe { device.handle.destroy_pipeline_layout(pipeline_layout, None) };
|
||||
|
||||
// let present_queue = device.get_device_queue(0);
|
||||
//
|
||||
// let pool_create_info = vk::CommandPoolCreateInfo::default()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue