mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
msl: Overload matrix-vector arithmetic operators
These operators are not defined in the metal namespace when the vector operands are packed. Fixed: tint:1121 Change-Id: I2e8f4302e08117ca41bac6c05fb24a70d1215740 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/62480 Kokoro: Kokoro <noreply+kokoro@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
11
test/expressions/binary/mul/mat3x2-vec3/f32.wgsl
Normal file
11
test/expressions/binary/mul/mat3x2-vec3/f32.wgsl
Normal file
@@ -0,0 +1,11 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x2<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
[[group(0), binding(0)]] var<uniform> data: S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = data.matrix * data.vector;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
cbuffer cbuffer_data : register(b0, space0) {
|
||||
uint4 data[3];
|
||||
};
|
||||
|
||||
float3x2 tint_symbol_2(uint4 buffer[3], uint offset) {
|
||||
const uint scalar_offset = ((offset + 0u)) / 4;
|
||||
uint4 ubo_load = buffer[scalar_offset / 4];
|
||||
const uint scalar_offset_1 = ((offset + 8u)) / 4;
|
||||
uint4 ubo_load_1 = buffer[scalar_offset_1 / 4];
|
||||
const uint scalar_offset_2 = ((offset + 16u)) / 4;
|
||||
uint4 ubo_load_2 = buffer[scalar_offset_2 / 4];
|
||||
return float3x2(asfloat(((scalar_offset & 2) ? ubo_load.zw : ubo_load.xy)), asfloat(((scalar_offset_1 & 2) ? ubo_load_1.zw : ubo_load_1.xy)), asfloat(((scalar_offset_2 & 2) ? ubo_load_2.zw : ubo_load_2.xy)));
|
||||
}
|
||||
|
||||
void main() {
|
||||
const float2 x = mul(asfloat(data[2].xyz), tint_symbol_2(data, 0u));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
||||
return lhs * vec<T, N>(rhs);
|
||||
}
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
||||
return vec<T, M>(lhs) * rhs;
|
||||
}
|
||||
|
||||
struct S {
|
||||
/* 0x0000 */ float3x2 tint_symbol;
|
||||
/* 0x0018 */ int8_t tint_pad[8];
|
||||
/* 0x0020 */ packed_float3 vector;
|
||||
/* 0x002c */ int8_t tint_pad_1[4];
|
||||
};
|
||||
|
||||
fragment void tint_symbol_1(constant S& data [[buffer(0)]]) {
|
||||
float2 const x = (data.tint_symbol * data.vector);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 22
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main"
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %S "S"
|
||||
OpMemberName %S 0 "matrix"
|
||||
OpMemberName %S 1 "vector"
|
||||
OpName %data "data"
|
||||
OpName %main "main"
|
||||
OpDecorate %S Block
|
||||
OpMemberDecorate %S 0 Offset 0
|
||||
OpMemberDecorate %S 0 ColMajor
|
||||
OpMemberDecorate %S 0 MatrixStride 8
|
||||
OpMemberDecorate %S 1 Offset 32
|
||||
OpDecorate %data NonWritable
|
||||
OpDecorate %data DescriptorSet 0
|
||||
OpDecorate %data Binding 0
|
||||
%float = OpTypeFloat 32
|
||||
%v2float = OpTypeVector %float 2
|
||||
%mat3v2float = OpTypeMatrix %v2float 3
|
||||
%v3float = OpTypeVector %float 3
|
||||
%S = OpTypeStruct %mat3v2float %v3float
|
||||
%_ptr_Uniform_S = OpTypePointer Uniform %S
|
||||
%data = OpVariable %_ptr_Uniform_S Uniform
|
||||
%void = OpTypeVoid
|
||||
%8 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Uniform_mat3v2float = OpTypePointer Uniform %mat3v2float
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%main = OpFunction %void None %8
|
||||
%11 = OpLabel
|
||||
%15 = OpAccessChain %_ptr_Uniform_mat3v2float %data %uint_0
|
||||
%16 = OpLoad %mat3v2float %15
|
||||
%19 = OpAccessChain %_ptr_Uniform_v3float %data %uint_1
|
||||
%20 = OpLoad %v3float %19
|
||||
%21 = OpMatrixTimesVector %v2float %16 %20
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,12 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x2<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> data : S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = (data.matrix * data.vector);
|
||||
}
|
||||
11
test/expressions/binary/mul/mat3x3-vec3/f32.wgsl
Normal file
11
test/expressions/binary/mul/mat3x3-vec3/f32.wgsl
Normal file
@@ -0,0 +1,11 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
[[group(0), binding(0)]] var<uniform> data: S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = data.matrix * data.vector;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
cbuffer cbuffer_data : register(b0, space0) {
|
||||
uint4 data[4];
|
||||
};
|
||||
|
||||
float3x3 tint_symbol_2(uint4 buffer[4], uint offset) {
|
||||
const uint scalar_offset = ((offset + 0u)) / 4;
|
||||
const uint scalar_offset_1 = ((offset + 16u)) / 4;
|
||||
const uint scalar_offset_2 = ((offset + 32u)) / 4;
|
||||
return float3x3(asfloat(buffer[scalar_offset / 4].xyz), asfloat(buffer[scalar_offset_1 / 4].xyz), asfloat(buffer[scalar_offset_2 / 4].xyz));
|
||||
}
|
||||
|
||||
void main() {
|
||||
const float3 x = mul(asfloat(data[3].xyz), tint_symbol_2(data, 0u));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
||||
return lhs * vec<T, N>(rhs);
|
||||
}
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
||||
return vec<T, M>(lhs) * rhs;
|
||||
}
|
||||
|
||||
struct S {
|
||||
/* 0x0000 */ float3x3 tint_symbol;
|
||||
/* 0x0030 */ packed_float3 vector;
|
||||
/* 0x003c */ int8_t tint_pad[4];
|
||||
};
|
||||
|
||||
fragment void tint_symbol_1(constant S& data [[buffer(0)]]) {
|
||||
float3 const x = (data.tint_symbol * data.vector);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 21
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main"
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %S "S"
|
||||
OpMemberName %S 0 "matrix"
|
||||
OpMemberName %S 1 "vector"
|
||||
OpName %data "data"
|
||||
OpName %main "main"
|
||||
OpDecorate %S Block
|
||||
OpMemberDecorate %S 0 Offset 0
|
||||
OpMemberDecorate %S 0 ColMajor
|
||||
OpMemberDecorate %S 0 MatrixStride 16
|
||||
OpMemberDecorate %S 1 Offset 48
|
||||
OpDecorate %data NonWritable
|
||||
OpDecorate %data DescriptorSet 0
|
||||
OpDecorate %data Binding 0
|
||||
%float = OpTypeFloat 32
|
||||
%v3float = OpTypeVector %float 3
|
||||
%mat3v3float = OpTypeMatrix %v3float 3
|
||||
%S = OpTypeStruct %mat3v3float %v3float
|
||||
%_ptr_Uniform_S = OpTypePointer Uniform %S
|
||||
%data = OpVariable %_ptr_Uniform_S Uniform
|
||||
%void = OpTypeVoid
|
||||
%7 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%main = OpFunction %void None %7
|
||||
%10 = OpLabel
|
||||
%14 = OpAccessChain %_ptr_Uniform_mat3v3float %data %uint_0
|
||||
%15 = OpLoad %mat3v3float %14
|
||||
%18 = OpAccessChain %_ptr_Uniform_v3float %data %uint_1
|
||||
%19 = OpLoad %v3float %18
|
||||
%20 = OpMatrixTimesVector %v3float %15 %19
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,12 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> data : S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = (data.matrix * data.vector);
|
||||
}
|
||||
11
test/expressions/binary/mul/vec3-mat3x3/f32.wgsl
Normal file
11
test/expressions/binary/mul/vec3-mat3x3/f32.wgsl
Normal file
@@ -0,0 +1,11 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
[[group(0), binding(0)]] var<uniform> data: S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = data.vector * data.matrix;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
cbuffer cbuffer_data : register(b0, space0) {
|
||||
uint4 data[4];
|
||||
};
|
||||
|
||||
float3x3 tint_symbol_3(uint4 buffer[4], uint offset) {
|
||||
const uint scalar_offset = ((offset + 0u)) / 4;
|
||||
const uint scalar_offset_1 = ((offset + 16u)) / 4;
|
||||
const uint scalar_offset_2 = ((offset + 32u)) / 4;
|
||||
return float3x3(asfloat(buffer[scalar_offset / 4].xyz), asfloat(buffer[scalar_offset_1 / 4].xyz), asfloat(buffer[scalar_offset_2 / 4].xyz));
|
||||
}
|
||||
|
||||
void main() {
|
||||
const float3 x = mul(tint_symbol_3(data, 0u), asfloat(data[3].xyz));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
||||
return lhs * vec<T, N>(rhs);
|
||||
}
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
||||
return vec<T, M>(lhs) * rhs;
|
||||
}
|
||||
|
||||
struct S {
|
||||
/* 0x0000 */ float3x3 tint_symbol;
|
||||
/* 0x0030 */ packed_float3 vector;
|
||||
/* 0x003c */ int8_t tint_pad[4];
|
||||
};
|
||||
|
||||
fragment void tint_symbol_1(constant S& data [[buffer(0)]]) {
|
||||
float3 const x = (data.vector * data.tint_symbol);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 21
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main"
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %S "S"
|
||||
OpMemberName %S 0 "matrix"
|
||||
OpMemberName %S 1 "vector"
|
||||
OpName %data "data"
|
||||
OpName %main "main"
|
||||
OpDecorate %S Block
|
||||
OpMemberDecorate %S 0 Offset 0
|
||||
OpMemberDecorate %S 0 ColMajor
|
||||
OpMemberDecorate %S 0 MatrixStride 16
|
||||
OpMemberDecorate %S 1 Offset 48
|
||||
OpDecorate %data NonWritable
|
||||
OpDecorate %data DescriptorSet 0
|
||||
OpDecorate %data Binding 0
|
||||
%float = OpTypeFloat 32
|
||||
%v3float = OpTypeVector %float 3
|
||||
%mat3v3float = OpTypeMatrix %v3float 3
|
||||
%S = OpTypeStruct %mat3v3float %v3float
|
||||
%_ptr_Uniform_S = OpTypePointer Uniform %S
|
||||
%data = OpVariable %_ptr_Uniform_S Uniform
|
||||
%void = OpTypeVoid
|
||||
%7 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
|
||||
%main = OpFunction %void None %7
|
||||
%10 = OpLabel
|
||||
%14 = OpAccessChain %_ptr_Uniform_v3float %data %uint_1
|
||||
%15 = OpLoad %v3float %14
|
||||
%18 = OpAccessChain %_ptr_Uniform_mat3v3float %data %uint_0
|
||||
%19 = OpLoad %mat3v3float %18
|
||||
%20 = OpVectorTimesMatrix %v3float %15 %19
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,12 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat3x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> data : S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = (data.vector * data.matrix);
|
||||
}
|
||||
11
test/expressions/binary/mul/vec3-mat4x3/f32.wgsl
Normal file
11
test/expressions/binary/mul/vec3-mat4x3/f32.wgsl
Normal file
@@ -0,0 +1,11 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat4x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
[[group(0), binding(0)]] var<uniform> data: S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = data.vector * data.matrix;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
cbuffer cbuffer_data : register(b0, space0) {
|
||||
uint4 data[5];
|
||||
};
|
||||
|
||||
float4x3 tint_symbol_3(uint4 buffer[5], uint offset) {
|
||||
const uint scalar_offset = ((offset + 0u)) / 4;
|
||||
const uint scalar_offset_1 = ((offset + 16u)) / 4;
|
||||
const uint scalar_offset_2 = ((offset + 32u)) / 4;
|
||||
const uint scalar_offset_3 = ((offset + 48u)) / 4;
|
||||
return float4x3(asfloat(buffer[scalar_offset / 4].xyz), asfloat(buffer[scalar_offset_1 / 4].xyz), asfloat(buffer[scalar_offset_2 / 4].xyz), asfloat(buffer[scalar_offset_3 / 4].xyz));
|
||||
}
|
||||
|
||||
void main() {
|
||||
const float4 x = mul(tint_symbol_3(data, 0u), asfloat(data[4].xyz));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
||||
return lhs * vec<T, N>(rhs);
|
||||
}
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
||||
return vec<T, M>(lhs) * rhs;
|
||||
}
|
||||
|
||||
struct S {
|
||||
/* 0x0000 */ float4x3 tint_symbol;
|
||||
/* 0x0040 */ packed_float3 vector;
|
||||
/* 0x004c */ int8_t tint_pad[4];
|
||||
};
|
||||
|
||||
fragment void tint_symbol_1(constant S& data [[buffer(0)]]) {
|
||||
float4 const x = (data.vector * data.tint_symbol);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 22
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main"
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %S "S"
|
||||
OpMemberName %S 0 "matrix"
|
||||
OpMemberName %S 1 "vector"
|
||||
OpName %data "data"
|
||||
OpName %main "main"
|
||||
OpDecorate %S Block
|
||||
OpMemberDecorate %S 0 Offset 0
|
||||
OpMemberDecorate %S 0 ColMajor
|
||||
OpMemberDecorate %S 0 MatrixStride 16
|
||||
OpMemberDecorate %S 1 Offset 64
|
||||
OpDecorate %data NonWritable
|
||||
OpDecorate %data DescriptorSet 0
|
||||
OpDecorate %data Binding 0
|
||||
%float = OpTypeFloat 32
|
||||
%v3float = OpTypeVector %float 3
|
||||
%mat4v3float = OpTypeMatrix %v3float 4
|
||||
%S = OpTypeStruct %mat4v3float %v3float
|
||||
%_ptr_Uniform_S = OpTypePointer Uniform %S
|
||||
%data = OpVariable %_ptr_Uniform_S Uniform
|
||||
%void = OpTypeVoid
|
||||
%7 = OpTypeFunction %void
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_1 = OpConstant %uint 1
|
||||
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
|
||||
%uint_0 = OpConstant %uint 0
|
||||
%_ptr_Uniform_mat4v3float = OpTypePointer Uniform %mat4v3float
|
||||
%v4float = OpTypeVector %float 4
|
||||
%main = OpFunction %void None %7
|
||||
%10 = OpLabel
|
||||
%14 = OpAccessChain %_ptr_Uniform_v3float %data %uint_1
|
||||
%15 = OpLoad %v3float %14
|
||||
%18 = OpAccessChain %_ptr_Uniform_mat4v3float %data %uint_0
|
||||
%19 = OpLoad %mat4v3float %18
|
||||
%20 = OpVectorTimesMatrix %v4float %15 %19
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,12 @@
|
||||
[[block]]
|
||||
struct S {
|
||||
matrix : mat4x3<f32>;
|
||||
vector : vec3<f32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> data : S;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
let x = (data.vector * data.matrix);
|
||||
}
|
||||
Reference in New Issue
Block a user