mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[spv] Fix OpImageQueries to allow Uints (#2404)
This commit is contained in:
committed by
GitHub
parent
bac2d82a43
commit
5f8e4f6dea
@@ -1045,7 +1045,7 @@ impl<'w> BlockContext<'w> {
|
||||
};
|
||||
let extended_size_type_id = self.get_type_id(LookupType::Local(LocalType::Value {
|
||||
vector_size,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}));
|
||||
@@ -1077,24 +1077,7 @@ impl<'w> BlockContext<'w> {
|
||||
}
|
||||
block.body.push(inst);
|
||||
|
||||
let bitcast_type_id = self.get_type_id(
|
||||
LocalType::Value {
|
||||
vector_size,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
let bitcast_id = self.gen_id();
|
||||
block.body.push(Instruction::unary(
|
||||
spirv::Op::Bitcast,
|
||||
bitcast_type_id,
|
||||
bitcast_id,
|
||||
id_extended,
|
||||
));
|
||||
|
||||
if result_type_id != bitcast_type_id {
|
||||
if result_type_id != extended_size_type_id {
|
||||
let id = self.gen_id();
|
||||
let components = match dim {
|
||||
// always pick the first component, and duplicate it for all 3 dimensions
|
||||
@@ -1104,42 +1087,26 @@ impl<'w> BlockContext<'w> {
|
||||
block.body.push(Instruction::vector_shuffle(
|
||||
result_type_id,
|
||||
id,
|
||||
bitcast_id,
|
||||
bitcast_id,
|
||||
id_extended,
|
||||
id_extended,
|
||||
components,
|
||||
));
|
||||
|
||||
id
|
||||
} else {
|
||||
bitcast_id
|
||||
id_extended
|
||||
}
|
||||
}
|
||||
Iq::NumLevels => {
|
||||
let query_id = self.gen_id();
|
||||
block.body.push(Instruction::image_query(
|
||||
spirv::Op::ImageQueryLevels,
|
||||
self.get_type_id(
|
||||
LocalType::Value {
|
||||
vector_size: None,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
result_type_id,
|
||||
query_id,
|
||||
image_id,
|
||||
));
|
||||
|
||||
let id = self.gen_id();
|
||||
block.body.push(Instruction::unary(
|
||||
spirv::Op::Bitcast,
|
||||
result_type_id,
|
||||
id,
|
||||
query_id,
|
||||
));
|
||||
|
||||
id
|
||||
query_id
|
||||
}
|
||||
Iq::NumLayers => {
|
||||
let vec_size = match dim {
|
||||
@@ -1149,7 +1116,7 @@ impl<'w> BlockContext<'w> {
|
||||
};
|
||||
let extended_size_type_id = self.get_type_id(LookupType::Local(LocalType::Value {
|
||||
vector_size: Some(vec_size),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
kind: crate::ScalarKind::Uint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}));
|
||||
@@ -1165,56 +1132,24 @@ impl<'w> BlockContext<'w> {
|
||||
|
||||
let extract_id = self.gen_id();
|
||||
block.body.push(Instruction::composite_extract(
|
||||
self.get_type_id(
|
||||
LocalType::Value {
|
||||
vector_size: None,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
result_type_id,
|
||||
extract_id,
|
||||
id_extended,
|
||||
&[vec_size as u32 - 1],
|
||||
));
|
||||
|
||||
let id = self.gen_id();
|
||||
block.body.push(Instruction::unary(
|
||||
spirv::Op::Bitcast,
|
||||
result_type_id,
|
||||
id,
|
||||
extract_id,
|
||||
));
|
||||
|
||||
id
|
||||
extract_id
|
||||
}
|
||||
Iq::NumSamples => {
|
||||
let query_id = self.gen_id();
|
||||
block.body.push(Instruction::image_query(
|
||||
spirv::Op::ImageQuerySamples,
|
||||
self.get_type_id(
|
||||
LocalType::Value {
|
||||
vector_size: None,
|
||||
kind: crate::ScalarKind::Sint,
|
||||
width: 4,
|
||||
pointer_space: None,
|
||||
}
|
||||
.into(),
|
||||
),
|
||||
result_type_id,
|
||||
query_id,
|
||||
image_id,
|
||||
));
|
||||
|
||||
let id = self.gen_id();
|
||||
block.body.push(Instruction::unary(
|
||||
spirv::Op::Bitcast,
|
||||
result_type_id,
|
||||
id,
|
||||
query_id,
|
||||
));
|
||||
|
||||
id
|
||||
query_id
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::arena::{Arena, Handle, UniqueArena};
|
||||
use crate::arena::{Handle, UniqueArena};
|
||||
|
||||
use super::{Error, LookupExpression, LookupHelper as _};
|
||||
|
||||
@@ -689,11 +689,20 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
image: image_lexp.handle,
|
||||
query: crate::ImageQuery::Size { level },
|
||||
};
|
||||
let expr = crate::Expression::As {
|
||||
expr: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
|
||||
let result_type_handle = self.lookup_type.lookup(result_type_id)?.handle;
|
||||
let maybe_scalar_kind = ctx.type_arena[result_type_handle].inner.scalar_kind();
|
||||
|
||||
let expr = if maybe_scalar_kind == Some(crate::ScalarKind::Sint) {
|
||||
crate::Expression::As {
|
||||
expr: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
}
|
||||
} else {
|
||||
expr
|
||||
};
|
||||
|
||||
self.lookup_expression.insert(
|
||||
result_id,
|
||||
LookupExpression {
|
||||
@@ -702,13 +711,14 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
block_id,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn parse_image_query_other(
|
||||
&mut self,
|
||||
query: crate::ImageQuery,
|
||||
expressions: &mut Arena<crate::Expression>,
|
||||
ctx: &mut super::BlockContext,
|
||||
block_id: spirv::Word,
|
||||
) -> Result<(), Error> {
|
||||
let start = self.data_offset;
|
||||
@@ -724,19 +734,29 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
|
||||
image: image_lexp.handle,
|
||||
query,
|
||||
};
|
||||
let expr = crate::Expression::As {
|
||||
expr: expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
|
||||
let result_type_handle = self.lookup_type.lookup(result_type_id)?.handle;
|
||||
let maybe_scalar_kind = ctx.type_arena[result_type_handle].inner.scalar_kind();
|
||||
|
||||
let expr = if maybe_scalar_kind == Some(crate::ScalarKind::Sint) {
|
||||
crate::Expression::As {
|
||||
expr: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
kind: crate::ScalarKind::Sint,
|
||||
convert: Some(4),
|
||||
}
|
||||
} else {
|
||||
expr
|
||||
};
|
||||
|
||||
self.lookup_expression.insert(
|
||||
result_id,
|
||||
LookupExpression {
|
||||
handle: expressions.append(expr, self.span_from_with_op(start)),
|
||||
handle: ctx.expressions.append(expr, self.span_from_with_op(start)),
|
||||
type_id: result_type_id,
|
||||
block_id,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2695,19 +2695,11 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
}
|
||||
Op::ImageQueryLevels => {
|
||||
inst.expect(4)?;
|
||||
self.parse_image_query_other(
|
||||
crate::ImageQuery::NumLevels,
|
||||
ctx.expressions,
|
||||
block_id,
|
||||
)?;
|
||||
self.parse_image_query_other(crate::ImageQuery::NumLevels, ctx, block_id)?;
|
||||
}
|
||||
Op::ImageQuerySamples => {
|
||||
inst.expect(4)?;
|
||||
self.parse_image_query_other(
|
||||
crate::ImageQuery::NumSamples,
|
||||
ctx.expressions,
|
||||
block_id,
|
||||
)?;
|
||||
self.parse_image_query_other(crate::ImageQuery::NumSamples, ctx, block_id)?;
|
||||
}
|
||||
// other ops
|
||||
Op::Select => {
|
||||
|
||||
Reference in New Issue
Block a user