1fd4e5da5Sopenharmony_ci// Copyright (c) 2019 Valve Corporation 2fd4e5da5Sopenharmony_ci// Copyright (c) 2019 LunarG Inc. 3fd4e5da5Sopenharmony_ci// 4fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 5fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 6fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 7fd4e5da5Sopenharmony_ci// 8fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 9fd4e5da5Sopenharmony_ci// 10fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 11fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 12fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 14fd4e5da5Sopenharmony_ci// limitations under the License. 15fd4e5da5Sopenharmony_ci 16fd4e5da5Sopenharmony_ci// Convert Relaxed to Half tests 17fd4e5da5Sopenharmony_ci 18fd4e5da5Sopenharmony_ci#include <string> 19fd4e5da5Sopenharmony_ci#include <vector> 20fd4e5da5Sopenharmony_ci 21fd4e5da5Sopenharmony_ci#include "test/opt/assembly_builder.h" 22fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h" 23fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h" 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_cinamespace spvtools { 26fd4e5da5Sopenharmony_cinamespace opt { 27fd4e5da5Sopenharmony_cinamespace { 28fd4e5da5Sopenharmony_ci 29fd4e5da5Sopenharmony_ciusing ConvertToHalfTest = PassTest<::testing::Test>; 30fd4e5da5Sopenharmony_ci 31fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfBasic) { 32fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 33fd4e5da5Sopenharmony_ci // 34fd4e5da5Sopenharmony_ci // clang-format off 35fd4e5da5Sopenharmony_ci // 36fd4e5da5Sopenharmony_ci // SamplerState g_sSamp : register(s0); 37fd4e5da5Sopenharmony_ci // uniform Texture1D <float4> g_tTex1df4 : register(t0); 38fd4e5da5Sopenharmony_ci // 39fd4e5da5Sopenharmony_ci // struct PS_INPUT 40fd4e5da5Sopenharmony_ci // { 41fd4e5da5Sopenharmony_ci // float Tex0 : TEXCOORD0; 42fd4e5da5Sopenharmony_ci // }; 43fd4e5da5Sopenharmony_ci // 44fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 45fd4e5da5Sopenharmony_ci // { 46fd4e5da5Sopenharmony_ci // float4 Color : SV_Target0; 47fd4e5da5Sopenharmony_ci // }; 48fd4e5da5Sopenharmony_ci // 49fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 50fd4e5da5Sopenharmony_ci // float c; 51fd4e5da5Sopenharmony_ci // } 52fd4e5da5Sopenharmony_ci // 53fd4e5da5Sopenharmony_ci // PS_OUTPUT main(PS_INPUT i) 54fd4e5da5Sopenharmony_ci // { 55fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 56fd4e5da5Sopenharmony_ci // psout.Color = g_tTex1df4.Sample(g_sSamp, i.Tex0) * c; 57fd4e5da5Sopenharmony_ci // return psout; 58fd4e5da5Sopenharmony_ci // } 59fd4e5da5Sopenharmony_ci // 60fd4e5da5Sopenharmony_ci // clang-format on 61fd4e5da5Sopenharmony_ci 62fd4e5da5Sopenharmony_ci const std::string defs_before = 63fd4e5da5Sopenharmony_ci R"(OpCapability Shader 64fd4e5da5Sopenharmony_ciOpCapability Sampled1D 65fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 66fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 67fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %_entryPointOutput_Color 68fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 69fd4e5da5Sopenharmony_ciOpSource HLSL 500 70fd4e5da5Sopenharmony_ciOpName %main "main" 71fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 72fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 73fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 74fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c" 75fd4e5da5Sopenharmony_ciOpName %_ "" 76fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 77fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 78fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 79fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 80fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 81fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 82fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 83fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 84fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 85fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 86fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 87fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 88fd4e5da5Sopenharmony_ciOpDecorate %48 RelaxedPrecision 89fd4e5da5Sopenharmony_ciOpDecorate %63 RelaxedPrecision 90fd4e5da5Sopenharmony_ciOpDecorate %65 RelaxedPrecision 91fd4e5da5Sopenharmony_ciOpDecorate %66 RelaxedPrecision 92fd4e5da5Sopenharmony_ci%void = OpTypeVoid 93fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 94fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 95fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 96fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 97fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 98fd4e5da5Sopenharmony_ci%19 = OpTypeImage %float 1D 0 0 0 1 Unknown 99fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19 100fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_19 UniformConstant 101fd4e5da5Sopenharmony_ci%23 = OpTypeSampler 102fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23 103fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_23 UniformConstant 104fd4e5da5Sopenharmony_ci%27 = OpTypeSampledImage %19 105fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float 106fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 107fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 108fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 109fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 110fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 111fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 112fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 113fd4e5da5Sopenharmony_ci)"; 114fd4e5da5Sopenharmony_ci 115fd4e5da5Sopenharmony_ci const std::string defs_after = 116fd4e5da5Sopenharmony_ci R"(OpCapability Shader 117fd4e5da5Sopenharmony_ciOpCapability Sampled1D 118fd4e5da5Sopenharmony_ciOpCapability Float16 119fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 120fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 121fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %_entryPointOutput_Color 122fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 123fd4e5da5Sopenharmony_ciOpSource HLSL 500 124fd4e5da5Sopenharmony_ciOpName %main "main" 125fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 126fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 127fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 128fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c" 129fd4e5da5Sopenharmony_ciOpName %_ "" 130fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 131fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 132fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 133fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 134fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 135fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 136fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 137fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 138fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 139fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 140fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 141fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 142fd4e5da5Sopenharmony_ci%void = OpTypeVoid 143fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 144fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 145fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 146fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 147fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 148fd4e5da5Sopenharmony_ci%19 = OpTypeImage %float 1D 0 0 0 1 Unknown 149fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19 150fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_19 UniformConstant 151fd4e5da5Sopenharmony_ci%23 = OpTypeSampler 152fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23 153fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_23 UniformConstant 154fd4e5da5Sopenharmony_ci%27 = OpTypeSampledImage %19 155fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float 156fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 157fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 158fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 159fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 160fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 161fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 162fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 163fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 164fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 165fd4e5da5Sopenharmony_ci)"; 166fd4e5da5Sopenharmony_ci 167fd4e5da5Sopenharmony_ci const std::string func_before = 168fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 169fd4e5da5Sopenharmony_ci%5 = OpLabel 170fd4e5da5Sopenharmony_ci%48 = OpLoad %float %i_Tex0 171fd4e5da5Sopenharmony_ci%58 = OpLoad %19 %g_tTex1df4 172fd4e5da5Sopenharmony_ci%59 = OpLoad %23 %g_sSamp 173fd4e5da5Sopenharmony_ci%60 = OpSampledImage %27 %58 %59 174fd4e5da5Sopenharmony_ci%63 = OpImageSampleImplicitLod %v4float %60 %48 175fd4e5da5Sopenharmony_ci%64 = OpAccessChain %_ptr_Uniform_float %_ %int_0 176fd4e5da5Sopenharmony_ci%65 = OpLoad %float %64 177fd4e5da5Sopenharmony_ci%66 = OpVectorTimesScalar %v4float %63 %65 178fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %66 179fd4e5da5Sopenharmony_ciOpReturn 180fd4e5da5Sopenharmony_ciOpFunctionEnd 181fd4e5da5Sopenharmony_ci)"; 182fd4e5da5Sopenharmony_ci 183fd4e5da5Sopenharmony_ci const std::string func_after = 184fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 185fd4e5da5Sopenharmony_ci%5 = OpLabel 186fd4e5da5Sopenharmony_ci%48 = OpLoad %float %i_Tex0 187fd4e5da5Sopenharmony_ci%58 = OpLoad %19 %g_tTex1df4 188fd4e5da5Sopenharmony_ci%59 = OpLoad %23 %g_sSamp 189fd4e5da5Sopenharmony_ci%60 = OpSampledImage %27 %58 %59 190fd4e5da5Sopenharmony_ci%63 = OpImageSampleImplicitLod %v4float %60 %48 191fd4e5da5Sopenharmony_ci%64 = OpAccessChain %_ptr_Uniform_float %_ %int_0 192fd4e5da5Sopenharmony_ci%65 = OpLoad %float %64 193fd4e5da5Sopenharmony_ci%69 = OpFConvert %v4half %63 194fd4e5da5Sopenharmony_ci%70 = OpFConvert %half %65 195fd4e5da5Sopenharmony_ci%66 = OpVectorTimesScalar %v4half %69 %70 196fd4e5da5Sopenharmony_ci%71 = OpFConvert %v4float %66 197fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %71 198fd4e5da5Sopenharmony_ciOpReturn 199fd4e5da5Sopenharmony_ciOpFunctionEnd 200fd4e5da5Sopenharmony_ci)"; 201fd4e5da5Sopenharmony_ci 202fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 203fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 204fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 205fd4e5da5Sopenharmony_ci} 206fd4e5da5Sopenharmony_ci 207fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfForLinkage) { 208fd4e5da5Sopenharmony_ci const std::string before = 209fd4e5da5Sopenharmony_ci R"(OpCapability Shader 210fd4e5da5Sopenharmony_ciOpCapability Linkage 211fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 212fd4e5da5Sopenharmony_ciOpSource HLSL 630 213fd4e5da5Sopenharmony_ciOpName %type_cbuff "type.cbuff" 214fd4e5da5Sopenharmony_ciOpMemberName %type_cbuff 0 "c" 215fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 216fd4e5da5Sopenharmony_ciOpName %main "main" 217fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor" 218fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry" 219fd4e5da5Sopenharmony_ciOpName %v "v" 220fd4e5da5Sopenharmony_ciOpDecorate %main LinkageAttributes "main" Export 221fd4e5da5Sopenharmony_ciOpDecorate %cbuff DescriptorSet 0 222fd4e5da5Sopenharmony_ciOpDecorate %cbuff Binding 0 223fd4e5da5Sopenharmony_ciOpMemberDecorate %type_cbuff 0 Offset 0 224fd4e5da5Sopenharmony_ciOpDecorate %type_cbuff Block 225fd4e5da5Sopenharmony_ciOpDecorate %18 RelaxedPrecision 226fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 227fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 228fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 229fd4e5da5Sopenharmony_ci%type_cbuff = OpTypeStruct %float 230fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_cbuff = OpTypePointer Uniform %type_cbuff 231fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 232fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float 233fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %v4float %_ptr_Function_v4float 234fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 235fd4e5da5Sopenharmony_ci%cbuff = OpVariable %_ptr_Uniform_type_cbuff Uniform 236fd4e5da5Sopenharmony_ci%main = OpFunction %v4float None %9 237fd4e5da5Sopenharmony_ci%BaseColor = OpFunctionParameter %_ptr_Function_v4float 238fd4e5da5Sopenharmony_ci%bb_entry = OpLabel 239fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function 240fd4e5da5Sopenharmony_ci%14 = OpLoad %v4float %BaseColor 241fd4e5da5Sopenharmony_ci%16 = OpAccessChain %_ptr_Uniform_float %cbuff %int_0 242fd4e5da5Sopenharmony_ci%17 = OpLoad %float %16 243fd4e5da5Sopenharmony_ci%18 = OpVectorTimesScalar %v4float %14 %17 244fd4e5da5Sopenharmony_ciOpStore %v %18 245fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %v 246fd4e5da5Sopenharmony_ciOpReturnValue %19 247fd4e5da5Sopenharmony_ciOpFunctionEnd 248fd4e5da5Sopenharmony_ci)"; 249fd4e5da5Sopenharmony_ci 250fd4e5da5Sopenharmony_ci const std::string after = 251fd4e5da5Sopenharmony_ci R"(OpCapability Shader 252fd4e5da5Sopenharmony_ciOpCapability Linkage 253fd4e5da5Sopenharmony_ciOpCapability Float16 254fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 255fd4e5da5Sopenharmony_ciOpSource HLSL 630 256fd4e5da5Sopenharmony_ciOpName %type_cbuff "type.cbuff" 257fd4e5da5Sopenharmony_ciOpMemberName %type_cbuff 0 "c" 258fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 259fd4e5da5Sopenharmony_ciOpName %main "main" 260fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor" 261fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry" 262fd4e5da5Sopenharmony_ciOpName %v "v" 263fd4e5da5Sopenharmony_ciOpDecorate %main LinkageAttributes "main" Export 264fd4e5da5Sopenharmony_ciOpDecorate %cbuff DescriptorSet 0 265fd4e5da5Sopenharmony_ciOpDecorate %cbuff Binding 0 266fd4e5da5Sopenharmony_ciOpMemberDecorate %type_cbuff 0 Offset 0 267fd4e5da5Sopenharmony_ciOpDecorate %type_cbuff Block 268fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 269fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 270fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 271fd4e5da5Sopenharmony_ci%type_cbuff = OpTypeStruct %float 272fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_cbuff = OpTypePointer Uniform %type_cbuff 273fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 274fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float 275fd4e5da5Sopenharmony_ci%14 = OpTypeFunction %v4float %_ptr_Function_v4float 276fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 277fd4e5da5Sopenharmony_ci%cbuff = OpVariable %_ptr_Uniform_type_cbuff Uniform 278fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 279fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 280fd4e5da5Sopenharmony_ci%main = OpFunction %v4float None %14 281fd4e5da5Sopenharmony_ci%BaseColor = OpFunctionParameter %_ptr_Function_v4float 282fd4e5da5Sopenharmony_ci%bb_entry = OpLabel 283fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function 284fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %BaseColor 285fd4e5da5Sopenharmony_ci%17 = OpAccessChain %_ptr_Uniform_float %cbuff %int_0 286fd4e5da5Sopenharmony_ci%18 = OpLoad %float %17 287fd4e5da5Sopenharmony_ci%22 = OpFConvert %v4half %16 288fd4e5da5Sopenharmony_ci%23 = OpFConvert %half %18 289fd4e5da5Sopenharmony_ci%7 = OpVectorTimesScalar %v4half %22 %23 290fd4e5da5Sopenharmony_ci%24 = OpFConvert %v4float %7 291fd4e5da5Sopenharmony_ciOpStore %v %24 292fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %v 293fd4e5da5Sopenharmony_ciOpReturnValue %19 294fd4e5da5Sopenharmony_ciOpFunctionEnd 295fd4e5da5Sopenharmony_ci)"; 296fd4e5da5Sopenharmony_ci 297fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(before, after, true, true); 298fd4e5da5Sopenharmony_ci} 299fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithDrefSample) { 300fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 301fd4e5da5Sopenharmony_ci // 302fd4e5da5Sopenharmony_ci // clang-format off 303fd4e5da5Sopenharmony_ci // 304fd4e5da5Sopenharmony_ci // SamplerComparisonState g_sSamp : register(s0); 305fd4e5da5Sopenharmony_ci // uniform Texture1D <float4> g_tTex1df4 : register(t0); 306fd4e5da5Sopenharmony_ci // 307fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 308fd4e5da5Sopenharmony_ci // float c1; 309fd4e5da5Sopenharmony_ci // float c2; 310fd4e5da5Sopenharmony_ci // }; 311fd4e5da5Sopenharmony_ci // 312fd4e5da5Sopenharmony_ci // struct PS_INPUT 313fd4e5da5Sopenharmony_ci // { 314fd4e5da5Sopenharmony_ci // float Tex0 : TEXCOORD0; 315fd4e5da5Sopenharmony_ci // float Tex1 : TEXCOORD1; 316fd4e5da5Sopenharmony_ci // }; 317fd4e5da5Sopenharmony_ci // 318fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 319fd4e5da5Sopenharmony_ci // { 320fd4e5da5Sopenharmony_ci // float Color : SV_Target0; 321fd4e5da5Sopenharmony_ci // }; 322fd4e5da5Sopenharmony_ci // 323fd4e5da5Sopenharmony_ci // PS_OUTPUT main(PS_INPUT i) 324fd4e5da5Sopenharmony_ci // { 325fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 326fd4e5da5Sopenharmony_ci // float txval10 = g_tTex1df4.SampleCmp(g_sSamp, i.Tex0 * 0.1, c1 + 0.1); 327fd4e5da5Sopenharmony_ci // float txval11 = g_tTex1df4.SampleCmp(g_sSamp, i.Tex1 * 0.2, c2 + 0.2); 328fd4e5da5Sopenharmony_ci // float t = txval10 + txval11; 329fd4e5da5Sopenharmony_ci // float t2 = t / 2.0; 330fd4e5da5Sopenharmony_ci // psout.Color = t2; 331fd4e5da5Sopenharmony_ci // return psout; 332fd4e5da5Sopenharmony_ci // } 333fd4e5da5Sopenharmony_ci // 334fd4e5da5Sopenharmony_ci // clang-format on 335fd4e5da5Sopenharmony_ci 336fd4e5da5Sopenharmony_ci const std::string defs_before = 337fd4e5da5Sopenharmony_ci R"(OpCapability Shader 338fd4e5da5Sopenharmony_ciOpCapability Sampled1D 339fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 340fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 341fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %i_Tex1 %_entryPointOutput_Color 342fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 343fd4e5da5Sopenharmony_ciOpSource HLSL 500 344fd4e5da5Sopenharmony_ciOpName %main "main" 345fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 346fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 347fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 348fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c1" 349fd4e5da5Sopenharmony_ciOpMemberName %cbuff 1 "c2" 350fd4e5da5Sopenharmony_ciOpName %_ "" 351fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 352fd4e5da5Sopenharmony_ciOpName %i_Tex1 "i.Tex1" 353fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 354fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 355fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 356fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 357fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 358fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 359fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 Offset 4 360fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 361fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 362fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 363fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 364fd4e5da5Sopenharmony_ciOpDecorate %i_Tex1 Location 1 365fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 366fd4e5da5Sopenharmony_ciOpDecorate %100 RelaxedPrecision 367fd4e5da5Sopenharmony_ciOpDecorate %76 RelaxedPrecision 368fd4e5da5Sopenharmony_ciOpDecorate %79 RelaxedPrecision 369fd4e5da5Sopenharmony_ciOpDecorate %98 RelaxedPrecision 370fd4e5da5Sopenharmony_ciOpDecorate %101 RelaxedPrecision 371fd4e5da5Sopenharmony_ciOpDecorate %110 RelaxedPrecision 372fd4e5da5Sopenharmony_ciOpDecorate %102 RelaxedPrecision 373fd4e5da5Sopenharmony_ciOpDecorate %112 RelaxedPrecision 374fd4e5da5Sopenharmony_ciOpDecorate %104 RelaxedPrecision 375fd4e5da5Sopenharmony_ciOpDecorate %113 RelaxedPrecision 376fd4e5da5Sopenharmony_ciOpDecorate %114 RelaxedPrecision 377fd4e5da5Sopenharmony_ciOpDecorate %116 RelaxedPrecision 378fd4e5da5Sopenharmony_ciOpDecorate %119 RelaxedPrecision 379fd4e5da5Sopenharmony_ciOpDecorate %121 RelaxedPrecision 380fd4e5da5Sopenharmony_ci%void = OpTypeVoid 381fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 382fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 383fd4e5da5Sopenharmony_ci%16 = OpTypeImage %float 1D 1 0 0 1 Unknown 384fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16 385fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_16 UniformConstant 386fd4e5da5Sopenharmony_ci%20 = OpTypeSampler 387fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20 388fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_20 UniformConstant 389fd4e5da5Sopenharmony_ci%24 = OpTypeSampledImage %16 390fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 391fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 392fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 393fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float %float 394fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 395fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 396fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 397fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2 398fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 399fd4e5da5Sopenharmony_ci%float_0_200000003 = OpConstant %float 0.200000003 400fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 401fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 402fd4e5da5Sopenharmony_ci%i_Tex1 = OpVariable %_ptr_Input_float Input 403fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float 404fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_float Output 405fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5 406fd4e5da5Sopenharmony_ci)"; 407fd4e5da5Sopenharmony_ci 408fd4e5da5Sopenharmony_ci const std::string defs_after = 409fd4e5da5Sopenharmony_ci R"(OpCapability Shader 410fd4e5da5Sopenharmony_ciOpCapability Sampled1D 411fd4e5da5Sopenharmony_ciOpCapability Float16 412fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 413fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 414fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %i_Tex1 %_entryPointOutput_Color 415fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 416fd4e5da5Sopenharmony_ciOpSource HLSL 500 417fd4e5da5Sopenharmony_ciOpName %main "main" 418fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 419fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 420fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 421fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c1" 422fd4e5da5Sopenharmony_ciOpMemberName %cbuff 1 "c2" 423fd4e5da5Sopenharmony_ciOpName %_ "" 424fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 425fd4e5da5Sopenharmony_ciOpName %i_Tex1 "i.Tex1" 426fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 427fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 428fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 429fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 430fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 431fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 432fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 Offset 4 433fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 434fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 435fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 436fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 437fd4e5da5Sopenharmony_ciOpDecorate %i_Tex1 Location 1 438fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 439fd4e5da5Sopenharmony_ci%void = OpTypeVoid 440fd4e5da5Sopenharmony_ci%25 = OpTypeFunction %void 441fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 442fd4e5da5Sopenharmony_ci%27 = OpTypeImage %float 1D 1 0 0 1 Unknown 443fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_27 = OpTypePointer UniformConstant %27 444fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_27 UniformConstant 445fd4e5da5Sopenharmony_ci%29 = OpTypeSampler 446fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_29 = OpTypePointer UniformConstant %29 447fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_29 UniformConstant 448fd4e5da5Sopenharmony_ci%31 = OpTypeSampledImage %27 449fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 450fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 451fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 452fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float %float 453fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 454fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 455fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 456fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2 457fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 458fd4e5da5Sopenharmony_ci%float_0_200000003 = OpConstant %float 0.200000003 459fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 460fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 461fd4e5da5Sopenharmony_ci%i_Tex1 = OpVariable %_ptr_Input_float Input 462fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float 463fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_float Output 464fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5 465fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 466fd4e5da5Sopenharmony_ci%v2half = OpTypeVector %half 2 467fd4e5da5Sopenharmony_ci)"; 468fd4e5da5Sopenharmony_ci 469fd4e5da5Sopenharmony_ci const std::string func_before = 470fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 471fd4e5da5Sopenharmony_ci%5 = OpLabel 472fd4e5da5Sopenharmony_ci%76 = OpLoad %float %i_Tex0 473fd4e5da5Sopenharmony_ci%79 = OpLoad %float %i_Tex1 474fd4e5da5Sopenharmony_ci%93 = OpLoad %16 %g_tTex1df4 475fd4e5da5Sopenharmony_ci%94 = OpLoad %20 %g_sSamp 476fd4e5da5Sopenharmony_ci%95 = OpSampledImage %24 %93 %94 477fd4e5da5Sopenharmony_ci%98 = OpFMul %float %76 %float_0_100000001 478fd4e5da5Sopenharmony_ci%99 = OpAccessChain %_ptr_Uniform_float %_ %int_0 479fd4e5da5Sopenharmony_ci%100 = OpLoad %float %99 480fd4e5da5Sopenharmony_ci%101 = OpFAdd %float %100 %float_0_100000001 481fd4e5da5Sopenharmony_ci%102 = OpCompositeConstruct %v2float %98 %101 482fd4e5da5Sopenharmony_ci%104 = OpImageSampleDrefImplicitLod %float %95 %102 %101 483fd4e5da5Sopenharmony_ci%105 = OpLoad %16 %g_tTex1df4 484fd4e5da5Sopenharmony_ci%106 = OpLoad %20 %g_sSamp 485fd4e5da5Sopenharmony_ci%107 = OpSampledImage %24 %105 %106 486fd4e5da5Sopenharmony_ci%110 = OpFMul %float %79 %float_0_200000003 487fd4e5da5Sopenharmony_ci%111 = OpAccessChain %_ptr_Uniform_float %_ %int_1 488fd4e5da5Sopenharmony_ci%112 = OpLoad %float %111 489fd4e5da5Sopenharmony_ci%113 = OpFAdd %float %112 %float_0_200000003 490fd4e5da5Sopenharmony_ci%114 = OpCompositeConstruct %v2float %110 %113 491fd4e5da5Sopenharmony_ci%116 = OpImageSampleDrefImplicitLod %float %107 %114 %113 492fd4e5da5Sopenharmony_ci%119 = OpFAdd %float %104 %116 493fd4e5da5Sopenharmony_ci%121 = OpFMul %float %119 %float_0_5 494fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %121 495fd4e5da5Sopenharmony_ciOpReturn 496fd4e5da5Sopenharmony_ciOpFunctionEnd 497fd4e5da5Sopenharmony_ci)"; 498fd4e5da5Sopenharmony_ci 499fd4e5da5Sopenharmony_ci const std::string func_after = 500fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %25 501fd4e5da5Sopenharmony_ci%43 = OpLabel 502fd4e5da5Sopenharmony_ci%11 = OpLoad %float %i_Tex0 503fd4e5da5Sopenharmony_ci%12 = OpLoad %float %i_Tex1 504fd4e5da5Sopenharmony_ci%44 = OpLoad %27 %g_tTex1df4 505fd4e5da5Sopenharmony_ci%45 = OpLoad %29 %g_sSamp 506fd4e5da5Sopenharmony_ci%46 = OpSampledImage %31 %44 %45 507fd4e5da5Sopenharmony_ci%53 = OpFConvert %half %11 508fd4e5da5Sopenharmony_ci%54 = OpFConvert %half %float_0_100000001 509fd4e5da5Sopenharmony_ci%13 = OpFMul %half %53 %54 510fd4e5da5Sopenharmony_ci%47 = OpAccessChain %_ptr_Uniform_float %_ %int_0 511fd4e5da5Sopenharmony_ci%10 = OpLoad %float %47 512fd4e5da5Sopenharmony_ci%55 = OpFConvert %half %10 513fd4e5da5Sopenharmony_ci%56 = OpFConvert %half %float_0_100000001 514fd4e5da5Sopenharmony_ci%14 = OpFAdd %half %55 %56 515fd4e5da5Sopenharmony_ci%16 = OpCompositeConstruct %v2half %13 %14 516fd4e5da5Sopenharmony_ci%58 = OpFConvert %float %14 517fd4e5da5Sopenharmony_ci%18 = OpImageSampleDrefImplicitLod %float %46 %16 %58 518fd4e5da5Sopenharmony_ci%48 = OpLoad %27 %g_tTex1df4 519fd4e5da5Sopenharmony_ci%49 = OpLoad %29 %g_sSamp 520fd4e5da5Sopenharmony_ci%50 = OpSampledImage %31 %48 %49 521fd4e5da5Sopenharmony_ci%59 = OpFConvert %half %12 522fd4e5da5Sopenharmony_ci%60 = OpFConvert %half %float_0_200000003 523fd4e5da5Sopenharmony_ci%15 = OpFMul %half %59 %60 524fd4e5da5Sopenharmony_ci%51 = OpAccessChain %_ptr_Uniform_float %_ %int_1 525fd4e5da5Sopenharmony_ci%17 = OpLoad %float %51 526fd4e5da5Sopenharmony_ci%61 = OpFConvert %half %17 527fd4e5da5Sopenharmony_ci%62 = OpFConvert %half %float_0_200000003 528fd4e5da5Sopenharmony_ci%19 = OpFAdd %half %61 %62 529fd4e5da5Sopenharmony_ci%20 = OpCompositeConstruct %v2half %15 %19 530fd4e5da5Sopenharmony_ci%63 = OpFConvert %float %19 531fd4e5da5Sopenharmony_ci%21 = OpImageSampleDrefImplicitLod %float %50 %20 %63 532fd4e5da5Sopenharmony_ci%64 = OpFConvert %half %18 533fd4e5da5Sopenharmony_ci%65 = OpFConvert %half %21 534fd4e5da5Sopenharmony_ci%22 = OpFAdd %half %64 %65 535fd4e5da5Sopenharmony_ci%66 = OpFConvert %half %float_0_5 536fd4e5da5Sopenharmony_ci%23 = OpFMul %half %22 %66 537fd4e5da5Sopenharmony_ci%67 = OpFConvert %float %23 538fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %67 539fd4e5da5Sopenharmony_ciOpReturn 540fd4e5da5Sopenharmony_ciOpFunctionEnd 541fd4e5da5Sopenharmony_ci)"; 542fd4e5da5Sopenharmony_ci 543fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 544fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 545fd4e5da5Sopenharmony_ci} 546fd4e5da5Sopenharmony_ci 547fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithVectorMatrixMult) { 548fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 549fd4e5da5Sopenharmony_ci // 550fd4e5da5Sopenharmony_ci // clang-format off 551fd4e5da5Sopenharmony_ci // 552fd4e5da5Sopenharmony_ci // SamplerState g_sSamp : register(s0); 553fd4e5da5Sopenharmony_ci // uniform Texture1D <float4> g_tTex1df4 : register(t0); 554fd4e5da5Sopenharmony_ci // 555fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 556fd4e5da5Sopenharmony_ci // { 557fd4e5da5Sopenharmony_ci // float4 Color : SV_Target0; 558fd4e5da5Sopenharmony_ci // }; 559fd4e5da5Sopenharmony_ci // 560fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 561fd4e5da5Sopenharmony_ci // float4x4 M; 562fd4e5da5Sopenharmony_ci // } 563fd4e5da5Sopenharmony_ci // 564fd4e5da5Sopenharmony_ci // PS_OUTPUT main() 565fd4e5da5Sopenharmony_ci // { 566fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 567fd4e5da5Sopenharmony_ci // float4 txval10 = g_tTex1df4.Sample(g_sSamp, 0.1); 568fd4e5da5Sopenharmony_ci // float4 t = mul(txval10, M); 569fd4e5da5Sopenharmony_ci // psout.Color = t; 570fd4e5da5Sopenharmony_ci // return psout; 571fd4e5da5Sopenharmony_ci //} 572fd4e5da5Sopenharmony_ci // 573fd4e5da5Sopenharmony_ci // clang-format on 574fd4e5da5Sopenharmony_ci 575fd4e5da5Sopenharmony_ci const std::string defs_before = 576fd4e5da5Sopenharmony_ci R"(OpCapability Shader 577fd4e5da5Sopenharmony_ciOpCapability Sampled1D 578fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 579fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 580fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 581fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 582fd4e5da5Sopenharmony_ciOpSource HLSL 500 583fd4e5da5Sopenharmony_ciOpName %main "main" 584fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 585fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 586fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 587fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "M" 588fd4e5da5Sopenharmony_ciOpName %_ "" 589fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 590fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 591fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 592fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 593fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 594fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 RowMajor 595fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 596fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 MatrixStride 16 597fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 598fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 599fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 600fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 601fd4e5da5Sopenharmony_ciOpDecorate %56 RelaxedPrecision 602fd4e5da5Sopenharmony_ciOpDecorate %58 RelaxedPrecision 603fd4e5da5Sopenharmony_ciOpDecorate %60 RelaxedPrecision 604fd4e5da5Sopenharmony_ci%void = OpTypeVoid 605fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 606fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 607fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 608fd4e5da5Sopenharmony_ci%14 = OpTypeImage %float 1D 0 0 0 1 Unknown 609fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14 610fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_14 UniformConstant 611fd4e5da5Sopenharmony_ci%18 = OpTypeSampler 612fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18 613fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_18 UniformConstant 614fd4e5da5Sopenharmony_ci%22 = OpTypeSampledImage %14 615fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 616fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4 617fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %mat4v4float 618fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 619fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 620fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 621fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 622fd4e5da5Sopenharmony_ci%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float 623fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 624fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 625fd4e5da5Sopenharmony_ci)"; 626fd4e5da5Sopenharmony_ci 627fd4e5da5Sopenharmony_ci const std::string defs_after = 628fd4e5da5Sopenharmony_ci R"(OpCapability Shader 629fd4e5da5Sopenharmony_ciOpCapability Sampled1D 630fd4e5da5Sopenharmony_ciOpCapability Float16 631fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 632fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 633fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 634fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 635fd4e5da5Sopenharmony_ciOpSource HLSL 500 636fd4e5da5Sopenharmony_ciOpName %main "main" 637fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 638fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 639fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 640fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "M" 641fd4e5da5Sopenharmony_ciOpName %_ "" 642fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 643fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 644fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 645fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 646fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 647fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 RowMajor 648fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 649fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 MatrixStride 16 650fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 651fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 652fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 653fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 654fd4e5da5Sopenharmony_ci%void = OpTypeVoid 655fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 656fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 657fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 658fd4e5da5Sopenharmony_ci%14 = OpTypeImage %float 1D 0 0 0 1 Unknown 659fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14 660fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_14 UniformConstant 661fd4e5da5Sopenharmony_ci%18 = OpTypeSampler 662fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18 663fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_18 UniformConstant 664fd4e5da5Sopenharmony_ci%22 = OpTypeSampledImage %14 665fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 666fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4 667fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %mat4v4float 668fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 669fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 670fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 671fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 672fd4e5da5Sopenharmony_ci%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float 673fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 674fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 675fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 676fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 677fd4e5da5Sopenharmony_ci%mat4v4half = OpTypeMatrix %v4half 4 678fd4e5da5Sopenharmony_ci)"; 679fd4e5da5Sopenharmony_ci 680fd4e5da5Sopenharmony_ci const std::string func_before = 681fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 682fd4e5da5Sopenharmony_ci%5 = OpLabel 683fd4e5da5Sopenharmony_ci%53 = OpLoad %14 %g_tTex1df4 684fd4e5da5Sopenharmony_ci%54 = OpLoad %18 %g_sSamp 685fd4e5da5Sopenharmony_ci%55 = OpSampledImage %22 %53 %54 686fd4e5da5Sopenharmony_ci%56 = OpImageSampleImplicitLod %v4float %55 %float_0_100000001 687fd4e5da5Sopenharmony_ci%57 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_0 688fd4e5da5Sopenharmony_ci%58 = OpLoad %mat4v4float %57 689fd4e5da5Sopenharmony_ci%60 = OpMatrixTimesVector %v4float %58 %56 690fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %60 691fd4e5da5Sopenharmony_ciOpReturn 692fd4e5da5Sopenharmony_ciOpFunctionEnd 693fd4e5da5Sopenharmony_ci)"; 694fd4e5da5Sopenharmony_ci 695fd4e5da5Sopenharmony_ci const std::string func_after = 696fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 697fd4e5da5Sopenharmony_ci%5 = OpLabel 698fd4e5da5Sopenharmony_ci%53 = OpLoad %14 %g_tTex1df4 699fd4e5da5Sopenharmony_ci%54 = OpLoad %18 %g_sSamp 700fd4e5da5Sopenharmony_ci%55 = OpSampledImage %22 %53 %54 701fd4e5da5Sopenharmony_ci%56 = OpImageSampleImplicitLod %v4float %55 %float_0_100000001 702fd4e5da5Sopenharmony_ci%57 = OpAccessChain %_ptr_Uniform_mat4v4float %_ %int_0 703fd4e5da5Sopenharmony_ci%58 = OpLoad %mat4v4float %57 704fd4e5da5Sopenharmony_ci%67 = OpCompositeExtract %v4float %58 0 705fd4e5da5Sopenharmony_ci%68 = OpFConvert %v4half %67 706fd4e5da5Sopenharmony_ci%69 = OpCompositeExtract %v4float %58 1 707fd4e5da5Sopenharmony_ci%70 = OpFConvert %v4half %69 708fd4e5da5Sopenharmony_ci%71 = OpCompositeExtract %v4float %58 2 709fd4e5da5Sopenharmony_ci%72 = OpFConvert %v4half %71 710fd4e5da5Sopenharmony_ci%73 = OpCompositeExtract %v4float %58 3 711fd4e5da5Sopenharmony_ci%74 = OpFConvert %v4half %73 712fd4e5da5Sopenharmony_ci%75 = OpCompositeConstruct %mat4v4half %68 %70 %72 %74 713fd4e5da5Sopenharmony_ci%64 = OpCopyObject %mat4v4float %58 714fd4e5da5Sopenharmony_ci%65 = OpFConvert %v4half %56 715fd4e5da5Sopenharmony_ci%60 = OpMatrixTimesVector %v4half %75 %65 716fd4e5da5Sopenharmony_ci%66 = OpFConvert %v4float %60 717fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %66 718fd4e5da5Sopenharmony_ciOpReturn 719fd4e5da5Sopenharmony_ciOpFunctionEnd 720fd4e5da5Sopenharmony_ci)"; 721fd4e5da5Sopenharmony_ci 722fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 723fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 724fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 725fd4e5da5Sopenharmony_ci} 726fd4e5da5Sopenharmony_ci 727fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithPhi) { 728fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 729fd4e5da5Sopenharmony_ci // 730fd4e5da5Sopenharmony_ci // clang-format off 731fd4e5da5Sopenharmony_ci // 732fd4e5da5Sopenharmony_ci // SamplerState g_sSamp : register(s0); 733fd4e5da5Sopenharmony_ci // uniform Texture1D <float4> g_tTex1df4 : register(t0); 734fd4e5da5Sopenharmony_ci // 735fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 736fd4e5da5Sopenharmony_ci // { 737fd4e5da5Sopenharmony_ci // float4 Color : SV_Target0; 738fd4e5da5Sopenharmony_ci // }; 739fd4e5da5Sopenharmony_ci // 740fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 741fd4e5da5Sopenharmony_ci // bool b; 742fd4e5da5Sopenharmony_ci // float4x4 M; 743fd4e5da5Sopenharmony_ci // } 744fd4e5da5Sopenharmony_ci // 745fd4e5da5Sopenharmony_ci // PS_OUTPUT main() 746fd4e5da5Sopenharmony_ci // { 747fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 748fd4e5da5Sopenharmony_ci // float4 t; 749fd4e5da5Sopenharmony_ci // 750fd4e5da5Sopenharmony_ci // if (b) 751fd4e5da5Sopenharmony_ci // t = g_tTex1df4.Sample(g_sSamp, 0.1); 752fd4e5da5Sopenharmony_ci // else 753fd4e5da5Sopenharmony_ci // t = float4(0.0, 0.0, 0.0, 0.0); 754fd4e5da5Sopenharmony_ci // 755fd4e5da5Sopenharmony_ci // float4 t2 = t * 2.0; 756fd4e5da5Sopenharmony_ci // psout.Color = t2; 757fd4e5da5Sopenharmony_ci // return psout; 758fd4e5da5Sopenharmony_ci // } 759fd4e5da5Sopenharmony_ci // 760fd4e5da5Sopenharmony_ci // clang-format on 761fd4e5da5Sopenharmony_ci 762fd4e5da5Sopenharmony_ci const std::string defs_before = 763fd4e5da5Sopenharmony_ci R"(OpCapability Shader 764fd4e5da5Sopenharmony_ciOpCapability Sampled1D 765fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 766fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 767fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 768fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 769fd4e5da5Sopenharmony_ciOpSource HLSL 500 770fd4e5da5Sopenharmony_ciOpName %main "main" 771fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 772fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "b" 773fd4e5da5Sopenharmony_ciOpMemberName %cbuff 1 "M" 774fd4e5da5Sopenharmony_ciOpName %_ "" 775fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 776fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 777fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 778fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 779fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 RowMajor 780fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 Offset 16 781fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 MatrixStride 16 782fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 783fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 784fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 785fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 786fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 787fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 788fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 789fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 790fd4e5da5Sopenharmony_ciOpDecorate %72 RelaxedPrecision 791fd4e5da5Sopenharmony_ciOpDecorate %85 RelaxedPrecision 792fd4e5da5Sopenharmony_ciOpDecorate %74 RelaxedPrecision 793fd4e5da5Sopenharmony_ci%void = OpTypeVoid 794fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 795fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 796fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 797fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0 798fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4 799fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %uint %mat4v4float 800fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 801fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 802fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 803fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 804fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint 805fd4e5da5Sopenharmony_ci%bool = OpTypeBool 806fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0 807fd4e5da5Sopenharmony_ci%29 = OpTypeImage %float 1D 0 0 0 1 Unknown 808fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_29 = OpTypePointer UniformConstant %29 809fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_29 UniformConstant 810fd4e5da5Sopenharmony_ci%33 = OpTypeSampler 811fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_33 = OpTypePointer UniformConstant %33 812fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_33 UniformConstant 813fd4e5da5Sopenharmony_ci%37 = OpTypeSampledImage %29 814fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 815fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 816fd4e5da5Sopenharmony_ci%43 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 817fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2 818fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 819fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 820fd4e5da5Sopenharmony_ci)"; 821fd4e5da5Sopenharmony_ci 822fd4e5da5Sopenharmony_ci const std::string defs_after = 823fd4e5da5Sopenharmony_ci R"(OpCapability Shader 824fd4e5da5Sopenharmony_ciOpCapability Sampled1D 825fd4e5da5Sopenharmony_ciOpCapability Float16 826fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 827fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 828fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 829fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 830fd4e5da5Sopenharmony_ciOpSource HLSL 500 831fd4e5da5Sopenharmony_ciOpName %main "main" 832fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 833fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "b" 834fd4e5da5Sopenharmony_ciOpMemberName %cbuff 1 "M" 835fd4e5da5Sopenharmony_ciOpName %_ "" 836fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 837fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 838fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 839fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 840fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 RowMajor 841fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 Offset 16 842fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 1 MatrixStride 16 843fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 844fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 845fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 846fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 847fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 848fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 849fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 850fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 851fd4e5da5Sopenharmony_ci%void = OpTypeVoid 852fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 853fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 854fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 855fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0 856fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4 857fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %uint %mat4v4float 858fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 859fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 860fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 861fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 862fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint 863fd4e5da5Sopenharmony_ci%bool = OpTypeBool 864fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0 865fd4e5da5Sopenharmony_ci%29 = OpTypeImage %float 1D 0 0 0 1 Unknown 866fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_29 = OpTypePointer UniformConstant %29 867fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_29 UniformConstant 868fd4e5da5Sopenharmony_ci%33 = OpTypeSampler 869fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_33 = OpTypePointer UniformConstant %33 870fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_33 UniformConstant 871fd4e5da5Sopenharmony_ci%37 = OpTypeSampledImage %29 872fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 873fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 874fd4e5da5Sopenharmony_ci%43 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 875fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2 876fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 877fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 878fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 879fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 880fd4e5da5Sopenharmony_ci)"; 881fd4e5da5Sopenharmony_ci 882fd4e5da5Sopenharmony_ci const std::string func_before = 883fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 884fd4e5da5Sopenharmony_ci%5 = OpLabel 885fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 886fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63 887fd4e5da5Sopenharmony_ci%65 = OpINotEqual %bool %64 %uint_0 888fd4e5da5Sopenharmony_ciOpSelectionMerge %66 None 889fd4e5da5Sopenharmony_ciOpBranchConditional %65 %67 %68 890fd4e5da5Sopenharmony_ci%67 = OpLabel 891fd4e5da5Sopenharmony_ci%69 = OpLoad %29 %g_tTex1df4 892fd4e5da5Sopenharmony_ci%70 = OpLoad %33 %g_sSamp 893fd4e5da5Sopenharmony_ci%71 = OpSampledImage %37 %69 %70 894fd4e5da5Sopenharmony_ci%72 = OpImageSampleImplicitLod %v4float %71 %float_0_100000001 895fd4e5da5Sopenharmony_ciOpBranch %66 896fd4e5da5Sopenharmony_ci%68 = OpLabel 897fd4e5da5Sopenharmony_ciOpBranch %66 898fd4e5da5Sopenharmony_ci%66 = OpLabel 899fd4e5da5Sopenharmony_ci%85 = OpPhi %v4float %72 %67 %43 %68 900fd4e5da5Sopenharmony_ci%74 = OpVectorTimesScalar %v4float %85 %float_2 901fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %74 902fd4e5da5Sopenharmony_ciOpReturn 903fd4e5da5Sopenharmony_ciOpFunctionEnd 904fd4e5da5Sopenharmony_ci)"; 905fd4e5da5Sopenharmony_ci 906fd4e5da5Sopenharmony_ci const std::string func_after = 907fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 908fd4e5da5Sopenharmony_ci%5 = OpLabel 909fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_Uniform_uint %_ %int_0 910fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63 911fd4e5da5Sopenharmony_ci%65 = OpINotEqual %bool %64 %uint_0 912fd4e5da5Sopenharmony_ciOpSelectionMerge %66 None 913fd4e5da5Sopenharmony_ciOpBranchConditional %65 %67 %68 914fd4e5da5Sopenharmony_ci%67 = OpLabel 915fd4e5da5Sopenharmony_ci%69 = OpLoad %29 %g_tTex1df4 916fd4e5da5Sopenharmony_ci%70 = OpLoad %33 %g_sSamp 917fd4e5da5Sopenharmony_ci%71 = OpSampledImage %37 %69 %70 918fd4e5da5Sopenharmony_ci%72 = OpImageSampleImplicitLod %v4float %71 %float_0_100000001 919fd4e5da5Sopenharmony_ci%88 = OpFConvert %v4half %72 920fd4e5da5Sopenharmony_ciOpBranch %66 921fd4e5da5Sopenharmony_ci%68 = OpLabel 922fd4e5da5Sopenharmony_ci%89 = OpFConvert %v4half %43 923fd4e5da5Sopenharmony_ciOpBranch %66 924fd4e5da5Sopenharmony_ci%66 = OpLabel 925fd4e5da5Sopenharmony_ci%85 = OpPhi %v4half %88 %67 %89 %68 926fd4e5da5Sopenharmony_ci%90 = OpFConvert %half %float_2 927fd4e5da5Sopenharmony_ci%74 = OpVectorTimesScalar %v4half %85 %90 928fd4e5da5Sopenharmony_ci%91 = OpFConvert %v4float %74 929fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %91 930fd4e5da5Sopenharmony_ciOpReturn 931fd4e5da5Sopenharmony_ciOpFunctionEnd 932fd4e5da5Sopenharmony_ci)"; 933fd4e5da5Sopenharmony_ci 934fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 935fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 936fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 937fd4e5da5Sopenharmony_ci} 938fd4e5da5Sopenharmony_ci 939fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithLoopAndFConvert) { 940fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 941fd4e5da5Sopenharmony_ci // 942fd4e5da5Sopenharmony_ci // The loop causes an FConvert to be generated at the bottom of the loop 943fd4e5da5Sopenharmony_ci // for the Phi. The FConvert is later processed and turned into a (dead) 944fd4e5da5Sopenharmony_ci // copy. 945fd4e5da5Sopenharmony_ci // 946fd4e5da5Sopenharmony_ci // clang-format off 947fd4e5da5Sopenharmony_ci // 948fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 949fd4e5da5Sopenharmony_ci // { 950fd4e5da5Sopenharmony_ci // float4 Color : SV_Target0; 951fd4e5da5Sopenharmony_ci // }; 952fd4e5da5Sopenharmony_ci // 953fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 954fd4e5da5Sopenharmony_ci // float4 a[10]; 955fd4e5da5Sopenharmony_ci // } 956fd4e5da5Sopenharmony_ci // 957fd4e5da5Sopenharmony_ci // PS_OUTPUT main() 958fd4e5da5Sopenharmony_ci // { 959fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 960fd4e5da5Sopenharmony_ci // float4 t = 0.0;; 961fd4e5da5Sopenharmony_ci // 962fd4e5da5Sopenharmony_ci // for (int i = 0; i<10; ++i) 963fd4e5da5Sopenharmony_ci // t = t + a[i]; 964fd4e5da5Sopenharmony_ci // 965fd4e5da5Sopenharmony_ci // float4 t2 = t / 10.0; 966fd4e5da5Sopenharmony_ci // psout.Color = t2; 967fd4e5da5Sopenharmony_ci // return psout; 968fd4e5da5Sopenharmony_ci // } 969fd4e5da5Sopenharmony_ci // 970fd4e5da5Sopenharmony_ci // clang-format on 971fd4e5da5Sopenharmony_ci 972fd4e5da5Sopenharmony_ci const std::string defs_before = 973fd4e5da5Sopenharmony_ci R"(OpCapability Shader 974fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 975fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 976fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 977fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 978fd4e5da5Sopenharmony_ciOpSource HLSL 500 979fd4e5da5Sopenharmony_ciOpName %main "main" 980fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 981fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "a" 982fd4e5da5Sopenharmony_ciOpName %_ "" 983fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 984fd4e5da5Sopenharmony_ciOpDecorate %_arr_v4float_uint_10 ArrayStride 16 985fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 986fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 987fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 988fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 0 989fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 990fd4e5da5Sopenharmony_ciOpDecorate %96 RelaxedPrecision 991fd4e5da5Sopenharmony_ciOpDecorate %81 RelaxedPrecision 992fd4e5da5Sopenharmony_ciOpDecorate %75 RelaxedPrecision 993fd4e5da5Sopenharmony_ciOpDecorate %76 RelaxedPrecision 994fd4e5da5Sopenharmony_ci%void = OpTypeVoid 995fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 996fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 997fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 998fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 999fd4e5da5Sopenharmony_ci%15 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 1000fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 1001fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 1002fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10 1003fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1004fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0 1005fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10 1006fd4e5da5Sopenharmony_ci%_arr_v4float_uint_10 = OpTypeArray %v4float %uint_10 1007fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %_arr_v4float_uint_10 1008fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 1009fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 1010fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float 1011fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 1012fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1013fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 1014fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 1015fd4e5da5Sopenharmony_ci%94 = OpConstantComposite %v4float %float_0_100000001 %float_0_100000001 %float_0_100000001 %float_0_100000001 1016fd4e5da5Sopenharmony_ci)"; 1017fd4e5da5Sopenharmony_ci 1018fd4e5da5Sopenharmony_ci const std::string defs_after = 1019fd4e5da5Sopenharmony_ci R"(OpCapability Shader 1020fd4e5da5Sopenharmony_ciOpCapability Float16 1021fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 1022fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1023fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_entryPointOutput_Color 1024fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1025fd4e5da5Sopenharmony_ciOpSource HLSL 500 1026fd4e5da5Sopenharmony_ciOpName %main "main" 1027fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 1028fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "a" 1029fd4e5da5Sopenharmony_ciOpName %_ "" 1030fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 1031fd4e5da5Sopenharmony_ciOpDecorate %_arr_v4float_uint_10 ArrayStride 16 1032fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 1033fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 1034fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 1035fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 0 1036fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 1037fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1038fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 1039fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1040fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 1041fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1042fd4e5da5Sopenharmony_ci%15 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0 1043fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 1044fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 1045fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10 1046fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1047fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0 1048fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10 1049fd4e5da5Sopenharmony_ci%_arr_v4float_uint_10 = OpTypeArray %v4float %uint_10 1050fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %_arr_v4float_uint_10 1051fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 1052fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 1053fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float 1054fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 1055fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1056fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 1057fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001 1058fd4e5da5Sopenharmony_ci%94 = OpConstantComposite %v4float %float_0_100000001 %float_0_100000001 %float_0_100000001 %float_0_100000001 1059fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 1060fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 1061fd4e5da5Sopenharmony_ci)"; 1062fd4e5da5Sopenharmony_ci 1063fd4e5da5Sopenharmony_ci const std::string func_before = 1064fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 1065fd4e5da5Sopenharmony_ci%5 = OpLabel 1066fd4e5da5Sopenharmony_ciOpBranch %65 1067fd4e5da5Sopenharmony_ci%65 = OpLabel 1068fd4e5da5Sopenharmony_ci%96 = OpPhi %v4float %15 %5 %76 %71 1069fd4e5da5Sopenharmony_ci%95 = OpPhi %int %int_0 %5 %78 %71 1070fd4e5da5Sopenharmony_ci%70 = OpSLessThan %bool %95 %int_10 1071fd4e5da5Sopenharmony_ciOpLoopMerge %66 %71 None 1072fd4e5da5Sopenharmony_ciOpBranchConditional %70 %71 %66 1073fd4e5da5Sopenharmony_ci%71 = OpLabel 1074fd4e5da5Sopenharmony_ci%74 = OpAccessChain %_ptr_Uniform_v4float %_ %int_0 %95 1075fd4e5da5Sopenharmony_ci%75 = OpLoad %v4float %74 1076fd4e5da5Sopenharmony_ci%76 = OpFAdd %v4float %96 %75 1077fd4e5da5Sopenharmony_ci%78 = OpIAdd %int %95 %int_1 1078fd4e5da5Sopenharmony_ciOpBranch %65 1079fd4e5da5Sopenharmony_ci%66 = OpLabel 1080fd4e5da5Sopenharmony_ci%81 = OpFMul %v4float %96 %94 1081fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %81 1082fd4e5da5Sopenharmony_ciOpReturn 1083fd4e5da5Sopenharmony_ciOpFunctionEnd 1084fd4e5da5Sopenharmony_ci)"; 1085fd4e5da5Sopenharmony_ci 1086fd4e5da5Sopenharmony_ci const std::string func_after = 1087fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 1088fd4e5da5Sopenharmony_ci%5 = OpLabel 1089fd4e5da5Sopenharmony_ci%99 = OpFConvert %v4half %15 1090fd4e5da5Sopenharmony_ciOpBranch %65 1091fd4e5da5Sopenharmony_ci%65 = OpLabel 1092fd4e5da5Sopenharmony_ci%96 = OpPhi %v4half %99 %5 %100 %71 1093fd4e5da5Sopenharmony_ci%95 = OpPhi %int %int_0 %5 %78 %71 1094fd4e5da5Sopenharmony_ci%70 = OpSLessThan %bool %95 %int_10 1095fd4e5da5Sopenharmony_ciOpLoopMerge %66 %71 None 1096fd4e5da5Sopenharmony_ciOpBranchConditional %70 %71 %66 1097fd4e5da5Sopenharmony_ci%71 = OpLabel 1098fd4e5da5Sopenharmony_ci%74 = OpAccessChain %_ptr_Uniform_v4float %_ %int_0 %95 1099fd4e5da5Sopenharmony_ci%75 = OpLoad %v4float %74 1100fd4e5da5Sopenharmony_ci%103 = OpFConvert %v4half %75 1101fd4e5da5Sopenharmony_ci%76 = OpFAdd %v4half %96 %103 1102fd4e5da5Sopenharmony_ci%78 = OpIAdd %int %95 %int_1 1103fd4e5da5Sopenharmony_ci%100 = OpCopyObject %v4half %76 1104fd4e5da5Sopenharmony_ciOpBranch %65 1105fd4e5da5Sopenharmony_ci%66 = OpLabel 1106fd4e5da5Sopenharmony_ci%101 = OpFConvert %v4half %94 1107fd4e5da5Sopenharmony_ci%81 = OpFMul %v4half %96 %101 1108fd4e5da5Sopenharmony_ci%102 = OpFConvert %v4float %81 1109fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %102 1110fd4e5da5Sopenharmony_ciOpReturn 1111fd4e5da5Sopenharmony_ciOpFunctionEnd 1112fd4e5da5Sopenharmony_ci)"; 1113fd4e5da5Sopenharmony_ci 1114fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1115fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 1116fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 1117fd4e5da5Sopenharmony_ci} 1118fd4e5da5Sopenharmony_ci 1119fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithExtracts) { 1120fd4e5da5Sopenharmony_ci // The resulting SPIR-V was processed with --relax-float-ops. 1121fd4e5da5Sopenharmony_ci // 1122fd4e5da5Sopenharmony_ci // The extra converts in the func_after can be DCE'd. 1123fd4e5da5Sopenharmony_ci // 1124fd4e5da5Sopenharmony_ci // clang-format off 1125fd4e5da5Sopenharmony_ci // 1126fd4e5da5Sopenharmony_ci // SamplerState g_sSamp : register(s0); 1127fd4e5da5Sopenharmony_ci // uniform Texture1D <float4> g_tTex1df4 : register(t0); 1128fd4e5da5Sopenharmony_ci // 1129fd4e5da5Sopenharmony_ci // struct PS_INPUT 1130fd4e5da5Sopenharmony_ci // { 1131fd4e5da5Sopenharmony_ci // float Tex0 : TEXCOORD0; 1132fd4e5da5Sopenharmony_ci // }; 1133fd4e5da5Sopenharmony_ci // 1134fd4e5da5Sopenharmony_ci // struct PS_OUTPUT 1135fd4e5da5Sopenharmony_ci // { 1136fd4e5da5Sopenharmony_ci // float4 Color : SV_Target0; 1137fd4e5da5Sopenharmony_ci // }; 1138fd4e5da5Sopenharmony_ci // 1139fd4e5da5Sopenharmony_ci // cbuffer cbuff{ 1140fd4e5da5Sopenharmony_ci // float c; 1141fd4e5da5Sopenharmony_ci // } 1142fd4e5da5Sopenharmony_ci // 1143fd4e5da5Sopenharmony_ci // PS_OUTPUT main(PS_INPUT i) 1144fd4e5da5Sopenharmony_ci // { 1145fd4e5da5Sopenharmony_ci // PS_OUTPUT psout; 1146fd4e5da5Sopenharmony_ci // float4 tx = g_tTex1df4.Sample(g_sSamp, i.Tex0); 1147fd4e5da5Sopenharmony_ci // float4 t = float4(tx.y, tx.z, tx.x, tx.w) * c; 1148fd4e5da5Sopenharmony_ci // psout.Color = t; 1149fd4e5da5Sopenharmony_ci // return psout; 1150fd4e5da5Sopenharmony_ci // } 1151fd4e5da5Sopenharmony_ci // 1152fd4e5da5Sopenharmony_ci // clang-format on 1153fd4e5da5Sopenharmony_ci 1154fd4e5da5Sopenharmony_ci const std::string defs_before = 1155fd4e5da5Sopenharmony_ci R"(OpCapability Shader 1156fd4e5da5Sopenharmony_ciOpCapability Sampled1D 1157fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 1158fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1159fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %_entryPointOutput_Color 1160fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1161fd4e5da5Sopenharmony_ciOpSource HLSL 500 1162fd4e5da5Sopenharmony_ciOpName %main "main" 1163fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 1164fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 1165fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 1166fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c" 1167fd4e5da5Sopenharmony_ciOpName %_ "" 1168fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 1169fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 1170fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 1171fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 1172fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 1173fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 1174fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 1175fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 1176fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 1177fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 1178fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 1179fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 1180fd4e5da5Sopenharmony_ciOpDecorate %65 RelaxedPrecision 1181fd4e5da5Sopenharmony_ciOpDecorate %82 RelaxedPrecision 1182fd4e5da5Sopenharmony_ciOpDecorate %84 RelaxedPrecision 1183fd4e5da5Sopenharmony_ciOpDecorate %86 RelaxedPrecision 1184fd4e5da5Sopenharmony_ciOpDecorate %88 RelaxedPrecision 1185fd4e5da5Sopenharmony_ciOpDecorate %90 RelaxedPrecision 1186fd4e5da5Sopenharmony_ciOpDecorate %91 RelaxedPrecision 1187fd4e5da5Sopenharmony_ciOpDecorate %93 RelaxedPrecision 1188fd4e5da5Sopenharmony_ciOpDecorate %94 RelaxedPrecision 1189fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1190fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 1191fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1192fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 1193fd4e5da5Sopenharmony_ci%17 = OpTypeImage %float 1D 0 0 0 1 Unknown 1194fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17 1195fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_17 UniformConstant 1196fd4e5da5Sopenharmony_ci%21 = OpTypeSampler 1197fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21 1198fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_21 UniformConstant 1199fd4e5da5Sopenharmony_ci%25 = OpTypeSampledImage %17 1200fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 1201fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 1202fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float 1203fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 1204fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 1205fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 1206fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 1207fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 1208fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1209fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 1210fd4e5da5Sopenharmony_ci)"; 1211fd4e5da5Sopenharmony_ci 1212fd4e5da5Sopenharmony_ci const std::string defs_after = 1213fd4e5da5Sopenharmony_ci R"(OpCapability Shader 1214fd4e5da5Sopenharmony_ciOpCapability Sampled1D 1215fd4e5da5Sopenharmony_ciOpCapability Float16 1216fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 1217fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1218fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i_Tex0 %_entryPointOutput_Color 1219fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1220fd4e5da5Sopenharmony_ciOpSource HLSL 500 1221fd4e5da5Sopenharmony_ciOpName %main "main" 1222fd4e5da5Sopenharmony_ciOpName %g_tTex1df4 "g_tTex1df4" 1223fd4e5da5Sopenharmony_ciOpName %g_sSamp "g_sSamp" 1224fd4e5da5Sopenharmony_ciOpName %cbuff "cbuff" 1225fd4e5da5Sopenharmony_ciOpMemberName %cbuff 0 "c" 1226fd4e5da5Sopenharmony_ciOpName %_ "" 1227fd4e5da5Sopenharmony_ciOpName %i_Tex0 "i.Tex0" 1228fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_Color "@entryPointOutput.Color" 1229fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 DescriptorSet 0 1230fd4e5da5Sopenharmony_ciOpDecorate %g_tTex1df4 Binding 0 1231fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp DescriptorSet 0 1232fd4e5da5Sopenharmony_ciOpDecorate %g_sSamp Binding 0 1233fd4e5da5Sopenharmony_ciOpMemberDecorate %cbuff 0 Offset 0 1234fd4e5da5Sopenharmony_ciOpDecorate %cbuff Block 1235fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0 1236fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 1 1237fd4e5da5Sopenharmony_ciOpDecorate %i_Tex0 Location 0 1238fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_Color Location 0 1239fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1240fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 1241fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1242fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4 1243fd4e5da5Sopenharmony_ci%17 = OpTypeImage %float 1D 0 0 0 1 Unknown 1244fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17 1245fd4e5da5Sopenharmony_ci%g_tTex1df4 = OpVariable %_ptr_UniformConstant_17 UniformConstant 1246fd4e5da5Sopenharmony_ci%21 = OpTypeSampler 1247fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21 1248fd4e5da5Sopenharmony_ci%g_sSamp = OpVariable %_ptr_UniformConstant_21 UniformConstant 1249fd4e5da5Sopenharmony_ci%25 = OpTypeSampledImage %17 1250fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1 1251fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 1252fd4e5da5Sopenharmony_ci%cbuff = OpTypeStruct %float 1253fd4e5da5Sopenharmony_ci%_ptr_Uniform_cbuff = OpTypePointer Uniform %cbuff 1254fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_cbuff Uniform 1255fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 1256fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float 1257fd4e5da5Sopenharmony_ci%i_Tex0 = OpVariable %_ptr_Input_float Input 1258fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1259fd4e5da5Sopenharmony_ci%_entryPointOutput_Color = OpVariable %_ptr_Output_v4float Output 1260fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 1261fd4e5da5Sopenharmony_ci%v4half = OpTypeVector %half 4 1262fd4e5da5Sopenharmony_ci)"; 1263fd4e5da5Sopenharmony_ci 1264fd4e5da5Sopenharmony_ci const std::string func_before = 1265fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 1266fd4e5da5Sopenharmony_ci%5 = OpLabel 1267fd4e5da5Sopenharmony_ci%65 = OpLoad %float %i_Tex0 1268fd4e5da5Sopenharmony_ci%77 = OpLoad %17 %g_tTex1df4 1269fd4e5da5Sopenharmony_ci%78 = OpLoad %21 %g_sSamp 1270fd4e5da5Sopenharmony_ci%79 = OpSampledImage %25 %77 %78 1271fd4e5da5Sopenharmony_ci%82 = OpImageSampleImplicitLod %v4float %79 %65 1272fd4e5da5Sopenharmony_ci%84 = OpCompositeExtract %float %82 1 1273fd4e5da5Sopenharmony_ci%86 = OpCompositeExtract %float %82 2 1274fd4e5da5Sopenharmony_ci%88 = OpCompositeExtract %float %82 0 1275fd4e5da5Sopenharmony_ci%90 = OpCompositeExtract %float %82 3 1276fd4e5da5Sopenharmony_ci%91 = OpCompositeConstruct %v4float %84 %86 %88 %90 1277fd4e5da5Sopenharmony_ci%92 = OpAccessChain %_ptr_Uniform_float %_ %int_0 1278fd4e5da5Sopenharmony_ci%93 = OpLoad %float %92 1279fd4e5da5Sopenharmony_ci%94 = OpVectorTimesScalar %v4float %91 %93 1280fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %94 1281fd4e5da5Sopenharmony_ciOpReturn 1282fd4e5da5Sopenharmony_ciOpFunctionEnd 1283fd4e5da5Sopenharmony_ci)"; 1284fd4e5da5Sopenharmony_ci 1285fd4e5da5Sopenharmony_ci const std::string func_after = 1286fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 1287fd4e5da5Sopenharmony_ci%5 = OpLabel 1288fd4e5da5Sopenharmony_ci%65 = OpLoad %float %i_Tex0 1289fd4e5da5Sopenharmony_ci%77 = OpLoad %17 %g_tTex1df4 1290fd4e5da5Sopenharmony_ci%78 = OpLoad %21 %g_sSamp 1291fd4e5da5Sopenharmony_ci%79 = OpSampledImage %25 %77 %78 1292fd4e5da5Sopenharmony_ci%82 = OpImageSampleImplicitLod %v4float %79 %65 1293fd4e5da5Sopenharmony_ci%97 = OpFConvert %v4half %82 1294fd4e5da5Sopenharmony_ci%84 = OpCompositeExtract %half %97 1 1295fd4e5da5Sopenharmony_ci%98 = OpFConvert %v4half %82 1296fd4e5da5Sopenharmony_ci%86 = OpCompositeExtract %half %98 2 1297fd4e5da5Sopenharmony_ci%99 = OpFConvert %v4half %82 1298fd4e5da5Sopenharmony_ci%88 = OpCompositeExtract %half %99 0 1299fd4e5da5Sopenharmony_ci%100 = OpFConvert %v4half %82 1300fd4e5da5Sopenharmony_ci%90 = OpCompositeExtract %half %100 3 1301fd4e5da5Sopenharmony_ci%91 = OpCompositeConstruct %v4half %84 %86 %88 %90 1302fd4e5da5Sopenharmony_ci%92 = OpAccessChain %_ptr_Uniform_float %_ %int_0 1303fd4e5da5Sopenharmony_ci%93 = OpLoad %float %92 1304fd4e5da5Sopenharmony_ci%101 = OpFConvert %half %93 1305fd4e5da5Sopenharmony_ci%94 = OpVectorTimesScalar %v4half %91 %101 1306fd4e5da5Sopenharmony_ci%102 = OpFConvert %v4float %94 1307fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_Color %102 1308fd4e5da5Sopenharmony_ciOpReturn 1309fd4e5da5Sopenharmony_ciOpFunctionEnd 1310fd4e5da5Sopenharmony_ci)"; 1311fd4e5da5Sopenharmony_ci 1312fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1313fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(defs_before + func_before, 1314fd4e5da5Sopenharmony_ci defs_after + func_after, true, true); 1315fd4e5da5Sopenharmony_ci} 1316fd4e5da5Sopenharmony_ci 1317fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, ConvertToHalfWithClosure) { 1318fd4e5da5Sopenharmony_ci // Include as many contiguous composite instructions as possible into 1319fd4e5da5Sopenharmony_ci // half-precision computations 1320fd4e5da5Sopenharmony_ci // 1321fd4e5da5Sopenharmony_ci // Compiled with glslang -V -Os 1322fd4e5da5Sopenharmony_ci // 1323fd4e5da5Sopenharmony_ci // clang-format off 1324fd4e5da5Sopenharmony_ci // 1325fd4e5da5Sopenharmony_ci // #version 410 core 1326fd4e5da5Sopenharmony_ci // 1327fd4e5da5Sopenharmony_ci // precision mediump float; 1328fd4e5da5Sopenharmony_ci // 1329fd4e5da5Sopenharmony_ci // layout(location = 1) in vec3 foo; 1330fd4e5da5Sopenharmony_ci // layout(location = 2) in mat2 bar; 1331fd4e5da5Sopenharmony_ci // layout(location = 1) out vec3 res; 1332fd4e5da5Sopenharmony_ci // 1333fd4e5da5Sopenharmony_ci // vec3 func(vec3 tap, mat2 M) { 1334fd4e5da5Sopenharmony_ci // return vec3(M * tap.xy, 1.0); 1335fd4e5da5Sopenharmony_ci // } 1336fd4e5da5Sopenharmony_ci // 1337fd4e5da5Sopenharmony_ci // void main() { 1338fd4e5da5Sopenharmony_ci // res = func(foo, bar); 1339fd4e5da5Sopenharmony_ci // } 1340fd4e5da5Sopenharmony_ci // 1341fd4e5da5Sopenharmony_ci // clang-format on 1342fd4e5da5Sopenharmony_ci 1343fd4e5da5Sopenharmony_ci const std::string defs = 1344fd4e5da5Sopenharmony_ci R"(OpCapability Shader 1345fd4e5da5Sopenharmony_ci; CHECK: OpCapability Float16 1346fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450" 1347fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1348fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %res %foo %bar 1349fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1350fd4e5da5Sopenharmony_ciOpSource GLSL 410 1351fd4e5da5Sopenharmony_ciOpName %main "main" 1352fd4e5da5Sopenharmony_ciOpName %res "res" 1353fd4e5da5Sopenharmony_ciOpName %foo "foo" 1354fd4e5da5Sopenharmony_ciOpName %bar "bar" 1355fd4e5da5Sopenharmony_ciOpDecorate %res RelaxedPrecision 1356fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %res RelaxedPrecision 1357fd4e5da5Sopenharmony_ciOpDecorate %res Location 1 1358fd4e5da5Sopenharmony_ciOpDecorate %foo RelaxedPrecision 1359fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %foo RelaxedPrecision 1360fd4e5da5Sopenharmony_ciOpDecorate %foo Location 1 1361fd4e5da5Sopenharmony_ciOpDecorate %bar RelaxedPrecision 1362fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %bar RelaxedPrecision 1363fd4e5da5Sopenharmony_ciOpDecorate %bar Location 2 1364fd4e5da5Sopenharmony_ciOpDecorate %34 RelaxedPrecision 1365fd4e5da5Sopenharmony_ciOpDecorate %36 RelaxedPrecision 1366fd4e5da5Sopenharmony_ciOpDecorate %41 RelaxedPrecision 1367fd4e5da5Sopenharmony_ciOpDecorate %42 RelaxedPrecision 1368fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %34 RelaxedPrecision 1369fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %36 RelaxedPrecision 1370fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %41 RelaxedPrecision 1371fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate %42 RelaxedPrecision 1372fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1373fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void 1374fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1375fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3 1376fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2 1377fd4e5da5Sopenharmony_ci%mat2v2float = OpTypeMatrix %v2float 2 1378fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1 1379fd4e5da5Sopenharmony_ci%_ptr_Output_v3float = OpTypePointer Output %v3float 1380fd4e5da5Sopenharmony_ci%res = OpVariable %_ptr_Output_v3float Output 1381fd4e5da5Sopenharmony_ci%_ptr_Input_v3float = OpTypePointer Input %v3float 1382fd4e5da5Sopenharmony_ci%foo = OpVariable %_ptr_Input_v3float Input 1383fd4e5da5Sopenharmony_ci%_ptr_Input_mat2v2float = OpTypePointer Input %mat2v2float 1384fd4e5da5Sopenharmony_ci%bar = OpVariable %_ptr_Input_mat2v2float Input 1385fd4e5da5Sopenharmony_ci)"; 1386fd4e5da5Sopenharmony_ci 1387fd4e5da5Sopenharmony_ci const std::string func = 1388fd4e5da5Sopenharmony_ci R"(%main = OpFunction %void None %3 1389fd4e5da5Sopenharmony_ci%5 = OpLabel 1390fd4e5da5Sopenharmony_ci%34 = OpLoad %v3float %foo 1391fd4e5da5Sopenharmony_ci%36 = OpLoad %mat2v2float %bar 1392fd4e5da5Sopenharmony_ci; CHECK: %48 = OpFConvert %v3half %34 1393fd4e5da5Sopenharmony_ci; CHECK: %49 = OpFConvert %v3half %34 1394fd4e5da5Sopenharmony_ci%41 = OpVectorShuffle %v2float %34 %34 0 1 1395fd4e5da5Sopenharmony_ci; CHECK-NOT: %41 = OpVectorShuffle %v2float %34 %34 0 1 1396fd4e5da5Sopenharmony_ci; CHECK: %41 = OpVectorShuffle %v2half %48 %49 0 1 1397fd4e5da5Sopenharmony_ci%42 = OpMatrixTimesVector %v2float %36 %41 1398fd4e5da5Sopenharmony_ci; CHECK-NOT: %42 = OpMatrixTimesVector %v2float %36 %41 1399fd4e5da5Sopenharmony_ci; CHECK: %55 = OpCompositeExtract %v2float %36 0 1400fd4e5da5Sopenharmony_ci; CHECK: %56 = OpFConvert %v2half %55 1401fd4e5da5Sopenharmony_ci; CHECK: %57 = OpCompositeExtract %v2float %36 1 1402fd4e5da5Sopenharmony_ci; CHECK: %58 = OpFConvert %v2half %57 1403fd4e5da5Sopenharmony_ci; CHECK: %59 = OpCompositeConstruct %mat2v2half %56 %58 1404fd4e5da5Sopenharmony_ci; CHECK: %52 = OpCopyObject %mat2v2float %36 1405fd4e5da5Sopenharmony_ci; CHECK: %42 = OpMatrixTimesVector %v2half %59 %41 1406fd4e5da5Sopenharmony_ci%43 = OpCompositeExtract %float %42 0 1407fd4e5da5Sopenharmony_ci%44 = OpCompositeExtract %float %42 1 1408fd4e5da5Sopenharmony_ci; CHECK-NOT: %43 = OpCompositeExtract %float %42 0 1409fd4e5da5Sopenharmony_ci; CHECK-NOT: %44 = OpCompositeExtract %float %42 1 1410fd4e5da5Sopenharmony_ci; CHECK: %43 = OpCompositeExtract %half %42 0 1411fd4e5da5Sopenharmony_ci; CHECK: %44 = OpCompositeExtract %half %42 1 1412fd4e5da5Sopenharmony_ci%45 = OpCompositeConstruct %v3float %43 %44 %float_1 1413fd4e5da5Sopenharmony_ci; CHECK-NOT: %45 = OpCompositeConstruct %v3float %43 %44 %float_1 1414fd4e5da5Sopenharmony_ci; CHECK: %53 = OpFConvert %float %43 1415fd4e5da5Sopenharmony_ci; CHECK: %54 = OpFConvert %float %44 1416fd4e5da5Sopenharmony_ci; CHECK: %45 = OpCompositeConstruct %v3float %53 %54 %float_1 1417fd4e5da5Sopenharmony_ciOpStore %res %45 1418fd4e5da5Sopenharmony_ciOpReturn 1419fd4e5da5Sopenharmony_ciOpFunctionEnd 1420fd4e5da5Sopenharmony_ci)"; 1421fd4e5da5Sopenharmony_ci 1422fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1423fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<ConvertToHalfPass>(defs + func, true); 1424fd4e5da5Sopenharmony_ci} 1425fd4e5da5Sopenharmony_ci 1426fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, RemoveRelaxDec) { 1427fd4e5da5Sopenharmony_ci // See https://github.com/KhronosGroup/SPIRV-Tools/issues/4117 1428fd4e5da5Sopenharmony_ci 1429fd4e5da5Sopenharmony_ci // This test is a case where the relax precision decorations need to be 1430fd4e5da5Sopenharmony_ci // removed, but the body of the function does not change because there are not 1431fd4e5da5Sopenharmony_ci // arithmetic operations. So, there is not need for the Float16 capability. 1432fd4e5da5Sopenharmony_ci const std::string test = 1433fd4e5da5Sopenharmony_ci R"( 1434fd4e5da5Sopenharmony_ci; CHECK-NOT: OpCapability Float16 1435fd4e5da5Sopenharmony_ci; GLSL seems to generate this decoration on the load of a texture, which seems odd to me. 1436fd4e5da5Sopenharmony_ci; This pass does not currently remove it, and I'm not sure what we should do with it, so I will leave it. 1437fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[tex:%\w+]] RelaxedPrecision 1438fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{%\w+}} RelaxedPrecision 1439fd4e5da5Sopenharmony_ci; CHECK: OpLabel 1440fd4e5da5Sopenharmony_ci; CHECK: [[tex]] = OpLoad {{%\w+}} %sTexture 1441fd4e5da5Sopenharmony_ci; CHECK: [[coord:%\w+]] = OpLoad %v2float 1442fd4e5da5Sopenharmony_ci; CHECK: [[retval:%\w+]] = OpImageSampleImplicitLod %v4float {{%\w+}} [[coord]] 1443fd4e5da5Sopenharmony_ci; CHECK: OpStore %outFragColor [[retval]] 1444fd4e5da5Sopenharmony_ci OpCapability Shader 1445fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "GLSL.std.450" 1446fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 1447fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %outFragColor %v_texcoord 1448fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 1449fd4e5da5Sopenharmony_ci OpSource ESSL 310 1450fd4e5da5Sopenharmony_ci OpName %main "main" 1451fd4e5da5Sopenharmony_ci OpName %outFragColor "outFragColor" 1452fd4e5da5Sopenharmony_ci OpName %sTexture "sTexture" 1453fd4e5da5Sopenharmony_ci OpName %v_texcoord "v_texcoord" 1454fd4e5da5Sopenharmony_ci OpDecorate %outFragColor RelaxedPrecision 1455fd4e5da5Sopenharmony_ci OpDecorate %outFragColor Location 0 1456fd4e5da5Sopenharmony_ci OpDecorate %sTexture RelaxedPrecision 1457fd4e5da5Sopenharmony_ci OpDecorate %sTexture DescriptorSet 0 1458fd4e5da5Sopenharmony_ci OpDecorate %sTexture Binding 0 1459fd4e5da5Sopenharmony_ci OpDecorate %14 RelaxedPrecision 1460fd4e5da5Sopenharmony_ci OpDecorate %v_texcoord RelaxedPrecision 1461fd4e5da5Sopenharmony_ci OpDecorate %v_texcoord Location 0 1462fd4e5da5Sopenharmony_ci OpDecorate %18 RelaxedPrecision 1463fd4e5da5Sopenharmony_ci OpDecorate %19 RelaxedPrecision 1464fd4e5da5Sopenharmony_ci %void = OpTypeVoid 1465fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 1466fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 1467fd4e5da5Sopenharmony_ci %v4float = OpTypeVector %float 4 1468fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1469fd4e5da5Sopenharmony_ci%outFragColor = OpVariable %_ptr_Output_v4float Output 1470fd4e5da5Sopenharmony_ci %10 = OpTypeImage %float 2D 0 0 0 1 Unknown 1471fd4e5da5Sopenharmony_ci %11 = OpTypeSampledImage %10 1472fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 1473fd4e5da5Sopenharmony_ci %sTexture = OpVariable %_ptr_UniformConstant_11 UniformConstant 1474fd4e5da5Sopenharmony_ci %v2float = OpTypeVector %float 2 1475fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float 1476fd4e5da5Sopenharmony_ci %v_texcoord = OpVariable %_ptr_Input_v2float Input 1477fd4e5da5Sopenharmony_ci %main = OpFunction %void None %3 1478fd4e5da5Sopenharmony_ci %5 = OpLabel 1479fd4e5da5Sopenharmony_ci %14 = OpLoad %11 %sTexture 1480fd4e5da5Sopenharmony_ci %18 = OpLoad %v2float %v_texcoord 1481fd4e5da5Sopenharmony_ci %19 = OpImageSampleImplicitLod %v4float %14 %18 1482fd4e5da5Sopenharmony_ci OpStore %outFragColor %19 1483fd4e5da5Sopenharmony_ci OpReturn 1484fd4e5da5Sopenharmony_ci OpFunctionEnd 1485fd4e5da5Sopenharmony_ci)"; 1486fd4e5da5Sopenharmony_ci 1487fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1488fd4e5da5Sopenharmony_ci auto result = SinglePassRunAndMatch<ConvertToHalfPass>(test, true); 1489fd4e5da5Sopenharmony_ci EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); 1490fd4e5da5Sopenharmony_ci} 1491fd4e5da5Sopenharmony_ci 1492fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, HandleNonRelaxedPhi) { 1493fd4e5da5Sopenharmony_ci // See https://github.com/KhronosGroup/SPIRV-Tools/issues/4452 1494fd4e5da5Sopenharmony_ci 1495fd4e5da5Sopenharmony_ci // This test is a case with a non-relaxed phi with a relaxed operand. 1496fd4e5da5Sopenharmony_ci // A convert must be inserted at the end of the block associated with 1497fd4e5da5Sopenharmony_ci // the operand. 1498fd4e5da5Sopenharmony_ci const std::string test = 1499fd4e5da5Sopenharmony_ci R"( 1500fd4e5da5Sopenharmony_ci; CHECK: [[fcvt:%\w+]] = OpFConvert %v3float {{%\w+}} 1501fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpSelectionMerge {{%\w+}} None 1502fd4e5da5Sopenharmony_ci; CHECK: {{%\w+}} = OpPhi %v3float [[fcvt]] {{%\w+}} {{%\w+}} {{%\w+}} 1503fd4e5da5Sopenharmony_ci OpCapability Shader 1504fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "GLSL.std.450" 1505fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 1506fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %main "main" %output_color 1507fd4e5da5Sopenharmony_ci OpExecutionMode %main OriginUpperLeft 1508fd4e5da5Sopenharmony_ci OpSource GLSL 450 1509fd4e5da5Sopenharmony_ci OpName %main "main" 1510fd4e5da5Sopenharmony_ci OpName %MaterialParams "MaterialParams" 1511fd4e5da5Sopenharmony_ci OpMemberName %MaterialParams 0 "foo" 1512fd4e5da5Sopenharmony_ci OpName %materialParams "materialParams" 1513fd4e5da5Sopenharmony_ci OpName %output_color "output_color" 1514fd4e5da5Sopenharmony_ci OpMemberDecorate %MaterialParams 0 Offset 0 1515fd4e5da5Sopenharmony_ci OpDecorate %MaterialParams Block 1516fd4e5da5Sopenharmony_ci OpDecorate %materialParams DescriptorSet 0 1517fd4e5da5Sopenharmony_ci OpDecorate %materialParams Binding 5 1518fd4e5da5Sopenharmony_ci OpDecorate %output_color Location 0 1519fd4e5da5Sopenharmony_ci OpDecorate %57 RelaxedPrecision 1520fd4e5da5Sopenharmony_ci %void = OpTypeVoid 1521fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %void 1522fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 1523fd4e5da5Sopenharmony_ci %v3float = OpTypeVector %float 3 1524fd4e5da5Sopenharmony_ci%MaterialParams = OpTypeStruct %float 1525fd4e5da5Sopenharmony_ci%_ptr_Uniform_MaterialParams = OpTypePointer Uniform %MaterialParams 1526fd4e5da5Sopenharmony_ci%materialParams = OpVariable %_ptr_Uniform_MaterialParams Uniform 1527fd4e5da5Sopenharmony_ci %int = OpTypeInt 32 1 1528fd4e5da5Sopenharmony_ci %int_0 = OpConstant %int 0 1529fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float 1530fd4e5da5Sopenharmony_ci %float_0 = OpConstant %float 0 1531fd4e5da5Sopenharmony_ci %bool = OpTypeBool 1532fd4e5da5Sopenharmony_ci %v4float = OpTypeVector %float 4 1533fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float 1534fd4e5da5Sopenharmony_ci%output_color = OpVariable %_ptr_Output_v4float Output 1535fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 1536fd4e5da5Sopenharmony_ci %uint_0 = OpConstant %uint 0 1537fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float 1538fd4e5da5Sopenharmony_ci %uint_1 = OpConstant %uint 1 1539fd4e5da5Sopenharmony_ci %uint_2 = OpConstant %uint 2 1540fd4e5da5Sopenharmony_ci %float_0_5 = OpConstant %float 0.5 1541fd4e5da5Sopenharmony_ci %61 = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0_5 1542fd4e5da5Sopenharmony_ci %main = OpFunction %void None %3 1543fd4e5da5Sopenharmony_ci %5 = OpLabel 1544fd4e5da5Sopenharmony_ci %55 = OpAccessChain %_ptr_Uniform_float %materialParams %int_0 1545fd4e5da5Sopenharmony_ci %56 = OpLoad %float %55 1546fd4e5da5Sopenharmony_ci %57 = OpCompositeConstruct %v3float %56 %56 %56 1547fd4e5da5Sopenharmony_ci %31 = OpFOrdGreaterThan %bool %56 %float_0 1548fd4e5da5Sopenharmony_ci OpSelectionMerge %33 None 1549fd4e5da5Sopenharmony_ci OpBranchConditional %31 %32 %33 1550fd4e5da5Sopenharmony_ci %32 = OpLabel 1551fd4e5da5Sopenharmony_ci %37 = OpFMul %v3float %57 %61 1552fd4e5da5Sopenharmony_ci OpBranch %33 1553fd4e5da5Sopenharmony_ci %33 = OpLabel 1554fd4e5da5Sopenharmony_ci %58 = OpPhi %v3float %57 %5 %37 %32 1555fd4e5da5Sopenharmony_ci %45 = OpAccessChain %_ptr_Output_float %output_color %uint_0 1556fd4e5da5Sopenharmony_ci %46 = OpCompositeExtract %float %58 0 1557fd4e5da5Sopenharmony_ci OpStore %45 %46 1558fd4e5da5Sopenharmony_ci %48 = OpAccessChain %_ptr_Output_float %output_color %uint_1 1559fd4e5da5Sopenharmony_ci %49 = OpCompositeExtract %float %58 1 1560fd4e5da5Sopenharmony_ci OpStore %48 %49 1561fd4e5da5Sopenharmony_ci %51 = OpAccessChain %_ptr_Output_float %output_color %uint_2 1562fd4e5da5Sopenharmony_ci %52 = OpCompositeExtract %float %58 2 1563fd4e5da5Sopenharmony_ci OpStore %51 %52 1564fd4e5da5Sopenharmony_ci OpReturn 1565fd4e5da5Sopenharmony_ci OpFunctionEnd 1566fd4e5da5Sopenharmony_ci)"; 1567fd4e5da5Sopenharmony_ci 1568fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1569fd4e5da5Sopenharmony_ci auto result = SinglePassRunAndMatch<ConvertToHalfPass>(test, true); 1570fd4e5da5Sopenharmony_ci EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result)); 1571fd4e5da5Sopenharmony_ci} 1572fd4e5da5Sopenharmony_ci 1573fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, DoNotReplaceStructMember) { 1574fd4e5da5Sopenharmony_ci // See https://github.com/KhronosGroup/SPIRV-Tools/issues/4814 1575fd4e5da5Sopenharmony_ci 1576fd4e5da5Sopenharmony_ci // This test is a case with a non-relaxed phi with a relaxed operand. 1577fd4e5da5Sopenharmony_ci // A convert must be inserted at the end of the block associated with 1578fd4e5da5Sopenharmony_ci // the operand. 1579fd4e5da5Sopenharmony_ci const std::string test = 1580fd4e5da5Sopenharmony_ci R"(OpCapability Shader 1581fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1582fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %PSMain "PSMain" %out_var_SV_TARGET %MyConstants 1583fd4e5da5Sopenharmony_ciOpExecutionMode %PSMain OriginUpperLeft 1584fd4e5da5Sopenharmony_ciOpSource HLSL 600 1585fd4e5da5Sopenharmony_ciOpName %type_ConstantBuffer_myStruct "type.ConstantBuffer.myStruct" 1586fd4e5da5Sopenharmony_ciOpMemberName %type_ConstantBuffer_myStruct 0 "f" 1587fd4e5da5Sopenharmony_ciOpName %MyConstants "MyConstants" 1588fd4e5da5Sopenharmony_ciOpName %out_var_SV_TARGET "out.var.SV_TARGET" 1589fd4e5da5Sopenharmony_ciOpName %PSMain "PSMain" 1590fd4e5da5Sopenharmony_ciOpDecorate %out_var_SV_TARGET Location 0 1591fd4e5da5Sopenharmony_ciOpDecorate %MyConstants DescriptorSet 1 1592fd4e5da5Sopenharmony_ciOpDecorate %MyConstants Binding 2 1593fd4e5da5Sopenharmony_ciOpMemberDecorate %type_ConstantBuffer_myStruct 0 Offset 0 1594fd4e5da5Sopenharmony_ciOpDecorate %type_ConstantBuffer_myStruct Block 1595fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1596fd4e5da5Sopenharmony_ci%type_ConstantBuffer_myStruct = OpTypeStruct %float 1597fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ConstantBuffer_myStruct = OpTypePointer Uniform %type_ConstantBuffer_myStruct 1598fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float 1599fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1600fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void 1601fd4e5da5Sopenharmony_ci%MyConstants = OpVariable %_ptr_Uniform_type_ConstantBuffer_myStruct Uniform 1602fd4e5da5Sopenharmony_ci%out_var_SV_TARGET = OpVariable %_ptr_Output_float Output 1603fd4e5da5Sopenharmony_ci%PSMain = OpFunction %void None %9 1604fd4e5da5Sopenharmony_ci%10 = OpLabel 1605fd4e5da5Sopenharmony_ci%11 = OpLoad %type_ConstantBuffer_myStruct %MyConstants 1606fd4e5da5Sopenharmony_ci%12 = OpCompositeExtract %float %11 0 1607fd4e5da5Sopenharmony_ciOpStore %out_var_SV_TARGET %12 1608fd4e5da5Sopenharmony_ciOpReturn 1609fd4e5da5Sopenharmony_ciOpFunctionEnd 1610fd4e5da5Sopenharmony_ci)"; 1611fd4e5da5Sopenharmony_ci 1612fd4e5da5Sopenharmony_ci SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); 1613fd4e5da5Sopenharmony_ci SinglePassRunAndCheck<ConvertToHalfPass>(test, test, true); 1614fd4e5da5Sopenharmony_ci} 1615fd4e5da5Sopenharmony_ci 1616fd4e5da5Sopenharmony_ciTEST_F(ConvertToHalfTest, PreserveImageOperandPrecision) { 1617fd4e5da5Sopenharmony_ci // Ensure that a non-relaxed texture coordinate does not get relaxed nor 1618fd4e5da5Sopenharmony_ci // converted to half precision if the image instruction is marked relaxed. 1619fd4e5da5Sopenharmony_ci 1620fd4e5da5Sopenharmony_ci // Also ensure that a relaxed local variable does get converted to half 1621fd4e5da5Sopenharmony_ci // precision before being passed to an image opeartor. 1622fd4e5da5Sopenharmony_ci 1623fd4e5da5Sopenharmony_ci // #version 310 es 1624fd4e5da5Sopenharmony_ci // 1625fd4e5da5Sopenharmony_ci // precision mediump float; 1626fd4e5da5Sopenharmony_ci // 1627fd4e5da5Sopenharmony_ci // layout(location = 10) in highp vec4 vertex_uv01; 1628fd4e5da5Sopenharmony_ci // layout(binding = 0, set = 3) uniform sampler2D materialParams_baseColorMap; 1629fd4e5da5Sopenharmony_ci // 1630fd4e5da5Sopenharmony_ci // layout(location = 0) out vec4 fragColor; 1631fd4e5da5Sopenharmony_ci // 1632fd4e5da5Sopenharmony_ci // void main() { 1633fd4e5da5Sopenharmony_ci // vec4 uv = vec4(2.0); 1634fd4e5da5Sopenharmony_ci // fragColor = texture(materialParams_baseColorMap, uv.xy); 1635fd4e5da5Sopenharmony_ci // fragColor = texture(materialParams_baseColorMap, vertex_uv01.xy); 1636fd4e5da5Sopenharmony_ci // } 1637fd4e5da5Sopenharmony_ci const std::string test = R"( 1638fd4e5da5Sopenharmony_ci OpCapability Shader 1639fd4e5da5Sopenharmony_ci OpCapability Float16 1640fd4e5da5Sopenharmony_ci %1 = OpExtInstImport "GLSL.std.450" 1641fd4e5da5Sopenharmony_ci OpMemoryModel Logical GLSL450 1642fd4e5da5Sopenharmony_ci OpEntryPoint Fragment %4 "main" %13 %25 1643fd4e5da5Sopenharmony_ci OpExecutionMode %4 OriginUpperLeft 1644fd4e5da5Sopenharmony_ci OpSource ESSL 310 1645fd4e5da5Sopenharmony_ci OpDecorate %9 RelaxedPrecision 1646fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[uv:%\w+]] RelaxedPrecision 1647fd4e5da5Sopenharmony_ci OpDecorate %13 Location 0 1648fd4e5da5Sopenharmony_ci OpDecorate %17 DescriptorSet 3 1649fd4e5da5Sopenharmony_ci OpDecorate %17 Binding 0 1650fd4e5da5Sopenharmony_ci OpDecorate %18 RelaxedPrecision 1651fd4e5da5Sopenharmony_ci OpDecorate %23 RelaxedPrecision 1652fd4e5da5Sopenharmony_ci OpDecorate %25 Location 10 1653fd4e5da5Sopenharmony_ci %2 = OpTypeVoid 1654fd4e5da5Sopenharmony_ci %3 = OpTypeFunction %2 1655fd4e5da5Sopenharmony_ci %6 = OpTypeFloat 32 1656fd4e5da5Sopenharmony_ci;CHECK: [[float32_t:%\w+]] = OpTypeFloat 32 1657fd4e5da5Sopenharmony_ci %7 = OpTypeVector %6 4 1658fd4e5da5Sopenharmony_ci;CHECK: [[vec4_t:%\w+]] = OpTypeVector [[float32_t]] 4 1659fd4e5da5Sopenharmony_ci %8 = OpTypePointer Function %7 1660fd4e5da5Sopenharmony_ci %10 = OpConstant %6 2 1661fd4e5da5Sopenharmony_ci %11 = OpConstantComposite %7 %10 %10 %10 %10 1662fd4e5da5Sopenharmony_ci %12 = OpTypePointer Output %7 1663fd4e5da5Sopenharmony_ci;CHECK: [[output_ptr_t:%\w+]] = OpTypePointer Output [[vec4_t]] 1664fd4e5da5Sopenharmony_ci %13 = OpVariable %12 Output 1665fd4e5da5Sopenharmony_ci;CHECK: [[output:%\w+]] = OpVariable [[output_ptr_t]] Output 1666fd4e5da5Sopenharmony_ci %14 = OpTypeImage %6 2D 0 0 0 1 Unknown 1667fd4e5da5Sopenharmony_ci %15 = OpTypeSampledImage %14 1668fd4e5da5Sopenharmony_ci %16 = OpTypePointer UniformConstant %15 1669fd4e5da5Sopenharmony_ci %17 = OpVariable %16 UniformConstant 1670fd4e5da5Sopenharmony_ci %19 = OpTypeVector %6 2 1671fd4e5da5Sopenharmony_ci;CHECK: [[vec2_t:%\w+]] = OpTypeVector [[float32_t]] 2 1672fd4e5da5Sopenharmony_ci %24 = OpTypePointer Input %7 1673fd4e5da5Sopenharmony_ci;CHECK: [[input_ptr_t:%\w+]] = OpTypePointer Input [[vec4_t]] 1674fd4e5da5Sopenharmony_ci %25 = OpVariable %24 Input 1675fd4e5da5Sopenharmony_ci %29 = OpTypeFloat 16 1676fd4e5da5Sopenharmony_ci;CHECK: [[float16_t:%\w+]] = OpTypeFloat 16 1677fd4e5da5Sopenharmony_ci %30 = OpTypeVector %29 4 1678fd4e5da5Sopenharmony_ci %33 = OpTypeVector %29 2 1679fd4e5da5Sopenharmony_ci;CHECK: [[vec2_16b_t:%\w+]] = OpTypeVector [[float16_t]] 2 1680fd4e5da5Sopenharmony_ci %4 = OpFunction %2 None %3 1681fd4e5da5Sopenharmony_ci %5 = OpLabel 1682fd4e5da5Sopenharmony_ci 1683fd4e5da5Sopenharmony_ci; The only Function storage variable is marked as relaxed 1684fd4e5da5Sopenharmony_ci %9 = OpVariable %8 Function 1685fd4e5da5Sopenharmony_ci;CHECK: [[uv]] = OpVariable {{%\w+}} Function 1686fd4e5da5Sopenharmony_ci OpStore %9 %11 1687fd4e5da5Sopenharmony_ci %18 = OpLoad %15 %17 1688fd4e5da5Sopenharmony_ci %20 = OpLoad %7 %9 1689fd4e5da5Sopenharmony_ci %31 = OpFConvert %30 %20 1690fd4e5da5Sopenharmony_ci %32 = OpFConvert %30 %20 1691fd4e5da5Sopenharmony_ci 1692fd4e5da5Sopenharmony_ci; The first sample op should get a 16b coordinate 1693fd4e5da5Sopenharmony_ci %21 = OpVectorShuffle %33 %31 %32 0 1 1694fd4e5da5Sopenharmony_ci;CHECK: [[uv_16b:%\w+]] = OpVectorShuffle [[vec2_16b_t]] 1695fd4e5da5Sopenharmony_ci %22 = OpImageSampleImplicitLod %7 %18 %21 1696fd4e5da5Sopenharmony_ci;CHECK: OpImageSampleImplicitLod [[vec4_t]] {{%\w+}} [[uv_16b]] 1697fd4e5da5Sopenharmony_ci 1698fd4e5da5Sopenharmony_ci OpStore %13 %22 1699fd4e5da5Sopenharmony_ci %23 = OpLoad %15 %17 1700fd4e5da5Sopenharmony_ci %26 = OpLoad %7 %25 1701fd4e5da5Sopenharmony_ci 1702fd4e5da5Sopenharmony_ci; The second sample op should get a 32b coordinate 1703fd4e5da5Sopenharmony_ci %27 = OpVectorShuffle %19 %26 %26 0 1 1704fd4e5da5Sopenharmony_ci;CHECK: [[uv_32b:%\w+]] = OpVectorShuffle [[vec2_t]] 1705fd4e5da5Sopenharmony_ci %28 = OpImageSampleImplicitLod %7 %23 %27 1706fd4e5da5Sopenharmony_ci;CHECK: OpImageSampleImplicitLod [[vec4_t]] {{%\w+}} [[uv_32b]] 1707fd4e5da5Sopenharmony_ci 1708fd4e5da5Sopenharmony_ci OpStore %13 %28 1709fd4e5da5Sopenharmony_ci OpReturn 1710fd4e5da5Sopenharmony_ci OpFunctionEnd 1711fd4e5da5Sopenharmony_ci )"; 1712fd4e5da5Sopenharmony_ci 1713fd4e5da5Sopenharmony_ci SinglePassRunAndMatch<ConvertToHalfPass>(test, true); 1714fd4e5da5Sopenharmony_ci} 1715fd4e5da5Sopenharmony_ci 1716fd4e5da5Sopenharmony_ci} // namespace 1717fd4e5da5Sopenharmony_ci} // namespace opt 1718fd4e5da5Sopenharmony_ci} // namespace spvtools 1719