tint: Preserve padding in matrices with three rows

The PreservePadding transform now decomposes writes to matrices with
three rows into separate column vector writes, to avoid modifying
padding between columns.

Bug: tint:1571
Change-Id: If575f79bb87f52810783fd3338e2f3ce3228ab2e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121600
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price
2023-02-27 16:06:54 +00:00
committed by Dawn LUCI CQ
parent fe19fee3ea
commit 6176c85be8
84 changed files with 3733 additions and 1968 deletions

View File

@@ -8,9 +8,25 @@ layout(binding = 1, std430) buffer u_block_ssbo {
mat3 inner[4];
} s;
void assign_and_preserve_padding_1_s_X(uint dest[1], mat3 value) {
s.inner[dest[0]][0] = value[0u];
s.inner[dest[0]][1] = value[1u];
s.inner[dest[0]][2] = value[2u];
}
void assign_and_preserve_padding_s(mat3 value[4]) {
{
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
uint tint_symbol[1] = uint[1](i);
assign_and_preserve_padding_1_s_X(tint_symbol, value[i]);
}
}
}
void f() {
s.inner = u.inner;
s.inner[1] = u.inner[2];
assign_and_preserve_padding_s(u.inner);
uint tint_symbol_1[1] = uint[1](1u);
assign_and_preserve_padding_1_s_X(tint_symbol_1, u.inner[2]);
s.inner[1][0] = u.inner[0][1].zxy;
s.inner[1][0].x = u.inner[0][1].x;
}

View File

@@ -14,9 +14,21 @@ struct tint_array {
T elements[N];
};
void assign_and_preserve_padding_1(device float3x3* const dest, float3x3 value) {
(*(dest))[0u] = value[0u];
(*(dest))[1u] = value[1u];
(*(dest))[2u] = value[2u];
}
void assign_and_preserve_padding(device tint_array<float3x3, 4>* const dest, tint_array<float3x3, 4> value) {
for(uint i = 0u; (i < 4u); i = (i + 1u)) {
assign_and_preserve_padding_1(&((*(dest))[i]), value[i]);
}
}
kernel void f(device tint_array<float3x3, 4>* tint_symbol [[buffer(1)]], const constant tint_array<float3x3, 4>* tint_symbol_1 [[buffer(0)]]) {
*(tint_symbol) = *(tint_symbol_1);
(*(tint_symbol))[1] = (*(tint_symbol_1))[2];
assign_and_preserve_padding(tint_symbol, *(tint_symbol_1));
assign_and_preserve_padding_1(&((*(tint_symbol))[1]), (*(tint_symbol_1))[2]);
(*(tint_symbol))[1][0] = float3((*(tint_symbol_1))[0][1]).zxy;
(*(tint_symbol))[1][0][0] = (*(tint_symbol_1))[0][1][0];
return;

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 42
; Bound: 87
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -11,6 +11,13 @@
OpMemberName %u_block 0 "inner"
OpName %u "u"
OpName %s "s"
OpName %assign_and_preserve_padding_1_s_X "assign_and_preserve_padding_1_s_X"
OpName %dest "dest"
OpName %value "value"
OpName %assign_and_preserve_padding_s "assign_and_preserve_padding_s"
OpName %value_0 "value"
OpName %i "i"
OpName %var_for_index "var_for_index"
OpName %f "f"
OpDecorate %u_block Block
OpMemberDecorate %u_block 0 Offset 0
@@ -22,6 +29,7 @@
OpDecorate %u Binding 0
OpDecorate %s DescriptorSet 0
OpDecorate %s Binding 1
OpDecorate %_arr_uint_uint_1 ArrayStride 4
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%mat3v3float = OpTypeMatrix %v3float 3
@@ -34,38 +42,99 @@
%_ptr_StorageBuffer_u_block = OpTypePointer StorageBuffer %u_block
%s = OpVariable %_ptr_StorageBuffer_u_block StorageBuffer
%void = OpTypeVoid
%12 = OpTypeFunction %void
%uint_1 = OpConstant %uint 1
%_arr_uint_uint_1 = OpTypeArray %uint %uint_1
%12 = OpTypeFunction %void %_arr_uint_uint_1 %mat3v3float
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer__arr_mat3v3float_uint_4 = OpTypePointer StorageBuffer %_arr_mat3v3float_uint_4
%_ptr_Uniform__arr_mat3v3float_uint_4 = OpTypePointer Uniform %_arr_mat3v3float_uint_4
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%_ptr_StorageBuffer_mat3v3float = OpTypePointer StorageBuffer %mat3v3float
%int_2 = OpConstant %int 2
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
%30 = OpConstantNull %int
%22 = OpConstantNull %int
%_ptr_StorageBuffer_v3float = OpTypePointer StorageBuffer %v3float
%26 = OpConstantNull %uint
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%uint_2 = OpConstant %uint 2
%37 = OpTypeFunction %void %_arr_mat3v3float_uint_4
%_ptr_Function_uint = OpTypePointer Function %uint
%bool = OpTypeBool
%_ptr_Function__arr_mat3v3float_uint_4 = OpTypePointer Function %_arr_mat3v3float_uint_4
%55 = OpConstantNull %_arr_mat3v3float_uint_4
%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
%65 = OpTypeFunction %void
%_ptr_Uniform__arr_mat3v3float_uint_4 = OpTypePointer Uniform %_arr_mat3v3float_uint_4
%73 = OpConstantComposite %_arr_uint_uint_1 %uint_1
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
%_ptr_Uniform_v3float = OpTypePointer Uniform %v3float
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%_ptr_Uniform_float = OpTypePointer Uniform %float
%f = OpFunction %void None %12
%15 = OpLabel
%18 = OpAccessChain %_ptr_StorageBuffer__arr_mat3v3float_uint_4 %s %uint_0
%20 = OpAccessChain %_ptr_Uniform__arr_mat3v3float_uint_4 %u %uint_0
%21 = OpLoad %_arr_mat3v3float_uint_4 %20
OpStore %18 %21
%25 = OpAccessChain %_ptr_StorageBuffer_mat3v3float %s %uint_0 %int_1
%28 = OpAccessChain %_ptr_Uniform_mat3v3float %u %uint_0 %int_2
%29 = OpLoad %mat3v3float %28
OpStore %25 %29
%32 = OpAccessChain %_ptr_StorageBuffer_v3float %s %uint_0 %int_1 %30
%34 = OpAccessChain %_ptr_Uniform_v3float %u %uint_0 %30 %int_1
%35 = OpLoad %v3float %34
%36 = OpVectorShuffle %v3float %35 %35 2 0 1
OpStore %32 %36
%38 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %int_1 %30 %uint_0
%40 = OpAccessChain %_ptr_Uniform_float %u %uint_0 %30 %int_1 %uint_0
%41 = OpLoad %float %40
OpStore %38 %41
%assign_and_preserve_padding_1_s_X = OpFunction %void None %12
%dest = OpFunctionParameter %_arr_uint_uint_1
%value = OpFunctionParameter %mat3v3float
%19 = OpLabel
%23 = OpCompositeExtract %uint %dest 0
%25 = OpAccessChain %_ptr_StorageBuffer_v3float %s %uint_0 %23 %22
%27 = OpCompositeExtract %v3float %value 0
OpStore %25 %27
%28 = OpCompositeExtract %uint %dest 0
%30 = OpAccessChain %_ptr_StorageBuffer_v3float %s %uint_0 %28 %int_1
%31 = OpCompositeExtract %v3float %value 1
OpStore %30 %31
%32 = OpCompositeExtract %uint %dest 0
%34 = OpAccessChain %_ptr_StorageBuffer_v3float %s %uint_0 %32 %int_2
%36 = OpCompositeExtract %v3float %value 2
OpStore %34 %36
OpReturn
OpFunctionEnd
%assign_and_preserve_padding_s = OpFunction %void None %37
%value_0 = OpFunctionParameter %_arr_mat3v3float_uint_4
%40 = OpLabel
%i = OpVariable %_ptr_Function_uint Function %26
%var_for_index = OpVariable %_ptr_Function__arr_mat3v3float_uint_4 Function %55
OpStore %i %26
OpBranch %43
%43 = OpLabel
OpLoopMerge %44 %45 None
OpBranch %46
%46 = OpLabel
%48 = OpLoad %uint %i
%49 = OpULessThan %bool %48 %uint_4
%47 = OpLogicalNot %bool %49
OpSelectionMerge %51 None
OpBranchConditional %47 %52 %51
%52 = OpLabel
OpBranch %44
%51 = OpLabel
OpStore %var_for_index %value_0
%57 = OpLoad %uint %i
%58 = OpCompositeConstruct %_arr_uint_uint_1 %57
%59 = OpLoad %uint %i
%61 = OpAccessChain %_ptr_Function_mat3v3float %var_for_index %59
%62 = OpLoad %mat3v3float %61
%56 = OpFunctionCall %void %assign_and_preserve_padding_1_s_X %58 %62
OpBranch %45
%45 = OpLabel
%63 = OpLoad %uint %i
%64 = OpIAdd %uint %63 %uint_1
OpStore %i %64
OpBranch %43
%44 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %65
%67 = OpLabel
%70 = OpAccessChain %_ptr_Uniform__arr_mat3v3float_uint_4 %u %uint_0
%71 = OpLoad %_arr_mat3v3float_uint_4 %70
%68 = OpFunctionCall %void %assign_and_preserve_padding_s %71
%75 = OpAccessChain %_ptr_Uniform_mat3v3float %u %uint_0 %int_2
%76 = OpLoad %mat3v3float %75
%72 = OpFunctionCall %void %assign_and_preserve_padding_1_s_X %73 %76
%77 = OpAccessChain %_ptr_StorageBuffer_v3float %s %uint_0 %int_1 %22
%79 = OpAccessChain %_ptr_Uniform_v3float %u %uint_0 %22 %int_1
%80 = OpLoad %v3float %79
%81 = OpVectorShuffle %v3float %80 %80 2 0 1
OpStore %77 %81
%83 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %int_1 %22 %uint_0
%85 = OpAccessChain %_ptr_Uniform_float %u %uint_0 %22 %int_1 %uint_0
%86 = OpLoad %float %85
OpStore %83 %86
OpReturn
OpFunctionEnd