| 1 |
// Copyright (c) 2018 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 |
|
| 21 |
namespace spvtools { |
| 22 |
namespace opt { |
| 23 |
namespace { |
| 24 |
|
| 25 |
using CopyPropArrayPassTest = PassTest<::testing::Test>; |
| 26 |
|
| 27 |
TEST_F(CopyPropArrayPassTest, BasicPropagateArray) { |
| 28 |
const std::string before = |
| 29 |
R"( |
| 30 |
OpCapability Shader |
| 31 |
OpMemoryModel Logical GLSL450 |
| 32 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 33 |
OpExecutionMode %main OriginUpperLeft |
| 34 |
OpSource HLSL 600 |
| 35 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 36 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 37 |
OpName %MyCBuffer "MyCBuffer" |
| 38 |
OpName %main "main" |
| 39 |
OpName %in_var_INDEX "in.var.INDEX" |
| 40 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 41 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 42 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 43 |
OpDecorate %type_MyCBuffer Block |
| 44 |
OpDecorate %in_var_INDEX Flat |
| 45 |
OpDecorate %in_var_INDEX Location 0 |
| 46 |
OpDecorate %out_var_SV_Target Location 0 |
| 47 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 48 |
OpDecorate %MyCBuffer Binding 0 |
| 49 |
%float = OpTypeFloat 32 |
| 50 |
%v4float = OpTypeVector %float 4 |
| 51 |
%uint = OpTypeInt 32 0 |
| 52 |
%uint_8 = OpConstant %uint 8 |
| 53 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 54 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 55 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 56 |
%void = OpTypeVoid |
| 57 |
%13 = OpTypeFunction %void |
| 58 |
%int = OpTypeInt 32 1 |
| 59 |
%_ptr_Input_int = OpTypePointer Input %int |
| 60 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 61 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 62 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 63 |
%int_0 = OpConstant %int 0 |
| 64 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 65 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 66 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 67 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 68 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 69 |
; CHECK: OpFunction |
| 70 |
; CHECK: OpLabel |
| 71 |
; CHECK: OpVariable |
| 72 |
; CHECK: OpAccessChain |
| 73 |
; CHECK: [[new_address:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 74 |
; CHECK: [[element_ptr:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[new_address]] %24 |
| 75 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[element_ptr]] |
| 76 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 77 |
%main = OpFunction %void None %13 |
| 78 |
%22 = OpLabel |
| 79 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 80 |
%24 = OpLoad %int %in_var_INDEX |
| 81 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 82 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 83 |
%27 = OpCompositeExtract %v4float %26 0 |
| 84 |
%28 = OpCompositeExtract %v4float %26 1 |
| 85 |
%29 = OpCompositeExtract %v4float %26 2 |
| 86 |
%30 = OpCompositeExtract %v4float %26 3 |
| 87 |
%31 = OpCompositeExtract %v4float %26 4 |
| 88 |
%32 = OpCompositeExtract %v4float %26 5 |
| 89 |
%33 = OpCompositeExtract %v4float %26 6 |
| 90 |
%34 = OpCompositeExtract %v4float %26 7 |
| 91 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 92 |
OpStore %23 %35 |
| 93 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 94 |
%37 = OpLoad %v4float %36 |
| 95 |
OpStore %out_var_SV_Target %37 |
| 96 |
OpReturn |
| 97 |
OpFunctionEnd |
| 98 |
)"; |
| 99 |
|
| 100 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 101 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 102 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 103 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 104 |
} |
| 105 |
|
| 106 |
TEST_F(CopyPropArrayPassTest, BasicPropagateArrayWithName) { |
| 107 |
const std::string before = |
| 108 |
R"( |
| 109 |
OpCapability Shader |
| 110 |
OpMemoryModel Logical GLSL450 |
| 111 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 112 |
OpExecutionMode %main OriginUpperLeft |
| 113 |
OpSource HLSL 600 |
| 114 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 115 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 116 |
OpName %MyCBuffer "MyCBuffer" |
| 117 |
OpName %main "main" |
| 118 |
OpName %local "local" |
| 119 |
OpName %in_var_INDEX "in.var.INDEX" |
| 120 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 121 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 122 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 123 |
OpDecorate %type_MyCBuffer Block |
| 124 |
OpDecorate %in_var_INDEX Flat |
| 125 |
OpDecorate %in_var_INDEX Location 0 |
| 126 |
OpDecorate %out_var_SV_Target Location 0 |
| 127 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 128 |
OpDecorate %MyCBuffer Binding 0 |
| 129 |
%float = OpTypeFloat 32 |
| 130 |
%v4float = OpTypeVector %float 4 |
| 131 |
%uint = OpTypeInt 32 0 |
| 132 |
%uint_8 = OpConstant %uint 8 |
| 133 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 134 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 135 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 136 |
%void = OpTypeVoid |
| 137 |
%13 = OpTypeFunction %void |
| 138 |
%int = OpTypeInt 32 1 |
| 139 |
%_ptr_Input_int = OpTypePointer Input %int |
| 140 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 141 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 142 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 143 |
%int_0 = OpConstant %int 0 |
| 144 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 145 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 146 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 147 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 148 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 149 |
; CHECK: OpFunction |
| 150 |
; CHECK: OpLabel |
| 151 |
; CHECK: OpVariable |
| 152 |
; CHECK: OpAccessChain |
| 153 |
; CHECK: [[new_address:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 154 |
; CHECK: [[element_ptr:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[new_address]] %24 |
| 155 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[element_ptr]] |
| 156 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 157 |
%main = OpFunction %void None %13 |
| 158 |
%22 = OpLabel |
| 159 |
%local = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 160 |
%24 = OpLoad %int %in_var_INDEX |
| 161 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 162 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 163 |
%27 = OpCompositeExtract %v4float %26 0 |
| 164 |
%28 = OpCompositeExtract %v4float %26 1 |
| 165 |
%29 = OpCompositeExtract %v4float %26 2 |
| 166 |
%30 = OpCompositeExtract %v4float %26 3 |
| 167 |
%31 = OpCompositeExtract %v4float %26 4 |
| 168 |
%32 = OpCompositeExtract %v4float %26 5 |
| 169 |
%33 = OpCompositeExtract %v4float %26 6 |
| 170 |
%34 = OpCompositeExtract %v4float %26 7 |
| 171 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 172 |
OpStore %local %35 |
| 173 |
%36 = OpAccessChain %_ptr_Function_v4float %local %24 |
| 174 |
%37 = OpLoad %v4float %36 |
| 175 |
OpStore %out_var_SV_Target %37 |
| 176 |
OpReturn |
| 177 |
OpFunctionEnd |
| 178 |
)"; |
| 179 |
|
| 180 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 181 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 182 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 183 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 184 |
} |
| 185 |
|
| 186 |
// Propagate 2d array. This test identifying a copy through multiple levels. |
| 187 |
// Also has to traverse multiple OpAccessChains. |
| 188 |
TEST_F(CopyPropArrayPassTest, Propagate2DArray) { |
| 189 |
const std::string text = |
| 190 |
R"(OpCapability Shader |
| 191 |
OpMemoryModel Logical GLSL450 |
| 192 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 193 |
OpExecutionMode %main OriginUpperLeft |
| 194 |
OpSource HLSL 600 |
| 195 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 196 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 197 |
OpName %MyCBuffer "MyCBuffer" |
| 198 |
OpName %main "main" |
| 199 |
OpName %in_var_INDEX "in.var.INDEX" |
| 200 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 201 |
OpDecorate %_arr_v4float_uint_2 ArrayStride 16 |
| 202 |
OpDecorate %_arr__arr_v4float_uint_2_uint_2 ArrayStride 32 |
| 203 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 204 |
OpDecorate %type_MyCBuffer Block |
| 205 |
OpDecorate %in_var_INDEX Flat |
| 206 |
OpDecorate %in_var_INDEX Location 0 |
| 207 |
OpDecorate %out_var_SV_Target Location 0 |
| 208 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 209 |
OpDecorate %MyCBuffer Binding 0 |
| 210 |
%float = OpTypeFloat 32 |
| 211 |
%v4float = OpTypeVector %float 4 |
| 212 |
%uint = OpTypeInt 32 0 |
| 213 |
%uint_2 = OpConstant %uint 2 |
| 214 |
%_arr_v4float_uint_2 = OpTypeArray %v4float %uint_2 |
| 215 |
%_arr__arr_v4float_uint_2_uint_2 = OpTypeArray %_arr_v4float_uint_2 %uint_2 |
| 216 |
%type_MyCBuffer = OpTypeStruct %_arr__arr_v4float_uint_2_uint_2 |
| 217 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 218 |
%void = OpTypeVoid |
| 219 |
%14 = OpTypeFunction %void |
| 220 |
%int = OpTypeInt 32 1 |
| 221 |
%_ptr_Input_int = OpTypePointer Input %int |
| 222 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 223 |
%_arr_v4float_uint_2_0 = OpTypeArray %v4float %uint_2 |
| 224 |
%_arr__arr_v4float_uint_2_0_uint_2 = OpTypeArray %_arr_v4float_uint_2_0 %uint_2 |
| 225 |
%_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 = OpTypePointer Function %_arr__arr_v4float_uint_2_0_uint_2 |
| 226 |
%int_0 = OpConstant %int 0 |
| 227 |
%_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 = OpTypePointer Uniform %_arr__arr_v4float_uint_2_uint_2 |
| 228 |
%_ptr_Function__arr_v4float_uint_2_0 = OpTypePointer Function %_arr_v4float_uint_2_0 |
| 229 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 230 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 231 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 232 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 233 |
; CHECK: OpFunction |
| 234 |
; CHECK: OpLabel |
| 235 |
; CHECK: OpVariable |
| 236 |
; CHECK: OpVariable |
| 237 |
; CHECK: OpAccessChain |
| 238 |
; CHECK: [[new_address:%\w+]] = OpAccessChain %_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 %MyCBuffer %int_0 |
| 239 |
%main = OpFunction %void None %14 |
| 240 |
%25 = OpLabel |
| 241 |
%26 = OpVariable %_ptr_Function__arr_v4float_uint_2_0 Function |
| 242 |
%27 = OpVariable %_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 Function |
| 243 |
%28 = OpLoad %int %in_var_INDEX |
| 244 |
%29 = OpAccessChain %_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 %MyCBuffer %int_0 |
| 245 |
%30 = OpLoad %_arr__arr_v4float_uint_2_uint_2 %29 |
| 246 |
%31 = OpCompositeExtract %_arr_v4float_uint_2 %30 0 |
| 247 |
%32 = OpCompositeExtract %v4float %31 0 |
| 248 |
%33 = OpCompositeExtract %v4float %31 1 |
| 249 |
%34 = OpCompositeConstruct %_arr_v4float_uint_2_0 %32 %33 |
| 250 |
%35 = OpCompositeExtract %_arr_v4float_uint_2 %30 1 |
| 251 |
%36 = OpCompositeExtract %v4float %35 0 |
| 252 |
%37 = OpCompositeExtract %v4float %35 1 |
| 253 |
%38 = OpCompositeConstruct %_arr_v4float_uint_2_0 %36 %37 |
| 254 |
%39 = OpCompositeConstruct %_arr__arr_v4float_uint_2_0_uint_2 %34 %38 |
| 255 |
; CHECK: OpStore |
| 256 |
OpStore %27 %39 |
| 257 |
%40 = OpAccessChain %_ptr_Function__arr_v4float_uint_2_0 %27 %28 |
| 258 |
%42 = OpAccessChain %_ptr_Function_v4float %40 %28 |
| 259 |
%43 = OpLoad %v4float %42 |
| 260 |
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_2 [[new_address]] %28 |
| 261 |
; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[ac1]] %28 |
| 262 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[ac2]] |
| 263 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 264 |
OpStore %out_var_SV_Target %43 |
| 265 |
OpReturn |
| 266 |
OpFunctionEnd |
| 267 |
)"; |
| 268 |
|
| 269 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 270 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 271 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 272 |
SinglePassRunAndMatch<CopyPropagateArrays>(text, false); |
| 273 |
} |
| 274 |
|
| 275 |
// Propagate 2d array. This test identifying a copy through multiple levels. |
| 276 |
// Also has to traverse multiple OpAccessChains. |
| 277 |
TEST_F(CopyPropArrayPassTest, Propagate2DArrayWithMultiLevelExtract) { |
| 278 |
const std::string text = |
| 279 |
R"(OpCapability Shader |
| 280 |
OpMemoryModel Logical GLSL450 |
| 281 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 282 |
OpExecutionMode %main OriginUpperLeft |
| 283 |
OpSource HLSL 600 |
| 284 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 285 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 286 |
OpName %MyCBuffer "MyCBuffer" |
| 287 |
OpName %main "main" |
| 288 |
OpName %in_var_INDEX "in.var.INDEX" |
| 289 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 290 |
OpDecorate %_arr_v4float_uint_2 ArrayStride 16 |
| 291 |
OpDecorate %_arr__arr_v4float_uint_2_uint_2 ArrayStride 32 |
| 292 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 293 |
OpDecorate %type_MyCBuffer Block |
| 294 |
OpDecorate %in_var_INDEX Flat |
| 295 |
OpDecorate %in_var_INDEX Location 0 |
| 296 |
OpDecorate %out_var_SV_Target Location 0 |
| 297 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 298 |
OpDecorate %MyCBuffer Binding 0 |
| 299 |
%float = OpTypeFloat 32 |
| 300 |
%v4float = OpTypeVector %float 4 |
| 301 |
%uint = OpTypeInt 32 0 |
| 302 |
%uint_2 = OpConstant %uint 2 |
| 303 |
%_arr_v4float_uint_2 = OpTypeArray %v4float %uint_2 |
| 304 |
%_arr__arr_v4float_uint_2_uint_2 = OpTypeArray %_arr_v4float_uint_2 %uint_2 |
| 305 |
%type_MyCBuffer = OpTypeStruct %_arr__arr_v4float_uint_2_uint_2 |
| 306 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 307 |
%void = OpTypeVoid |
| 308 |
%14 = OpTypeFunction %void |
| 309 |
%int = OpTypeInt 32 1 |
| 310 |
%_ptr_Input_int = OpTypePointer Input %int |
| 311 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 312 |
%_arr_v4float_uint_2_0 = OpTypeArray %v4float %uint_2 |
| 313 |
%_arr__arr_v4float_uint_2_0_uint_2 = OpTypeArray %_arr_v4float_uint_2_0 %uint_2 |
| 314 |
%_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 = OpTypePointer Function %_arr__arr_v4float_uint_2_0_uint_2 |
| 315 |
%int_0 = OpConstant %int 0 |
| 316 |
%_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 = OpTypePointer Uniform %_arr__arr_v4float_uint_2_uint_2 |
| 317 |
%_ptr_Function__arr_v4float_uint_2_0 = OpTypePointer Function %_arr_v4float_uint_2_0 |
| 318 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 319 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 320 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 321 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 322 |
; CHECK: OpFunction |
| 323 |
; CHECK: OpLabel |
| 324 |
; CHECK: OpVariable |
| 325 |
; CHECK: OpVariable |
| 326 |
; CHECK: OpAccessChain |
| 327 |
; CHECK: [[new_address:%\w+]] = OpAccessChain %_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 %MyCBuffer %int_0 |
| 328 |
%main = OpFunction %void None %14 |
| 329 |
%25 = OpLabel |
| 330 |
%26 = OpVariable %_ptr_Function__arr_v4float_uint_2_0 Function |
| 331 |
%27 = OpVariable %_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 Function |
| 332 |
%28 = OpLoad %int %in_var_INDEX |
| 333 |
%29 = OpAccessChain %_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 %MyCBuffer %int_0 |
| 334 |
%30 = OpLoad %_arr__arr_v4float_uint_2_uint_2 %29 |
| 335 |
%32 = OpCompositeExtract %v4float %30 0 0 |
| 336 |
%33 = OpCompositeExtract %v4float %30 0 1 |
| 337 |
%34 = OpCompositeConstruct %_arr_v4float_uint_2_0 %32 %33 |
| 338 |
%36 = OpCompositeExtract %v4float %30 1 0 |
| 339 |
%37 = OpCompositeExtract %v4float %30 1 1 |
| 340 |
%38 = OpCompositeConstruct %_arr_v4float_uint_2_0 %36 %37 |
| 341 |
%39 = OpCompositeConstruct %_arr__arr_v4float_uint_2_0_uint_2 %34 %38 |
| 342 |
; CHECK: OpStore |
| 343 |
OpStore %27 %39 |
| 344 |
%40 = OpAccessChain %_ptr_Function__arr_v4float_uint_2_0 %27 %28 |
| 345 |
%42 = OpAccessChain %_ptr_Function_v4float %40 %28 |
| 346 |
%43 = OpLoad %v4float %42 |
| 347 |
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_2 [[new_address]] %28 |
| 348 |
; CHECK: [[ac2:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[ac1]] %28 |
| 349 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[ac2]] |
| 350 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 351 |
OpStore %out_var_SV_Target %43 |
| 352 |
OpReturn |
| 353 |
OpFunctionEnd |
| 354 |
)"; |
| 355 |
|
| 356 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 357 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 358 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 359 |
SinglePassRunAndMatch<CopyPropagateArrays>(text, false); |
| 360 |
} |
| 361 |
|
| 362 |
// Test decomposing an object when we need to "rewrite" a store. |
| 363 |
TEST_F(CopyPropArrayPassTest, DecomposeObjectForArrayStore) { |
| 364 |
const std::string text = |
| 365 |
R"( OpCapability Shader |
| 366 |
OpMemoryModel Logical GLSL450 |
| 367 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 368 |
OpExecutionMode %main OriginUpperLeft |
| 369 |
OpSource HLSL 600 |
| 370 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 371 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 372 |
OpName %MyCBuffer "MyCBuffer" |
| 373 |
OpName %main "main" |
| 374 |
OpName %in_var_INDEX "in.var.INDEX" |
| 375 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 376 |
OpDecorate %_arr_v4float_uint_2 ArrayStride 16 |
| 377 |
OpDecorate %_arr__arr_v4float_uint_2_uint_2 ArrayStride 32 |
| 378 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 379 |
OpDecorate %type_MyCBuffer Block |
| 380 |
OpDecorate %in_var_INDEX Flat |
| 381 |
OpDecorate %in_var_INDEX Location 0 |
| 382 |
OpDecorate %out_var_SV_Target Location 0 |
| 383 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 384 |
OpDecorate %MyCBuffer Binding 0 |
| 385 |
%float = OpTypeFloat 32 |
| 386 |
%v4float = OpTypeVector %float 4 |
| 387 |
%uint = OpTypeInt 32 0 |
| 388 |
%uint_2 = OpConstant %uint 2 |
| 389 |
%_arr_v4float_uint_2 = OpTypeArray %v4float %uint_2 |
| 390 |
%_arr__arr_v4float_uint_2_uint_2 = OpTypeArray %_arr_v4float_uint_2 %uint_2 |
| 391 |
%type_MyCBuffer = OpTypeStruct %_arr__arr_v4float_uint_2_uint_2 |
| 392 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 393 |
%void = OpTypeVoid |
| 394 |
%14 = OpTypeFunction %void |
| 395 |
%int = OpTypeInt 32 1 |
| 396 |
%_ptr_Input_int = OpTypePointer Input %int |
| 397 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 398 |
%_arr_v4float_uint_2_0 = OpTypeArray %v4float %uint_2 |
| 399 |
%_arr__arr_v4float_uint_2_0_uint_2 = OpTypeArray %_arr_v4float_uint_2_0 %uint_2 |
| 400 |
%_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 = OpTypePointer Function %_arr__arr_v4float_uint_2_0_uint_2 |
| 401 |
%int_0 = OpConstant %int 0 |
| 402 |
%_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 = OpTypePointer Uniform %_arr__arr_v4float_uint_2_uint_2 |
| 403 |
%_ptr_Function__arr_v4float_uint_2_0 = OpTypePointer Function %_arr_v4float_uint_2_0 |
| 404 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 405 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 406 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 407 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 408 |
%main = OpFunction %void None %14 |
| 409 |
%25 = OpLabel |
| 410 |
%26 = OpVariable %_ptr_Function__arr_v4float_uint_2_0 Function |
| 411 |
%27 = OpVariable %_ptr_Function__arr__arr_v4float_uint_2_0_uint_2 Function |
| 412 |
%28 = OpLoad %int %in_var_INDEX |
| 413 |
%29 = OpAccessChain %_ptr_Uniform__arr__arr_v4float_uint_2_uint_2 %MyCBuffer %int_0 |
| 414 |
%30 = OpLoad %_arr__arr_v4float_uint_2_uint_2 %29 |
| 415 |
%31 = OpCompositeExtract %_arr_v4float_uint_2 %30 0 |
| 416 |
%32 = OpCompositeExtract %v4float %31 0 |
| 417 |
%33 = OpCompositeExtract %v4float %31 1 |
| 418 |
%34 = OpCompositeConstruct %_arr_v4float_uint_2_0 %32 %33 |
| 419 |
%35 = OpCompositeExtract %_arr_v4float_uint_2 %30 1 |
| 420 |
%36 = OpCompositeExtract %v4float %35 0 |
| 421 |
%37 = OpCompositeExtract %v4float %35 1 |
| 422 |
%38 = OpCompositeConstruct %_arr_v4float_uint_2_0 %36 %37 |
| 423 |
%39 = OpCompositeConstruct %_arr__arr_v4float_uint_2_0_uint_2 %34 %38 |
| 424 |
OpStore %27 %39 |
| 425 |
; CHECK: [[access_chain:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_2 |
| 426 |
%40 = OpAccessChain %_ptr_Function__arr_v4float_uint_2_0 %27 %28 |
| 427 |
; CHECK: [[load:%\w+]] = OpLoad %_arr_v4float_uint_2 [[access_chain]] |
| 428 |
%41 = OpLoad %_arr_v4float_uint_2_0 %40 |
| 429 |
; CHECK: [[extract1:%\w+]] = OpCompositeExtract %v4float [[load]] 0 |
| 430 |
; CHECK: [[extract2:%\w+]] = OpCompositeExtract %v4float [[load]] 1 |
| 431 |
; CHECK: [[construct:%\w+]] = OpCompositeConstruct %_arr_v4float_uint_2_0 [[extract1]] [[extract2]] |
| 432 |
; CHECK: OpStore %26 [[construct]] |
| 433 |
OpStore %26 %41 |
| 434 |
%42 = OpAccessChain %_ptr_Function_v4float %26 %28 |
| 435 |
%43 = OpLoad %v4float %42 |
| 436 |
OpStore %out_var_SV_Target %43 |
| 437 |
OpReturn |
| 438 |
OpFunctionEnd |
| 439 |
)"; |
| 440 |
|
| 441 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 442 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 443 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 444 |
SinglePassRunAndMatch<CopyPropagateArrays>(text, false); |
| 445 |
} |
| 446 |
|
| 447 |
// Test decomposing an object when we need to "rewrite" a store. |
| 448 |
TEST_F(CopyPropArrayPassTest, DecomposeObjectForStructStore) { |
| 449 |
const std::string text = |
| 450 |
R"( OpCapability Shader |
| 451 |
OpMemoryModel Logical GLSL450 |
| 452 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 453 |
OpExecutionMode %main OriginUpperLeft |
| 454 |
OpSource HLSL 600 |
| 455 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 456 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 457 |
OpName %MyCBuffer "MyCBuffer" |
| 458 |
OpName %main "main" |
| 459 |
OpName %in_var_INDEX "in.var.INDEX" |
| 460 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 461 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 462 |
OpDecorate %type_MyCBuffer Block |
| 463 |
OpDecorate %in_var_INDEX Flat |
| 464 |
OpDecorate %in_var_INDEX Location 0 |
| 465 |
OpDecorate %out_var_SV_Target Location 0 |
| 466 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 467 |
OpDecorate %MyCBuffer Binding 0 |
| 468 |
; CHECK: OpDecorate [[decorated_type:%\w+]] GLSLPacked |
| 469 |
OpDecorate %struct GLSLPacked |
| 470 |
%float = OpTypeFloat 32 |
| 471 |
%v4float = OpTypeVector %float 4 |
| 472 |
%uint = OpTypeInt 32 0 |
| 473 |
%uint_2 = OpConstant %uint 2 |
| 474 |
; CHECK: [[decorated_type]] = OpTypeStruct |
| 475 |
%struct = OpTypeStruct %float %uint |
| 476 |
%_arr_struct_uint_2 = OpTypeArray %struct %uint_2 |
| 477 |
%type_MyCBuffer = OpTypeStruct %_arr_struct_uint_2 |
| 478 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 479 |
%void = OpTypeVoid |
| 480 |
%14 = OpTypeFunction %void |
| 481 |
%int = OpTypeInt 32 1 |
| 482 |
%_ptr_Input_int = OpTypePointer Input %int |
| 483 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 484 |
; CHECK: [[struct:%\w+]] = OpTypeStruct %float %uint |
| 485 |
%struct_0 = OpTypeStruct %float %uint |
| 486 |
%_arr_struct_0_uint_2 = OpTypeArray %struct_0 %uint_2 |
| 487 |
%_ptr_Function__arr_struct_0_uint_2 = OpTypePointer Function %_arr_struct_0_uint_2 |
| 488 |
%int_0 = OpConstant %int 0 |
| 489 |
%_ptr_Uniform__arr_struct_uint_2 = OpTypePointer Uniform %_arr_struct_uint_2 |
| 490 |
; CHECK: [[decorated_ptr:%\w+]] = OpTypePointer Uniform [[decorated_type]] |
| 491 |
%_ptr_Function_struct_0 = OpTypePointer Function %struct_0 |
| 492 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 493 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 494 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 495 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 496 |
%main = OpFunction %void None %14 |
| 497 |
%25 = OpLabel |
| 498 |
%26 = OpVariable %_ptr_Function_struct_0 Function |
| 499 |
%27 = OpVariable %_ptr_Function__arr_struct_0_uint_2 Function |
| 500 |
%28 = OpLoad %int %in_var_INDEX |
| 501 |
%29 = OpAccessChain %_ptr_Uniform__arr_struct_uint_2 %MyCBuffer %int_0 |
| 502 |
%30 = OpLoad %_arr_struct_uint_2 %29 |
| 503 |
%31 = OpCompositeExtract %struct %30 0 |
| 504 |
%32 = OpCompositeExtract %v4float %31 0 |
| 505 |
%33 = OpCompositeExtract %v4float %31 1 |
| 506 |
%34 = OpCompositeConstruct %struct_0 %32 %33 |
| 507 |
%35 = OpCompositeExtract %struct %30 1 |
| 508 |
%36 = OpCompositeExtract %float %35 0 |
| 509 |
%37 = OpCompositeExtract %uint %35 1 |
| 510 |
%38 = OpCompositeConstruct %struct_0 %36 %37 |
| 511 |
%39 = OpCompositeConstruct %_arr_struct_0_uint_2 %34 %38 |
| 512 |
OpStore %27 %39 |
| 513 |
; CHECK: [[access_chain:%\w+]] = OpAccessChain [[decorated_ptr]] |
| 514 |
%40 = OpAccessChain %_ptr_Function_struct_0 %27 %28 |
| 515 |
; CHECK: [[load:%\w+]] = OpLoad [[decorated_type]] [[access_chain]] |
| 516 |
%41 = OpLoad %struct_0 %40 |
| 517 |
; CHECK: [[extract1:%\w+]] = OpCompositeExtract %float [[load]] 0 |
| 518 |
; CHECK: [[extract2:%\w+]] = OpCompositeExtract %uint [[load]] 1 |
| 519 |
; CHECK: [[construct:%\w+]] = OpCompositeConstruct [[struct]] [[extract1]] [[extract2]] |
| 520 |
; CHECK: OpStore %26 [[construct]] |
| 521 |
OpStore %26 %41 |
| 522 |
%42 = OpAccessChain %_ptr_Function_v4float %26 %28 |
| 523 |
%43 = OpLoad %v4float %42 |
| 524 |
OpStore %out_var_SV_Target %43 |
| 525 |
OpReturn |
| 526 |
OpFunctionEnd |
| 527 |
)"; |
| 528 |
|
| 529 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 530 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 531 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 532 |
SinglePassRunAndMatch<CopyPropagateArrays>(text, false); |
| 533 |
} |
| 534 |
|
| 535 |
TEST_F(CopyPropArrayPassTest, CopyViaInserts) { |
| 536 |
const std::string before = |
| 537 |
R"( |
| 538 |
OpCapability Shader |
| 539 |
OpMemoryModel Logical GLSL450 |
| 540 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 541 |
OpExecutionMode %main OriginUpperLeft |
| 542 |
OpSource HLSL 600 |
| 543 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 544 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 545 |
OpName %MyCBuffer "MyCBuffer" |
| 546 |
OpName %main "main" |
| 547 |
OpName %in_var_INDEX "in.var.INDEX" |
| 548 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 549 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 550 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 551 |
OpDecorate %type_MyCBuffer Block |
| 552 |
OpDecorate %in_var_INDEX Flat |
| 553 |
OpDecorate %in_var_INDEX Location 0 |
| 554 |
OpDecorate %out_var_SV_Target Location 0 |
| 555 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 556 |
OpDecorate %MyCBuffer Binding 0 |
| 557 |
%float = OpTypeFloat 32 |
| 558 |
%v4float = OpTypeVector %float 4 |
| 559 |
%uint = OpTypeInt 32 0 |
| 560 |
%uint_8 = OpConstant %uint 8 |
| 561 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 562 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 563 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 564 |
%void = OpTypeVoid |
| 565 |
%13 = OpTypeFunction %void |
| 566 |
%int = OpTypeInt 32 1 |
| 567 |
%_ptr_Input_int = OpTypePointer Input %int |
| 568 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 569 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 570 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 571 |
%int_0 = OpConstant %int 0 |
| 572 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 573 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 574 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 575 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 576 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 577 |
; CHECK: OpFunction |
| 578 |
; CHECK: OpLabel |
| 579 |
; CHECK: OpVariable |
| 580 |
; CHECK: OpAccessChain |
| 581 |
; CHECK: [[new_address:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 582 |
; CHECK: [[element_ptr:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[new_address]] %24 |
| 583 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[element_ptr]] |
| 584 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 585 |
%main = OpFunction %void None %13 |
| 586 |
%22 = OpLabel |
| 587 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 588 |
%undef = OpUndef %_arr_v4float_uint_8_0 |
| 589 |
%24 = OpLoad %int %in_var_INDEX |
| 590 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 591 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 592 |
%27 = OpCompositeExtract %v4float %26 0 |
| 593 |
%i0 = OpCompositeInsert %_arr_v4float_uint_8_0 %27 %undef 0 |
| 594 |
%28 = OpCompositeExtract %v4float %26 1 |
| 595 |
%i1 = OpCompositeInsert %_arr_v4float_uint_8_0 %28 %i0 1 |
| 596 |
%29 = OpCompositeExtract %v4float %26 2 |
| 597 |
%i2 = OpCompositeInsert %_arr_v4float_uint_8_0 %29 %i1 2 |
| 598 |
%30 = OpCompositeExtract %v4float %26 3 |
| 599 |
%i3 = OpCompositeInsert %_arr_v4float_uint_8_0 %30 %i2 3 |
| 600 |
%31 = OpCompositeExtract %v4float %26 4 |
| 601 |
%i4 = OpCompositeInsert %_arr_v4float_uint_8_0 %31 %i3 4 |
| 602 |
%32 = OpCompositeExtract %v4float %26 5 |
| 603 |
%i5 = OpCompositeInsert %_arr_v4float_uint_8_0 %32 %i4 5 |
| 604 |
%33 = OpCompositeExtract %v4float %26 6 |
| 605 |
%i6 = OpCompositeInsert %_arr_v4float_uint_8_0 %33 %i5 6 |
| 606 |
%34 = OpCompositeExtract %v4float %26 7 |
| 607 |
%i7 = OpCompositeInsert %_arr_v4float_uint_8_0 %34 %i6 7 |
| 608 |
OpStore %23 %i7 |
| 609 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 610 |
%37 = OpLoad %v4float %36 |
| 611 |
OpStore %out_var_SV_Target %37 |
| 612 |
OpReturn |
| 613 |
OpFunctionEnd |
| 614 |
)"; |
| 615 |
|
| 616 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 617 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 618 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 619 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 620 |
} |
| 621 |
|
| 622 |
TEST_F(CopyPropArrayPassTest, IsomorphicTypes1) { |
| 623 |
const std::string before = |
| 624 |
R"( |
| 625 |
; CHECK: [[int:%\w+]] = OpTypeInt 32 0 |
| 626 |
; CHECK: [[s1:%\w+]] = OpTypeStruct [[int]] |
| 627 |
; CHECK: [[s2:%\w+]] = OpTypeStruct [[s1]] |
| 628 |
; CHECK: [[a1:%\w+]] = OpTypeArray [[s2]] |
| 629 |
; CHECK: [[s3:%\w+]] = OpTypeStruct [[a1]] |
| 630 |
; CHECK: [[p_s3:%\w+]] = OpTypePointer Uniform [[s3]] |
| 631 |
; CHECK: [[global_var:%\w+]] = OpVariable [[p_s3]] Uniform |
| 632 |
; CHECK: [[p_a1:%\w+]] = OpTypePointer Uniform [[a1]] |
| 633 |
; CHECK: [[p_s2:%\w+]] = OpTypePointer Uniform [[s2]] |
| 634 |
; CHECK: [[ac1:%\w+]] = OpAccessChain [[p_a1]] [[global_var]] %uint_0 |
| 635 |
; CHECK: [[ac2:%\w+]] = OpAccessChain [[p_s2]] [[ac1]] %uint_0 |
| 636 |
; CHECK: [[ld:%\w+]] = OpLoad [[s2]] [[ac2]] |
| 637 |
; CHECK: [[ex:%\w+]] = OpCompositeExtract [[s1]] [[ld]] |
| 638 |
OpCapability Shader |
| 639 |
%1 = OpExtInstImport "GLSL.std.450" |
| 640 |
OpMemoryModel Logical GLSL450 |
| 641 |
OpEntryPoint Fragment %2 "PS_main" |
| 642 |
OpExecutionMode %2 OriginUpperLeft |
| 643 |
OpSource HLSL 600 |
| 644 |
OpDecorate %3 DescriptorSet 0 |
| 645 |
OpDecorate %3 Binding 101 |
| 646 |
%uint = OpTypeInt 32 0 |
| 647 |
%uint_1 = OpConstant %uint 1 |
| 648 |
%s1 = OpTypeStruct %uint |
| 649 |
%s2 = OpTypeStruct %s1 |
| 650 |
%a1 = OpTypeArray %s2 %uint_1 |
| 651 |
%s3 = OpTypeStruct %a1 |
| 652 |
%s1_1 = OpTypeStruct %uint |
| 653 |
%_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| 654 |
%void = OpTypeVoid |
| 655 |
%13 = OpTypeFunction %void |
| 656 |
%uint_0 = OpConstant %uint 0 |
| 657 |
%s1_0 = OpTypeStruct %uint |
| 658 |
%s2_0 = OpTypeStruct %s1_0 |
| 659 |
%a1_0 = OpTypeArray %s2_0 %uint_1 |
| 660 |
%s3_0 = OpTypeStruct %a1_0 |
| 661 |
%p_s3 = OpTypePointer Uniform %s3 |
| 662 |
%p_s3_0 = OpTypePointer Function %s3_0 |
| 663 |
%3 = OpVariable %p_s3 Uniform |
| 664 |
%p_a1_0 = OpTypePointer Function %a1_0 |
| 665 |
%p_s2_0 = OpTypePointer Function %s2_0 |
| 666 |
%2 = OpFunction %void None %13 |
| 667 |
%20 = OpLabel |
| 668 |
%21 = OpVariable %p_a1_0 Function |
| 669 |
%22 = OpLoad %s3 %3 |
| 670 |
%23 = OpCompositeExtract %a1 %22 0 |
| 671 |
%24 = OpCompositeExtract %s2 %23 0 |
| 672 |
%25 = OpCompositeExtract %s1 %24 0 |
| 673 |
%26 = OpCompositeExtract %uint %25 0 |
| 674 |
%27 = OpCompositeConstruct %s1_0 %26 |
| 675 |
%32 = OpCompositeConstruct %s2_0 %27 |
| 676 |
%28 = OpCompositeConstruct %a1_0 %32 |
| 677 |
OpStore %21 %28 |
| 678 |
%29 = OpAccessChain %p_s2_0 %21 %uint_0 |
| 679 |
%30 = OpLoad %s2 %29 |
| 680 |
%31 = OpCompositeExtract %s1 %30 0 |
| 681 |
OpReturn |
| 682 |
OpFunctionEnd |
| 683 |
)"; |
| 684 |
|
| 685 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 686 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 687 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 688 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 689 |
} |
| 690 |
|
| 691 |
TEST_F(CopyPropArrayPassTest, IsomorphicTypes2) { |
| 692 |
const std::string before = |
| 693 |
R"( |
| 694 |
; CHECK: [[int:%\w+]] = OpTypeInt 32 0 |
| 695 |
; CHECK: [[s1:%\w+]] = OpTypeStruct [[int]] |
| 696 |
; CHECK: [[s2:%\w+]] = OpTypeStruct [[s1]] |
| 697 |
; CHECK: [[a1:%\w+]] = OpTypeArray [[s2]] |
| 698 |
; CHECK: [[s3:%\w+]] = OpTypeStruct [[a1]] |
| 699 |
; CHECK: [[p_s3:%\w+]] = OpTypePointer Uniform [[s3]] |
| 700 |
; CHECK: [[global_var:%\w+]] = OpVariable [[p_s3]] Uniform |
| 701 |
; CHECK: [[p_s2:%\w+]] = OpTypePointer Uniform [[s2]] |
| 702 |
; CHECK: [[p_s1:%\w+]] = OpTypePointer Uniform [[s1]] |
| 703 |
; CHECK: [[ac1:%\w+]] = OpAccessChain [[p_s2]] [[global_var]] %uint_0 %uint_0 |
| 704 |
; CHECK: [[ac2:%\w+]] = OpAccessChain [[p_s1]] [[ac1]] %uint_0 |
| 705 |
; CHECK: [[ld:%\w+]] = OpLoad [[s1]] [[ac2]] |
| 706 |
; CHECK: [[ex:%\w+]] = OpCompositeExtract [[int]] [[ld]] |
| 707 |
OpCapability Shader |
| 708 |
%1 = OpExtInstImport "GLSL.std.450" |
| 709 |
OpMemoryModel Logical GLSL450 |
| 710 |
OpEntryPoint Fragment %2 "PS_main" |
| 711 |
OpExecutionMode %2 OriginUpperLeft |
| 712 |
OpSource HLSL 600 |
| 713 |
OpDecorate %3 DescriptorSet 0 |
| 714 |
OpDecorate %3 Binding 101 |
| 715 |
%uint = OpTypeInt 32 0 |
| 716 |
%uint_1 = OpConstant %uint 1 |
| 717 |
%_struct_6 = OpTypeStruct %uint |
| 718 |
%_struct_7 = OpTypeStruct %_struct_6 |
| 719 |
%_arr__struct_7_uint_1 = OpTypeArray %_struct_7 %uint_1 |
| 720 |
%_struct_9 = OpTypeStruct %_arr__struct_7_uint_1 |
| 721 |
%_struct_10 = OpTypeStruct %uint |
| 722 |
%_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| 723 |
%void = OpTypeVoid |
| 724 |
%13 = OpTypeFunction %void |
| 725 |
%uint_0 = OpConstant %uint 0 |
| 726 |
%_struct_15 = OpTypeStruct %uint |
| 727 |
%_arr__struct_15_uint_1 = OpTypeArray %_struct_15 %uint_1 |
| 728 |
%_ptr_Uniform__struct_9 = OpTypePointer Uniform %_struct_9 |
| 729 |
%_ptr_Function__struct_15 = OpTypePointer Function %_struct_15 |
| 730 |
%3 = OpVariable %_ptr_Uniform__struct_9 Uniform |
| 731 |
%_ptr_Function__arr__struct_15_uint_1 = OpTypePointer Function %_arr__struct_15_uint_1 |
| 732 |
%2 = OpFunction %void None %13 |
| 733 |
%20 = OpLabel |
| 734 |
%21 = OpVariable %_ptr_Function__arr__struct_15_uint_1 Function |
| 735 |
%22 = OpLoad %_struct_9 %3 |
| 736 |
%23 = OpCompositeExtract %_arr__struct_7_uint_1 %22 0 |
| 737 |
%24 = OpCompositeExtract %_struct_7 %23 0 |
| 738 |
%25 = OpCompositeExtract %_struct_6 %24 0 |
| 739 |
%26 = OpCompositeExtract %uint %25 0 |
| 740 |
%27 = OpCompositeConstruct %_struct_15 %26 |
| 741 |
%28 = OpCompositeConstruct %_arr__struct_15_uint_1 %27 |
| 742 |
OpStore %21 %28 |
| 743 |
%29 = OpAccessChain %_ptr_Function__struct_15 %21 %uint_0 |
| 744 |
%30 = OpLoad %_struct_15 %29 |
| 745 |
%31 = OpCompositeExtract %uint %30 0 |
| 746 |
OpReturn |
| 747 |
OpFunctionEnd |
| 748 |
)"; |
| 749 |
|
| 750 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 751 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 752 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 753 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 754 |
} |
| 755 |
|
| 756 |
TEST_F(CopyPropArrayPassTest, IsomorphicTypes3) { |
| 757 |
const std::string before = |
| 758 |
R"( |
| 759 |
; CHECK: [[int:%\w+]] = OpTypeInt 32 0 |
| 760 |
; CHECK: [[s1:%\w+]] = OpTypeStruct [[int]] |
| 761 |
; CHECK: [[s2:%\w+]] = OpTypeStruct [[s1]] |
| 762 |
; CHECK: [[a1:%\w+]] = OpTypeArray [[s2]] |
| 763 |
; CHECK: [[s3:%\w+]] = OpTypeStruct [[a1]] |
| 764 |
; CHECK: [[s1_1:%\w+]] = OpTypeStruct [[int]] |
| 765 |
; CHECK: [[p_s3:%\w+]] = OpTypePointer Uniform [[s3]] |
| 766 |
; CHECK: [[p_s1_1:%\w+]] = OpTypePointer Function [[s1_1]] |
| 767 |
; CHECK: [[global_var:%\w+]] = OpVariable [[p_s3]] Uniform |
| 768 |
; CHECK: [[p_s2:%\w+]] = OpTypePointer Uniform [[s2]] |
| 769 |
; CHECK: [[p_s1:%\w+]] = OpTypePointer Uniform [[s1]] |
| 770 |
; CHECK: [[var:%\w+]] = OpVariable [[p_s1_1]] Function |
| 771 |
; CHECK: [[ac1:%\w+]] = OpAccessChain [[p_s2]] [[global_var]] %uint_0 %uint_0 |
| 772 |
; CHECK: [[ac2:%\w+]] = OpAccessChain [[p_s1]] [[ac1]] %uint_0 |
| 773 |
; CHECK: [[ld:%\w+]] = OpLoad [[s1]] [[ac2]] |
| 774 |
; CHECK: [[ex:%\w+]] = OpCompositeExtract [[int]] [[ld]] |
| 775 |
; CHECK: [[copy:%\w+]] = OpCompositeConstruct [[s1_1]] [[ex]] |
| 776 |
; CHECK: OpStore [[var]] [[copy]] |
| 777 |
OpCapability Shader |
| 778 |
%1 = OpExtInstImport "GLSL.std.450" |
| 779 |
OpMemoryModel Logical GLSL450 |
| 780 |
OpEntryPoint Fragment %2 "PS_main" |
| 781 |
OpExecutionMode %2 OriginUpperLeft |
| 782 |
OpSource HLSL 600 |
| 783 |
OpDecorate %3 DescriptorSet 0 |
| 784 |
OpDecorate %3 Binding 101 |
| 785 |
%uint = OpTypeInt 32 0 |
| 786 |
%uint_1 = OpConstant %uint 1 |
| 787 |
%_struct_6 = OpTypeStruct %uint |
| 788 |
%_struct_7 = OpTypeStruct %_struct_6 |
| 789 |
%_arr__struct_7_uint_1 = OpTypeArray %_struct_7 %uint_1 |
| 790 |
%_struct_9 = OpTypeStruct %_arr__struct_7_uint_1 |
| 791 |
%_ptr_Uniform_uint = OpTypePointer Uniform %uint |
| 792 |
%void = OpTypeVoid |
| 793 |
%13 = OpTypeFunction %void |
| 794 |
%uint_0 = OpConstant %uint 0 |
| 795 |
%_struct_15 = OpTypeStruct %uint |
| 796 |
%_struct_10 = OpTypeStruct %uint |
| 797 |
%_arr__struct_15_uint_1 = OpTypeArray %_struct_15 %uint_1 |
| 798 |
%_ptr_Uniform__struct_9 = OpTypePointer Uniform %_struct_9 |
| 799 |
%_ptr_Function__struct_15 = OpTypePointer Function %_struct_15 |
| 800 |
%3 = OpVariable %_ptr_Uniform__struct_9 Uniform |
| 801 |
%_ptr_Function__arr__struct_15_uint_1 = OpTypePointer Function %_arr__struct_15_uint_1 |
| 802 |
%2 = OpFunction %void None %13 |
| 803 |
%20 = OpLabel |
| 804 |
%21 = OpVariable %_ptr_Function__arr__struct_15_uint_1 Function |
| 805 |
%var = OpVariable %_ptr_Function__struct_15 Function |
| 806 |
%22 = OpLoad %_struct_9 %3 |
| 807 |
%23 = OpCompositeExtract %_arr__struct_7_uint_1 %22 0 |
| 808 |
%24 = OpCompositeExtract %_struct_7 %23 0 |
| 809 |
%25 = OpCompositeExtract %_struct_6 %24 0 |
| 810 |
%26 = OpCompositeExtract %uint %25 0 |
| 811 |
%27 = OpCompositeConstruct %_struct_15 %26 |
| 812 |
%28 = OpCompositeConstruct %_arr__struct_15_uint_1 %27 |
| 813 |
OpStore %21 %28 |
| 814 |
%29 = OpAccessChain %_ptr_Function__struct_15 %21 %uint_0 |
| 815 |
%30 = OpLoad %_struct_15 %29 |
| 816 |
OpStore %var %30 |
| 817 |
OpReturn |
| 818 |
OpFunctionEnd |
| 819 |
)"; |
| 820 |
|
| 821 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 822 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 823 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 824 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 825 |
} |
| 826 |
|
| 827 |
TEST_F(CopyPropArrayPassTest, BadMergingTwoObjects) { |
| 828 |
// The second element in the |OpCompositeConstruct| is from a different |
| 829 |
// object. |
| 830 |
const std::string text = |
| 831 |
R"(OpCapability Shader |
| 832 |
OpMemoryModel Logical GLSL450 |
| 833 |
OpEntryPoint Fragment %main "main" |
| 834 |
OpExecutionMode %main OriginUpperLeft |
| 835 |
OpName %type_ConstBuf "type.ConstBuf" |
| 836 |
OpMemberName %type_ConstBuf 0 "TexSizeU" |
| 837 |
OpMemberName %type_ConstBuf 1 "TexSizeV" |
| 838 |
OpName %ConstBuf "ConstBuf" |
| 839 |
OpName %main "main" |
| 840 |
OpMemberDecorate %type_ConstBuf 0 Offset 0 |
| 841 |
OpMemberDecorate %type_ConstBuf 1 Offset 8 |
| 842 |
OpDecorate %type_ConstBuf Block |
| 843 |
OpDecorate %ConstBuf DescriptorSet 0 |
| 844 |
OpDecorate %ConstBuf Binding 2 |
| 845 |
%float = OpTypeFloat 32 |
| 846 |
%v2float = OpTypeVector %float 2 |
| 847 |
%type_ConstBuf = OpTypeStruct %v2float %v2float |
| 848 |
%_ptr_Uniform_type_ConstBuf = OpTypePointer Uniform %type_ConstBuf |
| 849 |
%void = OpTypeVoid |
| 850 |
%9 = OpTypeFunction %void |
| 851 |
%uint = OpTypeInt 32 0 |
| 852 |
%int_0 = OpConstant %uint 0 |
| 853 |
%uint_2 = OpConstant %uint 2 |
| 854 |
%_arr_v2float_uint_2 = OpTypeArray %v2float %uint_2 |
| 855 |
%_ptr_Function__arr_v2float_uint_2 = OpTypePointer Function %_arr_v2float_uint_2 |
| 856 |
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float |
| 857 |
%ConstBuf = OpVariable %_ptr_Uniform_type_ConstBuf Uniform |
| 858 |
%main = OpFunction %void None %9 |
| 859 |
%24 = OpLabel |
| 860 |
%25 = OpVariable %_ptr_Function__arr_v2float_uint_2 Function |
| 861 |
%27 = OpAccessChain %_ptr_Uniform_v2float %ConstBuf %int_0 |
| 862 |
%28 = OpLoad %v2float %27 |
| 863 |
%29 = OpAccessChain %_ptr_Uniform_v2float %ConstBuf %int_0 |
| 864 |
%30 = OpLoad %v2float %29 |
| 865 |
%31 = OpFNegate %v2float %30 |
| 866 |
%37 = OpCompositeConstruct %_arr_v2float_uint_2 %28 %31 |
| 867 |
OpStore %25 %37 |
| 868 |
OpReturn |
| 869 |
OpFunctionEnd |
| 870 |
)"; |
| 871 |
|
| 872 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 873 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 874 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 875 |
} |
| 876 |
|
| 877 |
TEST_F(CopyPropArrayPassTest, SecondElementNotContained) { |
| 878 |
// The second element in the |OpCompositeConstruct| is not a memory object. |
| 879 |
// Make sure no change happends. |
| 880 |
const std::string text = |
| 881 |
R"(OpCapability Shader |
| 882 |
OpMemoryModel Logical GLSL450 |
| 883 |
OpEntryPoint Fragment %main "main" |
| 884 |
OpExecutionMode %main OriginUpperLeft |
| 885 |
OpName %type_ConstBuf "type.ConstBuf" |
| 886 |
OpMemberName %type_ConstBuf 0 "TexSizeU" |
| 887 |
OpMemberName %type_ConstBuf 1 "TexSizeV" |
| 888 |
OpName %ConstBuf "ConstBuf" |
| 889 |
OpName %main "main" |
| 890 |
OpMemberDecorate %type_ConstBuf 0 Offset 0 |
| 891 |
OpMemberDecorate %type_ConstBuf 1 Offset 8 |
| 892 |
OpDecorate %type_ConstBuf Block |
| 893 |
OpDecorate %ConstBuf DescriptorSet 0 |
| 894 |
OpDecorate %ConstBuf Binding 2 |
| 895 |
OpDecorate %ConstBuf2 DescriptorSet 1 |
| 896 |
OpDecorate %ConstBuf2 Binding 2 |
| 897 |
%float = OpTypeFloat 32 |
| 898 |
%v2float = OpTypeVector %float 2 |
| 899 |
%type_ConstBuf = OpTypeStruct %v2float %v2float |
| 900 |
%_ptr_Uniform_type_ConstBuf = OpTypePointer Uniform %type_ConstBuf |
| 901 |
%void = OpTypeVoid |
| 902 |
%9 = OpTypeFunction %void |
| 903 |
%uint = OpTypeInt 32 0 |
| 904 |
%int_0 = OpConstant %uint 0 |
| 905 |
%int_1 = OpConstant %uint 1 |
| 906 |
%uint_2 = OpConstant %uint 2 |
| 907 |
%_arr_v2float_uint_2 = OpTypeArray %v2float %uint_2 |
| 908 |
%_ptr_Function__arr_v2float_uint_2 = OpTypePointer Function %_arr_v2float_uint_2 |
| 909 |
%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float |
| 910 |
%ConstBuf = OpVariable %_ptr_Uniform_type_ConstBuf Uniform |
| 911 |
%ConstBuf2 = OpVariable %_ptr_Uniform_type_ConstBuf Uniform |
| 912 |
%main = OpFunction %void None %9 |
| 913 |
%24 = OpLabel |
| 914 |
%25 = OpVariable %_ptr_Function__arr_v2float_uint_2 Function |
| 915 |
%27 = OpAccessChain %_ptr_Uniform_v2float %ConstBuf %int_0 |
| 916 |
%28 = OpLoad %v2float %27 |
| 917 |
%29 = OpAccessChain %_ptr_Uniform_v2float %ConstBuf2 %int_1 |
| 918 |
%30 = OpLoad %v2float %29 |
| 919 |
%37 = OpCompositeConstruct %_arr_v2float_uint_2 %28 %30 |
| 920 |
OpStore %25 %37 |
| 921 |
OpReturn |
| 922 |
OpFunctionEnd |
| 923 |
)"; |
| 924 |
|
| 925 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 926 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 927 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 928 |
} |
| 929 |
// This test will place a load before the store. We cannot propagate in this |
| 930 |
// case. |
| 931 |
TEST_F(CopyPropArrayPassTest, LoadBeforeStore) { |
| 932 |
const std::string text = |
| 933 |
R"( |
| 934 |
OpCapability Shader |
| 935 |
OpMemoryModel Logical GLSL450 |
| 936 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 937 |
OpExecutionMode %main OriginUpperLeft |
| 938 |
OpSource HLSL 600 |
| 939 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 940 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 941 |
OpName %MyCBuffer "MyCBuffer" |
| 942 |
OpName %main "main" |
| 943 |
OpName %in_var_INDEX "in.var.INDEX" |
| 944 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 945 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 946 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 947 |
OpDecorate %type_MyCBuffer Block |
| 948 |
OpDecorate %in_var_INDEX Flat |
| 949 |
OpDecorate %in_var_INDEX Location 0 |
| 950 |
OpDecorate %out_var_SV_Target Location 0 |
| 951 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 952 |
OpDecorate %MyCBuffer Binding 0 |
| 953 |
%float = OpTypeFloat 32 |
| 954 |
%v4float = OpTypeVector %float 4 |
| 955 |
%uint = OpTypeInt 32 0 |
| 956 |
%uint_8 = OpConstant %uint 8 |
| 957 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 958 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 959 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 960 |
%void = OpTypeVoid |
| 961 |
%13 = OpTypeFunction %void |
| 962 |
%int = OpTypeInt 32 1 |
| 963 |
%_ptr_Input_int = OpTypePointer Input %int |
| 964 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 965 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 966 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 967 |
%int_0 = OpConstant %int 0 |
| 968 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 969 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 970 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 971 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 972 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 973 |
%main = OpFunction %void None %13 |
| 974 |
%22 = OpLabel |
| 975 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 976 |
%38 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 977 |
%39 = OpLoad %v4float %36 |
| 978 |
%24 = OpLoad %int %in_var_INDEX |
| 979 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 980 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 981 |
%27 = OpCompositeExtract %v4float %26 0 |
| 982 |
%28 = OpCompositeExtract %v4float %26 1 |
| 983 |
%29 = OpCompositeExtract %v4float %26 2 |
| 984 |
%30 = OpCompositeExtract %v4float %26 3 |
| 985 |
%31 = OpCompositeExtract %v4float %26 4 |
| 986 |
%32 = OpCompositeExtract %v4float %26 5 |
| 987 |
%33 = OpCompositeExtract %v4float %26 6 |
| 988 |
%34 = OpCompositeExtract %v4float %26 7 |
| 989 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 990 |
OpStore %23 %35 |
| 991 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 992 |
%37 = OpLoad %v4float %36 |
| 993 |
OpStore %out_var_SV_Target %37 |
| 994 |
OpReturn |
| 995 |
OpFunctionEnd |
| 996 |
)"; |
| 997 |
|
| 998 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 999 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1000 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1001 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1002 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1003 |
|
| 1004 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1005 |
} |
| 1006 |
|
| 1007 |
// This test will place a load where it is not dominated by the store. We |
| 1008 |
// cannot propagate in this case. |
| 1009 |
TEST_F(CopyPropArrayPassTest, LoadNotDominated) { |
| 1010 |
const std::string text = |
| 1011 |
R"( |
| 1012 |
OpCapability Shader |
| 1013 |
OpMemoryModel Logical GLSL450 |
| 1014 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1015 |
OpExecutionMode %main OriginUpperLeft |
| 1016 |
OpSource HLSL 600 |
| 1017 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1018 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1019 |
OpName %MyCBuffer "MyCBuffer" |
| 1020 |
OpName %main "main" |
| 1021 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1022 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1023 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1024 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1025 |
OpDecorate %type_MyCBuffer Block |
| 1026 |
OpDecorate %in_var_INDEX Flat |
| 1027 |
OpDecorate %in_var_INDEX Location 0 |
| 1028 |
OpDecorate %out_var_SV_Target Location 0 |
| 1029 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1030 |
OpDecorate %MyCBuffer Binding 0 |
| 1031 |
%bool = OpTypeBool |
| 1032 |
%true = OpConstantTrue %bool |
| 1033 |
%float = OpTypeFloat 32 |
| 1034 |
%v4float = OpTypeVector %float 4 |
| 1035 |
%uint = OpTypeInt 32 0 |
| 1036 |
%uint_8 = OpConstant %uint 8 |
| 1037 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1038 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1039 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1040 |
%void = OpTypeVoid |
| 1041 |
%13 = OpTypeFunction %void |
| 1042 |
%int = OpTypeInt 32 1 |
| 1043 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1044 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1045 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1046 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1047 |
%int_0 = OpConstant %int 0 |
| 1048 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1049 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1050 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1051 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1052 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1053 |
%main = OpFunction %void None %13 |
| 1054 |
%22 = OpLabel |
| 1055 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1056 |
OpSelectionMerge %merge None |
| 1057 |
OpBranchConditional %true %if %else |
| 1058 |
%if = OpLabel |
| 1059 |
%24 = OpLoad %int %in_var_INDEX |
| 1060 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1061 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1062 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1063 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1064 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1065 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1066 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1067 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1068 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1069 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1070 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 1071 |
OpStore %23 %35 |
| 1072 |
%38 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1073 |
%39 = OpLoad %v4float %36 |
| 1074 |
OpBranch %merge |
| 1075 |
%else = OpLabel |
| 1076 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1077 |
%37 = OpLoad %v4float %36 |
| 1078 |
OpBranch %merge |
| 1079 |
%merge = OpLabel |
| 1080 |
%phi = OpPhi %out_var_SV_Target %39 %if %37 %else |
| 1081 |
OpStore %out_var_SV_Target %phi |
| 1082 |
OpReturn |
| 1083 |
OpFunctionEnd |
| 1084 |
)"; |
| 1085 |
|
| 1086 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1087 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1088 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1089 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1090 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1091 |
|
| 1092 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1093 |
} |
| 1094 |
|
| 1095 |
// This test has a partial store to the variable. We cannot propagate in this |
| 1096 |
// case. |
| 1097 |
TEST_F(CopyPropArrayPassTest, PartialStore) { |
| 1098 |
const std::string text = |
| 1099 |
R"( |
| 1100 |
OpCapability Shader |
| 1101 |
OpMemoryModel Logical GLSL450 |
| 1102 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1103 |
OpExecutionMode %main OriginUpperLeft |
| 1104 |
OpSource HLSL 600 |
| 1105 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1106 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1107 |
OpName %MyCBuffer "MyCBuffer" |
| 1108 |
OpName %main "main" |
| 1109 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1110 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1111 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1112 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1113 |
OpDecorate %type_MyCBuffer Block |
| 1114 |
OpDecorate %in_var_INDEX Flat |
| 1115 |
OpDecorate %in_var_INDEX Location 0 |
| 1116 |
OpDecorate %out_var_SV_Target Location 0 |
| 1117 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1118 |
OpDecorate %MyCBuffer Binding 0 |
| 1119 |
%float = OpTypeFloat 32 |
| 1120 |
%v4float = OpTypeVector %float 4 |
| 1121 |
%uint = OpTypeInt 32 0 |
| 1122 |
%uint_8 = OpConstant %uint 8 |
| 1123 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1124 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1125 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1126 |
%void = OpTypeVoid |
| 1127 |
%13 = OpTypeFunction %void |
| 1128 |
%int = OpTypeInt 32 1 |
| 1129 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1130 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1131 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1132 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1133 |
%int_0 = OpConstant %int 0 |
| 1134 |
%f0 = OpConstant %float 0 |
| 1135 |
%v4const = OpConstantComposite %v4float %f0 %f0 %f0 %f0 |
| 1136 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1137 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1138 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1139 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1140 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1141 |
%main = OpFunction %void None %13 |
| 1142 |
%22 = OpLabel |
| 1143 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1144 |
%24 = OpLoad %int %in_var_INDEX |
| 1145 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1146 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1147 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1148 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1149 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1150 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1151 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1152 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1153 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1154 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1155 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 1156 |
OpStore %23 %35 |
| 1157 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1158 |
%37 = OpLoad %v4float %36 |
| 1159 |
OpStore %36 %v4const |
| 1160 |
OpStore %out_var_SV_Target %37 |
| 1161 |
OpReturn |
| 1162 |
OpFunctionEnd |
| 1163 |
)"; |
| 1164 |
|
| 1165 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1166 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1167 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1168 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1169 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1170 |
|
| 1171 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1172 |
} |
| 1173 |
|
| 1174 |
// This test does not have a proper copy of an object. We cannot propagate in |
| 1175 |
// this case. |
| 1176 |
TEST_F(CopyPropArrayPassTest, NotACopy) { |
| 1177 |
const std::string text = |
| 1178 |
R"( |
| 1179 |
OpCapability Shader |
| 1180 |
OpMemoryModel Logical GLSL450 |
| 1181 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1182 |
OpExecutionMode %main OriginUpperLeft |
| 1183 |
OpSource HLSL 600 |
| 1184 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1185 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1186 |
OpName %MyCBuffer "MyCBuffer" |
| 1187 |
OpName %main "main" |
| 1188 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1189 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1190 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1191 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1192 |
OpDecorate %type_MyCBuffer Block |
| 1193 |
OpDecorate %in_var_INDEX Flat |
| 1194 |
OpDecorate %in_var_INDEX Location 0 |
| 1195 |
OpDecorate %out_var_SV_Target Location 0 |
| 1196 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1197 |
OpDecorate %MyCBuffer Binding 0 |
| 1198 |
%float = OpTypeFloat 32 |
| 1199 |
%v4float = OpTypeVector %float 4 |
| 1200 |
%uint = OpTypeInt 32 0 |
| 1201 |
%uint_8 = OpConstant %uint 8 |
| 1202 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1203 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1204 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1205 |
%void = OpTypeVoid |
| 1206 |
%13 = OpTypeFunction %void |
| 1207 |
%int = OpTypeInt 32 1 |
| 1208 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1209 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1210 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1211 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1212 |
%int_0 = OpConstant %int 0 |
| 1213 |
%f0 = OpConstant %float 0 |
| 1214 |
%v4const = OpConstantComposite %v4float %f0 %f0 %f0 %f0 |
| 1215 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1216 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1217 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1218 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1219 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1220 |
%main = OpFunction %void None %13 |
| 1221 |
%22 = OpLabel |
| 1222 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1223 |
%24 = OpLoad %int %in_var_INDEX |
| 1224 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1225 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1226 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1227 |
%28 = OpCompositeExtract %v4float %26 0 |
| 1228 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1229 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1230 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1231 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1232 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1233 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1234 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 1235 |
OpStore %23 %35 |
| 1236 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1237 |
%37 = OpLoad %v4float %36 |
| 1238 |
OpStore %out_var_SV_Target %37 |
| 1239 |
OpReturn |
| 1240 |
OpFunctionEnd |
| 1241 |
)"; |
| 1242 |
|
| 1243 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1244 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1245 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1246 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1247 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1248 |
|
| 1249 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1250 |
} |
| 1251 |
|
| 1252 |
TEST_F(CopyPropArrayPassTest, BadCopyViaInserts1) { |
| 1253 |
const std::string text = |
| 1254 |
R"( |
| 1255 |
OpCapability Shader |
| 1256 |
OpMemoryModel Logical GLSL450 |
| 1257 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1258 |
OpExecutionMode %main OriginUpperLeft |
| 1259 |
OpSource HLSL 600 |
| 1260 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1261 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1262 |
OpName %MyCBuffer "MyCBuffer" |
| 1263 |
OpName %main "main" |
| 1264 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1265 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1266 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1267 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1268 |
OpDecorate %type_MyCBuffer Block |
| 1269 |
OpDecorate %in_var_INDEX Flat |
| 1270 |
OpDecorate %in_var_INDEX Location 0 |
| 1271 |
OpDecorate %out_var_SV_Target Location 0 |
| 1272 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1273 |
OpDecorate %MyCBuffer Binding 0 |
| 1274 |
%float = OpTypeFloat 32 |
| 1275 |
%v4float = OpTypeVector %float 4 |
| 1276 |
%uint = OpTypeInt 32 0 |
| 1277 |
%uint_8 = OpConstant %uint 8 |
| 1278 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1279 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1280 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1281 |
%void = OpTypeVoid |
| 1282 |
%13 = OpTypeFunction %void |
| 1283 |
%int = OpTypeInt 32 1 |
| 1284 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1285 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1286 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1287 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1288 |
%int_0 = OpConstant %int 0 |
| 1289 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1290 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1291 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1292 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1293 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1294 |
%main = OpFunction %void None %13 |
| 1295 |
%22 = OpLabel |
| 1296 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1297 |
%undef = OpUndef %_arr_v4float_uint_8_0 |
| 1298 |
%24 = OpLoad %int %in_var_INDEX |
| 1299 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1300 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1301 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1302 |
%i0 = OpCompositeInsert %_arr_v4float_uint_8_0 %27 %undef 0 |
| 1303 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1304 |
%i1 = OpCompositeInsert %_arr_v4float_uint_8_0 %28 %i0 1 |
| 1305 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1306 |
%i2 = OpCompositeInsert %_arr_v4float_uint_8_0 %29 %i1 3 |
| 1307 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1308 |
%i3 = OpCompositeInsert %_arr_v4float_uint_8_0 %30 %i2 3 |
| 1309 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1310 |
%i4 = OpCompositeInsert %_arr_v4float_uint_8_0 %31 %i3 4 |
| 1311 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1312 |
%i5 = OpCompositeInsert %_arr_v4float_uint_8_0 %32 %i4 5 |
| 1313 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1314 |
%i6 = OpCompositeInsert %_arr_v4float_uint_8_0 %33 %i5 6 |
| 1315 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1316 |
%i7 = OpCompositeInsert %_arr_v4float_uint_8_0 %34 %i6 7 |
| 1317 |
OpStore %23 %i7 |
| 1318 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1319 |
%37 = OpLoad %v4float %36 |
| 1320 |
OpStore %out_var_SV_Target %37 |
| 1321 |
OpReturn |
| 1322 |
OpFunctionEnd |
| 1323 |
)"; |
| 1324 |
|
| 1325 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1326 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1327 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1328 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1329 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1330 |
|
| 1331 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1332 |
} |
| 1333 |
|
| 1334 |
TEST_F(CopyPropArrayPassTest, BadCopyViaInserts2) { |
| 1335 |
const std::string text = |
| 1336 |
R"( |
| 1337 |
OpCapability Shader |
| 1338 |
OpMemoryModel Logical GLSL450 |
| 1339 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1340 |
OpExecutionMode %main OriginUpperLeft |
| 1341 |
OpSource HLSL 600 |
| 1342 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1343 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1344 |
OpName %MyCBuffer "MyCBuffer" |
| 1345 |
OpName %main "main" |
| 1346 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1347 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1348 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1349 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1350 |
OpDecorate %type_MyCBuffer Block |
| 1351 |
OpDecorate %in_var_INDEX Flat |
| 1352 |
OpDecorate %in_var_INDEX Location 0 |
| 1353 |
OpDecorate %out_var_SV_Target Location 0 |
| 1354 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1355 |
OpDecorate %MyCBuffer Binding 0 |
| 1356 |
%float = OpTypeFloat 32 |
| 1357 |
%v4float = OpTypeVector %float 4 |
| 1358 |
%uint = OpTypeInt 32 0 |
| 1359 |
%uint_8 = OpConstant %uint 8 |
| 1360 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1361 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1362 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1363 |
%void = OpTypeVoid |
| 1364 |
%13 = OpTypeFunction %void |
| 1365 |
%int = OpTypeInt 32 1 |
| 1366 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1367 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1368 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1369 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1370 |
%int_0 = OpConstant %int 0 |
| 1371 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1372 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1373 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1374 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1375 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1376 |
%main = OpFunction %void None %13 |
| 1377 |
%22 = OpLabel |
| 1378 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1379 |
%undef = OpUndef %_arr_v4float_uint_8_0 |
| 1380 |
%24 = OpLoad %int %in_var_INDEX |
| 1381 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1382 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1383 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1384 |
%i0 = OpCompositeInsert %_arr_v4float_uint_8_0 %27 %undef 0 |
| 1385 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1386 |
%i1 = OpCompositeInsert %_arr_v4float_uint_8_0 %28 %i0 1 |
| 1387 |
%29 = OpCompositeExtract %v4float %26 3 |
| 1388 |
%i2 = OpCompositeInsert %_arr_v4float_uint_8_0 %29 %i1 2 |
| 1389 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1390 |
%i3 = OpCompositeInsert %_arr_v4float_uint_8_0 %30 %i2 3 |
| 1391 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1392 |
%i4 = OpCompositeInsert %_arr_v4float_uint_8_0 %31 %i3 4 |
| 1393 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1394 |
%i5 = OpCompositeInsert %_arr_v4float_uint_8_0 %32 %i4 5 |
| 1395 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1396 |
%i6 = OpCompositeInsert %_arr_v4float_uint_8_0 %33 %i5 6 |
| 1397 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1398 |
%i7 = OpCompositeInsert %_arr_v4float_uint_8_0 %34 %i6 7 |
| 1399 |
OpStore %23 %i7 |
| 1400 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1401 |
%37 = OpLoad %v4float %36 |
| 1402 |
OpStore %out_var_SV_Target %37 |
| 1403 |
OpReturn |
| 1404 |
OpFunctionEnd |
| 1405 |
)"; |
| 1406 |
|
| 1407 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1408 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1409 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1410 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1411 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1412 |
|
| 1413 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1414 |
} |
| 1415 |
|
| 1416 |
TEST_F(CopyPropArrayPassTest, BadCopyViaInserts3) { |
| 1417 |
const std::string text = |
| 1418 |
R"( |
| 1419 |
OpCapability Shader |
| 1420 |
OpMemoryModel Logical GLSL450 |
| 1421 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1422 |
OpExecutionMode %main OriginUpperLeft |
| 1423 |
OpSource HLSL 600 |
| 1424 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1425 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1426 |
OpName %MyCBuffer "MyCBuffer" |
| 1427 |
OpName %main "main" |
| 1428 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1429 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1430 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1431 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1432 |
OpDecorate %type_MyCBuffer Block |
| 1433 |
OpDecorate %in_var_INDEX Flat |
| 1434 |
OpDecorate %in_var_INDEX Location 0 |
| 1435 |
OpDecorate %out_var_SV_Target Location 0 |
| 1436 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1437 |
OpDecorate %MyCBuffer Binding 0 |
| 1438 |
%float = OpTypeFloat 32 |
| 1439 |
%v4float = OpTypeVector %float 4 |
| 1440 |
%uint = OpTypeInt 32 0 |
| 1441 |
%uint_8 = OpConstant %uint 8 |
| 1442 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1443 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1444 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1445 |
%void = OpTypeVoid |
| 1446 |
%13 = OpTypeFunction %void |
| 1447 |
%int = OpTypeInt 32 1 |
| 1448 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1449 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1450 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1451 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1452 |
%int_0 = OpConstant %int 0 |
| 1453 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1454 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1455 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1456 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1457 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1458 |
%main = OpFunction %void None %13 |
| 1459 |
%22 = OpLabel |
| 1460 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1461 |
%undef = OpUndef %_arr_v4float_uint_8_0 |
| 1462 |
%24 = OpLoad %int %in_var_INDEX |
| 1463 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1464 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1465 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1466 |
%i1 = OpCompositeInsert %_arr_v4float_uint_8_0 %28 %undef 1 |
| 1467 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1468 |
%i2 = OpCompositeInsert %_arr_v4float_uint_8_0 %29 %i1 2 |
| 1469 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1470 |
%i3 = OpCompositeInsert %_arr_v4float_uint_8_0 %30 %i2 3 |
| 1471 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1472 |
%i4 = OpCompositeInsert %_arr_v4float_uint_8_0 %31 %i3 4 |
| 1473 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1474 |
%i5 = OpCompositeInsert %_arr_v4float_uint_8_0 %32 %i4 5 |
| 1475 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1476 |
%i6 = OpCompositeInsert %_arr_v4float_uint_8_0 %33 %i5 6 |
| 1477 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1478 |
%i7 = OpCompositeInsert %_arr_v4float_uint_8_0 %34 %i6 7 |
| 1479 |
OpStore %23 %i7 |
| 1480 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1481 |
%37 = OpLoad %v4float %36 |
| 1482 |
OpStore %out_var_SV_Target %37 |
| 1483 |
OpReturn |
| 1484 |
OpFunctionEnd |
| 1485 |
)"; |
| 1486 |
|
| 1487 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1488 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1489 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1490 |
auto result = SinglePassRunAndDisassemble<CopyPropagateArrays>( |
| 1491 |
text, /* skip_nop = */ true, /* do_validation = */ false); |
| 1492 |
|
| 1493 |
EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result)); |
| 1494 |
} |
| 1495 |
|
| 1496 |
TEST_F(CopyPropArrayPassTest, AtomicAdd) { |
| 1497 |
const std::string before = R"(OpCapability SampledBuffer |
| 1498 |
OpCapability StorageImageExtendedFormats |
| 1499 |
OpCapability ImageBuffer |
| 1500 |
OpCapability Shader |
| 1501 |
%1 = OpExtInstImport "GLSL.std.450" |
| 1502 |
OpMemoryModel Logical GLSL450 |
| 1503 |
OpEntryPoint GLCompute %2 "min" %gl_GlobalInvocationID |
| 1504 |
OpExecutionMode %2 LocalSize 64 1 1 |
| 1505 |
OpSource HLSL 600 |
| 1506 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 1507 |
OpDecorate %4 DescriptorSet 4 |
| 1508 |
OpDecorate %4 Binding 70 |
| 1509 |
%uint = OpTypeInt 32 0 |
| 1510 |
%6 = OpTypeImage %uint Buffer 0 0 0 2 R32ui |
| 1511 |
%_ptr_UniformConstant_6 = OpTypePointer UniformConstant %6 |
| 1512 |
%_ptr_Function_6 = OpTypePointer Function %6 |
| 1513 |
%void = OpTypeVoid |
| 1514 |
%10 = OpTypeFunction %void |
| 1515 |
%uint_0 = OpConstant %uint 0 |
| 1516 |
%uint_1 = OpConstant %uint 1 |
| 1517 |
%v3uint = OpTypeVector %uint 3 |
| 1518 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 1519 |
%_ptr_Image_uint = OpTypePointer Image %uint |
| 1520 |
%4 = OpVariable %_ptr_UniformConstant_6 UniformConstant |
| 1521 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 1522 |
%2 = OpFunction %void None %10 |
| 1523 |
%17 = OpLabel |
| 1524 |
%16 = OpVariable %_ptr_Function_6 Function |
| 1525 |
%18 = OpLoad %6 %4 |
| 1526 |
OpStore %16 %18 |
| 1527 |
%19 = OpImageTexelPointer %_ptr_Image_uint %16 %uint_0 %uint_0 |
| 1528 |
%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1 |
| 1529 |
OpReturn |
| 1530 |
OpFunctionEnd |
| 1531 |
)"; |
| 1532 |
|
| 1533 |
const std::string after = R"(OpCapability SampledBuffer |
| 1534 |
OpCapability StorageImageExtendedFormats |
| 1535 |
OpCapability ImageBuffer |
| 1536 |
OpCapability Shader |
| 1537 |
%1 = OpExtInstImport "GLSL.std.450" |
| 1538 |
OpMemoryModel Logical GLSL450 |
| 1539 |
OpEntryPoint GLCompute %2 "min" %gl_GlobalInvocationID |
| 1540 |
OpExecutionMode %2 LocalSize 64 1 1 |
| 1541 |
OpSource HLSL 600 |
| 1542 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 1543 |
OpDecorate %4 DescriptorSet 4 |
| 1544 |
OpDecorate %4 Binding 70 |
| 1545 |
%uint = OpTypeInt 32 0 |
| 1546 |
%6 = OpTypeImage %uint Buffer 0 0 0 2 R32ui |
| 1547 |
%_ptr_UniformConstant_6 = OpTypePointer UniformConstant %6 |
| 1548 |
%_ptr_Function_6 = OpTypePointer Function %6 |
| 1549 |
%void = OpTypeVoid |
| 1550 |
%10 = OpTypeFunction %void |
| 1551 |
%uint_0 = OpConstant %uint 0 |
| 1552 |
%uint_1 = OpConstant %uint 1 |
| 1553 |
%v3uint = OpTypeVector %uint 3 |
| 1554 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 1555 |
%_ptr_Image_uint = OpTypePointer Image %uint |
| 1556 |
%4 = OpVariable %_ptr_UniformConstant_6 UniformConstant |
| 1557 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 1558 |
%2 = OpFunction %void None %10 |
| 1559 |
%17 = OpLabel |
| 1560 |
%16 = OpVariable %_ptr_Function_6 Function |
| 1561 |
%18 = OpLoad %6 %4 |
| 1562 |
OpStore %16 %18 |
| 1563 |
%19 = OpImageTexelPointer %_ptr_Image_uint %4 %uint_0 %uint_0 |
| 1564 |
%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1 |
| 1565 |
OpReturn |
| 1566 |
OpFunctionEnd |
| 1567 |
)"; |
| 1568 |
|
| 1569 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1570 |
SinglePassRunAndCheck<CopyPropagateArrays>(before, after, true, true); |
| 1571 |
} |
| 1572 |
|
| 1573 |
TEST_F(CopyPropArrayPassTest, IndexIsNullConstnat) { |
| 1574 |
const std::string text = R"( |
| 1575 |
; CHECK: [[var:%\w+]] = OpVariable {{%\w+}} Uniform |
| 1576 |
; CHECK: [[null:%\w+]] = OpConstantNull %uint |
| 1577 |
; CHECK: [[ac1:%\w+]] = OpAccessChain %_ptr_Uniform__arr_uint_uint_1 [[var]] %uint_0 %uint_0 |
| 1578 |
; CHECK: OpAccessChain %_ptr_Uniform_uint [[ac1]] [[null]] |
| 1579 |
; CHECK-NEXT: OpReturn |
| 1580 |
OpCapability Shader |
| 1581 |
OpMemoryModel Logical GLSL450 |
| 1582 |
OpEntryPoint Fragment %main "main" |
| 1583 |
OpExecutionMode %main OriginUpperLeft |
| 1584 |
OpSource HLSL 600 |
| 1585 |
OpDecorate %myCBuffer DescriptorSet 0 |
| 1586 |
OpDecorate %myCBuffer Binding 0 |
| 1587 |
OpDecorate %_arr_v4float_uint_1 ArrayStride 16 |
| 1588 |
OpMemberDecorate %MyConstantBuffer 0 Offset 0 |
| 1589 |
OpMemberDecorate %type_myCBuffer 0 Offset 0 |
| 1590 |
OpDecorate %type_myCBuffer Block |
| 1591 |
%uint = OpTypeInt 32 0 |
| 1592 |
%int_0 = OpConstant %uint 0 |
| 1593 |
%uint_1 = OpConstant %uint 1 |
| 1594 |
%_arr_v4float_uint_1 = OpTypeArray %uint %uint_1 |
| 1595 |
%MyConstantBuffer = OpTypeStruct %_arr_v4float_uint_1 |
| 1596 |
%type_myCBuffer = OpTypeStruct %MyConstantBuffer |
| 1597 |
%_ptr_Uniform_type_myCBuffer = OpTypePointer Uniform %type_myCBuffer |
| 1598 |
%_arr_v4float_uint_1_0 = OpTypeArray %uint %uint_1 |
| 1599 |
%void = OpTypeVoid |
| 1600 |
%19 = OpTypeFunction %void |
| 1601 |
%_ptr_Function_v4float = OpTypePointer Function %uint |
| 1602 |
%_ptr_Uniform_MyConstantBuffer = OpTypePointer Uniform %MyConstantBuffer |
| 1603 |
%myCBuffer = OpVariable %_ptr_Uniform_type_myCBuffer Uniform |
| 1604 |
%_ptr_Function__arr_v4float_uint_1_0 = OpTypePointer Function %_arr_v4float_uint_1_0 |
| 1605 |
%23 = OpConstantNull %uint |
| 1606 |
%main = OpFunction %void None %19 |
| 1607 |
%24 = OpLabel |
| 1608 |
%25 = OpVariable %_ptr_Function__arr_v4float_uint_1_0 Function |
| 1609 |
%26 = OpAccessChain %_ptr_Uniform_MyConstantBuffer %myCBuffer %int_0 |
| 1610 |
%27 = OpLoad %MyConstantBuffer %26 |
| 1611 |
%28 = OpCompositeExtract %_arr_v4float_uint_1 %27 0 |
| 1612 |
%29 = OpCompositeExtract %uint %28 0 |
| 1613 |
%30 = OpCompositeConstruct %_arr_v4float_uint_1_0 %29 |
| 1614 |
OpStore %25 %30 |
| 1615 |
%31 = OpAccessChain %_ptr_Function_v4float %25 %23 |
| 1616 |
OpReturn |
| 1617 |
OpFunctionEnd |
| 1618 |
)"; |
| 1619 |
|
| 1620 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1621 |
SinglePassRunAndMatch<CopyPropagateArrays>(text, true); |
| 1622 |
} |
| 1623 |
|
| 1624 |
TEST_F(CopyPropArrayPassTest, DebugDeclare) { |
| 1625 |
const std::string before = |
| 1626 |
R"(OpCapability Shader |
| 1627 |
%ext = OpExtInstImport "OpenCL.DebugInfo.100" |
| 1628 |
OpMemoryModel Logical GLSL450 |
| 1629 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1630 |
OpExecutionMode %main OriginUpperLeft |
| 1631 |
OpSource HLSL 600 |
| 1632 |
%file_name = OpString "test" |
| 1633 |
%float_name = OpString "float" |
| 1634 |
%main_name = OpString "main" |
| 1635 |
%f_name = OpString "f" |
| 1636 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1637 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1638 |
OpName %MyCBuffer "MyCBuffer" |
| 1639 |
OpName %main "main" |
| 1640 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1641 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1642 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1643 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1644 |
OpDecorate %type_MyCBuffer Block |
| 1645 |
OpDecorate %in_var_INDEX Flat |
| 1646 |
OpDecorate %in_var_INDEX Location 0 |
| 1647 |
OpDecorate %out_var_SV_Target Location 0 |
| 1648 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1649 |
OpDecorate %MyCBuffer Binding 0 |
| 1650 |
%float = OpTypeFloat 32 |
| 1651 |
%v4float = OpTypeVector %float 4 |
| 1652 |
%uint = OpTypeInt 32 0 |
| 1653 |
%uint_8 = OpConstant %uint 8 |
| 1654 |
%uint_32 = OpConstant %uint 32 |
| 1655 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1656 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1657 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1658 |
%void = OpTypeVoid |
| 1659 |
%13 = OpTypeFunction %void |
| 1660 |
%int = OpTypeInt 32 1 |
| 1661 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1662 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1663 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1664 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1665 |
%int_0 = OpConstant %int 0 |
| 1666 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1667 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1668 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1669 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1670 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1671 |
%null_expr = OpExtInst %void %ext DebugExpression |
| 1672 |
%src = OpExtInst %void %ext DebugSource %file_name |
| 1673 |
%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL |
| 1674 |
%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float |
| 1675 |
%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_tf |
| 1676 |
%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main |
| 1677 |
|
| 1678 |
; CHECK: [[deref:%\w+]] = OpExtInst %void [[ext:%\w+]] DebugOperation Deref |
| 1679 |
; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable |
| 1680 |
%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal |
| 1681 |
|
| 1682 |
; CHECK: [[deref_expr:%\w+]] = OpExtInst %void [[ext]] DebugExpression [[deref]] |
| 1683 |
; CHECK: OpAccessChain |
| 1684 |
; CHECK: [[newptr:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1685 |
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[newptr]] [[deref_expr]] |
| 1686 |
; CHECK: [[element_ptr:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[newptr]] %24 |
| 1687 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[element_ptr]] |
| 1688 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 1689 |
%main = OpFunction %void None %13 |
| 1690 |
%22 = OpLabel |
| 1691 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1692 |
%24 = OpLoad %int %in_var_INDEX |
| 1693 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1694 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1695 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1696 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1697 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1698 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1699 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1700 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1701 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1702 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1703 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 1704 |
OpStore %23 %35 |
| 1705 |
%decl = OpExtInst %void %ext DebugDeclare %dbg_f %23 %null_expr |
| 1706 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1707 |
%37 = OpLoad %v4float %36 |
| 1708 |
OpStore %out_var_SV_Target %37 |
| 1709 |
OpReturn |
| 1710 |
OpFunctionEnd |
| 1711 |
)"; |
| 1712 |
|
| 1713 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1714 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1715 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1716 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 1717 |
} |
| 1718 |
|
| 1719 |
TEST_F(CopyPropArrayPassTest, DebugValue) { |
| 1720 |
const std::string before = |
| 1721 |
R"(OpCapability Shader |
| 1722 |
%ext = OpExtInstImport "OpenCL.DebugInfo.100" |
| 1723 |
OpMemoryModel Logical GLSL450 |
| 1724 |
OpEntryPoint Fragment %main "main" %in_var_INDEX %out_var_SV_Target |
| 1725 |
OpExecutionMode %main OriginUpperLeft |
| 1726 |
OpSource HLSL 600 |
| 1727 |
%file_name = OpString "test" |
| 1728 |
%float_name = OpString "float" |
| 1729 |
%main_name = OpString "main" |
| 1730 |
%f_name = OpString "f" |
| 1731 |
OpName %type_MyCBuffer "type.MyCBuffer" |
| 1732 |
OpMemberName %type_MyCBuffer 0 "Data" |
| 1733 |
OpName %MyCBuffer "MyCBuffer" |
| 1734 |
OpName %main "main" |
| 1735 |
OpName %in_var_INDEX "in.var.INDEX" |
| 1736 |
OpName %out_var_SV_Target "out.var.SV_Target" |
| 1737 |
OpDecorate %_arr_v4float_uint_8 ArrayStride 16 |
| 1738 |
OpMemberDecorate %type_MyCBuffer 0 Offset 0 |
| 1739 |
OpDecorate %type_MyCBuffer Block |
| 1740 |
OpDecorate %in_var_INDEX Flat |
| 1741 |
OpDecorate %in_var_INDEX Location 0 |
| 1742 |
OpDecorate %out_var_SV_Target Location 0 |
| 1743 |
OpDecorate %MyCBuffer DescriptorSet 0 |
| 1744 |
OpDecorate %MyCBuffer Binding 0 |
| 1745 |
%float = OpTypeFloat 32 |
| 1746 |
%v4float = OpTypeVector %float 4 |
| 1747 |
%uint = OpTypeInt 32 0 |
| 1748 |
%uint_8 = OpConstant %uint 8 |
| 1749 |
%uint_32 = OpConstant %uint 32 |
| 1750 |
%_arr_v4float_uint_8 = OpTypeArray %v4float %uint_8 |
| 1751 |
%type_MyCBuffer = OpTypeStruct %_arr_v4float_uint_8 |
| 1752 |
%_ptr_Uniform_type_MyCBuffer = OpTypePointer Uniform %type_MyCBuffer |
| 1753 |
%void = OpTypeVoid |
| 1754 |
%13 = OpTypeFunction %void |
| 1755 |
%int = OpTypeInt 32 1 |
| 1756 |
%_ptr_Input_int = OpTypePointer Input %int |
| 1757 |
%_ptr_Output_v4float = OpTypePointer Output %v4float |
| 1758 |
%_arr_v4float_uint_8_0 = OpTypeArray %v4float %uint_8 |
| 1759 |
%_ptr_Function__arr_v4float_uint_8_0 = OpTypePointer Function %_arr_v4float_uint_8_0 |
| 1760 |
%int_0 = OpConstant %int 0 |
| 1761 |
%_ptr_Uniform__arr_v4float_uint_8 = OpTypePointer Uniform %_arr_v4float_uint_8 |
| 1762 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1763 |
%MyCBuffer = OpVariable %_ptr_Uniform_type_MyCBuffer Uniform |
| 1764 |
%in_var_INDEX = OpVariable %_ptr_Input_int Input |
| 1765 |
%out_var_SV_Target = OpVariable %_ptr_Output_v4float Output |
| 1766 |
|
| 1767 |
; CHECK: [[deref:%\w+]] = OpExtInst %void [[ext:%\w+]] DebugOperation Deref |
| 1768 |
; CHECK: [[deref_expr:%\w+]] = OpExtInst %void [[ext]] DebugExpression [[deref]] |
| 1769 |
%deref = OpExtInst %void %ext DebugOperation Deref |
| 1770 |
%expr = OpExtInst %void %ext DebugExpression %deref |
| 1771 |
%src = OpExtInst %void %ext DebugSource %file_name |
| 1772 |
%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL |
| 1773 |
%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float |
| 1774 |
%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_tf |
| 1775 |
%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main |
| 1776 |
|
| 1777 |
; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable |
| 1778 |
%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal |
| 1779 |
%main = OpFunction %void None %13 |
| 1780 |
%22 = OpLabel |
| 1781 |
%23 = OpVariable %_ptr_Function__arr_v4float_uint_8_0 Function |
| 1782 |
%24 = OpLoad %int %in_var_INDEX |
| 1783 |
%25 = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1784 |
%26 = OpLoad %_arr_v4float_uint_8 %25 |
| 1785 |
%27 = OpCompositeExtract %v4float %26 0 |
| 1786 |
%28 = OpCompositeExtract %v4float %26 1 |
| 1787 |
%29 = OpCompositeExtract %v4float %26 2 |
| 1788 |
%30 = OpCompositeExtract %v4float %26 3 |
| 1789 |
%31 = OpCompositeExtract %v4float %26 4 |
| 1790 |
%32 = OpCompositeExtract %v4float %26 5 |
| 1791 |
%33 = OpCompositeExtract %v4float %26 6 |
| 1792 |
%34 = OpCompositeExtract %v4float %26 7 |
| 1793 |
%35 = OpCompositeConstruct %_arr_v4float_uint_8_0 %27 %28 %29 %30 %31 %32 %33 %34 |
| 1794 |
OpStore %23 %35 |
| 1795 |
|
| 1796 |
; CHECK: OpAccessChain |
| 1797 |
; CHECK: [[newptr:%\w+]] = OpAccessChain %_ptr_Uniform__arr_v4float_uint_8 %MyCBuffer %int_0 |
| 1798 |
; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[newptr]] [[deref_expr]] |
| 1799 |
; CHECK: [[element_ptr:%\w+]] = OpAccessChain %_ptr_Uniform_v4float [[newptr]] %24 |
| 1800 |
; CHECK: [[load:%\w+]] = OpLoad %v4float [[element_ptr]] |
| 1801 |
; CHECK: OpStore %out_var_SV_Target [[load]] |
| 1802 |
%decl = OpExtInst %void %ext DebugValue %dbg_f %23 %expr |
| 1803 |
%36 = OpAccessChain %_ptr_Function_v4float %23 %24 |
| 1804 |
%37 = OpLoad %v4float %36 |
| 1805 |
OpStore %out_var_SV_Target %37 |
| 1806 |
OpReturn |
| 1807 |
OpFunctionEnd |
| 1808 |
)"; |
| 1809 |
|
| 1810 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1811 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 1812 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 1813 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 1814 |
} |
| 1815 |
|
| 1816 |
TEST_F(CopyPropArrayPassTest, FunctionDeclaration) { |
| 1817 |
// Make sure the pass works with a function declaration that is called. |
| 1818 |
const std::string text = R"(OpCapability Addresses |
| 1819 |
OpCapability Linkage |
| 1820 |
OpCapability Kernel |
| 1821 |
OpCapability Int8 |
| 1822 |
%1 = OpExtInstImport "OpenCL.std" |
| 1823 |
OpMemoryModel Physical64 OpenCL |
| 1824 |
OpEntryPoint Kernel %2 "_Z23julia__1166_kernel_77094Bool" |
| 1825 |
OpExecutionMode %2 ContractionOff |
| 1826 |
OpSource Unknown 0 |
| 1827 |
OpDecorate %3 LinkageAttributes "julia_error_7712" Import |
| 1828 |
%void = OpTypeVoid |
| 1829 |
%5 = OpTypeFunction %void |
| 1830 |
%3 = OpFunction %void None %5 |
| 1831 |
OpFunctionEnd |
| 1832 |
%2 = OpFunction %void None %5 |
| 1833 |
%6 = OpLabel |
| 1834 |
%7 = OpFunctionCall %void %3 |
| 1835 |
OpReturn |
| 1836 |
OpFunctionEnd |
| 1837 |
)"; |
| 1838 |
|
| 1839 |
SinglePassRunAndCheck<CopyPropagateArrays>(text, text, false); |
| 1840 |
} |
| 1841 |
|
| 1842 |
// Since Spir-V 1.4, resources that are used by a shader must be on the |
| 1843 |
// OpEntryPoint instruction with the inputs and outputs. This test ensures that |
| 1844 |
// this does not stop the pass from working. |
| 1845 |
TEST_F(CopyPropArrayPassTest, EntryPointUser) { |
| 1846 |
const std::string before = R"(OpCapability Shader |
| 1847 |
OpMemoryModel Logical GLSL450 |
| 1848 |
OpEntryPoint GLCompute %main "main" %g_rwTexture3d |
| 1849 |
OpExecutionMode %main LocalSize 256 1 1 |
| 1850 |
OpSource HLSL 660 |
| 1851 |
OpName %type_3d_image "type.3d.image" |
| 1852 |
OpName %g_rwTexture3d "g_rwTexture3d" |
| 1853 |
OpName %main "main" |
| 1854 |
OpDecorate %g_rwTexture3d DescriptorSet 0 |
| 1855 |
OpDecorate %g_rwTexture3d Binding 0 |
| 1856 |
%uint = OpTypeInt 32 0 |
| 1857 |
%uint_0 = OpConstant %uint 0 |
| 1858 |
%uint_1 = OpConstant %uint 1 |
| 1859 |
%uint_2 = OpConstant %uint 2 |
| 1860 |
%uint_3 = OpConstant %uint 3 |
| 1861 |
%v3uint = OpTypeVector %uint 3 |
| 1862 |
%10 = OpConstantComposite %v3uint %uint_1 %uint_2 %uint_3 |
| 1863 |
%type_3d_image = OpTypeImage %uint 3D 2 0 0 2 R32ui |
| 1864 |
%_ptr_UniformConstant_type_3d_image = OpTypePointer UniformConstant %type_3d_image |
| 1865 |
%void = OpTypeVoid |
| 1866 |
%13 = OpTypeFunction %void |
| 1867 |
%_ptr_Function_type_3d_image = OpTypePointer Function %type_3d_image |
| 1868 |
%_ptr_Image_uint = OpTypePointer Image %uint |
| 1869 |
%g_rwTexture3d = OpVariable %_ptr_UniformConstant_type_3d_image UniformConstant |
| 1870 |
%main = OpFunction %void None %13 |
| 1871 |
%16 = OpLabel |
| 1872 |
%17 = OpVariable %_ptr_Function_type_3d_image Function |
| 1873 |
%18 = OpLoad %type_3d_image %g_rwTexture3d |
| 1874 |
OpStore %17 %18 |
| 1875 |
; CHECK: %19 = OpImageTexelPointer %_ptr_Image_uint %g_rwTexture3d %10 %uint_0 |
| 1876 |
%19 = OpImageTexelPointer %_ptr_Image_uint %17 %10 %uint_0 |
| 1877 |
%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1 |
| 1878 |
OpReturn |
| 1879 |
OpFunctionEnd |
| 1880 |
)"; |
| 1881 |
|
| 1882 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 1883 |
SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); |
| 1884 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 1885 |
} |
| 1886 |
|
| 1887 |
// As per SPIRV spec, struct cannot be indexed with non-constant indices |
| 1888 |
// through OpAccessChain, only arrays. |
| 1889 |
// The copy-propagate-array pass tries to remove superfluous copies when the |
| 1890 |
// original array could be indexed instead of the copy. |
| 1891 |
// |
| 1892 |
// This test verifies we handle this case: |
| 1893 |
// struct SRC { int field1; ...; int fieldN } |
| 1894 |
// int tmp_arr[N] = { SRC.field1, ..., SRC.fieldN } |
| 1895 |
// return tmp_arr[index]; |
| 1896 |
// |
| 1897 |
// In such case, we cannot optimize the access: this array was added to allow |
| 1898 |
// dynamic indexing in the struct. |
| 1899 |
TEST_F(CopyPropArrayPassTest, StructIndexCannotBecomeDynamic) { |
| 1900 |
const std::string text = R"(OpCapability Shader |
| 1901 |
OpMemoryModel Logical GLSL450 |
| 1902 |
OpEntryPoint Vertex %1 "main" |
| 1903 |
OpDecorate %2 DescriptorSet 0 |
| 1904 |
OpDecorate %2 Binding 0 |
| 1905 |
OpMemberDecorate %_struct_3 0 Offset 0 |
| 1906 |
OpDecorate %_struct_3 Block |
| 1907 |
%int = OpTypeInt 32 1 |
| 1908 |
%int_0 = OpConstant %int 0 |
| 1909 |
%float = OpTypeFloat 32 |
| 1910 |
%v4float = OpTypeVector %float 4 |
| 1911 |
%_struct_3 = OpTypeStruct %v4float |
| 1912 |
%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3 |
| 1913 |
%uint = OpTypeInt 32 0 |
| 1914 |
%void = OpTypeVoid |
| 1915 |
%11 = OpTypeFunction %void |
| 1916 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 1917 |
%13 = OpTypeFunction %v4float %_ptr_Function_uint |
| 1918 |
%uint_1 = OpConstant %uint 1 |
| 1919 |
%_arr_v4float_uint_1 = OpTypeArray %v4float %uint_1 |
| 1920 |
%_ptr_Function__arr_v4float_uint_1 = OpTypePointer Function %_arr_v4float_uint_1 |
| 1921 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 1922 |
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float |
| 1923 |
%2 = OpVariable %_ptr_Uniform__struct_3 Uniform |
| 1924 |
%19 = OpUndef %v4float |
| 1925 |
%1 = OpFunction %void None %11 |
| 1926 |
%20 = OpLabel |
| 1927 |
OpReturn |
| 1928 |
OpFunctionEnd |
| 1929 |
%21 = OpFunction %v4float None %13 |
| 1930 |
%22 = OpFunctionParameter %_ptr_Function_uint |
| 1931 |
%23 = OpLabel |
| 1932 |
%24 = OpVariable %_ptr_Function__arr_v4float_uint_1 Function |
| 1933 |
%25 = OpAccessChain %_ptr_Uniform_v4float %2 %int_0 |
| 1934 |
%26 = OpLoad %v4float %25 |
| 1935 |
%27 = OpCompositeConstruct %_arr_v4float_uint_1 %26 |
| 1936 |
OpStore %24 %27 |
| 1937 |
%28 = OpLoad %uint %22 |
| 1938 |
%29 = OpAccessChain %_ptr_Function_v4float %24 %28 |
| 1939 |
OpReturnValue %19 |
| 1940 |
OpFunctionEnd |
| 1941 |
)"; |
| 1942 |
|
| 1943 |
SinglePassRunAndCheck<CopyPropagateArrays>(text, text, false); |
| 1944 |
} |
| 1945 |
|
| 1946 |
// If the size of an array used in an OpCompositeInsert is not known at compile |
| 1947 |
// time, then we should not propagate the array, because we do not have a single |
| 1948 |
// array that represents the final value. |
| 1949 |
TEST_F(CopyPropArrayPassTest, SpecConstSizedArray) { |
| 1950 |
const std::string text = R"(OpCapability Shader |
| 1951 |
%1 = OpExtInstImport "GLSL.std.450" |
| 1952 |
OpMemoryModel Logical GLSL450 |
| 1953 |
OpEntryPoint Fragment %2 "main" |
| 1954 |
OpExecutionMode %2 OriginUpperLeft |
| 1955 |
%void = OpTypeVoid |
| 1956 |
%4 = OpTypeFunction %void |
| 1957 |
%int = OpTypeInt 32 1 |
| 1958 |
%uint = OpTypeInt 32 0 |
| 1959 |
%7 = OpSpecConstant %uint 32 |
| 1960 |
%_arr_int_7 = OpTypeArray %int %7 |
| 1961 |
%int_63 = OpConstant %int 63 |
| 1962 |
%uint_0 = OpConstant %uint 0 |
| 1963 |
%bool = OpTypeBool |
| 1964 |
%int_0 = OpConstant %int 0 |
| 1965 |
%int_587202566 = OpConstant %int 587202566 |
| 1966 |
%false = OpConstantFalse %bool |
| 1967 |
%_ptr_Function__arr_int_7 = OpTypePointer Function %_arr_int_7 |
| 1968 |
%16 = OpUndef %_arr_int_7 |
| 1969 |
%2 = OpFunction %void None %4 |
| 1970 |
%17 = OpLabel |
| 1971 |
%18 = OpVariable %_ptr_Function__arr_int_7 Function |
| 1972 |
%19 = OpCompositeInsert %_arr_int_7 %int_0 %16 0 |
| 1973 |
OpStore %18 %19 |
| 1974 |
OpReturn |
| 1975 |
OpFunctionEnd |
| 1976 |
)"; |
| 1977 |
|
| 1978 |
SinglePassRunAndCheck<CopyPropagateArrays>(text, text, false); |
| 1979 |
} |
| 1980 |
|
| 1981 |
TEST_F(CopyPropArrayPassTest, InterpolateFunctions) { |
| 1982 |
const std::string before = R"(OpCapability InterpolationFunction |
| 1983 |
OpCapability Shader |
| 1984 |
%1 = OpExtInstImport "GLSL.std.450" |
| 1985 |
OpMemoryModel Logical GLSL450 |
| 1986 |
OpEntryPoint Fragment %main "main" %in_var_COLOR |
| 1987 |
OpExecutionMode %main OriginUpperLeft |
| 1988 |
OpSource HLSL 680 |
| 1989 |
OpName %in_var_COLOR "in.var.COLOR" |
| 1990 |
OpName %main "main" |
| 1991 |
OpName %offset "offset" |
| 1992 |
OpDecorate %in_var_COLOR Location 0 |
| 1993 |
%int = OpTypeInt 32 1 |
| 1994 |
%int_0 = OpConstant %int 0 |
| 1995 |
%float = OpTypeFloat 32 |
| 1996 |
%float_0 = OpConstant %float 0 |
| 1997 |
%v2float = OpTypeVector %float 2 |
| 1998 |
%v4float = OpTypeVector %float 4 |
| 1999 |
%_ptr_Input_v4float = OpTypePointer Input %v4float |
| 2000 |
%void = OpTypeVoid |
| 2001 |
%19 = OpTypeFunction %void |
| 2002 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 2003 |
%in_var_COLOR = OpVariable %_ptr_Input_v4float Input |
| 2004 |
%main = OpFunction %void None %19 |
| 2005 |
%20 = OpLabel |
| 2006 |
%45 = OpVariable %_ptr_Function_v4float Function |
| 2007 |
%25 = OpLoad %v4float %in_var_COLOR |
| 2008 |
OpStore %45 %25 |
| 2009 |
; CHECK: OpExtInst %v4float %1 InterpolateAtCentroid %in_var_COLOR |
| 2010 |
%52 = OpExtInst %v4float %1 InterpolateAtCentroid %45 |
| 2011 |
; CHECK: OpExtInst %v4float %1 InterpolateAtSample %in_var_COLOR %int_0 |
| 2012 |
%54 = OpExtInst %v4float %1 InterpolateAtSample %45 %int_0 |
| 2013 |
%offset = OpCompositeConstruct %v2float %float_0 %float_0 |
| 2014 |
; CHECK: OpExtInst %v4float %1 InterpolateAtOffset %in_var_COLOR %offset |
| 2015 |
%56 = OpExtInst %v4float %1 InterpolateAtOffset %45 %offset |
| 2016 |
OpReturn |
| 2017 |
OpFunctionEnd |
| 2018 |
)"; |
| 2019 |
|
| 2020 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 2021 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 2022 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 2023 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2024 |
} |
| 2025 |
|
| 2026 |
TEST_F(CopyPropArrayPassTest, InterpolateMultiPropagation) { |
| 2027 |
const std::string before = R"(OpCapability InterpolationFunction |
| 2028 |
OpCapability Shader |
| 2029 |
%1 = OpExtInstImport "GLSL.std.450" |
| 2030 |
OpMemoryModel Logical GLSL450 |
| 2031 |
OpEntryPoint Fragment %main "main" %in_var_COLOR |
| 2032 |
OpExecutionMode %main OriginUpperLeft |
| 2033 |
OpSource HLSL 680 |
| 2034 |
OpName %in_var_COLOR "in.var.COLOR" |
| 2035 |
OpName %main "main" |
| 2036 |
OpName %param_var_color "param.var.color" |
| 2037 |
OpDecorate %in_var_COLOR Location 0 |
| 2038 |
%float = OpTypeFloat 32 |
| 2039 |
%v4float = OpTypeVector %float 4 |
| 2040 |
%_ptr_Input_v4float = OpTypePointer Input %v4float |
| 2041 |
%void = OpTypeVoid |
| 2042 |
%19 = OpTypeFunction %void |
| 2043 |
%_ptr_Function_v4float = OpTypePointer Function %v4float |
| 2044 |
%in_var_COLOR = OpVariable %_ptr_Input_v4float Input |
| 2045 |
%main = OpFunction %void None %19 |
| 2046 |
%20 = OpLabel |
| 2047 |
%45 = OpVariable %_ptr_Function_v4float Function |
| 2048 |
%param_var_color = OpVariable %_ptr_Function_v4float Function |
| 2049 |
%25 = OpLoad %v4float %in_var_COLOR |
| 2050 |
OpStore %param_var_color %25 |
| 2051 |
; CHECK: OpExtInst %v4float %1 InterpolateAtCentroid %in_var_COLOR |
| 2052 |
%52 = OpExtInst %v4float %1 InterpolateAtCentroid %param_var_color |
| 2053 |
%49 = OpLoad %v4float %param_var_color |
| 2054 |
OpStore %45 %49 |
| 2055 |
; CHECK: OpExtInst %v4float %1 InterpolateAtCentroid %in_var_COLOR |
| 2056 |
%54 = OpExtInst %v4float %1 InterpolateAtCentroid %45 |
| 2057 |
OpReturn |
| 2058 |
OpFunctionEnd |
| 2059 |
)"; |
| 2060 |
|
| 2061 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 2062 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 2063 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 2064 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2065 |
} |
| 2066 |
|
| 2067 |
TEST_F(CopyPropArrayPassTest, PropagateScalar) { |
| 2068 |
const std::string before = R"(OpCapability InterpolationFunction |
| 2069 |
OpCapability Shader |
| 2070 |
%1 = OpExtInstImport "GLSL.std.450" |
| 2071 |
OpMemoryModel Logical GLSL450 |
| 2072 |
OpEntryPoint Fragment %main "main" %in_var_SV_InstanceID |
| 2073 |
OpExecutionMode %main OriginUpperLeft |
| 2074 |
OpSource HLSL 680 |
| 2075 |
OpName %in_var_SV_InstanceID "in.var.SV_InstanceID" |
| 2076 |
OpName %main "main" |
| 2077 |
OpDecorate %in_var_SV_InstanceID Location 0 |
| 2078 |
%float = OpTypeFloat 32 |
| 2079 |
%v4float = OpTypeVector %float 4 |
| 2080 |
%_ptr_Input_float = OpTypePointer Input %float |
| 2081 |
%void = OpTypeVoid |
| 2082 |
%19 = OpTypeFunction %void |
| 2083 |
%_ptr_Function_float = OpTypePointer Function %float |
| 2084 |
%in_var_SV_InstanceID = OpVariable %_ptr_Input_float Input |
| 2085 |
%main = OpFunction %void None %19 |
| 2086 |
%20 = OpLabel |
| 2087 |
%45 = OpVariable %_ptr_Function_float Function |
| 2088 |
%25 = OpLoad %v4float %in_var_SV_InstanceID |
| 2089 |
OpStore %45 %25 |
| 2090 |
; CHECK: OpExtInst %v4float %1 InterpolateAtCentroid %in_var_SV_InstanceID |
| 2091 |
%52 = OpExtInst %v4float %1 InterpolateAtCentroid %45 |
| 2092 |
OpReturn |
| 2093 |
OpFunctionEnd |
| 2094 |
)"; |
| 2095 |
|
| 2096 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 2097 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | |
| 2098 |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES); |
| 2099 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2100 |
} |
| 2101 |
|
| 2102 |
TEST_F(CopyPropArrayPassTest, StoreToAccessChain) { |
| 2103 |
const std::string before = R"(OpCapability InterpolationFunction |
| 2104 |
OpCapability MeshShadingEXT |
| 2105 |
OpExtension "SPV_EXT_mesh_shader" |
| 2106 |
OpMemoryModel Logical GLSL450 |
| 2107 |
OpEntryPoint MeshEXT %1 "main" %2 %3 |
| 2108 |
OpExecutionMode %1 LocalSize 128 1 1 |
| 2109 |
OpExecutionMode %1 OutputTrianglesEXT |
| 2110 |
OpExecutionMode %1 OutputVertices 64 |
| 2111 |
OpExecutionMode %1 OutputPrimitivesEXT 126 |
| 2112 |
OpDecorate %3 Flat |
| 2113 |
OpDecorate %3 Location 2 |
| 2114 |
%uint = OpTypeInt 32 0 |
| 2115 |
%uint_4 = OpConstant %uint 4 |
| 2116 |
%uint_32 = OpConstant %uint 32 |
| 2117 |
%_arr_uint_uint_32 = OpTypeArray %uint %uint_32 |
| 2118 |
%_struct_8 = OpTypeStruct %_arr_uint_uint_32 |
| 2119 |
%_ptr_TaskPayloadWorkgroupEXT__struct_8 = OpTypePointer TaskPayloadWorkgroupEXT %_struct_8 |
| 2120 |
%uint_64 = OpConstant %uint 64 |
| 2121 |
%_arr_uint_uint_64 = OpTypeArray %uint %uint_64 |
| 2122 |
%_ptr_Output__arr_uint_uint_64 = OpTypePointer Output %_arr_uint_uint_64 |
| 2123 |
%void = OpTypeVoid |
| 2124 |
%14 = OpTypeFunction %void |
| 2125 |
%_ptr_Function_uint = OpTypePointer Function %uint |
| 2126 |
%_ptr_Function__arr_uint_uint_32 = OpTypePointer Function %_arr_uint_uint_32 |
| 2127 |
%_ptr_Output_uint = OpTypePointer Output %uint |
| 2128 |
%2 = OpVariable %_ptr_TaskPayloadWorkgroupEXT__struct_8 TaskPayloadWorkgroupEXT |
| 2129 |
%3 = OpVariable %_ptr_Output__arr_uint_uint_64 Output |
| 2130 |
%1 = OpFunction %void None %14 |
| 2131 |
%18 = OpLabel |
| 2132 |
%19 = OpVariable %_ptr_Function__arr_uint_uint_32 Function |
| 2133 |
%20 = OpLoad %_struct_8 %2 |
| 2134 |
%21 = OpCompositeExtract %_arr_uint_uint_32 %20 0 |
| 2135 |
; CHECK: %28 = OpAccessChain %_ptr_TaskPayloadWorkgroupEXT__arr_uint_uint_32 %2 %uint_0 |
| 2136 |
OpStore %19 %21 |
| 2137 |
; CHECK: %22 = OpAccessChain %_ptr_TaskPayloadWorkgroupEXT_uint %28 %uint_4 |
| 2138 |
%22 = OpAccessChain %_ptr_Function_uint %19 %uint_4 |
| 2139 |
%23 = OpLoad %uint %22 |
| 2140 |
%24 = OpAccessChain %_ptr_Output_uint %3 %uint_4 |
| 2141 |
OpStore %24 %23 |
| 2142 |
OpReturn |
| 2143 |
OpFunctionEnd |
| 2144 |
)"; |
| 2145 |
|
| 2146 |
SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); |
| 2147 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, true); |
| 2148 |
} |
| 2149 |
|
| 2150 |
TEST_F(CopyPropArrayPassTest, PropCopyLogical) { |
| 2151 |
const std::string before = R"( |
| 2152 |
; CHECK: [[v4array_ptr:%\w+]] = OpTypePointer Uniform %14 |
| 2153 |
; CHECK: [[v4_ptr:%\w+]] = OpTypePointer Uniform %7 |
| 2154 |
; CHECK: [[ac:%\w+]] = OpAccessChain [[v4array_ptr]] %19 %21 %33 |
| 2155 |
; CHECK: %47 = OpAccessChain [[v4_ptr]] [[ac]] %37 |
| 2156 |
OpCapability Shader |
| 2157 |
%1 = OpExtInstImport "GLSL.std.450" |
| 2158 |
OpMemoryModel Logical GLSL450 |
| 2159 |
OpEntryPoint Vertex %4 "main" %19 %30 %32 |
| 2160 |
OpSource GLSL 430 |
| 2161 |
OpName %4 "main" |
| 2162 |
OpDecorate %14 ArrayStride 16 |
| 2163 |
OpDecorate %15 ArrayStride 16 |
| 2164 |
OpMemberDecorate %16 0 Offset 0 |
| 2165 |
OpMemberDecorate %16 1 Offset 32 |
| 2166 |
OpDecorate %17 Block |
| 2167 |
OpMemberDecorate %17 0 Offset 0 |
| 2168 |
OpDecorate %19 Binding 0 |
| 2169 |
OpDecorate %19 DescriptorSet 0 |
| 2170 |
OpDecorate %28 Block |
| 2171 |
OpMemberDecorate %28 0 BuiltIn Position |
| 2172 |
OpMemberDecorate %28 1 BuiltIn PointSize |
| 2173 |
OpMemberDecorate %28 2 BuiltIn ClipDistance |
| 2174 |
OpDecorate %32 Location 0 |
| 2175 |
%2 = OpTypeVoid |
| 2176 |
%3 = OpTypeFunction %2 |
| 2177 |
%6 = OpTypeFloat 32 |
| 2178 |
%7 = OpTypeVector %6 4 |
| 2179 |
%8 = OpTypeInt 32 0 |
| 2180 |
%9 = OpConstant %8 2 |
| 2181 |
%10 = OpTypeArray %7 %9 |
| 2182 |
%11 = OpTypeStruct %10 %10 |
| 2183 |
%14 = OpTypeArray %7 %9 |
| 2184 |
%15 = OpTypeArray %7 %9 |
| 2185 |
%16 = OpTypeStruct %14 %15 |
| 2186 |
%17 = OpTypeStruct %16 |
| 2187 |
%18 = OpTypePointer Uniform %17 |
| 2188 |
%19 = OpVariable %18 Uniform |
| 2189 |
%20 = OpTypeInt 32 1 |
| 2190 |
%21 = OpConstant %20 0 |
| 2191 |
%22 = OpTypePointer Uniform %16 |
| 2192 |
%26 = OpConstant %8 1 |
| 2193 |
%27 = OpTypeArray %6 %26 |
| 2194 |
%28 = OpTypeStruct %7 %6 %27 |
| 2195 |
%29 = OpTypePointer Output %28 |
| 2196 |
%30 = OpVariable %29 Output |
| 2197 |
%31 = OpTypePointer Input %7 |
| 2198 |
%32 = OpVariable %31 Input |
| 2199 |
%33 = OpConstant %8 0 |
| 2200 |
%34 = OpTypePointer Input %6 |
| 2201 |
%38 = OpTypePointer Function %7 |
| 2202 |
%41 = OpTypePointer Output %7 |
| 2203 |
%43 = OpTypePointer Function %10 |
| 2204 |
%4 = OpFunction %2 None %3 |
| 2205 |
%5 = OpLabel |
| 2206 |
%44 = OpVariable %43 Function |
| 2207 |
%23 = OpAccessChain %22 %19 %21 |
| 2208 |
%24 = OpLoad %16 %23 |
| 2209 |
%25 = OpCopyLogical %11 %24 |
| 2210 |
%46 = OpCompositeExtract %10 %25 0 |
| 2211 |
OpStore %44 %46 |
| 2212 |
%35 = OpAccessChain %34 %32 %33 |
| 2213 |
%36 = OpLoad %6 %35 |
| 2214 |
%37 = OpConvertFToS %20 %36 |
| 2215 |
%47 = OpAccessChain %38 %44 %37 |
| 2216 |
%40 = OpLoad %7 %47 |
| 2217 |
%42 = OpAccessChain %41 %30 %21 |
| 2218 |
OpStore %42 %40 |
| 2219 |
OpReturn |
| 2220 |
OpFunctionEnd |
| 2221 |
)"; |
| 2222 |
|
| 2223 |
SetTargetEnv(SPV_ENV_UNIVERSAL_1_6); |
| 2224 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 2225 |
SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER); |
| 2226 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, true); |
| 2227 |
} |
| 2228 |
|
| 2229 |
// Ensure that the use of the global variable in a debug instruction does not |
| 2230 |
// stop copy propagation. We expect the image operand to OpImageTexelPointer to |
| 2231 |
// be replaced. |
| 2232 |
TEST_F(CopyPropArrayPassTest, DebugInstNotStore) { |
| 2233 |
const std::string before = R"( |
| 2234 |
OpCapability Shader |
| 2235 |
OpCapability SampledBuffer |
| 2236 |
OpExtension "SPV_KHR_non_semantic_info" |
| 2237 |
OpExtension "SPV_EXT_descriptor_indexing" |
| 2238 |
%1 = OpExtInstImport "GLSL.std.450" |
| 2239 |
%2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" |
| 2240 |
OpMemoryModel Logical GLSL450 |
| 2241 |
OpEntryPoint GLCompute %3 "maincomp" |
| 2242 |
OpExecutionMode %3 LocalSize 16 16 1 |
| 2243 |
%4 = OpString "" |
| 2244 |
%uint = OpTypeInt 32 0 |
| 2245 |
%uint_0 = OpConstant %uint 0 |
| 2246 |
%uint_1 = OpConstant %uint 1 |
| 2247 |
%uint_6 = OpConstant %uint 6 |
| 2248 |
%uint_8 = OpConstant %uint 8 |
| 2249 |
%uint_2 = OpConstant %uint 2 |
| 2250 |
%uint_7 = OpConstant %uint 7 |
| 2251 |
%uint_3 = OpConstant %uint 3 |
| 2252 |
%uint_32 = OpConstant %uint 32 |
| 2253 |
%uint_16 = OpConstant %uint 16 |
| 2254 |
%uint_4 = OpConstant %uint 4 |
| 2255 |
%16 = OpTypeImage %uint Buffer 2 0 0 2 R32ui |
| 2256 |
%_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16 |
| 2257 |
%void = OpTypeVoid |
| 2258 |
%uint_5 = OpConstant %uint 5 |
| 2259 |
%uint_70 = OpConstant %uint 70 |
| 2260 |
%uint_71 = OpConstant %uint 71 |
| 2261 |
%uint_72 = OpConstant %uint 72 |
| 2262 |
%uint_17 = OpConstant %uint 17 |
| 2263 |
%uint_9 = OpConstant %uint 9 |
| 2264 |
%uint_25 = OpConstant %uint 25 |
| 2265 |
%uint_14 = OpConstant %uint 14 |
| 2266 |
%uint_24 = OpConstant %uint 24 |
| 2267 |
%uint_13 = OpConstant %uint 13 |
| 2268 |
%29 = OpTypeFunction %void |
| 2269 |
%_ptr_Function_16 = OpTypePointer Function %16 |
| 2270 |
%_ptr_Image_uint = OpTypePointer Image %uint |
| 2271 |
; CHECK: [[GV:%\w+]] = OpVariable {{%\w+}} UniformConstant |
| 2272 |
%32 = OpVariable %_ptr_UniformConstant_16 UniformConstant |
| 2273 |
%33 = OpExtInst %void %2 DebugInfoNone |
| 2274 |
%34 = OpExtInst %void %2 DebugExpression |
| 2275 |
%35 = OpExtInst %void %2 DebugTypeBasic %4 %uint_32 %uint_3 %uint_0 |
| 2276 |
%36 = OpExtInst %void %2 DebugTypeVector %35 %uint_3 |
| 2277 |
%37 = OpExtInst %void %2 DebugSource %4 %4 |
| 2278 |
%38 = OpExtInst %void %2 DebugCompilationUnit %uint_1 %uint_4 %37 %uint_5 |
| 2279 |
%39 = OpExtInst %void %2 DebugTypeTemplateParameter %4 %36 %33 %37 %uint_0 %uint_0 |
| 2280 |
%40 = OpExtInst %void %2 DebugTypeBasic %4 %uint_32 %uint_6 %uint_0 |
| 2281 |
%41 = OpExtInst %void %2 DebugSource %4 %4 |
| 2282 |
%42 = OpExtInst %void %2 DebugCompilationUnit %uint_1 %uint_4 %41 %uint_5 |
| 2283 |
%43 = OpExtInst %void %2 DebugTypeComposite %4 %uint_0 %37 %uint_0 %uint_0 %38 %4 %33 %uint_3 |
| 2284 |
%44 = OpExtInst %void %2 DebugTypeTemplateParameter %4 %40 %33 %37 %uint_0 %uint_0 |
| 2285 |
%45 = OpExtInst %void %2 DebugTypeTemplate %43 %44 |
| 2286 |
%46 = OpExtInst %void %2 DebugTypeFunction %uint_3 %void %40 |
| 2287 |
%47 = OpExtInst %void %2 DebugFunction %4 %46 %37 %uint_70 %uint_1 %38 %4 %uint_3 %uint_71 |
| 2288 |
%48 = OpExtInst %void %2 DebugLexicalBlock %37 %uint_71 %uint_1 %47 |
| 2289 |
%49 = OpExtInst %void %2 DebugLocalVariable %4 %45 %37 %uint_72 %uint_17 %48 %uint_4 |
| 2290 |
%50 = OpExtInst %void %2 DebugTypeFunction %uint_3 %void |
| 2291 |
%51 = OpExtInst %void %2 DebugSource %4 %4 |
| 2292 |
%52 = OpExtInst %void %2 DebugCompilationUnit %uint_1 %uint_4 %51 %uint_5 |
| 2293 |
%53 = OpExtInst %void %2 DebugFunction %4 %50 %51 %uint_24 %uint_1 %52 %4 %uint_3 %uint_25 |
| 2294 |
%54 = OpExtInst %void %2 DebugGlobalVariable %4 %45 %37 %uint_17 %uint_16 %38 %4 %32 %uint_8 |
| 2295 |
%55 = OpExtInst %void %2 DebugTypeMember %4 %40 %37 %uint_14 %uint_7 %uint_0 %uint_32 %uint_3 |
| 2296 |
%56 = OpExtInst %void %2 DebugTypeComposite %4 %uint_1 %37 %uint_13 %uint_9 %38 %4 %uint_32 %uint_3 %55 |
| 2297 |
%57 = OpExtInst %void %2 DebugEntryPoint %53 %42 %4 %4 |
| 2298 |
%3 = OpFunction %void None %29 |
| 2299 |
%58 = OpLabel |
| 2300 |
%59 = OpVariable %_ptr_Function_16 Function |
| 2301 |
%60 = OpLoad %16 %32 |
| 2302 |
OpStore %59 %60 |
| 2303 |
%61 = OpExtInst %void %2 DebugDeclare %49 %59 %34 |
| 2304 |
%62 = OpExtInst %void %2 DebugLine %37 %uint_0 %uint_0 %uint_2 %uint_2 |
| 2305 |
; CHECK: OpImageTexelPointer %_ptr_Image_uint [[GV]] %uint_0 %uint_0 |
| 2306 |
%63 = OpImageTexelPointer %_ptr_Image_uint %59 %uint_0 %uint_0 |
| 2307 |
%64 = OpAtomicIAdd %uint %63 %uint_1 %uint_0 %uint_1 |
| 2308 |
OpReturn |
| 2309 |
OpFunctionEnd |
| 2310 |
)"; |
| 2311 |
|
| 2312 |
SetTargetEnv(SPV_ENV_VULKAN_1_1); |
| 2313 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2314 |
} |
| 2315 |
|
| 2316 |
TEST_F(CopyPropArrayPassTest, DebugInstNotDominatingStore) { |
| 2317 |
// Move the debug value to after the new access chain instruction. |
| 2318 |
const std::string before = R"( |
| 2319 |
OpCapability Shader |
| 2320 |
OpCapability MeshShadingEXT |
| 2321 |
OpExtension "SPV_EXT_mesh_shader" |
| 2322 |
%1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" |
| 2323 |
OpMemoryModel Logical GLSL450 |
| 2324 |
OpEntryPoint MeshEXT %2 "main" %3 |
| 2325 |
OpExecutionMode %2 LocalSize 1 1 1 |
| 2326 |
OpExecutionMode %2 OutputTrianglesEXT |
| 2327 |
OpExecutionMode %2 OutputVertices 64 |
| 2328 |
OpExecutionMode %2 OutputPrimitivesEXT 124 |
| 2329 |
%4 = OpString "" |
| 2330 |
%int = OpTypeInt 32 1 |
| 2331 |
%int_0 = OpConstant %int 0 |
| 2332 |
%uint = OpTypeInt 32 0 |
| 2333 |
%uint_32 = OpConstant %uint 32 |
| 2334 |
%_arr_uint_uint_32 = OpTypeArray %uint %uint_32 |
| 2335 |
%_struct_10 = OpTypeStruct %_arr_uint_uint_32 |
| 2336 |
%_ptr_TaskPayloadWorkgroupEXT__struct_10 = OpTypePointer TaskPayloadWorkgroupEXT %_struct_10 |
| 2337 |
%uint_124 = OpConstant %uint 124 |
| 2338 |
%uint_64 = OpConstant %uint 64 |
| 2339 |
%void = OpTypeVoid |
| 2340 |
%uint_6 = OpConstant %uint 6 |
| 2341 |
%uint_0 = OpConstant %uint 0 |
| 2342 |
%uint_1 = OpConstant %uint 1 |
| 2343 |
%uint_4 = OpConstant %uint 4 |
| 2344 |
%uint_5 = OpConstant %uint 5 |
| 2345 |
%uint_1024 = OpConstant %uint 1024 |
| 2346 |
%uint_7 = OpConstant %uint 7 |
| 2347 |
%uint_8 = OpConstant %uint 8 |
| 2348 |
%uint_3 = OpConstant %uint 3 |
| 2349 |
%uint_96 = OpConstant %uint 96 |
| 2350 |
%uint_11 = OpConstant %uint 11 |
| 2351 |
%uint_12 = OpConstant %uint 12 |
| 2352 |
%uint_10 = OpConstant %uint 10 |
| 2353 |
%uint_16 = OpConstant %uint 16 |
| 2354 |
%uint_21 = OpConstant %uint 21 |
| 2355 |
%uint_17 = OpConstant %uint 17 |
| 2356 |
%uint_26 = OpConstant %uint 26 |
| 2357 |
%32 = OpTypeFunction %void |
| 2358 |
%_ptr_Function__arr_uint_uint_32 = OpTypePointer Function %_arr_uint_uint_32 |
| 2359 |
%3 = OpVariable %_ptr_TaskPayloadWorkgroupEXT__struct_10 TaskPayloadWorkgroupEXT |
| 2360 |
%34 = OpExtInst %void %1 DebugOperation %uint_0 |
| 2361 |
%35 = OpExtInst %void %1 DebugTypeBasic %4 %uint_32 %uint_6 %uint_0 |
| 2362 |
%36 = OpExtInst %void %1 DebugSource %4 %4 |
| 2363 |
%37 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %36 %uint_5 |
| 2364 |
%38 = OpExtInst %void %1 DebugTypeArray %35 %uint_32 |
| 2365 |
%39 = OpExtInst %void %1 DebugTypeMember %4 %38 %36 %uint_7 %uint_8 %uint_0 %uint_1024 %uint_3 |
| 2366 |
%40 = OpExtInst %void %1 DebugTypeComposite %4 %uint_1 %36 %uint_6 %uint_8 %37 %4 %uint_1024 %uint_3 %39 |
| 2367 |
%41 = OpExtInst %void %1 DebugTypeVector %35 %uint_3 |
| 2368 |
%42 = OpExtInst %void %1 DebugTypeArray %41 %uint_124 |
| 2369 |
%43 = OpExtInst %void %1 DebugTypeBasic %4 %uint_32 %uint_3 %uint_0 |
| 2370 |
%44 = OpExtInst %void %1 DebugTypeVector %43 %uint_3 |
| 2371 |
%45 = OpExtInst %void %1 DebugTypeMember %4 %44 %36 %uint_11 %uint_12 %uint_0 %uint_96 %uint_3 |
| 2372 |
%46 = OpExtInst %void %1 DebugTypeComposite %4 %uint_1 %36 %uint_10 %uint_8 %37 %4 %uint_96 %uint_3 %45 |
| 2373 |
%47 = OpExtInst %void %1 DebugTypeArray %46 %uint_64 |
| 2374 |
%48 = OpExtInst %void %1 DebugTypeFunction %uint_3 %void %40 %35 %42 %47 |
| 2375 |
%49 = OpExtInst %void %1 DebugFunction %4 %48 %36 %uint_16 %uint_1 %37 %4 %uint_3 %uint_21 |
| 2376 |
%50 = OpExtInst %void %1 DebugLocalVariable %4 %40 %36 %uint_17 %uint_26 %49 %uint_4 %uint_1 |
| 2377 |
%51 = OpExtInst %void %1 DebugExpression %34 |
| 2378 |
; CHECK: OpFunction |
| 2379 |
%2 = OpFunction %void None %32 |
| 2380 |
%52 = OpLabel |
| 2381 |
%53 = OpVariable %_ptr_Function__arr_uint_uint_32 Function |
| 2382 |
; CHECK: [[new_ptr:%\w+]] = OpAccessChain %_ptr_TaskPayloadWorkgroupEXT__arr_uint_uint_32 |
| 2383 |
; CHECK: OpExtInst %void %1 DebugValue {{%\w+}} [[new_ptr]] |
| 2384 |
%54 = OpExtInst %void %1 DebugValue %50 %53 %51 %int_0 |
| 2385 |
%55 = OpLoad %_struct_10 %3 |
| 2386 |
%56 = OpCompositeExtract %_arr_uint_uint_32 %55 0 |
| 2387 |
OpStore %53 %56 |
| 2388 |
OpReturn |
| 2389 |
OpFunctionEnd |
| 2390 |
)"; |
| 2391 |
|
| 2392 |
SetTargetEnv(SPV_ENV_VULKAN_1_1); |
| 2393 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2394 |
} |
| 2395 |
|
| 2396 |
TEST_F(CopyPropArrayPassTest, DebugInstNotDominatingStoreInDifferentBB) { |
| 2397 |
// Move the debug value to after the new access chain instruction. |
| 2398 |
const std::string before = R"( |
| 2399 |
OpCapability Shader |
| 2400 |
OpCapability MeshShadingEXT |
| 2401 |
OpExtension "SPV_EXT_mesh_shader" |
| 2402 |
%1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" |
| 2403 |
OpMemoryModel Logical GLSL450 |
| 2404 |
OpEntryPoint MeshEXT %2 "main" %3 |
| 2405 |
OpExecutionMode %2 LocalSize 1 1 1 |
| 2406 |
OpExecutionMode %2 OutputTrianglesEXT |
| 2407 |
OpExecutionMode %2 OutputVertices 64 |
| 2408 |
OpExecutionMode %2 OutputPrimitivesEXT 124 |
| 2409 |
%4 = OpString "" |
| 2410 |
%int = OpTypeInt 32 1 |
| 2411 |
%int_0 = OpConstant %int 0 |
| 2412 |
%uint = OpTypeInt 32 0 |
| 2413 |
%uint_32 = OpConstant %uint 32 |
| 2414 |
%_arr_uint_uint_32 = OpTypeArray %uint %uint_32 |
| 2415 |
%_struct_10 = OpTypeStruct %_arr_uint_uint_32 |
| 2416 |
%_ptr_TaskPayloadWorkgroupEXT__struct_10 = OpTypePointer TaskPayloadWorkgroupEXT %_struct_10 |
| 2417 |
%uint_124 = OpConstant %uint 124 |
| 2418 |
%uint_64 = OpConstant %uint 64 |
| 2419 |
%void = OpTypeVoid |
| 2420 |
%uint_6 = OpConstant %uint 6 |
| 2421 |
%uint_0 = OpConstant %uint 0 |
| 2422 |
%uint_1 = OpConstant %uint 1 |
| 2423 |
%uint_4 = OpConstant %uint 4 |
| 2424 |
%uint_5 = OpConstant %uint 5 |
| 2425 |
%uint_1024 = OpConstant %uint 1024 |
| 2426 |
%uint_7 = OpConstant %uint 7 |
| 2427 |
%uint_8 = OpConstant %uint 8 |
| 2428 |
%uint_3 = OpConstant %uint 3 |
| 2429 |
%uint_96 = OpConstant %uint 96 |
| 2430 |
%uint_11 = OpConstant %uint 11 |
| 2431 |
%uint_12 = OpConstant %uint 12 |
| 2432 |
%uint_10 = OpConstant %uint 10 |
| 2433 |
%uint_16 = OpConstant %uint 16 |
| 2434 |
%uint_21 = OpConstant %uint 21 |
| 2435 |
%uint_17 = OpConstant %uint 17 |
| 2436 |
%uint_26 = OpConstant %uint 26 |
| 2437 |
%32 = OpTypeFunction %void |
| 2438 |
%_ptr_Function__arr_uint_uint_32 = OpTypePointer Function %_arr_uint_uint_32 |
| 2439 |
%3 = OpVariable %_ptr_TaskPayloadWorkgroupEXT__struct_10 TaskPayloadWorkgroupEXT |
| 2440 |
%34 = OpExtInst %void %1 DebugOperation %uint_0 |
| 2441 |
%35 = OpExtInst %void %1 DebugTypeBasic %4 %uint_32 %uint_6 %uint_0 |
| 2442 |
%36 = OpExtInst %void %1 DebugSource %4 %4 |
| 2443 |
%37 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %36 %uint_5 |
| 2444 |
%38 = OpExtInst %void %1 DebugTypeArray %35 %uint_32 |
| 2445 |
%39 = OpExtInst %void %1 DebugTypeMember %4 %38 %36 %uint_7 %uint_8 %uint_0 %uint_1024 %uint_3 |
| 2446 |
%40 = OpExtInst %void %1 DebugTypeComposite %4 %uint_1 %36 %uint_6 %uint_8 %37 %4 %uint_1024 %uint_3 %39 |
| 2447 |
%41 = OpExtInst %void %1 DebugTypeVector %35 %uint_3 |
| 2448 |
%42 = OpExtInst %void %1 DebugTypeArray %41 %uint_124 |
| 2449 |
%43 = OpExtInst %void %1 DebugTypeBasic %4 %uint_32 %uint_3 %uint_0 |
| 2450 |
%44 = OpExtInst %void %1 DebugTypeVector %43 %uint_3 |
| 2451 |
%45 = OpExtInst %void %1 DebugTypeMember %4 %44 %36 %uint_11 %uint_12 %uint_0 %uint_96 %uint_3 |
| 2452 |
%46 = OpExtInst %void %1 DebugTypeComposite %4 %uint_1 %36 %uint_10 %uint_8 %37 %4 %uint_96 %uint_3 %45 |
| 2453 |
%47 = OpExtInst %void %1 DebugTypeArray %46 %uint_64 |
| 2454 |
%48 = OpExtInst %void %1 DebugTypeFunction %uint_3 %void %40 %35 %42 %47 |
| 2455 |
%49 = OpExtInst %void %1 DebugFunction %4 %48 %36 %uint_16 %uint_1 %37 %4 %uint_3 %uint_21 |
| 2456 |
%50 = OpExtInst %void %1 DebugLocalVariable %4 %40 %36 %uint_17 %uint_26 %49 %uint_4 %uint_1 |
| 2457 |
%51 = OpExtInst %void %1 DebugExpression %34 |
| 2458 |
; CHECK: OpFunction |
| 2459 |
%2 = OpFunction %void None %32 |
| 2460 |
%52 = OpLabel |
| 2461 |
%53 = OpVariable %_ptr_Function__arr_uint_uint_32 Function |
| 2462 |
; CHECK: [[new_ptr:%\w+]] = OpAccessChain %_ptr_TaskPayloadWorkgroupEXT__arr_uint_uint_32 |
| 2463 |
; CHECK: OpExtInst %void %1 DebugValue {{%\w+}} [[new_ptr]] |
| 2464 |
%54 = OpExtInst %void %1 DebugValue %50 %53 %51 %int_0 |
| 2465 |
%55 = OpLoad %_struct_10 %3 |
| 2466 |
%56 = OpCompositeExtract %_arr_uint_uint_32 %55 0 |
| 2467 |
OpBranch %57 |
| 2468 |
%57 = OpLabel |
| 2469 |
OpStore %53 %56 |
| 2470 |
OpReturn |
| 2471 |
OpFunctionEnd |
| 2472 |
)"; |
| 2473 |
|
| 2474 |
SetTargetEnv(SPV_ENV_VULKAN_1_1); |
| 2475 |
SinglePassRunAndMatch<CopyPropagateArrays>(before, false); |
| 2476 |
} |
| 2477 |
|
| 2478 |
} // namespace |
| 2479 |
} // namespace opt |
| 2480 |
} // namespace spvtools |