more triangle stuff

This commit is contained in:
maik klein 2016-12-05 18:44:01 +01:00
parent bcf36b1e77
commit efca2c004f
2 changed files with 157 additions and 7 deletions

View file

@ -219,6 +219,79 @@ impl Device {
}
}
pub fn destroy_semaphore(&self, semaphore: vk::Semaphore) {
unsafe {
self.device_fn.destroy_semaphore(self.handle, semaphore, ptr::null());
}
}
pub fn cmd_begin_render_pass(&self,
command_buffer: vk::CommandBuffer,
create_info: &vk::RenderPassBeginInfo,
contents: vk::SubpassContents) {
unsafe {
self.device_fn.cmd_begin_render_pass(command_buffer, create_info, contents);
}
}
pub fn cmd_bind_pipeline(&self,
command_buffer: vk::CommandBuffer,
pipeline_bind_point: vk::PipelineBindPoint,
pipeline: vk::Pipeline) {
unsafe {
self.device_fn.cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline);
}
}
pub fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) {
unsafe {
self.device_fn
.cmd_set_scissor(command_buffer, 0, scissors.len() as u32, scissors.as_ptr());
}
}
pub fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) {
unsafe {
self.device_fn.cmd_set_viewport(command_buffer,
0,
viewports.len() as u32,
viewports.as_ptr());
}
}
pub fn acquire_next_image_khr(&self,
swapchain: vk::SwapchainKHR,
timeout: u64,
semaphore: vk::Semaphore,
fence: vk::Fence)
-> VkResult<u32> {
unsafe {
let mut index = mem::uninitialized();
let err_code = self.device_fn
.acquire_next_image_khr(self.handle,
swapchain,
timeout,
semaphore,
fence,
&mut index);
match err_code {
vk::Result::Success => Ok(index),
_ => Err(err_code),
}
}
}
pub fn create_semaphore(&self,
create_info: &vk::SemaphoreCreateInfo)
-> VkResult<vk::Semaphore> {
unsafe {
let mut semaphore = mem::uninitialized();
let err_code = self.device_fn
.create_semaphore(self.handle, create_info, ptr::null(), &mut semaphore);
match err_code {
vk::Result::Success => Ok(semaphore),
_ => Err(err_code),
}
}
}
pub fn create_graphics_pipelines(&self,
pipeline_cache: vk::PipelineCache,
create_infos: &[vk::GraphicsPipelineCreateInfo])

View file

@ -339,7 +339,7 @@ fn main() {
device.cmd_pipeline_barrier(setup_command_buffer,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::DEPENDENCY_BY_REGION_BIT,
vk::DependencyFlags::empty(),
&[],
&[],
&[layout_transition_barrier]);
@ -686,10 +686,6 @@ fn main() {
p_attachments: color_blend_attachment_states.as_ptr(),
blend_constants: [0.0, 0.0, 0.0, 0.0],
};
// VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo;
// dynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
// dynamicStateCreateInfo.dynamicStateCount = 2;
// dynamicStateCreateInfo.pDynamicStates = dynamicState.ptr;
let dynamic_state = [vk::DynamicState::Viewport, vk::DynamicState::Scissor];
let dynamic_state_info = vk::PipelineDynamicStateCreateInfo {
s_type: vk::StructureType::PipelineDynamicStateCreateInfo,
@ -719,14 +715,95 @@ fn main() {
base_pipeline_handle: vk::Pipeline::null(),
base_pipeline_index: 0,
};
let graphics_pipelines =
device.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info])
.unwrap();
let graphic_pipeline = graphics_pipelines[0];
printlndb!(graphic_pipeline);
let semaphore_create_info = vk::SemaphoreCreateInfo {
s_type: vk::StructureType::SemaphoreCreateInfo,
p_next: ptr::null(),
flags: 0,
};
let present_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info).unwrap();
while !window.should_close() {
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events) {
handle_window_event(&mut window, event);
}
let present_index = device.acquire_next_image_khr(swapchain,
std::u64::MAX,
present_complete_semaphore,
vk::Fence::null())
.unwrap();
printlndb!(present_index);
device.begin_command_buffer(draw_command_buffer, &command_buffer_begin_info);
let layout_to_color = vk::ImageMemoryBarrier {
s_type: vk::StructureType::ImageMemoryBarrier,
p_next: ptr::null(),
src_access_mask: vk::AccessFlags::empty(),
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT |
vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
old_layout: vk::ImageLayout::Undefined,
new_layout: vk::ImageLayout::ColorAttachmentOptimal,
src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
image: present_images[present_index as usize],
subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
},
};
device.cmd_pipeline_barrier(draw_command_buffer,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::PIPELINE_STAGE_TOP_OF_PIPE_BIT,
vk::DependencyFlags::empty(),
&[],
&[],
&[layout_to_color]);
let clear_values =
[vk::ClearValue::new_color(vk::ClearColorValue::new_float32([1.0, 1.0, 1.0, 1.0])),
vk::ClearValue::new_depth_stencil(vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
})];
let render_pass_begin_info = vk::RenderPassBeginInfo {
s_type: vk::StructureType::RenderPassBeginInfo,
p_next: ptr::null(),
render_pass: renderpass,
framebuffer: framebuffers[present_index as usize],
render_area: vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: surface_resoultion.clone(),
},
clear_value_count: clear_values.len() as u32,
p_clear_values: clear_values.as_ptr(),
};
// vkCmdBeginRenderPass(
// vkcontext.drawCmdBuffer, &renderPassBeginInfo,
// VK_SUBPASS_CONTENTS_INLINE
// );
//
// vkCmdBindPipeline(vkcontext.drawCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vkcontext.pipeline);
// vkCmdSetViewport(vkcontext.drawCmdBuffer, 0, 1, &viewport);
// vkCmdSetScissor(vkcontext.drawCmdBuffer, 0 ,1, &scissors);
//
// VkDeviceSize offsets;
// vkCmdBindVertexBuffers( vkcontext.drawCmdBuffer, 0, 1, &vkcontext.vertexInputBuffer, &offsets );
// vkCmdDraw( vkcontext.drawCmdBuffer, 3, 1, 0, 0 );
// vkCmdEndRenderPass( vkcontext.drawCmdBuffer );
}
device.destroy_semaphore(present_complete_semaphore);
device.destroy_semaphore(rendering_complete_semaphore);
for pipeline in graphics_pipelines {
device.destroy_pipeline(pipeline);
}