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

Store floats as bits #237

Merged
merged 1 commit into from
Oct 6, 2022
Merged
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
2 changes: 1 addition & 1 deletion autogen/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn get_decode_method(kind: &str) -> Ident {
if kind.starts_with("Literal") {
kind = &kind["Literal".len()..];
if kind == "Integer" {
return as_ident("int32");
return as_ident("bit32");
}
}
as_ident(&kind.to_snake_case())
Expand Down
25 changes: 9 additions & 16 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn get_push_extras(
Some(quote! {
for v in #name {
#container.push(dr::Operand::IdRef(v.0));
#container.push(dr::Operand::LiteralInt32(v.1));
#container.push(dr::Operand::LiteralBit32(v.1));
}
})
} else if param.kind == "PairIdRefIdRef" {
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
.filter(|element| {
// Pair kinds are not used in dr::Operand.
// LiteralContextDependentNumber is replaced by suitable literals.
// LiteralInteger is replaced by LiteralInt32.
// LiteralInteger is replaced by LiteralBit32.
// IdResult and IdResultType are not stored as operands in `dr`.
!(element.starts_with("Pair")
|| matches!(
Expand Down Expand Up @@ -254,10 +254,8 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
.map(|element| (element.clone(), quote! { spirv::Word }));

let num_kinds = vec![
(format_ident!("LiteralInt32"), quote! {u32}),
(format_ident!("LiteralInt64"), quote! {u64}),
(format_ident!("LiteralFloat32"), quote! {f32}),
(format_ident!("LiteralFloat64"), quote! {f64}),
(format_ident!("LiteralBit32"), quote! {u32}),
(format_ident!("LiteralBit64"), quote! {u64}),
(format_ident!("LiteralExtInstInteger"), quote! {u32}),
(
format_ident!("LiteralSpecConstantOpInteger"),
Expand Down Expand Up @@ -310,7 +308,7 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
});
quote! {
#[doc = "Data representation of a SPIR-V operand."]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(clippy::upper_case_acronyms)]
pub enum Operand {
#(#kinds,)*
Expand All @@ -336,15 +334,10 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
// impl fmt::Display for dr::Operand.
let mut kinds = kinds;
kinds.extend(
[
"LiteralInt32",
"LiteralInt64",
"LiteralFloat32",
"LiteralFloat64",
]
.iter()
.cloned()
.map(as_ident),
["LiteralBit32", "LiteralBit64"]
.iter()
.cloned()
.map(as_ident),
);
let cases = kinds.iter().map(|element| {
if element == "Dim" {
Expand Down
6 changes: 3 additions & 3 deletions autogen/src/sr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl OperandTokens {
"LiteralInteger" => (
quote! { u32 },
quote! { *value },
OperandTy::Single("LiteralInt32"),
OperandTy::Single("LiteralBit32"),
),
"LiteralExtInstInteger" => (
quote! { u32 },
Expand All @@ -134,7 +134,7 @@ impl OperandTokens {
quote! { (u32, Jump) },
quote! { (first, self.lookup_jump(second)) },
OperandTy::Pair {
first: "LiteralInt32",
first: "LiteralBit32",
second: "IdRef",
},
),
Expand All @@ -143,7 +143,7 @@ impl OperandTokens {
quote! { (self.lookup_jump(first), second) },
OperandTy::Pair {
first: "IdRef",
second: "LiteralInt32",
second: "LiteralBit32",
},
),
"PairIdRefIdRef" => (
Expand Down
2 changes: 1 addition & 1 deletion autogen/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn get_dr_operand_kind(kind: &str) -> Ident {
as_ident(
if matches!(kind, "LiteralInteger" | "LiteralContextDependentNumber") {
// TODO: LiteralContextDependentNumber should use the correct type to decode
"LiteralInt32"
"LiteralBit32"
} else {
kind
},
Expand Down
10 changes: 3 additions & 7 deletions rspirv/binary/assemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ impl Assemble for dr::Operand {
Self::IdMemorySemantics(v)
| Self::IdScope(v)
| Self::IdRef(v)
| Self::LiteralInt32(v)
| Self::LiteralBit32(v)
| Self::LiteralExtInstInteger(v) => result.push(v),
Self::LiteralInt64(v) => result.extend([v as u32, (v >> 32) as u32]),
Self::LiteralFloat32(v) => result.push(v.to_bits()),
Self::LiteralFloat64(v) => {
result.extend([v.to_bits() as u32, (v.to_bits() >> 32) as u32])
}
Self::LiteralBit64(v) => result.extend([v as u32, (v >> 32) as u32]),
Self::LiteralSpecConstantOpInteger(v) => result.push(v as u32),
Self::LiteralString(ref v) => assemble_str(v, result),
Self::RayFlags(ref v) => result.push(v.bits()),
Expand Down Expand Up @@ -255,7 +251,7 @@ mod tests {
// No result type, having result id
#[test]
fn test_assemble_inst_type_int() {
let operands = vec![dr::Operand::LiteralInt32(32), dr::Operand::LiteralInt32(1)];
let operands = vec![dr::Operand::LiteralBit32(32), dr::Operand::LiteralBit32(1)];
assert_eq!(
vec![wc_op(4, spirv::Op::TypeInt), 42, 32, 1],
dr::Instruction::new(spirv::Op::TypeInt, None, Some(42), operands).assemble()
Expand Down
Loading