tint: Add vec2(), vec3(), vec4()

Fixed: tint:1892
Change-Id: I3e823dd84cb7feb58b16c7763b520f149714576e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128380
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2023-04-21 12:19:49 +00:00 committed by Dawn LUCI CQ
parent 5a5b7dfe92
commit de42feb949
28 changed files with 1726 additions and 1414 deletions

View File

@ -862,6 +862,9 @@ fn textureStore<C: iu32>(texture: texture_storage_3d<u32_texel_format, write>, c
@must_use @const("Zero") ctor f32() -> f32
@must_use @const("Zero") ctor f16() -> f16
@must_use @const("Zero") ctor bool() -> bool
@must_use @const("Zero") ctor vec2() -> vec2<ia>
@must_use @const("Zero") ctor vec3() -> vec3<ia>
@must_use @const("Zero") ctor vec4() -> vec4<ia>
@must_use @const("Zero") ctor vec2<T: concrete_scalar>() -> vec2<T>
@must_use @const("Zero") ctor vec3<T: concrete_scalar>() -> vec3<T>
@must_use @const("Zero") ctor vec4<T: concrete_scalar>() -> vec4<T>

View File

@ -1921,10 +1921,11 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_Init) {
EXPECT_EQ(r()->error(),
R"(12:34 error: no matching constructor for vec2<f32>(abstract-float, bool)
4 candidate constructors:
5 candidate constructors:
vec2(x: T, y: T) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2(T) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2(vec2<T>) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2() -> vec2<abstract-int>
vec2<T>() -> vec2<T> where: T is f32, f16, i32, u32 or bool
5 candidate conversions:
@ -1948,10 +1949,11 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_Init) {
EXPECT_EQ(r()->error(),
R"(12:34 error: no matching constructor for vec2<f32>(abstract-float, bool)
4 candidate constructors:
5 candidate constructors:
vec2(x: T, y: T) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2(T) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2(vec2<T>) -> vec2<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec2() -> vec2<abstract-int>
vec2<T>() -> vec2<T> where: T is f32, f16, i32, u32 or bool
5 candidate conversions:

View File

@ -189,6 +189,9 @@ INSTANTIATE_TEST_SUITE_P(ZeroInit,
C<f32>(),
C<f16>(),
C<bool>(),
C<builder::vec2<AInt>>(),
C<builder::vec3<AInt>>(),
C<builder::vec4<AInt>>(),
C<builder::vec3<u32>>(),
C<builder::vec3<i32>>(),
C<builder::vec3<f32>>(),

View File

@ -180,6 +180,9 @@ class TemplateState {
return numbers_[idx];
}
/// @return the total number of type and number templates
size_t Count() const { return types_.Length() + numbers_.Length(); }
private:
utils::Vector<const type::Type*, 4> types_;
utils::Vector<Number, 2> numbers_;
@ -1589,6 +1592,7 @@ Impl::Candidate Impl::ScoreOverload(const OverloadInfo* overload,
// The overloads with the lowest score will be displayed first (top-most).
constexpr int kMismatchedParamCountPenalty = 3;
constexpr int kMismatchedParamTypePenalty = 2;
constexpr int kMismatchedTemplateCountPenalty = 1;
constexpr int kMismatchedTemplateTypePenalty = 1;
constexpr int kMismatchedTemplateNumberPenalty = 1;
@ -1602,6 +1606,15 @@ Impl::Candidate Impl::ScoreOverload(const OverloadInfo* overload,
std::min(num_parameters, num_arguments));
}
if (score == 0) {
// Check that all of the template arguments provided are actually expected by the overload.
size_t expected_templates = overload->num_template_types + overload->num_template_numbers;
size_t provided_templates = in_templates.Count();
if (provided_templates > expected_templates) {
score += kMismatchedTemplateCountPenalty * (provided_templates - expected_templates);
}
}
// Make a mutable copy of the input templates so we can implicitly match more templated
// arguments.
TemplateState templates(in_templates);

File diff suppressed because it is too large Load Diff

View File

@ -841,12 +841,13 @@ TEST_F(IntrinsicTableTest, MismatchTypeInitializerImplicit) {
EXPECT_EQ(Diagnostics().str(),
R"(12:34 error: no matching constructor for vec3(i32, f32, i32)
6 candidate constructors:
7 candidate constructors:
vec3(x: T, y: T, z: T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(xy: vec2<T>, z: T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(x: T, yz: vec2<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(vec3<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3() -> vec3<abstract-int>
vec3<T>() -> vec3<T> where: T is f32, f16, i32, u32 or bool
5 candidate conversions:
@ -867,12 +868,13 @@ TEST_F(IntrinsicTableTest, MismatchTypeInitializerExplicit) {
EXPECT_EQ(Diagnostics().str(),
R"(12:34 error: no matching constructor for vec3<i32>(i32, f32, i32)
6 candidate constructors:
7 candidate constructors:
vec3(x: T, y: T, z: T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(x: T, yz: vec2<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(xy: vec2<T>, z: T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(vec3<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3() -> vec3<abstract-int>
vec3<T>() -> vec3<T> where: T is f32, f16, i32, u32 or bool
5 candidate conversions:
@ -971,9 +973,10 @@ TEST_F(IntrinsicTableTest, MismatchTypeConversion) {
EXPECT_EQ(Diagnostics().str(),
R"(12:34 error: no matching constructor for vec3<f32>(array<u32>)
6 candidate constructors:
7 candidate constructors:
vec3(vec3<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3() -> vec3<abstract-int>
vec3<T>() -> vec3<T> where: T is f32, f16, i32, u32 or bool
vec3(xy: vec2<T>, z: T) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
vec3(x: T, yz: vec2<T>) -> vec3<T> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool

View File

@ -2299,11 +2299,26 @@ TEST_F(ResolverValueConstructorValidationTest, InferVec4ElementTypeFromVec2AndVe
EXPECT_EQ(TypeOf(vec4_f16)->As<type::Vector>()->Width(), 4u);
}
TEST_F(ResolverValueConstructorValidationTest, CannotInferVectorElementTypeWithoutArgs) {
WrapInFunction(Call(Source{{12, 34}}, "vec3"));
TEST_F(ResolverValueConstructorValidationTest, InferVecNoArgs) {
auto* v2 = vec2<Infer>();
auto* v3 = vec3<Infer>();
auto* v4 = vec4<Infer>();
EXPECT_FALSE(r()->Resolve());
EXPECT_THAT(r()->error(), HasSubstr("12:34 error: no matching constructor for vec3()"));
GlobalConst("v2", v2);
GlobalConst("v3", v3);
GlobalConst("v4", v4);
ASSERT_TRUE(r()->Resolve()) << r()->error();
ASSERT_TRUE(TypeOf(v2)->Is<type::Vector>());
ASSERT_TRUE(TypeOf(v3)->Is<type::Vector>());
ASSERT_TRUE(TypeOf(v4)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(v2)->As<type::Vector>()->type()->Is<type::AbstractInt>());
EXPECT_TRUE(TypeOf(v3)->As<type::Vector>()->type()->Is<type::AbstractInt>());
EXPECT_TRUE(TypeOf(v4)->As<type::Vector>()->type()->Is<type::AbstractInt>());
EXPECT_EQ(TypeOf(v2)->As<type::Vector>()->Width(), 2u);
EXPECT_EQ(TypeOf(v3)->As<type::Vector>()->Width(), 3u);
EXPECT_EQ(TypeOf(v4)->As<type::Vector>()->Width(), 4u);
}
TEST_F(ResolverValueConstructorValidationTest, CannotInferVec2ElementTypeFromScalarsMismatch) {

View File

@ -0,0 +1,3 @@
var<private> f : vec2f = vec2();
var<private> i : vec2i = vec2();
var<private> u : vec2u = vec2();

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float2 f = (0.0f).xx;
static int2 i = (0).xx;
static uint2 u = (0u).xx;

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float2 f = (0.0f).xx;
static int2 i = (0).xx;
static uint2 u = (0u).xx;

View File

@ -0,0 +1,9 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
vec2 f = vec2(0.0f);
ivec2 i = ivec2(0);
uvec2 u = uvec2(0u);

View File

@ -0,0 +1,9 @@
#include <metal_stdlib>
using namespace metal;
struct tint_private_vars_struct {
float2 f;
int2 i;
uint2 u;
};

View File

@ -0,0 +1,34 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 20
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %f "f"
OpName %i "i"
OpName %u "u"
OpName %unused_entry_point "unused_entry_point"
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%3 = OpConstantNull %v2float
%_ptr_Private_v2float = OpTypePointer Private %v2float
%f = OpVariable %_ptr_Private_v2float Private %3
%int = OpTypeInt 32 1
%v2int = OpTypeVector %int 2
%8 = OpConstantNull %v2int
%_ptr_Private_v2int = OpTypePointer Private %v2int
%i = OpVariable %_ptr_Private_v2int Private %8
%uint = OpTypeInt 32 0
%v2uint = OpTypeVector %uint 2
%13 = OpConstantNull %v2uint
%_ptr_Private_v2uint = OpTypePointer Private %v2uint
%u = OpVariable %_ptr_Private_v2uint Private %13
%void = OpTypeVoid
%16 = OpTypeFunction %void
%unused_entry_point = OpFunction %void None %16
%19 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,5 @@
var<private> f : vec2f = vec2();
var<private> i : vec2i = vec2();
var<private> u : vec2u = vec2();

View File

@ -0,0 +1,3 @@
var<private> f : vec3f = vec3();
var<private> i : vec3i = vec3();
var<private> u : vec3u = vec3();

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float3 f = (0.0f).xxx;
static int3 i = (0).xxx;
static uint3 u = (0u).xxx;

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float3 f = (0.0f).xxx;
static int3 i = (0).xxx;
static uint3 u = (0u).xxx;

View File

@ -0,0 +1,9 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
vec3 f = vec3(0.0f);
ivec3 i = ivec3(0);
uvec3 u = uvec3(0u);

View File

@ -0,0 +1,9 @@
#include <metal_stdlib>
using namespace metal;
struct tint_private_vars_struct {
float3 f;
int3 i;
uint3 u;
};

View File

@ -0,0 +1,34 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 20
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %f "f"
OpName %i "i"
OpName %u "u"
OpName %unused_entry_point "unused_entry_point"
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%3 = OpConstantNull %v3float
%_ptr_Private_v3float = OpTypePointer Private %v3float
%f = OpVariable %_ptr_Private_v3float Private %3
%int = OpTypeInt 32 1
%v3int = OpTypeVector %int 3
%8 = OpConstantNull %v3int
%_ptr_Private_v3int = OpTypePointer Private %v3int
%i = OpVariable %_ptr_Private_v3int Private %8
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%13 = OpConstantNull %v3uint
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%u = OpVariable %_ptr_Private_v3uint Private %13
%void = OpTypeVoid
%16 = OpTypeFunction %void
%unused_entry_point = OpFunction %void None %16
%19 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,5 @@
var<private> f : vec3f = vec3();
var<private> i : vec3i = vec3();
var<private> u : vec3u = vec3();

View File

@ -0,0 +1,3 @@
var<private> f : vec4f = vec4();
var<private> i : vec4i = vec4();
var<private> u : vec4u = vec4();

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float4 f = (0.0f).xxxx;
static int4 i = (0).xxxx;
static uint4 u = (0u).xxxx;

View File

@ -0,0 +1,8 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
static float4 f = (0.0f).xxxx;
static int4 i = (0).xxxx;
static uint4 u = (0u).xxxx;

View File

@ -0,0 +1,9 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
vec4 f = vec4(0.0f);
ivec4 i = ivec4(0);
uvec4 u = uvec4(0u);

View File

@ -0,0 +1,9 @@
#include <metal_stdlib>
using namespace metal;
struct tint_private_vars_struct {
float4 f;
int4 i;
uint4 u;
};

View File

@ -0,0 +1,34 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 20
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %f "f"
OpName %i "i"
OpName %u "u"
OpName %unused_entry_point "unused_entry_point"
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%3 = OpConstantNull %v4float
%_ptr_Private_v4float = OpTypePointer Private %v4float
%f = OpVariable %_ptr_Private_v4float Private %3
%int = OpTypeInt 32 1
%v4int = OpTypeVector %int 4
%8 = OpConstantNull %v4int
%_ptr_Private_v4int = OpTypePointer Private %v4int
%i = OpVariable %_ptr_Private_v4int Private %8
%uint = OpTypeInt 32 0
%v4uint = OpTypeVector %uint 4
%13 = OpConstantNull %v4uint
%_ptr_Private_v4uint = OpTypePointer Private %v4uint
%u = OpVariable %_ptr_Private_v4uint Private %13
%void = OpTypeVoid
%16 = OpTypeFunction %void
%unused_entry_point = OpFunction %void None %16
%19 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,5 @@
var<private> f : vec4f = vec4();
var<private> i : vec4i = vec4();
var<private> u : vec4u = vec4();