sync
This commit is contained in:
@@ -32,7 +32,6 @@ use winit::event_loop::EventLoop;
|
||||
/// and the compute and canvas states
|
||||
pub struct VkProcessor<'a> {
|
||||
// Vulkan state fields
|
||||
pub instance: Arc<Instance>,
|
||||
pub physical: PhysicalDevice<'a>,
|
||||
pub device: Arc<Device>,
|
||||
pub queues: QueuesIter,
|
||||
@@ -43,9 +42,6 @@ pub struct VkProcessor<'a> {
|
||||
|
||||
pub swapchain_recreate_needed: bool,
|
||||
|
||||
pub surface: Arc<Surface<Window>>,
|
||||
pub event_loop: Arc<EventLoop<()>>,
|
||||
|
||||
/// State holding textures, images, and their related vertex buffers
|
||||
canvas_state: CanvasState,
|
||||
/// State holding
|
||||
@@ -59,42 +55,29 @@ pub struct VkProcessor<'a> {
|
||||
impl<'a> VkProcessor<'a> {
|
||||
/// Creates a new VkProcessor from an instance and surface
|
||||
/// This includes the physical device, queues, compute and canvas state
|
||||
//pub fn new(instance: &'a Arc<Instance>, surface: &'a Arc<Surface<Window>>) -> VkProcessor<'a> {
|
||||
pub fn new(instance: Arc<Instance>) -> VkProcessor<'a> {
|
||||
pub fn new(instance: &'a Arc<Instance>, surface: Arc<Surface<Window>>) -> VkProcessor<'a> {
|
||||
|
||||
let _callback = DebugCallback::errors_and_warnings(&instance, |msg| {
|
||||
println!("Debug callback: {:?}", msg.description);
|
||||
}).ok();
|
||||
let physical = PhysicalDevice::enumerate(instance).next().unwrap();
|
||||
|
||||
let mut events_loop = Arc::new(EventLoop::new());
|
||||
let queue_family = physical.queue_families().find(|&q| {
|
||||
// We take the first queue that supports drawing to our window.
|
||||
q.supports_graphics() &&
|
||||
surface.is_supported(q).unwrap_or(false) &&
|
||||
q.supports_compute()
|
||||
}).unwrap();
|
||||
|
||||
let mut surface = WindowBuilder::new()
|
||||
.with_inner_size(LogicalSize::new(800, 800));
|
||||
let device_ext = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::none() };
|
||||
|
||||
// Some weird namespacing issue here
|
||||
let mut surface = VkSurfaceBuild::build_vk_surface(surface, &events_loop, instance.clone()).unwrap();
|
||||
let (device, mut queues) = Device::new(physical,
|
||||
physical.supported_features(),
|
||||
&device_ext,
|
||||
[(queue_family, 0.5)].iter().cloned()).unwrap();
|
||||
let queue = queues.next().unwrap();
|
||||
|
||||
let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
|
||||
let capabilities = surface.capabilities(physical).unwrap();
|
||||
|
||||
let queue_family = physical.queue_families().find(|&q| {
|
||||
// We take the first queue that supports drawing to our window.
|
||||
q.supports_graphics() &&
|
||||
surface.is_supported(q).unwrap_or(false) &&
|
||||
q.supports_compute()
|
||||
}).unwrap();
|
||||
|
||||
let device_ext = DeviceExtensions { khr_swapchain: true, ..DeviceExtensions::none() };
|
||||
|
||||
let (device, mut queues) = Device::new(physical,
|
||||
physical.supported_features(),
|
||||
&device_ext,
|
||||
[(queue_family, 0.5)].iter().cloned()).unwrap();
|
||||
let queue = queues.next().unwrap();
|
||||
|
||||
let capabilities = surface.capabilities(physical).unwrap();
|
||||
|
||||
VkProcessor {
|
||||
instance: instance.clone(),
|
||||
physical: physical.clone(),
|
||||
device: device.clone(),
|
||||
queue: queue.clone(),
|
||||
@@ -105,8 +88,6 @@ impl<'a> VkProcessor<'a> {
|
||||
compute_state: CompuState::new(),
|
||||
capabilities: capabilities.clone(),
|
||||
canvas_state: CanvasState::new(queue, device, physical, capabilities),
|
||||
surface: surface,
|
||||
event_loop: events_loop,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,24 +97,19 @@ impl<'a> VkProcessor<'a> {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn event_loop(&mut self) -> Arc<EventLoop<()>> {
|
||||
self.event_loop()
|
||||
}
|
||||
|
||||
/// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images
|
||||
pub fn create_swapchain(&mut self) {
|
||||
|
||||
pub fn create_swapchain(&mut self, surface: Arc<Surface<Window>>) {
|
||||
let (mut swapchain, images) = {
|
||||
let capabilities = self.surface.capabilities(self.physical).unwrap();
|
||||
let capabilities = surface.capabilities(self.physical).unwrap();
|
||||
let usage = capabilities.supported_usage_flags;
|
||||
let alpha = capabilities.supported_composite_alpha.iter().next().unwrap();
|
||||
// Choosing the internal format that the images will have.
|
||||
let format = capabilities.supported_formats[0].0;
|
||||
|
||||
// Set the swapchains window dimensions
|
||||
let initial_dimensions = if let dimensions = self.surface.window().inner_size() {
|
||||
let initial_dimensions = if let dimensions = surface.window().inner_size() {
|
||||
// convert to physical pixels
|
||||
let dimensions: (u32, u32) = dimensions.to_logical::<u32>(self.surface.window().scale_factor()).into();
|
||||
let dimensions: (u32, u32) = dimensions.to_logical::<u32>(surface.window().scale_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
// The window no longer exists so exit the application.
|
||||
@@ -141,7 +117,7 @@ impl<'a> VkProcessor<'a> {
|
||||
};
|
||||
|
||||
Swapchain::new(self.device.clone(),
|
||||
self.surface.clone(),
|
||||
surface.clone(),
|
||||
capabilities.min_image_count, // number of attachment images
|
||||
format,
|
||||
initial_dimensions,
|
||||
@@ -160,9 +136,9 @@ impl<'a> VkProcessor<'a> {
|
||||
}
|
||||
|
||||
/// On screen resizes, the swapchain and images must be recreated
|
||||
pub fn recreate_swapchain(&mut self) {
|
||||
let dimensions = if let dimensions = self.surface.window().inner_size() {
|
||||
let dimensions: (u32, u32) = dimensions.to_logical::<u32>(self.surface.window().scale_factor()).into();
|
||||
pub fn recreate_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
||||
let dimensions = if let dimensions = surface.window().inner_size() {
|
||||
let dimensions: (u32, u32) = dimensions.to_logical::<u32>(surface.window().scale_factor()).into();
|
||||
[dimensions.0, dimensions.1]
|
||||
} else {
|
||||
return;
|
||||
@@ -254,6 +230,7 @@ impl<'a> VkProcessor<'a> {
|
||||
|
||||
/// Run the VKprocessor for a single frame, consuming the Canvas/Compu Frames
|
||||
pub fn run(&mut self,
|
||||
surface: &'a Arc<Surface<Window>>,
|
||||
canvas_frame: CanvasFrame,
|
||||
compute_frame: CompuFrame,
|
||||
) {
|
||||
@@ -269,7 +246,7 @@ impl<'a> VkProcessor<'a> {
|
||||
// Whenever the window resizes we need to recreate everything dependent on the window size.
|
||||
// In this example that includes the swapchain, the framebuffers and the dynamic state viewport.
|
||||
if self.swapchain_recreate_needed {
|
||||
self.recreate_swapchain();
|
||||
self.recreate_swapchain(surface);
|
||||
framebuffers =
|
||||
self.canvas_state.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
|
||||
self.swapchain_recreate_needed = false;
|
||||
|
||||
Reference in New Issue
Block a user