Skip to content

Commit 56cd569

Browse files
committed
Update vulkano version to 0.21
1 parent 105fd06 commit 56cd569

File tree

5 files changed

+189
-104
lines changed

5 files changed

+189
-104
lines changed

wyvern-vulkan/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ wyvern-core = { path = "../wyvern-core" }
88
rspirv = "0.5"
99
spirv_headers = "=1.3.4"
1010
byteorder = "1.2"
11-
vulkano = "0.11"
11+
vulkano = "0.21"
1212
rand = "0.5.0-pre.0"
1313
tempfile = "3"

wyvern-vulkan/src/executable.rs

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 | Dario Ostuni <[email protected]>
1+
// Copyright 2018-2021 | Dario Ostuni <[email protected]>
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@ use executor::ModuleLayout;
1616
use generator::{BindType, Binding, VkVersion};
1717
use resource::ResourceType;
1818
use resource::VkResource;
19+
use std::iter::empty;
1920
use std::mem::swap;
2021
use std::sync::Arc;
2122
use vulkano::buffer::cpu_access::CpuAccessibleBuffer;
@@ -30,6 +31,7 @@ use vulkano::descriptor::descriptor_set::UnsafeDescriptorSetLayout;
3031
use vulkano::descriptor::descriptor_set::{DescriptorSet, DescriptorSetDesc};
3132
use vulkano::descriptor::pipeline_layout::PipelineLayout;
3233
use vulkano::descriptor::pipeline_layout::PipelineLayoutDesc;
34+
use vulkano::device::DeviceOwned;
3335
use vulkano::device::{Device, Queue};
3436
use vulkano::image::ImageViewAccess;
3537
use vulkano::pipeline::shader::ShaderModule;
@@ -99,7 +101,8 @@ impl Executable for VkExecutable {
99101
let unsafe_layout_object = UnsafeDescriptorSetLayout::new(
100102
self.device.clone(),
101103
(0..self.layout.num_bindings_in_set(0).unwrap()).map(|x| self.layout.descriptor(0, x)),
102-
).unwrap();
104+
)
105+
.unwrap();
103106
let layout = (0..1).map(|_| &unsafe_layout_object);
104107
let mut set = unsafe { self.pool.alloc(layout) }.unwrap().next().unwrap();
105108
let mut buffers = Vec::new();
@@ -113,22 +116,28 @@ impl Executable for VkExecutable {
113116
CpuAccessibleBuffer::from_iter(
114117
self.device.clone(),
115118
BufferUsage::all(),
119+
true,
116120
(0..size).map(|_| 0_u32),
117-
).unwrap(),
121+
)
122+
.unwrap(),
118123
)),
119124
DataType::I32 => buffers.push(ResourceType::VI32(
120125
CpuAccessibleBuffer::from_iter(
121126
self.device.clone(),
122127
BufferUsage::all(),
128+
true,
123129
(0..size).map(|_| 0_i32),
124-
).unwrap(),
130+
)
131+
.unwrap(),
125132
)),
126133
DataType::F32 => buffers.push(ResourceType::VF32(
127134
CpuAccessibleBuffer::from_iter(
128135
self.device.clone(),
129136
BufferUsage::all(),
137+
true,
130138
(0..size).map(|_| 0_f32),
131-
).unwrap(),
139+
)
140+
.unwrap(),
132141
)),
133142
DataType::Bool => unreachable!(),
134143
};
@@ -168,23 +177,27 @@ impl Executable for VkExecutable {
168177
set,
169178
layout: self.layout.clone(),
170179
buffers,
180+
device: self.device.clone(),
171181
};
172-
let command_buffer = AutoCommandBufferBuilder::primary_one_time_submit(
173-
self.device.clone(),
174-
self.queue.family(),
175-
).unwrap()
176-
.dispatch(
177-
// FIXME: [self.work_size, 1, 1],
178-
[128, 1, 1],
179-
self.pipeline.clone(),
180-
sanitized_set,
181-
(),
182+
let cmd = {
183+
let mut command_buffer = AutoCommandBufferBuilder::primary_one_time_submit(
184+
self.device.clone(),
185+
self.queue.family(),
182186
)
183-
.unwrap()
184-
.build()
185187
.unwrap();
188+
command_buffer
189+
.dispatch(
190+
[self.work_size / 12, 1, 1], // FIXME: this assumes 12 CU
191+
self.pipeline.clone(),
192+
sanitized_set,
193+
empty::<u32>(),
194+
empty(),
195+
)
196+
.unwrap();
197+
command_buffer.build().unwrap()
198+
};
186199
let future = now(self.device.clone())
187-
.then_execute(self.queue.clone(), command_buffer)
200+
.then_execute(self.queue.clone(), cmd)
188201
.unwrap()
189202
.then_signal_fence_and_flush()
190203
.unwrap();
@@ -198,6 +211,7 @@ struct MyDescriptorSet {
198211
set: UnsafeDescriptorSet,
199212
layout: ModuleLayout,
200213
buffers: Vec<ResourceType>,
214+
device: Arc<Device>,
201215
}
202216

203217
unsafe impl DescriptorSetDesc for MyDescriptorSet {
@@ -210,6 +224,12 @@ unsafe impl DescriptorSetDesc for MyDescriptorSet {
210224
}
211225
}
212226

227+
unsafe impl DeviceOwned for MyDescriptorSet {
228+
fn device(&self) -> &Arc<Device> {
229+
&self.device
230+
}
231+
}
232+
213233
unsafe impl DescriptorSet for MyDescriptorSet {
214234
fn inner(&self) -> &UnsafeDescriptorSet {
215235
&self.set
@@ -219,7 +239,7 @@ unsafe impl DescriptorSet for MyDescriptorSet {
219239
self.buffers.len()
220240
}
221241

222-
fn buffer(&self, index: usize) -> Option<(&BufferAccess, u32)> {
242+
fn buffer(&self, index: usize) -> Option<(&dyn BufferAccess, u32)> {
223243
if index >= self.buffers.len() {
224244
return None;
225245
}
@@ -239,7 +259,7 @@ unsafe impl DescriptorSet for MyDescriptorSet {
239259
0
240260
}
241261

242-
fn image(&self, _index: usize) -> Option<(&ImageViewAccess, u32)> {
262+
fn image(&self, _index: usize) -> Option<(&dyn ImageViewAccess, u32)> {
243263
None
244264
}
245265
}

wyvern-vulkan/src/executor.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl Executor for VkExecutor {
4949
type Executable = VkExecutable;
5050

5151
fn new(_config: ()) -> Result<VkExecutor, String> {
52-
let instance =
53-
Instance::new(None, &InstanceExtensions::none(), None).map_err(|x| format!("{:?}", x))?;
52+
let instance = Instance::new(None, &InstanceExtensions::none(), None)
53+
.map_err(|x| format!("{:?}", x))?;
5454
let physical_device = PhysicalDevice::enumerate(&instance)
5555
.next()
5656
.ok_or("No Vulkan device found")?;
@@ -80,7 +80,8 @@ impl Executor for VkExecutor {
8080
physical_device.supported_features(),
8181
&DeviceExtensions::none(),
8282
[(queue, 0.5)].iter().cloned(),
83-
).map_err(|x| format!("{:?}", x))?
83+
)
84+
.map_err(|x| format!("{:?}", x))?
8485
};
8586
let queue = queues.next().ok_or("No queue found")?;
8687
Ok(VkExecutor {
@@ -143,7 +144,8 @@ impl Executor for VkExecutor {
143144
}
144145
}
145146
let module = unsafe {
146-
ShaderModule::from_words(self.device.clone(), &binary).map_err(|x| format!("{:?}", x))?
147+
ShaderModule::from_words(self.device.clone(), &binary)
148+
.map_err(|x| format!("{:?}", x))?
147149
};
148150
let num_bindings = bindings.iter().map(|x| x.0 + 1).max().unwrap_or(0);
149151
let layout = ModuleLayout {
@@ -156,7 +158,9 @@ impl Executor for VkExecutor {
156158
self.device.clone(),
157159
&unsafe { module.compute_entry_point(&CString::new("main").unwrap(), layout) },
158160
&(),
159-
).map_err(|x| format!("{:?}", x))?
161+
None,
162+
)
163+
.map_err(|x| format!("{:?}", x))?
160164
});
161165
let layout = ModuleLayout {
162166
bindings: bindings.clone(),
@@ -172,7 +176,8 @@ impl Executor for VkExecutor {
172176
},
173177
1,
174178
true,
175-
).unwrap();
179+
)
180+
.unwrap();
176181
Ok(VkExecutable {
177182
pool,
178183
module,

0 commit comments

Comments
 (0)