Skip to content

Commit 2df2646

Browse files
authored
Merge branch 'trunk' into naga-ray-tracing-pipelines
2 parents 880607d + 0cd51d2 commit 2df2646

File tree

14 files changed

+183
-158
lines changed

14 files changed

+183
-158
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Bottom level categories:
5454
- BREAKING: Migrated from the `maxInterStageShaderComponents` limit to `maxInterStageShaderVariables`, which changes validation in a way that should not affect most programs. This follows the latest changes of the WebGPU spec. By @ErichDonGubler in [#8652](https://github.com/gfx-rs/wgpu/pull/8652), [#8792](https://github.com/gfx-rs/wgpu/pull/8792).
5555
- Fixed validation of the texture format in GPUDepthStencilState when neither depth nor stencil is actually enabled. By @andyleiserson in [#8766](https://github.com/gfx-rs/wgpu/pull/8766).
5656

57+
#### naga
58+
59+
- The validator checks that override-sized arrays have a positive size, if overrides have been resolved. By @andyleiserson in [#8822](https://github.com/gfx-rs/wgpu/pull/8822).
60+
- Fix some cases where f16 constants were not working. By @andyleiserson in [#8816](https://github.com/gfx-rs/wgpu/pull/8816).
61+
5762
#### GLES
5863

5964
- `DisplayHandle` should now be passed to `InstanceDescriptor` for correct EGL initialization on Wayland. By @MarijnS95 in [#8012](https://github.com/gfx-rs/wgpu/pull/8012)

cts_runner/test.lst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,23 @@ webgpu:shader,execution,flow_control,return:*
237237
// Fails on Metal in CI only, not when running locally.
238238
fails-if(metal) webgpu:shader,execution,robust_access_vertex:vertex_buffer_access:indexed=true;indirect=false;drawCallTestParameter="baseVertex";type="float32x4";additionalBuffers=4;partialLastNumber=false;offsetVertexBuffer=true
239239
webgpu:shader,validation,const_assert,const_assert:*
240+
webgpu:shader,validation,expression,access,array:early_eval_errors:case="override_array_cnt_size_zero_unsigned"
241+
webgpu:shader,validation,expression,access,array:early_eval_errors:case="override_array_cnt_size_zero_signed"
242+
webgpu:shader,validation,expression,access,array:early_eval_errors:case="override_array_cnt_size_neg"
243+
webgpu:shader,validation,expression,access,array:early_eval_errors:case="override_array_cnt_size_one"
244+
webgpu:shader,validation,expression,access,array:early_eval_errors:case="override_in_bounds"
240245
webgpu:shader,validation,expression,binary,short_circuiting_and_or:array_override:op="%26%26";a_val=1;b_val=1
241246
webgpu:shader,validation,expression,binary,short_circuiting_and_or:invalid_types:*
242247
webgpu:shader,validation,expression,binary,short_circuiting_and_or:scalar_vector:op="%26%26";lhs="bool";rhs="bool"
243248
webgpu:shader,validation,expression,call,builtin,all:arguments:test="ptr_deref"
244249
webgpu:shader,validation,expression,call,builtin,max:values:*
250+
// FAIL: others in `value_constructor` due to #8815, #8442, #4720, possibly more
251+
webgpu:shader,validation,expression,call,builtin,value_constructor:array_value:*
252+
webgpu:shader,validation,expression,call,builtin,value_constructor:matrix_zero_value:*
253+
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_zero_value:*
254+
webgpu:shader,validation,expression,call,builtin,value_constructor:scalar_value:*
255+
webgpu:shader,validation,expression,call,builtin,value_constructor:struct_value:*
256+
webgpu:shader,validation,expression,call,builtin,value_constructor:vector_zero_value:*
245257
// NOTE: This is supposed to be an exhaustive listing underneath
246258
// `webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:*`, so exceptions can be
247259
// worked around.

naga/src/back/pipeline_constants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn process_workgroup_size_override(
280280
Some(h) => {
281281
ep.workgroup_size[i] = module
282282
.to_ctx()
283-
.eval_expr_to_u32(adjusted_global_expressions[h])
283+
.get_const_val(adjusted_global_expressions[h])
284284
.map(|n| {
285285
if n == 0 {
286286
Err(PipelineConstantError::NegativeWorkgroupSize)
@@ -309,13 +309,13 @@ fn process_mesh_shader_overrides(
309309
if let Some(r#override) = mesh_info.max_vertices_override {
310310
mesh_info.max_vertices = module
311311
.to_ctx()
312-
.eval_expr_to_u32(adjusted_global_expressions[r#override])
312+
.get_const_val(adjusted_global_expressions[r#override])
313313
.map_err(|_| PipelineConstantError::NegativeMeshOutputMax)?;
314314
}
315315
if let Some(r#override) = mesh_info.max_primitives_override {
316316
mesh_info.max_primitives = module
317317
.to_ctx()
318-
.eval_expr_to_u32(adjusted_global_expressions[r#override])
318+
.get_const_val(adjusted_global_expressions[r#override])
319319
.map_err(|_| PipelineConstantError::NegativeMeshOutputMax)?;
320320
}
321321
}

naga/src/front/glsl/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl<'a> Context<'a> {
561561
_ => self
562562
.module
563563
.to_ctx()
564-
.eval_expr_to_u32_from(index, &self.expressions)
564+
.get_const_val_from(index, &self.expressions)
565565
.ok(),
566566
};
567567

naga/src/front/glsl/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{
1414
variables::{GlobalOrConstant, VarDeclaration},
1515
Frontend, Result,
1616
};
17-
use crate::{arena::Handle, proc::U32EvalError, Expression, Module, Span, Type};
17+
use crate::{arena::Handle, proc::ConstValueError, Expression, Module, Span, Type};
1818

1919
mod declarations;
2020
mod expressions;
@@ -211,15 +211,15 @@ impl<'source> ParsingContext<'source> {
211211
ctx.global_expression_kind_tracker,
212212
)?;
213213

214-
let res = ctx.module.to_ctx().eval_expr_to_u32(const_expr);
214+
let res = ctx.module.to_ctx().get_const_val(const_expr);
215215

216216
let int = match res {
217217
Ok(value) => Ok(value),
218-
Err(U32EvalError::Negative) => Err(Error {
218+
Err(ConstValueError::Negative) => Err(Error {
219219
kind: ErrorKind::SemanticError("int constant overflows".into()),
220220
meta,
221221
}),
222-
Err(U32EvalError::NonConst) => Err(Error {
222+
Err(ConstValueError::NonConst | ConstValueError::InvalidType) => Err(Error {
223223
kind: ErrorKind::SemanticError("Expected a uint constant".into()),
224224
meta,
225225
}),

naga/src/front/spv/next_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
277277
let index_maybe = match *index_expr_data {
278278
crate::Expression::Constant(const_handle) => Some(
279279
ctx.gctx()
280-
.eval_expr_to_u32(ctx.module.constants[const_handle].init)
280+
.get_const_val(ctx.module.constants[const_handle].init)
281281
.map_err(|_| {
282282
Error::InvalidAccess(crate::Expression::Constant(
283283
const_handle,

naga/src/front/wgsl/lower/mod.rs

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -535,50 +535,28 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
535535
.map_err(|e| Box::new(Error::ConstantEvaluatorError(e.into(), span)))
536536
}
537537

538-
fn const_eval_expr_to_u32(
538+
fn get_const_val<T: TryFrom<crate::Literal, Error = proc::ConstValueError>>(
539539
&self,
540540
handle: Handle<ir::Expression>,
541-
) -> core::result::Result<u32, proc::U32EvalError> {
541+
) -> core::result::Result<T, proc::ConstValueError> {
542542
match self.expr_type {
543543
ExpressionContextType::Runtime(ref ctx) => {
544544
if !ctx.local_expression_kind_tracker.is_const(handle) {
545-
return Err(proc::U32EvalError::NonConst);
545+
return Err(proc::ConstValueError::NonConst);
546546
}
547547

548548
self.module
549549
.to_ctx()
550-
.eval_expr_to_u32_from(handle, &ctx.function.expressions)
550+
.get_const_val_from(handle, &ctx.function.expressions)
551551
}
552552
ExpressionContextType::Constant(Some(ref ctx)) => {
553553
assert!(ctx.local_expression_kind_tracker.is_const(handle));
554554
self.module
555555
.to_ctx()
556-
.eval_expr_to_u32_from(handle, &ctx.function.expressions)
556+
.get_const_val_from(handle, &ctx.function.expressions)
557557
}
558-
ExpressionContextType::Constant(None) => self.module.to_ctx().eval_expr_to_u32(handle),
559-
ExpressionContextType::Override => Err(proc::U32EvalError::NonConst),
560-
}
561-
}
562-
563-
fn const_eval_expr_to_bool(&self, handle: Handle<ir::Expression>) -> Option<bool> {
564-
match self.expr_type {
565-
ExpressionContextType::Runtime(ref ctx) => {
566-
if !ctx.local_expression_kind_tracker.is_const(handle) {
567-
return None;
568-
}
569-
570-
self.module
571-
.to_ctx()
572-
.eval_expr_to_bool_from(handle, &ctx.function.expressions)
573-
}
574-
ExpressionContextType::Constant(Some(ref ctx)) => {
575-
assert!(ctx.local_expression_kind_tracker.is_const(handle));
576-
self.module
577-
.to_ctx()
578-
.eval_expr_to_bool_from(handle, &ctx.function.expressions)
579-
}
580-
ExpressionContextType::Constant(None) => self.module.to_ctx().eval_expr_to_bool(handle),
581-
ExpressionContextType::Override => None,
558+
ExpressionContextType::Constant(None) => self.module.to_ctx().get_const_val(handle),
559+
ExpressionContextType::Override => Err(proc::ConstValueError::NonConst),
582560
}
583561
}
584562

@@ -716,12 +694,14 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
716694
let index = self
717695
.module
718696
.to_ctx()
719-
.eval_expr_to_u32_from(expr, &rctx.function.expressions)
697+
.get_const_val_from::<u32, _>(expr, &rctx.function.expressions)
720698
.map_err(|err| match err {
721-
proc::U32EvalError::NonConst => {
699+
proc::ConstValueError::NonConst | proc::ConstValueError::InvalidType => {
722700
Error::ExpectedConstExprConcreteIntegerScalar(component_span)
723701
}
724-
proc::U32EvalError::Negative => Error::ExpectedNonNegative(component_span),
702+
proc::ConstValueError::Negative => {
703+
Error::ExpectedNonNegative(component_span)
704+
}
725705
})?;
726706
ir::SwizzleComponent::XYZW
727707
.get(index as usize)
@@ -1417,11 +1397,14 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
14171397
match ctx
14181398
.module
14191399
.to_ctx()
1420-
.eval_expr_to_bool_from(condition, &ctx.module.global_expressions)
1400+
.get_const_val_from(condition, &ctx.module.global_expressions)
14211401
{
1422-
Some(true) => Ok(()),
1423-
Some(false) => Err(Error::ConstAssertFailed(span)),
1424-
_ => Err(Error::NotBool(span)),
1402+
Ok(true) => Ok(()),
1403+
Ok(false) => Err(Error::ConstAssertFailed(span)),
1404+
Err(proc::ConstValueError::NonConst | proc::ConstValueError::Negative) => {
1405+
unreachable!()
1406+
}
1407+
Err(proc::ConstValueError::InvalidType) => Err(Error::NotBool(span)),
14251408
}?;
14261409
}
14271410
}
@@ -1956,14 +1939,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
19561939
match ctx
19571940
.module
19581941
.to_ctx()
1959-
.eval_expr_to_literal_from(expr, &ctx.function.expressions)
1942+
.get_const_val_from(expr, &ctx.function.expressions)
19601943
{
1961-
Some(ir::Literal::I32(value)) => {
1962-
ir::SwitchValue::I32(value)
1963-
}
1964-
Some(ir::Literal::U32(value)) => {
1965-
ir::SwitchValue::U32(value)
1966-
}
1944+
Ok(ir::Literal::I32(value)) => ir::SwitchValue::I32(value),
1945+
Ok(ir::Literal::U32(value)) => ir::SwitchValue::U32(value),
19671946
_ => {
19681947
return Err(Box::new(Error::InvalidSwitchCase {
19691948
span,
@@ -2184,11 +2163,14 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
21842163
match ctx
21852164
.module
21862165
.to_ctx()
2187-
.eval_expr_to_bool_from(condition, &ctx.function.expressions)
2166+
.get_const_val_from(condition, &ctx.function.expressions)
21882167
{
2189-
Some(true) => Ok(()),
2190-
Some(false) => Err(Error::ConstAssertFailed(span)),
2191-
_ => Err(Error::NotBool(span)),
2168+
Ok(true) => Ok(()),
2169+
Ok(false) => Err(Error::ConstAssertFailed(span)),
2170+
Err(proc::ConstValueError::NonConst | proc::ConstValueError::Negative) => {
2171+
unreachable!()
2172+
}
2173+
Err(proc::ConstValueError::InvalidType) => Err(Error::NotBool(span)),
21922174
}?;
21932175

21942176
block.extend(emitter.finish(&ctx.function.expressions));
@@ -2386,7 +2368,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
23862368
}
23872369
}
23882370

2389-
lowered_base.try_map(|base| match ctx.const_eval_expr_to_u32(index).ok() {
2371+
lowered_base.try_map(|base| match ctx.get_const_val(index).ok() {
23902372
Some(index) => Ok::<_, Box<Error>>(ir::Expression::AccessIndex { base, index }),
23912373
None => {
23922374
// When an abstract array value e is indexed by an expression
@@ -2581,7 +2563,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
25812563
result_var,
25822564
)))
25832565
} else {
2584-
let left_val = ctx.const_eval_expr_to_bool(left);
2566+
let left_val: Option<bool> = ctx.get_const_val(left).ok();
25852567

25862568
if left_val.is_some_and(|left_val| {
25872569
op == crate::BinaryOperator::LogicalAnd && !left_val
@@ -4239,10 +4221,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
42394221
let value = ctx
42404222
.module
42414223
.to_ctx()
4242-
.eval_expr_to_u32(expr)
4224+
.get_const_val(expr)
42434225
.map_err(|err| match err {
4244-
proc::U32EvalError::NonConst => Error::ExpectedConstExprConcreteIntegerScalar(span),
4245-
proc::U32EvalError::Negative => Error::ExpectedNonNegative(span),
4226+
proc::ConstValueError::NonConst | proc::ConstValueError::InvalidType => {
4227+
Error::ExpectedConstExprConcreteIntegerScalar(span)
4228+
}
4229+
proc::ConstValueError::Negative => Error::ExpectedNonNegative(span),
42464230
})?;
42474231
Ok((value, span))
42484232
}
@@ -4258,12 +4242,13 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
42584242
let const_expr = self.expression(expr, &mut ctx.as_const());
42594243
match const_expr {
42604244
Ok(value) => {
4261-
let len = ctx.const_eval_expr_to_u32(value).map_err(|err| {
4245+
let len = ctx.get_const_val(value).map_err(|err| {
42624246
Box::new(match err {
4263-
proc::U32EvalError::NonConst => {
4247+
proc::ConstValueError::NonConst
4248+
| proc::ConstValueError::InvalidType => {
42644249
Error::ExpectedConstExprConcreteIntegerScalar(span)
42654250
}
4266-
proc::U32EvalError::Negative => {
4251+
proc::ConstValueError::Negative => {
42674252
Error::ExpectedPositiveArrayLength(span)
42684253
}
42694254
})

naga/src/proc/constant_evaluator.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,11 @@ impl<'a> ConstantEvaluator<'a> {
12681268
let base = self.check_and_get(base)?;
12691269
let index = self.check_and_get(index)?;
12701270

1271-
self.access(base, self.constant_index(index)?, span)
1271+
let index_val: u32 = self
1272+
.to_ctx()
1273+
.get_const_val_from(index, self.expressions)
1274+
.map_err(|_| ConstantEvaluatorError::InvalidAccessIndexTy)?;
1275+
self.access(base, index_val as usize, span)
12721276
}
12731277
Expression::Swizzle {
12741278
size,
@@ -2116,24 +2120,6 @@ impl<'a> ConstantEvaluator<'a> {
21162120
}
21172121
}
21182122

2119-
fn constant_index(&self, expr: Handle<Expression>) -> Result<usize, ConstantEvaluatorError> {
2120-
match self.expressions[expr] {
2121-
Expression::ZeroValue(ty)
2122-
if matches!(
2123-
self.types[ty].inner,
2124-
TypeInner::Scalar(crate::Scalar {
2125-
kind: ScalarKind::Uint,
2126-
..
2127-
})
2128-
) =>
2129-
{
2130-
Ok(0)
2131-
}
2132-
Expression::Literal(Literal::U32(index)) => Ok(index as usize),
2133-
_ => Err(ConstantEvaluatorError::InvalidAccessIndexTy),
2134-
}
2135-
}
2136-
21372123
/// Lower [`ZeroValue`] and [`Splat`] expressions to [`Literal`] and [`Compose`] expressions.
21382124
///
21392125
/// [`ZeroValue`]: Expression::ZeroValue

naga/src/proc/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ impl GuardedIndex {
483483
expressions: &crate::Arena<crate::Expression>,
484484
module: &crate::Module,
485485
) -> Self {
486-
match module.to_ctx().eval_expr_to_u32_from(expr, expressions) {
486+
match module.to_ctx().get_const_val_from(expr, expressions) {
487487
Ok(value) => Self::Known(value),
488488
Err(_) => Self::Expression(expr),
489489
}

0 commit comments

Comments
 (0)