| 1 |
// Copyright (c) 2019 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#include <string> |
| 16 |
|
| 17 |
#include "gmock/gmock.h" |
| 18 |
#include "test/opt/assembly_builder.h" |
| 19 |
#include "test/opt/pass_fixture.h" |
| 20 |
#include "test/opt/pass_utils.h" |
| 21 |
|
| 22 |
namespace spvtools { |
| 23 |
namespace opt { |
| 24 |
namespace { |
| 25 |
|
| 26 |
using FixStorageClassTest = PassTest<::testing::Test>; |
| 27 |
|
| 28 |
TEST_F(FixStorageClassTest, FixAccessChain) { |
| 29 |
const std::string text = R"( |
| 30 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 31 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 32 |
OpCapability Shader |
| 33 |
OpMemoryModel Logical GLSL450 |
| 34 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 35 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 36 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 37 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 38 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 39 |
OpDecorate %8 DescriptorSet 0 |
| 40 |
OpDecorate %8 Binding 0 |
| 41 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 42 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 43 |
OpDecorate %_struct_7 BufferBlock |
| 44 |
%int = OpTypeInt 32 1 |
| 45 |
%int_0 = OpConstant %int 0 |
| 46 |
%float = OpTypeFloat 32 |
| 47 |
%float_2 = OpConstant %float 2 |
| 48 |
%uint = OpTypeInt 32 0 |
| 49 |
%uint_10 = OpConstant %uint 10 |
| 50 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 51 |
%ptr = OpTypePointer Function %_arr_float_uint_10 |
| 52 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 53 |
%_struct_5 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 54 |
%_ptr_Workgroup__struct_5 = OpTypePointer Workgroup %_struct_5 |
| 55 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 56 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 57 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 58 |
%v3uint = OpTypeVector %uint 3 |
| 59 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 60 |
%void = OpTypeVoid |
| 61 |
%30 = OpTypeFunction %void |
| 62 |
%_ptr_Function_float = OpTypePointer Function %float |
| 63 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 64 |
%6 = OpVariable %_ptr_Workgroup__struct_5 Workgroup |
| 65 |
%8 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 66 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 67 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 68 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 69 |
%1 = OpFunction %void None %30 |
| 70 |
%38 = OpLabel |
| 71 |
%44 = OpLoad %v3uint %gl_LocalInvocationID |
| 72 |
%50 = OpAccessChain %_ptr_Function_float %6 %int_0 %int_0 %int_0 |
| 73 |
%51 = OpLoad %float %50 |
| 74 |
%52 = OpFMul %float %float_2 %51 |
| 75 |
OpStore %50 %52 |
| 76 |
%55 = OpLoad %float %50 |
| 77 |
%59 = OpCompositeExtract %uint %44 0 |
| 78 |
%60 = OpAccessChain %_ptr_Uniform_float %8 %int_0 %59 |
| 79 |
OpStore %60 %55 |
| 80 |
OpReturn |
| 81 |
OpFunctionEnd |
| 82 |
)"; |
| 83 |
|
| 84 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 85 |
} |
| 86 |
|
| 87 |
TEST_F(FixStorageClassTest, FixLinkedAccessChain) { |
| 88 |
const std::string text = R"( |
| 89 |
; CHECK: OpAccessChain %_ptr_Workgroup__arr_float_uint_10 |
| 90 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 91 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 92 |
OpCapability Shader |
| 93 |
OpMemoryModel Logical GLSL450 |
| 94 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 95 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 96 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 97 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 98 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 99 |
OpDecorate %5 DescriptorSet 0 |
| 100 |
OpDecorate %5 Binding 0 |
| 101 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 102 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 103 |
OpDecorate %_struct_7 BufferBlock |
| 104 |
%int = OpTypeInt 32 1 |
| 105 |
%int_0 = OpConstant %int 0 |
| 106 |
%float = OpTypeFloat 32 |
| 107 |
%float_2 = OpConstant %float 2 |
| 108 |
%uint = OpTypeInt 32 0 |
| 109 |
%uint_10 = OpConstant %uint 10 |
| 110 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 111 |
%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 |
| 112 |
%_ptr = OpTypePointer Function %_arr_float_uint_10 |
| 113 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 114 |
%_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 115 |
%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 |
| 116 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 117 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 118 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 119 |
%v3uint = OpTypeVector %uint 3 |
| 120 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 121 |
%void = OpTypeVoid |
| 122 |
%23 = OpTypeFunction %void |
| 123 |
%_ptr_Function_float = OpTypePointer Function %float |
| 124 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 125 |
%27 = OpVariable %_ptr_Workgroup__struct_17 Workgroup |
| 126 |
%5 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 127 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 128 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 129 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 130 |
%1 = OpFunction %void None %23 |
| 131 |
%28 = OpLabel |
| 132 |
%29 = OpLoad %v3uint %gl_LocalInvocationID |
| 133 |
%30 = OpAccessChain %_ptr_Function__arr_float_uint_10 %27 %int_0 %int_0 |
| 134 |
%31 = OpAccessChain %_ptr_Function_float %30 %int_0 |
| 135 |
%32 = OpLoad %float %31 |
| 136 |
%33 = OpFMul %float %float_2 %32 |
| 137 |
OpStore %31 %33 |
| 138 |
%34 = OpLoad %float %31 |
| 139 |
%35 = OpCompositeExtract %uint %29 0 |
| 140 |
%36 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %35 |
| 141 |
OpStore %36 %34 |
| 142 |
OpReturn |
| 143 |
OpFunctionEnd |
| 144 |
)"; |
| 145 |
|
| 146 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 147 |
} |
| 148 |
|
| 149 |
TEST_F(FixStorageClassTest, FixCopyObject) { |
| 150 |
const std::string text = R"( |
| 151 |
; CHECK: OpCopyObject %_ptr_Workgroup__struct_17 |
| 152 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 153 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 154 |
OpCapability Shader |
| 155 |
OpMemoryModel Logical GLSL450 |
| 156 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 157 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 158 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 159 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 160 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 161 |
OpDecorate %8 DescriptorSet 0 |
| 162 |
OpDecorate %8 Binding 0 |
| 163 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 164 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 165 |
OpDecorate %_struct_7 BufferBlock |
| 166 |
%int = OpTypeInt 32 1 |
| 167 |
%int_0 = OpConstant %int 0 |
| 168 |
%float = OpTypeFloat 32 |
| 169 |
%float_2 = OpConstant %float 2 |
| 170 |
%uint = OpTypeInt 32 0 |
| 171 |
%uint_10 = OpConstant %uint 10 |
| 172 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 173 |
%ptr = OpTypePointer Function %_arr_float_uint_10 |
| 174 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 175 |
%_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 176 |
%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 |
| 177 |
%_ptr_Function__struct_17 = OpTypePointer Function %_struct_17 |
| 178 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 179 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 180 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 181 |
%v3uint = OpTypeVector %uint 3 |
| 182 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 183 |
%void = OpTypeVoid |
| 184 |
%30 = OpTypeFunction %void |
| 185 |
%_ptr_Function_float = OpTypePointer Function %float |
| 186 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 187 |
%6 = OpVariable %_ptr_Workgroup__struct_17 Workgroup |
| 188 |
%8 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 189 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 190 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 191 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 192 |
%1 = OpFunction %void None %30 |
| 193 |
%38 = OpLabel |
| 194 |
%44 = OpLoad %v3uint %gl_LocalInvocationID |
| 195 |
%cp = OpCopyObject %_ptr_Function__struct_17 %6 |
| 196 |
%50 = OpAccessChain %_ptr_Function_float %cp %int_0 %int_0 %int_0 |
| 197 |
%51 = OpLoad %float %50 |
| 198 |
%52 = OpFMul %float %float_2 %51 |
| 199 |
OpStore %50 %52 |
| 200 |
%55 = OpLoad %float %50 |
| 201 |
%59 = OpCompositeExtract %uint %44 0 |
| 202 |
%60 = OpAccessChain %_ptr_Uniform_float %8 %int_0 %59 |
| 203 |
OpStore %60 %55 |
| 204 |
OpReturn |
| 205 |
OpFunctionEnd |
| 206 |
)"; |
| 207 |
|
| 208 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 209 |
} |
| 210 |
|
| 211 |
TEST_F(FixStorageClassTest, FixPhiInSelMerge) { |
| 212 |
const std::string text = R"( |
| 213 |
; CHECK: OpPhi %_ptr_Workgroup__struct_19 |
| 214 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 215 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 216 |
OpCapability Shader |
| 217 |
OpMemoryModel Logical GLSL450 |
| 218 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 219 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 220 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 221 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 222 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 223 |
OpDecorate %5 DescriptorSet 0 |
| 224 |
OpDecorate %5 Binding 0 |
| 225 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 226 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 227 |
OpDecorate %_struct_7 BufferBlock |
| 228 |
%bool = OpTypeBool |
| 229 |
%true = OpConstantTrue %bool |
| 230 |
%int = OpTypeInt 32 1 |
| 231 |
%int_0 = OpConstant %int 0 |
| 232 |
%float = OpTypeFloat 32 |
| 233 |
%float_2 = OpConstant %float 2 |
| 234 |
%uint = OpTypeInt 32 0 |
| 235 |
%uint_10 = OpConstant %uint 10 |
| 236 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 237 |
%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 |
| 238 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 239 |
%_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 240 |
%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 |
| 241 |
%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 |
| 242 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 243 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 244 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 245 |
%v3uint = OpTypeVector %uint 3 |
| 246 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 247 |
%void = OpTypeVoid |
| 248 |
%25 = OpTypeFunction %void |
| 249 |
%_ptr_Function_float = OpTypePointer Function %float |
| 250 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 251 |
%28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 252 |
%29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 253 |
%5 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 254 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 255 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 256 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 257 |
%1 = OpFunction %void None %25 |
| 258 |
%30 = OpLabel |
| 259 |
OpSelectionMerge %31 None |
| 260 |
OpBranchConditional %true %32 %31 |
| 261 |
%32 = OpLabel |
| 262 |
OpBranch %31 |
| 263 |
%31 = OpLabel |
| 264 |
%33 = OpPhi %_ptr_Function__struct_19 %28 %30 %29 %32 |
| 265 |
%34 = OpLoad %v3uint %gl_LocalInvocationID |
| 266 |
%35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 |
| 267 |
%36 = OpLoad %float %35 |
| 268 |
%37 = OpFMul %float %float_2 %36 |
| 269 |
OpStore %35 %37 |
| 270 |
%38 = OpLoad %float %35 |
| 271 |
%39 = OpCompositeExtract %uint %34 0 |
| 272 |
%40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 |
| 273 |
OpStore %40 %38 |
| 274 |
OpReturn |
| 275 |
OpFunctionEnd |
| 276 |
)"; |
| 277 |
|
| 278 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 279 |
} |
| 280 |
|
| 281 |
TEST_F(FixStorageClassTest, FixPhiInLoop) { |
| 282 |
const std::string text = R"( |
| 283 |
; CHECK: OpPhi %_ptr_Workgroup__struct_19 |
| 284 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 285 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 286 |
OpCapability Shader |
| 287 |
OpMemoryModel Logical GLSL450 |
| 288 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 289 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 290 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 291 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 292 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 293 |
OpDecorate %5 DescriptorSet 0 |
| 294 |
OpDecorate %5 Binding 0 |
| 295 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 296 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 297 |
OpDecorate %_struct_7 BufferBlock |
| 298 |
%bool = OpTypeBool |
| 299 |
%true = OpConstantTrue %bool |
| 300 |
%int = OpTypeInt 32 1 |
| 301 |
%int_0 = OpConstant %int 0 |
| 302 |
%float = OpTypeFloat 32 |
| 303 |
%float_2 = OpConstant %float 2 |
| 304 |
%uint = OpTypeInt 32 0 |
| 305 |
%uint_10 = OpConstant %uint 10 |
| 306 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 307 |
%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 |
| 308 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 309 |
%_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 310 |
%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 |
| 311 |
%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 |
| 312 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 313 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 314 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 315 |
%v3uint = OpTypeVector %uint 3 |
| 316 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 317 |
%void = OpTypeVoid |
| 318 |
%25 = OpTypeFunction %void |
| 319 |
%_ptr_Function_float = OpTypePointer Function %float |
| 320 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 321 |
%28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 322 |
%29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 323 |
%5 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 324 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 325 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 326 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 327 |
%1 = OpFunction %void None %25 |
| 328 |
%30 = OpLabel |
| 329 |
OpSelectionMerge %31 None |
| 330 |
OpBranchConditional %true %32 %31 |
| 331 |
%32 = OpLabel |
| 332 |
OpBranch %31 |
| 333 |
%31 = OpLabel |
| 334 |
%33 = OpPhi %_ptr_Function__struct_19 %28 %30 %29 %32 |
| 335 |
%34 = OpLoad %v3uint %gl_LocalInvocationID |
| 336 |
%35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 |
| 337 |
%36 = OpLoad %float %35 |
| 338 |
%37 = OpFMul %float %float_2 %36 |
| 339 |
OpStore %35 %37 |
| 340 |
%38 = OpLoad %float %35 |
| 341 |
%39 = OpCompositeExtract %uint %34 0 |
| 342 |
%40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 |
| 343 |
OpStore %40 %38 |
| 344 |
OpReturn |
| 345 |
OpFunctionEnd |
| 346 |
)"; |
| 347 |
|
| 348 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 349 |
} |
| 350 |
|
| 351 |
TEST_F(FixStorageClassTest, DontChangeFunctionCalls) { |
| 352 |
const std::string text = R"(OpCapability Shader |
| 353 |
OpMemoryModel Logical GLSL450 |
| 354 |
OpEntryPoint GLCompute %1 "testMain" |
| 355 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 356 |
OpDecorate %2 DescriptorSet 0 |
| 357 |
OpDecorate %2 Binding 0 |
| 358 |
%int = OpTypeInt 32 1 |
| 359 |
%_ptr_Function_int = OpTypePointer Function %int |
| 360 |
%_ptr_Workgroup_int = OpTypePointer Workgroup %int |
| 361 |
%_ptr_Uniform_int = OpTypePointer Uniform %int |
| 362 |
%void = OpTypeVoid |
| 363 |
%8 = OpTypeFunction %void |
| 364 |
%9 = OpTypeFunction %_ptr_Uniform_int %_ptr_Function_int |
| 365 |
%10 = OpVariable %_ptr_Workgroup_int Workgroup |
| 366 |
%2 = OpVariable %_ptr_Uniform_int Uniform |
| 367 |
%1 = OpFunction %void None %8 |
| 368 |
%11 = OpLabel |
| 369 |
%12 = OpFunctionCall %_ptr_Uniform_int %13 %10 |
| 370 |
OpReturn |
| 371 |
OpFunctionEnd |
| 372 |
%13 = OpFunction %_ptr_Uniform_int None %9 |
| 373 |
%14 = OpFunctionParameter %_ptr_Function_int |
| 374 |
%15 = OpLabel |
| 375 |
OpReturnValue %2 |
| 376 |
OpFunctionEnd |
| 377 |
)"; |
| 378 |
|
| 379 |
SinglePassRunAndCheck<FixStorageClass>(text, text, false, false); |
| 380 |
} |
| 381 |
|
| 382 |
TEST_F(FixStorageClassTest, FixSelect) { |
| 383 |
const std::string text = R"( |
| 384 |
; CHECK: OpSelect %_ptr_Workgroup__struct_19 |
| 385 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 386 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 387 |
OpCapability Shader |
| 388 |
OpMemoryModel Logical GLSL450 |
| 389 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 390 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 391 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 392 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 393 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 394 |
OpDecorate %5 DescriptorSet 0 |
| 395 |
OpDecorate %5 Binding 0 |
| 396 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 397 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 398 |
OpDecorate %_struct_7 BufferBlock |
| 399 |
%bool = OpTypeBool |
| 400 |
%true = OpConstantTrue %bool |
| 401 |
%int = OpTypeInt 32 1 |
| 402 |
%int_0 = OpConstant %int 0 |
| 403 |
%float = OpTypeFloat 32 |
| 404 |
%float_2 = OpConstant %float 2 |
| 405 |
%uint = OpTypeInt 32 0 |
| 406 |
%uint_10 = OpConstant %uint 10 |
| 407 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 408 |
%_ptr_Function__arr_float_uint_10 = OpTypePointer Function %_arr_float_uint_10 |
| 409 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 410 |
%_struct_19 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 411 |
%_ptr_Workgroup__struct_19 = OpTypePointer Workgroup %_struct_19 |
| 412 |
%_ptr_Function__struct_19 = OpTypePointer Function %_struct_19 |
| 413 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 414 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 415 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 416 |
%v3uint = OpTypeVector %uint 3 |
| 417 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 418 |
%void = OpTypeVoid |
| 419 |
%25 = OpTypeFunction %void |
| 420 |
%_ptr_Function_float = OpTypePointer Function %float |
| 421 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 422 |
%28 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 423 |
%29 = OpVariable %_ptr_Workgroup__struct_19 Workgroup |
| 424 |
%5 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 425 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 426 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 427 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 428 |
%1 = OpFunction %void None %25 |
| 429 |
%30 = OpLabel |
| 430 |
%33 = OpSelect %_ptr_Function__struct_19 %true %28 %29 |
| 431 |
%34 = OpLoad %v3uint %gl_LocalInvocationID |
| 432 |
%35 = OpAccessChain %_ptr_Function_float %33 %int_0 %int_0 %int_0 |
| 433 |
%36 = OpLoad %float %35 |
| 434 |
%37 = OpFMul %float %float_2 %36 |
| 435 |
OpStore %35 %37 |
| 436 |
%38 = OpLoad %float %35 |
| 437 |
%39 = OpCompositeExtract %uint %34 0 |
| 438 |
%40 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %39 |
| 439 |
OpStore %40 %38 |
| 440 |
OpReturn |
| 441 |
OpFunctionEnd |
| 442 |
)"; |
| 443 |
|
| 444 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 445 |
} |
| 446 |
|
| 447 |
TEST_F(FixStorageClassTest, BitCast) { |
| 448 |
const std::string text = R"(OpCapability VariablePointersStorageBuffer |
| 449 |
OpMemoryModel Logical GLSL450 |
| 450 |
OpEntryPoint GLCompute %1 "main" |
| 451 |
%void = OpTypeVoid |
| 452 |
%3 = OpTypeFunction %void |
| 453 |
%_ptr_Output_void = OpTypePointer Output %void |
| 454 |
%_ptr_Private__ptr_Output_void = OpTypePointer Private %_ptr_Output_void |
| 455 |
%6 = OpVariable %_ptr_Private__ptr_Output_void Private |
| 456 |
%1 = OpFunction %void Inline %3 |
| 457 |
%7 = OpLabel |
| 458 |
%8 = OpBitcast %_ptr_Output_void %6 |
| 459 |
OpReturn |
| 460 |
OpFunctionEnd |
| 461 |
)"; |
| 462 |
|
| 463 |
SinglePassRunAndCheck<FixStorageClass>(text, text, false); |
| 464 |
} |
| 465 |
|
| 466 |
TEST_F(FixStorageClassTest, FixLinkedAccessChain2) { |
| 467 |
// This case is similar to FixLinkedAccessChain. The difference is that the |
| 468 |
// first OpAccessChain instruction starts as workgroup storage class. Only |
| 469 |
// the second one needs to change. |
| 470 |
const std::string text = R"( |
| 471 |
; CHECK: OpAccessChain %_ptr_Workgroup__arr_float_uint_10 |
| 472 |
; CHECK: OpAccessChain %_ptr_Workgroup_float |
| 473 |
; CHECK: OpAccessChain %_ptr_Uniform_float |
| 474 |
OpCapability Shader |
| 475 |
OpMemoryModel Logical GLSL450 |
| 476 |
OpEntryPoint GLCompute %1 "testMain" %gl_GlobalInvocationID %gl_LocalInvocationID %gl_WorkGroupID |
| 477 |
OpExecutionMode %1 LocalSize 8 8 1 |
| 478 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 479 |
OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId |
| 480 |
OpDecorate %gl_WorkGroupID BuiltIn WorkgroupId |
| 481 |
OpDecorate %5 DescriptorSet 0 |
| 482 |
OpDecorate %5 Binding 0 |
| 483 |
OpDecorate %_runtimearr_float ArrayStride 4 |
| 484 |
OpMemberDecorate %_struct_7 0 Offset 0 |
| 485 |
OpDecorate %_struct_7 BufferBlock |
| 486 |
%int = OpTypeInt 32 1 |
| 487 |
%int_0 = OpConstant %int 0 |
| 488 |
%float = OpTypeFloat 32 |
| 489 |
%float_2 = OpConstant %float 2 |
| 490 |
%uint = OpTypeInt 32 0 |
| 491 |
%uint_10 = OpConstant %uint 10 |
| 492 |
%_arr_float_uint_10 = OpTypeArray %float %uint_10 |
| 493 |
%_ptr_Workgroup__arr_float_uint_10 = OpTypePointer Workgroup %_arr_float_uint_10 |
| 494 |
%_ptr = OpTypePointer Function %_arr_float_uint_10 |
| 495 |
%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10 |
| 496 |
%_struct_17 = OpTypeStruct %_arr__arr_float_uint_10_uint_10 |
| 497 |
%_ptr_Workgroup__struct_17 = OpTypePointer Workgroup %_struct_17 |
| 498 |
%_runtimearr_float = OpTypeRuntimeArray %float |
| 499 |
%_struct_7 = OpTypeStruct %_runtimearr_float |
| 500 |
%_ptr_Uniform__struct_7 = OpTypePointer Uniform %_struct_7 |
| 501 |
%v3uint = OpTypeVector %uint 3 |
| 502 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 503 |
%void = OpTypeVoid |
| 504 |
%23 = OpTypeFunction %void |
| 505 |
%_ptr_Function_float = OpTypePointer Function %float |
| 506 |
%_ptr_Uniform_float = OpTypePointer Uniform %float |
| 507 |
%27 = OpVariable %_ptr_Workgroup__struct_17 Workgroup |
| 508 |
%5 = OpVariable %_ptr_Uniform__struct_7 Uniform |
| 509 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 510 |
%gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 511 |
%gl_WorkGroupID = OpVariable %_ptr_Input_v3uint Input |
| 512 |
%1 = OpFunction %void None %23 |
| 513 |
%28 = OpLabel |
| 514 |
%29 = OpLoad %v3uint %gl_LocalInvocationID |
| 515 |
%30 = OpAccessChain %_ptr_Workgroup__arr_float_uint_10 %27 %int_0 %int_0 |
| 516 |
%31 = OpAccessChain %_ptr_Function_float %30 %int_0 |
| 517 |
%32 = OpLoad %float %31 |
| 518 |
%33 = OpFMul %float %float_2 %32 |
| 519 |
OpStore %31 %33 |
| 520 |
%34 = OpLoad %float %31 |
| 521 |
%35 = OpCompositeExtract %uint %29 0 |
| 522 |
%36 = OpAccessChain %_ptr_Uniform_float %5 %int_0 %35 |
| 523 |
OpStore %36 %34 |
| 524 |
OpReturn |
| 525 |
OpFunctionEnd |
| 526 |
)"; |
| 527 |
|
| 528 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 529 |
} |
| 530 |
|
| 531 |
using FixTypeTest = PassTest<::testing::Test>; |
| 532 |
|
| 533 |
TEST_F(FixTypeTest, FixAccessChain) { |
| 534 |
const std::string text = R"( |
| 535 |
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 |
| 536 |
; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_T [[ac1]] %int_0 |
| 537 |
OpCapability Shader |
| 538 |
OpMemoryModel Logical GLSL450 |
| 539 |
OpEntryPoint GLCompute %main "main" |
| 540 |
OpExecutionMode %main LocalSize 1 1 1 |
| 541 |
OpSource HLSL 600 |
| 542 |
OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" |
| 543 |
OpName %S "S" |
| 544 |
OpMemberName %S 0 "t" |
| 545 |
OpName %T "T" |
| 546 |
OpMemberName %T 0 "a" |
| 547 |
OpName %A "A" |
| 548 |
OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" |
| 549 |
OpMemberName %type_ACSBuffer_counter 0 "counter" |
| 550 |
OpName %counter_var_A "counter.var.A" |
| 551 |
OpName %main "main" |
| 552 |
OpName %S_0 "S" |
| 553 |
OpMemberName %S_0 0 "t" |
| 554 |
OpName %T_0 "T" |
| 555 |
OpMemberName %T_0 0 "a" |
| 556 |
OpDecorate %A DescriptorSet 0 |
| 557 |
OpDecorate %A Binding 0 |
| 558 |
OpDecorate %counter_var_A DescriptorSet 0 |
| 559 |
OpDecorate %counter_var_A Binding 1 |
| 560 |
OpMemberDecorate %T 0 Offset 0 |
| 561 |
OpMemberDecorate %S 0 Offset 0 |
| 562 |
OpDecorate %_runtimearr_S ArrayStride 4 |
| 563 |
OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 |
| 564 |
OpDecorate %type_RWStructuredBuffer_S BufferBlock |
| 565 |
OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 |
| 566 |
OpDecorate %type_ACSBuffer_counter BufferBlock |
| 567 |
%int = OpTypeInt 32 1 |
| 568 |
%int_0 = OpConstant %int 0 |
| 569 |
%uint = OpTypeInt 32 0 |
| 570 |
%uint_0 = OpConstant %uint 0 |
| 571 |
%T = OpTypeStruct %int |
| 572 |
%S = OpTypeStruct %T |
| 573 |
%_runtimearr_S = OpTypeRuntimeArray %S |
| 574 |
%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S |
| 575 |
%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S |
| 576 |
%type_ACSBuffer_counter = OpTypeStruct %int |
| 577 |
%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter |
| 578 |
%void = OpTypeVoid |
| 579 |
%18 = OpTypeFunction %void |
| 580 |
%T_0 = OpTypeStruct %int |
| 581 |
%S_0 = OpTypeStruct %T_0 |
| 582 |
%_ptr_Function_S_0 = OpTypePointer Function %S_0 |
| 583 |
%_ptr_Uniform_S = OpTypePointer Uniform %S |
| 584 |
%_ptr_Uniform_T = OpTypePointer Uniform %T |
| 585 |
%22 = OpTypeFunction %T_0 %_ptr_Function_S_0 |
| 586 |
%_ptr_Function_T_0 = OpTypePointer Function %T_0 |
| 587 |
%A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform |
| 588 |
%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform |
| 589 |
%main = OpFunction %void None %18 |
| 590 |
%24 = OpLabel |
| 591 |
%25 = OpVariable %_ptr_Function_T_0 Function |
| 592 |
%26 = OpVariable %_ptr_Function_S_0 Function |
| 593 |
%27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 |
| 594 |
%28 = OpAccessChain %_ptr_Function_T_0 %27 %int_0 |
| 595 |
OpReturn |
| 596 |
OpFunctionEnd |
| 597 |
)"; |
| 598 |
|
| 599 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 600 |
} |
| 601 |
|
| 602 |
TEST_F(FixTypeTest, FixLoad) { |
| 603 |
const std::string text = R"( |
| 604 |
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 |
| 605 |
; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_T [[ac1]] %int_0 |
| 606 |
; CHECK: [[ld:%\w+]] = OpLoad %T [[ac2]] |
| 607 |
OpCapability Shader |
| 608 |
OpMemoryModel Logical GLSL450 |
| 609 |
OpEntryPoint GLCompute %main "main" |
| 610 |
OpExecutionMode %main LocalSize 1 1 1 |
| 611 |
OpSource HLSL 600 |
| 612 |
OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" |
| 613 |
OpName %S "S" |
| 614 |
OpMemberName %S 0 "t" |
| 615 |
OpName %T "T" |
| 616 |
OpMemberName %T 0 "a" |
| 617 |
OpName %A "A" |
| 618 |
OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" |
| 619 |
OpMemberName %type_ACSBuffer_counter 0 "counter" |
| 620 |
OpName %counter_var_A "counter.var.A" |
| 621 |
OpName %main "main" |
| 622 |
OpName %S_0 "S" |
| 623 |
OpMemberName %S_0 0 "t" |
| 624 |
OpName %T_0 "T" |
| 625 |
OpMemberName %T_0 0 "a" |
| 626 |
OpDecorate %A DescriptorSet 0 |
| 627 |
OpDecorate %A Binding 0 |
| 628 |
OpDecorate %counter_var_A DescriptorSet 0 |
| 629 |
OpDecorate %counter_var_A Binding 1 |
| 630 |
OpMemberDecorate %T 0 Offset 0 |
| 631 |
OpMemberDecorate %S 0 Offset 0 |
| 632 |
OpDecorate %_runtimearr_S ArrayStride 4 |
| 633 |
OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 |
| 634 |
OpDecorate %type_RWStructuredBuffer_S BufferBlock |
| 635 |
OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 |
| 636 |
OpDecorate %type_ACSBuffer_counter BufferBlock |
| 637 |
%int = OpTypeInt 32 1 |
| 638 |
%int_0 = OpConstant %int 0 |
| 639 |
%uint = OpTypeInt 32 0 |
| 640 |
%uint_0 = OpConstant %uint 0 |
| 641 |
%T = OpTypeStruct %int |
| 642 |
%S = OpTypeStruct %T |
| 643 |
%_runtimearr_S = OpTypeRuntimeArray %S |
| 644 |
%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S |
| 645 |
%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S |
| 646 |
%type_ACSBuffer_counter = OpTypeStruct %int |
| 647 |
%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter |
| 648 |
%void = OpTypeVoid |
| 649 |
%18 = OpTypeFunction %void |
| 650 |
%T_0 = OpTypeStruct %int |
| 651 |
%S_0 = OpTypeStruct %T_0 |
| 652 |
%_ptr_Function_S_0 = OpTypePointer Function %S_0 |
| 653 |
%_ptr_Uniform_S = OpTypePointer Uniform %S |
| 654 |
%_ptr_Uniform_T = OpTypePointer Uniform %T |
| 655 |
%22 = OpTypeFunction %T_0 %_ptr_Function_S_0 |
| 656 |
%_ptr_Function_T_0 = OpTypePointer Function %T_0 |
| 657 |
%A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform |
| 658 |
%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform |
| 659 |
%main = OpFunction %void None %18 |
| 660 |
%24 = OpLabel |
| 661 |
%25 = OpVariable %_ptr_Function_T_0 Function |
| 662 |
%26 = OpVariable %_ptr_Function_S_0 Function |
| 663 |
%27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 |
| 664 |
%28 = OpAccessChain %_ptr_Uniform_T %27 %int_0 |
| 665 |
%29 = OpLoad %T_0 %28 |
| 666 |
OpReturn |
| 667 |
OpFunctionEnd |
| 668 |
)"; |
| 669 |
|
| 670 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 671 |
} |
| 672 |
|
| 673 |
TEST_F(FixTypeTest, FixStore) { |
| 674 |
const std::string text = R"( |
| 675 |
; CHECK: [[ld:%\w+]] = OpLoad %T |
| 676 |
; CHECK: OpStore |
| 677 |
OpCapability Shader |
| 678 |
OpMemoryModel Logical GLSL450 |
| 679 |
OpEntryPoint GLCompute %main "main" |
| 680 |
OpExecutionMode %main LocalSize 1 1 1 |
| 681 |
OpSource HLSL 600 |
| 682 |
OpName %type_RWStructuredBuffer_S "type.RWStructuredBuffer.S" |
| 683 |
OpName %S "S" |
| 684 |
OpMemberName %S 0 "t" |
| 685 |
OpName %T "T" |
| 686 |
OpMemberName %T 0 "a" |
| 687 |
OpName %A "A" |
| 688 |
OpName %type_ACSBuffer_counter "type.ACSBuffer.counter" |
| 689 |
OpMemberName %type_ACSBuffer_counter 0 "counter" |
| 690 |
OpName %counter_var_A "counter.var.A" |
| 691 |
OpName %main "main" |
| 692 |
OpName %S_0 "S" |
| 693 |
OpMemberName %S_0 0 "t" |
| 694 |
OpName %T_0 "T" |
| 695 |
OpMemberName %T_0 0 "a" |
| 696 |
OpDecorate %A DescriptorSet 0 |
| 697 |
OpDecorate %A Binding 0 |
| 698 |
OpDecorate %counter_var_A DescriptorSet 0 |
| 699 |
OpDecorate %counter_var_A Binding 1 |
| 700 |
OpMemberDecorate %T 0 Offset 0 |
| 701 |
OpMemberDecorate %S 0 Offset 0 |
| 702 |
OpDecorate %_runtimearr_S ArrayStride 4 |
| 703 |
OpMemberDecorate %type_RWStructuredBuffer_S 0 Offset 0 |
| 704 |
OpDecorate %type_RWStructuredBuffer_S BufferBlock |
| 705 |
OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0 |
| 706 |
OpDecorate %type_ACSBuffer_counter BufferBlock |
| 707 |
%int = OpTypeInt 32 1 |
| 708 |
%int_0 = OpConstant %int 0 |
| 709 |
%uint = OpTypeInt 32 0 |
| 710 |
%uint_0 = OpConstant %uint 0 |
| 711 |
%T = OpTypeStruct %int |
| 712 |
%S = OpTypeStruct %T |
| 713 |
%_runtimearr_S = OpTypeRuntimeArray %S |
| 714 |
%type_RWStructuredBuffer_S = OpTypeStruct %_runtimearr_S |
| 715 |
%_ptr_Uniform_type_RWStructuredBuffer_S = OpTypePointer Uniform %type_RWStructuredBuffer_S |
| 716 |
%type_ACSBuffer_counter = OpTypeStruct %int |
| 717 |
%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter |
| 718 |
%void = OpTypeVoid |
| 719 |
%18 = OpTypeFunction %void |
| 720 |
%T_0 = OpTypeStruct %int |
| 721 |
%S_0 = OpTypeStruct %T_0 |
| 722 |
%_ptr_Function_S_0 = OpTypePointer Function %S_0 |
| 723 |
%_ptr_Uniform_S = OpTypePointer Uniform %S |
| 724 |
%_ptr_Uniform_T = OpTypePointer Uniform %T |
| 725 |
%22 = OpTypeFunction %T_0 %_ptr_Function_S_0 |
| 726 |
%_ptr_Function_T_0 = OpTypePointer Function %T_0 |
| 727 |
%A = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_S Uniform |
| 728 |
%counter_var_A = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform |
| 729 |
%main = OpFunction %void None %18 |
| 730 |
%24 = OpLabel |
| 731 |
%25 = OpVariable %_ptr_Function_T_0 Function |
| 732 |
%26 = OpVariable %_ptr_Function_S_0 Function |
| 733 |
%27 = OpAccessChain %_ptr_Uniform_S %A %int_0 %uint_0 |
| 734 |
%28 = OpAccessChain %_ptr_Uniform_T %27 %int_0 |
| 735 |
%29 = OpLoad %T %28 |
| 736 |
OpStore %25 %29 |
| 737 |
OpReturn |
| 738 |
OpFunctionEnd |
| 739 |
)"; |
| 740 |
|
| 741 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 742 |
} |
| 743 |
|
| 744 |
TEST_F(FixTypeTest, FixSelect) { |
| 745 |
const std::string text = R"( |
| 746 |
; CHECK: OpSelect %_ptr_Uniform__struct_3 |
| 747 |
OpCapability Shader |
| 748 |
OpMemoryModel Logical GLSL450 |
| 749 |
OpEntryPoint GLCompute %1 "main" |
| 750 |
OpExecutionMode %1 LocalSize 1 1 1 |
| 751 |
OpSource HLSL 600 |
| 752 |
OpDecorate %2 DescriptorSet 0 |
| 753 |
OpDecorate %2 Binding 0 |
| 754 |
OpMemberDecorate %_struct_3 0 Offset 0 |
| 755 |
OpDecorate %_runtimearr__struct_3 ArrayStride 4 |
| 756 |
OpMemberDecorate %_struct_5 0 Offset 0 |
| 757 |
OpDecorate %_struct_5 BufferBlock |
| 758 |
%uint = OpTypeInt 32 0 |
| 759 |
%uint_0 = OpConstant %uint 0 |
| 760 |
%uint_1 = OpConstant %uint 1 |
| 761 |
%_struct_3 = OpTypeStruct %uint |
| 762 |
%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3 |
| 763 |
%_struct_5 = OpTypeStruct %_runtimearr__struct_3 |
| 764 |
%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5 |
| 765 |
%void = OpTypeVoid |
| 766 |
%11 = OpTypeFunction %void |
| 767 |
%_struct_12 = OpTypeStruct %uint |
| 768 |
%_ptr_Function__struct_12 = OpTypePointer Function %_struct_12 |
| 769 |
%_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| 770 |
%bool = OpTypeBool |
| 771 |
%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3 |
| 772 |
%2 = OpVariable %_ptr_Uniform__struct_5 Uniform |
| 773 |
%1 = OpFunction %void None %11 |
| 774 |
%17 = OpLabel |
| 775 |
%18 = OpAccessChain %_ptr_Uniform_uint %2 %uint_0 %uint_0 %uint_0 |
| 776 |
%19 = OpLoad %uint %18 |
| 777 |
%20 = OpSGreaterThan %bool %19 %uint_0 |
| 778 |
%21 = OpAccessChain %_ptr_Uniform__struct_3 %2 %uint_0 %uint_0 |
| 779 |
%22 = OpAccessChain %_ptr_Uniform__struct_3 %2 %uint_0 %uint_1 |
| 780 |
%23 = OpSelect %_ptr_Function__struct_12 %20 %21 %22 |
| 781 |
OpReturn |
| 782 |
OpFunctionEnd |
| 783 |
)"; |
| 784 |
|
| 785 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 786 |
} |
| 787 |
|
| 788 |
TEST_F(FixTypeTest, FixPhiInLoop) { |
| 789 |
const std::string text = R"( |
| 790 |
; CHECK: [[ac_init:%\w+]] = OpAccessChain %_ptr_Uniform__struct_3 |
| 791 |
; CHECK: [[ac_phi:%\w+]] = OpPhi %_ptr_Uniform__struct_3 [[ac_init]] {{%\w+}} [[ac_update:%\w+]] {{%\w+}} |
| 792 |
; CHECK: [[ac_update]] = OpPtrAccessChain %_ptr_Uniform__struct_3 [[ac_phi]] %int_1 |
| 793 |
OpCapability Shader |
| 794 |
OpMemoryModel Logical GLSL450 |
| 795 |
OpEntryPoint GLCompute %1 "main" |
| 796 |
OpExecutionMode %1 LocalSize 1 1 1 |
| 797 |
OpSource HLSL 600 |
| 798 |
OpDecorate %2 DescriptorSet 0 |
| 799 |
OpDecorate %2 Binding 0 |
| 800 |
OpMemberDecorate %_struct_3 0 Offset 0 |
| 801 |
OpDecorate %_runtimearr__struct_3 ArrayStride 4 |
| 802 |
OpMemberDecorate %_struct_5 0 Offset 0 |
| 803 |
OpDecorate %_struct_5 BufferBlock |
| 804 |
%int = OpTypeInt 32 1 |
| 805 |
%int_0 = OpConstant %int 0 |
| 806 |
%int_1 = OpConstant %int 1 |
| 807 |
%_struct_3 = OpTypeStruct %int |
| 808 |
%_struct_9 = OpTypeStruct %int |
| 809 |
%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3 |
| 810 |
%_struct_5 = OpTypeStruct %_runtimearr__struct_3 |
| 811 |
%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5 |
| 812 |
%void = OpTypeVoid |
| 813 |
%12 = OpTypeFunction %void |
| 814 |
%bool = OpTypeBool |
| 815 |
%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3 |
| 816 |
%_ptr_Function__struct_9 = OpTypePointer Function %_struct_9 |
| 817 |
%2 = OpVariable %_ptr_Uniform__struct_5 Uniform |
| 818 |
%1 = OpFunction %void None %12 |
| 819 |
%16 = OpLabel |
| 820 |
%17 = OpAccessChain %_ptr_Uniform__struct_3 %2 %int_0 %int_0 |
| 821 |
OpBranch %18 |
| 822 |
%18 = OpLabel |
| 823 |
%20 = OpPhi %_ptr_Function__struct_9 %17 %16 %21 %22 |
| 824 |
%23 = OpUndef %bool |
| 825 |
OpLoopMerge %24 %22 None |
| 826 |
OpBranchConditional %23 %22 %24 |
| 827 |
%22 = OpLabel |
| 828 |
%21 = OpPtrAccessChain %_ptr_Function__struct_9 %20 %int_1 |
| 829 |
OpBranch %18 |
| 830 |
%24 = OpLabel |
| 831 |
OpReturn |
| 832 |
OpFunctionEnd |
| 833 |
)"; |
| 834 |
|
| 835 |
SinglePassRunAndMatch<FixStorageClass>(text, false); |
| 836 |
} |
| 837 |
|
| 838 |
} // namespace |
| 839 |
} // namespace opt |
| 840 |
} // namespace spvtools |