diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc index 15aa233069..62f8f4c906 100644 --- a/src/tint/transform/builtin_polyfill.cc +++ b/src/tint/transform/builtin_polyfill.cc @@ -301,8 +301,18 @@ struct BuiltinPolyfill::State { case Level::kFull: body.Push(b.Decl(b.Let("shl", b.Sub(u32(W), "e")))); body.Push(b.Decl(b.Let("shr", b.Add("shl", "s")))); - body.Push( - b.Return(b.Shr(b.Shl("v", vecN_u32(b.Expr("shl"))), vecN_u32(b.Expr("shr"))))); + // Here we don't want the shl and shr modulos the rhs, so handle the `rhs >= 32u` + // cases using `select`. In order to handle the signed shr `lhs >> rhs` corrently, + // use `(lhs >> 31u) >> 1u` if `rhs >= 32u`. + body.Push(b.Decl(b.Let("shl_result", b.Call("select", b.Construct(T(ty)), + b.Shl("v", vecN_u32(b.Expr("shl"))), + b.LessThan("shl", 32_u))))); + body.Push(b.Return(b.Call( + "select", + b.Shr(b.Shr("shl_result", vecN_u32(b.Expr(31_u))), vecN_u32(b.Expr(1_u))), + b.Shr("shl_result", vecN_u32(b.Expr("shr"))), b.LessThan("shr", 32_u)) + + )); break; case Level::kClampParameters: body.Push(b.Return(b.Call("extractBits", "v", "s", b.Sub("e", "s")))); diff --git a/src/tint/transform/builtin_polyfill_test.cc b/src/tint/transform/builtin_polyfill_test.cc index 87fd9d5cf7..1fbea9ce64 100644 --- a/src/tint/transform/builtin_polyfill_test.cc +++ b/src/tint/transform/builtin_polyfill_test.cc @@ -1109,7 +1109,8 @@ fn tint_extract_bits(v : i32, offset : u32, count : u32) -> i32 { let e = min(32u, (s + count)); let shl = (32u - e); let shr = (shl + s); - return ((v << shl) >> shr); + let shl_result = select(i32(), (v << shl), (shl < 32u)); + return select(((shl_result >> 31u) >> 1u), (shl_result >> shr), (shr < 32u)); } fn f() { @@ -1137,7 +1138,8 @@ fn tint_extract_bits(v : u32, offset : u32, count : u32) -> u32 { let e = min(32u, (s + count)); let shl = (32u - e); let shr = (shl + s); - return ((v << shl) >> shr); + let shl_result = select(u32(), (v << shl), (shl < 32u)); + return select(((shl_result >> 31u) >> 1u), (shl_result >> shr), (shr < 32u)); } fn f() { @@ -1165,7 +1167,8 @@ fn tint_extract_bits(v : vec3, offset : u32, count : u32) -> vec3 { let e = min(32u, (s + count)); let shl = (32u - e); let shr = (shl + s); - return ((v << vec3(shl)) >> vec3(shr)); + let shl_result = select(vec3(), (v << vec3(shl)), (shl < 32u)); + return select(((shl_result >> vec3(31u)) >> vec3(1u)), (shl_result >> vec3(shr)), (shr < 32u)); } fn f() { @@ -1193,7 +1196,8 @@ fn tint_extract_bits(v : vec3, offset : u32, count : u32) -> vec3 { let e = min(32u, (s + count)); let shl = (32u - e); let shr = (shl + s); - return ((v << vec3(shl)) >> vec3(shr)); + let shl_result = select(vec3(), (v << vec3(shl)), (shl < 32u)); + return select(((shl_result >> vec3(31u)) >> vec3(1u)), (shl_result >> vec3(shr)), (shr < 32u)); } fn f() { diff --git a/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.dxc.hlsl b/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.dxc.hlsl index 5857151e89..0567c8c653 100644 --- a/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.dxc.hlsl +++ b/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.dxc.hlsl @@ -3,7 +3,8 @@ int tint_extract_bits(int v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const int shl_result = ((shl < 32u) ? (v << shl) : 0); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void f_1() { diff --git a/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.fxc.hlsl b/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.fxc.hlsl index 5857151e89..0567c8c653 100644 --- a/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.fxc.hlsl +++ b/test/tint/builtins/extractBits/scalar/i32.spvasm.expected.fxc.hlsl @@ -3,7 +3,8 @@ int tint_extract_bits(int v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const int shl_result = ((shl < 32u) ? (v << shl) : 0); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void f_1() { diff --git a/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.dxc.hlsl b/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.dxc.hlsl index c82dd86de2..c356a5a2ae 100644 --- a/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.dxc.hlsl +++ b/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint tint_extract_bits(uint v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const uint shl_result = ((shl < 32u) ? (v << shl) : 0u); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void f_1() { diff --git a/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.fxc.hlsl b/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.fxc.hlsl index c82dd86de2..c356a5a2ae 100644 --- a/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.fxc.hlsl +++ b/test/tint/builtins/extractBits/scalar/u32.spvasm.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint tint_extract_bits(uint v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const uint shl_result = ((shl < 32u) ? (v << shl) : 0u); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void f_1() { diff --git a/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.dxc.hlsl b/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.dxc.hlsl index ec89a7c980..f1190c06d1 100644 --- a/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.dxc.hlsl +++ b/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.dxc.hlsl @@ -3,7 +3,8 @@ int3 tint_extract_bits(int3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const int3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void f_1() { diff --git a/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.fxc.hlsl b/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.fxc.hlsl index ec89a7c980..f1190c06d1 100644 --- a/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.fxc.hlsl +++ b/test/tint/builtins/extractBits/vec3/i32.spvasm.expected.fxc.hlsl @@ -3,7 +3,8 @@ int3 tint_extract_bits(int3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const int3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void f_1() { diff --git a/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.dxc.hlsl b/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.dxc.hlsl index c9b84dcda4..6786f5a245 100644 --- a/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.dxc.hlsl +++ b/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint3 tint_extract_bits(uint3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const uint3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0u).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void f_1() { diff --git a/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.fxc.hlsl b/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.fxc.hlsl index c9b84dcda4..6786f5a245 100644 --- a/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.fxc.hlsl +++ b/test/tint/builtins/extractBits/vec3/u32.spvasm.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint3 tint_extract_bits(uint3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const uint3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0u).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void f_1() { diff --git a/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.dxc.hlsl index d5d112534f..357f955fdb 100644 --- a/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint3 tint_extract_bits(uint3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const uint3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0u).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void extractBits_12b197() { diff --git a/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.fxc.hlsl index d5d112534f..357f955fdb 100644 --- a/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/12b197.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint3 tint_extract_bits(uint3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const uint3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0u).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void extractBits_12b197() { diff --git a/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.dxc.hlsl index bd0e6fe47e..0ae62b5efe 100644 --- a/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ int tint_extract_bits(int v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const int shl_result = ((shl < 32u) ? (v << shl) : 0); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void extractBits_249874() { diff --git a/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.fxc.hlsl index bd0e6fe47e..0ae62b5efe 100644 --- a/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/249874.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ int tint_extract_bits(int v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const int shl_result = ((shl < 32u) ? (v << shl) : 0); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void extractBits_249874() { diff --git a/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.dxc.hlsl index 5f5832cab7..fddff8115d 100644 --- a/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint4 tint_extract_bits(uint4 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint4((shl).xxxx)) >> uint4((shr).xxxx)); + const uint4 shl_result = ((shl < 32u) ? (v << uint4((shl).xxxx)) : (0u).xxxx); + return ((shr < 32u) ? (shl_result >> uint4((shr).xxxx)) : ((shl_result >> (31u).xxxx) >> (1u).xxxx)); } void extractBits_631377() { diff --git a/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.fxc.hlsl index 5f5832cab7..fddff8115d 100644 --- a/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/631377.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint4 tint_extract_bits(uint4 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint4((shl).xxxx)) >> uint4((shr).xxxx)); + const uint4 shl_result = ((shl < 32u) ? (v << uint4((shl).xxxx)) : (0u).xxxx); + return ((shr < 32u) ? (shl_result >> uint4((shr).xxxx)) : ((shl_result >> (31u).xxxx) >> (1u).xxxx)); } void extractBits_631377() { diff --git a/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.dxc.hlsl index 4971f269a4..dc1c74df92 100644 --- a/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ int2 tint_extract_bits(int2 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint2((shl).xx)) >> uint2((shr).xx)); + const int2 shl_result = ((shl < 32u) ? (v << uint2((shl).xx)) : (0).xx); + return ((shr < 32u) ? (shl_result >> uint2((shr).xx)) : ((shl_result >> (31u).xx) >> (1u).xx)); } void extractBits_a99a8d() { diff --git a/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.fxc.hlsl index 4971f269a4..dc1c74df92 100644 --- a/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/a99a8d.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ int2 tint_extract_bits(int2 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint2((shl).xx)) >> uint2((shr).xx)); + const int2 shl_result = ((shl < 32u) ? (v << uint2((shl).xx)) : (0).xx); + return ((shr < 32u) ? (shl_result >> uint2((shr).xx)) : ((shl_result >> (31u).xx) >> (1u).xx)); } void extractBits_a99a8d() { diff --git a/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.dxc.hlsl index 944fe861ff..8fb330f47c 100644 --- a/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint tint_extract_bits(uint v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const uint shl_result = ((shl < 32u) ? (v << shl) : 0u); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void extractBits_ce81f8() { diff --git a/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.fxc.hlsl index 944fe861ff..8fb330f47c 100644 --- a/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/ce81f8.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint tint_extract_bits(uint v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << shl) >> shr); + const uint shl_result = ((shl < 32u) ? (v << shl) : 0u); + return ((shr < 32u) ? (shl_result >> shr) : ((shl_result >> 31u) >> 1u)); } void extractBits_ce81f8() { diff --git a/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.dxc.hlsl index c45a595f13..b0c453f245 100644 --- a/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ int3 tint_extract_bits(int3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const int3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void extractBits_e04f5d() { diff --git a/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.fxc.hlsl index c45a595f13..b0c453f245 100644 --- a/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/e04f5d.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ int3 tint_extract_bits(int3 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint3((shl).xxx)) >> uint3((shr).xxx)); + const int3 shl_result = ((shl < 32u) ? (v << uint3((shl).xxx)) : (0).xxx); + return ((shr < 32u) ? (shl_result >> uint3((shr).xxx)) : ((shl_result >> (31u).xxx) >> (1u).xxx)); } void extractBits_e04f5d() { diff --git a/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.dxc.hlsl index c56231c894..88b2c88325 100644 --- a/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ uint2 tint_extract_bits(uint2 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint2((shl).xx)) >> uint2((shr).xx)); + const uint2 shl_result = ((shl < 32u) ? (v << uint2((shl).xx)) : (0u).xx); + return ((shr < 32u) ? (shl_result >> uint2((shr).xx)) : ((shl_result >> (31u).xx) >> (1u).xx)); } void extractBits_f28f69() { diff --git a/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.fxc.hlsl index c56231c894..88b2c88325 100644 --- a/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/f28f69.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ uint2 tint_extract_bits(uint2 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint2((shl).xx)) >> uint2((shr).xx)); + const uint2 shl_result = ((shl < 32u) ? (v << uint2((shl).xx)) : (0u).xx); + return ((shr < 32u) ? (shl_result >> uint2((shr).xx)) : ((shl_result >> (31u).xx) >> (1u).xx)); } void extractBits_f28f69() { diff --git a/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.dxc.hlsl index 40ab22ce85..b1452a7b0a 100644 --- a/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.dxc.hlsl @@ -3,7 +3,8 @@ int4 tint_extract_bits(int4 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint4((shl).xxxx)) >> uint4((shr).xxxx)); + const int4 shl_result = ((shl < 32u) ? (v << uint4((shl).xxxx)) : (0).xxxx); + return ((shr < 32u) ? (shl_result >> uint4((shr).xxxx)) : ((shl_result >> (31u).xxxx) >> (1u).xxxx)); } void extractBits_fb850f() { diff --git a/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.fxc.hlsl index 40ab22ce85..b1452a7b0a 100644 --- a/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/extractBits/fb850f.wgsl.expected.fxc.hlsl @@ -3,7 +3,8 @@ int4 tint_extract_bits(int4 v, uint offset, uint count) { const uint e = min(32u, (s + count)); const uint shl = (32u - e); const uint shr = (shl + s); - return ((v << uint4((shl).xxxx)) >> uint4((shr).xxxx)); + const int4 shl_result = ((shl < 32u) ? (v << uint4((shl).xxxx)) : (0).xxxx); + return ((shr < 32u) ? (shl_result >> uint4((shr).xxxx)) : ((shl_result >> (31u).xxxx) >> (1u).xxxx)); } void extractBits_fb850f() { diff --git a/webgpu-cts/expectations.txt b/webgpu-cts/expectations.txt index 91d3e2c230..dbeedece3d 100644 --- a/webgpu-cts/expectations.txt +++ b/webgpu-cts/expectations.txt @@ -219,30 +219,6 @@ crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,do crbug.com/dawn/0000 [ monterey ] webgpu:shader,execution,expression,call,builtin,dot:f32_vec4:* [ Failure ] crbug.com/dawn/0000 [ ubuntu ] webgpu:shader,execution,expression,call,builtin,dot:f32_vec4:inputSource="const" [ Failure ] crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,dot:f32_vec4:inputSource="const" [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_r";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_r";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_r";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_r";width=4 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_rw";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_rw";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_rw";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="storage_rw";width=4 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="uniform";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="uniform";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="uniform";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:i32:inputSource="uniform";width=4 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_r";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_r";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_r";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_r";width=4 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_rw";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_rw";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_rw";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="storage_rw";width=4 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="uniform";width=1 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="uniform";width=2 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="uniform";width=3 [ Failure ] -crbug.com/dawn/0000 [ win10 ] webgpu:shader,execution,expression,call,builtin,extractBits:u32:inputSource="uniform";width=4 [ Failure ] crbug.com/dawn/0000 [ intel-gen-9 ubuntu ] webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="storage_r";vectorize="_undef_" [ Failure ] crbug.com/dawn/0000 [ intel-gen-9 ubuntu ] webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="storage_r";vectorize=2 [ Failure ] crbug.com/dawn/0000 [ intel-gen-9 ubuntu ] webgpu:shader,execution,expression,call,builtin,firstTrailingBit:i32:inputSource="storage_r";vectorize=3 [ Failure ]