|
1 | 1 | use super::Error;
|
2 | 2 | use crate::{
|
3 | 3 | back::{self, Baked},
|
4 |
| - proc::{self, NameKey}, |
| 4 | + proc::{self, ExpressionKindTracker, NameKey}, |
5 | 5 | valid, Handle, Module, ShaderStage, TypeInner,
|
6 | 6 | };
|
7 | 7 | use std::fmt::Write;
|
@@ -166,6 +166,7 @@ impl<W: Write> Writer<W> {
|
166 | 166 | info: fun_info,
|
167 | 167 | expressions: &function.expressions,
|
168 | 168 | named_expressions: &function.named_expressions,
|
| 169 | + expr_kind_tracker: ExpressionKindTracker::from_arena(&function.expressions), |
169 | 170 | };
|
170 | 171 |
|
171 | 172 | // Write the function
|
@@ -193,6 +194,7 @@ impl<W: Write> Writer<W> {
|
193 | 194 | info: info.get_entry_point(index),
|
194 | 195 | expressions: &ep.function.expressions,
|
195 | 196 | named_expressions: &ep.function.named_expressions,
|
| 197 | + expr_kind_tracker: ExpressionKindTracker::from_arena(&ep.function.expressions), |
196 | 198 | };
|
197 | 199 | self.write_function(module, &ep.function, &func_ctx)?;
|
198 | 200 |
|
@@ -1115,8 +1117,14 @@ impl<W: Write> Writer<W> {
|
1115 | 1117 | func_ctx: &back::FunctionCtx,
|
1116 | 1118 | name: &str,
|
1117 | 1119 | ) -> BackendResult {
|
| 1120 | + // Some functions are marked as const, but are not yet implemented as constant expression |
| 1121 | + let quantifier = if func_ctx.expr_kind_tracker.is_impl_const(handle) { |
| 1122 | + "const" |
| 1123 | + } else { |
| 1124 | + "let" |
| 1125 | + }; |
1118 | 1126 | // Write variable name
|
1119 |
| - write!(self.out, "let {name}")?; |
| 1127 | + write!(self.out, "{quantifier} {name}")?; |
1120 | 1128 | if self.flags.contains(WriterFlags::EXPLICIT_TYPES) {
|
1121 | 1129 | write!(self.out, ": ")?;
|
1122 | 1130 | let ty = &func_ctx.info[handle].ty;
|
|
0 commit comments