Skip to content

Commit

Permalink
Only emit loop macro for checked index
Browse files Browse the repository at this point in the history
  • Loading branch information
rudderbucky committed Nov 13, 2024
1 parent 2bea408 commit ac60902
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion naga/src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3028,7 +3028,10 @@ impl<W: Write> Writer<W> {
ref continuing,
break_if,
} => {
self.emit_loop_reachable_macro()?;
// We only emit the macro if the index policy is not checked.
if context.expression.policies.index != index::BoundsCheckPolicy::Unchecked {
self.emit_loop_reachable_macro()?;
}
if !continuing.is_empty() || break_if.is_some() {
let gate_name = self.namer.call("loop_init");
writeln!(self.out, "{level}bool {gate_name} = true;")?;
Expand Down
1 change: 1 addition & 0 deletions naga/src/proc/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum BoundsCheckPolicy {
pub struct BoundsCheckPolicies {
/// How should the generated code handle array, vector, or matrix indices
/// that are out of range?
/// On Metal, this policy also dictates how loops are checked for UB.
#[cfg_attr(feature = "deserialize", serde(default))]
pub index: BoundsCheckPolicy,

Expand Down

0 comments on commit ac60902

Please sign in to comment.