Tint: Fix extractBits polyfill

This CL fix the extractBits polyfill, used for D3D12 backend on windows.
With this patch the related CTS would get pass.

Fixed: tint:1775
Change-Id: I15636bb55af502fff773c19f03b4c3c9e99b63fd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112207
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Zhaoming Jiang 2022-11-30 23:55:28 +00:00 committed by Dawn LUCI CQ
parent 2e30a374d7
commit a54df5eca5
27 changed files with 68 additions and 54 deletions

View File

@ -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"))));

View File

@ -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<i32>, offset : u32, count : u32) -> vec3<i32> {
let e = min(32u, (s + count));
let shl = (32u - e);
let shr = (shl + s);
return ((v << vec3<u32>(shl)) >> vec3<u32>(shr));
let shl_result = select(vec3<i32>(), (v << vec3<u32>(shl)), (shl < 32u));
return select(((shl_result >> vec3<u32>(31u)) >> vec3<u32>(1u)), (shl_result >> vec3<u32>(shr)), (shr < 32u));
}
fn f() {
@ -1193,7 +1196,8 @@ fn tint_extract_bits(v : vec3<u32>, offset : u32, count : u32) -> vec3<u32> {
let e = min(32u, (s + count));
let shl = (32u - e);
let shr = (shl + s);
return ((v << vec3<u32>(shl)) >> vec3<u32>(shr));
let shl_result = select(vec3<u32>(), (v << vec3<u32>(shl)), (shl < 32u));
return select(((shl_result >> vec3<u32>(31u)) >> vec3<u32>(1u)), (shl_result >> vec3<u32>(shr)), (shr < 32u));
}
fn f() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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 ]