Add const-eval for `any`.

This CL adds const-eval for the `any` builtin.

Bug: tint:1581
Change-Id: I32d8946b3cd5c6d210b75104fa37c4d1ef6a6f84
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107542
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-10-29 16:21:24 +00:00 committed by Dawn LUCI CQ
parent 7494e10f91
commit 8a523d7d8e
24 changed files with 4818 additions and 4783 deletions

View File

@ -412,8 +412,8 @@ fn acosh<T: f32_f16>(T) -> T
fn acosh<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T> fn acosh<N: num, T: f32_f16>(vec<N, T>) -> vec<N, T>
fn all(bool) -> bool fn all(bool) -> bool
fn all<N: num>(vec<N, bool>) -> bool fn all<N: num>(vec<N, bool>) -> bool
fn any(bool) -> bool @const fn any(bool) -> bool
fn any<N: num>(vec<N, bool>) -> bool @const fn any<N: num>(vec<N, bool>) -> bool
fn arrayLength<T, A: access>(ptr<storage, array<T>, A>) -> u32 fn arrayLength<T, A: access>(ptr<storage, array<T>, A>) -> u32
@const fn asin<T: fa_f32_f16>(@test_value(0.479425538604) T) -> T @const fn asin<T: fa_f32_f16>(@test_value(0.479425538604) T) -> T
@const fn asin<N: num, T: fa_f32_f16>(@test_value(0.479425538604) vec<N, T>) -> vec<N, T> @const fn asin<N: num, T: fa_f32_f16>(@test_value(0.479425538604) vec<N, T>) -> vec<N, T>

View File

@ -1536,6 +1536,12 @@ ConstEval::Result ConstEval::OpShiftLeft(const sem::Type* ty,
return r; return r;
} }
ConstEval::Result ConstEval::any(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source&) {
return CreateElement(builder, ty, !args[0]->AllZero());
}
ConstEval::Result ConstEval::asin(const sem::Type* ty, ConstEval::Result ConstEval::asin(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args, utils::VectorRef<const sem::Constant*> args,
const Source& source) { const Source& source) {

View File

@ -377,6 +377,15 @@ class ConstEval {
// Builtins // Builtins
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/// any builtin
/// @param ty the expression type
/// @param args the input arguments
/// @param source the source location of the conversion
/// @return the result value, or null if the value cannot be calculated
Result any(const sem::Type* ty,
utils::VectorRef<const sem::Constant*> args,
const Source& source);
/// asin builtin /// asin builtin
/// @param ty the expression type /// @param ty the expression type
/// @param args the input arguments /// @param args the input arguments

View File

@ -146,6 +146,35 @@ INSTANTIATE_TEST_SUITE_P( //
C({1.0_a, 0_a}, kPiOver2<AFloat>), C({1.0_a, 0_a}, kPiOver2<AFloat>),
}))); })));
static std::vector<Case> AnyCases() {
return {
C({Val(true)}, Val(true)),
C({Val(false)}, Val(false)),
C({Vec(true, true)}, Val(true)),
C({Vec(true, false)}, Val(true)),
C({Vec(false, true)}, Val(true)),
C({Vec(false, false)}, Val(false)),
C({Vec(true, true, true)}, Val(true)),
C({Vec(false, true, true)}, Val(true)),
C({Vec(true, false, true)}, Val(true)),
C({Vec(true, true, false)}, Val(true)),
C({Vec(false, false, false)}, Val(false)),
C({Vec(true, true, true, true)}, Val(true)),
C({Vec(false, true, true, true)}, Val(true)),
C({Vec(true, false, true, true)}, Val(true)),
C({Vec(true, true, false, true)}, Val(true)),
C({Vec(true, true, true, false)}, Val(true)),
C({Vec(false, false, false, false)}, Val(false)),
};
}
INSTANTIATE_TEST_SUITE_P( //
Any,
ResolverConstEvalBuiltinTest,
testing::Combine(testing::Values(sem::BuiltinType::kAny), testing::ValuesIn(AnyCases())));
template <typename T, bool finite_only> template <typename T, bool finite_only>
std::vector<Case> Atan2Cases() { std::vector<Case> Atan2Cases() {
std::vector<Case> cases = { std::vector<Case> cases = {

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
void any_083428() { void any_083428() {
bool res = any((true).xxxx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,5 +1,5 @@
void any_083428() { void any_083428() {
bool res = any((true).xxxx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
#version 310 es #version 310 es
void any_083428() { void any_083428() {
bool res = any(bvec4(true)); bool res = true;
} }
vec4 vertex_main() { vec4 vertex_main() {
@ -21,7 +21,7 @@ void main() {
precision mediump float; precision mediump float;
void any_083428() { void any_083428() {
bool res = any(bvec4(true)); bool res = true;
} }
void fragment_main() { void fragment_main() {
@ -35,7 +35,7 @@ void main() {
#version 310 es #version 310 es
void any_083428() { void any_083428() {
bool res = any(bvec4(true)); bool res = true;
} }
void compute_main() { void compute_main() {

View File

@ -2,7 +2,7 @@
using namespace metal; using namespace metal;
void any_083428() { void any_083428() {
bool res = any(bool4(true)); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 35 ; Bound: 32
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -31,39 +31,36 @@
%void = OpTypeVoid %void = OpTypeVoid
%9 = OpTypeFunction %void %9 = OpTypeFunction %void
%bool = OpTypeBool %bool = OpTypeBool
%v4bool = OpTypeVector %bool 4
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%17 = OpConstantComposite %v4bool %true %true %true %true
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%20 = OpConstantNull %bool %17 = OpConstantNull %bool
%21 = OpTypeFunction %v4float %18 = OpTypeFunction %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%any_083428 = OpFunction %void None %9 %any_083428 = OpFunction %void None %9
%12 = OpLabel %12 = OpLabel
%res = OpVariable %_ptr_Function_bool Function %20 %res = OpVariable %_ptr_Function_bool Function %17
%13 = OpAny %bool %17 OpStore %res %true
OpStore %res %13
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%vertex_main_inner = OpFunction %v4float None %21 %vertex_main_inner = OpFunction %v4float None %18
%23 = OpLabel %20 = OpLabel
%24 = OpFunctionCall %void %any_083428 %21 = OpFunctionCall %void %any_083428
OpReturnValue %5 OpReturnValue %5
OpFunctionEnd OpFunctionEnd
%vertex_main = OpFunction %void None %9 %vertex_main = OpFunction %void None %9
%26 = OpLabel %23 = OpLabel
%27 = OpFunctionCall %v4float %vertex_main_inner %24 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %27 OpStore %value %24
OpStore %vertex_point_size %float_1 OpStore %vertex_point_size %float_1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %9 %fragment_main = OpFunction %void None %9
%27 = OpLabel
%28 = OpFunctionCall %void %any_083428
OpReturn
OpFunctionEnd
%compute_main = OpFunction %void None %9
%30 = OpLabel %30 = OpLabel
%31 = OpFunctionCall %void %any_083428 %31 = OpFunctionCall %void %any_083428
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %9
%33 = OpLabel
%34 = OpFunctionCall %void %any_083428
OpReturn
OpFunctionEnd

View File

@ -1,5 +1,5 @@
void any_0e3e58() { void any_0e3e58() {
bool res = any((true).xx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,5 +1,5 @@
void any_0e3e58() { void any_0e3e58() {
bool res = any((true).xx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
#version 310 es #version 310 es
void any_0e3e58() { void any_0e3e58() {
bool res = any(bvec2(true)); bool res = true;
} }
vec4 vertex_main() { vec4 vertex_main() {
@ -21,7 +21,7 @@ void main() {
precision mediump float; precision mediump float;
void any_0e3e58() { void any_0e3e58() {
bool res = any(bvec2(true)); bool res = true;
} }
void fragment_main() { void fragment_main() {
@ -35,7 +35,7 @@ void main() {
#version 310 es #version 310 es
void any_0e3e58() { void any_0e3e58() {
bool res = any(bvec2(true)); bool res = true;
} }
void compute_main() { void compute_main() {

View File

@ -2,7 +2,7 @@
using namespace metal; using namespace metal;
void any_0e3e58() { void any_0e3e58() {
bool res = any(bool2(true)); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 35 ; Bound: 32
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -31,39 +31,36 @@
%void = OpTypeVoid %void = OpTypeVoid
%9 = OpTypeFunction %void %9 = OpTypeFunction %void
%bool = OpTypeBool %bool = OpTypeBool
%v2bool = OpTypeVector %bool 2
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%17 = OpConstantComposite %v2bool %true %true
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%20 = OpConstantNull %bool %17 = OpConstantNull %bool
%21 = OpTypeFunction %v4float %18 = OpTypeFunction %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%any_0e3e58 = OpFunction %void None %9 %any_0e3e58 = OpFunction %void None %9
%12 = OpLabel %12 = OpLabel
%res = OpVariable %_ptr_Function_bool Function %20 %res = OpVariable %_ptr_Function_bool Function %17
%13 = OpAny %bool %17 OpStore %res %true
OpStore %res %13
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%vertex_main_inner = OpFunction %v4float None %21 %vertex_main_inner = OpFunction %v4float None %18
%23 = OpLabel %20 = OpLabel
%24 = OpFunctionCall %void %any_0e3e58 %21 = OpFunctionCall %void %any_0e3e58
OpReturnValue %5 OpReturnValue %5
OpFunctionEnd OpFunctionEnd
%vertex_main = OpFunction %void None %9 %vertex_main = OpFunction %void None %9
%26 = OpLabel %23 = OpLabel
%27 = OpFunctionCall %v4float %vertex_main_inner %24 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %27 OpStore %value %24
OpStore %vertex_point_size %float_1 OpStore %vertex_point_size %float_1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %9 %fragment_main = OpFunction %void None %9
%27 = OpLabel
%28 = OpFunctionCall %void %any_0e3e58
OpReturn
OpFunctionEnd
%compute_main = OpFunction %void None %9
%30 = OpLabel %30 = OpLabel
%31 = OpFunctionCall %void %any_0e3e58 %31 = OpFunctionCall %void %any_0e3e58
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %9
%33 = OpLabel
%34 = OpFunctionCall %void %any_0e3e58
OpReturn
OpFunctionEnd

View File

@ -1,5 +1,5 @@
void any_2ab91a() { void any_2ab91a() {
bool res = any(true); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,5 +1,5 @@
void any_2ab91a() { void any_2ab91a() {
bool res = any(true); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -2,7 +2,7 @@
using namespace metal; using namespace metal;
void any_2ab91a() { void any_2ab91a() {
bool res = any(true); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 33 ; Bound: 32
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -33,34 +33,34 @@
%bool = OpTypeBool %bool = OpTypeBool
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%18 = OpConstantNull %bool %17 = OpConstantNull %bool
%19 = OpTypeFunction %v4float %18 = OpTypeFunction %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%any_2ab91a = OpFunction %void None %9 %any_2ab91a = OpFunction %void None %9
%12 = OpLabel %12 = OpLabel
%res = OpVariable %_ptr_Function_bool Function %18 %res = OpVariable %_ptr_Function_bool Function %17
OpStore %res %true OpStore %res %true
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%vertex_main_inner = OpFunction %v4float None %19 %vertex_main_inner = OpFunction %v4float None %18
%21 = OpLabel %20 = OpLabel
%22 = OpFunctionCall %void %any_2ab91a %21 = OpFunctionCall %void %any_2ab91a
OpReturnValue %5 OpReturnValue %5
OpFunctionEnd OpFunctionEnd
%vertex_main = OpFunction %void None %9 %vertex_main = OpFunction %void None %9
%24 = OpLabel %23 = OpLabel
%25 = OpFunctionCall %v4float %vertex_main_inner %24 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %25 OpStore %value %24
OpStore %vertex_point_size %float_1 OpStore %vertex_point_size %float_1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %9 %fragment_main = OpFunction %void None %9
%28 = OpLabel %27 = OpLabel
%29 = OpFunctionCall %void %any_2ab91a %28 = OpFunctionCall %void %any_2ab91a
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %9 %compute_main = OpFunction %void None %9
%31 = OpLabel %30 = OpLabel
%32 = OpFunctionCall %void %any_2ab91a %31 = OpFunctionCall %void %any_2ab91a
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,5 +1,5 @@
void any_e755c1() { void any_e755c1() {
bool res = any((true).xxx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,5 +1,5 @@
void any_e755c1() { void any_e755c1() {
bool res = any((true).xxx); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
#version 310 es #version 310 es
void any_e755c1() { void any_e755c1() {
bool res = any(bvec3(true)); bool res = true;
} }
vec4 vertex_main() { vec4 vertex_main() {
@ -21,7 +21,7 @@ void main() {
precision mediump float; precision mediump float;
void any_e755c1() { void any_e755c1() {
bool res = any(bvec3(true)); bool res = true;
} }
void fragment_main() { void fragment_main() {
@ -35,7 +35,7 @@ void main() {
#version 310 es #version 310 es
void any_e755c1() { void any_e755c1() {
bool res = any(bvec3(true)); bool res = true;
} }
void compute_main() { void compute_main() {

View File

@ -2,7 +2,7 @@
using namespace metal; using namespace metal;
void any_e755c1() { void any_e755c1() {
bool res = any(bool3(true)); bool res = true;
} }
struct tint_symbol { struct tint_symbol {

View File

@ -1,7 +1,7 @@
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 35 ; Bound: 32
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -31,39 +31,36 @@
%void = OpTypeVoid %void = OpTypeVoid
%9 = OpTypeFunction %void %9 = OpTypeFunction %void
%bool = OpTypeBool %bool = OpTypeBool
%v3bool = OpTypeVector %bool 3
%true = OpConstantTrue %bool %true = OpConstantTrue %bool
%17 = OpConstantComposite %v3bool %true %true %true
%_ptr_Function_bool = OpTypePointer Function %bool %_ptr_Function_bool = OpTypePointer Function %bool
%20 = OpConstantNull %bool %17 = OpConstantNull %bool
%21 = OpTypeFunction %v4float %18 = OpTypeFunction %v4float
%float_1 = OpConstant %float 1 %float_1 = OpConstant %float 1
%any_e755c1 = OpFunction %void None %9 %any_e755c1 = OpFunction %void None %9
%12 = OpLabel %12 = OpLabel
%res = OpVariable %_ptr_Function_bool Function %20 %res = OpVariable %_ptr_Function_bool Function %17
%13 = OpAny %bool %17 OpStore %res %true
OpStore %res %13
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%vertex_main_inner = OpFunction %v4float None %21 %vertex_main_inner = OpFunction %v4float None %18
%23 = OpLabel %20 = OpLabel
%24 = OpFunctionCall %void %any_e755c1 %21 = OpFunctionCall %void %any_e755c1
OpReturnValue %5 OpReturnValue %5
OpFunctionEnd OpFunctionEnd
%vertex_main = OpFunction %void None %9 %vertex_main = OpFunction %void None %9
%26 = OpLabel %23 = OpLabel
%27 = OpFunctionCall %v4float %vertex_main_inner %24 = OpFunctionCall %v4float %vertex_main_inner
OpStore %value %27 OpStore %value %24
OpStore %vertex_point_size %float_1 OpStore %vertex_point_size %float_1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %9 %fragment_main = OpFunction %void None %9
%27 = OpLabel
%28 = OpFunctionCall %void %any_e755c1
OpReturn
OpFunctionEnd
%compute_main = OpFunction %void None %9
%30 = OpLabel %30 = OpLabel
%31 = OpFunctionCall %void %any_e755c1 %31 = OpFunctionCall %void %any_e755c1
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %9
%33 = OpLabel
%34 = OpFunctionCall %void %any_e755c1
OpReturn
OpFunctionEnd