mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-10-29 21:42:26 +00:00
Minimise unsafe
block size, in examples (#2591)
This commit is contained in:
parent
54dafb73bf
commit
6da1f96c73
@ -217,11 +217,9 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// The command buffer only does one thing: execute the compute pipeline. This is called a
|
||||||
// The command buffer only does one thing: execute the compute pipeline. This is called a
|
// *dispatch* operation.
|
||||||
// *dispatch* operation.
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finish building the command buffer by calling `build`.
|
// Finish building the command buffer by calling `build`.
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
@ -445,9 +445,7 @@ impl ApplicationHandler for App {
|
|||||||
.bind_vertex_buffers(0, buffer)
|
.bind_vertex_buffers(0, buffer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe { builder.draw(num_vertices, 1, 0, 0) }.unwrap();
|
||||||
builder.draw(num_vertices, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ fn main() {
|
|||||||
))
|
))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.ok()
|
}
|
||||||
};
|
.ok();
|
||||||
|
|
||||||
// Create Vulkan objects in the same way as the other examples.
|
// Create Vulkan objects in the same way as the other examples.
|
||||||
let device_extensions = DeviceExtensions {
|
let device_extensions = DeviceExtensions {
|
||||||
|
@ -204,12 +204,7 @@ impl AmbientLightingSystem {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -218,12 +218,7 @@ impl DirectionalLightingSystem {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -231,12 +231,7 @@ impl PointLightingSystem {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -153,12 +153,7 @@ impl TriangleDrawSystem {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -255,10 +255,7 @@ fn main() {
|
|||||||
set.clone().offsets([index * align as u32]),
|
set.clone().offsets([index * align as u32]),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([12, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([12, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
@ -267,12 +267,8 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// Note that dispatch dimensions must be proportional to the local size.
|
||||||
// Note that dispatch dimensions must be proportional to the local size.
|
unsafe { builder.dispatch([1024 / local_size_x, 1024 / local_size_y, 1]) }.unwrap();
|
||||||
builder
|
|
||||||
.dispatch([1024 / local_size_x, 1024 / local_size_y, 1])
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.copy_image_to_buffer(CopyImageToBufferInfo::image_buffer(image, buf.clone()))
|
.copy_image_to_buffer(CopyImageToBufferInfo::image_buffer(image, buf.clone()))
|
||||||
|
@ -178,8 +178,8 @@ mod linux {
|
|||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
|
|
||||||
let device_extensions = DeviceExtensions {
|
let device_extensions = DeviceExtensions {
|
||||||
khr_external_semaphore: true,
|
khr_external_semaphore: true,
|
||||||
@ -326,12 +326,11 @@ mod linux {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// SAFETY: we just created this raw image and hasn't bound any memory to it.
|
// SAFETY: we just created this raw image and hasn't bound any memory to it.
|
||||||
let image = Arc::new(unsafe {
|
let image = Arc::new(
|
||||||
raw_image
|
unsafe { raw_image.bind_memory([ResourceMemory::new_dedicated(image_memory)]) }
|
||||||
.bind_memory([ResourceMemory::new_dedicated(image_memory)])
|
|
||||||
.map_err(|(err, _, _)| err)
|
.map_err(|(err, _, _)| err)
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
});
|
);
|
||||||
|
|
||||||
let image_view = ImageView::new_default(image).unwrap();
|
let image_view = ImageView::new_default(image).unwrap();
|
||||||
|
|
||||||
@ -370,16 +369,10 @@ mod linux {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let acquire_fd = unsafe {
|
let acquire_fd =
|
||||||
acquire_sem
|
unsafe { acquire_sem.export_fd(ExternalSemaphoreHandleType::OpaqueFd) }.unwrap();
|
||||||
.export_fd(ExternalSemaphoreHandleType::OpaqueFd)
|
let release_fd =
|
||||||
.unwrap()
|
unsafe { release_sem.export_fd(ExternalSemaphoreHandleType::OpaqueFd) }.unwrap();
|
||||||
};
|
|
||||||
let release_fd = unsafe {
|
|
||||||
release_sem
|
|
||||||
.export_fd(ExternalSemaphoreHandleType::OpaqueFd)
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
let barrier_clone = barrier.clone();
|
let barrier_clone = barrier.clone();
|
||||||
let barrier_2_clone = barrier_2.clone();
|
let barrier_2_clone = barrier_2.clone();
|
||||||
@ -407,13 +400,12 @@ mod linux {
|
|||||||
|
|
||||||
let gl_acquire_sem = unsafe {
|
let gl_acquire_sem = unsafe {
|
||||||
glium::semaphore::Semaphore::new_from_fd(gl_display.as_ref(), acquire_fd)
|
glium::semaphore::Semaphore::new_from_fd(gl_display.as_ref(), acquire_fd)
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
|
|
||||||
let gl_release_sem = unsafe {
|
let gl_release_sem = unsafe {
|
||||||
glium::semaphore::Semaphore::new_from_fd(gl_display.as_ref(), release_fd)
|
glium::semaphore::Semaphore::new_from_fd(gl_display.as_ref(), release_fd)
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
|
|
||||||
let rotation_start = Instant::now();
|
let rotation_start = Instant::now();
|
||||||
|
|
||||||
@ -733,12 +725,7 @@ mod linux {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -554,12 +554,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -498,12 +498,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -517,12 +517,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -541,10 +541,7 @@ impl ApplicationHandler for App {
|
|||||||
cs_descriptor_set,
|
cs_descriptor_set,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.begin_render_pass(
|
.begin_render_pass(
|
||||||
@ -564,11 +561,9 @@ impl ApplicationHandler for App {
|
|||||||
.bind_vertex_buffers(0, vertices)
|
.bind_vertex_buffers(0, vertices)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// The indirect draw call is placed in the command buffer with a reference to
|
||||||
// The indirect draw call is placed in the command buffer with a reference to
|
// the buffer that will contain the arguments for the draw.
|
||||||
// the buffer that will contain the arguments for the draw.
|
unsafe { builder.draw_indirect(indirect_buffer) }.unwrap();
|
||||||
builder.draw_indirect(indirect_buffer).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -470,17 +470,15 @@ impl ApplicationHandler for App {
|
|||||||
(self.vertex_buffer.clone(), self.instance_buffer.clone()),
|
(self.vertex_buffer.clone(), self.instance_buffer.clone()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
builder
|
builder.draw(
|
||||||
.draw(
|
self.vertex_buffer.len() as u32,
|
||||||
self.vertex_buffer.len() as u32,
|
self.instance_buffer.len() as u32,
|
||||||
self.instance_buffer.len() as u32,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
)
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -175,12 +175,7 @@ impl FractalComputePipeline {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.push_constants(self.pipeline.layout().clone(), 0, push_constants)
|
.push_constants(self.pipeline.layout().clone(), 0, push_constants)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([image_extent[0] / 8, image_extent[1] / 8, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.dispatch([image_extent[0] / 8, image_extent[1] / 8, 1])
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
let finished = command_buffer.execute(self.queue.clone()).unwrap();
|
let finished = command_buffer.execute(self.queue.clone()).unwrap();
|
||||||
|
@ -162,10 +162,7 @@ impl PixelsDrawPipeline {
|
|||||||
self.create_descriptor_set(image),
|
self.create_descriptor_set(image),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(6, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw(6, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -476,10 +476,7 @@ impl ApplicationHandler for App {
|
|||||||
rcx.descriptor_set.clone(),
|
rcx.descriptor_set.clone(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw_mesh_tasks([self.cols, self.rows, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw_mesh_tasks([self.cols, self.rows, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -401,10 +401,7 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, vertex_buffer.clone())
|
.bind_vertex_buffers(0, vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw(vertex_buffer.len() as u32, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.end_render_pass(Default::default())
|
.end_render_pass(Default::default())
|
||||||
|
@ -205,12 +205,7 @@ impl GameOfLifeComputePipeline {
|
|||||||
push_constants,
|
push_constants,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([image_extent[0] / 8, image_extent[1] / 8, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.dispatch([image_extent[0] / 8, image_extent[1] / 8, 1])
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,10 +158,7 @@ impl PixelsDrawPipeline {
|
|||||||
self.create_image_sampler_nearest(image),
|
self.create_image_sampler_nearest(image),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(6, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw(6, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -450,12 +450,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -349,12 +349,10 @@ fn main() {
|
|||||||
.bind_vertex_buffers(0, vertex_buffer.clone())
|
.bind_vertex_buffers(0, vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// Drawing commands are broadcast to each view in the view mask of the active renderpass
|
||||||
// Drawing commands are broadcast to each view in the view mask of the active renderpass
|
// which means only a single draw call is needed to draw to multiple layers of the
|
||||||
// which means only a single draw call is needed to draw to multiple layers of the
|
// framebuffer.
|
||||||
// framebuffer.
|
unsafe { builder.draw(vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
builder.draw(vertex_buffer.len() as u32, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -485,68 +485,72 @@ impl ApplicationHandler for App {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// A query must be reset before each use, including the first use. This
|
||||||
|
// must be done outside a render pass.
|
||||||
// Beginning or resetting a query is unsafe for now.
|
// Beginning or resetting a query is unsafe for now.
|
||||||
|
unsafe { builder.reset_query_pool(self.query_pool.clone(), 0..3) }.unwrap();
|
||||||
|
|
||||||
|
builder
|
||||||
|
.set_viewport(0, [rcx.viewport.clone()].into_iter().collect())
|
||||||
|
.unwrap()
|
||||||
|
.bind_pipeline_graphics(rcx.pipeline.clone())
|
||||||
|
.unwrap()
|
||||||
|
.begin_render_pass(
|
||||||
|
RenderPassBeginInfo {
|
||||||
|
clear_values: vec![Some([0.0, 0.0, 1.0, 1.0].into()), Some(1.0.into())],
|
||||||
|
..RenderPassBeginInfo::framebuffer(
|
||||||
|
rcx.framebuffers[image_index as usize].clone(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
Default::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Begin query 0, then draw the red triangle. Enabling the
|
||||||
|
// `QueryControlFlags::PRECISE` flag would give exact numeric results. This
|
||||||
|
// needs the `occlusion_query_precise` feature to be enabled on the device.
|
||||||
unsafe {
|
unsafe {
|
||||||
builder
|
builder.begin_query(
|
||||||
// A query must be reset before each use, including the first use. This
|
self.query_pool.clone(),
|
||||||
// must be done outside a render pass.
|
0,
|
||||||
.reset_query_pool(self.query_pool.clone(), 0..3)
|
QueryControlFlags::empty(),
|
||||||
.unwrap()
|
// QueryControlFlags::PRECISE,
|
||||||
.set_viewport(0, [rcx.viewport.clone()].into_iter().collect())
|
)
|
||||||
.unwrap()
|
|
||||||
.bind_pipeline_graphics(rcx.pipeline.clone())
|
|
||||||
.unwrap()
|
|
||||||
.begin_render_pass(
|
|
||||||
RenderPassBeginInfo {
|
|
||||||
clear_values: vec![
|
|
||||||
Some([0.0, 0.0, 1.0, 1.0].into()),
|
|
||||||
Some(1.0.into()),
|
|
||||||
],
|
|
||||||
..RenderPassBeginInfo::framebuffer(
|
|
||||||
rcx.framebuffers[image_index as usize].clone(),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
Default::default(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
// Begin query 0, then draw the red triangle. Enabling the
|
|
||||||
// `QueryControlFlags::PRECISE` flag would give exact numeric results. This
|
|
||||||
// needs the `occlusion_query_precise` feature to be enabled on the device.
|
|
||||||
.begin_query(
|
|
||||||
self.query_pool.clone(),
|
|
||||||
0,
|
|
||||||
QueryControlFlags::empty(),
|
|
||||||
// QueryControlFlags::PRECISE,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.bind_vertex_buffers(0, self.triangle1.clone())
|
|
||||||
.unwrap()
|
|
||||||
.draw(self.triangle1.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap()
|
|
||||||
// End query 0.
|
|
||||||
.end_query(self.query_pool.clone(), 0)
|
|
||||||
.unwrap()
|
|
||||||
// Begin query 1 for the cyan triangle.
|
|
||||||
.begin_query(self.query_pool.clone(), 1, QueryControlFlags::empty())
|
|
||||||
.unwrap()
|
|
||||||
.bind_vertex_buffers(0, self.triangle2.clone())
|
|
||||||
.unwrap()
|
|
||||||
.draw(self.triangle2.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap()
|
|
||||||
.end_query(self.query_pool.clone(), 1)
|
|
||||||
.unwrap()
|
|
||||||
// Finally, query 2 for the green triangle.
|
|
||||||
.begin_query(self.query_pool.clone(), 2, QueryControlFlags::empty())
|
|
||||||
.unwrap()
|
|
||||||
.bind_vertex_buffers(0, self.triangle3.clone())
|
|
||||||
.unwrap()
|
|
||||||
.draw(self.triangle3.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap()
|
|
||||||
.end_query(self.query_pool.clone(), 2)
|
|
||||||
.unwrap()
|
|
||||||
.end_render_pass(Default::default())
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
.unwrap();
|
||||||
|
builder
|
||||||
|
.bind_vertex_buffers(0, self.triangle1.clone())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
unsafe { builder.draw(self.triangle1.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
|
// End query 0.
|
||||||
|
builder.end_query(self.query_pool.clone(), 0).unwrap();
|
||||||
|
|
||||||
|
// Begin query 1 for the cyan triangle.
|
||||||
|
unsafe {
|
||||||
|
builder.begin_query(self.query_pool.clone(), 1, QueryControlFlags::empty())
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
builder
|
||||||
|
.bind_vertex_buffers(0, self.triangle2.clone())
|
||||||
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.triangle2.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
|
builder.end_query(self.query_pool.clone(), 1).unwrap();
|
||||||
|
|
||||||
|
// Finally, query 2 for the green triangle.
|
||||||
|
unsafe {
|
||||||
|
builder.begin_query(self.query_pool.clone(), 2, QueryControlFlags::empty())
|
||||||
|
}
|
||||||
|
.unwrap();
|
||||||
|
builder
|
||||||
|
.bind_vertex_buffers(0, self.triangle3.clone())
|
||||||
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.triangle3.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
|
builder
|
||||||
|
.end_query(self.query_pool.clone(), 2)
|
||||||
|
.unwrap()
|
||||||
|
.end_render_pass(Default::default())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
|
||||||
|
@ -297,10 +297,7 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, vertex_buffer.clone())
|
.bind_vertex_buffers(0, vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw(vertex_buffer.len() as u32, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// We are creating an empty PipelineCache to start somewhere.
|
// We are creating an empty PipelineCache to start somewhere.
|
||||||
let pipeline_cache = unsafe { PipelineCache::new(device.clone(), Default::default()).unwrap() };
|
let pipeline_cache = unsafe { PipelineCache::new(device.clone(), Default::default()) }.unwrap();
|
||||||
|
|
||||||
// We need to create the compute pipeline that describes our operation. We are using the shader
|
// We need to create the compute pipeline that describes our operation. We are using the shader
|
||||||
// from the basic-compute-shader example.
|
// from the basic-compute-shader example.
|
||||||
@ -192,8 +192,8 @@ fn main() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
|
|
||||||
// As the `PipelineCache` of the Vulkan implementation saves an opaque blob of data, there is
|
// As the `PipelineCache` of the Vulkan implementation saves an opaque blob of data, there is
|
||||||
// no real way to know if the data is correct. There might be differences in the byte blob
|
// no real way to know if the data is correct. There might be differences in the byte blob
|
||||||
|
@ -199,10 +199,7 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.push_constants(pipeline.layout().clone(), 0, push_constants)
|
.push_constants(pipeline.layout().clone(), 0, push_constants)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
|
||||||
|
@ -490,12 +490,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -625,12 +625,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -258,8 +258,8 @@ impl ApplicationHandler for App {
|
|||||||
// NOTE: You will have to verify correctness of the data by yourself!
|
// NOTE: You will have to verify correctness of the data by yourself!
|
||||||
let module = unsafe {
|
let module = unsafe {
|
||||||
ShaderModule::new(self.device.clone(), ShaderModuleCreateInfo::new(&code))
|
ShaderModule::new(self.device.clone(), ShaderModuleCreateInfo::new(&code))
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
module.entry_point("main").unwrap()
|
module.entry_point("main").unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -268,8 +268,8 @@ impl ApplicationHandler for App {
|
|||||||
|
|
||||||
let module = unsafe {
|
let module = unsafe {
|
||||||
ShaderModule::new(self.device.clone(), ShaderModuleCreateInfo::new(&code))
|
ShaderModule::new(self.device.clone(), ShaderModuleCreateInfo::new(&code))
|
||||||
.unwrap()
|
}
|
||||||
};
|
.unwrap();
|
||||||
module.entry_point("main").unwrap()
|
module.entry_point("main").unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -414,12 +414,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -192,10 +192,7 @@ fn main() {
|
|||||||
set,
|
set,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
|
||||||
|
@ -183,10 +183,7 @@ fn main() {
|
|||||||
set,
|
set,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
let future = sync::now(device)
|
let future = sync::now(device)
|
||||||
|
@ -211,10 +211,7 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.push_constants(pipeline.layout().clone(), 0, parameters)
|
.push_constants(pipeline.layout().clone(), 0, parameters)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
let future = sync::now(queue.device().clone())
|
let future = sync::now(queue.device().clone())
|
||||||
|
@ -559,12 +559,7 @@ impl ApplicationHandler for App {
|
|||||||
self.descriptor_set.clone(),
|
self.descriptor_set.clone(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([PARTICLE_COUNT as u32 / 128, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.dispatch([PARTICLE_COUNT as u32 / 128, 1, 1])
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use render-pass to draw particles to swapchain.
|
// Use render-pass to draw particles to swapchain.
|
||||||
builder
|
builder
|
||||||
@ -582,10 +577,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(PARTICLE_COUNT as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.draw(PARTICLE_COUNT as u32, 1, 0, 0).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -186,10 +186,7 @@ fn main() {
|
|||||||
descriptor_set,
|
descriptor_set,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.dispatch([1024, 1, 1]) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder.dispatch([1024, 1, 1]).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let command_buffer = builder.build().unwrap();
|
let command_buffer = builder.build().unwrap();
|
||||||
|
|
||||||
|
@ -481,12 +481,8 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_index_buffer(self.index_buffer.clone())
|
.bind_index_buffer(self.index_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw_indexed(self.index_buffer.len() as u32, 1, 0, 0, 0) }
|
||||||
unsafe {
|
.unwrap();
|
||||||
builder
|
|
||||||
.draw_indexed(self.index_buffer.len() as u32, 1, 0, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -441,12 +441,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -511,12 +511,7 @@ impl ApplicationHandler for App {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 3, 0, 0) }.unwrap();
|
||||||
unsafe {
|
|
||||||
builder
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 3, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.end_render_pass(Default::default()).unwrap();
|
builder.end_render_pass(Default::default()).unwrap();
|
||||||
|
|
||||||
|
@ -424,12 +424,8 @@ impl ApplicationHandler for App {
|
|||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// We add a draw command.
|
||||||
builder
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
// We add a draw command.
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
// We leave the render pass. Note that if we had multiple subpasses we could
|
// We leave the render pass. Note that if we had multiple subpasses we could
|
||||||
|
@ -690,12 +690,8 @@ impl ApplicationHandler for App {
|
|||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// We add a draw command.
|
||||||
builder
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
// We add a draw command.
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
// We leave the render pass.
|
// We leave the render pass.
|
||||||
|
@ -690,12 +690,8 @@ impl ApplicationHandler for App {
|
|||||||
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
.bind_vertex_buffers(0, self.vertex_buffer.clone())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
unsafe {
|
// We add a draw command.
|
||||||
builder
|
unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap();
|
||||||
// We add a draw command.
|
|
||||||
.draw(self.vertex_buffer.len() as u32, 1, 0, 0)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder
|
builder
|
||||||
// We leave the render pass. Note that if we had multiple subpasses we could
|
// We leave the render pass. Note that if we had multiple subpasses we could
|
||||||
|
Loading…
Reference in New Issue
Block a user