diff --git a/cli/src/main.rs b/cli/src/main.rs index d5ef5ccc4f..8930791d3d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -14,7 +14,7 @@ struct Args { /// /// May be `Restrict`, `ReadZeroSkipWrite`, or `UndefinedBehavior` #[argh(option)] - index_bounds_check_policy: Option, + index_bounds_check_policy: Option, /// directory to dump the SPIR-V flow dump to #[argh(option)] @@ -43,19 +43,19 @@ struct Args { output: Vec, } -/// 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 { - 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, spv_adjust_coordinate_space: bool, spv_flow_dump_prefix: Option, diff --git a/src/back/mod.rs b/src/back/mod.rs index e753e7aa5c..7ac135f9d1 100644 --- a/src/back/mod.rs +++ b/src/back/mod.rs @@ -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 } } diff --git a/src/back/spv/index.rs b/src/back/spv/index.rs index a6b4b0dd29..e82e719725 100644 --- a/src/back/spv/index.rs +++ b/src/back/spv/index.rs @@ -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 { 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]), }) } diff --git a/src/back/spv/mod.rs b/src/back/spv/mod.rs index bd52a03776..0d871ac3d1 100644 --- a/src/back/spv/mod.rs +++ b/src/back/spv/mod.rs @@ -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, annotations: Vec, 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, @@ -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(), } } } diff --git a/tests/in/bounds-check-zero.wgsl b/tests/in/bounds-check-zero.wgsl index 773a1788fb..74811c12b4 100644 --- a/tests/in/bounds-check-zero.wgsl +++ b/tests/in/bounds-check-zero.wgsl @@ -1,4 +1,4 @@ -// Tests for `naga::back::IndexBoundsCheckPolicy::ReadZeroSkipWrite`. +// Tests for `naga::back::BoundsCheckPolicy::ReadZeroSkipWrite`. [[block]] struct Globals { diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 339f944dd4..9d917f47d2 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -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 }, };