-
Notifications
You must be signed in to change notification settings - Fork 47
/
04_logical_device.rs.diff
71 lines (63 loc) · 2.22 KB
/
04_logical_device.rs.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--- a/03_physical_device_selection.rs
+++ b/04_logical_device.rs
@@ -15,6 +15,7 @@ use vulkano::instance::{
PhysicalDevice,
};
use vulkano::instance::debug::{DebugCallback, MessageTypes};
+use vulkano::device::{Device, DeviceExtensions, Queue, Features};
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
@@ -49,6 +50,9 @@ struct HelloTriangleApplication {
events_loop: EventsLoop,
physical_device_index: usize, // can't store PhysicalDevice directly (lifetime issues)
+ device: Arc<Device>,
+
+ graphics_queue: Arc<Queue>,
}
impl HelloTriangleApplication {
@@ -59,6 +63,8 @@ impl HelloTriangleApplication {
let events_loop = Self::init_window();
let physical_device_index = Self::pick_physical_device(&instance);
+ let (device, graphics_queue) = Self::create_logical_device(
+ &instance, physical_device_index);
Self {
instance,
@@ -67,6 +73,9 @@ impl HelloTriangleApplication {
events_loop,
physical_device_index,
+ device,
+
+ graphics_queue,
}
}
@@ -166,6 +175,31 @@ impl HelloTriangleApplication {
indices
}
+ fn create_logical_device(
+ instance: &Arc<Instance>,
+ physical_device_index: usize,
+ ) -> (Arc<Device>, Arc<Queue>) {
+ let physical_device = PhysicalDevice::from_index(&instance, physical_device_index).unwrap();
+ let indices = Self::find_queue_families(&physical_device);
+
+ let queue_family = physical_device.queue_families()
+ .nth(indices.graphics_family as usize).unwrap();
+
+ let queue_priority = 1.0;
+
+ // NOTE: the tutorial recommends passing the validation layers as well
+ // for legacy reasons (if ENABLE_VALIDATION_LAYERS is true). Vulkano handles that
+ // for us internally.
+
+ let (device, mut queues) = Device::new(physical_device, &Features::none(), &DeviceExtensions::none(),
+ [(queue_family, queue_priority)].iter().cloned())
+ .expect("failed to create logical device!");
+
+ let graphics_queue = queues.next().unwrap();
+
+ (device, graphics_queue)
+ }
+
#[allow(unused)]
fn main_loop(&mut self) {
loop {