File: fix_func_call_arguments_test.cpp

package info (click to toggle)
spirv-tools 2025.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,588 kB
  • sloc: cpp: 470,407; javascript: 5,893; python: 3,326; ansic: 488; sh: 450; ruby: 88; makefile: 18; lisp: 9
file content (151 lines) | stat: -rw-r--r-- 5,154 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) 2022 Advanced Micro Devices, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"

namespace spvtools {
namespace opt {
namespace {

using FixFuncCallArgumentsTest = PassTest<::testing::Test>;
TEST_F(FixFuncCallArgumentsTest, Simple) {
  const std::string text = R"(
;
; CHECK: [[v0:%\w+]] = OpVariable %_ptr_Function_float Function
; CHECK: [[v1:%\w+]] = OpVariable %_ptr_Function_float Function
; CHECK: [[v2:%\w+]] = OpVariable %_ptr_Function_T Function
; CHECK: [[ac0:%\w+]] = OpAccessChain %_ptr_Function_float %t %int_0
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform_float %r1 %int_0 %uint_0
; CHECK: [[ld0:%\w+]] = OpLoad %float [[ac0]]
; CHECK:                OpStore [[v1]] [[ld0]]
; CHECK: [[ld1:%\w+]] = OpLoad %float [[ac1]]
; CHECK:                OpStore [[v0]] [[ld1]]
; CHECK: [[func:%\w+]] = OpFunctionCall %void %fn [[v1]] [[v0]]
; CHECK: [[ld2:%\w+]] = OpLoad %float [[v0]]
; CHECK: OpStore [[ac1]] [[ld2]]
; CHECK: [[ld3:%\w+]] = OpLoad %float [[v1]]
; CHECK: OpStore [[ac0]] [[ld3]]
;
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
OpSource HLSL 630
OpName %type_RWStructuredBuffer_float "type.RWStructuredBuffer.float"
OpName %r1 "r1"
OpName %type_ACSBuffer_counter "type.ACSBuffer.counter"
OpMemberName %type_ACSBuffer_counter 0 "counter"
OpName %counter_var_r1 "counter.var.r1"
OpName %main "main"
OpName %bb_entry "bb.entry"
OpName %T "T"
OpMemberName %T 0 "t0"
OpName %t "t"
OpName %fn "fn"
OpName %p0 "p0"
OpName %p2 "p2"
OpName %bb_entry_0 "bb.entry"
OpDecorate %main LinkageAttributes "main" Export
OpDecorate %r1 DescriptorSet 0
OpDecorate %r1 Binding 0
OpDecorate %counter_var_r1 DescriptorSet 0
OpDecorate %counter_var_r1 Binding 1
OpDecorate %_runtimearr_float ArrayStride 4
OpMemberDecorate %type_RWStructuredBuffer_float 0 Offset 0
OpDecorate %type_RWStructuredBuffer_float BufferBlock
OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0
OpDecorate %type_ACSBuffer_counter BufferBlock
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%int_1 = OpConstant %int 1
%float = OpTypeFloat 32
%_runtimearr_float = OpTypeRuntimeArray %float
%type_RWStructuredBuffer_float = OpTypeStruct %_runtimearr_float
%_ptr_Uniform_type_RWStructuredBuffer_float = OpTypePointer Uniform %type_RWStructuredBuffer_float
%type_ACSBuffer_counter = OpTypeStruct %int
%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter
%15 = OpTypeFunction %int
%T = OpTypeStruct %float
%_ptr_Function_T = OpTypePointer Function %T
%_ptr_Function_float = OpTypePointer Function %float
%_ptr_Uniform_float = OpTypePointer Uniform %float
%void = OpTypeVoid
%27 = OpTypeFunction %void %_ptr_Function_float %_ptr_Function_float
%r1 = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_float Uniform
%counter_var_r1 = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform
%main = OpFunction %int None %15
%bb_entry = OpLabel
%t = OpVariable %_ptr_Function_T Function
%21 = OpAccessChain %_ptr_Function_float %t %int_0
%23 = OpAccessChain %_ptr_Uniform_float %r1 %int_0 %uint_0
%25 = OpFunctionCall %void %fn %21 %23
OpReturnValue %int_1
OpFunctionEnd
%fn = OpFunction %void DontInline %27
%p0 = OpFunctionParameter %_ptr_Function_float
%p2 = OpFunctionParameter %_ptr_Function_float
%bb_entry_0 = OpLabel
OpReturn
OpFunctionEnd
)";

  SinglePassRunAndMatch<FixFuncCallArgumentsPass>(text, true);
}

TEST_F(FixFuncCallArgumentsTest, NotAccessChainInput) {
  const std::string text = R"(
;
; CHECK: [[o:%\w+]] = OpCopyObject %_ptr_Function_float %t
; CHECK: [[func:%\w+]] = OpFunctionCall %void %fn [[o]]
;
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
OpSource HLSL 630
OpName %main "main"
OpName %bb_entry "bb.entry"
OpName %t "t"
OpName %fn "fn"
OpName %p0 "p0"
OpName %bb_entry_0 "bb.entry"
OpDecorate %main LinkageAttributes "main" Export
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%4 = OpTypeFunction %int
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%void = OpTypeVoid
%12 = OpTypeFunction %void %_ptr_Function_float
%main = OpFunction %int None %4
%bb_entry = OpLabel
%t = OpVariable %_ptr_Function_float Function
%t1 = OpCopyObject %_ptr_Function_float %t
%10 = OpFunctionCall %void %fn %t1
OpReturnValue %int_1
OpFunctionEnd
%fn = OpFunction %void DontInline %12
%p0 = OpFunctionParameter %_ptr_Function_float
%bb_entry_0 = OpLabel
OpReturn
OpFunctionEnd
)";

  SinglePassRunAndMatch<FixFuncCallArgumentsPass>(text, false);
}

}  // namespace
}  // namespace opt
}  // namespace spvtools