tint: spir-v writer: Fix matrix constructor from matrix variable

Bug: tint:1603
Change-Id: I580a450daa9392316cb628ceeb16490ec591deba
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94860
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
Antonio Maiorano 2022-06-27 20:07:45 +00:00 committed by Dawn LUCI CQ
parent 7c5255a197
commit ce466c0df3
55 changed files with 605 additions and 0 deletions

View File

@ -1362,6 +1362,15 @@ uint32_t Builder::GenerateTypeConstructorOrConversion(const sem::Call* call,
} }
} }
if (auto* res_mat = result_type->As<sem::Matrix>()) {
auto* value_type = args[0]->Type()->UnwrapRef();
if (auto* val_mat = value_type->As<sem::Matrix>()) {
// Generate passthrough for matrices of the same type
can_cast_or_copy =
(res_mat->columns() == val_mat->columns()) && (res_mat->rows() == val_mat->rows());
}
}
if (can_cast_or_copy) { if (can_cast_or_copy) {
return GenerateCastOrCopyOrPassthrough(result_type, args[0]->Declaration(), global_var); return GenerateCastOrCopyOrPassthrough(result_type, args[0]->Declaration(), global_var);
} }
@ -1607,6 +1616,8 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(const sem::Type* to_type,
} }
return result_id; return result_id;
} else if (from_type->Is<sem::Matrix>()) {
return val_id;
} else { } else {
TINT_ICE(Writer, builder_.Diagnostics()) << "Invalid from_type"; TINT_ICE(Writer, builder_.Diagnostics()) << "Invalid from_type";
} }

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x2<f32>();
let m_1 = mat2x2(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat2 m = mat2(vec2(0.0f), vec2(0.0f));
mat2 m_1 = mat2(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float2x2 m = float2x2((0.0f).xx, (0.0f).xx);
const float2x2 m_1 = float2x2(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float2x2 m = float2x2(float2(0.0f), float2(0.0f));
float2x2 const m_1 = float2x2(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%10 = OpConstantNull %mat2v2float
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat2v2float Function %10
OpStore %m %10
%14 = OpLoad %mat2v2float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x2<f32>();
let m_1 = mat2x2(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x3<f32>();
let m_1 = mat2x3(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat2x3 m = mat2x3(vec3(0.0f), vec3(0.0f));
mat2x3 m_1 = mat2x3(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float2x3 m = float2x3((0.0f).xxx, (0.0f).xxx);
const float2x3 m_1 = float2x3(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float2x3 m = float2x3(float3(0.0f), float3(0.0f));
float2x3 const m_1 = float2x3(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%mat2v3float = OpTypeMatrix %v3float 2
%10 = OpConstantNull %mat2v3float
%_ptr_Function_mat2v3float = OpTypePointer Function %mat2v3float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat2v3float Function %10
OpStore %m %10
%14 = OpLoad %mat2v3float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x3<f32>();
let m_1 = mat2x3(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x4<f32>();
let m_1 = mat2x4(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat2x4 m = mat2x4(vec4(0.0f), vec4(0.0f));
mat2x4 m_1 = mat2x4(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float2x4 m = float2x4((0.0f).xxxx, (0.0f).xxxx);
const float2x4 m_1 = float2x4(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float2x4 m = float2x4(float4(0.0f), float4(0.0f));
float2x4 const m_1 = float2x4(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat2v4float = OpTypeMatrix %v4float 2
%10 = OpConstantNull %mat2v4float
%_ptr_Function_mat2v4float = OpTypePointer Function %mat2v4float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat2v4float Function %10
OpStore %m %10
%14 = OpLoad %mat2v4float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat2x4<f32>();
let m_1 = mat2x4(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x2<f32>();
let m_1 = mat3x2(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat3x2 m = mat3x2(vec2(0.0f), vec2(0.0f), vec2(0.0f));
mat3x2 m_1 = mat3x2(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float3x2 m = float3x2((0.0f).xx, (0.0f).xx, (0.0f).xx);
const float3x2 m_1 = float3x2(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float3x2 m = float3x2(float2(0.0f), float2(0.0f), float2(0.0f));
float3x2 const m_1 = float3x2(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat3v2float = OpTypeMatrix %v2float 3
%10 = OpConstantNull %mat3v2float
%_ptr_Function_mat3v2float = OpTypePointer Function %mat3v2float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat3v2float Function %10
OpStore %m %10
%14 = OpLoad %mat3v2float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x2<f32>();
let m_1 = mat3x2(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x3<f32>();
let m_1 = mat3x3(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat3 m = mat3(vec3(0.0f), vec3(0.0f), vec3(0.0f));
mat3 m_1 = mat3(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float3x3 m = float3x3((0.0f).xxx, (0.0f).xxx, (0.0f).xxx);
const float3x3 m_1 = float3x3(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float3x3 m = float3x3(float3(0.0f), float3(0.0f), float3(0.0f));
float3x3 const m_1 = float3x3(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%mat3v3float = OpTypeMatrix %v3float 3
%10 = OpConstantNull %mat3v3float
%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat3v3float Function %10
OpStore %m %10
%14 = OpLoad %mat3v3float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x3<f32>();
let m_1 = mat3x3(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x4<f32>();
let m_1 = mat3x4(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat3x4 m = mat3x4(vec4(0.0f), vec4(0.0f), vec4(0.0f));
mat3x4 m_1 = mat3x4(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float3x4 m = float3x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx);
const float3x4 m_1 = float3x4(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float3x4 m = float3x4(float4(0.0f), float4(0.0f), float4(0.0f));
float3x4 const m_1 = float3x4(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat3v4float = OpTypeMatrix %v4float 3
%10 = OpConstantNull %mat3v4float
%_ptr_Function_mat3v4float = OpTypePointer Function %mat3v4float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat3v4float Function %10
OpStore %m %10
%14 = OpLoad %mat3v4float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat3x4<f32>();
let m_1 = mat3x4(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x2<f32>();
let m_1 = mat4x2(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat4x2 m = mat4x2(vec2(0.0f), vec2(0.0f), vec2(0.0f), vec2(0.0f));
mat4x2 m_1 = mat4x2(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float4x2 m = float4x2((0.0f).xx, (0.0f).xx, (0.0f).xx, (0.0f).xx);
const float4x2 m_1 = float4x2(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float4x2 m = float4x2(float2(0.0f), float2(0.0f), float2(0.0f), float2(0.0f));
float4x2 const m_1 = float4x2(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat4v2float = OpTypeMatrix %v2float 4
%10 = OpConstantNull %mat4v2float
%_ptr_Function_mat4v2float = OpTypePointer Function %mat4v2float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat4v2float Function %10
OpStore %m %10
%14 = OpLoad %mat4v2float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x2<f32>();
let m_1 = mat4x2(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x3<f32>();
let m_1 = mat4x3(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat4x3 m = mat4x3(vec3(0.0f), vec3(0.0f), vec3(0.0f), vec3(0.0f));
mat4x3 m_1 = mat4x3(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float4x3 m = float4x3((0.0f).xxx, (0.0f).xxx, (0.0f).xxx, (0.0f).xxx);
const float4x3 m_1 = float4x3(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float4x3 m = float4x3(float3(0.0f), float3(0.0f), float3(0.0f), float3(0.0f));
float4x3 const m_1 = float4x3(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%mat4v3float = OpTypeMatrix %v3float 4
%10 = OpConstantNull %mat4v3float
%_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat4v3float Function %10
OpStore %m %10
%14 = OpLoad %mat4v3float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x3<f32>();
let m_1 = mat4x3(m);
}

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x4<f32>();
let m_1 = mat4x4(m);
}

View File

@ -0,0 +1,11 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
void f() {
mat4 m = mat4(vec4(0.0f), vec4(0.0f), vec4(0.0f), vec4(0.0f));
mat4 m_1 = mat4(m);
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
float4x4 m = float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx);
const float4x4 m_1 = float4x4(m);
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
float4x4 m = float4x4(float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f));
float4x4 const m_1 = float4x4(m);
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; 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 %m "m"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat4v4float = OpTypeMatrix %v4float 4
%10 = OpConstantNull %mat4v4float
%_ptr_Function_mat4v4float = OpTypePointer Function %mat4v4float
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%m = OpVariable %_ptr_Function_mat4v4float Function %10
OpStore %m %10
%14 = OpLoad %mat4v4float %m
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
var m = mat4x4<f32>();
let m_1 = mat4x4(m);
}