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

WIP: VK_EXT_mesh_shader #1019

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
38 changes: 14 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ license.workspace = true
repository.workspace = true

[dependencies]
rspirv = "0.11"
rspirv = { git = "https://github.com/beastle9end/rspirv" }
serde = { version = "1.0", features = ["derive"] }
4 changes: 2 additions & 2 deletions crates/rustc_codegen_spirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ regex = { version = "1", features = ["perf"] }
ar = "0.9.0"
either = "1.8.0"
indexmap = "1.6.0"
rspirv = "0.11"
rspirv = { git = "https://github.com/beastle9end/rspirv" }
rustc-demangle = "0.1.21"
sanitize-filename = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smallvec = { version = "1.6.1", features = ["union"] }
spirv-tools = { version = "0.9", default-features = false }
rustc_codegen_spirv-types.workspace = true
spirt = "0.1.0"
spirt = { git = "https://github.com/projectkml/spirt" }
lazy_static = "1.4.0"

[dev-dependencies]
Expand Down
30 changes: 26 additions & 4 deletions crates/rustc_codegen_spirv/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::attr::{AggregatedSpirvAttributes, IntrinsicType};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use rspirv::spirv::{StorageClass, Word};
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::ErrorGuaranteed;
use rustc_index::vec::Idx;
Expand All @@ -28,8 +28,6 @@ use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::fmt;

use num_traits::cast::FromPrimitive;

pub(crate) fn provide(providers: &mut Providers) {
// This is a lil weird: so, we obviously don't support C ABIs at all. However, libcore does declare some extern
// C functions:
Expand Down Expand Up @@ -858,7 +856,31 @@ fn trans_intrinsic_type<'tcx>(
// let image_format: spirv::ImageFormat =
// type_from_variant_discriminant(cx, substs.const_at(6));

fn const_int_value<'tcx, P: FromPrimitive>(
trait FromU128 {
fn from_u128(value: u128) -> Option<Self>
where
Self: Sized;
}

impl FromU128 for Dim {
fn from_u128(value: u128) -> Option<Self> {
Self::from_u32(value.try_into().ok()?)
}
}

impl FromU128 for u32 {
fn from_u128(value: u128) -> Option<Self> {
value.try_into().ok()
}
}

impl FromU128 for ImageFormat {
fn from_u128(value: u128) -> Option<Self> {
Self::from_u32(value.try_into().ok()?)
}
}

fn const_int_value<'tcx, P: FromU128>(
cx: &CodegenCx<'tcx>,
const_: Const<'tcx>,
) -> Result<P, ErrorGuaranteed> {
Expand Down
12 changes: 6 additions & 6 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
))
} else if signed {
// this cast chain can probably be collapsed, but, whatever, be safe
Operand::LiteralInt32(v as u8 as i8 as i32 as u32)
Operand::LiteralBit32(v as u8 as i8 as i32 as u32)
} else {
Operand::LiteralInt32(v as u8 as u32)
Operand::LiteralBit32(v as u8 as u32)
}
}
fn construct_16(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand {
Expand All @@ -736,9 +736,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u16::MAX not supported: {v:?}"
))
} else if signed {
Operand::LiteralInt32(v as u16 as i16 as i32 as u32)
Operand::LiteralBit32(v as u16 as i16 as i32 as u32)
} else {
Operand::LiteralInt32(v as u16 as u32)
Operand::LiteralBit32(v as u16 as u32)
}
}
fn construct_32(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
Expand All @@ -747,7 +747,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u32::MAX not supported: {v:?}"
))
} else {
Operand::LiteralInt32(v as u32)
Operand::LiteralBit32(v as u32)
}
}
fn construct_64(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand {
Expand All @@ -756,7 +756,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
"Switches to values above u64::MAX not supported: {v:?}"
))
} else {
Operand::LiteralInt64(v as u64)
Operand::LiteralBit64(v as u64)
}
}
// pass in signed into the closure to be able to unify closure types
Expand Down
64 changes: 42 additions & 22 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,25 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Op::TypeVoid => SpirvType::Void.def(self.span(), self),
Op::TypeBool => SpirvType::Bool.def(self.span(), self),
Op::TypeInt => SpirvType::Integer(
inst.operands[0].unwrap_literal_int32(),
inst.operands[1].unwrap_literal_int32() != 0,
inst.operands[0].unwrap_literal_bit32(),
inst.operands[1].unwrap_literal_bit32() != 0,
)
.def(self.span(), self),
Op::TypeFloat => {
SpirvType::Float(inst.operands[0].unwrap_literal_int32()).def(self.span(), self)
SpirvType::Float(inst.operands[0].unwrap_literal_bit32()).def(self.span(), self)
}
Op::TypeStruct => {
self.err("OpTypeStruct in asm! is not supported yet");
return;
}
Op::TypeVector => SpirvType::Vector {
element: inst.operands[0].unwrap_id_ref(),
count: inst.operands[1].unwrap_literal_int32(),
count: inst.operands[1].unwrap_literal_bit32(),
}
.def(self.span(), self),
Op::TypeMatrix => SpirvType::Matrix {
element: inst.operands[0].unwrap_id_ref(),
count: inst.operands[1].unwrap_literal_int32(),
count: inst.operands[1].unwrap_literal_bit32(),
}
.def(self.span(), self),
Op::TypeArray => {
Expand Down Expand Up @@ -322,10 +322,10 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Op::TypeImage => SpirvType::Image {
sampled_type: inst.operands[0].unwrap_id_ref(),
dim: inst.operands[1].unwrap_dim(),
depth: inst.operands[2].unwrap_literal_int32(),
arrayed: inst.operands[3].unwrap_literal_int32(),
multisampled: inst.operands[4].unwrap_literal_int32(),
sampled: inst.operands[5].unwrap_literal_int32(),
depth: inst.operands[2].unwrap_literal_bit32(),
arrayed: inst.operands[3].unwrap_literal_bit32(),
multisampled: inst.operands[4].unwrap_literal_bit32(),
sampled: inst.operands[5].unwrap_literal_bit32(),
image_format: inst.operands[6].unwrap_image_format(),
}
.def(self.span(), self),
Expand Down Expand Up @@ -694,7 +694,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
let index_to_usize = || match *index {
// FIXME(eddyb) support more than just literals,
// by looking up `IdRef`s as constant integers.
dr::Operand::LiteralInt32(i) => usize::try_from(i).ok(),
dr::Operand::LiteralBit32(i) => usize::try_from(i).ok(),

_ => None,
};
Expand Down Expand Up @@ -1075,7 +1075,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}

(OperandKind::LiteralInteger, Some(word)) => match word.parse() {
Ok(v) => inst.operands.push(dr::Operand::LiteralInt32(v)),
Ok(v) => inst.operands.push(dr::Operand::LiteralBit32(v)),
Err(e) => self.err(&format!("invalid integer: {e}")),
},
(OperandKind::LiteralString, _) => {
Expand All @@ -1092,34 +1092,34 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
Ok(match ty {
SpirvType::Integer(8, false) => {
dr::Operand::LiteralInt32(w.parse::<u8>().map_err(fmt)? as u32)
dr::Operand::LiteralBit32(w.parse::<u8>().map_err(fmt)? as u32)
}
SpirvType::Integer(16, false) => {
dr::Operand::LiteralInt32(w.parse::<u16>().map_err(fmt)? as u32)
dr::Operand::LiteralBit32(w.parse::<u16>().map_err(fmt)? as u32)
}
SpirvType::Integer(32, false) => {
dr::Operand::LiteralInt32(w.parse::<u32>().map_err(fmt)?)
dr::Operand::LiteralBit32(w.parse::<u32>().map_err(fmt)?)
}
SpirvType::Integer(64, false) => {
dr::Operand::LiteralInt64(w.parse::<u64>().map_err(fmt)?)
dr::Operand::LiteralBit64(w.parse::<u64>().map_err(fmt)?)
}
SpirvType::Integer(8, true) => {
dr::Operand::LiteralInt32(w.parse::<i8>().map_err(fmt)? as i32 as u32)
dr::Operand::LiteralBit32(w.parse::<i8>().map_err(fmt)? as i32 as u32)
}
SpirvType::Integer(16, true) => {
dr::Operand::LiteralInt32(w.parse::<i16>().map_err(fmt)? as i32 as u32)
dr::Operand::LiteralBit32(w.parse::<i16>().map_err(fmt)? as i32 as u32)
}
SpirvType::Integer(32, true) => {
dr::Operand::LiteralInt32(w.parse::<i32>().map_err(fmt)? as u32)
dr::Operand::LiteralBit32(w.parse::<i32>().map_err(fmt)? as u32)
}
SpirvType::Integer(64, true) => {
dr::Operand::LiteralInt64(w.parse::<i64>().map_err(fmt)? as u64)
dr::Operand::LiteralBit64(w.parse::<i64>().map_err(fmt)? as u64)
}
SpirvType::Float(32) => {
dr::Operand::LiteralFloat32(w.parse::<f32>().map_err(fmt)?)
dr::Operand::LiteralBit32(w.parse::<f32>().map_err(fmt)?.to_bits())
}
SpirvType::Float(64) => {
dr::Operand::LiteralFloat64(w.parse::<f64>().map_err(fmt)?)
dr::Operand::LiteralBit64(w.parse::<f64>().map_err(fmt)?.to_bits())
}
_ => return Err("expected number literal in OpConstant".to_string()),
})
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
inst.operands.push(dr::Operand::IdRef(id));
match tokens.next() {
Some(Token::Word(word)) => match word.parse() {
Ok(v) => inst.operands.push(dr::Operand::LiteralInt32(v)),
Ok(v) => inst.operands.push(dr::Operand::LiteralBit32(v)),
Err(e) => {
self.err(&format!("invalid integer: {e}"));
}
Expand Down Expand Up @@ -1355,6 +1355,26 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
.push(dr::Operand::RayQueryCandidateIntersectionType(x)),
Err(()) => self.err(&format!("unknown RayQueryCandidateIntersectionType {word}")),
},
(OperandKind::FPDenormMode, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::FPDenormMode(x)),
Err(()) => self.err(&format!("unknown FPDenormMode {word}")),
},
(OperandKind::QuantizationModes, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::QuantizationModes(x)),
Err(()) => self.err(&format!("unknown QuantizationModes {word}")),
},
(OperandKind::FPOperationMode, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::FPOperationMode(x)),
Err(()) => self.err(&format!("unknown FPOperationMode {word}")),
},
(OperandKind::OverflowModes, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::OverflowModes(x)),
Err(()) => self.err(&format!("unknown OverflowModes {word}")),
},
(OperandKind::PackedVectorFormat, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::PackedVectorFormat(x)),
Err(()) => self.err(&format!("unknown PackedVectorFormat {word}")),
},
(kind, None) => match token {
Token::Word(_) => bug!(),
Token::String(_) => {
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/builder_spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ impl<'tcx> BuilderSpirv<'tcx> {
}
let val = val_with_type.val;
let id = match val {
SpirvConst::U32(v) => builder.constant_u32(ty, v),
SpirvConst::U64(v) => builder.constant_u64(ty, v),
SpirvConst::F32(v) => builder.constant_f32(ty, f32::from_bits(v)),
SpirvConst::F64(v) => builder.constant_f64(ty, f64::from_bits(v)),
SpirvConst::U32(v) => builder.constant_bit32(ty, v),
SpirvConst::U64(v) => builder.constant_bit64(ty, v),
SpirvConst::F32(v) => builder.constant_bit32(ty, v),
SpirvConst::F64(v) => builder.constant_bit64(ty, v),
SpirvConst::Bool(v) => {
if v {
builder.constant_true(ty)
Expand Down
8 changes: 4 additions & 4 deletions crates/rustc_codegen_spirv/src/codegen_cx/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,15 @@ impl<'tcx> CodegenCx<'tcx> {
self.emit_global().decorate(
var,
Decoration::DescriptorSet,
std::iter::once(Operand::LiteralInt32(index)),
std::iter::once(Operand::LiteralBit32(index)),
);
decoration_supersedes_location = true;
}
if let Some(index) = attrs.binding.map(|attr| attr.value) {
self.emit_global().decorate(
var,
Decoration::Binding,
std::iter::once(Operand::LiteralInt32(index)),
std::iter::once(Operand::LiteralBit32(index)),
);
decoration_supersedes_location = true;
}
Expand Down Expand Up @@ -633,7 +633,7 @@ impl<'tcx> CodegenCx<'tcx> {
self.emit_global().decorate(
var,
Decoration::InputAttachmentIndex,
std::iter::once(Operand::LiteralInt32(attachment_index.value)),
std::iter::once(Operand::LiteralBit32(attachment_index.value)),
);
} else if is_subpass_input {
self.tcx
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'tcx> CodegenCx<'tcx> {
self.emit_global().decorate(
var,
Decoration::Location,
std::iter::once(Operand::LiteralInt32(*location)),
std::iter::once(Operand::LiteralBit32(*location)),
);
*location += 1;
}
Expand Down
Loading