Skip to content

Commit

Permalink
[naga] Explicitly use global const ctx in offset (#6945)
Browse files Browse the repository at this point in the history
* Fix as_const on expr ctx

Signed-off-by: sagudev <[email protected]>

* fixup

Signed-off-by: sagudev <[email protected]>

---------

Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev authored Jan 20, 2025
1 parent 1f939e1 commit 6e7d3c4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,29 @@ pub struct ExpressionContext<'source, 'temp, 'out> {
}

impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
#[allow(dead_code)]
fn as_const(&mut self) -> ExpressionContext<'source, '_, '_> {
ExpressionContext {
globals: self.globals,
types: self.types,
ast_expressions: self.ast_expressions,
const_typifier: self.const_typifier,
module: self.module,
expr_type: ExpressionContextType::Constant(None),
expr_type: ExpressionContextType::Constant(match self.expr_type {
ExpressionContextType::Runtime(ref mut local_expression_context)
| ExpressionContextType::Constant(Some(ref mut local_expression_context)) => {
Some(LocalExpressionContext {
local_table: local_expression_context.local_table,
function: local_expression_context.function,
block: local_expression_context.block,
emitter: local_expression_context.emitter,
typifier: local_expression_context.typifier,
local_expression_kind_tracker: local_expression_context
.local_expression_kind_tracker,
})
}
ExpressionContextType::Constant(None) | ExpressionContextType::Override => None,
}),
global_expression_kind_tracker: self.global_expression_kind_tracker,
}
}
Expand Down Expand Up @@ -2903,7 +2918,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

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

Expand Down

0 comments on commit 6e7d3c4

Please sign in to comment.