1fd4e5da5Sopenharmony_ci// Copyright (c) 2019 Google LLC. 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include <vector> 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include "gmock/gmock.h" 18fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h" 19fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h" 20fd4e5da5Sopenharmony_ci 21fd4e5da5Sopenharmony_cinamespace spvtools { 22fd4e5da5Sopenharmony_cinamespace opt { 23fd4e5da5Sopenharmony_cinamespace { 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_ciusing AmdExtToKhrTest = PassTest<::testing::Test>; 26fd4e5da5Sopenharmony_ci 27fd4e5da5Sopenharmony_ciusing ::testing::HasSubstr; 28fd4e5da5Sopenharmony_ci 29fd4e5da5Sopenharmony_cistd::string GetTest(std::string op_code, std::string new_op_code, 30fd4e5da5Sopenharmony_ci bool is_float = false) { 31fd4e5da5Sopenharmony_ci const std::string text = R"( 32fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 33fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot" 34fd4e5da5Sopenharmony_ci; CHECK: OpFunction 35fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 36fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[undef:%\w+]] = OpUndef % 37fd4e5da5Sopenharmony_ci; CHECK-NEXT: )" + new_op_code + 38fd4e5da5Sopenharmony_ci " %" + (is_float ? "float" : "uint") + 39fd4e5da5Sopenharmony_ci R"( %uint_3 Reduce [[undef]] 40fd4e5da5Sopenharmony_ci OpCapability Shader 41fd4e5da5Sopenharmony_ci OpCapability Groups 42fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 43fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 44fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 45fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 46fd4e5da5Sopenharmony_ci %void = OpTypeVoid 47fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 48fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 49fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 50fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 51fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 52fd4e5da5Sopenharmony_ci %6 = OpLabel 53fd4e5da5Sopenharmony_ci %7 = OpUndef %)" + 54fd4e5da5Sopenharmony_ci (is_float ? "float" : "uint") + R"( 55fd4e5da5Sopenharmony_ci %8 = )" + op_code + 56fd4e5da5Sopenharmony_ci " %" + (is_float ? "float" : "uint") + 57fd4e5da5Sopenharmony_ci R"( %uint_3 Reduce %7 58fd4e5da5Sopenharmony_ci OpReturn 59fd4e5da5Sopenharmony_ci OpFunctionEnd 60fd4e5da5Sopenharmony_ci 61fd4e5da5Sopenharmony_ci)"; 62fd4e5da5Sopenharmony_ci return text; 63fd4e5da5Sopenharmony_ci} 64fd4e5da5Sopenharmony_ci 65fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupIAddNonUniformAMD) { 66fd4e5da5Sopenharmony_ci std::string text = 67fd4e5da5Sopenharmony_ci GetTest("OpGroupIAddNonUniformAMD", "OpGroupNonUniformIAdd"); 68fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 69fd4e5da5Sopenharmony_ci} 70fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupFAddNonUniformAMD) { 71fd4e5da5Sopenharmony_ci std::string text = 72fd4e5da5Sopenharmony_ci GetTest("OpGroupFAddNonUniformAMD", "OpGroupNonUniformFAdd", true); 73fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 74fd4e5da5Sopenharmony_ci} 75fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupUMinNonUniformAMD) { 76fd4e5da5Sopenharmony_ci std::string text = 77fd4e5da5Sopenharmony_ci GetTest("OpGroupUMinNonUniformAMD", "OpGroupNonUniformUMin"); 78fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 79fd4e5da5Sopenharmony_ci} 80fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupSMinNonUniformAMD) { 81fd4e5da5Sopenharmony_ci std::string text = 82fd4e5da5Sopenharmony_ci GetTest("OpGroupSMinNonUniformAMD", "OpGroupNonUniformSMin"); 83fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 84fd4e5da5Sopenharmony_ci} 85fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupFMinNonUniformAMD) { 86fd4e5da5Sopenharmony_ci std::string text = 87fd4e5da5Sopenharmony_ci GetTest("OpGroupFMinNonUniformAMD", "OpGroupNonUniformFMin", true); 88fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 89fd4e5da5Sopenharmony_ci} 90fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupUMaxNonUniformAMD) { 91fd4e5da5Sopenharmony_ci std::string text = 92fd4e5da5Sopenharmony_ci GetTest("OpGroupUMaxNonUniformAMD", "OpGroupNonUniformUMax"); 93fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 94fd4e5da5Sopenharmony_ci} 95fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupSMaxNonUniformAMD) { 96fd4e5da5Sopenharmony_ci std::string text = 97fd4e5da5Sopenharmony_ci GetTest("OpGroupSMaxNonUniformAMD", "OpGroupNonUniformSMax"); 98fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 99fd4e5da5Sopenharmony_ci} 100fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceGroupFMaxNonUniformAMD) { 101fd4e5da5Sopenharmony_ci std::string text = 102fd4e5da5Sopenharmony_ci GetTest("OpGroupFMaxNonUniformAMD", "OpGroupNonUniformFMax", true); 103fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 104fd4e5da5Sopenharmony_ci} 105fd4e5da5Sopenharmony_ci 106fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceMbcntAMD) { 107fd4e5da5Sopenharmony_ci const std::string text = R"( 108fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 109fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot" 110fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_ballot" 111fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn SubgroupLtMask 112fd4e5da5Sopenharmony_ci; CHECK: [[var]] = OpVariable %_ptr_Input_v4uint Input 113fd4e5da5Sopenharmony_ci; CHECK: OpFunction 114fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 115fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[ld:%\w+]] = OpLoad %v4uint [[var]] 116fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[shuffle:%\w+]] = OpVectorShuffle %v2uint [[ld]] [[ld]] 0 1 117fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[bitcast:%\w+]] = OpBitcast %ulong [[shuffle]] 118fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[and:%\w+]] = OpBitwiseAnd %ulong [[bitcast]] %ulong_0 119fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpBitCount %uint [[and]] 120fd4e5da5Sopenharmony_ci OpCapability Shader 121fd4e5da5Sopenharmony_ci OpCapability Int64 122fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 123fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "SPV_AMD_shader_ballot" 124fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 125fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %2 "func" 126fd4e5da5Sopenharmony_ci OpExecutionMode %2 OriginUpperLeft 127fd4e5da5Sopenharmony_ci %void = OpTypeVoid 128fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void 129fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 130fd4e5da5Sopenharmony_ci %ulong = OpTypeInt 64 0 131fd4e5da5Sopenharmony_ci %ulong_0 = OpConstant %ulong 0 132fd4e5da5Sopenharmony_ci %2 = OpFunction %void None %4 133fd4e5da5Sopenharmony_ci %8 = OpLabel 134fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %1 MbcntAMD %ulong_0 135fd4e5da5Sopenharmony_ci OpReturn 136fd4e5da5Sopenharmony_ci OpFunctionEnd 137fd4e5da5Sopenharmony_ci)"; 138fd4e5da5Sopenharmony_ci 139fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 140fd4e5da5Sopenharmony_ci} 141fd4e5da5Sopenharmony_ci 142fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceSwizzleInvocationsAMD) { 143fd4e5da5Sopenharmony_ci const std::string text = R"( 144fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 145fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot" 146fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_ballot" 147fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn SubgroupLocalInvocationId 148fd4e5da5Sopenharmony_ci; CHECK: [[subgroup:%\w+]] = OpConstant %uint 3 149fd4e5da5Sopenharmony_ci; CHECK: [[offset:%\w+]] = OpConstantComposite %v4uint 150fd4e5da5Sopenharmony_ci; CHECK: [[var]] = OpVariable %_ptr_Input_uint Input 151fd4e5da5Sopenharmony_ci; CHECK: [[uint_max:%\w+]] = OpConstant %uint 4294967295 152fd4e5da5Sopenharmony_ci; CHECK: [[ballot_value:%\w+]] = OpConstantComposite %v4uint [[uint_max]] [[uint_max]] [[uint_max]] [[uint_max]] 153fd4e5da5Sopenharmony_ci; CHECK: [[null:%\w+]] = OpConstantNull [[type:%\w+]] 154fd4e5da5Sopenharmony_ci; CHECK: OpFunction 155fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 156fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[data:%\w+]] = OpUndef [[type]] 157fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[id:%\w+]] = OpLoad %uint [[var]] 158fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[quad_idx:%\w+]] = OpBitwiseAnd %uint [[id]] %uint_3 159fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[quad_ldr:%\w+]] = OpBitwiseXor %uint [[id]] [[quad_idx]] 160fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[my_offset:%\w+]] = OpVectorExtractDynamic %uint [[offset]] [[quad_idx]] 161fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target_inv:%\w+]] = OpIAdd %uint [[quad_ldr]] [[my_offset]] 162fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[is_active:%\w+]] = OpGroupNonUniformBallotBitExtract %bool [[subgroup]] [[ballot_value]] [[target_inv]] 163fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[shuffle:%\w+]] = OpGroupNonUniformShuffle [[type]] [[subgroup]] [[data]] [[target_inv]] 164fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpSelect [[type]] [[is_active]] [[shuffle]] [[null]] 165fd4e5da5Sopenharmony_ci OpCapability Shader 166fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 167fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_ballot" 168fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 169fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 170fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 171fd4e5da5Sopenharmony_ci %void = OpTypeVoid 172fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 173fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 174fd4e5da5Sopenharmony_ci %uint_x = OpConstant %uint 1 175fd4e5da5Sopenharmony_ci %uint_y = OpConstant %uint 2 176fd4e5da5Sopenharmony_ci %uint_z = OpConstant %uint 3 177fd4e5da5Sopenharmony_ci %uint_w = OpConstant %uint 0 178fd4e5da5Sopenharmony_ci %v4uint = OpTypeVector %uint 4 179fd4e5da5Sopenharmony_ci %offset = OpConstantComposite %v4uint %uint_x %uint_y %uint_z %uint_x 180fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 181fd4e5da5Sopenharmony_ci %6 = OpLabel 182fd4e5da5Sopenharmony_ci %data = OpUndef %uint 183fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %ext SwizzleInvocationsAMD %data %offset 184fd4e5da5Sopenharmony_ci OpReturn 185fd4e5da5Sopenharmony_ci OpFunctionEnd 186fd4e5da5Sopenharmony_ci)"; 187fd4e5da5Sopenharmony_ci 188fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 189fd4e5da5Sopenharmony_ci} 190fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceSwizzleInvocationsMaskedAMD) { 191fd4e5da5Sopenharmony_ci const std::string text = R"( 192fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 193fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot" 194fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_ballot" 195fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn SubgroupLocalInvocationId 196fd4e5da5Sopenharmony_ci; CHECK: [[x:%\w+]] = OpConstant %uint 19 197fd4e5da5Sopenharmony_ci; CHECK: [[y:%\w+]] = OpConstant %uint 12 198fd4e5da5Sopenharmony_ci; CHECK: [[z:%\w+]] = OpConstant %uint 16 199fd4e5da5Sopenharmony_ci; CHECK: [[var]] = OpVariable %_ptr_Input_uint Input 200fd4e5da5Sopenharmony_ci; CHECK: [[mask_extend:%\w+]] = OpConstant %uint 4294967264 201fd4e5da5Sopenharmony_ci; CHECK: [[uint_max:%\w+]] = OpConstant %uint 4294967295 202fd4e5da5Sopenharmony_ci; CHECK: [[subgroup:%\w+]] = OpConstant %uint 3 203fd4e5da5Sopenharmony_ci; CHECK: [[ballot_value:%\w+]] = OpConstantComposite %v4uint [[uint_max]] [[uint_max]] [[uint_max]] [[uint_max]] 204fd4e5da5Sopenharmony_ci; CHECK: [[null:%\w+]] = OpConstantNull [[type:%\w+]] 205fd4e5da5Sopenharmony_ci; CHECK: OpFunction 206fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 207fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[data:%\w+]] = OpUndef [[type]] 208fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[id:%\w+]] = OpLoad %uint [[var]] 209fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[and_mask:%\w+]] = OpBitwiseOr %uint [[x]] [[mask_extend]] 210fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[and:%\w+]] = OpBitwiseAnd %uint [[id]] [[and_mask]] 211fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[or:%\w+]] = OpBitwiseOr %uint [[and]] [[y]] 212fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target_inv:%\w+]] = OpBitwiseXor %uint [[or]] [[z]] 213fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[is_active:%\w+]] = OpGroupNonUniformBallotBitExtract %bool [[subgroup]] [[ballot_value]] [[target_inv]] 214fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[shuffle:%\w+]] = OpGroupNonUniformShuffle [[type]] [[subgroup]] [[data]] [[target_inv]] 215fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpSelect [[type]] [[is_active]] [[shuffle]] [[null]] 216fd4e5da5Sopenharmony_ci OpCapability Shader 217fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 218fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_ballot" 219fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 220fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 221fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 222fd4e5da5Sopenharmony_ci %void = OpTypeVoid 223fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 224fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 225fd4e5da5Sopenharmony_ci %uint_x = OpConstant %uint 19 226fd4e5da5Sopenharmony_ci %uint_y = OpConstant %uint 12 227fd4e5da5Sopenharmony_ci %uint_z = OpConstant %uint 16 228fd4e5da5Sopenharmony_ci %v3uint = OpTypeVector %uint 3 229fd4e5da5Sopenharmony_ci %mask = OpConstantComposite %v3uint %uint_x %uint_y %uint_z 230fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 231fd4e5da5Sopenharmony_ci %6 = OpLabel 232fd4e5da5Sopenharmony_ci %data = OpUndef %uint 233fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %ext SwizzleInvocationsMaskedAMD %data %mask 234fd4e5da5Sopenharmony_ci OpReturn 235fd4e5da5Sopenharmony_ci OpFunctionEnd 236fd4e5da5Sopenharmony_ci)"; 237fd4e5da5Sopenharmony_ci 238fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 239fd4e5da5Sopenharmony_ci} 240fd4e5da5Sopenharmony_ci 241fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceWriteInvocationAMD) { 242fd4e5da5Sopenharmony_ci const std::string text = R"( 243fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 244fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_ballot" 245fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_ballot" 246fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn SubgroupLocalInvocationId 247fd4e5da5Sopenharmony_ci; CHECK: [[var]] = OpVariable %_ptr_Input_uint Input 248fd4e5da5Sopenharmony_ci; CHECK: OpFunction 249fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 250fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[input_val:%\w+]] = OpUndef %uint 251fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[write_val:%\w+]] = OpUndef %uint 252fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[ld:%\w+]] = OpLoad %uint [[var]] 253fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[cmp:%\w+]] = OpIEqual %bool [[ld]] %uint_3 254fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpSelect %uint [[cmp]] [[write_val]] [[input_val]] 255fd4e5da5Sopenharmony_ci OpCapability Shader 256fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 257fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_ballot" 258fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 259fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 260fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 261fd4e5da5Sopenharmony_ci %void = OpTypeVoid 262fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 263fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 264fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 265fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 266fd4e5da5Sopenharmony_ci %6 = OpLabel 267fd4e5da5Sopenharmony_ci %7 = OpUndef %uint 268fd4e5da5Sopenharmony_ci %8 = OpUndef %uint 269fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %ext WriteInvocationAMD %7 %8 %uint_3 270fd4e5da5Sopenharmony_ci OpReturn 271fd4e5da5Sopenharmony_ci OpFunctionEnd 272fd4e5da5Sopenharmony_ci)"; 273fd4e5da5Sopenharmony_ci 274fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 275fd4e5da5Sopenharmony_ci} 276fd4e5da5Sopenharmony_ci 277fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceFMin3AMD) { 278fd4e5da5Sopenharmony_ci const std::string text = R"( 279fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 280fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 281fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 282fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 283fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeFloat 32 284fd4e5da5Sopenharmony_ci; CHECK: OpFunction 285fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 286fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 287fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 288fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 289fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] FMin [[x]] [[y]] 290fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] FMin [[temp]] [[z]] 291fd4e5da5Sopenharmony_ci OpCapability Shader 292fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 293fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 294fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 295fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 296fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 297fd4e5da5Sopenharmony_ci %void = OpTypeVoid 298fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 299fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 300fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 301fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 302fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 303fd4e5da5Sopenharmony_ci %6 = OpLabel 304fd4e5da5Sopenharmony_ci %7 = OpUndef %float 305fd4e5da5Sopenharmony_ci %8 = OpUndef %float 306fd4e5da5Sopenharmony_ci %9 = OpUndef %float 307fd4e5da5Sopenharmony_ci %10 = OpExtInst %float %ext FMin3AMD %7 %8 %9 308fd4e5da5Sopenharmony_ci OpReturn 309fd4e5da5Sopenharmony_ci OpFunctionEnd 310fd4e5da5Sopenharmony_ci)"; 311fd4e5da5Sopenharmony_ci 312fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 313fd4e5da5Sopenharmony_ci} 314fd4e5da5Sopenharmony_ci 315fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceSMin3AMD) { 316fd4e5da5Sopenharmony_ci const std::string text = R"( 317fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 318fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 319fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 320fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 321fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 1 322fd4e5da5Sopenharmony_ci; CHECK: OpFunction 323fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 324fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 325fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 326fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 327fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] SMin [[x]] [[y]] 328fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] SMin [[temp]] [[z]] 329fd4e5da5Sopenharmony_ci OpCapability Shader 330fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 331fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 332fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 333fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 334fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 335fd4e5da5Sopenharmony_ci %void = OpTypeVoid 336fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 337fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 338fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 339fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 340fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 341fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 342fd4e5da5Sopenharmony_ci %6 = OpLabel 343fd4e5da5Sopenharmony_ci %7 = OpUndef %int 344fd4e5da5Sopenharmony_ci %8 = OpUndef %int 345fd4e5da5Sopenharmony_ci %9 = OpUndef %int 346fd4e5da5Sopenharmony_ci %10 = OpExtInst %int %ext SMin3AMD %7 %8 %9 347fd4e5da5Sopenharmony_ci OpReturn 348fd4e5da5Sopenharmony_ci OpFunctionEnd 349fd4e5da5Sopenharmony_ci)"; 350fd4e5da5Sopenharmony_ci 351fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 352fd4e5da5Sopenharmony_ci} 353fd4e5da5Sopenharmony_ci 354fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceUMin3AMD) { 355fd4e5da5Sopenharmony_ci const std::string text = R"( 356fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 357fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 358fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 359fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 360fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 0 361fd4e5da5Sopenharmony_ci; CHECK: OpFunction 362fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 363fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 364fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 365fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 366fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] UMin [[x]] [[y]] 367fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] UMin [[temp]] [[z]] 368fd4e5da5Sopenharmony_ci OpCapability Shader 369fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 370fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 371fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 372fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 373fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 374fd4e5da5Sopenharmony_ci %void = OpTypeVoid 375fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 376fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 377fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 378fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 379fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 380fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 381fd4e5da5Sopenharmony_ci %6 = OpLabel 382fd4e5da5Sopenharmony_ci %7 = OpUndef %uint 383fd4e5da5Sopenharmony_ci %8 = OpUndef %uint 384fd4e5da5Sopenharmony_ci %9 = OpUndef %uint 385fd4e5da5Sopenharmony_ci %10 = OpExtInst %uint %ext UMin3AMD %7 %8 %9 386fd4e5da5Sopenharmony_ci OpReturn 387fd4e5da5Sopenharmony_ci OpFunctionEnd 388fd4e5da5Sopenharmony_ci)"; 389fd4e5da5Sopenharmony_ci 390fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 391fd4e5da5Sopenharmony_ci} 392fd4e5da5Sopenharmony_ci 393fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceFMax3AMD) { 394fd4e5da5Sopenharmony_ci const std::string text = R"( 395fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 396fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 397fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 398fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 399fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeFloat 32 400fd4e5da5Sopenharmony_ci; CHECK: OpFunction 401fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 402fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 403fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 404fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 405fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] FMax [[x]] [[y]] 406fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] FMax [[temp]] [[z]] 407fd4e5da5Sopenharmony_ci OpCapability Shader 408fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 409fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 410fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 411fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 412fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 413fd4e5da5Sopenharmony_ci %void = OpTypeVoid 414fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 415fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 416fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 417fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 418fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 419fd4e5da5Sopenharmony_ci %6 = OpLabel 420fd4e5da5Sopenharmony_ci %7 = OpUndef %float 421fd4e5da5Sopenharmony_ci %8 = OpUndef %float 422fd4e5da5Sopenharmony_ci %9 = OpUndef %float 423fd4e5da5Sopenharmony_ci %10 = OpExtInst %float %ext FMax3AMD %7 %8 %9 424fd4e5da5Sopenharmony_ci OpReturn 425fd4e5da5Sopenharmony_ci OpFunctionEnd 426fd4e5da5Sopenharmony_ci)"; 427fd4e5da5Sopenharmony_ci 428fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 429fd4e5da5Sopenharmony_ci} 430fd4e5da5Sopenharmony_ci 431fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceSMax3AMD) { 432fd4e5da5Sopenharmony_ci const std::string text = R"( 433fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 434fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 435fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 436fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 437fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 1 438fd4e5da5Sopenharmony_ci; CHECK: OpFunction 439fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 440fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 441fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 442fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 443fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] SMax [[x]] [[y]] 444fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] SMax [[temp]] [[z]] 445fd4e5da5Sopenharmony_ci OpCapability Shader 446fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 447fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 448fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 449fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 450fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 451fd4e5da5Sopenharmony_ci %void = OpTypeVoid 452fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 453fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 454fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 455fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 456fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 457fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 458fd4e5da5Sopenharmony_ci %6 = OpLabel 459fd4e5da5Sopenharmony_ci %7 = OpUndef %int 460fd4e5da5Sopenharmony_ci %8 = OpUndef %int 461fd4e5da5Sopenharmony_ci %9 = OpUndef %int 462fd4e5da5Sopenharmony_ci %10 = OpExtInst %int %ext SMax3AMD %7 %8 %9 463fd4e5da5Sopenharmony_ci OpReturn 464fd4e5da5Sopenharmony_ci OpFunctionEnd 465fd4e5da5Sopenharmony_ci)"; 466fd4e5da5Sopenharmony_ci 467fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 468fd4e5da5Sopenharmony_ci} 469fd4e5da5Sopenharmony_ci 470fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceUMax3AMD) { 471fd4e5da5Sopenharmony_ci const std::string text = R"( 472fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 473fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 474fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 475fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 476fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 0 477fd4e5da5Sopenharmony_ci; CHECK: OpFunction 478fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 479fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 480fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 481fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 482fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[x]] [[y]] 483fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[temp]] [[z]] 484fd4e5da5Sopenharmony_ci OpCapability Shader 485fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 486fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 487fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 488fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 489fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 490fd4e5da5Sopenharmony_ci %void = OpTypeVoid 491fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 492fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 493fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 494fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 495fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 496fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 497fd4e5da5Sopenharmony_ci %6 = OpLabel 498fd4e5da5Sopenharmony_ci %7 = OpUndef %uint 499fd4e5da5Sopenharmony_ci %8 = OpUndef %uint 500fd4e5da5Sopenharmony_ci %9 = OpUndef %uint 501fd4e5da5Sopenharmony_ci %10 = OpExtInst %uint %ext UMax3AMD %7 %8 %9 502fd4e5da5Sopenharmony_ci OpReturn 503fd4e5da5Sopenharmony_ci OpFunctionEnd 504fd4e5da5Sopenharmony_ci)"; 505fd4e5da5Sopenharmony_ci 506fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 507fd4e5da5Sopenharmony_ci} 508fd4e5da5Sopenharmony_ci 509fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceVecUMax3AMD) { 510fd4e5da5Sopenharmony_ci const std::string text = R"( 511fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 512fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 513fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 514fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 515fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeVector 516fd4e5da5Sopenharmony_ci; CHECK: OpFunction 517fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 518fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 519fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 520fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 521fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[temp:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[x]] [[y]] 522fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[temp]] [[z]] 523fd4e5da5Sopenharmony_ci OpCapability Shader 524fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 525fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 526fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 527fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 528fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 529fd4e5da5Sopenharmony_ci %void = OpTypeVoid 530fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 531fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 532fd4e5da5Sopenharmony_ci %vec = OpTypeVector %uint 4 533fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 534fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 535fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 536fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 537fd4e5da5Sopenharmony_ci %6 = OpLabel 538fd4e5da5Sopenharmony_ci %7 = OpUndef %vec 539fd4e5da5Sopenharmony_ci %8 = OpUndef %vec 540fd4e5da5Sopenharmony_ci %9 = OpUndef %vec 541fd4e5da5Sopenharmony_ci %10 = OpExtInst %vec %ext UMax3AMD %7 %8 %9 542fd4e5da5Sopenharmony_ci OpReturn 543fd4e5da5Sopenharmony_ci OpFunctionEnd 544fd4e5da5Sopenharmony_ci)"; 545fd4e5da5Sopenharmony_ci 546fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 547fd4e5da5Sopenharmony_ci} 548fd4e5da5Sopenharmony_ci 549fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceFMid3AMD) { 550fd4e5da5Sopenharmony_ci const std::string text = R"( 551fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 552fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 553fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 554fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 555fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeFloat 32 556fd4e5da5Sopenharmony_ci; CHECK: OpFunction 557fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 558fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 559fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 560fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 561fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[min:%\w+]] = OpExtInst [[type]] [[ext]] FMin [[y]] [[z]] 562fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[max:%\w+]] = OpExtInst [[type]] [[ext]] FMax [[y]] [[z]] 563fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] FClamp [[x]] [[min]] [[max]] 564fd4e5da5Sopenharmony_ci OpCapability Shader 565fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 566fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 567fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 568fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 569fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 570fd4e5da5Sopenharmony_ci %void = OpTypeVoid 571fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 572fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 573fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 574fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 575fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 576fd4e5da5Sopenharmony_ci %6 = OpLabel 577fd4e5da5Sopenharmony_ci %7 = OpUndef %float 578fd4e5da5Sopenharmony_ci %8 = OpUndef %float 579fd4e5da5Sopenharmony_ci %9 = OpUndef %float 580fd4e5da5Sopenharmony_ci %10 = OpExtInst %float %ext FMid3AMD %7 %8 %9 581fd4e5da5Sopenharmony_ci OpReturn 582fd4e5da5Sopenharmony_ci OpFunctionEnd 583fd4e5da5Sopenharmony_ci)"; 584fd4e5da5Sopenharmony_ci 585fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 586fd4e5da5Sopenharmony_ci} 587fd4e5da5Sopenharmony_ci 588fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceSMid3AMD) { 589fd4e5da5Sopenharmony_ci const std::string text = R"( 590fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 591fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 592fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 593fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 594fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 1 595fd4e5da5Sopenharmony_ci; CHECK: OpFunction 596fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 597fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 598fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 599fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 600fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[min:%\w+]] = OpExtInst [[type]] [[ext]] SMin [[y]] [[z]] 601fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[max:%\w+]] = OpExtInst [[type]] [[ext]] SMax [[y]] [[z]] 602fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] SClamp [[x]] [[min]] [[max]] 603fd4e5da5Sopenharmony_ci OpCapability Shader 604fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 605fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 606fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 607fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 608fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 609fd4e5da5Sopenharmony_ci %void = OpTypeVoid 610fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 611fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 612fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 613fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 614fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 615fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 616fd4e5da5Sopenharmony_ci %6 = OpLabel 617fd4e5da5Sopenharmony_ci %7 = OpUndef %int 618fd4e5da5Sopenharmony_ci %8 = OpUndef %int 619fd4e5da5Sopenharmony_ci %9 = OpUndef %int 620fd4e5da5Sopenharmony_ci %10 = OpExtInst %int %ext SMid3AMD %7 %8 %9 621fd4e5da5Sopenharmony_ci OpReturn 622fd4e5da5Sopenharmony_ci OpFunctionEnd 623fd4e5da5Sopenharmony_ci)"; 624fd4e5da5Sopenharmony_ci 625fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 626fd4e5da5Sopenharmony_ci} 627fd4e5da5Sopenharmony_ci 628fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceUMid3AMD) { 629fd4e5da5Sopenharmony_ci const std::string text = R"( 630fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 631fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 632fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 633fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 634fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeInt 32 0 635fd4e5da5Sopenharmony_ci; CHECK: OpFunction 636fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 637fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 638fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 639fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 640fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[min:%\w+]] = OpExtInst [[type]] [[ext]] UMin [[y]] [[z]] 641fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[max:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[y]] [[z]] 642fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] UClamp [[x]] [[min]] [[max]] 643fd4e5da5Sopenharmony_ci OpCapability Shader 644fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 645fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 646fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 647fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 648fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 649fd4e5da5Sopenharmony_ci %void = OpTypeVoid 650fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 651fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 652fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 653fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 654fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 655fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 656fd4e5da5Sopenharmony_ci %6 = OpLabel 657fd4e5da5Sopenharmony_ci %7 = OpUndef %uint 658fd4e5da5Sopenharmony_ci %8 = OpUndef %uint 659fd4e5da5Sopenharmony_ci %9 = OpUndef %uint 660fd4e5da5Sopenharmony_ci %10 = OpExtInst %uint %ext UMid3AMD %7 %8 %9 661fd4e5da5Sopenharmony_ci OpReturn 662fd4e5da5Sopenharmony_ci OpFunctionEnd 663fd4e5da5Sopenharmony_ci)"; 664fd4e5da5Sopenharmony_ci 665fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 666fd4e5da5Sopenharmony_ci} 667fd4e5da5Sopenharmony_ci 668fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceVecUMid3AMD) { 669fd4e5da5Sopenharmony_ci const std::string text = R"( 670fd4e5da5Sopenharmony_ci; CHECK: OpCapability Shader 671fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_shader_trinary_minmax" 672fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_shader_trinary_minmax" 673fd4e5da5Sopenharmony_ci; CHECK: [[ext:%\w+]] = OpExtInstImport "GLSL.std.450" 674fd4e5da5Sopenharmony_ci; CHECK: [[type:%\w+]] = OpTypeVector 675fd4e5da5Sopenharmony_ci; CHECK: OpFunction 676fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpLabel 677fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[x:%\w+]] = OpUndef [[type]] 678fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[y:%\w+]] = OpUndef [[type]] 679fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[z:%\w+]] = OpUndef [[type]] 680fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[min:%\w+]] = OpExtInst [[type]] [[ext]] UMin [[y]] [[z]] 681fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[max:%\w+]] = OpExtInst [[type]] [[ext]] UMax [[y]] [[z]] 682fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[result:%\w+]] = OpExtInst [[type]] [[ext]] UClamp [[x]] [[min]] [[max]] 683fd4e5da5Sopenharmony_ci OpCapability Shader 684fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_trinary_minmax" 685fd4e5da5Sopenharmony_ci %ext = OpExtInstImport "SPV_AMD_shader_trinary_minmax" 686fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 687fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %1 "func" 688fd4e5da5Sopenharmony_ci OpExecutionMode %1 OriginUpperLeft 689fd4e5da5Sopenharmony_ci %void = OpTypeVoid 690fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 691fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 692fd4e5da5Sopenharmony_ci %vec = OpTypeVector %uint 3 693fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 694fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 695fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 696fd4e5da5Sopenharmony_ci %1 = OpFunction %void None %3 697fd4e5da5Sopenharmony_ci %6 = OpLabel 698fd4e5da5Sopenharmony_ci %7 = OpUndef %vec 699fd4e5da5Sopenharmony_ci %8 = OpUndef %vec 700fd4e5da5Sopenharmony_ci %9 = OpUndef %vec 701fd4e5da5Sopenharmony_ci %10 = OpExtInst %vec %ext UMid3AMD %7 %8 %9 702fd4e5da5Sopenharmony_ci OpReturn 703fd4e5da5Sopenharmony_ci OpFunctionEnd 704fd4e5da5Sopenharmony_ci)"; 705fd4e5da5Sopenharmony_ci 706fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 707fd4e5da5Sopenharmony_ci} 708fd4e5da5Sopenharmony_ci 709fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceCubeFaceCoordAMD) { 710fd4e5da5Sopenharmony_ci // Sorry for the Check test. The code sequence is so long, I do not think 711fd4e5da5Sopenharmony_ci // that a match test would be anymore legible. This tests the replacement of 712fd4e5da5Sopenharmony_ci // the CubeFaceCoordAMD instruction. 713fd4e5da5Sopenharmony_ci const std::string before = R"( 714fd4e5da5Sopenharmony_ci OpCapability Shader 715fd4e5da5Sopenharmony_ci OpExtension "SPV_KHR_storage_buffer_storage_class" 716fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_gcn_shader" 717fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "SPV_AMD_gcn_shader" 718fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 719fd4e5da5Sopenharmony_ci OpEntryPoint GLCompute %2 "main" 720fd4e5da5Sopenharmony_ci OpExecutionMode %2 LocalSize 1 1 1 721fd4e5da5Sopenharmony_ci %void = OpTypeVoid 722fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void 723fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 724fd4e5da5Sopenharmony_ci %v2float = OpTypeVector %float 2 725fd4e5da5Sopenharmony_ci %v3float = OpTypeVector %float 3 726fd4e5da5Sopenharmony_ci %2 = OpFunction %void None %4 727fd4e5da5Sopenharmony_ci %8 = OpLabel 728fd4e5da5Sopenharmony_ci %9 = OpUndef %v3float 729fd4e5da5Sopenharmony_ci %10 = OpExtInst %v2float %1 CubeFaceCoordAMD %9 730fd4e5da5Sopenharmony_ci OpReturn 731fd4e5da5Sopenharmony_ci OpFunctionEnd 732fd4e5da5Sopenharmony_ci)"; 733fd4e5da5Sopenharmony_ci 734fd4e5da5Sopenharmony_ci const std::string after = R"(OpCapability Shader 735fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 736fd4e5da5Sopenharmony_ci%12 = OpExtInstImport "GLSL.std.450" 737fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 738fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %2 "main" 739fd4e5da5Sopenharmony_ciOpExecutionMode %2 LocalSize 1 1 1 740fd4e5da5Sopenharmony_ci%void = OpTypeVoid 741fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void 742fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 743fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2 744fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3 745fd4e5da5Sopenharmony_ci%bool = OpTypeBool 746fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 747fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2 748fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5 749fd4e5da5Sopenharmony_ci%16 = OpConstantComposite %v2float %float_0_5 %float_0_5 750fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %4 751fd4e5da5Sopenharmony_ci%8 = OpLabel 752fd4e5da5Sopenharmony_ci%9 = OpUndef %v3float 753fd4e5da5Sopenharmony_ci%17 = OpCompositeExtract %float %9 0 754fd4e5da5Sopenharmony_ci%18 = OpCompositeExtract %float %9 1 755fd4e5da5Sopenharmony_ci%19 = OpCompositeExtract %float %9 2 756fd4e5da5Sopenharmony_ci%20 = OpFNegate %float %17 757fd4e5da5Sopenharmony_ci%21 = OpFNegate %float %18 758fd4e5da5Sopenharmony_ci%22 = OpFNegate %float %19 759fd4e5da5Sopenharmony_ci%23 = OpExtInst %float %12 FAbs %17 760fd4e5da5Sopenharmony_ci%24 = OpExtInst %float %12 FAbs %18 761fd4e5da5Sopenharmony_ci%25 = OpExtInst %float %12 FAbs %19 762fd4e5da5Sopenharmony_ci%26 = OpFOrdLessThan %bool %19 %float_0 763fd4e5da5Sopenharmony_ci%27 = OpFOrdLessThan %bool %18 %float_0 764fd4e5da5Sopenharmony_ci%28 = OpFOrdLessThan %bool %17 %float_0 765fd4e5da5Sopenharmony_ci%29 = OpExtInst %float %12 FMax %23 %24 766fd4e5da5Sopenharmony_ci%30 = OpExtInst %float %12 FMax %25 %29 767fd4e5da5Sopenharmony_ci%31 = OpFMul %float %float_2 %30 768fd4e5da5Sopenharmony_ci%32 = OpFOrdGreaterThanEqual %bool %25 %29 769fd4e5da5Sopenharmony_ci%33 = OpLogicalNot %bool %32 770fd4e5da5Sopenharmony_ci%34 = OpFOrdGreaterThanEqual %bool %24 %23 771fd4e5da5Sopenharmony_ci%35 = OpLogicalAnd %bool %33 %34 772fd4e5da5Sopenharmony_ci%36 = OpSelect %float %26 %20 %17 773fd4e5da5Sopenharmony_ci%37 = OpSelect %float %28 %19 %22 774fd4e5da5Sopenharmony_ci%38 = OpSelect %float %35 %17 %37 775fd4e5da5Sopenharmony_ci%39 = OpSelect %float %32 %36 %38 776fd4e5da5Sopenharmony_ci%40 = OpSelect %float %27 %22 %19 777fd4e5da5Sopenharmony_ci%41 = OpSelect %float %35 %40 %21 778fd4e5da5Sopenharmony_ci%42 = OpCompositeConstruct %v2float %39 %41 779fd4e5da5Sopenharmony_ci%43 = OpCompositeConstruct %v2float %31 %31 780fd4e5da5Sopenharmony_ci%44 = OpFDiv %v2float %42 %43 781fd4e5da5Sopenharmony_ci%10 = OpFAdd %v2float %44 %16 782fd4e5da5Sopenharmony_ciOpReturn 783fd4e5da5Sopenharmony_ciOpFunctionEnd 784fd4e5da5Sopenharmony_ci)"; 785fd4e5da5Sopenharmony_ci 786fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<AmdExtensionToKhrPass>(before, after, true); 787fd4e5da5Sopenharmony_ci} 788fd4e5da5Sopenharmony_ci 789fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, ReplaceCubeFaceIndexAMD) { 790fd4e5da5Sopenharmony_ci // Sorry for the Check test. The code sequence is so long, I do not think 791fd4e5da5Sopenharmony_ci // that a match test would be anymore legible. This tests the replacement of 792fd4e5da5Sopenharmony_ci // the CubeFaceIndexAMD instruction. 793fd4e5da5Sopenharmony_ci const std::string before = R"(OpCapability Shader 794fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 795fd4e5da5Sopenharmony_ciOpExtension "SPV_AMD_gcn_shader" 796fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "SPV_AMD_gcn_shader" 797fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 798fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %2 "main" 799fd4e5da5Sopenharmony_ciOpExecutionMode %2 LocalSize 1 1 1 800fd4e5da5Sopenharmony_ci%void = OpTypeVoid 801fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void 802fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 803fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3 804fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %4 805fd4e5da5Sopenharmony_ci%7 = OpLabel 806fd4e5da5Sopenharmony_ci%8 = OpUndef %v3float 807fd4e5da5Sopenharmony_ci%9 = OpExtInst %float %1 CubeFaceIndexAMD %8 808fd4e5da5Sopenharmony_ciOpReturn 809fd4e5da5Sopenharmony_ciOpFunctionEnd 810fd4e5da5Sopenharmony_ci)"; 811fd4e5da5Sopenharmony_ci 812fd4e5da5Sopenharmony_ci const std::string after = R"(OpCapability Shader 813fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class" 814fd4e5da5Sopenharmony_ci%11 = OpExtInstImport "GLSL.std.450" 815fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 816fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %2 "main" 817fd4e5da5Sopenharmony_ciOpExecutionMode %2 LocalSize 1 1 1 818fd4e5da5Sopenharmony_ci%void = OpTypeVoid 819fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void 820fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 821fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3 822fd4e5da5Sopenharmony_ci%bool = OpTypeBool 823fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 824fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1 825fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2 826fd4e5da5Sopenharmony_ci%float_3 = OpConstant %float 3 827fd4e5da5Sopenharmony_ci%float_4 = OpConstant %float 4 828fd4e5da5Sopenharmony_ci%float_5 = OpConstant %float 5 829fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %4 830fd4e5da5Sopenharmony_ci%7 = OpLabel 831fd4e5da5Sopenharmony_ci%8 = OpUndef %v3float 832fd4e5da5Sopenharmony_ci%18 = OpCompositeExtract %float %8 0 833fd4e5da5Sopenharmony_ci%19 = OpCompositeExtract %float %8 1 834fd4e5da5Sopenharmony_ci%20 = OpCompositeExtract %float %8 2 835fd4e5da5Sopenharmony_ci%21 = OpExtInst %float %11 FAbs %18 836fd4e5da5Sopenharmony_ci%22 = OpExtInst %float %11 FAbs %19 837fd4e5da5Sopenharmony_ci%23 = OpExtInst %float %11 FAbs %20 838fd4e5da5Sopenharmony_ci%24 = OpFOrdLessThan %bool %20 %float_0 839fd4e5da5Sopenharmony_ci%25 = OpFOrdLessThan %bool %19 %float_0 840fd4e5da5Sopenharmony_ci%26 = OpFOrdLessThan %bool %18 %float_0 841fd4e5da5Sopenharmony_ci%27 = OpExtInst %float %11 FMax %21 %22 842fd4e5da5Sopenharmony_ci%28 = OpFOrdGreaterThanEqual %bool %23 %27 843fd4e5da5Sopenharmony_ci%29 = OpFOrdGreaterThanEqual %bool %22 %21 844fd4e5da5Sopenharmony_ci%30 = OpSelect %float %24 %float_5 %float_4 845fd4e5da5Sopenharmony_ci%31 = OpSelect %float %25 %float_3 %float_2 846fd4e5da5Sopenharmony_ci%32 = OpSelect %float %26 %float_1 %float_0 847fd4e5da5Sopenharmony_ci%33 = OpSelect %float %29 %31 %32 848fd4e5da5Sopenharmony_ci%9 = OpSelect %float %28 %30 %33 849fd4e5da5Sopenharmony_ciOpReturn 850fd4e5da5Sopenharmony_ciOpFunctionEnd 851fd4e5da5Sopenharmony_ci)"; 852fd4e5da5Sopenharmony_ci 853fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<AmdExtensionToKhrPass>(before, after, true); 854fd4e5da5Sopenharmony_ci} 855fd4e5da5Sopenharmony_ci 856fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, SetVersion) { 857fd4e5da5Sopenharmony_ci const std::string text = R"( 858fd4e5da5Sopenharmony_ci OpCapability Shader 859fd4e5da5Sopenharmony_ci OpCapability Int64 860fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 861fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "SPV_AMD_shader_ballot" 862fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 863fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %2 "func" 864fd4e5da5Sopenharmony_ci OpExecutionMode %2 OriginUpperLeft 865fd4e5da5Sopenharmony_ci %void = OpTypeVoid 866fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void 867fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 868fd4e5da5Sopenharmony_ci %ulong = OpTypeInt 64 0 869fd4e5da5Sopenharmony_ci %ulong_0 = OpConstant %ulong 0 870fd4e5da5Sopenharmony_ci %2 = OpFunction %void None %4 871fd4e5da5Sopenharmony_ci %8 = OpLabel 872fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %1 MbcntAMD %ulong_0 873fd4e5da5Sopenharmony_ci OpReturn 874fd4e5da5Sopenharmony_ci OpFunctionEnd 875fd4e5da5Sopenharmony_ci)"; 876fd4e5da5Sopenharmony_ci 877fd4e5da5Sopenharmony_ci // Set the version to 1.1 and make sure it is upgraded to 1.3. 878fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_1); 879fd4e5da5Sopenharmony_ci SetDisassembleOptions(0); 880fd4e5da5Sopenharmony_ci auto result = SinglePassRunAndDisassemble<AmdExtensionToKhrPass>( 881fd4e5da5Sopenharmony_ci text, /* skip_nop = */ true, /* skip_validation = */ false); 882fd4e5da5Sopenharmony_ci 883fd4e5da5Sopenharmony_ci EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); 884fd4e5da5Sopenharmony_ci const std::string& output = std::get<0>(result); 885fd4e5da5Sopenharmony_ci EXPECT_THAT(output, HasSubstr("Version: 1.3")); 886fd4e5da5Sopenharmony_ci} 887fd4e5da5Sopenharmony_ci 888fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, SetVersion1) { 889fd4e5da5Sopenharmony_ci const std::string text = R"( 890fd4e5da5Sopenharmony_ci OpCapability Shader 891fd4e5da5Sopenharmony_ci OpCapability Int64 892fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_shader_ballot" 893fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "SPV_AMD_shader_ballot" 894fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 895fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %2 "func" 896fd4e5da5Sopenharmony_ci OpExecutionMode %2 OriginUpperLeft 897fd4e5da5Sopenharmony_ci %void = OpTypeVoid 898fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void 899fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 900fd4e5da5Sopenharmony_ci %ulong = OpTypeInt 64 0 901fd4e5da5Sopenharmony_ci %ulong_0 = OpConstant %ulong 0 902fd4e5da5Sopenharmony_ci %2 = OpFunction %void None %4 903fd4e5da5Sopenharmony_ci %8 = OpLabel 904fd4e5da5Sopenharmony_ci %9 = OpExtInst %uint %1 MbcntAMD %ulong_0 905fd4e5da5Sopenharmony_ci OpReturn 906fd4e5da5Sopenharmony_ci OpFunctionEnd 907fd4e5da5Sopenharmony_ci)"; 908fd4e5da5Sopenharmony_ci 909fd4e5da5Sopenharmony_ci // Set the version to 1.4 and make sure it is stays the same. 910fd4e5da5Sopenharmony_ci SetTargetEnv(SPV_ENV_UNIVERSAL_1_4); 911fd4e5da5Sopenharmony_ci SetDisassembleOptions(0); 912fd4e5da5Sopenharmony_ci auto result = SinglePassRunAndDisassemble<AmdExtensionToKhrPass>( 913fd4e5da5Sopenharmony_ci text, /* skip_nop = */ true, /* skip_validation = */ false); 914fd4e5da5Sopenharmony_ci 915fd4e5da5Sopenharmony_ci EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); 916fd4e5da5Sopenharmony_ci const std::string& output = std::get<0>(result); 917fd4e5da5Sopenharmony_ci EXPECT_THAT(output, HasSubstr("Version: 1.4")); 918fd4e5da5Sopenharmony_ci} 919fd4e5da5Sopenharmony_ci 920fd4e5da5Sopenharmony_ciTEST_F(AmdExtToKhrTest, TimeAMD) { 921fd4e5da5Sopenharmony_ci const std::string text = R"( 922fd4e5da5Sopenharmony_ci OpCapability Shader 923fd4e5da5Sopenharmony_ci OpCapability Int64 924fd4e5da5Sopenharmony_ci OpExtension "SPV_AMD_gcn_shader" 925fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtension "SPV_AMD_gcn_shader" 926fd4e5da5Sopenharmony_ci; CHECK: OpExtension "SPV_KHR_shader_clock" 927fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "GLSL.std.450" 928fd4e5da5Sopenharmony_ci %2 = OpExtInstImport "SPV_AMD_gcn_shader" 929fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInstImport "SPV_AMD_gcn_shader" 930fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 931fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" 932fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 933fd4e5da5Sopenharmony_ci OpSource GLSL 450 934fd4e5da5Sopenharmony_ci OpSourceExtension "GL_AMD_gcn_shader" 935fd4e5da5Sopenharmony_ci OpSourceExtension "GL_ARB_gpu_shader_int64" 936fd4e5da5Sopenharmony_ci OpName %main "main" 937fd4e5da5Sopenharmony_ci OpName %time "time" 938fd4e5da5Sopenharmony_ci %void = OpTypeVoid 939fd4e5da5Sopenharmony_ci %6 = OpTypeFunction %void 940fd4e5da5Sopenharmony_ci %ulong = OpTypeInt 64 0 941fd4e5da5Sopenharmony_ci%_ptr_Function_ulong = OpTypePointer Function %ulong 942fd4e5da5Sopenharmony_ci %main = OpFunction %void None %6 943fd4e5da5Sopenharmony_ci %9 = OpLabel 944fd4e5da5Sopenharmony_ci %time = OpVariable %_ptr_Function_ulong Function 945fd4e5da5Sopenharmony_ci; CHECK: [[uint:%\w+]] = OpTypeInt 32 0 946fd4e5da5Sopenharmony_ci; CHECK: [[uint_3:%\w+]] = OpConstant [[uint]] 3 947fd4e5da5Sopenharmony_ci %10 = OpExtInst %ulong %2 TimeAMD 948fd4e5da5Sopenharmony_ci; CHECK: %10 = OpReadClockKHR %ulong [[uint_3]] 949fd4e5da5Sopenharmony_ci OpStore %time %10 950fd4e5da5Sopenharmony_ci OpReturn 951fd4e5da5Sopenharmony_ci OpFunctionEnd 952fd4e5da5Sopenharmony_ci)"; 953fd4e5da5Sopenharmony_ci 954fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<AmdExtensionToKhrPass>(text, true); 955fd4e5da5Sopenharmony_ci} 956fd4e5da5Sopenharmony_ci} // namespace 957fd4e5da5Sopenharmony_ci} // namespace opt 958fd4e5da5Sopenharmony_ci} // namespace spvtools 959