mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-06 04:05:40 +00:00
Instead of a ConstantBuffer. HLSL requires that each structure field in a UBO is 16 byte aligned. WGSL has much looser constraints with its UBO field alignment rules. Instead generate an array of uint4 vectors, and index into this, much like we index into [RW]ByteAddressBuffers for SSBOs. Extend the DecomposeStorageAccess transform to support uniforms too. This has been renamed to DecomposeMemoryAccess. Change-Id: I3868ff80af1ab3b3dddfbf5b969724cb87ef0744 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55246 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com>
39 lines
1.2 KiB
HLSL
39 lines
1.2 KiB
HLSL
ByteAddressBuffer firstMatrix : register(t0, space0);
|
|
ByteAddressBuffer secondMatrix : register(t1, space0);
|
|
RWByteAddressBuffer resultMatrix : register(u2, space0);
|
|
cbuffer cbuffer_uniforms : register(b3, space0) {
|
|
uint4 uniforms[2];
|
|
};
|
|
|
|
struct tint_symbol_1 {
|
|
uint3 global_id : SV_DispatchThreadID;
|
|
};
|
|
|
|
[numthreads(2, 2, 1)]
|
|
void main(tint_symbol_1 tint_symbol) {
|
|
const uint3 global_id = tint_symbol.global_id;
|
|
const uint2 resultCell = uint2(global_id.y, global_id.x);
|
|
const int scalar_offset = (4u) / 4;
|
|
const uint dimInner = uniforms[scalar_offset / 4][scalar_offset % 4];
|
|
const int scalar_offset_1 = (20u) / 4;
|
|
const uint dimOutter = uniforms[scalar_offset_1 / 4][scalar_offset_1 % 4];
|
|
uint result = 0u;
|
|
{
|
|
uint i = 0u;
|
|
while (true) {
|
|
if (!((i < dimInner))) {
|
|
break;
|
|
}
|
|
const uint a = (i + (resultCell.x * dimInner));
|
|
const uint b = (resultCell.y + (i * dimOutter));
|
|
result = (result + (firstMatrix.Load((4u * a)) * secondMatrix.Load((4u * b))));
|
|
{
|
|
i = (i + 1u);
|
|
}
|
|
}
|
|
}
|
|
const uint index = (resultCell.y + (resultCell.x * dimOutter));
|
|
resultMatrix.Store((4u * index), asuint(result));
|
|
return;
|
|
}
|