From d7255e37f68914d135ac01e56ec284c545735c1e Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 7 Jun 2021 20:01:54 +0000 Subject: [PATCH] writer/hlsl: Emit vector-of-bool as boolN Much like uintN, intN, floatN - boolN is far more common, and easier to read than vector Change-Id: I51f9edc003c590266316d3eba286ca2f6882da10 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53390 Kokoro: Kokoro Reviewed-by: Antonio Maiorano Reviewed-by: James Price --- src/writer/hlsl/generator_impl.cc | 2 ++ src/writer/hlsl/generator_impl_intrinsic_test.cc | 3 +-- test/intrinsics/gen/all/986c7b.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/all/bd2dba.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/all/f46790.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/any/083428.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/any/0e3e58.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/any/e755c1.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isFinite/34d32b.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isFinite/8a23ad.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isFinite/f31987.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isInf/666f2a.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isInf/7e81b5.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/isInf/a46d6f.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/00b848.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/01e2cd.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/1e960b.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/266aff.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/28a27e.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/80a9a9.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/a2860e.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/bb8aae.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/c4a4ef.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/cb9301.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/e3e028.wgsl.expected.hlsl | 2 +- test/intrinsics/gen/select/ebfea2.wgsl.expected.hlsl | 2 +- 26 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 40f90e1235..22963c3721 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2479,6 +2479,8 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << "int" << size; } else if (vec->type()->Is() && size >= 1 && size <= 4) { out << "uint" << size; + } else if (vec->type()->Is() && size >= 1 && size <= 4) { + out << "bool" << size; } else { out << "vector<"; if (!EmitType(out, vec->type(), storage_class, access, "")) { diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index 314ead212a..1dfdea055c 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -290,8 +290,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Vector) { gen.increment_indent(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); - EXPECT_EQ(result(), - "(vector(true, false) ? int2(1, 2) : int2(3, 4))"); + EXPECT_EQ(result(), "(bool2(true, false) ? int2(1, 2) : int2(3, 4))"); } TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) { diff --git a/test/intrinsics/gen/all/986c7b.wgsl.expected.hlsl b/test/intrinsics/gen/all/986c7b.wgsl.expected.hlsl index ed1d46053e..5813269168 100644 --- a/test/intrinsics/gen/all/986c7b.wgsl.expected.hlsl +++ b/test/intrinsics/gen/all/986c7b.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void all_986c7b() { - bool res = all(vector(false, false, false, false)); + bool res = all(bool4(false, false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/all/bd2dba.wgsl.expected.hlsl b/test/intrinsics/gen/all/bd2dba.wgsl.expected.hlsl index 93b3bba06e..5b6b8edb0a 100644 --- a/test/intrinsics/gen/all/bd2dba.wgsl.expected.hlsl +++ b/test/intrinsics/gen/all/bd2dba.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void all_bd2dba() { - bool res = all(vector(false, false, false)); + bool res = all(bool3(false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/all/f46790.wgsl.expected.hlsl b/test/intrinsics/gen/all/f46790.wgsl.expected.hlsl index d4d0393e52..8839cf0801 100644 --- a/test/intrinsics/gen/all/f46790.wgsl.expected.hlsl +++ b/test/intrinsics/gen/all/f46790.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void all_f46790() { - bool res = all(vector(false, false)); + bool res = all(bool2(false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/any/083428.wgsl.expected.hlsl b/test/intrinsics/gen/any/083428.wgsl.expected.hlsl index e70364e2f8..c3271b0480 100644 --- a/test/intrinsics/gen/any/083428.wgsl.expected.hlsl +++ b/test/intrinsics/gen/any/083428.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void any_083428() { - bool res = any(vector(false, false, false, false)); + bool res = any(bool4(false, false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/any/0e3e58.wgsl.expected.hlsl b/test/intrinsics/gen/any/0e3e58.wgsl.expected.hlsl index 0b9d54a71f..2a86e563b3 100644 --- a/test/intrinsics/gen/any/0e3e58.wgsl.expected.hlsl +++ b/test/intrinsics/gen/any/0e3e58.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void any_0e3e58() { - bool res = any(vector(false, false)); + bool res = any(bool2(false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/any/e755c1.wgsl.expected.hlsl b/test/intrinsics/gen/any/e755c1.wgsl.expected.hlsl index 1130198771..3b80182cdd 100644 --- a/test/intrinsics/gen/any/e755c1.wgsl.expected.hlsl +++ b/test/intrinsics/gen/any/e755c1.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void any_e755c1() { - bool res = any(vector(false, false, false)); + bool res = any(bool3(false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isFinite/34d32b.wgsl.expected.hlsl b/test/intrinsics/gen/isFinite/34d32b.wgsl.expected.hlsl index fd5747e974..138a1e19ff 100644 --- a/test/intrinsics/gen/isFinite/34d32b.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isFinite/34d32b.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isFinite_34d32b() { - vector res = isfinite(float2(0.0f, 0.0f)); + bool2 res = isfinite(float2(0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isFinite/8a23ad.wgsl.expected.hlsl b/test/intrinsics/gen/isFinite/8a23ad.wgsl.expected.hlsl index 010d015f4b..646590d990 100644 --- a/test/intrinsics/gen/isFinite/8a23ad.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isFinite/8a23ad.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isFinite_8a23ad() { - vector res = isfinite(float3(0.0f, 0.0f, 0.0f)); + bool3 res = isfinite(float3(0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isFinite/f31987.wgsl.expected.hlsl b/test/intrinsics/gen/isFinite/f31987.wgsl.expected.hlsl index ba30f1a218..829735166a 100644 --- a/test/intrinsics/gen/isFinite/f31987.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isFinite/f31987.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isFinite_f31987() { - vector res = isfinite(float4(0.0f, 0.0f, 0.0f, 0.0f)); + bool4 res = isfinite(float4(0.0f, 0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isInf/666f2a.wgsl.expected.hlsl b/test/intrinsics/gen/isInf/666f2a.wgsl.expected.hlsl index c18d7bbe03..0d885e0ea2 100644 --- a/test/intrinsics/gen/isInf/666f2a.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isInf/666f2a.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isInf_666f2a() { - vector res = isinf(float3(0.0f, 0.0f, 0.0f)); + bool3 res = isinf(float3(0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isInf/7e81b5.wgsl.expected.hlsl b/test/intrinsics/gen/isInf/7e81b5.wgsl.expected.hlsl index c7019e2011..b1f7ad6db6 100644 --- a/test/intrinsics/gen/isInf/7e81b5.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isInf/7e81b5.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isInf_7e81b5() { - vector res = isinf(float4(0.0f, 0.0f, 0.0f, 0.0f)); + bool4 res = isinf(float4(0.0f, 0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/isInf/a46d6f.wgsl.expected.hlsl b/test/intrinsics/gen/isInf/a46d6f.wgsl.expected.hlsl index 93d5e9e194..e87b8826ae 100644 --- a/test/intrinsics/gen/isInf/a46d6f.wgsl.expected.hlsl +++ b/test/intrinsics/gen/isInf/a46d6f.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void isInf_a46d6f() { - vector res = isinf(float2(0.0f, 0.0f)); + bool2 res = isinf(float2(0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/00b848.wgsl.expected.hlsl b/test/intrinsics/gen/select/00b848.wgsl.expected.hlsl index 7c4709c8c6..ec293211f2 100644 --- a/test/intrinsics/gen/select/00b848.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/00b848.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_00b848() { - int2 res = (vector(false, false) ? int2(0, 0) : int2(0, 0)); + int2 res = (bool2(false, false) ? int2(0, 0) : int2(0, 0)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/01e2cd.wgsl.expected.hlsl b/test/intrinsics/gen/select/01e2cd.wgsl.expected.hlsl index f94a217c3f..9aac2c03ba 100644 --- a/test/intrinsics/gen/select/01e2cd.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/01e2cd.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_01e2cd() { - int3 res = (vector(false, false, false) ? int3(0, 0, 0) : int3(0, 0, 0)); + int3 res = (bool3(false, false, false) ? int3(0, 0, 0) : int3(0, 0, 0)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/1e960b.wgsl.expected.hlsl b/test/intrinsics/gen/select/1e960b.wgsl.expected.hlsl index 8a476b888e..adb0fe4d18 100644 --- a/test/intrinsics/gen/select/1e960b.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/1e960b.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_1e960b() { - uint2 res = (vector(false, false) ? uint2(0u, 0u) : uint2(0u, 0u)); + uint2 res = (bool2(false, false) ? uint2(0u, 0u) : uint2(0u, 0u)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/266aff.wgsl.expected.hlsl b/test/intrinsics/gen/select/266aff.wgsl.expected.hlsl index 430c689e7e..dbe0b9234c 100644 --- a/test/intrinsics/gen/select/266aff.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/266aff.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_266aff() { - float2 res = (vector(false, false) ? float2(0.0f, 0.0f) : float2(0.0f, 0.0f)); + float2 res = (bool2(false, false) ? float2(0.0f, 0.0f) : float2(0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/28a27e.wgsl.expected.hlsl b/test/intrinsics/gen/select/28a27e.wgsl.expected.hlsl index ad1d9923a7..de68cc14e6 100644 --- a/test/intrinsics/gen/select/28a27e.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/28a27e.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_28a27e() { - uint3 res = (vector(false, false, false) ? uint3(0u, 0u, 0u) : uint3(0u, 0u, 0u)); + uint3 res = (bool3(false, false, false) ? uint3(0u, 0u, 0u) : uint3(0u, 0u, 0u)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/80a9a9.wgsl.expected.hlsl b/test/intrinsics/gen/select/80a9a9.wgsl.expected.hlsl index f0700b10e7..d98233bfc8 100644 --- a/test/intrinsics/gen/select/80a9a9.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/80a9a9.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_80a9a9() { - vector res = (vector(false, false, false) ? vector(false, false, false) : vector(false, false, false)); + bool3 res = (bool3(false, false, false) ? bool3(false, false, false) : bool3(false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/a2860e.wgsl.expected.hlsl b/test/intrinsics/gen/select/a2860e.wgsl.expected.hlsl index 6266236e58..5dd5d64e8f 100644 --- a/test/intrinsics/gen/select/a2860e.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/a2860e.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_a2860e() { - int4 res = (vector(false, false, false, false) ? int4(0, 0, 0, 0) : int4(0, 0, 0, 0)); + int4 res = (bool4(false, false, false, false) ? int4(0, 0, 0, 0) : int4(0, 0, 0, 0)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/bb8aae.wgsl.expected.hlsl b/test/intrinsics/gen/select/bb8aae.wgsl.expected.hlsl index 55e26b878d..2660cecf89 100644 --- a/test/intrinsics/gen/select/bb8aae.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/bb8aae.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_bb8aae() { - float4 res = (vector(false, false, false, false) ? float4(0.0f, 0.0f, 0.0f, 0.0f) : float4(0.0f, 0.0f, 0.0f, 0.0f)); + float4 res = (bool4(false, false, false, false) ? float4(0.0f, 0.0f, 0.0f, 0.0f) : float4(0.0f, 0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/c4a4ef.wgsl.expected.hlsl b/test/intrinsics/gen/select/c4a4ef.wgsl.expected.hlsl index b5c3056372..11845c3460 100644 --- a/test/intrinsics/gen/select/c4a4ef.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/c4a4ef.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_c4a4ef() { - uint4 res = (vector(false, false, false, false) ? uint4(0u, 0u, 0u, 0u) : uint4(0u, 0u, 0u, 0u)); + uint4 res = (bool4(false, false, false, false) ? uint4(0u, 0u, 0u, 0u) : uint4(0u, 0u, 0u, 0u)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/cb9301.wgsl.expected.hlsl b/test/intrinsics/gen/select/cb9301.wgsl.expected.hlsl index 5041d269ae..3e35b51673 100644 --- a/test/intrinsics/gen/select/cb9301.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/cb9301.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_cb9301() { - vector res = (vector(false, false) ? vector(false, false) : vector(false, false)); + bool2 res = (bool2(false, false) ? bool2(false, false) : bool2(false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/e3e028.wgsl.expected.hlsl b/test/intrinsics/gen/select/e3e028.wgsl.expected.hlsl index f65fa64332..f9d7c076d0 100644 --- a/test/intrinsics/gen/select/e3e028.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/e3e028.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_e3e028() { - vector res = (vector(false, false, false, false) ? vector(false, false, false, false) : vector(false, false, false, false)); + bool4 res = (bool4(false, false, false, false) ? bool4(false, false, false, false) : bool4(false, false, false, false)); } tint_symbol vertex_main() { diff --git a/test/intrinsics/gen/select/ebfea2.wgsl.expected.hlsl b/test/intrinsics/gen/select/ebfea2.wgsl.expected.hlsl index 7183f0e40c..76919df4c6 100644 --- a/test/intrinsics/gen/select/ebfea2.wgsl.expected.hlsl +++ b/test/intrinsics/gen/select/ebfea2.wgsl.expected.hlsl @@ -3,7 +3,7 @@ struct tint_symbol { }; void select_ebfea2() { - float3 res = (vector(false, false, false) ? float3(0.0f, 0.0f, 0.0f) : float3(0.0f, 0.0f, 0.0f)); + float3 res = (bool3(false, false, false) ? float3(0.0f, 0.0f, 0.0f) : float3(0.0f, 0.0f, 0.0f)); } tint_symbol vertex_main() {