1
- // Copyright 2018 | Dario Ostuni <[email protected] >
1
+ // Copyright 2018-2021 | Dario Ostuni <[email protected] >
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@ use executor::ModuleLayout;
16
16
use generator:: { BindType , Binding , VkVersion } ;
17
17
use resource:: ResourceType ;
18
18
use resource:: VkResource ;
19
+ use std:: iter:: empty;
19
20
use std:: mem:: swap;
20
21
use std:: sync:: Arc ;
21
22
use vulkano:: buffer:: cpu_access:: CpuAccessibleBuffer ;
@@ -30,6 +31,7 @@ use vulkano::descriptor::descriptor_set::UnsafeDescriptorSetLayout;
30
31
use vulkano:: descriptor:: descriptor_set:: { DescriptorSet , DescriptorSetDesc } ;
31
32
use vulkano:: descriptor:: pipeline_layout:: PipelineLayout ;
32
33
use vulkano:: descriptor:: pipeline_layout:: PipelineLayoutDesc ;
34
+ use vulkano:: device:: DeviceOwned ;
33
35
use vulkano:: device:: { Device , Queue } ;
34
36
use vulkano:: image:: ImageViewAccess ;
35
37
use vulkano:: pipeline:: shader:: ShaderModule ;
@@ -99,7 +101,8 @@ impl Executable for VkExecutable {
99
101
let unsafe_layout_object = UnsafeDescriptorSetLayout :: new (
100
102
self . device . clone ( ) ,
101
103
( 0 ..self . layout . num_bindings_in_set ( 0 ) . unwrap ( ) ) . map ( |x| self . layout . descriptor ( 0 , x) ) ,
102
- ) . unwrap ( ) ;
104
+ )
105
+ . unwrap ( ) ;
103
106
let layout = ( 0 ..1 ) . map ( |_| & unsafe_layout_object) ;
104
107
let mut set = unsafe { self . pool . alloc ( layout) } . unwrap ( ) . next ( ) . unwrap ( ) ;
105
108
let mut buffers = Vec :: new ( ) ;
@@ -113,22 +116,28 @@ impl Executable for VkExecutable {
113
116
CpuAccessibleBuffer :: from_iter (
114
117
self . device . clone ( ) ,
115
118
BufferUsage :: all ( ) ,
119
+ true ,
116
120
( 0 ..size) . map ( |_| 0_u32 ) ,
117
- ) . unwrap ( ) ,
121
+ )
122
+ . unwrap ( ) ,
118
123
) ) ,
119
124
DataType :: I32 => buffers. push ( ResourceType :: VI32 (
120
125
CpuAccessibleBuffer :: from_iter (
121
126
self . device . clone ( ) ,
122
127
BufferUsage :: all ( ) ,
128
+ true ,
123
129
( 0 ..size) . map ( |_| 0_i32 ) ,
124
- ) . unwrap ( ) ,
130
+ )
131
+ . unwrap ( ) ,
125
132
) ) ,
126
133
DataType :: F32 => buffers. push ( ResourceType :: VF32 (
127
134
CpuAccessibleBuffer :: from_iter (
128
135
self . device . clone ( ) ,
129
136
BufferUsage :: all ( ) ,
137
+ true ,
130
138
( 0 ..size) . map ( |_| 0_f32 ) ,
131
- ) . unwrap ( ) ,
139
+ )
140
+ . unwrap ( ) ,
132
141
) ) ,
133
142
DataType :: Bool => unreachable ! ( ) ,
134
143
} ;
@@ -168,23 +177,27 @@ impl Executable for VkExecutable {
168
177
set,
169
178
layout : self . layout . clone ( ) ,
170
179
buffers,
180
+ device : self . device . clone ( ) ,
171
181
} ;
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 ( ) ,
182
186
)
183
- . unwrap ( )
184
- . build ( )
185
187
. 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
+ } ;
186
199
let future = now ( self . device . clone ( ) )
187
- . then_execute ( self . queue . clone ( ) , command_buffer )
200
+ . then_execute ( self . queue . clone ( ) , cmd )
188
201
. unwrap ( )
189
202
. then_signal_fence_and_flush ( )
190
203
. unwrap ( ) ;
@@ -198,6 +211,7 @@ struct MyDescriptorSet {
198
211
set : UnsafeDescriptorSet ,
199
212
layout : ModuleLayout ,
200
213
buffers : Vec < ResourceType > ,
214
+ device : Arc < Device > ,
201
215
}
202
216
203
217
unsafe impl DescriptorSetDesc for MyDescriptorSet {
@@ -210,6 +224,12 @@ unsafe impl DescriptorSetDesc for MyDescriptorSet {
210
224
}
211
225
}
212
226
227
+ unsafe impl DeviceOwned for MyDescriptorSet {
228
+ fn device ( & self ) -> & Arc < Device > {
229
+ & self . device
230
+ }
231
+ }
232
+
213
233
unsafe impl DescriptorSet for MyDescriptorSet {
214
234
fn inner ( & self ) -> & UnsafeDescriptorSet {
215
235
& self . set
@@ -219,7 +239,7 @@ unsafe impl DescriptorSet for MyDescriptorSet {
219
239
self . buffers . len ( )
220
240
}
221
241
222
- fn buffer ( & self , index : usize ) -> Option < ( & BufferAccess , u32 ) > {
242
+ fn buffer ( & self , index : usize ) -> Option < ( & dyn BufferAccess , u32 ) > {
223
243
if index >= self . buffers . len ( ) {
224
244
return None ;
225
245
}
@@ -239,7 +259,7 @@ unsafe impl DescriptorSet for MyDescriptorSet {
239
259
0
240
260
}
241
261
242
- fn image ( & self , _index : usize ) -> Option < ( & ImageViewAccess , u32 ) > {
262
+ fn image ( & self , _index : usize ) -> Option < ( & dyn ImageViewAccess , u32 ) > {
243
263
None
244
264
}
245
265
}
0 commit comments