working triangle

This commit is contained in:
maik klein 2016-12-05 19:31:46 +01:00
parent efca2c004f
commit 0a31776136
3 changed files with 134 additions and 23 deletions

View file

@ -249,6 +249,40 @@ impl Device {
.cmd_set_scissor(command_buffer, 0, scissors.len() as u32, scissors.as_ptr()); .cmd_set_scissor(command_buffer, 0, scissors.len() as u32, scissors.as_ptr());
} }
} }
pub fn cmd_bind_vertex_buffers(&self,
command_buffer: vk::CommandBuffer,
buffers: &[vk::Buffer],
offsets: &vk::DeviceSize) {
unsafe {
self.device_fn.cmd_bind_vertex_buffers(command_buffer,
0,
buffers.len() as u32,
buffers.as_ptr(),
offsets);
}
}
pub fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) {
unsafe {
self.device_fn.cmd_end_render_pass(command_buffer);
}
}
pub fn cmd_draw(&self,
command_buffer: vk::CommandBuffer,
vertex_count: u32,
instance_count: u32,
first_vertex: u32,
first_instance: u32) {
unsafe {
self.device_fn.cmd_draw(command_buffer,
vertex_count,
instance_count,
first_vertex,
first_instance);
}
}
pub fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) { pub fn cmd_set_viewport(&self, command_buffer: vk::CommandBuffer, viewports: &[vk::Viewport]) {
unsafe { unsafe {
self.device_fn.cmd_set_viewport(command_buffer, self.device_fn.cmd_set_viewport(command_buffer,
@ -469,14 +503,38 @@ impl Device {
} }
} }
} }
pub fn queue_wait_idle(&self, queue: vk::Queue) -> VkResult<()> {
unsafe {
let err_code = self.device_fn.queue_wait_idle(queue);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
}
pub fn queue_present_khr(&self,
queue: vk::Queue,
create_info: &vk::PresentInfoKHR)
-> VkResult<()> {
unsafe {
let err_code = self.device_fn
.queue_present_khr(queue, create_info);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
}
pub fn queue_submit(&self, pub fn queue_submit(&self,
queue: vk::Queue, queue: vk::Queue,
submit_count: u32, submits: &[vk::SubmitInfo],
p_submits: &vk::SubmitInfo,
fence: vk::Fence) fence: vk::Fence)
-> VkResult<()> { -> VkResult<()> {
unsafe { unsafe {
let err_code = self.device_fn.queue_submit(queue, submit_count, p_submits, fence); let err_code = self.device_fn
.queue_submit(queue, submits.len() as u32, submits.as_ptr(), fence);
match err_code { match err_code {
vk::Result::Success => Ok(()), vk::Result::Success => Ok(()),
_ => Err(err_code), _ => Err(err_code),

View file

@ -362,7 +362,7 @@ fn main() {
p_command_buffers: &setup_command_buffer, p_command_buffers: &setup_command_buffer,
}; };
device.end_command_buffer(setup_command_buffer).unwrap(); device.end_command_buffer(setup_command_buffer).unwrap();
device.queue_submit(present_queue, 1, &submit_info, submit_fence).unwrap(); device.queue_submit(present_queue, &[submit_info], submit_fence).unwrap();
device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap(); device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap();
let depth_image_view_info = vk::ImageViewCreateInfo { let depth_image_view_info = vk::ImageViewCreateInfo {
s_type: vk::StructureType::ImageViewCreateInfo, s_type: vk::StructureType::ImageViewCreateInfo,
@ -740,8 +740,7 @@ fn main() {
present_complete_semaphore, present_complete_semaphore,
vk::Fence::null()) vk::Fence::null())
.unwrap(); .unwrap();
printlndb!(present_index); device.begin_command_buffer(draw_command_buffer, &command_buffer_begin_info).unwrap();
device.begin_command_buffer(draw_command_buffer, &command_buffer_begin_info);
let layout_to_color = vk::ImageMemoryBarrier { let layout_to_color = vk::ImageMemoryBarrier {
s_type: vk::StructureType::ImageMemoryBarrier, s_type: vk::StructureType::ImageMemoryBarrier,
p_next: ptr::null(), p_next: ptr::null(),
@ -787,19 +786,72 @@ fn main() {
clear_value_count: clear_values.len() as u32, clear_value_count: clear_values.len() as u32,
p_clear_values: clear_values.as_ptr(), p_clear_values: clear_values.as_ptr(),
}; };
// vkCmdBeginRenderPass( device.cmd_begin_render_pass(draw_command_buffer,
// vkcontext.drawCmdBuffer, &renderPassBeginInfo, &render_pass_begin_info,
// VK_SUBPASS_CONTENTS_INLINE vk::SubpassContents::Inline);
// ); device.cmd_bind_pipeline(draw_command_buffer,
// vk::PipelineBindPoint::Graphics,
// vkCmdBindPipeline(vkcontext.drawCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vkcontext.pipeline); graphic_pipeline);
// vkCmdSetViewport(vkcontext.drawCmdBuffer, 0, 1, &viewport); device.cmd_set_viewport(draw_command_buffer, &viewports);
// vkCmdSetScissor(vkcontext.drawCmdBuffer, 0 ,1, &scissors); device.cmd_set_scissor(draw_command_buffer, &scissors);
// device.cmd_bind_vertex_buffers(draw_command_buffer, &[vertex_input_buffer], &0);
// VkDeviceSize offsets; device.cmd_draw(draw_command_buffer, 3, 1, 0, 0);
// vkCmdBindVertexBuffers( vkcontext.drawCmdBuffer, 0, 1, &vkcontext.vertexInputBuffer, &offsets ); device.cmd_end_render_pass(draw_command_buffer);
// vkCmdDraw( vkcontext.drawCmdBuffer, 3, 1, 0, 0 ); let pre_present_barrier = vk::ImageMemoryBarrier {
// vkCmdEndRenderPass( vkcontext.drawCmdBuffer ); s_type: vk::StructureType::ImageMemoryBarrier,
p_next: ptr::null(),
src_access_mask: vk::ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
dst_access_mask: vk::ACCESS_COLOR_ATTACHMENT_READ_BIT,
old_layout: vk::ImageLayout::ColorAttachmentOptimal,
new_layout: vk::ImageLayout::PresentSrcKhr,
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_ALL_COMMANDS_BIT,
vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
vk::DependencyFlags::empty(),
&[],
&[],
&[pre_present_barrier]);
device.end_command_buffer(draw_command_buffer);
let wait_render_mask = [vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT];
let submit_info = vk::SubmitInfo {
s_type: vk::StructureType::SubmitInfo,
p_next: ptr::null(),
wait_semaphore_count: 1,
p_wait_semaphores: &present_complete_semaphore,
p_wait_dst_stage_mask: wait_render_mask.as_ptr(),
command_buffer_count: 1,
p_command_buffers: &draw_command_buffer,
signal_semaphore_count: 1,
p_signal_semaphores: &rendering_complete_semaphore,
};
device.queue_submit(present_queue, &[submit_info], vk::Fence::null()).unwrap();
device.queue_wait_idle(present_queue).unwrap();
let mut present_info_err = unsafe { mem::uninitialized() };
let present_info = vk::PresentInfoKHR {
s_type: vk::StructureType::PresentInfoKhr,
p_next: ptr::null(),
wait_semaphore_count: 1,
p_wait_semaphores: &rendering_complete_semaphore,
swapchain_count: 1,
p_swapchains: &swapchain,
p_image_indices: &present_index,
p_results: &mut present_info_err,
};
device.queue_present_khr(present_queue, &present_info).unwrap();
device.queue_wait_idle(present_queue).unwrap();
} }
device.destroy_semaphore(present_complete_semaphore); device.destroy_semaphore(present_complete_semaphore);

View file

@ -3738,10 +3738,6 @@ vk_functions!{
) -> Bool32; ) -> Bool32;
"vkQueuePresentKHR", queue_present_khr(
queue: Queue,
p_present_info: *const PresentInfoKHR,
) -> Result;
"vkCreateSharedSwapchainsKHR", create_shared_swapchains_khr( "vkCreateSharedSwapchainsKHR", create_shared_swapchains_khr(
device: Device, device: Device,
@ -4681,4 +4677,9 @@ vk_functions!{
fence: Fence, fence: Fence,
p_image_index: *mut uint32_t, p_image_index: *mut uint32_t,
) -> Result; ) -> Result;
"vkQueuePresentKHR", queue_present_khr(
queue: Queue,
p_present_info: *const PresentInfoKHR,
) -> Result;
}} }}