mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[naga wgsl-in] Introduce ExpressionContext::is_const helper.
In `naga::front::wgsl::lower`, add a new method, `ExpressionContext::is_const`, for looking up the constness of a given expression. Change existing code to use it.
This commit is contained in:
committed by
Connor Fitzgerald
parent
8f7dc8c070
commit
def9d7142a
@@ -526,6 +526,19 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return `true` if `handle` is a constant expression.
|
||||
fn is_const(&self, handle: Handle<crate::Expression>) -> bool {
|
||||
use ExpressionContextType as Ect;
|
||||
match self.expr_type {
|
||||
Ect::Runtime(ref ctx) | Ect::Constant(Some(ref ctx)) => {
|
||||
ctx.local_expression_kind_tracker.is_const(handle)
|
||||
}
|
||||
Ect::Constant(None) | Ect::Override => {
|
||||
self.global_expression_kind_tracker.is_const(handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_expression_span(&self, handle: Handle<crate::Expression>) -> Span {
|
||||
match self.expr_type {
|
||||
ExpressionContextType::Runtime(ref ctx)
|
||||
@@ -2262,16 +2275,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
|
||||
// We only have to explicitly do so for shifts as their operands may be
|
||||
// of different types - for other binary ops this is achieved by finding
|
||||
// the conversion consensus for both operands.
|
||||
let expr_kind_tracker = match ctx.expr_type {
|
||||
ExpressionContextType::Runtime(ref ctx)
|
||||
| ExpressionContextType::Constant(Some(ref ctx)) => {
|
||||
&ctx.local_expression_kind_tracker
|
||||
}
|
||||
ExpressionContextType::Constant(None) | ExpressionContextType::Override => {
|
||||
&ctx.global_expression_kind_tracker
|
||||
}
|
||||
};
|
||||
if !expr_kind_tracker.is_const(right) {
|
||||
if !ctx.is_const(right) {
|
||||
left = ctx.concretize(left)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ ANDed = "ANDed"
|
||||
D3DCOLORtoUBYTE4 = "D3DCOLORtoUBYTE4"
|
||||
Derivate = "Derivate"
|
||||
inout = "inout"
|
||||
Ect = "Ect"
|
||||
|
||||
[type.wgsl]
|
||||
extend-glob = ["*.wgsl"]
|
||||
|
||||
Reference in New Issue
Block a user