mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-05 12:46:11 +00:00
Add `transform::DecomposeStridedMatrix`, which replaces matrix members of storage or uniform buffer structures, that have a [[stride]] decoration, into an array of N column vectors. This is required to correctly handle `mat2x2` matrices in UBOs, as std140 rules will expect a default stride of 16 bytes, when in WGSL the default structure layout expects a stride of 8 bytes. Bug: tint:1047 Change-Id: If5ca3c6ec087bbc1ac31a8d9a657b99bf34042a4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59840 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
35 lines
783 B
Plaintext
35 lines
783 B
Plaintext
#include <metal_stdlib>
|
|
|
|
using namespace metal;
|
|
struct tint_padded_array_element {
|
|
/* 0x0000 */ packed_float2 el;
|
|
/* 0x0008 */ int8_t tint_pad[8];
|
|
};
|
|
struct tint_array_wrapper {
|
|
/* 0x0000 */ tint_padded_array_element arr[2];
|
|
};
|
|
struct SSBO {
|
|
/* 0x0000 */ tint_array_wrapper m;
|
|
};
|
|
|
|
float2x2 arr_to_mat2x2_stride_16(tint_array_wrapper arr) {
|
|
return float2x2(arr.arr[0u].el, arr.arr[1u].el);
|
|
}
|
|
|
|
tint_array_wrapper mat2x2_stride_16_to_arr(float2x2 mat) {
|
|
tint_array_wrapper const tint_symbol = {.arr={{.el=mat[0u]}, {.el=mat[1u]}}};
|
|
return tint_symbol;
|
|
}
|
|
|
|
void f_1(device SSBO& ssbo) {
|
|
float2x2 const x_15 = arr_to_mat2x2_stride_16(ssbo.m);
|
|
ssbo.m = mat2x2_stride_16_to_arr(x_15);
|
|
return;
|
|
}
|
|
|
|
kernel void f(device SSBO& ssbo [[buffer(0)]]) {
|
|
f_1(ssbo);
|
|
return;
|
|
}
|
|
|