mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Rename IndexBoundsCheckPolicy to BoundsCheckPolicy.
This commit is contained in:
committed by
Dzmitry Malyshau
parent
fd10b7d9e8
commit
de114e479b
@@ -14,7 +14,7 @@ struct Args {
|
||||
///
|
||||
/// May be `Restrict`, `ReadZeroSkipWrite`, or `UndefinedBehavior`
|
||||
#[argh(option)]
|
||||
index_bounds_check_policy: Option<IndexBoundsCheckPolicyArg>,
|
||||
index_bounds_check_policy: Option<BoundsCheckPolicyArg>,
|
||||
|
||||
/// directory to dump the SPIR-V flow dump to
|
||||
#[argh(option)]
|
||||
@@ -43,19 +43,19 @@ struct Args {
|
||||
output: Vec<String>,
|
||||
}
|
||||
|
||||
/// Newtype so we can implement [`FromStr`] for `IndexBoundsCheckPolicy`.
|
||||
/// Newtype so we can implement [`FromStr`] for `BoundsCheckPolicy`.
|
||||
#[derive(Debug, Clone)]
|
||||
struct IndexBoundsCheckPolicyArg(naga::back::IndexBoundsCheckPolicy);
|
||||
struct BoundsCheckPolicyArg(naga::back::BoundsCheckPolicy);
|
||||
|
||||
impl FromStr for IndexBoundsCheckPolicyArg {
|
||||
impl FromStr for BoundsCheckPolicyArg {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
use naga::back::IndexBoundsCheckPolicy;
|
||||
use naga::back::BoundsCheckPolicy;
|
||||
Ok(Self(match s.to_lowercase().as_str() {
|
||||
"restrict" => IndexBoundsCheckPolicy::Restrict,
|
||||
"readzeroskipwrite" => IndexBoundsCheckPolicy::ReadZeroSkipWrite,
|
||||
"undefinedbehavior" => IndexBoundsCheckPolicy::UndefinedBehavior,
|
||||
"restrict" => BoundsCheckPolicy::Restrict,
|
||||
"readzeroskipwrite" => BoundsCheckPolicy::ReadZeroSkipWrite,
|
||||
"undefinedbehavior" => BoundsCheckPolicy::UndefinedBehavior,
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"Invalid value for --index-bounds-check-policy: {}",
|
||||
@@ -106,7 +106,7 @@ impl FromStr for GlslProfileArg {
|
||||
#[derive(Default)]
|
||||
struct Parameters {
|
||||
validation_flags: naga::valid::ValidationFlags,
|
||||
index_bounds_check_policy: naga::back::IndexBoundsCheckPolicy,
|
||||
index_bounds_check_policy: naga::back::BoundsCheckPolicy,
|
||||
entry_point: Option<String>,
|
||||
spv_adjust_coordinate_space: bool,
|
||||
spv_flow_dump_prefix: Option<String>,
|
||||
|
||||
@@ -123,7 +123,7 @@ impl<'a> FunctionCtx<'_> {
|
||||
/// - Naga's own default is `UndefinedBehavior`, so that shader translations
|
||||
/// are as faithful to the original as possible.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum IndexBoundsCheckPolicy {
|
||||
pub enum BoundsCheckPolicy {
|
||||
/// Replace out-of-bounds indexes with some arbitrary in-bounds index.
|
||||
///
|
||||
/// (This does not necessarily mean clamping. For example, interpreting the
|
||||
@@ -141,10 +141,10 @@ pub enum IndexBoundsCheckPolicy {
|
||||
UndefinedBehavior,
|
||||
}
|
||||
|
||||
/// The default `IndexBoundsCheckPolicy` is `UndefinedBehavior`.
|
||||
impl Default for IndexBoundsCheckPolicy {
|
||||
/// The default `BoundsCheckPolicy` is `UndefinedBehavior`.
|
||||
impl Default for BoundsCheckPolicy {
|
||||
fn default() -> Self {
|
||||
IndexBoundsCheckPolicy::UndefinedBehavior
|
||||
BoundsCheckPolicy::UndefinedBehavior
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Bounds-checking for SPIR-V output.
|
||||
|
||||
use super::{Block, BlockContext, Error, IdGenerator, Instruction, Word};
|
||||
use crate::{arena::Handle, back::IndexBoundsCheckPolicy};
|
||||
use crate::{arena::Handle, back::BoundsCheckPolicy};
|
||||
|
||||
/// The results of emitting code for a left-hand-side expression.
|
||||
///
|
||||
@@ -157,11 +157,11 @@ impl<'w> BlockContext<'w> {
|
||||
|
||||
/// Restrict an index to be in range for a vector, matrix, or array.
|
||||
///
|
||||
/// This is used to implement `IndexBoundsCheckPolicy::Restrict`. An
|
||||
/// in-bounds index is left unchanged. An out-of-bounds index is replaced
|
||||
/// with some arbitrary in-bounds index. Note,this is not necessarily
|
||||
/// clamping; for example, negative indices might be changed to refer to the
|
||||
/// last element of the sequence, not the first, as clamping would do.
|
||||
/// This is used to implement `BoundsCheckPolicy::Restrict`. An in-bounds
|
||||
/// index is left unchanged. An out-of-bounds index is replaced with some
|
||||
/// arbitrary in-bounds index. Note,this is not necessarily clamping; for
|
||||
/// example, negative indices might be changed to refer to the last element
|
||||
/// of the sequence, not the first, as clamping would do.
|
||||
///
|
||||
/// Either return the restricted index value, if known, or add instructions
|
||||
/// to `block` to compute it, and return the id of the result. See the
|
||||
@@ -202,7 +202,7 @@ impl<'w> BlockContext<'w> {
|
||||
};
|
||||
|
||||
// One or the other of the index or length is dynamic, so emit code for
|
||||
// IndexBoundsCheckPolicy::Restrict.
|
||||
// BoundsCheckPolicy::Restrict.
|
||||
let restricted_index_id = self.gen_id();
|
||||
block.body.push(Instruction::ext_inst(
|
||||
self.writer.gl450_ext_inst_id,
|
||||
@@ -290,7 +290,7 @@ impl<'w> BlockContext<'w> {
|
||||
Ok(BoundsCheckResult::Conditional(condition_id))
|
||||
}
|
||||
|
||||
/// Emit a conditional load for `IndexBoundsCheckPolicy::ReadZeroSkipWrite`.
|
||||
/// Emit a conditional load for `BoundsCheckPolicy::ReadZeroSkipWrite`.
|
||||
///
|
||||
/// Generate code to load a value of `result_type` if `condition` is true,
|
||||
/// and generate a null value of that type if it is false. Call `emit_load`
|
||||
@@ -362,13 +362,11 @@ impl<'w> BlockContext<'w> {
|
||||
block: &mut Block,
|
||||
) -> Result<BoundsCheckResult, Error> {
|
||||
Ok(match self.writer.index_bounds_check_policy {
|
||||
IndexBoundsCheckPolicy::Restrict => self.write_restricted_index(base, index, block)?,
|
||||
IndexBoundsCheckPolicy::ReadZeroSkipWrite => {
|
||||
BoundsCheckPolicy::Restrict => self.write_restricted_index(base, index, block)?,
|
||||
BoundsCheckPolicy::ReadZeroSkipWrite => {
|
||||
self.write_index_comparison(base, index, block)?
|
||||
}
|
||||
IndexBoundsCheckPolicy::UndefinedBehavior => {
|
||||
BoundsCheckResult::Computed(self.cached[index])
|
||||
}
|
||||
BoundsCheckPolicy::UndefinedBehavior => BoundsCheckResult::Computed(self.cached[index]),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ mod writer;
|
||||
|
||||
pub use spirv::Capability;
|
||||
|
||||
use crate::{arena::Handle, back::IndexBoundsCheckPolicy, proc::TypeResolution};
|
||||
use crate::{arena::Handle, back::BoundsCheckPolicy, proc::TypeResolution};
|
||||
|
||||
use spirv::Word;
|
||||
use std::ops;
|
||||
@@ -400,7 +400,7 @@ pub struct Writer {
|
||||
debugs: Vec<Instruction>,
|
||||
annotations: Vec<Instruction>,
|
||||
flags: WriterFlags,
|
||||
index_bounds_check_policy: IndexBoundsCheckPolicy,
|
||||
index_bounds_check_policy: BoundsCheckPolicy,
|
||||
void_type: Word,
|
||||
//TODO: convert most of these into vectors, addressable by handle indices
|
||||
lookup_type: crate::FastHashMap<LookupType, Word>,
|
||||
@@ -444,7 +444,7 @@ pub struct Options {
|
||||
|
||||
/// How should the generated code handle array, vector, or matrix indices
|
||||
/// that are out of range?
|
||||
pub index_bounds_check_policy: IndexBoundsCheckPolicy,
|
||||
pub index_bounds_check_policy: BoundsCheckPolicy,
|
||||
}
|
||||
|
||||
impl Default for Options {
|
||||
@@ -457,7 +457,7 @@ impl Default for Options {
|
||||
lang_version: (1, 0),
|
||||
flags,
|
||||
capabilities: None,
|
||||
index_bounds_check_policy: super::IndexBoundsCheckPolicy::default(),
|
||||
index_bounds_check_policy: super::BoundsCheckPolicy::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Tests for `naga::back::IndexBoundsCheckPolicy::ReadZeroSkipWrite`.
|
||||
// Tests for `naga::back::BoundsCheckPolicy::ReadZeroSkipWrite`.
|
||||
|
||||
[[block]]
|
||||
struct Globals {
|
||||
|
||||
@@ -24,7 +24,7 @@ struct Parameters {
|
||||
#[serde(default)]
|
||||
god_mode: bool,
|
||||
|
||||
// We can only deserialize `IndexBoundsCheckPolicy` values if `deserialize`
|
||||
// We can only deserialize `BoundsCheckPolicy` values if `deserialize`
|
||||
// feature was enabled, but features should not affect snapshot contents, so
|
||||
// just take the policy as booleans instead.
|
||||
#[serde(default)]
|
||||
@@ -166,11 +166,11 @@ fn write_output_spv(
|
||||
Some(params.spv_capabilities.clone())
|
||||
},
|
||||
index_bounds_check_policy: if params.bounds_check_restrict {
|
||||
naga::back::IndexBoundsCheckPolicy::Restrict
|
||||
naga::back::BoundsCheckPolicy::Restrict
|
||||
} else if params.bounds_check_read_zero_skip_write {
|
||||
naga::back::IndexBoundsCheckPolicy::ReadZeroSkipWrite
|
||||
naga::back::BoundsCheckPolicy::ReadZeroSkipWrite
|
||||
} else {
|
||||
naga::back::IndexBoundsCheckPolicy::UndefinedBehavior
|
||||
naga::back::BoundsCheckPolicy::UndefinedBehavior
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user