From 95dd428c750d1af73c0b53fa7d12d227a5c134a1 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 25 Oct 2022 13:08:45 +0000 Subject: [PATCH] tint/intrinsics.def: Add @test_value() annotation Specifies the value to use for argument values when generating end-to-end tests. Use this to provide a legal value for atanh(). Change-Id: I008050c856f9d687ab918c68e90678c4e74f3a1d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106887 Kokoro: Kokoro Reviewed-by: Dan Sinclair --- src/tint/intrinsics.def | 4 +- src/tint/resolver/intrinsic_table.inl | 4 +- test/tint/builtins/gen/gen.wgsl.tmpl | 19 +- .../builtins/gen/literal/atanh/440cca.wgsl | 2 +- .../atanh/440cca.wgsl.expected.dxc.hlsl | 2 +- .../atanh/440cca.wgsl.expected.fxc.hlsl | 2 +- .../literal/atanh/440cca.wgsl.expected.glsl | 6 +- .../literal/atanh/440cca.wgsl.expected.msl | 2 +- .../literal/atanh/440cca.wgsl.expected.spvasm | 28 +-- .../literal/atanh/440cca.wgsl.expected.wgsl | 2 +- .../builtins/gen/literal/atanh/7997d8.wgsl | 2 +- .../atanh/7997d8.wgsl.expected.dxc.hlsl | 2 +- .../atanh/7997d8.wgsl.expected.fxc.hlsl | 2 +- .../literal/atanh/7997d8.wgsl.expected.glsl | 6 +- .../literal/atanh/7997d8.wgsl.expected.msl | 2 +- .../literal/atanh/7997d8.wgsl.expected.spvasm | 27 +-- .../literal/atanh/7997d8.wgsl.expected.wgsl | 2 +- .../builtins/gen/literal/atanh/c0e634.wgsl | 2 +- .../atanh/c0e634.wgsl.expected.dxc.hlsl | 2 +- .../atanh/c0e634.wgsl.expected.fxc.hlsl | 2 +- .../literal/atanh/c0e634.wgsl.expected.glsl | 6 +- .../literal/atanh/c0e634.wgsl.expected.msl | 2 +- .../literal/atanh/c0e634.wgsl.expected.spvasm | 28 +-- .../literal/atanh/c0e634.wgsl.expected.wgsl | 2 +- .../builtins/gen/literal/atanh/f3e01b.wgsl | 2 +- .../atanh/f3e01b.wgsl.expected.dxc.hlsl | 2 +- .../atanh/f3e01b.wgsl.expected.fxc.hlsl | 2 +- .../literal/atanh/f3e01b.wgsl.expected.glsl | 6 +- .../literal/atanh/f3e01b.wgsl.expected.msl | 2 +- .../literal/atanh/f3e01b.wgsl.expected.spvasm | 28 +-- .../literal/atanh/f3e01b.wgsl.expected.wgsl | 2 +- test/tint/builtins/gen/var/atanh/440cca.wgsl | 2 +- .../var/atanh/440cca.wgsl.expected.dxc.hlsl | 2 +- .../var/atanh/440cca.wgsl.expected.fxc.hlsl | 2 +- .../gen/var/atanh/440cca.wgsl.expected.glsl | 6 +- .../gen/var/atanh/440cca.wgsl.expected.msl | 2 +- .../gen/var/atanh/440cca.wgsl.expected.spvasm | 34 ++-- .../gen/var/atanh/440cca.wgsl.expected.wgsl | 2 +- test/tint/builtins/gen/var/atanh/7997d8.wgsl | 2 +- .../var/atanh/7997d8.wgsl.expected.dxc.hlsl | 2 +- .../var/atanh/7997d8.wgsl.expected.fxc.hlsl | 2 +- .../gen/var/atanh/7997d8.wgsl.expected.glsl | 6 +- .../gen/var/atanh/7997d8.wgsl.expected.msl | 2 +- .../gen/var/atanh/7997d8.wgsl.expected.spvasm | 33 +-- .../gen/var/atanh/7997d8.wgsl.expected.wgsl | 2 +- test/tint/builtins/gen/var/atanh/c0e634.wgsl | 2 +- .../var/atanh/c0e634.wgsl.expected.dxc.hlsl | 2 +- .../var/atanh/c0e634.wgsl.expected.fxc.hlsl | 2 +- .../gen/var/atanh/c0e634.wgsl.expected.glsl | 6 +- .../gen/var/atanh/c0e634.wgsl.expected.msl | 2 +- .../gen/var/atanh/c0e634.wgsl.expected.spvasm | 34 ++-- .../gen/var/atanh/c0e634.wgsl.expected.wgsl | 2 +- test/tint/builtins/gen/var/atanh/f3e01b.wgsl | 2 +- .../var/atanh/f3e01b.wgsl.expected.dxc.hlsl | 2 +- .../var/atanh/f3e01b.wgsl.expected.fxc.hlsl | 2 +- .../gen/var/atanh/f3e01b.wgsl.expected.glsl | 6 +- .../gen/var/atanh/f3e01b.wgsl.expected.msl | 2 +- .../gen/var/atanh/f3e01b.wgsl.expected.spvasm | 34 ++-- .../gen/var/atanh/f3e01b.wgsl.expected.wgsl | 2 +- tools/src/cmd/gen/main.go | 1 + tools/src/tint/intrinsic/ast/ast.go | 2 +- tools/src/tint/intrinsic/gen/permutate.go | 7 +- tools/src/tint/intrinsic/lexer/lexer.go | 18 +- tools/src/tint/intrinsic/lexer/lexer_test.go | 192 +++++++++--------- tools/src/tint/intrinsic/parser/parser.go | 21 +- .../src/tint/intrinsic/parser/parser_test.go | 24 +-- tools/src/tint/intrinsic/resolver/resolve.go | 33 ++- tools/src/tint/intrinsic/sem/sem.go | 7 +- tools/src/tint/intrinsic/tok/tok.go | 1 + 69 files changed, 394 insertions(+), 313 deletions(-) diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index 54f2a85312..9718405ec1 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -423,8 +423,8 @@ fn asinh(vec) -> vec @const fn atan(vec) -> vec @const fn atan2(T, T) -> T @const fn atan2(vec, vec) -> vec -fn atanh(T) -> T -fn atanh(vec) -> vec +fn atanh(@test_value(0.5) T) -> T +fn atanh(@test_value(0.5) vec) -> vec fn ceil(T) -> T fn ceil(vec) -> vec @const fn clamp(T, T, T) -> T diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl index 361a669ee5..e7b2178f76 100644 --- a/src/tint/resolver/intrinsic_table.inl +++ b/src/tint/resolver/intrinsic_table.inl @@ -13997,8 +13997,8 @@ constexpr IntrinsicInfo kBuiltins[] = { }, { /* [10] */ - /* fn atanh(T) -> T */ - /* fn atanh(vec) -> vec */ + /* fn atanh(@test_value(0.5) T) -> T */ + /* fn atanh(@test_value(0.5) vec) -> vec */ /* num overloads */ 2, /* overloads */ &kOverloads[404], }, diff --git a/test/tint/builtins/gen/gen.wgsl.tmpl b/test/tint/builtins/gen/gen.wgsl.tmpl index da230648df..3c304743c8 100644 --- a/test/tint/builtins/gen/gen.wgsl.tmpl +++ b/test/tint/builtins/gen/gen.wgsl.tmpl @@ -265,17 +265,22 @@ enable f16; {{- /* Returns a value that can be used for the parameter argument */ -}} {{- /* ------------------------------------------------------------------ */ -}} {{- $ty := .Type -}} -{{- if eq $ty.Target.Name "i32" -}}1i -{{- else if eq $ty.Target.Name "u32" -}}1u -{{- else if eq $ty.Target.Name "f32" -}}1.f -{{- else if eq $ty.Target.Name "fa" -}}1 -{{- else if eq $ty.Target.Name "ia" -}}1.0 +{{- $value := printf "%v" .TestValue }} +{{- /* $float_value is $value with a '.' suffix (if it wasn't a float already) */ -}} +{{- $float_value := $value }} +{{- if not (Contains $value ".") }}{{$float_value = printf "%v." $value}}{{end}} +{{- /* emit the value with any necessary suffixes */ -}} +{{- if eq $ty.Target.Name "i32" -}}{{$value}}i +{{- else if eq $ty.Target.Name "u32" -}}{{$value}}u +{{- else if eq $ty.Target.Name "f32" -}}{{$float_value}}f +{{- else if eq $ty.Target.Name "fa" -}}{{$value}} +{{- else if eq $ty.Target.Name "ia" -}}{{$float_value}}0 {{- else if eq $ty.Target.Name "bool" -}}true {{- else if eq $ty.Target.Name "vec" -}} -{{- $el := Eval "ArgumentValue" "Type" (ElementType .Type) "Name" ""}} +{{- $el := Eval "ArgumentValue" "Type" (ElementType .Type) "Name" "" "TestValue" .TestValue }} {{- template "Type" $ty}}({{$el}}) {{- else if eq $ty.Target.Name "mat" -}}{{template "Type" $ty}}( -{{- $el := Eval "ArgumentValue" "Type" (ElementType .Type) "Name" ""}} +{{- $el := Eval "ArgumentValue" "Type" (ElementType .Type) "Name" "" "TestValue" .TestValue }} {{- range $col := Iterate (index $ty.TemplateArguments 0) }} {{- range $row := Iterate (index $ty.TemplateArguments 1) }} {{- if or $col $row -}}, {{end}}{{$el}} diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl index 508c4d8ba6..2ed2e89ef6 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<3, f32>) -> vec<3, f32> fn atanh_440cca() { - var res: vec3 = atanh(vec3(1.f)); + var res: vec3 = atanh(vec3(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.dxc.hlsl index 62b4e58561..9359293cb4 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 res = tint_atanh((1.0f).xxx); + float3 res = tint_atanh((0.5f).xxx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.fxc.hlsl index 62b4e58561..9359293cb4 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 res = tint_atanh((1.0f).xxx); + float3 res = tint_atanh((0.5f).xxx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.glsl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.glsl index b94d529143..ec207ee146 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 res = tint_atanh(vec3(1.0f)); + vec3 res = tint_atanh(vec3(0.5f)); } vec4 vertex_main() { @@ -29,7 +29,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 res = tint_atanh(vec3(1.0f)); + vec3 res = tint_atanh(vec3(0.5f)); } void fragment_main() { @@ -47,7 +47,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 res = tint_atanh(vec3(1.0f)); + vec3 res = tint_atanh(vec3(0.5f)); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.msl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.msl index 3d3664918a..929e1776d0 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.msl @@ -6,7 +6,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 res = tint_atanh(float3(1.0f)); + float3 res = tint_atanh(float3(0.5f)); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.spvasm index c2c163db22..a0b1acccd0 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 43 +; Bound: 45 ; Schema: 0 OpCapability Shader %22 = OpExtInstImport "GLSL.std.450" @@ -40,8 +40,10 @@ %20 = OpConstantNull %v3float %void = OpTypeVoid %23 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %29 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 %_ptr_Function_v3float = OpTypePointer Function %v3float - %30 = OpTypeFunction %v4float + %32 = OpTypeFunction %v4float %tint_atanh = OpFunction %v3float None %9 %x = OpFunctionParameter %v3float %13 = OpLabel @@ -53,29 +55,29 @@ %atanh_440cca = OpFunction %void None %23 %26 = OpLabel %res = OpVariable %_ptr_Function_v3float Function %20 - %27 = OpFunctionCall %v3float %tint_atanh %16 + %27 = OpFunctionCall %v3float %tint_atanh %29 OpStore %res %27 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %30 - %32 = OpLabel - %33 = OpFunctionCall %void %atanh_440cca +%vertex_main_inner = OpFunction %v4float None %32 + %34 = OpLabel + %35 = OpFunctionCall %void %atanh_440cca OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %23 - %35 = OpLabel - %36 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %36 + %37 = OpLabel + %38 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %38 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %23 - %38 = OpLabel - %39 = OpFunctionCall %void %atanh_440cca + %40 = OpLabel + %41 = OpFunctionCall %void %atanh_440cca OpReturn OpFunctionEnd %compute_main = OpFunction %void None %23 - %41 = OpLabel - %42 = OpFunctionCall %void %atanh_440cca + %43 = OpLabel + %44 = OpFunctionCall %void %atanh_440cca OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.wgsl index 44260807bc..f3409508ae 100644 --- a/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/literal/atanh/440cca.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_440cca() { - var res : vec3 = atanh(vec3(1.0f)); + var res : vec3 = atanh(vec3(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl index 1fc4412d0a..a2c969a1ff 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl @@ -23,7 +23,7 @@ // fn atanh(f32) -> f32 fn atanh_7997d8() { - var res: f32 = atanh(1.f); + var res: f32 = atanh(0.5f); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.dxc.hlsl index 76a5352a17..eb5bf9631a 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.fxc.hlsl index 76a5352a17..eb5bf9631a 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.glsl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.glsl index f73d0d791e..6a74200f27 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.glsl @@ -5,7 +5,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } vec4 vertex_main() { @@ -29,7 +29,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } void fragment_main() { @@ -47,7 +47,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.msl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.msl index ec298cf5e3..147d54ad7a 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.msl @@ -6,7 +6,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float res = tint_atanh(1.0f); + float res = tint_atanh(0.5f); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.spvasm index 9910eed56b..8274b37f6c 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 39 +; Bound: 40 ; Schema: 0 OpCapability Shader %18 = OpExtInstImport "GLSL.std.450" @@ -36,8 +36,9 @@ %bool = OpTypeBool %void = OpTypeVoid %19 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 %_ptr_Function_float = OpTypePointer Function %float - %26 = OpTypeFunction %v4float + %27 = OpTypeFunction %v4float %tint_atanh = OpFunction %float None %9 %x = OpFunctionParameter %float %12 = OpLabel @@ -49,29 +50,29 @@ %atanh_7997d8 = OpFunction %void None %19 %22 = OpLabel %res = OpVariable %_ptr_Function_float Function %8 - %23 = OpFunctionCall %float %tint_atanh %float_1 + %23 = OpFunctionCall %float %tint_atanh %float_0_5 OpStore %res %23 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %26 - %28 = OpLabel - %29 = OpFunctionCall %void %atanh_7997d8 +%vertex_main_inner = OpFunction %v4float None %27 + %29 = OpLabel + %30 = OpFunctionCall %void %atanh_7997d8 OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %19 - %31 = OpLabel - %32 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %32 + %32 = OpLabel + %33 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %33 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %19 - %34 = OpLabel - %35 = OpFunctionCall %void %atanh_7997d8 + %35 = OpLabel + %36 = OpFunctionCall %void %atanh_7997d8 OpReturn OpFunctionEnd %compute_main = OpFunction %void None %19 - %37 = OpLabel - %38 = OpFunctionCall %void %atanh_7997d8 + %38 = OpLabel + %39 = OpFunctionCall %void %atanh_7997d8 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.wgsl index dcf31c2a9e..c395d17efc 100644 --- a/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/literal/atanh/7997d8.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_7997d8() { - var res : f32 = atanh(1.0f); + var res : f32 = atanh(0.5f); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl index 9a9eb9d6fd..26654e7578 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<2, f32>) -> vec<2, f32> fn atanh_c0e634() { - var res: vec2 = atanh(vec2(1.f)); + var res: vec2 = atanh(vec2(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.dxc.hlsl index 961f86a870..4342cb056b 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 res = tint_atanh((1.0f).xx); + float2 res = tint_atanh((0.5f).xx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.fxc.hlsl index 961f86a870..4342cb056b 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 res = tint_atanh((1.0f).xx); + float2 res = tint_atanh((0.5f).xx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.glsl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.glsl index af242ca8a4..1e9ca1a19b 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 res = tint_atanh(vec2(1.0f)); + vec2 res = tint_atanh(vec2(0.5f)); } vec4 vertex_main() { @@ -29,7 +29,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 res = tint_atanh(vec2(1.0f)); + vec2 res = tint_atanh(vec2(0.5f)); } void fragment_main() { @@ -47,7 +47,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 res = tint_atanh(vec2(1.0f)); + vec2 res = tint_atanh(vec2(0.5f)); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.msl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.msl index d5c6b49b1f..bc96c02f9e 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.msl @@ -6,7 +6,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 res = tint_atanh(float2(1.0f)); + float2 res = tint_atanh(float2(0.5f)); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.spvasm index 4cc3fa4871..5fea132136 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 43 +; Bound: 45 ; Schema: 0 OpCapability Shader %22 = OpExtInstImport "GLSL.std.450" @@ -40,8 +40,10 @@ %20 = OpConstantNull %v2float %void = OpTypeVoid %23 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %29 = OpConstantComposite %v2float %float_0_5 %float_0_5 %_ptr_Function_v2float = OpTypePointer Function %v2float - %30 = OpTypeFunction %v4float + %32 = OpTypeFunction %v4float %tint_atanh = OpFunction %v2float None %9 %x = OpFunctionParameter %v2float %13 = OpLabel @@ -53,29 +55,29 @@ %atanh_c0e634 = OpFunction %void None %23 %26 = OpLabel %res = OpVariable %_ptr_Function_v2float Function %20 - %27 = OpFunctionCall %v2float %tint_atanh %16 + %27 = OpFunctionCall %v2float %tint_atanh %29 OpStore %res %27 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %30 - %32 = OpLabel - %33 = OpFunctionCall %void %atanh_c0e634 +%vertex_main_inner = OpFunction %v4float None %32 + %34 = OpLabel + %35 = OpFunctionCall %void %atanh_c0e634 OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %23 - %35 = OpLabel - %36 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %36 + %37 = OpLabel + %38 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %38 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %23 - %38 = OpLabel - %39 = OpFunctionCall %void %atanh_c0e634 + %40 = OpLabel + %41 = OpFunctionCall %void %atanh_c0e634 OpReturn OpFunctionEnd %compute_main = OpFunction %void None %23 - %41 = OpLabel - %42 = OpFunctionCall %void %atanh_c0e634 + %43 = OpLabel + %44 = OpFunctionCall %void %atanh_c0e634 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.wgsl index c36353610a..d8285dc6a6 100644 --- a/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/literal/atanh/c0e634.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_c0e634() { - var res : vec2 = atanh(vec2(1.0f)); + var res : vec2 = atanh(vec2(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl index 038b9475f2..f9b0d0cab3 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<4, f32>) -> vec<4, f32> fn atanh_f3e01b() { - var res: vec4 = atanh(vec4(1.f)); + var res: vec4 = atanh(vec4(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.dxc.hlsl index fcae34abcf..8fa46153dc 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 res = tint_atanh((1.0f).xxxx); + float4 res = tint_atanh((0.5f).xxxx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.fxc.hlsl index fcae34abcf..8fa46153dc 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 res = tint_atanh((1.0f).xxxx); + float4 res = tint_atanh((0.5f).xxxx); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.glsl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.glsl index a2cda73ae4..e86a88fdcb 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.glsl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 res = tint_atanh(vec4(1.0f)); + vec4 res = tint_atanh(vec4(0.5f)); } vec4 vertex_main() { @@ -29,7 +29,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 res = tint_atanh(vec4(1.0f)); + vec4 res = tint_atanh(vec4(0.5f)); } void fragment_main() { @@ -47,7 +47,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 res = tint_atanh(vec4(1.0f)); + vec4 res = tint_atanh(vec4(0.5f)); } void compute_main() { diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.msl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.msl index 9bf9bd81f4..ea83ed2063 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.msl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.msl @@ -6,7 +6,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 res = tint_atanh(float4(1.0f)); + float4 res = tint_atanh(float4(0.5f)); } struct tint_symbol { diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.spvasm index 6086ee2c12..c0daec0631 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 41 +; Bound: 43 ; Schema: 0 OpCapability Shader %20 = OpExtInstImport "GLSL.std.450" @@ -38,8 +38,10 @@ %v4bool = OpTypeVector %bool 4 %void = OpTypeVoid %21 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %27 = OpConstantComposite %v4float %float_0_5 %float_0_5 %float_0_5 %float_0_5 %_ptr_Function_v4float = OpTypePointer Function %v4float - %28 = OpTypeFunction %v4float + %30 = OpTypeFunction %v4float %tint_atanh = OpFunction %v4float None %9 %x = OpFunctionParameter %v4float %12 = OpLabel @@ -51,29 +53,29 @@ %atanh_f3e01b = OpFunction %void None %21 %24 = OpLabel %res = OpVariable %_ptr_Function_v4float Function %5 - %25 = OpFunctionCall %v4float %tint_atanh %15 + %25 = OpFunctionCall %v4float %tint_atanh %27 OpStore %res %25 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %28 - %30 = OpLabel - %31 = OpFunctionCall %void %atanh_f3e01b +%vertex_main_inner = OpFunction %v4float None %30 + %32 = OpLabel + %33 = OpFunctionCall %void %atanh_f3e01b OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %21 - %33 = OpLabel - %34 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %34 + %35 = OpLabel + %36 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %36 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %21 - %36 = OpLabel - %37 = OpFunctionCall %void %atanh_f3e01b + %38 = OpLabel + %39 = OpFunctionCall %void %atanh_f3e01b OpReturn OpFunctionEnd %compute_main = OpFunction %void None %21 - %39 = OpLabel - %40 = OpFunctionCall %void %atanh_f3e01b + %41 = OpLabel + %42 = OpFunctionCall %void %atanh_f3e01b OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.wgsl index f3ad468495..23096b4926 100644 --- a/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/literal/atanh/f3e01b.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_f3e01b() { - var res : vec4 = atanh(vec4(1.0f)); + var res : vec4 = atanh(vec4(0.5f)); } @vertex diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl b/test/tint/builtins/gen/var/atanh/440cca.wgsl index 753c7a9ce1..a0b4fb4f43 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<3, f32>) -> vec<3, f32> fn atanh_440cca() { - var arg_0 = vec3(1.f); + var arg_0 = vec3(0.5f); var res: vec3 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.dxc.hlsl index 703758d97b..6cfcd4ce96 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 arg_0 = (1.0f).xxx; + float3 arg_0 = (0.5f).xxx; float3 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.fxc.hlsl index 703758d97b..6cfcd4ce96 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 arg_0 = (1.0f).xxx; + float3 arg_0 = (0.5f).xxx; float3 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.glsl b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.glsl index 4e5fb6b3e2..96f88b8eef 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.glsl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 arg_0 = vec3(1.0f); + vec3 arg_0 = vec3(0.5f); vec3 res = tint_atanh(arg_0); } @@ -30,7 +30,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 arg_0 = vec3(1.0f); + vec3 arg_0 = vec3(0.5f); vec3 res = tint_atanh(arg_0); } @@ -49,7 +49,7 @@ vec3 tint_atanh(vec3 x) { } void atanh_440cca() { - vec3 arg_0 = vec3(1.0f); + vec3 arg_0 = vec3(0.5f); vec3 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.msl b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.msl index 00cc45ce68..24e275cd14 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.msl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.msl @@ -6,7 +6,7 @@ float3 tint_atanh(float3 x) { } void atanh_440cca() { - float3 arg_0 = float3(1.0f); + float3 arg_0 = float3(0.5f); float3 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.spvasm b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.spvasm index 4b60b5112c..7e4e861a93 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 45 +; Bound: 47 ; Schema: 0 OpCapability Shader %22 = OpExtInstImport "GLSL.std.450" @@ -41,8 +41,10 @@ %20 = OpConstantNull %v3float %void = OpTypeVoid %23 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %28 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 %_ptr_Function_v3float = OpTypePointer Function %v3float - %32 = OpTypeFunction %v4float + %34 = OpTypeFunction %v4float %tint_atanh = OpFunction %v3float None %9 %x = OpFunctionParameter %v3float %13 = OpLabel @@ -55,31 +57,31 @@ %26 = OpLabel %arg_0 = OpVariable %_ptr_Function_v3float Function %20 %res = OpVariable %_ptr_Function_v3float Function %20 - OpStore %arg_0 %16 - %30 = OpLoad %v3float %arg_0 - %29 = OpFunctionCall %v3float %tint_atanh %30 - OpStore %res %29 + OpStore %arg_0 %28 + %32 = OpLoad %v3float %arg_0 + %31 = OpFunctionCall %v3float %tint_atanh %32 + OpStore %res %31 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %32 - %34 = OpLabel - %35 = OpFunctionCall %void %atanh_440cca +%vertex_main_inner = OpFunction %v4float None %34 + %36 = OpLabel + %37 = OpFunctionCall %void %atanh_440cca OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %23 - %37 = OpLabel - %38 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %38 + %39 = OpLabel + %40 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %40 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %23 - %40 = OpLabel - %41 = OpFunctionCall %void %atanh_440cca + %42 = OpLabel + %43 = OpFunctionCall %void %atanh_440cca OpReturn OpFunctionEnd %compute_main = OpFunction %void None %23 - %43 = OpLabel - %44 = OpFunctionCall %void %atanh_440cca + %45 = OpLabel + %46 = OpFunctionCall %void %atanh_440cca OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.wgsl b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.wgsl index b2d4a5a520..1c99e3bd0f 100644 --- a/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/var/atanh/440cca.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_440cca() { - var arg_0 = vec3(1.0f); + var arg_0 = vec3(0.5f); var res : vec3 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl index c08b2316fe..45fcd80f42 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl @@ -23,7 +23,7 @@ // fn atanh(f32) -> f32 fn atanh_7997d8() { - var arg_0 = 1.f; + var arg_0 = 0.5f; var res: f32 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.dxc.hlsl index 20a886c866..24fe1783f1 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.fxc.hlsl index 20a886c866..24fe1783f1 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.glsl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.glsl index cedc900282..44e3d5f008 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.glsl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.glsl @@ -5,7 +5,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } @@ -30,7 +30,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } @@ -49,7 +49,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.msl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.msl index 3944dd009c..ef13becc7e 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.msl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.msl @@ -6,7 +6,7 @@ float tint_atanh(float x) { } void atanh_7997d8() { - float arg_0 = 1.0f; + float arg_0 = 0.5f; float res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.spvasm b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.spvasm index 1b473e9f4c..95322a98fb 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 41 +; Bound: 42 ; Schema: 0 OpCapability Shader %18 = OpExtInstImport "GLSL.std.450" @@ -37,8 +37,9 @@ %bool = OpTypeBool %void = OpTypeVoid %19 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 %_ptr_Function_float = OpTypePointer Function %float - %28 = OpTypeFunction %v4float + %29 = OpTypeFunction %v4float %tint_atanh = OpFunction %float None %9 %x = OpFunctionParameter %float %12 = OpLabel @@ -51,31 +52,31 @@ %22 = OpLabel %arg_0 = OpVariable %_ptr_Function_float Function %8 %res = OpVariable %_ptr_Function_float Function %8 - OpStore %arg_0 %float_1 - %26 = OpLoad %float %arg_0 - %25 = OpFunctionCall %float %tint_atanh %26 - OpStore %res %25 + OpStore %arg_0 %float_0_5 + %27 = OpLoad %float %arg_0 + %26 = OpFunctionCall %float %tint_atanh %27 + OpStore %res %26 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %28 - %30 = OpLabel - %31 = OpFunctionCall %void %atanh_7997d8 +%vertex_main_inner = OpFunction %v4float None %29 + %31 = OpLabel + %32 = OpFunctionCall %void %atanh_7997d8 OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %19 - %33 = OpLabel - %34 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %34 + %34 = OpLabel + %35 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %35 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %19 - %36 = OpLabel - %37 = OpFunctionCall %void %atanh_7997d8 + %37 = OpLabel + %38 = OpFunctionCall %void %atanh_7997d8 OpReturn OpFunctionEnd %compute_main = OpFunction %void None %19 - %39 = OpLabel - %40 = OpFunctionCall %void %atanh_7997d8 + %40 = OpLabel + %41 = OpFunctionCall %void %atanh_7997d8 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.wgsl b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.wgsl index 4355659004..a375e935dc 100644 --- a/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/var/atanh/7997d8.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_7997d8() { - var arg_0 = 1.0f; + var arg_0 = 0.5f; var res : f32 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl index 1538619e85..11abbc85df 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<2, f32>) -> vec<2, f32> fn atanh_c0e634() { - var arg_0 = vec2(1.f); + var arg_0 = vec2(0.5f); var res: vec2 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.dxc.hlsl index 2573bee49b..4c38c2deaf 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 arg_0 = (1.0f).xx; + float2 arg_0 = (0.5f).xx; float2 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.fxc.hlsl index 2573bee49b..4c38c2deaf 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 arg_0 = (1.0f).xx; + float2 arg_0 = (0.5f).xx; float2 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.glsl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.glsl index a6857cd97d..8693caa6ec 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.glsl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 arg_0 = vec2(1.0f); + vec2 arg_0 = vec2(0.5f); vec2 res = tint_atanh(arg_0); } @@ -30,7 +30,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 arg_0 = vec2(1.0f); + vec2 arg_0 = vec2(0.5f); vec2 res = tint_atanh(arg_0); } @@ -49,7 +49,7 @@ vec2 tint_atanh(vec2 x) { } void atanh_c0e634() { - vec2 arg_0 = vec2(1.0f); + vec2 arg_0 = vec2(0.5f); vec2 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.msl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.msl index a407911fb1..51cfc7ab3c 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.msl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.msl @@ -6,7 +6,7 @@ float2 tint_atanh(float2 x) { } void atanh_c0e634() { - float2 arg_0 = float2(1.0f); + float2 arg_0 = float2(0.5f); float2 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.spvasm b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.spvasm index 3bfbe162ff..8c6366e01c 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 45 +; Bound: 47 ; Schema: 0 OpCapability Shader %22 = OpExtInstImport "GLSL.std.450" @@ -41,8 +41,10 @@ %20 = OpConstantNull %v2float %void = OpTypeVoid %23 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %28 = OpConstantComposite %v2float %float_0_5 %float_0_5 %_ptr_Function_v2float = OpTypePointer Function %v2float - %32 = OpTypeFunction %v4float + %34 = OpTypeFunction %v4float %tint_atanh = OpFunction %v2float None %9 %x = OpFunctionParameter %v2float %13 = OpLabel @@ -55,31 +57,31 @@ %26 = OpLabel %arg_0 = OpVariable %_ptr_Function_v2float Function %20 %res = OpVariable %_ptr_Function_v2float Function %20 - OpStore %arg_0 %16 - %30 = OpLoad %v2float %arg_0 - %29 = OpFunctionCall %v2float %tint_atanh %30 - OpStore %res %29 + OpStore %arg_0 %28 + %32 = OpLoad %v2float %arg_0 + %31 = OpFunctionCall %v2float %tint_atanh %32 + OpStore %res %31 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %32 - %34 = OpLabel - %35 = OpFunctionCall %void %atanh_c0e634 +%vertex_main_inner = OpFunction %v4float None %34 + %36 = OpLabel + %37 = OpFunctionCall %void %atanh_c0e634 OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %23 - %37 = OpLabel - %38 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %38 + %39 = OpLabel + %40 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %40 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %23 - %40 = OpLabel - %41 = OpFunctionCall %void %atanh_c0e634 + %42 = OpLabel + %43 = OpFunctionCall %void %atanh_c0e634 OpReturn OpFunctionEnd %compute_main = OpFunction %void None %23 - %43 = OpLabel - %44 = OpFunctionCall %void %atanh_c0e634 + %45 = OpLabel + %46 = OpFunctionCall %void %atanh_c0e634 OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.wgsl b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.wgsl index e9d9908b06..fd266f33a2 100644 --- a/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/var/atanh/c0e634.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_c0e634() { - var arg_0 = vec2(1.0f); + var arg_0 = vec2(0.5f); var res : vec2 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl index c97144012e..0f72799991 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl @@ -23,7 +23,7 @@ // fn atanh(vec<4, f32>) -> vec<4, f32> fn atanh_f3e01b() { - var arg_0 = vec4(1.f); + var arg_0 = vec4(0.5f); var res: vec4 = atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.dxc.hlsl index f85a7e62a4..88b907811d 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.dxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.dxc.hlsl @@ -3,7 +3,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 arg_0 = (1.0f).xxxx; + float4 arg_0 = (0.5f).xxxx; float4 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.fxc.hlsl index f85a7e62a4..88b907811d 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.fxc.hlsl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.fxc.hlsl @@ -3,7 +3,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 arg_0 = (1.0f).xxxx; + float4 arg_0 = (0.5f).xxxx; float4 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.glsl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.glsl index 75486c5f35..cf63d642a0 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.glsl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.glsl @@ -5,7 +5,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 arg_0 = vec4(1.0f); + vec4 arg_0 = vec4(0.5f); vec4 res = tint_atanh(arg_0); } @@ -30,7 +30,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 arg_0 = vec4(1.0f); + vec4 arg_0 = vec4(0.5f); vec4 res = tint_atanh(arg_0); } @@ -49,7 +49,7 @@ vec4 tint_atanh(vec4 x) { } void atanh_f3e01b() { - vec4 arg_0 = vec4(1.0f); + vec4 arg_0 = vec4(0.5f); vec4 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.msl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.msl index 41b2f08ff2..ed733d4668 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.msl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.msl @@ -6,7 +6,7 @@ float4 tint_atanh(float4 x) { } void atanh_f3e01b() { - float4 arg_0 = float4(1.0f); + float4 arg_0 = float4(0.5f); float4 res = tint_atanh(arg_0); } diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.spvasm b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.spvasm index e78165eaa5..fb1f009d3e 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.spvasm +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 43 +; Bound: 45 ; Schema: 0 OpCapability Shader %20 = OpExtInstImport "GLSL.std.450" @@ -39,8 +39,10 @@ %v4bool = OpTypeVector %bool 4 %void = OpTypeVoid %21 = OpTypeFunction %void + %float_0_5 = OpConstant %float 0.5 + %26 = OpConstantComposite %v4float %float_0_5 %float_0_5 %float_0_5 %float_0_5 %_ptr_Function_v4float = OpTypePointer Function %v4float - %30 = OpTypeFunction %v4float + %32 = OpTypeFunction %v4float %tint_atanh = OpFunction %v4float None %9 %x = OpFunctionParameter %v4float %12 = OpLabel @@ -53,31 +55,31 @@ %24 = OpLabel %arg_0 = OpVariable %_ptr_Function_v4float Function %5 %res = OpVariable %_ptr_Function_v4float Function %5 - OpStore %arg_0 %15 - %28 = OpLoad %v4float %arg_0 - %27 = OpFunctionCall %v4float %tint_atanh %28 - OpStore %res %27 + OpStore %arg_0 %26 + %30 = OpLoad %v4float %arg_0 + %29 = OpFunctionCall %v4float %tint_atanh %30 + OpStore %res %29 OpReturn OpFunctionEnd -%vertex_main_inner = OpFunction %v4float None %30 - %32 = OpLabel - %33 = OpFunctionCall %void %atanh_f3e01b +%vertex_main_inner = OpFunction %v4float None %32 + %34 = OpLabel + %35 = OpFunctionCall %void %atanh_f3e01b OpReturnValue %5 OpFunctionEnd %vertex_main = OpFunction %void None %21 - %35 = OpLabel - %36 = OpFunctionCall %v4float %vertex_main_inner - OpStore %value %36 + %37 = OpLabel + %38 = OpFunctionCall %v4float %vertex_main_inner + OpStore %value %38 OpStore %vertex_point_size %float_1 OpReturn OpFunctionEnd %fragment_main = OpFunction %void None %21 - %38 = OpLabel - %39 = OpFunctionCall %void %atanh_f3e01b + %40 = OpLabel + %41 = OpFunctionCall %void %atanh_f3e01b OpReturn OpFunctionEnd %compute_main = OpFunction %void None %21 - %41 = OpLabel - %42 = OpFunctionCall %void %atanh_f3e01b + %43 = OpLabel + %44 = OpFunctionCall %void %atanh_f3e01b OpReturn OpFunctionEnd diff --git a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.wgsl b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.wgsl index ead0ca86cc..214386dde3 100644 --- a/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.wgsl +++ b/test/tint/builtins/gen/var/atanh/f3e01b.wgsl.expected.wgsl @@ -1,5 +1,5 @@ fn atanh_f3e01b() { - var arg_0 = vec4(1.0f); + var arg_0 = vec4(0.5f); var res : vec4 = atanh(arg_0); } diff --git a/tools/src/cmd/gen/main.go b/tools/src/cmd/gen/main.go index 595f77c337..f45c624efd 100644 --- a/tools/src/cmd/gen/main.go +++ b/tools/src/cmd/gen/main.go @@ -303,6 +303,7 @@ func (g *generator) bindAndParse(t *template.Template, text string) error { "Title": strings.Title, "PascalCase": pascalCase, "SplitDisplayName": gen.SplitDisplayName, + "Contains": strings.Contains, "HasPrefix": strings.HasPrefix, "HasSuffix": strings.HasSuffix, "TrimPrefix": strings.TrimPrefix, diff --git a/tools/src/tint/intrinsic/ast/ast.go b/tools/src/tint/intrinsic/ast/ast.go index 6944da22f8..ffb036e8ee 100644 --- a/tools/src/tint/intrinsic/ast/ast.go +++ b/tools/src/tint/intrinsic/ast/ast.go @@ -367,7 +367,7 @@ func (l *Attributes) Take(name string) *Attribute { type Attribute struct { Source tok.Source Name string - Values []string + Values []any } // Format implements the fmt.Formatter interface diff --git a/tools/src/tint/intrinsic/gen/permutate.go b/tools/src/tint/intrinsic/gen/permutate.go index df5f1d21df..59b3fa59b9 100644 --- a/tools/src/tint/intrinsic/gen/permutate.go +++ b/tools/src/tint/intrinsic/gen/permutate.go @@ -83,9 +83,10 @@ func (p *Permuter) Permute(overload *sem.Overload) ([]Permutation, error) { return nil } o.Parameters = append(o.Parameters, sem.Parameter{ - Name: p.Name, - Type: ty, - IsConst: p.IsConst, + Name: p.Name, + Type: ty, + IsConst: p.IsConst, + TestValue: p.TestValue, }) } if overload.ReturnType != nil { diff --git a/tools/src/tint/intrinsic/lexer/lexer.go b/tools/src/tint/intrinsic/lexer/lexer.go index a98a988c6a..91042d6a52 100644 --- a/tools/src/tint/intrinsic/lexer/lexer.go +++ b/tools/src/tint/intrinsic/lexer/lexer.go @@ -104,7 +104,23 @@ func (l *lexer) lex() error { case unicode.IsLetter(l.peek(0)) || l.peek(0) == '_': l.tok(l.count(alphaNumericOrUnderscore), tok.Identifier) case unicode.IsNumber(l.peek(0)): - l.tok(l.count(unicode.IsNumber), tok.Integer) + isFloat := false + pred := func(r rune) bool { + if unicode.IsNumber(r) { + return true + } + if !isFloat && r == '.' { + isFloat = true + return true + } + return false + } + n := l.count(pred) + if isFloat { + l.tok(n, tok.Float) + } else { + l.tok(n, tok.Integer) + } case l.match("&&", tok.AndAnd): case l.match("&", tok.And): case l.match("||", tok.OrOr): diff --git a/tools/src/tint/intrinsic/lexer/lexer_test.go b/tools/src/tint/intrinsic/lexer/lexer_test.go index ce1d618114..aec38ec14d 100644 --- a/tools/src/tint/intrinsic/lexer/lexer_test.go +++ b/tools/src/tint/intrinsic/lexer/lexer_test.go @@ -20,12 +20,13 @@ import ( "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/lexer" "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/tok" + "github.com/google/go-cmp/cmp" ) func TestLexTokens(t *testing.T) { type test struct { src string - expect tok.Token + expect []tok.Token } filepath := "test.txt" @@ -34,144 +35,153 @@ func TestLexTokens(t *testing.T) { } for _, test := range []test{ - {"ident", tok.Token{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{ + {"ident", []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 6, 5), - }}}, - {"ident_123", tok.Token{Kind: tok.Identifier, Runes: []rune("ident_123"), Source: tok.Source{ + }}}}, + {"ident_123", []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident_123"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 10, 9), - }}}, - {"_ident_", tok.Token{Kind: tok.Identifier, Runes: []rune("_ident_"), Source: tok.Source{ + }}}}, + {"_ident_", []tok.Token{{Kind: tok.Identifier, Runes: []rune("_ident_"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 8, 7), - }}}, - {"123456789", tok.Token{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{ + }}}}, + {"123456789", []tok.Token{{Kind: tok.Integer, Runes: []rune("123456789"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 10, 9), - }}}, - {"match", tok.Token{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{ + }}}}, + {"1234.56789", []tok.Token{{Kind: tok.Float, Runes: []rune("1234.56789"), Source: tok.Source{ + S: loc(1, 1, 0), E: loc(1, 11, 10), + }}}}, + {"123.456.789", []tok.Token{ + {Kind: tok.Float, Runes: []rune("123.456"), Source: tok.Source{ + S: loc(1, 1, 0), E: loc(1, 8, 7), + }}, + {Kind: tok.Dot, Runes: []rune("."), Source: tok.Source{ + S: loc(1, 8, 7), E: loc(1, 9, 8), + }}, + {Kind: tok.Integer, Runes: []rune("789"), Source: tok.Source{ + S: loc(1, 9, 8), E: loc(1, 12, 11), + }}, + }}, + {"match", []tok.Token{{Kind: tok.Match, Runes: []rune("match"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 6, 5), - }}}, - {"fn", tok.Token{Kind: tok.Function, Runes: []rune("fn"), Source: tok.Source{ + }}}}, + {"fn", []tok.Token{{Kind: tok.Function, Runes: []rune("fn"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"op", tok.Token{Kind: tok.Operator, Runes: []rune("op"), Source: tok.Source{ + }}}}, + {"op", []tok.Token{{Kind: tok.Operator, Runes: []rune("op"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"type", tok.Token{Kind: tok.Type, Runes: []rune("type"), Source: tok.Source{ + }}}}, + {"type", []tok.Token{{Kind: tok.Type, Runes: []rune("type"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 5, 4), - }}}, - {"init", tok.Token{Kind: tok.Initializer, Runes: []rune("init"), Source: tok.Source{ + }}}}, + {"init", []tok.Token{{Kind: tok.Initializer, Runes: []rune("init"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 5, 4), - }}}, - {"conv", tok.Token{Kind: tok.Converter, Runes: []rune("conv"), Source: tok.Source{ + }}}}, + {"conv", []tok.Token{{Kind: tok.Converter, Runes: []rune("conv"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 5, 4), - }}}, - {"enum", tok.Token{Kind: tok.Enum, Runes: []rune("enum"), Source: tok.Source{ + }}}}, + {"enum", []tok.Token{{Kind: tok.Enum, Runes: []rune("enum"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 5, 4), - }}}, - {":", tok.Token{Kind: tok.Colon, Runes: []rune(":"), Source: tok.Source{ + }}}}, + {":", []tok.Token{{Kind: tok.Colon, Runes: []rune(":"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {",", tok.Token{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{ + }}}}, + {",", []tok.Token{{Kind: tok.Comma, Runes: []rune(","), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"<", tok.Token{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{ + }}}}, + {"<", []tok.Token{{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {">", tok.Token{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{ + }}}}, + {">", []tok.Token{{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"{", tok.Token{Kind: tok.Lbrace, Runes: []rune("{"), Source: tok.Source{ + }}}}, + {"{", []tok.Token{{Kind: tok.Lbrace, Runes: []rune("{"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"}", tok.Token{Kind: tok.Rbrace, Runes: []rune("}"), Source: tok.Source{ + }}}}, + {"}", []tok.Token{{Kind: tok.Rbrace, Runes: []rune("}"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"&&", tok.Token{Kind: tok.AndAnd, Runes: []rune("&&"), Source: tok.Source{ + }}}}, + {"&&", []tok.Token{{Kind: tok.AndAnd, Runes: []rune("&&"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"&", tok.Token{Kind: tok.And, Runes: []rune("&"), Source: tok.Source{ + }}}}, + {"&", []tok.Token{{Kind: tok.And, Runes: []rune("&"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"||", tok.Token{Kind: tok.OrOr, Runes: []rune("||"), Source: tok.Source{ + }}}}, + {"||", []tok.Token{{Kind: tok.OrOr, Runes: []rune("||"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"|", tok.Token{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{ + }}}}, + {"|", []tok.Token{{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"!", tok.Token{Kind: tok.Not, Runes: []rune("!"), Source: tok.Source{ + }}}}, + {"!", []tok.Token{{Kind: tok.Not, Runes: []rune("!"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"!=", tok.Token{Kind: tok.NotEqual, Runes: []rune("!="), Source: tok.Source{ + }}}}, + {"!=", []tok.Token{{Kind: tok.NotEqual, Runes: []rune("!="), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"==", tok.Token{Kind: tok.Equal, Runes: []rune("=="), Source: tok.Source{ + }}}}, + {"==", []tok.Token{{Kind: tok.Equal, Runes: []rune("=="), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"=", tok.Token{Kind: tok.Assign, Runes: []rune("="), Source: tok.Source{ + }}}}, + {"=", []tok.Token{{Kind: tok.Assign, Runes: []rune("="), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"<<", tok.Token{Kind: tok.Shl, Runes: []rune("<<"), Source: tok.Source{ + }}}}, + {"<<", []tok.Token{{Kind: tok.Shl, Runes: []rune("<<"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"<=", tok.Token{Kind: tok.Le, Runes: []rune("<="), Source: tok.Source{ + }}}}, + {"<=", []tok.Token{{Kind: tok.Le, Runes: []rune("<="), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"<", tok.Token{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{ + }}}}, + {"<", []tok.Token{{Kind: tok.Lt, Runes: []rune("<"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {">=", tok.Token{Kind: tok.Ge, Runes: []rune(">="), Source: tok.Source{ + }}}}, + {">=", []tok.Token{{Kind: tok.Ge, Runes: []rune(">="), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {">>", tok.Token{Kind: tok.Shr, Runes: []rune(">>"), Source: tok.Source{ + }}}}, + {">>", []tok.Token{{Kind: tok.Shr, Runes: []rune(">>"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {">", tok.Token{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{ + }}}}, + {">", []tok.Token{{Kind: tok.Gt, Runes: []rune(">"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"@", tok.Token{Kind: tok.Attr, Runes: []rune("@"), Source: tok.Source{ + }}}}, + {"@", []tok.Token{{Kind: tok.Attr, Runes: []rune("@"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"(", tok.Token{Kind: tok.Lparen, Runes: []rune("("), Source: tok.Source{ + }}}}, + {"(", []tok.Token{{Kind: tok.Lparen, Runes: []rune("("), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {")", tok.Token{Kind: tok.Rparen, Runes: []rune(")"), Source: tok.Source{ + }}}}, + {")", []tok.Token{{Kind: tok.Rparen, Runes: []rune(")"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"|", tok.Token{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{ + }}}}, + {"|", []tok.Token{{Kind: tok.Or, Runes: []rune("|"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"*", tok.Token{Kind: tok.Star, Runes: []rune("*"), Source: tok.Source{ + }}}}, + {"*", []tok.Token{{Kind: tok.Star, Runes: []rune("*"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {"->", tok.Token{Kind: tok.Arrow, Runes: []rune("->"), Source: tok.Source{ + }}}}, + {"->", []tok.Token{{Kind: tok.Arrow, Runes: []rune("->"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 3, 2), - }}}, - {"x // y ", tok.Token{Kind: tok.Identifier, Runes: []rune("x"), Source: tok.Source{ + }}}}, + {"x // y ", []tok.Token{{Kind: tok.Identifier, Runes: []rune("x"), Source: tok.Source{ S: loc(1, 1, 0), E: loc(1, 2, 1), - }}}, - {`"abc"`, tok.Token{Kind: tok.String, Runes: []rune("abc"), Source: tok.Source{ + }}}}, + {`"abc"`, []tok.Token{{Kind: tok.String, Runes: []rune("abc"), Source: tok.Source{ S: loc(1, 2, 1), E: loc(1, 5, 4), - }}}, + }}}}, {` // ident - `, tok.Token{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{ + `, []tok.Token{{Kind: tok.Identifier, Runes: []rune("ident"), Source: tok.Source{ S: loc(3, 4, 10), E: loc(3, 9, 15), - }}}, + }}}}, } { got, err := lexer.Lex([]rune(test.src), filepath) name := fmt.Sprintf(`Lex("%v")`, test.src) - switch { - case err != nil: + if err != nil { t.Errorf("%v returned error: %v", name, err) - case len(got) != 1: - t.Errorf("%v returned %d tokens: %v", name, len(got), got) - case got[0].Kind != test.expect.Kind: - t.Errorf(`%v returned unexpected token kind: got "%+v", expected "%+v"`, name, got[0], test.expect) - case string(got[0].Runes) != string(test.expect.Runes): - t.Errorf(`%v returned unexpected token runes: got "%+v", expected "%+v"`, name, string(got[0].Runes), string(test.expect.Runes)) - case got[0].Source != test.expect.Source: - t.Errorf(`%v returned unexpected token source: got %+v, expected %+v`, name, got[0].Source, test.expect.Source) + continue + } + if diff := cmp.Diff(got, test.expect); diff != "" { + t.Errorf(`%v: %v`, name, diff) } } } diff --git a/tools/src/tint/intrinsic/parser/parser.go b/tools/src/tint/intrinsic/parser/parser.go index cec8d2d3fd..418d543166 100644 --- a/tools/src/tint/intrinsic/parser/parser.go +++ b/tools/src/tint/intrinsic/parser/parser.go @@ -18,6 +18,7 @@ package parser import ( "fmt" + "strconv" "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/ast" "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/lexer" @@ -145,10 +146,26 @@ func (p *parser) attributes() ast.Attributes { var out ast.Attributes for p.match(tok.Attr) != nil && p.err == nil { name := p.expect(tok.Identifier, "attribute name") - values := []string{} + var values []any if p.match(tok.Lparen) != nil { + loop: for p.err == nil { - values = append(values, string(p.next().Runes)) + t := p.next() + switch t.Kind { + case tok.Rparen: + break loop + case tok.String: + values = append(values, string(t.Runes)) + case tok.Integer: + i, _ := strconv.ParseInt(string(t.Runes), 10, 64) + values = append(values, int(i)) + case tok.Float: + f, _ := strconv.ParseFloat(string(t.Runes), 64) + values = append(values, f) + default: + p.err = fmt.Errorf("%v invalid attribute value kind: %v", t.Source, t.Kind) + return nil + } if p.match(tok.Comma) == nil { break } diff --git a/tools/src/tint/intrinsic/parser/parser_test.go b/tools/src/tint/intrinsic/parser/parser_test.go index 24dec43eb1..ce8b377ac7 100644 --- a/tools/src/tint/intrinsic/parser/parser_test.go +++ b/tools/src/tint/intrinsic/parser/parser_test.go @@ -52,7 +52,7 @@ func TestParser(t *testing.T) { { Attributes: ast.Attributes{{ Name: "attr", - Values: []string{}, + Values: nil, }}, Name: "B", }, @@ -85,7 +85,7 @@ func TestParser(t *testing.T) { ast.AST{ Types: []ast.TypeDecl{{ Attributes: ast.Attributes{ - {Name: "attr", Values: []string{}}, + {Name: "attr", Values: nil}, }, Name: "T", }}, @@ -96,8 +96,8 @@ func TestParser(t *testing.T) { ast.AST{ Types: []ast.TypeDecl{{ Attributes: ast.Attributes{ - {Name: "attr_a", Values: []string{}}, - {Name: "attr_b", Values: []string{}}, + {Name: "attr_a", Values: nil}, + {Name: "attr_b", Values: nil}, }, Name: "T", }}, @@ -107,17 +107,17 @@ func TestParser(t *testing.T) { `@attr("a", "b") type T`, ast.AST{ Types: []ast.TypeDecl{{ Attributes: ast.Attributes{ - {Name: "attr", Values: []string{"a", "b"}}, + {Name: "attr", Values: []any{"a", "b"}}, }, Name: "T", }}, }, }, { /////////////////////////////////////////////////////////////////// utils.ThisLine(), - `@attr(1, "x") type T`, ast.AST{ + `@attr(1, "x", 2.0) type T`, ast.AST{ Types: []ast.TypeDecl{{ Attributes: ast.Attributes{ - {Name: "attr", Values: []string{"1", "x"}}, + {Name: "attr", Values: []any{1, "x", 2.0}}, }, Name: "T", }}, @@ -194,7 +194,7 @@ func TestParser(t *testing.T) { Kind: ast.Builtin, Name: "F", Attributes: ast.Attributes{ - {Name: "attr", Values: []string{}}, + {Name: "attr", Values: nil}, }, Parameters: ast.Parameters{}, }}, @@ -318,7 +318,7 @@ func TestParser(t *testing.T) { Kind: ast.Operator, Name: "F", Attributes: ast.Attributes{ - {Name: "attr", Values: []string{}}, + {Name: "attr", Values: nil}, }, Parameters: ast.Parameters{}, }}, @@ -344,7 +344,7 @@ func TestParser(t *testing.T) { Name: "F", Parameters: ast.Parameters{ { - Attributes: ast.Attributes{{Name: "blah", Values: []string{}}}, + Attributes: ast.Attributes{{Name: "blah", Values: nil}}, Type: ast.TemplatedName{Name: "a"}}, }, }}, @@ -456,7 +456,7 @@ func TestParser(t *testing.T) { Kind: ast.Initializer, Name: "F", Attributes: ast.Attributes{ - {Name: "attr", Values: []string{}}, + {Name: "attr", Values: nil}, }, Parameters: ast.Parameters{}, }}, @@ -580,7 +580,7 @@ func TestParser(t *testing.T) { Kind: ast.Converter, Name: "F", Attributes: ast.Attributes{ - {Name: "attr", Values: []string{}}, + {Name: "attr", Values: nil}, }, Parameters: ast.Parameters{}, }}, diff --git a/tools/src/tint/intrinsic/resolver/resolve.go b/tools/src/tint/intrinsic/resolver/resolve.go index ab83c09003..59e4bfdb02 100644 --- a/tools/src/tint/intrinsic/resolver/resolve.go +++ b/tools/src/tint/intrinsic/resolver/resolve.go @@ -17,7 +17,6 @@ package resolver import ( "fmt" "sort" - "strconv" "dawn.googlesource.com/dawn/tools/src/container" "dawn.googlesource.com/dawn/tools/src/tint/intrinsic/ast" @@ -184,15 +183,15 @@ func (r *resolver) ty(a ast.TypeDecl) error { if len(d.Values) != 1 { return fmt.Errorf("%v expected a single value for 'display' attribute", d.Source) } - t.DisplayName = d.Values[0] + t.DisplayName = fmt.Sprint(d.Values[0]) } if d := a.Attributes.Take("precedence"); d != nil { if len(d.Values) != 1 { return fmt.Errorf("%v expected a single integer value for 'precedence' attribute", d.Source) } - n, err := strconv.Atoi(d.Values[0]) - if err != nil { - return fmt.Errorf("%v %v", d.Source, err) + n, ok := d.Values[0].(int) + if !ok { + return fmt.Errorf("%v @precedence value must be an integer", d.Source) } t.Precedence = n } @@ -358,7 +357,11 @@ func (r *resolver) intrinsic( overload.ConstEvalFunction = "Conv" } case 1: - overload.ConstEvalFunction = constEvalFn.Values[0] + fn, ok := constEvalFn.Values[0].(string) + if !ok { + return fmt.Errorf("%v optional @const value must be a string", constEvalFn.Source) + } + overload.ConstEvalFunction = fn default: return fmt.Errorf("%v too many values for @const attribute", constEvalFn.Source) } @@ -405,13 +408,25 @@ func (r *resolver) intrinsic( if attribute := p.Attributes.Take("const"); attribute != nil { isConst = true } + testValue := 1.0 + if attribute := p.Attributes.Take("test_value"); attribute != nil { + switch v := attribute.Values[0].(type) { + case int: + testValue = float64(v) + case float64: + testValue = v + default: + return fmt.Errorf("%v @test_value must be an integer or float", p.Attributes[0].Source) + } + } if len(p.Attributes) != 0 { return fmt.Errorf("%v unknown attribute", p.Attributes[0].Source) } overload.Parameters[i] = sem.Parameter{ - Name: p.Name, - Type: usage, - IsConst: isConst, + Name: p.Name, + Type: usage, + IsConst: isConst, + TestValue: testValue, } } diff --git a/tools/src/tint/intrinsic/sem/sem.go b/tools/src/tint/intrinsic/sem/sem.go index b7d70d8d0a..2c0c1ee9d6 100644 --- a/tools/src/tint/intrinsic/sem/sem.go +++ b/tools/src/tint/intrinsic/sem/sem.go @@ -242,9 +242,10 @@ func (o Overload) Format(w fmt.State, verb rune) { // Parameter describes a single parameter of a function overload type Parameter struct { - Name string - Type FullyQualifiedName - IsConst bool // Did this parameter have a @const attribute? + Name string + Type FullyQualifiedName + IsConst bool // Did this parameter have a @const attribute? + TestValue float64 // Value to use for end-to-end tests } // Format implements the fmt.Formatter interface diff --git a/tools/src/tint/intrinsic/tok/tok.go b/tools/src/tint/intrinsic/tok/tok.go index 8899ffb588..0516ce9e4e 100644 --- a/tools/src/tint/intrinsic/tok/tok.go +++ b/tools/src/tint/intrinsic/tok/tok.go @@ -26,6 +26,7 @@ const ( InvalidToken Kind = "" Identifier Kind = "ident" Integer Kind = "integer" + Float Kind = "float" String Kind = "string" Match Kind = "match" Function Kind = "fn"