1use super::NativeFlagBits;
9pub use crate::runtime::types::DeviceInfo;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum DeviceKind {
13 Integrated,
14 Discrete,
15 Virtual,
16 Cpu,
18 Other,
19}
20
21impl DeviceInfo {
22 pub const fn index(&self) -> usize {
23 self.hardware.index
24 }
25
26 pub fn name(&self) -> &str {
27 &self.hardware.name
28 }
29
30 pub const fn kind(&self) -> DeviceKind {
31 self.hardware.kind
32 }
33
34 pub fn api_version(&self) -> &str {
35 &self.software.api_version
36 }
37
38 pub const fn vendor_id(&self) -> u32 {
39 self.hardware.vendor_id
40 }
41
42 pub const fn device_id(&self) -> u32 {
43 self.hardware.device_id
44 }
45
46 pub fn driver_name(&self) -> &str {
47 &self.software.driver_name
48 }
49
50 pub fn driver_info(&self) -> &str {
51 &self.software.driver_info
52 }
53
54 pub const fn driver_version(&self) -> u32 {
55 self.software.driver_version
56 }
57
58 pub const fn capability_identity(&self) -> u64 {
62 self.software.capability_identity
63 }
64
65 pub const fn local_memory_bytes(&self) -> u64 {
66 self.hardware.local_memory_bytes
67 }
68
69 pub const fn local_memory_budget_bytes(&self) -> Option<u64> {
71 self.hardware.local_memory_budget_bytes
72 }
73
74 pub const fn local_memory_unified(&self) -> bool {
77 self.hardware.local_memory_unified
78 }
79
80 pub const fn local_memory_usage_bytes(&self) -> Option<u64> {
82 self.hardware.local_memory_usage_bytes
83 }
84
85 pub const fn max_compute_shared_memory_bytes(&self) -> u32 {
86 self.hardware.max_compute_shared_memory_bytes
87 }
88
89 pub const fn max_compute_workgroup_invocations(&self) -> u32 {
90 self.hardware.max_compute_workgroup_invocations
91 }
92
93 pub const fn subgroup_size(&self) -> u32 {
94 self.hardware.subgroup_size
95 }
96
97 pub const fn storage_buffer_descriptors(&self) -> u32 {
99 self.hardware.storage_buffer_descriptors
100 }
101
102 pub const fn storage_image_descriptors(&self) -> u32 {
104 self.hardware.storage_image_descriptors
105 }
106
107 pub const fn supports_shader_float16(&self) -> bool {
108 self.software.shader_float16
109 }
110
111 pub const fn supports_storage_buffer_16_bit_access(&self) -> bool {
112 self.software.storage_buffer_16_bit_access
113 }
114
115 pub const fn supports_fp16_storage(&self) -> bool {
116 self.software.shader_float16 && self.software.storage_buffer_16_bit_access
117 }
118
119 pub const fn supports_shader_float64(&self) -> bool {
120 self.software.shader_float64
121 }
122
123 pub const fn supports_shader_integer_dot_product(&self) -> bool {
124 self.software.shader_integer_dot_product
125 }
126
127 pub const fn cooperative_matrix_tuple_count(&self) -> usize {
128 self.software.cooperative_matrix_tuple_count
129 }
130
131 pub const fn supports_graphics(&self) -> bool {
132 self.hardware.graphics
133 }
134
135 pub const fn supports_swapchain(&self) -> bool {
136 self.hardware.swapchain
137 }
138}
139
140#[derive(Clone, Debug, PartialEq, Eq)]
146pub struct DeviceSummary {
147 pub(crate) index: usize,
148 pub(crate) name: String,
149 pub(crate) kind: DeviceKind,
150 pub(crate) api_version: String,
151}
152
153impl DeviceSummary {
154 pub const fn index(&self) -> usize {
156 self.index
157 }
158 pub fn name(&self) -> &str {
160 &self.name
161 }
162 pub const fn kind(&self) -> DeviceKind {
164 self.kind
165 }
166 pub fn api_version(&self) -> &str {
168 &self.api_version
169 }
170}
171
172#[derive(Clone)]
180pub(in crate::runtime) struct DevicePhysicalInfo {
181 pub(in crate::runtime) index: usize,
182 pub(in crate::runtime) name: String,
183 pub(in crate::runtime) kind: DeviceKind,
184 pub(in crate::runtime) device_type: &'static str,
185 pub(in crate::runtime) api_version: String,
186 pub(in crate::runtime) vendor_id: u32,
187 pub(in crate::runtime) device_id: u32,
188 pub(in crate::runtime) driver_name: String,
189 pub(in crate::runtime) driver_info: String,
190 pub(in crate::runtime) driver_id: vk::DriverId,
191 pub(in crate::runtime) driver_version: u32,
192 pub(in crate::runtime) conformance_version: vk::ConformanceVersion,
193 pub(in crate::runtime) pipeline_cache_uuid: [u8; 16],
197 pub(in crate::runtime) capability_identity: u64,
198 pub(in crate::runtime) local_memory_bytes: u64,
199 pub(in crate::runtime) local_memory_budget_bytes: Option<u64>,
200 pub(in crate::runtime) local_memory_usage_bytes: Option<u64>,
201 pub(in crate::runtime) local_memory_unified: bool,
202}
203
204pub(super) fn format_capacity_value(bytes: u64) -> String {
206 const GIB: u64 = 1024 * 1024 * 1024;
207 const MIB: u64 = 1024 * 1024;
208 if bytes >= GIB {
209 format!("{:.2} GiB", bytes as f64 / GIB as f64)
210 } else {
211 format!("{:.2} MiB", bytes as f64 / MIB as f64)
212 }
213}
214
215pub(super) struct ElectionCandidate<'a> {
217 pub(super) index: usize,
218 pub(super) name: &'a str,
219 pub(super) local_heap_bytes: u64,
220 pub(super) cooperative_matrix_compute: bool,
221 pub(super) shader_float16: bool,
222 pub(super) shader_integer_dot_product: bool,
223 pub(super) on_frontier: bool,
224}
225
226pub(super) fn log_device_election(
233 enumerated_count: usize,
234 candidates: &[ElectionCandidate<'_>],
235 rejections: &[String],
236) {
237 let frontier_count = candidates.iter().filter(|c| c.on_frontier).count();
238 crate::log_info!(
239 crate::LogComponent::RUNTIME,
240 "Vulkan device election · {} enumerated · {} admitted · {} Pareto-front candidates {{",
241 enumerated_count,
242 candidates.len(),
243 frontier_count,
244 );
245 let mut order: Vec<usize> = (0..candidates.len()).collect();
247 order.sort_by_key(|&i| !candidates[i].on_frontier);
248 for i in order {
249 let c = &candidates[i];
250 let tier = match (
251 c.cooperative_matrix_compute,
252 c.shader_float16 || c.shader_integer_dot_product,
253 ) {
254 (true, _) => "hpc",
255 (false, true) => "mid",
256 _ => "edge",
257 };
258 let status = if c.on_frontier {
259 "frontier"
260 } else {
261 "dominated"
262 };
263 crate::log_info!(
264 crate::LogComponent::RUNTIME,
265 " [{}] {} · local-memory {} · {} · {}",
266 c.index,
267 c.name,
268 format_capacity_value(c.local_heap_bytes),
269 tier,
270 status,
271 );
272 }
273 for rejection in rejections {
274 crate::log_info!(crate::LogComponent::RUNTIME, " rejected {rejection}");
275 }
276 crate::log_info!(crate::LogComponent::RUNTIME, "}}");
277}
278
279pub(super) fn log_compute_device(device: &super::Device, p: &str, is_last: bool) {
285 let pp = format!("{} ", p);
286 let ppp = format!("{} ", p);
287 let physical = device.physical();
288 let configuration = device.configuration();
289 let info = &physical.info;
290 let conformance = info.conformance_version;
291
292 crate::log_info!(
293 crate::LogComponent::RUNTIME,
294 "{}oa::Device [{}] {{",
295 p,
296 info.index
297 );
298 crate::log_info!(
299 crate::LogComponent::RUNTIME,
300 "{}name: {} · {}",
301 pp,
302 info.name,
303 info.device_type,
304 );
305 match (
306 info.local_memory_budget_bytes,
307 info.local_memory_usage_bytes,
308 ) {
309 (Some(budget), Some(usage)) => crate::log_info!(
310 crate::LogComponent::RUNTIME,
311 "{}local-memory: {} / {}{}",
312 pp,
313 format_capacity_value(usage),
314 format_capacity_value(budget),
315 if info.local_memory_unified {
316 " (host-visible)"
317 } else {
318 ""
319 },
320 ),
321 _ => crate::log_info!(
322 crate::LogComponent::RUNTIME,
323 "{}local-memory: {}{}",
324 pp,
325 format_capacity_value(info.local_memory_bytes),
326 if info.local_memory_unified {
327 " (host-visible)"
328 } else {
329 ""
330 },
331 ),
332 }
333 let tier = match (
334 physical
335 .cooperative_matrix
336 .supported_stages
337 .contains(vk::ShaderStageFlagBits::COMPUTE_BIT)
338 && !physical.cooperative_matrix.tuples.is_empty(),
339 physical.features.shader_float16 || physical.features.shader_integer_dot_product,
340 ) {
341 (true, _) => "hpc accelerator",
342 (false, true) => "mid-end",
343 _ => "edge",
344 };
345 crate::log_info!(crate::LogComponent::RUNTIME, "{}kind: {}", pp, tier);
346 crate::log_info!(crate::LogComponent::RUNTIME, "{}driver {{", pp);
347 if info.driver_info.is_empty() {
348 crate::log_info!(
349 crate::LogComponent::RUNTIME,
350 "{}name: {}",
351 ppp,
352 info.driver_name
353 );
354 } else {
355 crate::log_info!(
356 crate::LogComponent::RUNTIME,
357 "{}name: {}",
358 ppp,
359 info.driver_info
360 );
361 }
362 crate::log_info!(
363 crate::LogComponent::RUNTIME,
364 "{}id: {:?} · version 0x{:08x} · conformance {}.{}.{}.{}",
365 ppp,
366 info.driver_id,
367 info.driver_version,
368 conformance.major,
369 conformance.minor,
370 conformance.subminor,
371 conformance.patch
372 );
373 crate::log_info!(
374 crate::LogComponent::RUNTIME,
375 "{}api: Vulkan {}",
376 ppp,
377 info.api_version
378 );
379 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
380 crate::log_info!(crate::LogComponent::RUNTIME, "{}hardware {{", pp);
381 crate::log_info!(
382 crate::LogComponent::RUNTIME,
383 "{}pci: {:04x}:{:04x}",
384 ppp,
385 info.vendor_id,
386 info.device_id,
387 );
388 crate::log_info!(
389 crate::LogComponent::RUNTIME,
390 "{}capability_identity: oa.device.v1.{:016x}",
391 ppp,
392 info.capability_identity
393 );
394 crate::log_info!(
395 crate::LogComponent::RUNTIME,
396 "{}profile: {}",
397 ppp,
398 device.execution_profile_name()
399 );
400 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
401 crate::log_info!(crate::LogComponent::RUNTIME, "{}queues {{", pp);
402 crate::log_info!(
403 crate::LogComponent::RUNTIME,
404 "{}compute: family {} · available {} · created {}",
405 ppp,
406 physical.compute_queue_family,
407 physical.compute_queue_count,
408 configuration.queue_count(physical.compute_queue_family),
409 );
410 match physical.graphics_queue_family {
411 Some(gfx) => crate::log_info!(
412 crate::LogComponent::RUNTIME,
413 "{}graphics: family {} · available {} · created {}",
414 ppp,
415 gfx,
416 physical.graphics_queue_count,
417 configuration.queue_count(gfx),
418 ),
419 None => crate::log_info!(
420 crate::LogComponent::RUNTIME,
421 "{}graphics: not supported",
422 ppp
423 ),
424 }
425 match physical.transfer_queue_family {
426 Some(xfr) => crate::log_info!(
427 crate::LogComponent::RUNTIME,
428 "{}transfer: family {} · available {} · created {}",
429 ppp,
430 xfr,
431 physical.transfer_queue_count,
432 configuration.queue_count(xfr),
433 ),
434 None => crate::log_info!(
435 crate::LogComponent::RUNTIME,
436 "{}transfer: not supported",
437 ppp
438 ),
439 }
440 {
441 let v = &physical.video;
442 match v.decode_queue_family {
443 Some(fam) => {
444 let mut codecs = Vec::new();
445 if v.h264_decode {
446 codecs.push("H.264");
447 }
448 if v.h265_decode {
449 codecs.push("H.265");
450 }
451 if v.av1_decode {
452 codecs.push("AV1");
453 }
454 if v.vp9_decode {
455 codecs.push("VP9");
456 }
457 let codec_str = if codecs.is_empty() {
458 String::new()
459 } else {
460 format!(" · {}", codecs.join(" "))
461 };
462 crate::log_info!(
463 crate::LogComponent::RUNTIME,
464 "{}video-decode: family {}{}",
465 ppp,
466 fam,
467 codec_str
468 );
469 }
470 None => crate::log_info!(
471 crate::LogComponent::RUNTIME,
472 "{}video-decode: not supported",
473 ppp
474 ),
475 }
476 match v.encode_queue_family {
477 Some(fam) => {
478 let mut codecs = Vec::new();
479 if v.h264_encode {
480 codecs.push("H.264");
481 }
482 if v.h265_encode {
483 codecs.push("H.265");
484 }
485 if v.av1_encode {
486 codecs.push("AV1");
487 }
488 let codec_str = if codecs.is_empty() {
489 String::new()
490 } else {
491 format!(" · {}", codecs.join(" "))
492 };
493 crate::log_info!(
494 crate::LogComponent::RUNTIME,
495 "{}video-encode: family {}{}",
496 ppp,
497 fam,
498 codec_str
499 );
500 }
501 None => crate::log_info!(
502 crate::LogComponent::RUNTIME,
503 "{}video-encode: not supported",
504 ppp
505 ),
506 }
507 }
508 if device.supports_swapchain() {
509 crate::log_info!(crate::LogComponent::RUNTIME, "{}swapchain: enabled", ppp);
510 }
511 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
512 let lim = &physical.limits;
513 crate::log_info!(crate::LogComponent::RUNTIME, "{}compute {{", pp);
514 crate::log_info!(
515 crate::LogComponent::RUNTIME,
516 "{}shared: {} KiB/workgroup · {} invocations · subgroup {}",
517 ppp,
518 lim.max_compute_shared_memory_size / 1024,
519 lim.max_compute_work_group_invocations,
520 lim.subgroup_size
521 );
522 let (buffer_capacity, image_capacity) = device.descriptor_capacities();
523 crate::log_info!(
524 crate::LogComponent::RUNTIME,
525 "{}descriptors: {} storage-buffer · {} storage-image (allocated)",
526 ppp,
527 buffer_capacity,
528 image_capacity
529 );
530 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
531 let feat = &physical.features;
532 let enabled = configuration.features();
533 crate::log_info!(crate::LogComponent::RUNTIME, "{}precision {{", pp);
534 crate::log_info!(
535 crate::LogComponent::RUNTIME,
536 "{}f64: {}",
537 ppp,
538 feature_state(feat.shader_float64, enabled.shader_float64)
539 );
540 crate::log_info!(crate::LogComponent::RUNTIME, "{}f32: enabled", ppp);
541 crate::log_info!(
542 crate::LogComponent::RUNTIME,
543 "{}bf16: {}",
544 ppp,
545 feature_state(feat.shader_bfloat16, false)
546 );
547 crate::log_info!(
548 crate::LogComponent::RUNTIME,
549 "{}f16: {}",
550 ppp,
551 feature_state(feat.shader_float16, enabled.shader_float16)
552 );
553 let i8_reported = feat.shader_int8 && feat.storage_buffer_8_bit_access;
554 let i8_enabled = enabled.shader_int8 && enabled.storage_buffer_8_bit_access;
555 crate::log_info!(
556 crate::LogComponent::RUNTIME,
557 "{}i8: {}",
558 ppp,
559 feature_state(i8_reported, i8_enabled)
560 );
561 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
562 let coop_compute = physical
563 .cooperative_matrix
564 .supported_stages
565 .contains(vk::ShaderStageFlagBits::COMPUTE_BIT)
566 && !physical.cooperative_matrix.tuples.is_empty();
567 let coop_tuples = physical.cooperative_matrix.tuples.len();
568 crate::log_info!(crate::LogComponent::RUNTIME, "{}features {{", pp);
569 crate::log_info!(
570 crate::LogComponent::RUNTIME,
571 "{}hardware-ycbcr: {}",
572 ppp,
573 feature_state(
574 feat.sampler_ycbcr_conversion,
575 enabled.sampler_ycbcr_conversion
576 )
577 );
578 crate::log_info!(
579 crate::LogComponent::RUNTIME,
580 "{}int-dot: {}",
581 ppp,
582 feature_state(
583 feat.shader_integer_dot_product,
584 enabled.shader_integer_dot_product
585 )
586 );
587 if coop_compute {
588 crate::log_info!(
589 crate::LogComponent::RUNTIME,
590 "{}cooperative-matrix: {} ({} tuples)",
591 ppp,
592 feature_state(coop_compute, enabled.cooperative_matrix),
593 coop_tuples
594 );
595 } else {
596 crate::log_info!(
597 crate::LogComponent::RUNTIME,
598 "{}cooperative-matrix: not supported",
599 ppp
600 );
601 }
602 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", pp);
603 if is_last {
604 crate::log_info!(crate::LogComponent::RUNTIME, "{}}}", p);
605 } else {
606 crate::log_info!(crate::LogComponent::RUNTIME, "{}}},", p);
607 }
608}
609
610fn feature_state(reported: bool, enabled: bool) -> &'static str {
611 if enabled {
612 "enabled"
613 } else if reported {
614 "supported, disabled"
615 } else {
616 "not supported"
617 }
618}