mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Improve wgpu-info code after bitflags 2 (#3834)
This commit is contained in:
parent
1cb0bdcdef
commit
3db51e74bd
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3182,8 +3182,8 @@ dependencies = [
|
|||||||
name = "wgpu-info"
|
name = "wgpu-info"
|
||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bitflags 2.3.1",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"num-traits 0.2.15",
|
|
||||||
"wgpu",
|
"wgpu",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,6 @@ license.workspace = true
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bitflags.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
num-traits.workspace = true
|
|
||||||
wgpu.workspace = true
|
wgpu.workspace = true
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod inner {
|
mod inner {
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
|
||||||
mem::size_of,
|
|
||||||
process::{exit, Command},
|
process::{exit, Command},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use num_traits::FromPrimitive;
|
use bitflags::Flags;
|
||||||
|
|
||||||
// Lets keep these on one line
|
// Lets keep these on one line
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
@ -156,9 +154,9 @@ mod inner {
|
|||||||
|
|
||||||
println!("\tFeatures:");
|
println!("\tFeatures:");
|
||||||
let max_feature_flag_width = wgpu::Features::max_debug_print_width();
|
let max_feature_flag_width = wgpu::Features::max_debug_print_width();
|
||||||
wgpu::Features::for_valid_bits(|bit, _i| {
|
for bit in wgpu::Features::all().iter() {
|
||||||
println!("\t\t{:>width$}: {}", format!("{bit:?}"), features.contains(bit), width = max_feature_flag_width);
|
println!("\t\t{:>width$}: {}", bit.name(), features.contains(bit), width = max_feature_flag_width);
|
||||||
});
|
}
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Limits //
|
// Limits //
|
||||||
@ -238,9 +236,9 @@ mod inner {
|
|||||||
} = downlevel;
|
} = downlevel;
|
||||||
println!("\t\t Shader Model: {shader_model:?}");
|
println!("\t\t Shader Model: {shader_model:?}");
|
||||||
let max_downlevel_flag_width = wgpu::DownlevelFlags::max_debug_print_width();
|
let max_downlevel_flag_width = wgpu::DownlevelFlags::max_debug_print_width();
|
||||||
wgpu::DownlevelFlags::for_valid_bits(|bit, _i| {
|
for bit in wgpu::DownlevelFlags::all().iter() {
|
||||||
println!("\t\t{:>width$}: {}", format!("{bit:?}"), flags.contains(bit), width = max_downlevel_flag_width);
|
println!("\t\t{:>width$}: {}", bit.name(), flags.contains(bit), width = max_downlevel_flag_width);
|
||||||
});
|
};
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// Texture Usages //
|
// Texture Usages //
|
||||||
@ -257,16 +255,16 @@ mod inner {
|
|||||||
let features = adapter.get_texture_format_features(format);
|
let features = adapter.get_texture_format_features(format);
|
||||||
let format_name = texture_format_name(format);
|
let format_name = texture_format_name(format);
|
||||||
print!("\t\t{format_name:>0$}", max_format_name_size);
|
print!("\t\t{format_name:>0$}", max_format_name_size);
|
||||||
wgpu::TextureUsages::for_valid_bits(|bit, _i| {
|
for bit in wgpu::TextureUsages::all().iter() {
|
||||||
print!(" │ ");
|
print!(" │ ");
|
||||||
if features.allowed_usages.contains(bit) {
|
if features.allowed_usages.contains(bit) {
|
||||||
print!("{bit:?}");
|
print!("{}", bit.name());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let length = format!("{bit:?}").len();
|
let length = bit.name().len();
|
||||||
print!("{}", " ".repeat(length))
|
print!("{}", " ".repeat(length))
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
println!(" │");
|
println!(" │");
|
||||||
}
|
}
|
||||||
print!("\t\t {texture_format_whitespace}");
|
print!("\t\t {texture_format_whitespace}");
|
||||||
@ -286,16 +284,16 @@ mod inner {
|
|||||||
let format_name = texture_format_name(format);
|
let format_name = texture_format_name(format);
|
||||||
|
|
||||||
print!("\t\t{format_name:>0$}", max_format_name_size);
|
print!("\t\t{format_name:>0$}", max_format_name_size);
|
||||||
wgpu::TextureFormatFeatureFlags::for_valid_bits(|bit, _i| {
|
for bit in wgpu::TextureFormatFeatureFlags::all().iter() {
|
||||||
print!(" │ ");
|
print!(" │ ");
|
||||||
if features.flags.contains(bit) {
|
if features.flags.contains(bit) {
|
||||||
print!("{bit:?}");
|
print!("{}", bit.name());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let length = format!("{bit:?}").len();
|
let length = bit.name().len();
|
||||||
print!("{}", " ".repeat(length))
|
print!("{}", " ".repeat(length))
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
println!(" │");
|
println!(" │");
|
||||||
}
|
}
|
||||||
print!("\t\t {texture_format_whitespace}");
|
print!("\t\t {texture_format_whitespace}");
|
||||||
@ -367,83 +365,49 @@ mod inner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Bitflags: Sized + Debug {
|
trait FlagsExt: Flags {
|
||||||
type Underlying: FromPrimitive;
|
fn name(&self) -> &'static str {
|
||||||
|
self.iter_names().next().unwrap().0
|
||||||
|
}
|
||||||
|
|
||||||
fn from_bits(bits: Self::Underlying) -> Option<Self>;
|
fn valid_bits() -> std::iter::Enumerate<bitflags::iter::Iter<Self>> {
|
||||||
|
Self::all().iter().enumerate()
|
||||||
fn for_valid_bits(mut func: impl FnMut(Self, usize)) {
|
|
||||||
for i in 0..(size_of::<Self>() * 8) {
|
|
||||||
let bit = Self::from_bits(
|
|
||||||
<Self::Underlying as FromPrimitive>::from_u64(1 << i as u64).unwrap(),
|
|
||||||
);
|
|
||||||
if let Some(bit) = bit {
|
|
||||||
func(bit, i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_debug_print_width() -> usize {
|
fn max_debug_print_width() -> usize {
|
||||||
let mut width = 0;
|
let mut width = 0;
|
||||||
Self::for_valid_bits(|bit, _i| {
|
for bit in Self::all().iter() {
|
||||||
width = width.max(format!("{bit:?}").len());
|
width = width.max(bit.name().len());
|
||||||
});
|
}
|
||||||
width
|
width
|
||||||
}
|
}
|
||||||
|
|
||||||
fn println_table_header() {
|
fn println_table_header() {
|
||||||
print!("┌─");
|
print!("┌─");
|
||||||
Self::for_valid_bits(|bit, i| {
|
for (i, bit) in Self::valid_bits() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
print!("─┬─");
|
print!("─┬─");
|
||||||
}
|
}
|
||||||
let length = format!("{bit:?}").len();
|
let length = bit.name().len();
|
||||||
print!("{}", "─".repeat(length));
|
print!("{}", "─".repeat(length));
|
||||||
});
|
}
|
||||||
println!("─┐");
|
println!("─┐");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn println_table_footer() {
|
fn println_table_footer() {
|
||||||
print!("└─");
|
print!("└─");
|
||||||
Self::for_valid_bits(|bit, i| {
|
for (i, bit) in Self::valid_bits() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
print!("─┴─");
|
print!("─┴─");
|
||||||
}
|
}
|
||||||
let length = format!("{bit:?}").len();
|
let length = bit.name().len();
|
||||||
print!("{}", "─".repeat(length));
|
print!("{}", "─".repeat(length));
|
||||||
});
|
}
|
||||||
println!("─┘")
|
println!("─┘")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bitflags for wgpu::DownlevelFlags {
|
impl<T> FlagsExt for T where T: Flags {}
|
||||||
type Underlying = u32;
|
|
||||||
|
|
||||||
fn from_bits(bits: u32) -> Option<Self> {
|
|
||||||
Self::from_bits(bits)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Bitflags for wgpu::Features {
|
|
||||||
type Underlying = u64;
|
|
||||||
|
|
||||||
fn from_bits(bits: u64) -> Option<Self> {
|
|
||||||
Self::from_bits(bits)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Bitflags for wgpu::TextureUsages {
|
|
||||||
type Underlying = u32;
|
|
||||||
|
|
||||||
fn from_bits(bits: u32) -> Option<Self> {
|
|
||||||
Self::from_bits(bits)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Bitflags for wgpu::TextureFormatFeatureFlags {
|
|
||||||
type Underlying = u32;
|
|
||||||
|
|
||||||
fn from_bits(bits: u32) -> Option<Self> {
|
|
||||||
Self::from_bits(bits)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn max_texture_format_name_size() -> usize {
|
fn max_texture_format_name_size() -> usize {
|
||||||
TEXTURE_FORMAT_LIST
|
TEXTURE_FORMAT_LIST
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user