mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-10-29 21:41:36 +00:00
refactor access_needs_check
to take a reference to the expression arena
This commit is contained in:
parent
b32574b368
commit
3199a3a6b0
@ -630,7 +630,13 @@ impl<'a> ExpressionContext<'a> {
|
||||
base: Handle<crate::Expression>,
|
||||
index: index::GuardedIndex,
|
||||
) -> Option<index::IndexableLength> {
|
||||
index::access_needs_check(base, index, self.module, self.function, self.info)
|
||||
index::access_needs_check(
|
||||
base,
|
||||
index,
|
||||
self.module,
|
||||
&self.function.expressions,
|
||||
self.info,
|
||||
)
|
||||
}
|
||||
|
||||
fn get_packed_vec_kind(&self, expr_handle: Handle<crate::Expression>) -> Option<crate::Scalar> {
|
||||
|
@ -357,8 +357,11 @@ impl<'w> BlockContext<'w> {
|
||||
}
|
||||
crate::TypeInner::Array { .. } | crate::TypeInner::Matrix { .. } => {
|
||||
// See if `index` is known at compile time.
|
||||
match GuardedIndex::from_expression(index, self.ir_function, self.ir_module)
|
||||
{
|
||||
match GuardedIndex::from_expression(
|
||||
index,
|
||||
&self.ir_function.expressions,
|
||||
self.ir_module,
|
||||
) {
|
||||
GuardedIndex::Known(value) => {
|
||||
// If `index` is known and in bounds, we can just use
|
||||
// `OpCompositeExtract`.
|
||||
|
@ -512,7 +512,7 @@ impl<'w> BlockContext<'w> {
|
||||
block: &mut Block,
|
||||
) -> Result<BoundsCheckResult, Error> {
|
||||
// If the value of `index` is known at compile time, find it now.
|
||||
index.try_resolve_to_constant(self.ir_function, self.ir_module);
|
||||
index.try_resolve_to_constant(&self.ir_function.expressions, self.ir_module);
|
||||
|
||||
let policy = self.writer.bounds_check_policies.choose_policy(
|
||||
base,
|
||||
|
@ -250,7 +250,7 @@ pub fn find_checked_indexes(
|
||||
base,
|
||||
GuardedIndex::Expression(index),
|
||||
module,
|
||||
function,
|
||||
&function.expressions,
|
||||
info,
|
||||
)
|
||||
.is_some()
|
||||
@ -311,7 +311,7 @@ pub fn access_needs_check(
|
||||
base: Handle<crate::Expression>,
|
||||
mut index: GuardedIndex,
|
||||
module: &crate::Module,
|
||||
function: &crate::Function,
|
||||
expressions: &crate::Arena<crate::Expression>,
|
||||
info: &valid::FunctionInfo,
|
||||
) -> Option<IndexableLength> {
|
||||
let base_inner = info[base].ty.inner_with(&module.types);
|
||||
@ -319,7 +319,7 @@ pub fn access_needs_check(
|
||||
// length constants, but `access_needs_check` is only used by back ends, so
|
||||
// validation should have caught those problems.
|
||||
let length = base_inner.indexable_length(module).unwrap();
|
||||
index.try_resolve_to_constant(function, module);
|
||||
index.try_resolve_to_constant(expressions, module);
|
||||
if let (&GuardedIndex::Known(index), &IndexableLength::Known(length)) = (&index, &length) {
|
||||
if index < length {
|
||||
// Index is statically known to be in bounds, no check needed.
|
||||
@ -336,23 +336,20 @@ impl GuardedIndex {
|
||||
/// Return values that are already `Known` unchanged.
|
||||
pub(crate) fn try_resolve_to_constant(
|
||||
&mut self,
|
||||
function: &crate::Function,
|
||||
expressions: &crate::Arena<crate::Expression>,
|
||||
module: &crate::Module,
|
||||
) {
|
||||
if let GuardedIndex::Expression(expr) = *self {
|
||||
*self = GuardedIndex::from_expression(expr, function, module);
|
||||
*self = GuardedIndex::from_expression(expr, expressions, module);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_expression(
|
||||
expr: Handle<crate::Expression>,
|
||||
function: &crate::Function,
|
||||
expressions: &crate::Arena<crate::Expression>,
|
||||
module: &crate::Module,
|
||||
) -> Self {
|
||||
match module
|
||||
.to_ctx()
|
||||
.eval_expr_to_u32_from(expr, &function.expressions)
|
||||
{
|
||||
match module.to_ctx().eval_expr_to_u32_from(expr, expressions) {
|
||||
Ok(value) => Self::Known(value),
|
||||
Err(_) => Self::Expression(expr),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user