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

Make scalar_width return size in bytes #5532

Merged
merged 3 commits into from
Apr 15, 2024
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
6 changes: 4 additions & 2 deletions naga/src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion naga/src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),)?;
Expand Down
4 changes: 2 additions & 2 deletions naga/src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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)?;
Expand Down
6 changes: 3 additions & 3 deletions naga/src/back/spv/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion naga/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
Loading