Skip to content

Commit

Permalink
use local const ctx
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Feb 16, 2025
1 parent 926a333 commit 7d48696
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 27 deletions.
9 changes: 2 additions & 7 deletions naga/src/compact/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ impl ExpressionTracer<'_> {
self.expressions_used
.insert_iter([image, sampler, coordinate]);
self.expressions_used.insert_iter(array_index);
match self.global_expressions_used {
Some(ref mut used) => used.insert_iter(offset),
None => self.expressions_used.insert_iter(offset),
}
self.expressions_used.insert_iter(offset);
use crate::SampleLevel as Sl;
match *level {
Sl::Auto | Sl::Zero => {}
Expand Down Expand Up @@ -315,9 +312,7 @@ impl ModuleMap {
adjust(sampler);
adjust(coordinate);
operand_map.adjust_option(array_index);
if let Some(ref mut offset) = *offset {
self.global_expressions.adjust(offset);
}
operand_map.adjust_option(offset);
self.adjust_sample_level(level, operand_map);
operand_map.adjust_option(depth_ref);
}
Expand Down
3 changes: 2 additions & 1 deletion naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> {
}
}

#[allow(dead_code)]
fn as_global(&mut self) -> GlobalContext<'a, '_, '_> {
GlobalContext {
ast_expressions: self.ast_expressions,
Expand Down Expand Up @@ -2949,7 +2950,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

let offset = args
.next()
.map(|arg| self.expression(arg, &mut ctx.as_global().as_const()))
.map(|arg| self.expression(arg, &mut ctx.as_const()))
.ok()
.transpose()?;

Expand Down
2 changes: 1 addition & 1 deletion naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ pub struct Override {
pub init: Option<Handle<Expression>>,
}

/// Constant value.
/// Global constant value.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
Expand Down
6 changes: 3 additions & 3 deletions naga/src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl super::Validator {
module: &crate::Module,
info: &FunctionInfo,
mod_info: &ModuleInfo,
global_expr_kind: &crate::proc::ExpressionKindTracker,
expr_kind: &crate::proc::ExpressionKindTracker,
) -> Result<ShaderStages, ExpressionError> {
use crate::{Expression as E, Scalar as Sc, ScalarKind as Sk, TypeInner as Ti};

Expand Down Expand Up @@ -486,11 +486,11 @@ impl super::Validator {

// check constant offset
if let Some(const_expr) = offset {
if !global_expr_kind.is_const(const_expr) {
if !expr_kind.is_const(const_expr) {
return Err(ExpressionError::InvalidSampleOffsetExprType);
}

match *mod_info[const_expr].inner_with(&module.types) {
match resolver[const_expr] {
Ti::Scalar(Sc { kind: Sk::Sint, .. }) if num_components == 1 => {}
Ti::Vector {
size,
Expand Down
3 changes: 1 addition & 2 deletions naga/src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,6 @@ impl super::Validator {
module: &crate::Module,
mod_info: &ModuleInfo,
entry_point: bool,
global_expr_kind: &crate::proc::ExpressionKindTracker,
) -> Result<FunctionInfo, WithSpan<FunctionError>> {
let mut info = mod_info.process_function(fun, module, self.flags, self.capabilities)?;

Expand Down Expand Up @@ -1714,7 +1713,7 @@ impl super::Validator {
module,
&info,
mod_info,
global_expr_kind,
&local_expr_kind,
) {
Ok(stages) => info.available_stages &= stages,
Err(source) => {
Expand Down
11 changes: 2 additions & 9 deletions naga/src/valid/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ impl super::Validator {
handle_and_expr,
constants,
overrides,
global_expressions,
types,
local_variables,
global_variables,
Expand Down Expand Up @@ -385,7 +384,6 @@ impl super::Validator {
(handle, expression): (Handle<crate::Expression>, &crate::Expression),
constants: &Arena<crate::Constant>,
overrides: &Arena<crate::Override>,
global_expressions: &Arena<crate::Expression>,
types: &UniqueArena<crate::Type>,
local_variables: &Arena<crate::LocalVariable>,
global_variables: &Arena<crate::GlobalVariable>,
Expand All @@ -395,8 +393,6 @@ impl super::Validator {
) -> Result<(), InvalidHandleError> {
let validate_constant = |handle| Self::validate_constant_handle(handle, constants);
let validate_override = |handle| Self::validate_override_handle(handle, overrides);
let validate_const_expr =
|handle| Self::validate_expression_handle(handle, global_expressions);
let validate_type = |handle| Self::validate_type_handle(handle, types);

match *expression {
Expand Down Expand Up @@ -446,15 +442,12 @@ impl super::Validator {
level,
depth_ref,
} => {
if let Some(offset) = offset {
validate_const_expr(offset)?;
}

handle
.check_dep(image)?
.check_dep(sampler)?
.check_dep(coordinate)?
.check_dep_opt(array_index)?;
.check_dep_opt(array_index)?
.check_dep_opt(offset)?;

match level {
crate::SampleLevel::Auto | crate::SampleLevel::Zero => (),
Expand Down
3 changes: 1 addition & 2 deletions naga/src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ impl super::Validator {
ep: &crate::EntryPoint,
module: &crate::Module,
mod_info: &ModuleInfo,
global_expr_kind: &crate::proc::ExpressionKindTracker,
) -> Result<FunctionInfo, WithSpan<EntryPointError>> {
if ep.early_depth_test.is_some() {
let required = Capabilities::EARLY_DEPTH_TEST;
Expand Down Expand Up @@ -648,7 +647,7 @@ impl super::Validator {
}

let mut info = self
.validate_function(&ep.function, module, mod_info, true, global_expr_kind)
.validate_function(&ep.function, module, mod_info, true)
.map_err(WithSpan::into_other)?;

{
Expand Down
4 changes: 2 additions & 2 deletions naga/src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ impl Validator {
}

for (handle, fun) in module.functions.iter() {
match self.validate_function(fun, module, &mod_info, false, &global_expr_kind) {
match self.validate_function(fun, module, &mod_info, false) {
Ok(info) => mod_info.functions.push(info),
Err(error) => {
return Err(error.and_then(|source| {
Expand All @@ -738,7 +738,7 @@ impl Validator {
.with_span()); // TODO: keep some EP span information?
}

match self.validate_entry_point(ep, module, &mod_info, &global_expr_kind) {
match self.validate_entry_point(ep, module, &mod_info) {
Ok(info) => mod_info.entry_points.push(info),
Err(error) => {
return Err(error.and_then(|source| {
Expand Down

0 comments on commit 7d48696

Please sign in to comment.