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

Remove errant underscore in AABB abbreviation #255

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 5 additions & 11 deletions autogen/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashSet;
use crate::structs;
use crate::utils::*;

use heck::{ShoutySnakeCase, SnakeCase};
use heck::SnakeCase;
use proc_macro2::{Ident, TokenStream};
use quote::quote;

Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn gen_operand_decode_methods(grammar: &[structs::OperandKind]) -> TokenStre
});

quote! {
impl<'a> Decoder<'a> {
impl Decoder<'_> {
#(#methods)*
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ fn gen_operand_param_parse_methods(grammar: &[structs::OperandKind]) -> Vec<(&st
let decode = get_decode_method(element);
quote! { dr::Operand::#op_kind(self.decoder.#decode()?) }
});
let bit = as_ident(&symbol.to_shouty_snake_case());
let bit = as_ident(&as_shouty_snake_case(symbol));
quote! {
if #lo_kind.contains(spirv::#kind::#bit) {
params.append(&mut vec![#(#params),*]);
Expand Down Expand Up @@ -288,7 +288,7 @@ pub fn gen_operand_parse_methods(grammar: &[structs::OperandKind]) -> TokenStrea
});

quote! {
impl<'c, 'd> Parser<'c, 'd> {
impl Parser<'_, '_> {
fn parse_operand(&mut self, kind: GOpKind) -> Result<Vec<dr::Operand>> {
Ok(match kind {
#(#normal_cases),*,
Expand All @@ -315,13 +315,7 @@ pub fn gen_disas_bit_enum_operands(grammar: &[structs::OperandKind]) -> TokenStr
if enumerant.value == 0x0000 {
None
} else {
let symbol = as_ident(
&enumerant
.symbol
.to_snake_case()
.replace("na_n", "nan")
.to_uppercase(),
);
let symbol = as_ident(&as_shouty_snake_case(&enumerant.symbol));
Some((quote! { #kind::#symbol }, &enumerant.symbol))
}
})
Expand Down
9 changes: 4 additions & 5 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,11 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
let mut seen_discriminator = BTreeMap::new();

for e in enumerators {
if seen_discriminator.get(&e.value).is_none() {
use std::collections::btree_map::Entry;
if let Entry::Vacant(ve) = seen_discriminator.entry(e.value) {
let name = match category {
structs::Category::BitEnum => {
use heck::ShoutySnakeCase;

as_ident(&e.symbol.to_shouty_snake_case().replace("NA_N", "NAN"))
as_ident(&as_shouty_snake_case(&e.symbol))
}
structs::Category::ValueEnum => {
let name_str = if kind == "Dim" {
Expand All @@ -412,7 +411,7 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
_ => panic!("Unexpected operand type"),
};

seen_discriminator.insert(e.value, name.clone());
ve.insert(name.clone());

capability_clauses
.entry(&e.capabilities)
Expand Down
10 changes: 2 additions & 8 deletions autogen/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::structs;
use crate::utils::*;

use heck::{ShoutySnakeCase, SnakeCase};
use heck::SnakeCase;
use proc_macro2::TokenStream;
use quote::quote;
use std::cmp::Ordering;
Expand Down Expand Up @@ -102,13 +102,7 @@ fn gen_bit_enum_operand_kind(grammar: &structs::OperandKind) -> TokenStream {
let mut additional_operands_list = vec![];

for enumerant in grammar.enumerants.iter() {
// Special treatment for "NaN"
let symbol = as_ident(
&enumerant
.symbol
.to_shouty_snake_case()
.replace("NA_N", "NAN"),
);
let symbol = as_ident(&as_shouty_snake_case(&enumerant.symbol));
let value = enumerant.value;

elements.push(quote! {
Expand Down
3 changes: 2 additions & 1 deletion autogen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ mod table;
mod utils;

use std::{
env, fs,
env,
fs,
io::{Read, Write},
path::{Path, PathBuf},
process,
Expand Down
5 changes: 4 additions & 1 deletion autogen/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct Enumerant {
}

#[derive(Debug, Deserialize, Clone)]
#[allow(dead_code)]
pub struct OperandKind {
pub category: Category,
pub kind: String,
Expand All @@ -53,6 +54,7 @@ pub struct OperandKind {

#[derive(Debug, Deserialize)]
pub struct Grammar {
#[allow(dead_code)]
pub copyright: Vec<String>,
#[serde(deserialize_with = "num_or_hex")]
pub magic_number: u32,
Expand All @@ -64,6 +66,7 @@ pub struct Grammar {
}

#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct ExtInstSetGrammar {
pub copyright: Vec<String>,
pub version: u32,
Expand All @@ -74,7 +77,7 @@ pub struct ExtInstSetGrammar {
fn num_or_hex<'de, D: de::Deserializer<'de>>(d: D) -> result::Result<u32, D::Error> {
struct NumOrStr;

impl<'de> de::Visitor<'de> for NumOrStr {
impl de::Visitor<'_> for NumOrStr {
type Value = u32;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
11 changes: 10 additions & 1 deletion autogen/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::structs;
use std::fs;
use std::io::Write;

use heck::SnakeCase;
use heck::{ShoutySnakeCase, SnakeCase};
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;

Expand All @@ -23,6 +23,15 @@ pub fn as_ident(ident: &str) -> Ident {
Ident::new(ident, Span::call_site())
}

/// Returns an automatic conversion of the identifier to SHOUTY_SNAKE_CASE,
/// correcting known abbreviations as needed.
pub fn as_shouty_snake_case(ident: &str) -> String {
ident
.to_shouty_snake_case()
.replace("AAB_BS", "AABBS") // "AABBs"
.replace("NA_N", "NAN") // "NaN"
}

/// Returns the corresponding operand kind in data representation for the
/// given operand `kind` in the grammar.
pub fn get_dr_operand_kind(kind: &str) -> Ident {
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/autogen_decode_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// external/spirv.core.grammar.json.
// DO NOT MODIFY!

impl<'a> Decoder<'a> {
impl Decoder<'_> {
#[doc = "Decodes and returns the next SPIR-V word as\na SPIR-V ImageOperands value."]
pub fn image_operands(&mut self) -> Result<spirv::ImageOperands> {
if let Ok(word) = self.word() {
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/autogen_disas_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Disassemble for spirv::RayFlags {
if self.contains(spirv::RayFlags::SKIP_TRIANGLES_KHR) {
bits.push("SkipTrianglesKHR")
}
if self.contains(spirv::RayFlags::SKIP_AAB_BS_KHR) {
if self.contains(spirv::RayFlags::SKIP_AABBS_KHR) {
bits.push("SkipAABBsKHR")
}
if self.contains(spirv::RayFlags::FORCE_OPACITY_MICROMAP2_STATE_EXT) {
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/autogen_parse_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// external/spirv.core.grammar.json.
// DO NOT MODIFY!

impl<'c, 'd> Parser<'c, 'd> {
impl Parser<'_, '_> {
fn parse_operand(&mut self, kind: GOpKind) -> Result<Vec<dr::Operand>> {
Ok(match kind {
GOpKind::FPFastMathMode => vec![dr::Operand::FPFastMathMode(
Expand Down
4 changes: 2 additions & 2 deletions rspirv/binary/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a> Decoder<'a> {
}
}

impl<'a> Decoder<'a> {
impl Decoder<'_> {
/// Sets the limit to `num_words` words.
///
/// The decoder will return [`State::LimitReached`](enum.ParseState.html)
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<'a> Decoder<'a> {
}
}

impl<'a> Decoder<'a> {
impl Decoder<'_> {
/// Decodes and returns the next SPIR-V word as an id.
pub fn id(&mut self) -> Result<spirv::Word> {
self.word()
Expand Down
2 changes: 1 addition & 1 deletion rspirv/binary/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ExtInstSetTracker {
/// Returns true if the given extended instruction `set` has been
/// recognized thus tracked.
pub fn have(&self, set: spirv::Word) -> bool {
self.sets.get(&set).is_some()
self.sets.contains_key(&set)
}

/// Resolves the extended instruction with `opcode` in set `set`.
Expand Down
2 changes: 1 addition & 1 deletion rspirv/dr/autogen_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl Operand {
if v.intersects(s::RayFlags::FORCE_OPACITY_MICROMAP2_STATE_EXT) {
result.extend_from_slice(&[spirv::Capability::RayTracingOpacityMicromapEXT])
};
if v.intersects(s::RayFlags::SKIP_TRIANGLES_KHR | s::RayFlags::SKIP_AAB_BS_KHR) {
if v.intersects(s::RayFlags::SKIP_TRIANGLES_KHR | s::RayFlags::SKIP_AABBS_KHR) {
result.extend_from_slice(&[spirv::Capability::RayTraversalPrimitiveCullingKHR])
};
result
Expand Down
8 changes: 4 additions & 4 deletions rspirv/sr/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ mod tests {
#[test]
fn append_unique() {
let mut storage: Storage<f64> = Storage::new();
let t1 = storage.append(std::f64::NAN);
let t2 = storage.append(std::f64::NAN);
let t1 = storage.append(f64::NAN);
let t2 = storage.append(f64::NAN);
assert!(t1 != t2);
assert!(storage[t1] != storage[t2]);
}
Expand All @@ -130,8 +130,8 @@ mod tests {
#[test]
fn fetch_or_append_unique() {
let mut storage: Storage<f64> = Storage::new();
let t1 = storage.fetch_or_append(std::f64::NAN);
let t2 = storage.fetch_or_append(std::f64::NAN);
let t1 = storage.fetch_or_append(f64::NAN);
let t2 = storage.fetch_or_append(f64::NAN);
assert!(t1 != t2);
assert!(storage[t1] != storage[t2]);
}
Expand Down
3 changes: 2 additions & 1 deletion rspirv/tests/spirv_blobs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rspirv::{
binary::{Assemble as _, Disassemble as _},
dr, lift,
dr,
lift,
};

use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion spirv/autogen_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bitflags! { # [doc = "SPIR-V operand kind: [FunctionControl](https://www.khronos
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 ; } }
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 ; } }
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 ; } }
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 ; } }
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_AABBS_KHR = 512u32 ; const FORCE_OPACITY_MICROMAP2_STATE_EXT = 1024u32 ; } }
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 ; } }
#[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)]
Expand Down