Skip to content

Commit

Permalink
Revert "autogen: implement Display for bitenum types"
Browse files Browse the repository at this point in the history
This reverts commit 979308b.
  • Loading branch information
msiglreith committed Nov 21, 2023
1 parent 979308b commit d5c4c23
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 92 deletions.
47 changes: 22 additions & 25 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,24 @@ fn get_push_extras(
/// Returns the generated dr::Operand and its fmt::Display implementation by
/// walking the given SPIR-V operand kinds `grammar`.
pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
let kind_and_category: Vec<_> = grammar
let kinds: Vec<_> = grammar
.iter()
.map(|element| element.kind.as_str())
.filter(|element| {
let kind: &str = element.kind.as_str();

// Pair kinds are not used in dr::Operand.
// LiteralContextDependentNumber is replaced by suitable literals.
// LiteralInteger is replaced by LiteralBit32.
// IdResult and IdResultType are not stored as operands in `dr`.
!(kind.starts_with("Pair")
!(element.starts_with("Pair")
|| matches!(
kind,
*element,
"LiteralContextDependentNumber"
| "LiteralInteger"
| "IdResult"
| "IdResultType"
))
})
.map(|element| (as_ident(element.kind.as_str()), element.category))
.map(as_ident)
.collect();

let kind_to_enum: Vec<_> = grammar
Expand All @@ -249,10 +248,10 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
.collect();

let kind_and_ty = {
let id_kinds = kind_and_category
let id_kinds = kinds
.iter()
.filter(|(_, category)| *category == structs::Category::Id)
.map(|(element, _)| (element.clone(), quote! { spirv::Word }));
.filter(|element| element.to_string().starts_with("Id"))
.map(|element| (element.clone(), quote! { spirv::Word }));

let num_kinds = vec![
(format_ident!("LiteralBit32"), quote! {u32}),
Expand All @@ -264,21 +263,21 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
),
];

let str_kinds = kind_and_category
let str_kinds = kinds
.iter()
.filter(|(element, _)| element.to_string().ends_with("String"))
.map(|(element, _)| (element.clone(), quote! {String}));
.filter(|element| element.to_string().ends_with("String"))
.map(|element| (element.clone(), quote! {String}));

let enum_kinds = kind_and_category
let enum_kinds = kinds
.iter()
.filter(|(element, _)| {
.filter(|element| {
let element = element.to_string();
!(element.starts_with("Id")
|| element.ends_with("String")
|| element.ends_with("Integer")
|| element.ends_with("Number"))
})
.map(|(element, _)| (element.clone(), quote! {spirv::#element}));
.map(|element| (element.clone(), quote! {spirv::#element}));

enum_kinds
.chain(id_kinds)
Expand Down Expand Up @@ -333,12 +332,14 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {

let impl_code = {
// impl fmt::Display for dr::Operand.
let mut kinds = kind_and_category;
kinds.extend([
(as_ident("LiteralBit32"), structs::Category::Literal),
(as_ident("LiteralBit64"), structs::Category::Literal),
]);
let cases = kinds.iter().map(|(element, category)| {
let mut kinds = kinds;
kinds.extend(
["LiteralBit32", "LiteralBit64"]
.iter()
.cloned()
.map(as_ident),
);
let cases = kinds.iter().map(|element| {
if element == "Dim" {
// Skip the "Dim" prefix, which is only used in the API to
// avoid having an enumerant name starting with a number
Expand All @@ -350,10 +351,6 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
quote! {
Operand::#element(ref v) => write!(f, "%{}", v)
}
} else if *category == structs::Category::BitEnum {
quote! {
Operand::#element(ref v) => write!(f, "{}", v)
}
} else {
quote! {
Operand::#element(ref v) => write!(f, "{:?}", v)
Expand Down
6 changes: 0 additions & 6 deletions autogen/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ fn gen_bit_enum_operand_kind(grammar: &structs::OperandKind) -> TokenStream {
#(#elements)*
}
}

impl core::fmt::Display for #kind {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions rspirv/dr/autogen_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ impl From<String> for Operand {
impl fmt::Display for Operand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Operand::ImageOperands(ref v) => write!(f, "{}", v),
Operand::FPFastMathMode(ref v) => write!(f, "{}", v),
Operand::SelectionControl(ref v) => write!(f, "{}", v),
Operand::LoopControl(ref v) => write!(f, "{}", v),
Operand::FunctionControl(ref v) => write!(f, "{}", v),
Operand::MemorySemantics(ref v) => write!(f, "{}", v),
Operand::MemoryAccess(ref v) => write!(f, "{}", v),
Operand::KernelProfilingInfo(ref v) => write!(f, "{}", v),
Operand::RayFlags(ref v) => write!(f, "{}", v),
Operand::FragmentShadingRate(ref v) => write!(f, "{}", v),
Operand::ImageOperands(ref v) => write!(f, "{:?}", v),
Operand::FPFastMathMode(ref v) => write!(f, "{:?}", v),
Operand::SelectionControl(ref v) => write!(f, "{:?}", v),
Operand::LoopControl(ref v) => write!(f, "{:?}", v),
Operand::FunctionControl(ref v) => write!(f, "{:?}", v),
Operand::MemorySemantics(ref v) => write!(f, "{:?}", v),
Operand::MemoryAccess(ref v) => write!(f, "{:?}", v),
Operand::KernelProfilingInfo(ref v) => write!(f, "{:?}", v),
Operand::RayFlags(ref v) => write!(f, "{:?}", v),
Operand::FragmentShadingRate(ref v) => write!(f, "{:?}", v),
Operand::SourceLanguage(ref v) => write!(f, "{:?}", v),
Operand::ExecutionModel(ref v) => write!(f, "{:?}", v),
Operand::AddressingModel(ref v) => write!(f, "{:?}", v),
Expand Down
2 changes: 1 addition & 1 deletion rspirv/dr/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod tests {
spirv::FunctionControl::INLINE | spirv::FunctionControl::CONST
)
),
"INLINE | CONST",
"FunctionControl(INLINE | CONST)",
);
assert_eq!(format!("{}", dr::Operand::IdRef(3)), "%3");
assert_eq!(format!("{}", dr::Operand::LiteralBit32(3)), "3");
Expand Down
50 changes: 0 additions & 50 deletions spirv/autogen_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,15 @@ pub const MAJOR_VERSION: u8 = 1u8;
pub const MINOR_VERSION: u8 = 6u8;
pub const REVISION: u8 = 1u8;
bitflags! { # [doc = "SPIR-V operand kind: [ImageOperands](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_image_operands_a_image_operands)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct ImageOperands : u32 { const NONE = 0u32 ; const BIAS = 1u32 ; const LOD = 2u32 ; const GRAD = 4u32 ; const CONST_OFFSET = 8u32 ; const OFFSET = 16u32 ; const CONST_OFFSETS = 32u32 ; const SAMPLE = 64u32 ; const MIN_LOD = 128u32 ; const MAKE_TEXEL_AVAILABLE = 256u32 ; const MAKE_TEXEL_AVAILABLE_KHR = 256u32 ; const MAKE_TEXEL_VISIBLE = 512u32 ; const MAKE_TEXEL_VISIBLE_KHR = 512u32 ; const NON_PRIVATE_TEXEL = 1024u32 ; const NON_PRIVATE_TEXEL_KHR = 1024u32 ; const VOLATILE_TEXEL = 2048u32 ; const VOLATILE_TEXEL_KHR = 2048u32 ; const SIGN_EXTEND = 4096u32 ; const ZERO_EXTEND = 8192u32 ; const NONTEMPORAL = 16384u32 ; const OFFSETS = 65536u32 ; } }
impl core::fmt::Display for ImageOperands {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [FPFastMathMode](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_fp_fast_math_mode_a_fp_fast_math_mode)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct FPFastMathMode : u32 { const NONE = 0u32 ; const NOT_NAN = 1u32 ; const NOT_INF = 2u32 ; const NSZ = 4u32 ; const ALLOW_RECIP = 8u32 ; const FAST = 16u32 ; const ALLOW_CONTRACT_FAST_INTEL = 65536u32 ; const ALLOW_REASSOC_INTEL = 131072u32 ; } }
impl core::fmt::Display for FPFastMathMode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [SelectionControl](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_selection_control_a_selection_control)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct SelectionControl : u32 { const NONE = 0u32 ; const FLATTEN = 1u32 ; const DONT_FLATTEN = 2u32 ; } }
impl core::fmt::Display for SelectionControl {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [LoopControl](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_loop_control_a_loop_control)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct LoopControl : u32 { const NONE = 0u32 ; const UNROLL = 1u32 ; const DONT_UNROLL = 2u32 ; const DEPENDENCY_INFINITE = 4u32 ; const DEPENDENCY_LENGTH = 8u32 ; const MIN_ITERATIONS = 16u32 ; const MAX_ITERATIONS = 32u32 ; const ITERATION_MULTIPLE = 64u32 ; const PEEL_COUNT = 128u32 ; const PARTIAL_COUNT = 256u32 ; const INITIATION_INTERVAL_INTEL = 65536u32 ; const MAX_CONCURRENCY_INTEL = 131072u32 ; const DEPENDENCY_ARRAY_INTEL = 262144u32 ; const PIPELINE_ENABLE_INTEL = 524288u32 ; const LOOP_COALESCE_INTEL = 1048576u32 ; const MAX_INTERLEAVING_INTEL = 2097152u32 ; const SPECULATED_ITERATIONS_INTEL = 4194304u32 ; const NO_FUSION_INTEL = 8388608u32 ; const LOOP_COUNT_INTEL = 16777216u32 ; const MAX_REINVOCATION_DELAY_INTEL = 33554432u32 ; } }
impl core::fmt::Display for LoopControl {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [FunctionControl](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_function_control_a_function_control)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct FunctionControl : u32 { const NONE = 0u32 ; const INLINE = 1u32 ; const DONT_INLINE = 2u32 ; const PURE = 4u32 ; const CONST = 8u32 ; const OPT_NONE_INTEL = 65536u32 ; } }
impl core::fmt::Display for FunctionControl {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [MemorySemantics](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_semantics_a_memory_semantics)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct MemorySemantics : u32 { const RELAXED = 0u32 ; const NONE = 0u32 ; const ACQUIRE = 2u32 ; const RELEASE = 4u32 ; const ACQUIRE_RELEASE = 8u32 ; const SEQUENTIALLY_CONSISTENT = 16u32 ; const UNIFORM_MEMORY = 64u32 ; const SUBGROUP_MEMORY = 128u32 ; const WORKGROUP_MEMORY = 256u32 ; const CROSS_WORKGROUP_MEMORY = 512u32 ; const ATOMIC_COUNTER_MEMORY = 1024u32 ; const IMAGE_MEMORY = 2048u32 ; const OUTPUT_MEMORY = 4096u32 ; const OUTPUT_MEMORY_KHR = 4096u32 ; const MAKE_AVAILABLE = 8192u32 ; const MAKE_AVAILABLE_KHR = 8192u32 ; const MAKE_VISIBLE = 16384u32 ; const MAKE_VISIBLE_KHR = 16384u32 ; const VOLATILE = 32768u32 ; } }
impl core::fmt::Display for MemorySemantics {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [MemoryAccess](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_access_a_memory_access)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct MemoryAccess : u32 { const NONE = 0u32 ; const VOLATILE = 1u32 ; const ALIGNED = 2u32 ; const NONTEMPORAL = 4u32 ; const MAKE_POINTER_AVAILABLE = 8u32 ; const MAKE_POINTER_AVAILABLE_KHR = 8u32 ; const MAKE_POINTER_VISIBLE = 16u32 ; const MAKE_POINTER_VISIBLE_KHR = 16u32 ; const NON_PRIVATE_POINTER = 32u32 ; const NON_PRIVATE_POINTER_KHR = 32u32 ; const ALIAS_SCOPE_INTEL_MASK = 65536u32 ; const NO_ALIAS_INTEL_MASK = 131072u32 ; } }
impl core::fmt::Display for MemoryAccess {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [KernelProfilingInfo](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_kernel_profiling_info_a_kernel_profiling_info)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct KernelProfilingInfo : u32 { const NONE = 0u32 ; const CMD_EXEC_TIME = 1u32 ; } }
impl core::fmt::Display for KernelProfilingInfo {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [RayFlags](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_ray_flags_a_ray_flags)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct RayFlags : u32 { const NONE_KHR = 0u32 ; const OPAQUE_KHR = 1u32 ; const NO_OPAQUE_KHR = 2u32 ; const TERMINATE_ON_FIRST_HIT_KHR = 4u32 ; const SKIP_CLOSEST_HIT_SHADER_KHR = 8u32 ; const CULL_BACK_FACING_TRIANGLES_KHR = 16u32 ; const CULL_FRONT_FACING_TRIANGLES_KHR = 32u32 ; const CULL_OPAQUE_KHR = 64u32 ; const CULL_NO_OPAQUE_KHR = 128u32 ; const SKIP_TRIANGLES_KHR = 256u32 ; const SKIP_AAB_BS_KHR = 512u32 ; const FORCE_OPACITY_MICROMAP2_STATE_EXT = 1024u32 ; } }
impl core::fmt::Display for RayFlags {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
bitflags! { # [doc = "SPIR-V operand kind: [FragmentShadingRate](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_fragment_shading_rate_a_fragment_shading_rate)"] # [derive (Clone , Copy , Debug , PartialEq , Eq , Hash)] # [cfg_attr (feature = "serialize" , derive (serde :: Serialize))] # [cfg_attr (feature = "deserialize" , derive (serde :: Deserialize))] pub struct FragmentShadingRate : u32 { const VERTICAL2_PIXELS = 1u32 ; const VERTICAL4_PIXELS = 2u32 ; const HORIZONTAL2_PIXELS = 4u32 ; const HORIZONTAL4_PIXELS = 8u32 ; } }
impl core::fmt::Display for FragmentShadingRate {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(&self.0, f)
}
}
#[doc = "SPIR-V operand kind: [SourceLanguage](https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_source_language_a_source_language)"]
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down

0 comments on commit d5c4c23

Please sign in to comment.