writer[spirv,hlsl]: Call UnwrapRef() for splats

The TypeConstructorExpression logic that tested for splats was not considering references. This led to broken emission for the SPIR-V and HLSL backends.

Fixed: tint:992
Change-Id: I9824b71f526997f91d380c09b459f4fd73065b19
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58397
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-07-18 15:41:25 +00:00
committed by Tint LUCI CQ
parent 76feb6b626
commit 595b0547d4
29 changed files with 527 additions and 6 deletions

6
test/bug/tint/992.wgsl Normal file
View File

@@ -0,0 +1,6 @@
[[stage(fragment)]]
fn frag_main() -> [[location(0)]] vec4<f32> {
var b: f32 = 0.0;
var v: vec3<f32> = vec3<f32>(b);
return vec4<f32>(v, 1.0);
}

View File

@@ -0,0 +1,10 @@
struct tint_symbol {
float4 value : SV_Target0;
};
tint_symbol frag_main() {
float b = 0.0f;
float3 v = float3((b).xxx);
const tint_symbol tint_symbol_1 = {float4(v, 1.0f)};
return tint_symbol_1;
}

View File

@@ -0,0 +1,14 @@
#include <metal_stdlib>
using namespace metal;
struct tint_symbol {
float4 value [[color(0)]];
};
fragment tint_symbol frag_main() {
float b = 0.0f;
float3 v = float3(b);
tint_symbol const tint_symbol_1 = {.value=float4(v, 1.0f)};
return tint_symbol_1;
}

View File

@@ -0,0 +1,53 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 31
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %frag_main "frag_main" %tint_symbol_1
OpExecutionMode %frag_main OriginUpperLeft
OpName %tint_symbol_1 "tint_symbol_1"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol "tint_symbol"
OpName %frag_main "frag_main"
OpName %b "b"
OpName %v "v"
OpDecorate %tint_symbol_1 Location 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%5 = OpConstantNull %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %5
%void = OpTypeVoid
%6 = OpTypeFunction %void %v4float
%11 = OpTypeFunction %void
%float_0 = OpConstant %float 0
%_ptr_Function_float = OpTypePointer Function %float
%17 = OpConstantNull %float
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
%23 = OpConstantNull %v3float
%float_1 = OpConstant %float 1
%tint_symbol_2 = OpFunction %void None %6
%tint_symbol = OpFunctionParameter %v4float
%10 = OpLabel
OpStore %tint_symbol_1 %tint_symbol
OpReturn
OpFunctionEnd
%frag_main = OpFunction %void None %11
%13 = OpLabel
%b = OpVariable %_ptr_Function_float Function %17
%v = OpVariable %_ptr_Function_v3float Function %23
OpStore %b %float_0
%19 = OpLoad %float %b
%20 = OpCompositeConstruct %v3float %19 %19 %19
OpStore %v %20
%25 = OpLoad %v3float %v
%26 = OpCompositeExtract %float %25 0
%27 = OpCompositeExtract %float %25 1
%28 = OpCompositeExtract %float %25 2
%30 = OpCompositeConstruct %v4float %26 %27 %28 %float_1
%24 = OpFunctionCall %void %tint_symbol_2 %30
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
[[stage(fragment)]]
fn frag_main() -> [[location(0)]] vec4<f32> {
var b : f32 = 0.0;
var v : vec3<f32> = vec3<f32>(b);
return vec4<f32>(v, 1.0);
}

View File

@@ -0,0 +1,6 @@
fn f() {
var v = true || false;
var v2 : vec2<bool> = vec2<bool>(v);
var v3 : vec3<bool> = vec3<bool>(v);
var v4 : vec4<bool> = vec4<bool>(v);
}

View File

@@ -0,0 +1,15 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
bool tint_tmp = true;
if (!tint_tmp) {
tint_tmp = false;
}
bool v = (tint_tmp);
bool2 v2 = bool2((v).xx);
bool3 v3 = bool3((v).xxx);
bool4 v4 = bool4((v).xxxx);
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
void f() {
bool v = (true || false);
bool2 v2 = bool2(v);
bool3 v3 = bool3(v);
bool4 v4 = bool4(v);
}

View File

@@ -0,0 +1,59 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 34
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %v "v"
OpName %v2 "v2"
OpName %v3 "v3"
OpName %v4 "v4"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%bool = OpTypeBool
%true = OpConstantTrue %bool
%false = OpConstantFalse %bool
%_ptr_Function_bool = OpTypePointer Function %bool
%15 = OpConstantNull %bool
%v2bool = OpTypeVector %bool 2
%_ptr_Function_v2bool = OpTypePointer Function %v2bool
%21 = OpConstantNull %v2bool
%v3bool = OpTypeVector %bool 3
%_ptr_Function_v3bool = OpTypePointer Function %v3bool
%27 = OpConstantNull %v3bool
%v4bool = OpTypeVector %bool 4
%_ptr_Function_v4bool = OpTypePointer Function %v4bool
%33 = OpConstantNull %v4bool
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%v = OpVariable %_ptr_Function_bool Function %15
%v2 = OpVariable %_ptr_Function_v2bool Function %21
%v3 = OpVariable %_ptr_Function_v3bool Function %27
%v4 = OpVariable %_ptr_Function_v4bool Function %33
OpSelectionMerge %9 None
OpBranchConditional %true %9 %10
%10 = OpLabel
OpBranch %9
%9 = OpLabel
%12 = OpPhi %bool %true %6 %false %10
OpStore %v %12
%17 = OpLoad %bool %v
%18 = OpCompositeConstruct %v2bool %17 %17
OpStore %v2 %18
%23 = OpLoad %bool %v
%24 = OpCompositeConstruct %v3bool %23 %23 %23
OpStore %v3 %24
%29 = OpLoad %bool %v
%30 = OpCompositeConstruct %v4bool %29 %29 %29 %29
OpStore %v4 %30
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
fn f() {
var v = (true || false);
var v2 : vec2<bool> = vec2<bool>(v);
var v3 : vec3<bool> = vec3<bool>(v);
var v4 : vec4<bool> = vec4<bool>(v);
}

View File

@@ -0,0 +1,6 @@
fn f() {
var v = 1.0 + 2.0;
var v2 : vec2<f32> = vec2<f32>(v);
var v3 : vec3<f32> = vec3<f32>(v);
var v4 : vec4<f32> = vec4<f32>(v);
}

View File

@@ -0,0 +1,11 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float v = (1.0f + 2.0f);
float2 v2 = float2((v).xx);
float3 v3 = float3((v).xxx);
float4 v4 = float4((v).xxxx);
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float v = (1.0f + 2.0f);
float2 v2 = float2(v);
float3 v3 = float3(v);
float4 v4 = float4(v);
}

View File

@@ -0,0 +1,54 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 32
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %v "v"
OpName %v2 "v2"
OpName %v3 "v3"
OpName %v4 "v4"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%float_1 = OpConstant %float 1
%float_2 = OpConstant %float 2
%_ptr_Function_float = OpTypePointer Function %float
%13 = OpConstantNull %float
%v2float = OpTypeVector %float 2
%_ptr_Function_v2float = OpTypePointer Function %v2float
%19 = OpConstantNull %v2float
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
%25 = OpConstantNull %v3float
%v4float = OpTypeVector %float 4
%_ptr_Function_v4float = OpTypePointer Function %v4float
%31 = OpConstantNull %v4float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%v = OpVariable %_ptr_Function_float Function %13
%v2 = OpVariable %_ptr_Function_v2float Function %19
%v3 = OpVariable %_ptr_Function_v3float Function %25
%v4 = OpVariable %_ptr_Function_v4float Function %31
%10 = OpFAdd %float %float_1 %float_2
OpStore %v %10
%15 = OpLoad %float %v
%16 = OpCompositeConstruct %v2float %15 %15
OpStore %v2 %16
%21 = OpLoad %float %v
%22 = OpCompositeConstruct %v3float %21 %21 %21
OpStore %v3 %22
%27 = OpLoad %float %v
%28 = OpCompositeConstruct %v4float %27 %27 %27 %27
OpStore %v4 %28
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
fn f() {
var v = (1.0 + 2.0);
var v2 : vec2<f32> = vec2<f32>(v);
var v3 : vec3<f32> = vec3<f32>(v);
var v4 : vec4<f32> = vec4<f32>(v);
}

View File

@@ -0,0 +1,6 @@
fn f() {
var v = 1 + 2;
var v2 : vec2<i32> = vec2<i32>(v);
var v3 : vec3<i32> = vec3<i32>(v);
var v4 : vec4<i32> = vec4<i32>(v);
}

View File

@@ -0,0 +1,11 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
int v = (1 + 2);
int2 v2 = int2((v).xx);
int3 v3 = int3((v).xxx);
int4 v4 = int4((v).xxxx);
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
void f() {
int v = (1 + 2);
int2 v2 = int2(v);
int3 v3 = int3(v);
int4 v4 = int4(v);
}

View File

@@ -0,0 +1,54 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 32
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %v "v"
OpName %v2 "v2"
OpName %v3 "v3"
OpName %v4 "v4"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%_ptr_Function_int = OpTypePointer Function %int
%13 = OpConstantNull %int
%v2int = OpTypeVector %int 2
%_ptr_Function_v2int = OpTypePointer Function %v2int
%19 = OpConstantNull %v2int
%v3int = OpTypeVector %int 3
%_ptr_Function_v3int = OpTypePointer Function %v3int
%25 = OpConstantNull %v3int
%v4int = OpTypeVector %int 4
%_ptr_Function_v4int = OpTypePointer Function %v4int
%31 = OpConstantNull %v4int
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%v = OpVariable %_ptr_Function_int Function %13
%v2 = OpVariable %_ptr_Function_v2int Function %19
%v3 = OpVariable %_ptr_Function_v3int Function %25
%v4 = OpVariable %_ptr_Function_v4int Function %31
%10 = OpIAdd %int %int_1 %int_2
OpStore %v %10
%15 = OpLoad %int %v
%16 = OpCompositeConstruct %v2int %15 %15
OpStore %v2 %16
%21 = OpLoad %int %v
%22 = OpCompositeConstruct %v3int %21 %21 %21
OpStore %v3 %22
%27 = OpLoad %int %v
%28 = OpCompositeConstruct %v4int %27 %27 %27 %27
OpStore %v4 %28
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
fn f() {
var v = (1 + 2);
var v2 : vec2<i32> = vec2<i32>(v);
var v3 : vec3<i32> = vec3<i32>(v);
var v4 : vec4<i32> = vec4<i32>(v);
}

View File

@@ -0,0 +1,6 @@
fn f() {
var v = 1u + 2u;
var v2 : vec2<u32> = vec2<u32>(v);
var v3 : vec3<u32> = vec3<u32>(v);
var v4 : vec4<u32> = vec4<u32>(v);
}

View File

@@ -0,0 +1,11 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
uint v = (1u + 2u);
uint2 v2 = uint2((v).xx);
uint3 v3 = uint3((v).xxx);
uint4 v4 = uint4((v).xxxx);
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
void f() {
uint v = (1u + 2u);
uint2 v2 = uint2(v);
uint3 v3 = uint3(v);
uint4 v4 = uint4(v);
}

View File

@@ -0,0 +1,54 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 32
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %v "v"
OpName %v2 "v2"
OpName %v3 "v3"
OpName %v4 "v4"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%_ptr_Function_uint = OpTypePointer Function %uint
%13 = OpConstantNull %uint
%v2uint = OpTypeVector %uint 2
%_ptr_Function_v2uint = OpTypePointer Function %v2uint
%19 = OpConstantNull %v2uint
%v3uint = OpTypeVector %uint 3
%_ptr_Function_v3uint = OpTypePointer Function %v3uint
%25 = OpConstantNull %v3uint
%v4uint = OpTypeVector %uint 4
%_ptr_Function_v4uint = OpTypePointer Function %v4uint
%31 = OpConstantNull %v4uint
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%v = OpVariable %_ptr_Function_uint Function %13
%v2 = OpVariable %_ptr_Function_v2uint Function %19
%v3 = OpVariable %_ptr_Function_v3uint Function %25
%v4 = OpVariable %_ptr_Function_v4uint Function %31
%10 = OpIAdd %uint %uint_1 %uint_2
OpStore %v %10
%15 = OpLoad %uint %v
%16 = OpCompositeConstruct %v2uint %15 %15
OpStore %v2 %16
%21 = OpLoad %uint %v
%22 = OpCompositeConstruct %v3uint %21 %21 %21
OpStore %v3 %22
%27 = OpLoad %uint %v
%28 = OpCompositeConstruct %v4uint %27 %27 %27 %27
OpStore %v4 %28
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
fn f() {
var v = (1u + 2u);
var v2 : vec2<u32> = vec2<u32>(v);
var v3 : vec3<u32> = vec3<u32>(v);
var v4 : vec4<u32> = vec4<u32>(v);
}