tint/hlsl: fix frexp always returning positive values for fractional part

Bug: tint:1876
Change-Id: Ic56b37918fd1a2a42442b517985a49f10d85159d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124501
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2023-03-16 21:31:15 +00:00
parent 8cf01eef04
commit 52cd8caa07
23 changed files with 25 additions and 65 deletions

View File

@ -2045,7 +2045,7 @@ bool GeneratorImpl::EmitFrexpCall(utils::StringStream& out,
} }
line(b) << member_type << " exp;"; line(b) << member_type << " exp;";
line(b) << member_type << " fract = frexp(" << in << ", exp);"; line(b) << member_type << " fract = sign(" << in << ") * frexp(" << in << ", exp);";
{ {
auto l = line(b); auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined,

View File

@ -606,7 +606,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f32) {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }
@ -635,7 +635,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f16) {
}; };
frexp_result_f16 tint_frexp(float16_t param_0) { frexp_result_f16 tint_frexp(float16_t param_0) {
float16_t exp; float16_t exp;
float16_t fract = frexp(param_0, exp); float16_t fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f16 result = {fract, int(exp)}; frexp_result_f16 result = {fract, int(exp)};
return result; return result;
} }
@ -662,7 +662,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f32) {
}; };
frexp_result_vec3_f32 tint_frexp(float3 param_0) { frexp_result_vec3_f32 tint_frexp(float3 param_0) {
float3 exp; float3 exp;
float3 fract = frexp(param_0, exp); float3 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f32 result = {fract, int3(exp)}; frexp_result_vec3_f32 result = {fract, int3(exp)};
return result; return result;
} }
@ -691,7 +691,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f16) {
}; };
frexp_result_vec3_f16 tint_frexp(vector<float16_t, 3> param_0) { frexp_result_vec3_f16 tint_frexp(vector<float16_t, 3> param_0) {
vector<float16_t, 3> exp; vector<float16_t, 3> exp;
vector<float16_t, 3> fract = frexp(param_0, exp); vector<float16_t, 3> fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f16 result = {fract, int3(exp)}; frexp_result_vec3_f16 result = {fract, int3(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec4_f16 {
}; };
frexp_result_vec4_f16 tint_frexp(vector<float16_t, 4> param_0) { frexp_result_vec4_f16 tint_frexp(vector<float16_t, 4> param_0) {
vector<float16_t, 4> exp; vector<float16_t, 4> exp;
vector<float16_t, 4> fract = frexp(param_0, exp); vector<float16_t, 4> fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec4_f16 result = {fract, int4(exp)}; frexp_result_vec4_f16 result = {fract, int4(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f32 {
}; };
frexp_result_f32 tint_frexp(float param_0) { frexp_result_f32 tint_frexp(float param_0) {
float exp; float exp;
float fract = frexp(param_0, exp); float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)}; frexp_result_f32 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_f16 {
}; };
frexp_result_f16 tint_frexp(float16_t param_0) { frexp_result_f16 tint_frexp(float16_t param_0) {
float16_t exp; float16_t exp;
float16_t fract = frexp(param_0, exp); float16_t fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f16 result = {fract, int(exp)}; frexp_result_f16 result = {fract, int(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f16 {
}; };
frexp_result_vec2_f16 tint_frexp(vector<float16_t, 2> param_0) { frexp_result_vec2_f16 tint_frexp(vector<float16_t, 2> param_0) {
vector<float16_t, 2> exp; vector<float16_t, 2> exp;
vector<float16_t, 2> fract = frexp(param_0, exp); vector<float16_t, 2> fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f16 result = {fract, int2(exp)}; frexp_result_vec2_f16 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec4_f32 {
}; };
frexp_result_vec4_f32 tint_frexp(float4 param_0) { frexp_result_vec4_f32 tint_frexp(float4 param_0) {
float4 exp; float4 exp;
float4 fract = frexp(param_0, exp); float4 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec4_f32 result = {fract, int4(exp)}; frexp_result_vec4_f32 result = {fract, int4(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec4_f32 {
}; };
frexp_result_vec4_f32 tint_frexp(float4 param_0) { frexp_result_vec4_f32 tint_frexp(float4 param_0) {
float4 exp; float4 exp;
float4 fract = frexp(param_0, exp); float4 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec4_f32 result = {fract, int4(exp)}; frexp_result_vec4_f32 result = {fract, int4(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec3_f32 {
}; };
frexp_result_vec3_f32 tint_frexp(float3 param_0) { frexp_result_vec3_f32 tint_frexp(float3 param_0) {
float3 exp; float3 exp;
float3 fract = frexp(param_0, exp); float3 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f32 result = {fract, int3(exp)}; frexp_result_vec3_f32 result = {fract, int3(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec3_f32 {
}; };
frexp_result_vec3_f32 tint_frexp(float3 param_0) { frexp_result_vec3_f32 tint_frexp(float3 param_0) {
float3 exp; float3 exp;
float3 fract = frexp(param_0, exp); float3 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f32 result = {fract, int3(exp)}; frexp_result_vec3_f32 result = {fract, int3(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec3_f16 {
}; };
frexp_result_vec3_f16 tint_frexp(vector<float16_t, 3> param_0) { frexp_result_vec3_f16 tint_frexp(vector<float16_t, 3> param_0) {
vector<float16_t, 3> exp; vector<float16_t, 3> exp;
vector<float16_t, 3> fract = frexp(param_0, exp); vector<float16_t, 3> fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f16 result = {fract, int3(exp)}; frexp_result_vec3_f16 result = {fract, int3(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -4,7 +4,7 @@ struct frexp_result_vec2_f32 {
}; };
frexp_result_vec2_f32 tint_frexp(float2 param_0) { frexp_result_vec2_f32 tint_frexp(float2 param_0) {
float2 exp; float2 exp;
float2 fract = frexp(param_0, exp); float2 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec2_f32 result = {fract, int2(exp)}; frexp_result_vec2_f32 result = {fract, int2(exp)};
return result; return result;
} }

View File

@ -479,46 +479,6 @@ crbug.com/dawn/1677 webgpu:api,validation,resource_usages,texture,in_pass_encode
crbug.com/dawn/1677 webgpu:api,validation,resource_usages,texture,in_pass_encoder:bindings_in_bundle:type0="render-target";type1="multisampled-texture" [ Failure ] crbug.com/dawn/1677 webgpu:api,validation,resource_usages,texture,in_pass_encoder:bindings_in_bundle:type0="render-target";type1="multisampled-texture" [ Failure ]
crbug.com/dawn/1677 webgpu:api,validation,resource_usages,texture,in_render_common:subresources,depth_stencil_attachment_and_bind_group:* [ Failure ] crbug.com/dawn/1677 webgpu:api,validation,resource_usages,texture,in_render_common:subresources,depth_stencil_attachment_and_bind_group:* [ Failure ]
################################################################################
# frexp failures on Windows
################################################################################
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec2_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec3_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_r" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="storage_rw" [ Failure ]
crbug.com/dawn/1876 [ dawn-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation intel-0x9bc5 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="uniform" [ Failure ]
crbug.com/dawn/1876 [ dawn-no-backend-validation nvidia-0x2184 win10 ] webgpu:shader,execution,expression,call,builtin,frexp:f32_vec4_fract:inputSource="uniform" [ Failure ]
################################################################################ ################################################################################
# frexp failures on Linux Intel # frexp failures on Linux Intel
################################################################################ ################################################################################