Make scalar_width return size in bytes (#5532)

This commit is contained in:
vero 2024-04-15 11:05:42 -07:00 committed by GitHub
parent c9212c6d46
commit c6efbef8a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 9 deletions

View File

@ -3418,7 +3418,8 @@ impl<'a, W: Write> Writer<'a, W> {
let scalar_bits = ctx
.resolve_type(arg, &self.module.types)
.scalar_width()
.unwrap();
.unwrap()
* 8;
write!(self.out, "bitfieldExtract(")?;
self.write_expr(arg, ctx)?;
@ -3437,7 +3438,8 @@ impl<'a, W: Write> Writer<'a, W> {
let scalar_bits = ctx
.resolve_type(arg, &self.module.types)
.scalar_width()
.unwrap();
.unwrap()
* 8;
write!(self.out, "bitfieldInsert(")?;
self.write_expr(arg, ctx)?;

View File

@ -2593,7 +2593,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
true
}
None => {
if inner.scalar_width() == Some(64) {
if inner.scalar_width() == Some(8) {
false
} else {
write!(self.out, "{}(", kind.to_hlsl_cast(),)?;

View File

@ -1945,7 +1945,7 @@ impl<W: Write> Writer<W> {
//
// extract_bits(e, min(offset, w), min(count, w - min(offset, w))))
let scalar_bits = context.resolve_type(arg).scalar_width().unwrap();
let scalar_bits = context.resolve_type(arg).scalar_width().unwrap() * 8;
write!(self.out, "{NAMESPACE}::extract_bits(")?;
self.put_expression(arg, context, true)?;
@ -1961,7 +1961,7 @@ impl<W: Write> Writer<W> {
//
// insertBits(e, newBits, min(offset, w), min(count, w - min(offset, w))))
let scalar_bits = context.resolve_type(arg).scalar_width().unwrap();
let scalar_bits = context.resolve_type(arg).scalar_width().unwrap() * 8;
write!(self.out, "{NAMESPACE}::insert_bits(")?;
self.put_expression(arg, context, true)?;

View File

@ -1073,7 +1073,7 @@ impl<'w> BlockContext<'w> {
//
// bitfieldExtract(x, o, c)
let bit_width = arg_ty.scalar_width().unwrap();
let bit_width = arg_ty.scalar_width().unwrap() * 8;
let width_constant = self
.writer
.get_constant_scalar(crate::Literal::U32(bit_width as u32));
@ -1129,7 +1129,7 @@ impl<'w> BlockContext<'w> {
Mf::InsertBits => {
// The behavior of InsertBits has the same undefined behavior as ExtractBits.
let bit_width = arg_ty.scalar_width().unwrap();
let bit_width = arg_ty.scalar_width().unwrap() * 8;
let width_constant = self
.writer
.get_constant_scalar(crate::Literal::U32(bit_width as u32));
@ -1185,7 +1185,7 @@ impl<'w> BlockContext<'w> {
}
Mf::FindLsb => MathOp::Ext(spirv::GLOp::FindILsb),
Mf::FindMsb => {
if arg_ty.scalar_width() == Some(32) {
if arg_ty.scalar_width() == Some(4) {
let thing = match arg_scalar_kind {
Some(crate::ScalarKind::Uint) => spirv::GLOp::FindUMsb,
Some(crate::ScalarKind::Sint) => spirv::GLOp::FindSMsb,

View File

@ -279,8 +279,9 @@ impl super::TypeInner {
self.scalar().map(|scalar| scalar.kind)
}
/// Returns the scalar width in bytes
pub fn scalar_width(&self) -> Option<u8> {
self.scalar().map(|scalar| scalar.width * 8)
self.scalar().map(|scalar| scalar.width)
}
pub const fn pointer_space(&self) -> Option<crate::AddressSpace> {