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