transform/spirv: Use InlinePointerLets & Simplify

arrayLength() will take a pointer to a storage buffer array.
This pointer may pass through function scoped let statements.
To make this intrinsic easier to generate, inline the pointer lets and
remove chains of &*&*.

Bug: tint:806
Change-Id: Ib2c79a9c38cba7391cbb4313986af9a72b0f0435
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54060
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2021-06-10 17:34:44 +00:00 committed by Tint LUCI CQ
parent 3e59eb0e5c
commit 0aa7edbbd5
15 changed files with 2392 additions and 1903 deletions

View File

@ -27,7 +27,9 @@
#include "src/sem/struct.h"
#include "src/sem/variable.h"
#include "src/transform/external_texture_transform.h"
#include "src/transform/inline_pointer_lets.h"
#include "src/transform/manager.h"
#include "src/transform/simplify.h"
#include "src/transform/var_for_dynamic_index.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::Spirv::Config);
@ -40,6 +42,8 @@ Spirv::~Spirv() = default;
Output Spirv::Run(const Program* in, const DataMap& data) {
Manager manager;
manager.Add<InlinePointerLets>(); // Required for arrayLength()
manager.Add<Simplify>(); // Required for arrayLength()
manager.Add<ExternalTextureTransform>();
manager.Add<VarForDynamicIndex>();
auto transformedInput = manager.Run(in, data);

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 36
; Bound: 30
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -44,14 +44,14 @@
%dst = OpVariable %_ptr_Function__arr_int_uint_4 Function %11
%dst_struct = OpVariable %_ptr_Function_S Function %17
%dst_array = OpVariable %_ptr_Function__arr__arr_int_uint_4_uint_2 Function %22
%24 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_struct %uint_0
OpStore %24 %11
%26 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_array %int_1
OpStore %26 %11
OpStore %dst %11
%27 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_struct %uint_0
OpStore %27 %11
%29 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_array %int_1
%29 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_array %int_0
OpStore %29 %11
OpStore %dst %11
%32 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_struct %uint_0
OpStore %32 %11
%35 = OpAccessChain %_ptr_Function__arr_int_uint_4 %dst_array %int_0
OpStore %35 %11
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 44
; Bound: 42
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -32,8 +32,8 @@
%14 = OpConstantNull %uint
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%bool = OpTypeBool
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_1 = OpConstant %uint 1
%main = OpFunction %void None %7
%10 = OpLabel
%i = OpVariable %_ptr_Function_uint Function %14
@ -52,25 +52,27 @@
%26 = OpLabel
OpBranch %16
%25 = OpLabel
%29 = OpLoad %uint %i
%30 = OpAccessChain %_ptr_StorageBuffer_uint %b %uint_1 %29
%31 = OpLoad %uint %i
%33 = OpUMod %uint %31 %uint_2
%34 = OpIEqual %bool %33 %uint_0
OpSelectionMerge %35 None
OpBranchConditional %34 %36 %35
%36 = OpLabel
%27 = OpLoad %uint %i
%28 = OpLoad %uint %i
%30 = OpUMod %uint %28 %uint_2
%31 = OpIEqual %bool %30 %uint_0
OpSelectionMerge %32 None
OpBranchConditional %31 %33 %32
%33 = OpLabel
OpBranch %17
%35 = OpLabel
OpStore %30 %uint_0
%32 = OpLabel
%35 = OpAccessChain %_ptr_StorageBuffer_uint %b %uint_1 %27
OpStore %35 %uint_0
OpBranch %17
%17 = OpLabel
%40 = OpLoad %uint %30
%41 = OpIMul %uint %40 %uint_2
OpStore %30 %41
%42 = OpLoad %uint %i
%43 = OpIAdd %uint %42 %uint_1
OpStore %i %43
%36 = OpAccessChain %_ptr_StorageBuffer_uint %b %uint_1 %27
%37 = OpAccessChain %_ptr_StorageBuffer_uint %b %uint_1 %27
%38 = OpLoad %uint %37
%39 = OpIMul %uint %38 %uint_2
OpStore %36 %39
%40 = OpLoad %uint %i
%41 = OpIAdd %uint %40 %uint_1
OpStore %i %41
OpBranch %15
%16 = OpLabel
OpReturn

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 16
; Bound: 14
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -27,7 +27,7 @@
%int_12 = OpConstant %int 12
%main = OpFunction %void None %5
%8 = OpLabel
%13 = OpAccessChain %_ptr_StorageBuffer_int %buf %uint_0
OpStore %13 %int_12
%12 = OpAccessChain %_ptr_StorageBuffer_int %buf %uint_0
OpStore %12 %int_12
OpReturn
OpFunctionEnd

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 31
; Bound: 29
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -32,12 +32,12 @@
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%_ptr_Function_v3float = OpTypePointer Function %v3float
%30 = OpConstantComposite %v3float %float_5 %float_5 %float_5
%28 = OpConstantComposite %v3float %float_5 %float_5 %float_5
%main = OpFunction %void None %1
%4 = OpLabel
%m = OpVariable %_ptr_Function_mat3v3float Function %23
OpStore %m %20
%28 = OpAccessChain %_ptr_Function_v3float %m %int_1
OpStore %28 %30
%27 = OpAccessChain %_ptr_Function_v3float %m %int_1
OpStore %27 %28
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 21
; Bound: 19
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -27,7 +27,7 @@
%4 = OpLabel
%v = OpVariable %_ptr_Function_v3float Function %13
OpStore %v %10
%18 = OpAccessChain %_ptr_Function_float %v %uint_1
OpStore %18 %float_5
%17 = OpAccessChain %_ptr_Function_float %v %uint_1
OpStore %17 %float_5
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 10
; Bound: 9
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 15
; Bound: 13
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -20,7 +20,7 @@
%4 = OpLabel
%i = OpVariable %_ptr_Function_int Function %9
OpStore %i %int_123
%12 = OpLoad %int %i
%14 = OpIAdd %int %12 %int_1
%10 = OpLoad %int %i
%12 = OpIAdd %int %10 %int_1
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 14
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -18,7 +18,7 @@
%int_1 = OpConstant %int 1
%main = OpFunction %void None %5
%8 = OpLabel
%11 = OpLoad %int %i
%13 = OpIAdd %int %11 %int_1
%9 = OpLoad %int %i
%11 = OpIAdd %int %9 %int_1
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Bound: 16
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -27,8 +27,8 @@
%int_1 = OpConstant %int 1
%main = OpFunction %void None %5
%8 = OpLabel
%13 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0
%15 = OpLoad %int %13
%17 = OpIAdd %int %15 %int_1
%12 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0
%13 = OpLoad %int %12
%15 = OpIAdd %int %13 %int_1
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Bound: 16
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -28,8 +28,8 @@
%int_1 = OpConstant %int 1
%main = OpFunction %void None %5
%8 = OpLabel
%13 = OpAccessChain %_ptr_Uniform_int %v %uint_0
%15 = OpLoad %int %13
%17 = OpIAdd %int %15 %int_1
%12 = OpAccessChain %_ptr_Uniform_int %v %uint_0
%13 = OpLoad %int %12
%15 = OpIAdd %int %13 %int_1
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 14
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -19,7 +19,7 @@
%main = OpFunction %void None %4
%7 = OpLabel
OpStore %i %int_123
%11 = OpLoad %int %i
%13 = OpIAdd %int %11 %int_1
%9 = OpLoad %int %i
%11 = OpIAdd %int %9 %int_1
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Bound: 15
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -23,8 +23,8 @@
%i = OpVariable %_ptr_Function_int Function %9
OpStore %i %int_123
OpStore %i %int_123
%15 = OpIAdd %int %int_100 %int_20
%17 = OpIAdd %int %15 %int_3
OpStore %i %17
%12 = OpIAdd %int %int_100 %int_20
%14 = OpIAdd %int %12 %int_3
OpStore %i %14
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 52
; Bound: 49
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450