eliminate_dead_output_stores_test.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. // Copyright (c) 2022 The Khronos Group Inc.
  2. // Copyright (c) 2022 LunarG Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #include <unordered_set>
  16. #include "test/opt/pass_fixture.h"
  17. #include "test/opt/pass_utils.h"
  18. namespace spvtools {
  19. namespace opt {
  20. namespace {
  21. using ElimDeadOutputStoresTest = PassTest<::testing::Test>;
  22. TEST_F(ElimDeadOutputStoresTest, VertMultipleLocations) {
  23. // #version 450
  24. //
  25. // layout(location = 2) out Vertex
  26. // {
  27. // vec4 color0;
  28. // vec4 color1;
  29. // vec4 color2[3];
  30. // } oVert;
  31. //
  32. // void main()
  33. // {
  34. // oVert.color0 = vec4(0.0,0.0,0.0,0.0);
  35. // oVert.color1 = vec4(0.1,0.0,0.0,0.0);
  36. // oVert.color2[0] = vec4(0.2,0.0,0.0,0.0);
  37. // oVert.color2[1] = vec4(0.3,0.0,0.0,0.0);
  38. // oVert.color2[2] = vec4(0.4,0.0,0.0,0.0);
  39. // }
  40. const std::string text = R"(
  41. OpCapability Shader
  42. %1 = OpExtInstImport "GLSL.std.450"
  43. OpMemoryModel Logical GLSL450
  44. OpEntryPoint Vertex %main "main" %oVert
  45. OpSource GLSL 450
  46. OpName %main "main"
  47. OpName %Vertex "Vertex"
  48. OpMemberName %Vertex 0 "color0"
  49. OpMemberName %Vertex 1 "color1"
  50. OpMemberName %Vertex 2 "color2"
  51. OpName %oVert "oVert"
  52. OpDecorate %Vertex Block
  53. OpDecorate %oVert Location 2
  54. %void = OpTypeVoid
  55. %3 = OpTypeFunction %void
  56. %float = OpTypeFloat 32
  57. %v4float = OpTypeVector %float 4
  58. %uint = OpTypeInt 32 0
  59. %uint_3 = OpConstant %uint 3
  60. %_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
  61. %Vertex = OpTypeStruct %v4float %v4float %_arr_v4float_uint_3
  62. %_ptr_Output_Vertex = OpTypePointer Output %Vertex
  63. %oVert = OpVariable %_ptr_Output_Vertex Output
  64. %int = OpTypeInt 32 1
  65. %int_0 = OpConstant %int 0
  66. %float_0 = OpConstant %float 0
  67. %17 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
  68. %_ptr_Output_v4float = OpTypePointer Output %v4float
  69. %int_1 = OpConstant %int 1
  70. %float_0_100000001 = OpConstant %float 0.100000001
  71. %22 = OpConstantComposite %v4float %float_0_100000001 %float_0 %float_0 %float_0
  72. %int_2 = OpConstant %int 2
  73. %float_0_200000003 = OpConstant %float 0.200000003
  74. %26 = OpConstantComposite %v4float %float_0_200000003 %float_0 %float_0 %float_0
  75. %float_0_300000012 = OpConstant %float 0.300000012
  76. %29 = OpConstantComposite %v4float %float_0_300000012 %float_0 %float_0 %float_0
  77. %float_0_400000006 = OpConstant %float 0.400000006
  78. %32 = OpConstantComposite %v4float %float_0_400000006 %float_0 %float_0 %float_0
  79. %main = OpFunction %void None %3
  80. %5 = OpLabel
  81. %19 = OpAccessChain %_ptr_Output_v4float %oVert %int_0
  82. OpStore %19 %17
  83. ;CHECK: OpStore %19 %17
  84. %23 = OpAccessChain %_ptr_Output_v4float %oVert %int_1
  85. OpStore %23 %22
  86. ;CHECK-NOT: OpStore %23 %22
  87. %27 = OpAccessChain %_ptr_Output_v4float %oVert %int_2 %int_0
  88. OpStore %27 %26
  89. ;CHECK-NOT: OpStore %27 %26
  90. %30 = OpAccessChain %_ptr_Output_v4float %oVert %int_2 %int_1
  91. OpStore %30 %29
  92. ;CHECK: OpStore %30 %29
  93. %33 = OpAccessChain %_ptr_Output_v4float %oVert %int_2 %int_2
  94. OpStore %33 %32
  95. ;CHECK-NOT: OpStore %33 %32
  96. OpReturn
  97. OpFunctionEnd
  98. )";
  99. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  100. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  101. std::unordered_set<uint32_t> live_inputs;
  102. std::unordered_set<uint32_t> live_builtins;
  103. live_inputs.insert(2);
  104. live_inputs.insert(5);
  105. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  106. &live_builtins);
  107. }
  108. TEST_F(ElimDeadOutputStoresTest, VertMatrix) {
  109. // #version 450
  110. //
  111. // layout(location = 2) out Vertex
  112. // {
  113. // vec4 color0;
  114. // vec4 color1;
  115. // mat4 color2;
  116. // mat4 color3;
  117. // mat4 color4;
  118. // } oVert;
  119. //
  120. // void main()
  121. // {
  122. // oVert.color0 = vec4(0.0,0.0,0.0,0.0);
  123. // oVert.color1 = vec4(0.1,0.0,0.0,0.0);
  124. // oVert.color2[2] = vec4(0.2,0.0,0.0,0.0);
  125. // oVert.color3[1] = vec4(0.3,0.0,0.0,0.0);
  126. // oVert.color4[0] = vec4(0.4,0.0,0.0,0.0);
  127. // }
  128. const std::string text = R"(
  129. OpCapability Shader
  130. %1 = OpExtInstImport "GLSL.std.450"
  131. OpMemoryModel Logical GLSL450
  132. OpEntryPoint Vertex %main "main" %oVert
  133. OpSource GLSL 450
  134. OpName %main "main"
  135. OpName %Vertex "Vertex"
  136. OpMemberName %Vertex 0 "color0"
  137. OpMemberName %Vertex 1 "color1"
  138. OpMemberName %Vertex 2 "color2"
  139. OpMemberName %Vertex 3 "color3"
  140. OpMemberName %Vertex 4 "color4"
  141. OpName %oVert "oVert"
  142. OpDecorate %Vertex Block
  143. OpDecorate %oVert Location 2
  144. %void = OpTypeVoid
  145. %3 = OpTypeFunction %void
  146. %float = OpTypeFloat 32
  147. %v4float = OpTypeVector %float 4
  148. %mat4v4float = OpTypeMatrix %v4float 4
  149. %Vertex = OpTypeStruct %v4float %v4float %mat4v4float %mat4v4float %mat4v4float
  150. %_ptr_Output_Vertex = OpTypePointer Output %Vertex
  151. %oVert = OpVariable %_ptr_Output_Vertex Output
  152. %int = OpTypeInt 32 1
  153. %int_0 = OpConstant %int 0
  154. %float_0 = OpConstant %float 0
  155. %15 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
  156. %_ptr_Output_v4float = OpTypePointer Output %v4float
  157. %int_1 = OpConstant %int 1
  158. %float_0_100000001 = OpConstant %float 0.100000001
  159. %20 = OpConstantComposite %v4float %float_0_100000001 %float_0 %float_0 %float_0
  160. %int_2 = OpConstant %int 2
  161. %float_0_200000003 = OpConstant %float 0.200000003
  162. %24 = OpConstantComposite %v4float %float_0_200000003 %float_0 %float_0 %float_0
  163. %int_3 = OpConstant %int 3
  164. %float_0_300000012 = OpConstant %float 0.300000012
  165. %28 = OpConstantComposite %v4float %float_0_300000012 %float_0 %float_0 %float_0
  166. %int_4 = OpConstant %int 4
  167. %float_0_400000006 = OpConstant %float 0.400000006
  168. %32 = OpConstantComposite %v4float %float_0_400000006 %float_0 %float_0 %float_0
  169. %main = OpFunction %void None %3
  170. %5 = OpLabel
  171. %17 = OpAccessChain %_ptr_Output_v4float %oVert %int_0
  172. OpStore %17 %15
  173. ; CHECK: OpStore %17 %15
  174. %21 = OpAccessChain %_ptr_Output_v4float %oVert %int_1
  175. OpStore %21 %20
  176. ; CHECK-NOT: OpStore %21 %20
  177. %25 = OpAccessChain %_ptr_Output_v4float %oVert %int_2 %int_2
  178. OpStore %25 %24
  179. ; CHECK-NOT: OpStore %25 %24
  180. %29 = OpAccessChain %_ptr_Output_v4float %oVert %int_3 %int_1
  181. OpStore %29 %28
  182. ; CHECK: OpStore %29 %28
  183. %33 = OpAccessChain %_ptr_Output_v4float %oVert %int_4 %int_0
  184. OpStore %33 %32
  185. ; CHECK-NOT: OpStore %33 %32
  186. OpReturn
  187. OpFunctionEnd
  188. )";
  189. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  190. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  191. std::unordered_set<uint32_t> live_inputs;
  192. std::unordered_set<uint32_t> live_builtins;
  193. live_inputs.insert(2);
  194. live_inputs.insert(8);
  195. live_inputs.insert(9);
  196. live_inputs.insert(10);
  197. live_inputs.insert(11);
  198. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  199. &live_builtins);
  200. }
  201. TEST_F(ElimDeadOutputStoresTest, VertMemberLocs) {
  202. // #version 450
  203. //
  204. // out Vertex
  205. // {
  206. // layout (location = 1) vec4 Cd;
  207. // layout (location = 0) vec2 uv;
  208. // } oVert;
  209. //
  210. // layout (location = 0) in vec3 P;
  211. //
  212. // void main()
  213. // {
  214. // oVert.uv = vec2(0.1, 0.7);
  215. // oVert.Cd = vec4(1, 0.5, 0, 1);
  216. // gl_Position = vec4(P, 1);
  217. // }
  218. const std::string text = R"(
  219. OpCapability Shader
  220. %1 = OpExtInstImport "GLSL.std.450"
  221. OpMemoryModel Logical GLSL450
  222. OpEntryPoint Vertex %main "main" %oVert %_ %P
  223. OpSource GLSL 450
  224. OpName %main "main"
  225. OpName %Vertex "Vertex"
  226. OpMemberName %Vertex 0 "Cd"
  227. OpMemberName %Vertex 1 "uv"
  228. OpName %oVert "oVert"
  229. OpName %gl_PerVertex "gl_PerVertex"
  230. OpMemberName %gl_PerVertex 0 "gl_Position"
  231. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  232. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  233. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  234. OpName %_ ""
  235. OpName %P "P"
  236. OpMemberDecorate %Vertex 0 Location 1
  237. OpMemberDecorate %Vertex 1 Location 0
  238. OpDecorate %Vertex Block
  239. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  240. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  241. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  242. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  243. OpDecorate %gl_PerVertex Block
  244. OpDecorate %P Location 0
  245. %void = OpTypeVoid
  246. %3 = OpTypeFunction %void
  247. %float = OpTypeFloat 32
  248. %v4float = OpTypeVector %float 4
  249. %v2float = OpTypeVector %float 2
  250. %Vertex = OpTypeStruct %v4float %v2float
  251. %_ptr_Output_Vertex = OpTypePointer Output %Vertex
  252. %oVert = OpVariable %_ptr_Output_Vertex Output
  253. %int = OpTypeInt 32 1
  254. %int_1 = OpConstant %int 1
  255. %float_0_100000001 = OpConstant %float 0.100000001
  256. %float_0_699999988 = OpConstant %float 0.699999988
  257. %16 = OpConstantComposite %v2float %float_0_100000001 %float_0_699999988
  258. %_ptr_Output_v2float = OpTypePointer Output %v2float
  259. %int_0 = OpConstant %int 0
  260. %float_1 = OpConstant %float 1
  261. %float_0_5 = OpConstant %float 0.5
  262. %float_0 = OpConstant %float 0
  263. %23 = OpConstantComposite %v4float %float_1 %float_0_5 %float_0 %float_1
  264. %_ptr_Output_v4float = OpTypePointer Output %v4float
  265. %uint = OpTypeInt 32 0
  266. %uint_1 = OpConstant %uint 1
  267. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  268. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  269. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  270. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  271. %v3float = OpTypeVector %float 3
  272. %_ptr_Input_v3float = OpTypePointer Input %v3float
  273. %P = OpVariable %_ptr_Input_v3float Input
  274. %main = OpFunction %void None %3
  275. %5 = OpLabel
  276. %18 = OpAccessChain %_ptr_Output_v2float %oVert %int_1
  277. OpStore %18 %16
  278. ; CHECK-NOT: OpStore %18 %16
  279. %25 = OpAccessChain %_ptr_Output_v4float %oVert %int_0
  280. OpStore %25 %23
  281. ; CHECK: OpStore %25 %23
  282. %35 = OpLoad %v3float %P
  283. %36 = OpCompositeExtract %float %35 0
  284. %37 = OpCompositeExtract %float %35 1
  285. %38 = OpCompositeExtract %float %35 2
  286. %39 = OpCompositeConstruct %v4float %36 %37 %38 %float_1
  287. %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  288. OpStore %40 %39
  289. OpReturn
  290. OpFunctionEnd
  291. )";
  292. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  293. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  294. std::unordered_set<uint32_t> live_inputs;
  295. std::unordered_set<uint32_t> live_builtins;
  296. live_inputs.insert(1);
  297. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  298. &live_builtins);
  299. }
  300. TEST_F(ElimDeadOutputStoresTest, ArrayedOutput) {
  301. // Tests elimination of arrayed output as seen in Tesc shaders.
  302. //
  303. // #version 450
  304. //
  305. // layout (vertices = 4) out;
  306. //
  307. // layout (location = 0) in vec3 N[];
  308. // layout (location = 1) in vec3 P[];
  309. //
  310. // layout (location = 5) out Vertex
  311. // {
  312. // vec4 c;
  313. // vec3 n;
  314. // vec3 f[10];
  315. // } oVert[];
  316. //
  317. // void main()
  318. // {
  319. // oVert[gl_InvocationID].c = vec4(1, 0, 0, 1);
  320. // oVert[gl_InvocationID].n = N[gl_InvocationID];
  321. // oVert[gl_InvocationID].f[3] = vec3(0, 1, 0);
  322. // vec4 worldSpacePos = vec4(P[gl_InvocationID], 1);
  323. // gl_out[gl_InvocationID].gl_Position = worldSpacePos;
  324. // }
  325. const std::string text = R"(
  326. OpCapability Tessellation
  327. %1 = OpExtInstImport "GLSL.std.450"
  328. OpMemoryModel Logical GLSL450
  329. OpEntryPoint TessellationControl %main "main" %oVert %gl_InvocationID %N %P %gl_out
  330. OpExecutionMode %main OutputVertices 4
  331. OpSource GLSL 450
  332. OpName %main "main"
  333. OpName %Vertex "Vertex"
  334. OpMemberName %Vertex 0 "c"
  335. OpMemberName %Vertex 1 "n"
  336. OpMemberName %Vertex 2 "f"
  337. OpName %oVert "oVert"
  338. OpName %gl_InvocationID "gl_InvocationID"
  339. OpName %N "N"
  340. OpName %P "P"
  341. OpName %gl_PerVertex "gl_PerVertex"
  342. OpMemberName %gl_PerVertex 0 "gl_Position"
  343. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  344. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  345. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  346. OpName %gl_out "gl_out"
  347. OpDecorate %Vertex Block
  348. OpDecorate %oVert Location 5
  349. OpDecorate %gl_InvocationID BuiltIn InvocationId
  350. OpDecorate %N Location 0
  351. OpDecorate %P Location 1
  352. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  353. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  354. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  355. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  356. OpDecorate %gl_PerVertex Block
  357. %void = OpTypeVoid
  358. %3 = OpTypeFunction %void
  359. %float = OpTypeFloat 32
  360. %v4float = OpTypeVector %float 4
  361. %v3float = OpTypeVector %float 3
  362. %uint = OpTypeInt 32 0
  363. %uint_10 = OpConstant %uint 10
  364. %_arr_v3float_uint_10 = OpTypeArray %v3float %uint_10
  365. %Vertex = OpTypeStruct %v4float %v3float %_arr_v3float_uint_10
  366. %uint_4 = OpConstant %uint 4
  367. %_arr_Vertex_uint_4 = OpTypeArray %Vertex %uint_4
  368. %_ptr_Output__arr_Vertex_uint_4 = OpTypePointer Output %_arr_Vertex_uint_4
  369. %oVert = OpVariable %_ptr_Output__arr_Vertex_uint_4 Output
  370. %int = OpTypeInt 32 1
  371. %_ptr_Input_int = OpTypePointer Input %int
  372. %gl_InvocationID = OpVariable %_ptr_Input_int Input
  373. %int_0 = OpConstant %int 0
  374. %float_1 = OpConstant %float 1
  375. %float_0 = OpConstant %float 0
  376. %24 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
  377. %_ptr_Output_v4float = OpTypePointer Output %v4float
  378. %int_1 = OpConstant %int 1
  379. %uint_32 = OpConstant %uint 32
  380. %_arr_v3float_uint_32 = OpTypeArray %v3float %uint_32
  381. %_ptr_Input__arr_v3float_uint_32 = OpTypePointer Input %_arr_v3float_uint_32
  382. %N = OpVariable %_ptr_Input__arr_v3float_uint_32 Input
  383. %_ptr_Input_v3float = OpTypePointer Input %v3float
  384. %_ptr_Output_v3float = OpTypePointer Output %v3float
  385. %int_2 = OpConstant %int 2
  386. %int_3 = OpConstant %int 3
  387. %42 = OpConstantComposite %v3float %float_0 %float_1 %float_0
  388. %P = OpVariable %_ptr_Input__arr_v3float_uint_32 Input
  389. %uint_1 = OpConstant %uint 1
  390. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  391. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  392. %_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
  393. %_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
  394. %gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
  395. %main = OpFunction %void None %3
  396. %5 = OpLabel
  397. %20 = OpLoad %int %gl_InvocationID
  398. %26 = OpAccessChain %_ptr_Output_v4float %oVert %20 %int_0
  399. OpStore %26 %24
  400. ; CHECK: OpStore %26 %24
  401. %35 = OpAccessChain %_ptr_Input_v3float %N %20
  402. %36 = OpLoad %v3float %35
  403. %38 = OpAccessChain %_ptr_Output_v3float %oVert %20 %int_1
  404. OpStore %38 %36
  405. ; CHECK-NOT: OpStore %38 %36
  406. %43 = OpAccessChain %_ptr_Output_v3float %oVert %20 %int_2 %int_3
  407. OpStore %43 %42
  408. ; CHECK: OpStore %43 %42
  409. %48 = OpAccessChain %_ptr_Input_v3float %P %20
  410. %49 = OpLoad %v3float %48
  411. %50 = OpCompositeExtract %float %49 0
  412. %51 = OpCompositeExtract %float %49 1
  413. %52 = OpCompositeExtract %float %49 2
  414. %53 = OpCompositeConstruct %v4float %50 %51 %52 %float_1
  415. %62 = OpAccessChain %_ptr_Output_v4float %gl_out %20 %int_0
  416. OpStore %62 %53
  417. OpReturn
  418. OpFunctionEnd
  419. )";
  420. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  421. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  422. std::unordered_set<uint32_t> live_inputs;
  423. std::unordered_set<uint32_t> live_builtins;
  424. live_inputs.insert(5);
  425. live_inputs.insert(10);
  426. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  427. &live_builtins);
  428. }
  429. TEST_F(ElimDeadOutputStoresTest, ArrayedOutputMemberLocs) {
  430. // Tests elimination of member location with arrayed output as seen in
  431. // Tesc shaders.
  432. //
  433. // #version 450
  434. //
  435. // layout (vertices = 4) out;
  436. //
  437. // layout (location = 0) in vec3 N[];
  438. // layout (location = 1) in vec3 P[];
  439. //
  440. // out Vertex
  441. // {
  442. // layout (location = 1) vec4 c;
  443. // layout (location = 3) vec3 n;
  444. // layout (location = 5) vec3 f[10];
  445. // } oVert[];
  446. //
  447. // void main()
  448. // {
  449. // oVert[gl_InvocationID].c = vec4(1, 0, 0, 1);
  450. // oVert[gl_InvocationID].n = N[gl_InvocationID];
  451. // oVert[gl_InvocationID].f[3] = vec3(0, 1, 0);
  452. // vec4 worldSpacePos = vec4(P[gl_InvocationID], 1);
  453. // gl_out[gl_InvocationID].gl_Position = worldSpacePos;
  454. // }
  455. const std::string text = R"(
  456. OpCapability Tessellation
  457. %1 = OpExtInstImport "GLSL.std.450"
  458. OpMemoryModel Logical GLSL450
  459. OpEntryPoint TessellationControl %main "main" %oVert %gl_InvocationID %N %P %gl_out
  460. OpExecutionMode %main OutputVertices 4
  461. OpSource GLSL 450
  462. OpName %main "main"
  463. OpName %Vertex "Vertex"
  464. OpMemberName %Vertex 0 "c"
  465. OpMemberName %Vertex 1 "n"
  466. OpMemberName %Vertex 2 "f"
  467. OpName %oVert "oVert"
  468. OpName %gl_InvocationID "gl_InvocationID"
  469. OpName %N "N"
  470. OpName %P "P"
  471. OpName %gl_PerVertex "gl_PerVertex"
  472. OpMemberName %gl_PerVertex 0 "gl_Position"
  473. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  474. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  475. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  476. OpName %gl_out "gl_out"
  477. OpMemberDecorate %Vertex 0 Location 1
  478. OpMemberDecorate %Vertex 1 Location 3
  479. OpMemberDecorate %Vertex 2 Location 5
  480. OpDecorate %Vertex Block
  481. OpDecorate %gl_InvocationID BuiltIn InvocationId
  482. OpDecorate %N Location 0
  483. OpDecorate %P Location 1
  484. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  485. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  486. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  487. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  488. OpDecorate %gl_PerVertex Block
  489. %void = OpTypeVoid
  490. %3 = OpTypeFunction %void
  491. %float = OpTypeFloat 32
  492. %v4float = OpTypeVector %float 4
  493. %v3float = OpTypeVector %float 3
  494. %uint = OpTypeInt 32 0
  495. %uint_10 = OpConstant %uint 10
  496. %_arr_v3float_uint_10 = OpTypeArray %v3float %uint_10
  497. %Vertex = OpTypeStruct %v4float %v3float %_arr_v3float_uint_10
  498. %uint_4 = OpConstant %uint 4
  499. %_arr_Vertex_uint_4 = OpTypeArray %Vertex %uint_4
  500. %_ptr_Output__arr_Vertex_uint_4 = OpTypePointer Output %_arr_Vertex_uint_4
  501. %oVert = OpVariable %_ptr_Output__arr_Vertex_uint_4 Output
  502. %int = OpTypeInt 32 1
  503. %_ptr_Input_int = OpTypePointer Input %int
  504. %gl_InvocationID = OpVariable %_ptr_Input_int Input
  505. %int_0 = OpConstant %int 0
  506. %float_1 = OpConstant %float 1
  507. %float_0 = OpConstant %float 0
  508. %24 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
  509. %_ptr_Output_v4float = OpTypePointer Output %v4float
  510. %int_1 = OpConstant %int 1
  511. %uint_32 = OpConstant %uint 32
  512. %_arr_v3float_uint_32 = OpTypeArray %v3float %uint_32
  513. %_ptr_Input__arr_v3float_uint_32 = OpTypePointer Input %_arr_v3float_uint_32
  514. %N = OpVariable %_ptr_Input__arr_v3float_uint_32 Input
  515. %_ptr_Input_v3float = OpTypePointer Input %v3float
  516. %_ptr_Output_v3float = OpTypePointer Output %v3float
  517. %int_2 = OpConstant %int 2
  518. %int_3 = OpConstant %int 3
  519. %42 = OpConstantComposite %v3float %float_0 %float_1 %float_0
  520. %P = OpVariable %_ptr_Input__arr_v3float_uint_32 Input
  521. %uint_1 = OpConstant %uint 1
  522. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  523. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  524. %_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
  525. %_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
  526. %gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
  527. %main = OpFunction %void None %3
  528. %5 = OpLabel
  529. %20 = OpLoad %int %gl_InvocationID
  530. %26 = OpAccessChain %_ptr_Output_v4float %oVert %20 %int_0
  531. OpStore %26 %24
  532. ;CHECK: OpStore %26 %24
  533. %35 = OpAccessChain %_ptr_Input_v3float %N %20
  534. %36 = OpLoad %v3float %35
  535. %38 = OpAccessChain %_ptr_Output_v3float %oVert %20 %int_1
  536. OpStore %38 %36
  537. ;CHECK-NOT: OpStore %38 %36
  538. %43 = OpAccessChain %_ptr_Output_v3float %oVert %20 %int_2 %int_3
  539. OpStore %43 %42
  540. ;CHECK: OpStore %43 %42
  541. %48 = OpAccessChain %_ptr_Input_v3float %P %20
  542. %49 = OpLoad %v3float %48
  543. %50 = OpCompositeExtract %float %49 0
  544. %51 = OpCompositeExtract %float %49 1
  545. %52 = OpCompositeExtract %float %49 2
  546. %53 = OpCompositeConstruct %v4float %50 %51 %52 %float_1
  547. %62 = OpAccessChain %_ptr_Output_v4float %gl_out %20 %int_0
  548. OpStore %62 %53
  549. OpReturn
  550. OpFunctionEnd
  551. )";
  552. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  553. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  554. std::unordered_set<uint32_t> live_inputs;
  555. std::unordered_set<uint32_t> live_builtins;
  556. live_inputs.insert(1);
  557. live_inputs.insert(8);
  558. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  559. &live_builtins);
  560. }
  561. TEST_F(ElimDeadOutputStoresTest, ScalarBuiltins) {
  562. // Tests elimination of scalar builtins as seen in vert shaders.
  563. //
  564. // #version 460
  565. //
  566. // layout (location = 0) in vec3 P;
  567. //
  568. // void main()
  569. // {
  570. // gl_Position = vec4(P, 1.0);
  571. // gl_PointSize = 1.0;
  572. // }
  573. const std::string text = R"(
  574. OpCapability Shader
  575. %1 = OpExtInstImport "GLSL.std.450"
  576. OpMemoryModel Logical GLSL450
  577. OpEntryPoint Vertex %main "main" %_ %P
  578. OpSource GLSL 460
  579. OpName %main "main"
  580. OpName %gl_PerVertex "gl_PerVertex"
  581. OpMemberName %gl_PerVertex 0 "gl_Position"
  582. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  583. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  584. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  585. OpName %_ ""
  586. OpName %P "P"
  587. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  588. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  589. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  590. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  591. OpDecorate %gl_PerVertex Block
  592. OpDecorate %P Location 0
  593. %void = OpTypeVoid
  594. %3 = OpTypeFunction %void
  595. %float = OpTypeFloat 32
  596. %v4float = OpTypeVector %float 4
  597. %uint = OpTypeInt 32 0
  598. %uint_1 = OpConstant %uint 1
  599. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  600. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  601. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  602. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  603. %int = OpTypeInt 32 1
  604. %int_0 = OpConstant %int 0
  605. %v3float = OpTypeVector %float 3
  606. %_ptr_Input_v3float = OpTypePointer Input %v3float
  607. %P = OpVariable %_ptr_Input_v3float Input
  608. %float_1 = OpConstant %float 1
  609. %_ptr_Output_v4float = OpTypePointer Output %v4float
  610. %int_1 = OpConstant %int 1
  611. %_ptr_Output_float = OpTypePointer Output %float
  612. %main = OpFunction %void None %3
  613. %5 = OpLabel
  614. %19 = OpLoad %v3float %P
  615. %21 = OpCompositeExtract %float %19 0
  616. %22 = OpCompositeExtract %float %19 1
  617. %23 = OpCompositeExtract %float %19 2
  618. %24 = OpCompositeConstruct %v4float %21 %22 %23 %float_1
  619. %26 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  620. OpStore %26 %24
  621. ;CHECK: OpStore %26 %24
  622. %29 = OpAccessChain %_ptr_Output_float %_ %int_1
  623. OpStore %29 %float_1
  624. ;CHECK-NOT: OpStore %29 %float_1
  625. OpReturn
  626. OpFunctionEnd
  627. )";
  628. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  629. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  630. std::unordered_set<uint32_t> live_inputs;
  631. std::unordered_set<uint32_t> live_builtins;
  632. // Omit spv::BuiltIn::PointSize
  633. live_builtins.insert((uint32_t)spv::BuiltIn::ClipDistance);
  634. live_builtins.insert((uint32_t)spv::BuiltIn::CullDistance);
  635. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  636. &live_builtins);
  637. }
  638. TEST_F(ElimDeadOutputStoresTest, ArrayedBuiltins) {
  639. // Tests elimination of arrayed builtins as seen in geom, tesc, and tese
  640. // shaders.
  641. //
  642. // #version 460
  643. //
  644. // layout(triangle_strip, max_vertices = 3) out;
  645. // layout(triangles) in;
  646. //
  647. // void main()
  648. // {
  649. // for (int i = 0; i < 3; i++)
  650. // {
  651. // gl_Position = gl_in[i].gl_Position;
  652. // gl_PointSize = gl_in[i].gl_PointSize;
  653. //
  654. // EmitVertex();
  655. // }
  656. //
  657. // EndPrimitive();
  658. // }
  659. const std::string text = R"(
  660. OpCapability Geometry
  661. OpCapability GeometryPointSize
  662. %1 = OpExtInstImport "GLSL.std.450"
  663. OpMemoryModel Logical GLSL450
  664. OpEntryPoint Geometry %main "main" %_ %gl_in
  665. OpExecutionMode %main Triangles
  666. OpExecutionMode %main Invocations 1
  667. OpExecutionMode %main OutputTriangleStrip
  668. OpExecutionMode %main OutputVertices 3
  669. OpSource GLSL 460
  670. OpName %main "main"
  671. OpName %i "i"
  672. OpName %gl_PerVertex "gl_PerVertex"
  673. OpMemberName %gl_PerVertex 0 "gl_Position"
  674. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  675. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  676. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  677. OpName %_ ""
  678. OpName %gl_PerVertex_0 "gl_PerVertex"
  679. OpMemberName %gl_PerVertex_0 0 "gl_Position"
  680. OpMemberName %gl_PerVertex_0 1 "gl_PointSize"
  681. OpMemberName %gl_PerVertex_0 2 "gl_ClipDistance"
  682. OpMemberName %gl_PerVertex_0 3 "gl_CullDistance"
  683. OpName %gl_in "gl_in"
  684. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  685. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  686. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  687. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  688. OpDecorate %gl_PerVertex Block
  689. OpMemberDecorate %gl_PerVertex_0 0 BuiltIn Position
  690. OpMemberDecorate %gl_PerVertex_0 1 BuiltIn PointSize
  691. OpMemberDecorate %gl_PerVertex_0 2 BuiltIn ClipDistance
  692. OpMemberDecorate %gl_PerVertex_0 3 BuiltIn CullDistance
  693. OpDecorate %gl_PerVertex_0 Block
  694. %void = OpTypeVoid
  695. %3 = OpTypeFunction %void
  696. %int = OpTypeInt 32 1
  697. %_ptr_Function_int = OpTypePointer Function %int
  698. %int_0 = OpConstant %int 0
  699. %int_3 = OpConstant %int 3
  700. %bool = OpTypeBool
  701. %float = OpTypeFloat 32
  702. %v4float = OpTypeVector %float 4
  703. %uint = OpTypeInt 32 0
  704. %uint_1 = OpConstant %uint 1
  705. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  706. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  707. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  708. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  709. %gl_PerVertex_0 = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  710. %uint_3 = OpConstant %uint 3
  711. %_arr_gl_PerVertex_0_uint_3 = OpTypeArray %gl_PerVertex_0 %uint_3
  712. %_ptr_Input__arr_gl_PerVertex_0_uint_3 = OpTypePointer Input %_arr_gl_PerVertex_0_uint_3
  713. %gl_in = OpVariable %_ptr_Input__arr_gl_PerVertex_0_uint_3 Input
  714. %_ptr_Input_v4float = OpTypePointer Input %v4float
  715. %_ptr_Output_v4float = OpTypePointer Output %v4float
  716. %int_1 = OpConstant %int 1
  717. %_ptr_Input_float = OpTypePointer Input %float
  718. %_ptr_Output_float = OpTypePointer Output %float
  719. %main = OpFunction %void None %3
  720. %5 = OpLabel
  721. %i = OpVariable %_ptr_Function_int Function
  722. OpStore %i %int_0
  723. OpBranch %10
  724. %10 = OpLabel
  725. OpLoopMerge %12 %13 None
  726. OpBranch %14
  727. %14 = OpLabel
  728. %15 = OpLoad %int %i
  729. %18 = OpSLessThan %bool %15 %int_3
  730. OpBranchConditional %18 %11 %12
  731. %11 = OpLabel
  732. %32 = OpLoad %int %i
  733. %34 = OpAccessChain %_ptr_Input_v4float %gl_in %32 %int_0
  734. %35 = OpLoad %v4float %34
  735. %37 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  736. OpStore %37 %35
  737. ;CHECK: OpStore %37 %35
  738. %39 = OpLoad %int %i
  739. %41 = OpAccessChain %_ptr_Input_float %gl_in %39 %int_1
  740. %42 = OpLoad %float %41
  741. %44 = OpAccessChain %_ptr_Output_float %_ %int_1
  742. OpStore %44 %42
  743. ;CHECK-NOT: OpStore %44 %42
  744. OpEmitVertex
  745. OpBranch %13
  746. %13 = OpLabel
  747. %45 = OpLoad %int %i
  748. %46 = OpIAdd %int %45 %int_1
  749. OpStore %i %46
  750. OpBranch %10
  751. %12 = OpLabel
  752. OpEndPrimitive
  753. OpReturn
  754. OpFunctionEnd
  755. )";
  756. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  757. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  758. std::unordered_set<uint32_t> live_inputs;
  759. std::unordered_set<uint32_t> live_builtins;
  760. // Omit spv::BuiltIn::PointSize
  761. live_builtins.insert((uint32_t)spv::BuiltIn::ClipDistance);
  762. live_builtins.insert((uint32_t)spv::BuiltIn::CullDistance);
  763. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  764. &live_builtins);
  765. }
  766. TEST_F(ElimDeadOutputStoresTest, ArrayedOutputPatchLocs) {
  767. // Tests elimination of location with arrayed patch output as seen in
  768. // Tesc shaders.
  769. //
  770. // #version 450 core
  771. //
  772. // layout(vertices = 4) out;
  773. //
  774. // layout(location=0) patch out float patchOut0[2];
  775. // layout(location=2) patch out float patchOut1[2];
  776. //
  777. // void main()
  778. // {
  779. // patchOut0[1] = 0.0; // Dead loc 1
  780. // patchOut1[1] = 1.0; // Live loc 3
  781. // }
  782. const std::string text = R"(
  783. OpCapability Tessellation
  784. %1 = OpExtInstImport "GLSL.std.450"
  785. OpMemoryModel Logical GLSL450
  786. OpEntryPoint TessellationControl %main "main" %patchOut0 %patchOut1
  787. OpExecutionMode %main OutputVertices 4
  788. OpSource GLSL 450
  789. OpName %main "main"
  790. OpName %patchOut0 "patchOut0"
  791. OpName %patchOut1 "patchOut1"
  792. OpDecorate %patchOut0 Patch
  793. OpDecorate %patchOut0 Location 0
  794. OpDecorate %patchOut1 Patch
  795. OpDecorate %patchOut1 Location 2
  796. %void = OpTypeVoid
  797. %3 = OpTypeFunction %void
  798. %float = OpTypeFloat 32
  799. %uint = OpTypeInt 32 0
  800. %uint_2 = OpConstant %uint 2
  801. %_arr_float_uint_2 = OpTypeArray %float %uint_2
  802. %_ptr_Output__arr_float_uint_2 = OpTypePointer Output %_arr_float_uint_2
  803. %patchOut0 = OpVariable %_ptr_Output__arr_float_uint_2 Output
  804. %int = OpTypeInt 32 1
  805. %int_1 = OpConstant %int 1
  806. %float_0 = OpConstant %float 0
  807. %_ptr_Output_float = OpTypePointer Output %float
  808. %patchOut1 = OpVariable %_ptr_Output__arr_float_uint_2 Output
  809. %float_1 = OpConstant %float 1
  810. %main = OpFunction %void None %3
  811. %5 = OpLabel
  812. %16 = OpAccessChain %_ptr_Output_float %patchOut0 %int_1
  813. OpStore %16 %float_0
  814. ;CHECK-NOT: OpStore %16 %float_0
  815. %19 = OpAccessChain %_ptr_Output_float %patchOut1 %int_1
  816. OpStore %19 %float_1
  817. ;CHECK: OpStore %19 %float_1
  818. OpReturn
  819. OpFunctionEnd
  820. )";
  821. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  822. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  823. std::unordered_set<uint32_t> live_inputs;
  824. std::unordered_set<uint32_t> live_builtins;
  825. live_inputs.insert(3);
  826. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  827. &live_builtins);
  828. }
  829. TEST_F(ElimDeadOutputStoresTest, VertMultipleLocationsF16) {
  830. // #version 450
  831. //
  832. // layout(location = 2) out Vertex
  833. // {
  834. // f16vec4 color0;
  835. // f16vec4 color1;
  836. // f16vec4 color2[3];
  837. // } oVert;
  838. //
  839. // void main()
  840. // {
  841. // oVert.color0 = f16vec4(0.0,0.0,0.0,0.0);
  842. // oVert.color1 = f16vec4(0.1,0.0,0.0,0.0);
  843. // oVert.color2[0] = f16vec4(0.2,0.0,0.0,0.0);
  844. // oVert.color2[1] = f16vec4(0.3,0.0,0.0,0.0);
  845. // oVert.color2[2] = f16vec4(0.4,0.0,0.0,0.0);
  846. // }
  847. const std::string text = R"(
  848. OpCapability Shader
  849. OpCapability Float16
  850. OpCapability StorageInputOutput16
  851. %1 = OpExtInstImport "GLSL.std.450"
  852. OpMemoryModel Logical GLSL450
  853. OpEntryPoint Vertex %main "main" %oVert
  854. OpSource GLSL 450
  855. OpName %main "main"
  856. OpName %Vertex "Vertex"
  857. OpMemberName %Vertex 0 "color0"
  858. OpMemberName %Vertex 1 "color1"
  859. OpMemberName %Vertex 2 "color2"
  860. OpName %oVert "oVert"
  861. OpDecorate %Vertex Block
  862. OpDecorate %oVert Location 2
  863. %void = OpTypeVoid
  864. %3 = OpTypeFunction %void
  865. %half = OpTypeFloat 32
  866. %v4half = OpTypeVector %half 4
  867. %uint = OpTypeInt 32 0
  868. %uint_3 = OpConstant %uint 3
  869. %_arr_v4half_uint_3 = OpTypeArray %v4half %uint_3
  870. %Vertex = OpTypeStruct %v4half %v4half %_arr_v4half_uint_3
  871. %_ptr_Output_Vertex = OpTypePointer Output %Vertex
  872. %oVert = OpVariable %_ptr_Output_Vertex Output
  873. %int = OpTypeInt 32 1
  874. %int_0 = OpConstant %int 0
  875. %half_0 = OpConstant %half 0
  876. %17 = OpConstantComposite %v4half %half_0 %half_0 %half_0 %half_0
  877. %_ptr_Output_v4half = OpTypePointer Output %v4half
  878. %int_1 = OpConstant %int 1
  879. %half_0_100000001 = OpConstant %half 0.100000001
  880. %22 = OpConstantComposite %v4half %half_0_100000001 %half_0 %half_0 %half_0
  881. %int_2 = OpConstant %int 2
  882. %half_0_200000003 = OpConstant %half 0.200000003
  883. %26 = OpConstantComposite %v4half %half_0_200000003 %half_0 %half_0 %half_0
  884. %half_0_300000012 = OpConstant %half 0.300000012
  885. %29 = OpConstantComposite %v4half %half_0_300000012 %half_0 %half_0 %half_0
  886. %half_0_400000006 = OpConstant %half 0.400000006
  887. %32 = OpConstantComposite %v4half %half_0_400000006 %half_0 %half_0 %half_0
  888. %main = OpFunction %void None %3
  889. %5 = OpLabel
  890. %19 = OpAccessChain %_ptr_Output_v4half %oVert %int_0
  891. OpStore %19 %17
  892. ;CHECK: OpStore %19 %17
  893. %23 = OpAccessChain %_ptr_Output_v4half %oVert %int_1
  894. OpStore %23 %22
  895. ;CHECK-NOT: OpStore %23 %22
  896. %27 = OpAccessChain %_ptr_Output_v4half %oVert %int_2 %int_0
  897. OpStore %27 %26
  898. ;CHECK-NOT: OpStore %27 %26
  899. %30 = OpAccessChain %_ptr_Output_v4half %oVert %int_2 %int_1
  900. OpStore %30 %29
  901. ;CHECK: OpStore %30 %29
  902. %33 = OpAccessChain %_ptr_Output_v4half %oVert %int_2 %int_2
  903. OpStore %33 %32
  904. ;CHECK-NOT: OpStore %33 %32
  905. OpReturn
  906. OpFunctionEnd
  907. )";
  908. SetTargetEnv(SPV_ENV_VULKAN_1_3);
  909. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  910. std::unordered_set<uint32_t> live_inputs;
  911. std::unordered_set<uint32_t> live_builtins;
  912. live_inputs.insert(2);
  913. live_inputs.insert(5);
  914. SinglePassRunAndMatch<EliminateDeadOutputStoresPass>(text, true, &live_inputs,
  915. &live_builtins);
  916. }
  917. } // namespace
  918. } // namespace opt
  919. } // namespace spvtools