tint: Add RemovePhonies transform to spir-v backend

This will be needed by an upcoming CL that fixes call statements to
builtins that return a constant value. Without this transform, the
constant value reaches the backend, where we don't currently deal with
abstract numbers. Note that the other backends (HLSL, MSL, GLSL) already
use this transform.

Bug: chromium:1350147
Change-Id: Icc1f1416a07db228f8e3f39851a9ac079c48319f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98740
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2022-08-10 19:32:23 +00:00 committed by Dawn LUCI CQ
parent b91d7e1b31
commit 90d5eb6128
7 changed files with 22 additions and 34 deletions

View File

@ -26,6 +26,7 @@
#include "src/tint/transform/for_loop_to_loop.h"
#include "src/tint/transform/manager.h"
#include "src/tint/transform/promote_side_effects_to_decl.h"
#include "src/tint/transform/remove_phonies.h"
#include "src/tint/transform/remove_unreachable_statements.h"
#include "src/tint/transform/simplify_pointers.h"
#include "src/tint/transform/unshadow.h"
@ -75,6 +76,7 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
manager.Add<transform::PromoteSideEffectsToDecl>();
manager.Add<transform::UnwindDiscardFunctions>();
manager.Add<transform::SimplifyPointers>(); // Required for arrayLength()
manager.Add<transform::RemovePhonies>();
manager.Add<transform::VectorizeScalarMatrixConstructors>();
manager.Add<transform::ForLoopToLoop>(); // Must come after
manager.Add<transform::WhileToLoop>(); // ZeroInitWorkgroupMemory

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 108
; Bound: 107
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -129,7 +129,7 @@
%92 = OpConstantNull %float
%93 = OpConstantComposite %v4float %float_1 %92 %92 %float_1
%void = OpTypeVoid
%96 = OpTypeFunction %void
%95 = OpTypeFunction %void
%getColor = OpFunction %v4float None %30
%fragment = OpFunctionParameter %FragmentInput
%34 = OpLabel
@ -196,19 +196,19 @@
%output = OpVariable %_ptr_Function_FragmentOutput Function %89
%91 = OpAccessChain %_ptr_Function_v4float %output %uint_0
OpStore %91 %93
%95 = OpLoad %FragmentOutput %output
OpReturnValue %95
%94 = OpLoad %FragmentOutput %output
OpReturnValue %94
OpFunctionEnd
%main = OpFunction %void None %96
%99 = OpLabel
%101 = OpLoad %v4float %position_1
%102 = OpLoad %v4float %view_position_1
%103 = OpLoad %v4float %normal_1
%104 = OpLoad %v2float %uv_1
%105 = OpLoad %v4float %color_1
%106 = OpCompositeConstruct %FragmentInput %101 %102 %103 %104 %105
%100 = OpFunctionCall %FragmentOutput %main_inner %106
%107 = OpCompositeExtract %v4float %100 0
OpStore %color_2 %107
%main = OpFunction %void None %95
%98 = OpLabel
%100 = OpLoad %v4float %position_1
%101 = OpLoad %v4float %view_position_1
%102 = OpLoad %v4float %normal_1
%103 = OpLoad %v2float %uv_1
%104 = OpLoad %v4float %color_1
%105 = OpCompositeConstruct %FragmentInput %100 %101 %102 %103 %104
%99 = OpFunctionCall %FragmentOutput %main_inner %105
%106 = OpCompositeExtract %v4float %99 0
OpStore %color_2 %106
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 11
; Bound: 10
; 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: 10
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -23,11 +23,7 @@
%s = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer__runtimearr_int = OpTypePointer StorageBuffer %_runtimearr_int
%main = OpFunction %void None %6
%9 = OpLabel
%14 = OpAccessChain %_ptr_StorageBuffer__runtimearr_int %s %uint_0
OpReturn
OpFunctionEnd

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
@ -42,7 +42,5 @@
%18 = OpFunctionCall %int %f %int_4 %int_5 %int_6
%22 = OpFunctionCall %int %f %int_8 %int_9 %int_10
%26 = OpFunctionCall %int %f %int_7 %22 %int_11
%29 = OpIMul %int %18 %26
%30 = OpIAdd %int %14 %29
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 13
; Bound: 9
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -21,11 +21,7 @@
%s = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%5 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%main = OpFunction %void None %5
%8 = OpLabel
%12 = OpAccessChain %_ptr_StorageBuffer_int %s %uint_0
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 13
; Bound: 9
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@ -22,11 +22,7 @@
%u = OpVariable %_ptr_Uniform_S Uniform
%void = OpTypeVoid
%5 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_int = OpTypePointer Uniform %int
%main = OpFunction %void None %5
%8 = OpLabel
%12 = OpAccessChain %_ptr_Uniform_int %u %uint_0
OpReturn
OpFunctionEnd