1
1
//! Common state shared throughout the graphics system
2
2
3
+ use ash:: ext:: debug_utils;
3
4
use std:: ffi:: { c_char, CStr } ;
4
5
use std:: path:: PathBuf ;
5
6
use std:: sync:: Arc ;
6
- use std:: { fs, io, ptr } ;
7
+ use std:: { fs, io} ;
7
8
use tracing:: { error, info, trace, warn} ;
8
9
9
10
use ash:: { vk, Device } ;
@@ -34,6 +35,7 @@ pub struct Base {
34
35
pub limits : vk:: PhysicalDeviceLimits ,
35
36
pub timestamp_bits : u32 ,
36
37
pipeline_cache_path : Option < PathBuf > ,
38
+ debug_utils : Option < debug_utils:: Device > ,
37
39
}
38
40
39
41
unsafe impl Send for Base { }
@@ -133,11 +135,10 @@ impl Base {
133
135
instance
134
136
. create_device (
135
137
physical,
136
- & vk:: DeviceCreateInfo :: builder ( )
137
- . queue_create_infos ( & [ vk:: DeviceQueueCreateInfo :: builder ( )
138
+ & vk:: DeviceCreateInfo :: default ( )
139
+ . queue_create_infos ( & [ vk:: DeviceQueueCreateInfo :: default ( )
138
140
. queue_family_index ( queue_family_index)
139
- . queue_priorities ( & [ 1.0 ] )
140
- . build ( ) ] )
141
+ . queue_priorities ( & [ 1.0 ] ) ] )
141
142
. enabled_extension_names ( & device_exts) ,
142
143
None ,
143
144
)
@@ -147,14 +148,14 @@ impl Base {
147
148
let memory_properties = instance. get_physical_device_memory_properties ( physical) ;
148
149
let pipeline_cache = device
149
150
. create_pipeline_cache (
150
- & vk:: PipelineCacheCreateInfo :: builder ( ) . initial_data ( & pipeline_cache_data) ,
151
+ & vk:: PipelineCacheCreateInfo :: default ( ) . initial_data ( & pipeline_cache_data) ,
151
152
None ,
152
153
)
153
154
. unwrap ( ) ;
154
155
155
156
let render_pass = device
156
157
. create_render_pass (
157
- & vk:: RenderPassCreateInfo :: builder ( )
158
+ & vk:: RenderPassCreateInfo :: default ( )
158
159
. attachments ( & [
159
160
vk:: AttachmentDescription {
160
161
format : COLOR_FORMAT ,
@@ -176,7 +177,7 @@ impl Base {
176
177
} ,
177
178
] )
178
179
. subpasses ( & [
179
- vk:: SubpassDescription :: builder ( )
180
+ vk:: SubpassDescription :: default ( )
180
181
. color_attachments ( & [ vk:: AttachmentReference {
181
182
attachment : 0 ,
182
183
layout : vk:: ImageLayout :: COLOR_ATTACHMENT_OPTIMAL ,
@@ -185,9 +186,8 @@ impl Base {
185
186
attachment : 1 ,
186
187
layout : vk:: ImageLayout :: DEPTH_STENCIL_ATTACHMENT_OPTIMAL ,
187
188
} )
188
- . pipeline_bind_point ( vk:: PipelineBindPoint :: GRAPHICS )
189
- . build ( ) ,
190
- vk:: SubpassDescription :: builder ( )
189
+ . pipeline_bind_point ( vk:: PipelineBindPoint :: GRAPHICS ) ,
190
+ vk:: SubpassDescription :: default ( )
191
191
. color_attachments ( & [ vk:: AttachmentReference {
192
192
attachment : 0 ,
193
193
layout : vk:: ImageLayout :: COLOR_ATTACHMENT_OPTIMAL ,
@@ -196,8 +196,7 @@ impl Base {
196
196
attachment : 1 ,
197
197
layout : vk:: ImageLayout :: DEPTH_STENCIL_READ_ONLY_OPTIMAL ,
198
198
} ] )
199
- . pipeline_bind_point ( vk:: PipelineBindPoint :: GRAPHICS )
200
- . build ( ) ,
199
+ . pipeline_bind_point ( vk:: PipelineBindPoint :: GRAPHICS ) ,
201
200
] )
202
201
. dependencies ( & [
203
202
vk:: SubpassDependency {
@@ -225,7 +224,7 @@ impl Base {
225
224
226
225
let linear_sampler = device
227
226
. create_sampler (
228
- & vk:: SamplerCreateInfo :: builder ( )
227
+ & vk:: SamplerCreateInfo :: default ( )
229
228
. min_filter ( vk:: Filter :: LINEAR )
230
229
. mag_filter ( vk:: Filter :: LINEAR )
231
230
. mipmap_mode ( vk:: SamplerMipmapMode :: NEAREST )
@@ -238,28 +237,32 @@ impl Base {
238
237
239
238
let common_layout = device
240
239
. create_descriptor_set_layout (
241
- & vk:: DescriptorSetLayoutCreateInfo :: builder ( ) . bindings ( & [
240
+ & vk:: DescriptorSetLayoutCreateInfo :: default ( ) . bindings ( & [
242
241
// Uniforms
243
242
vk:: DescriptorSetLayoutBinding {
244
243
binding : 0 ,
245
244
descriptor_type : vk:: DescriptorType :: UNIFORM_BUFFER ,
246
245
descriptor_count : 1 ,
247
246
stage_flags : vk:: ShaderStageFlags :: VERTEX
248
247
| vk:: ShaderStageFlags :: FRAGMENT ,
249
- p_immutable_samplers : ptr :: null ( ) ,
248
+ .. Default :: default ( )
250
249
} ,
251
250
// Depth buffer
252
251
vk:: DescriptorSetLayoutBinding {
253
252
binding : 1 ,
254
253
descriptor_type : vk:: DescriptorType :: INPUT_ATTACHMENT ,
255
254
descriptor_count : 1 ,
256
255
stage_flags : vk:: ShaderStageFlags :: FRAGMENT ,
257
- p_immutable_samplers : ptr :: null ( ) ,
256
+ .. Default :: default ( )
258
257
} ,
259
258
] ) ,
260
259
None ,
261
260
)
262
261
. unwrap ( ) ;
262
+ let debug_utils = core
263
+ . debug_utils
264
+ . as_ref ( )
265
+ . map ( |_| debug_utils:: Device :: new ( & core. instance , & device) ) ;
263
266
264
267
Some ( Self {
265
268
core,
@@ -275,6 +278,7 @@ impl Base {
275
278
pipeline_cache_path,
276
279
limits : physical_properties. properties . limits ,
277
280
timestamp_bits : queue_family_properties. timestamp_valid_bits ,
281
+ debug_utils,
278
282
} )
279
283
}
280
284
}
@@ -301,15 +305,12 @@ impl Base {
301
305
302
306
/// Set an object's name for use in diagnostics
303
307
pub unsafe fn set_name < T : vk:: Handle > ( & self , object : T , name : & CStr ) {
304
- let ex = match self . core . debug_utils . as_ref ( ) {
305
- Some ( x) => x,
306
- None => return ,
308
+ let Some ( ref ex) = self . debug_utils else {
309
+ return ;
307
310
} ;
308
311
ex. set_debug_utils_object_name (
309
- self . device . handle ( ) ,
310
- & vk:: DebugUtilsObjectNameInfoEXT :: builder ( )
311
- . object_type ( T :: TYPE )
312
- . object_handle ( object. as_raw ( ) )
312
+ & vk:: DebugUtilsObjectNameInfoEXT :: default ( )
313
+ . object_handle ( object)
313
314
. object_name ( name) ,
314
315
)
315
316
. unwrap ( ) ;
0 commit comments