Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address CI failures and pretty-print bit enum operands #247

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions autogen/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStrea
// Logic operands that expand to concrete operand pairs,
// that is, those operand kinds with 'Pair' name prefix.
// We only have two cases. So hard code it.
let pair_kinds = vec![("IdRef", "LiteralInteger"), ("IdRef", "IdRef")];
let pair_kinds = [("IdRef", "LiteralInteger"), ("IdRef", "IdRef")];
let pair_cases = pair_kinds.iter().map(|&(k0, k1)| {
let kind = as_ident(&format!("Pair{}{}", k0, k1));
let kind0 = get_dr_operand_kind(k0);
Expand All @@ -253,7 +253,7 @@ pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStrea
});

// These kinds are manually handled.
let manual_kinds = vec![
let manual_kinds = [
"IdResultType",
"IdResult",
"LiteralContextDependentNumber",
Expand Down
49 changes: 26 additions & 23 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,25 @@ 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 kinds: Vec<_> = grammar
let kind_and_category: 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`.
!(element.starts_with("Pair")
!(kind.starts_with("Pair")
|| matches!(
*element,
kind,
"LiteralContextDependentNumber"
| "LiteralInteger"
| "IdResult"
| "IdResultType"
))
})
.map(as_ident)
.map(|element| (as_ident(element.kind.as_str()), element.category))
.collect();

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

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

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

let str_kinds = kinds
let str_kinds = kind_and_category
.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 = kinds
let enum_kinds = kind_and_category
.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)
.chain(num_kinds.into_iter())
.chain(num_kinds)
.chain(str_kinds)
.collect::<Vec<_>>()
};
Expand Down Expand Up @@ -332,14 +333,12 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {

let impl_code = {
// impl fmt::Display for dr::Operand.
let mut kinds = kinds;
kinds.extend(
["LiteralBit32", "LiteralBit64"]
.iter()
.cloned()
.map(as_ident),
);
let cases = kinds.iter().map(|element| {
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)| {
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 @@ -351,6 +350,10 @@ 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: 6 additions & 0 deletions autogen/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ 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
6 changes: 4 additions & 2 deletions rspirv/dr/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,11 @@ mod tests {
assert_eq!(
format!(
"{}",
dr::Operand::FunctionControl(spirv::FunctionControl::INLINE)
dr::Operand::FunctionControl(
spirv::FunctionControl::INLINE | spirv::FunctionControl::CONST
)
),
"INLINE",
"INLINE | CONST",
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved
);
assert_eq!(format!("{}", dr::Operand::IdRef(3)), "%3");
assert_eq!(format!("{}", dr::Operand::LiteralBit32(3)), "3");
Expand Down
6 changes: 5 additions & 1 deletion rspirv/lift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ impl LiftContext {
let start_label = fun.blocks[0].label.as_ref().unwrap().result_id.unwrap();
let start_block = context.blocks.lookup_token(start_label);
let blocks = mem::replace(&mut context.blocks, LiftStorage::new()).unwrap();
let fun_ret = fun.def.as_ref().and_then(|d| d.result_type).expect("functions must have a result type");
let fun_ret = fun
.def
.as_ref()
.and_then(|d| d.result_type)
.expect("functions must have a result type");

functions.push(module::Function {
control: def.function_control,
Expand Down
5 changes: 1 addition & 4 deletions rspirv/sr/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub struct Token<T> {

impl<T> Clone for Token<T> {
fn clone(&self) -> Self {
Token {
index: self.index,
marker: self.marker,
}
*self
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved
}
}
impl<T> Copy for Token<T> {}
Expand Down
50 changes: 50 additions & 0 deletions spirv/autogen_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,65 @@ 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
Loading