diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 372e9de5d4..3f03dc76bc 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -3127,6 +3127,11 @@ bool GeneratorImpl::EmitStructType(const sem::Struct* str) { } pre += mod; + } else if (deco->Is()) { + // Note: `precise` is not exactly the same as `invariant`, but is + // stricter and therefore provides the necessary guarantees. + // See discussion here: https://github.com/gpuweb/gpuweb/issues/893 + pre += "precise "; } else if (!deco->IsAnyOf()) { TINT_ICE(Writer, diagnostics_) diff --git a/test/shader_io/invariant.wgsl.expected.hlsl b/test/shader_io/invariant.wgsl.expected.hlsl index f0fa6fe3a9..4597e8d10e 100644 --- a/test/shader_io/invariant.wgsl.expected.hlsl +++ b/test/shader_io/invariant.wgsl.expected.hlsl @@ -1,10 +1,8 @@ -SKIP: FAILED - -../../src/writer/hlsl/generator_impl.cc:3056 internal compiler error: unhandled struct member attribute: invariant -******************************************************************** -* The tint shader compiler has encountered an unexpected error. * -* * -* Please help us fix this issue by submitting a bug report at * -* crbug.com/tint with the source program that triggered the bug. * -******************************************************************** +struct tint_symbol { + precise float4 value : SV_Position; +}; +tint_symbol main() { + const tint_symbol tint_symbol_1 = {float4(0.0f, 0.0f, 0.0f, 0.0f)}; + return tint_symbol_1; +} diff --git a/test/shader_io/invariant_struct_member.wgsl.expected.hlsl b/test/shader_io/invariant_struct_member.wgsl.expected.hlsl index f0fa6fe3a9..9090f0ed63 100644 --- a/test/shader_io/invariant_struct_member.wgsl.expected.hlsl +++ b/test/shader_io/invariant_struct_member.wgsl.expected.hlsl @@ -1,10 +1,12 @@ -SKIP: FAILED - -../../src/writer/hlsl/generator_impl.cc:3056 internal compiler error: unhandled struct member attribute: invariant -******************************************************************** -* The tint shader compiler has encountered an unexpected error. * -* * -* Please help us fix this issue by submitting a bug report at * -* crbug.com/tint with the source program that triggered the bug. * -******************************************************************** +struct Out { + float4 pos; +}; +struct tint_symbol { + precise float4 pos : SV_Position; +}; +tint_symbol main() { + const Out tint_symbol_1 = (Out)0; + const tint_symbol tint_symbol_2 = {tint_symbol_1.pos}; + return tint_symbol_2; +}