1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc. 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci// Tests for unique type declaration rules validator. 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include <string> 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_ci#include "gmock/gmock.h" 20fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h" 21fd4e5da5Sopenharmony_ci#include "test/val/val_code_generator.h" 22fd4e5da5Sopenharmony_ci#include "test/val/val_fixtures.h" 23fd4e5da5Sopenharmony_ci 24fd4e5da5Sopenharmony_cinamespace spvtools { 25fd4e5da5Sopenharmony_cinamespace val { 26fd4e5da5Sopenharmony_cinamespace { 27fd4e5da5Sopenharmony_ci 28fd4e5da5Sopenharmony_ciusing ::testing::HasSubstr; 29fd4e5da5Sopenharmony_ciusing ::testing::Not; 30fd4e5da5Sopenharmony_ciusing ::testing::Values; 31fd4e5da5Sopenharmony_ci 32fd4e5da5Sopenharmony_ciusing ValidateConversion = spvtest::ValidateBase<bool>; 33fd4e5da5Sopenharmony_ci 34fd4e5da5Sopenharmony_cistd::string GenerateShaderCode( 35fd4e5da5Sopenharmony_ci const std::string& body, 36fd4e5da5Sopenharmony_ci const std::string& capabilities_and_extensions = "", 37fd4e5da5Sopenharmony_ci const std::string& decorations = "", const std::string& types = "", 38fd4e5da5Sopenharmony_ci const std::string& variables = "") { 39fd4e5da5Sopenharmony_ci const std::string capabilities = 40fd4e5da5Sopenharmony_ci R"( 41fd4e5da5Sopenharmony_ciOpCapability Shader 42fd4e5da5Sopenharmony_ciOpCapability Int64 43fd4e5da5Sopenharmony_ciOpCapability Float64)"; 44fd4e5da5Sopenharmony_ci 45fd4e5da5Sopenharmony_ci const std::string after_extension_before_decorations = 46fd4e5da5Sopenharmony_ci R"( 47fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 48fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 49fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft)"; 50fd4e5da5Sopenharmony_ci 51fd4e5da5Sopenharmony_ci const std::string after_decorations_before_types = 52fd4e5da5Sopenharmony_ci R"( 53fd4e5da5Sopenharmony_ci%void = OpTypeVoid 54fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 55fd4e5da5Sopenharmony_ci%bool = OpTypeBool 56fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 57fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 58fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 59fd4e5da5Sopenharmony_ci%f64 = OpTypeFloat 64 60fd4e5da5Sopenharmony_ci%u64 = OpTypeInt 64 0 61fd4e5da5Sopenharmony_ci%s64 = OpTypeInt 64 1 62fd4e5da5Sopenharmony_ci%boolvec2 = OpTypeVector %bool 2 63fd4e5da5Sopenharmony_ci%s32vec2 = OpTypeVector %s32 2 64fd4e5da5Sopenharmony_ci%u32vec2 = OpTypeVector %u32 2 65fd4e5da5Sopenharmony_ci%u64vec2 = OpTypeVector %u64 2 66fd4e5da5Sopenharmony_ci%f32vec2 = OpTypeVector %f32 2 67fd4e5da5Sopenharmony_ci%f64vec2 = OpTypeVector %f64 2 68fd4e5da5Sopenharmony_ci%boolvec3 = OpTypeVector %bool 3 69fd4e5da5Sopenharmony_ci%u32vec3 = OpTypeVector %u32 3 70fd4e5da5Sopenharmony_ci%u64vec3 = OpTypeVector %u64 3 71fd4e5da5Sopenharmony_ci%s32vec3 = OpTypeVector %s32 3 72fd4e5da5Sopenharmony_ci%f32vec3 = OpTypeVector %f32 3 73fd4e5da5Sopenharmony_ci%f64vec3 = OpTypeVector %f64 3 74fd4e5da5Sopenharmony_ci%boolvec4 = OpTypeVector %bool 4 75fd4e5da5Sopenharmony_ci%u32vec4 = OpTypeVector %u32 4 76fd4e5da5Sopenharmony_ci%u64vec4 = OpTypeVector %u64 4 77fd4e5da5Sopenharmony_ci%s32vec4 = OpTypeVector %s32 4 78fd4e5da5Sopenharmony_ci%f32vec4 = OpTypeVector %f32 4 79fd4e5da5Sopenharmony_ci%f64vec4 = OpTypeVector %f64 4 80fd4e5da5Sopenharmony_ci 81fd4e5da5Sopenharmony_ci%f32_0 = OpConstant %f32 0 82fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1 83fd4e5da5Sopenharmony_ci%f32_2 = OpConstant %f32 2 84fd4e5da5Sopenharmony_ci%f32_3 = OpConstant %f32 3 85fd4e5da5Sopenharmony_ci%f32_4 = OpConstant %f32 4 86fd4e5da5Sopenharmony_ci 87fd4e5da5Sopenharmony_ci%s32_0 = OpConstant %s32 0 88fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1 89fd4e5da5Sopenharmony_ci%s32_2 = OpConstant %s32 2 90fd4e5da5Sopenharmony_ci%s32_3 = OpConstant %s32 3 91fd4e5da5Sopenharmony_ci%s32_4 = OpConstant %s32 4 92fd4e5da5Sopenharmony_ci%s32_m1 = OpConstant %s32 -1 93fd4e5da5Sopenharmony_ci 94fd4e5da5Sopenharmony_ci%u32_0 = OpConstant %u32 0 95fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1 96fd4e5da5Sopenharmony_ci%u32_2 = OpConstant %u32 2 97fd4e5da5Sopenharmony_ci%u32_3 = OpConstant %u32 3 98fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4 99fd4e5da5Sopenharmony_ci 100fd4e5da5Sopenharmony_ci%f64_0 = OpConstant %f64 0 101fd4e5da5Sopenharmony_ci%f64_1 = OpConstant %f64 1 102fd4e5da5Sopenharmony_ci%f64_2 = OpConstant %f64 2 103fd4e5da5Sopenharmony_ci%f64_3 = OpConstant %f64 3 104fd4e5da5Sopenharmony_ci%f64_4 = OpConstant %f64 4 105fd4e5da5Sopenharmony_ci 106fd4e5da5Sopenharmony_ci%s64_0 = OpConstant %s64 0 107fd4e5da5Sopenharmony_ci%s64_1 = OpConstant %s64 1 108fd4e5da5Sopenharmony_ci%s64_2 = OpConstant %s64 2 109fd4e5da5Sopenharmony_ci%s64_3 = OpConstant %s64 3 110fd4e5da5Sopenharmony_ci%s64_4 = OpConstant %s64 4 111fd4e5da5Sopenharmony_ci%s64_m1 = OpConstant %s64 -1 112fd4e5da5Sopenharmony_ci 113fd4e5da5Sopenharmony_ci%u64_0 = OpConstant %u64 0 114fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %u64 1 115fd4e5da5Sopenharmony_ci%u64_2 = OpConstant %u64 2 116fd4e5da5Sopenharmony_ci%u64_3 = OpConstant %u64 3 117fd4e5da5Sopenharmony_ci%u64_4 = OpConstant %u64 4 118fd4e5da5Sopenharmony_ci 119fd4e5da5Sopenharmony_ci%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1 120fd4e5da5Sopenharmony_ci%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2 121fd4e5da5Sopenharmony_ci%u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2 122fd4e5da5Sopenharmony_ci%u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3 123fd4e5da5Sopenharmony_ci%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3 124fd4e5da5Sopenharmony_ci%u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4 125fd4e5da5Sopenharmony_ci 126fd4e5da5Sopenharmony_ci%s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1 127fd4e5da5Sopenharmony_ci%s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2 128fd4e5da5Sopenharmony_ci%s32vec3_012 = OpConstantComposite %s32vec3 %s32_0 %s32_1 %s32_2 129fd4e5da5Sopenharmony_ci%s32vec3_123 = OpConstantComposite %s32vec3 %s32_1 %s32_2 %s32_3 130fd4e5da5Sopenharmony_ci%s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3 131fd4e5da5Sopenharmony_ci%s32vec4_1234 = OpConstantComposite %s32vec4 %s32_1 %s32_2 %s32_3 %s32_4 132fd4e5da5Sopenharmony_ci 133fd4e5da5Sopenharmony_ci%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1 134fd4e5da5Sopenharmony_ci%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2 135fd4e5da5Sopenharmony_ci%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2 136fd4e5da5Sopenharmony_ci%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3 137fd4e5da5Sopenharmony_ci%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3 138fd4e5da5Sopenharmony_ci%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4 139fd4e5da5Sopenharmony_ci 140fd4e5da5Sopenharmony_ci%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1 141fd4e5da5Sopenharmony_ci%f64vec2_12 = OpConstantComposite %f64vec2 %f64_1 %f64_2 142fd4e5da5Sopenharmony_ci%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2 143fd4e5da5Sopenharmony_ci%f64vec3_123 = OpConstantComposite %f64vec3 %f64_1 %f64_2 %f64_3 144fd4e5da5Sopenharmony_ci%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3 145fd4e5da5Sopenharmony_ci%f64vec4_1234 = OpConstantComposite %f64vec4 %f64_1 %f64_2 %f64_3 %f64_4 146fd4e5da5Sopenharmony_ci 147fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool 148fd4e5da5Sopenharmony_ci%false = OpConstantFalse %bool 149fd4e5da5Sopenharmony_ci 150fd4e5da5Sopenharmony_ci%f32ptr_func = OpTypePointer Function %f32)"; 151fd4e5da5Sopenharmony_ci 152fd4e5da5Sopenharmony_ci const std::string after_variables_before_body = 153fd4e5da5Sopenharmony_ci R"( 154fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 155fd4e5da5Sopenharmony_ci%main_entry = OpLabel)"; 156fd4e5da5Sopenharmony_ci 157fd4e5da5Sopenharmony_ci const std::string after_body = 158fd4e5da5Sopenharmony_ci R"( 159fd4e5da5Sopenharmony_ciOpReturn 160fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 161fd4e5da5Sopenharmony_ci 162fd4e5da5Sopenharmony_ci return capabilities + capabilities_and_extensions + 163fd4e5da5Sopenharmony_ci after_extension_before_decorations + decorations + 164fd4e5da5Sopenharmony_ci after_decorations_before_types + types + variables + 165fd4e5da5Sopenharmony_ci after_variables_before_body + body + after_body; 166fd4e5da5Sopenharmony_ci} 167fd4e5da5Sopenharmony_ci 168fd4e5da5Sopenharmony_cistd::string GenerateKernelCode( 169fd4e5da5Sopenharmony_ci const std::string& body, 170fd4e5da5Sopenharmony_ci const std::string& capabilities_and_extensions = "") { 171fd4e5da5Sopenharmony_ci const std::string capabilities = 172fd4e5da5Sopenharmony_ci R"( 173fd4e5da5Sopenharmony_ciOpCapability Addresses 174fd4e5da5Sopenharmony_ciOpCapability Kernel 175fd4e5da5Sopenharmony_ciOpCapability Linkage 176fd4e5da5Sopenharmony_ciOpCapability GenericPointer 177fd4e5da5Sopenharmony_ciOpCapability Int64 178fd4e5da5Sopenharmony_ciOpCapability Float64)"; 179fd4e5da5Sopenharmony_ci 180fd4e5da5Sopenharmony_ci const std::string after_extension_before_body = 181fd4e5da5Sopenharmony_ci R"( 182fd4e5da5Sopenharmony_ciOpMemoryModel Physical32 OpenCL 183fd4e5da5Sopenharmony_ci%void = OpTypeVoid 184fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 185fd4e5da5Sopenharmony_ci%bool = OpTypeBool 186fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 187fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 188fd4e5da5Sopenharmony_ci%f64 = OpTypeFloat 64 189fd4e5da5Sopenharmony_ci%u64 = OpTypeInt 64 0 190fd4e5da5Sopenharmony_ci%boolvec2 = OpTypeVector %bool 2 191fd4e5da5Sopenharmony_ci%u32vec2 = OpTypeVector %u32 2 192fd4e5da5Sopenharmony_ci%u64vec2 = OpTypeVector %u64 2 193fd4e5da5Sopenharmony_ci%f32vec2 = OpTypeVector %f32 2 194fd4e5da5Sopenharmony_ci%f64vec2 = OpTypeVector %f64 2 195fd4e5da5Sopenharmony_ci%boolvec3 = OpTypeVector %bool 3 196fd4e5da5Sopenharmony_ci%u32vec3 = OpTypeVector %u32 3 197fd4e5da5Sopenharmony_ci%u64vec3 = OpTypeVector %u64 3 198fd4e5da5Sopenharmony_ci%f32vec3 = OpTypeVector %f32 3 199fd4e5da5Sopenharmony_ci%f64vec3 = OpTypeVector %f64 3 200fd4e5da5Sopenharmony_ci%boolvec4 = OpTypeVector %bool 4 201fd4e5da5Sopenharmony_ci%u32vec4 = OpTypeVector %u32 4 202fd4e5da5Sopenharmony_ci%u64vec4 = OpTypeVector %u64 4 203fd4e5da5Sopenharmony_ci%f32vec4 = OpTypeVector %f32 4 204fd4e5da5Sopenharmony_ci%f64vec4 = OpTypeVector %f64 4 205fd4e5da5Sopenharmony_ci 206fd4e5da5Sopenharmony_ci%f32_0 = OpConstant %f32 0 207fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1 208fd4e5da5Sopenharmony_ci%f32_2 = OpConstant %f32 2 209fd4e5da5Sopenharmony_ci%f32_3 = OpConstant %f32 3 210fd4e5da5Sopenharmony_ci%f32_4 = OpConstant %f32 4 211fd4e5da5Sopenharmony_ci 212fd4e5da5Sopenharmony_ci%u32_0 = OpConstant %u32 0 213fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1 214fd4e5da5Sopenharmony_ci%u32_2 = OpConstant %u32 2 215fd4e5da5Sopenharmony_ci%u32_3 = OpConstant %u32 3 216fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4 217fd4e5da5Sopenharmony_ci 218fd4e5da5Sopenharmony_ci%f64_0 = OpConstant %f64 0 219fd4e5da5Sopenharmony_ci%f64_1 = OpConstant %f64 1 220fd4e5da5Sopenharmony_ci%f64_2 = OpConstant %f64 2 221fd4e5da5Sopenharmony_ci%f64_3 = OpConstant %f64 3 222fd4e5da5Sopenharmony_ci%f64_4 = OpConstant %f64 4 223fd4e5da5Sopenharmony_ci 224fd4e5da5Sopenharmony_ci%u64_0 = OpConstant %u64 0 225fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %u64 1 226fd4e5da5Sopenharmony_ci%u64_2 = OpConstant %u64 2 227fd4e5da5Sopenharmony_ci%u64_3 = OpConstant %u64 3 228fd4e5da5Sopenharmony_ci%u64_4 = OpConstant %u64 4 229fd4e5da5Sopenharmony_ci 230fd4e5da5Sopenharmony_ci%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1 231fd4e5da5Sopenharmony_ci%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2 232fd4e5da5Sopenharmony_ci%u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2 233fd4e5da5Sopenharmony_ci%u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3 234fd4e5da5Sopenharmony_ci%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3 235fd4e5da5Sopenharmony_ci%u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4 236fd4e5da5Sopenharmony_ci 237fd4e5da5Sopenharmony_ci%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1 238fd4e5da5Sopenharmony_ci%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2 239fd4e5da5Sopenharmony_ci%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2 240fd4e5da5Sopenharmony_ci%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3 241fd4e5da5Sopenharmony_ci%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3 242fd4e5da5Sopenharmony_ci%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4 243fd4e5da5Sopenharmony_ci 244fd4e5da5Sopenharmony_ci%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1 245fd4e5da5Sopenharmony_ci%f64vec2_12 = OpConstantComposite %f64vec2 %f64_1 %f64_2 246fd4e5da5Sopenharmony_ci%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2 247fd4e5da5Sopenharmony_ci%f64vec3_123 = OpConstantComposite %f64vec3 %f64_1 %f64_2 %f64_3 248fd4e5da5Sopenharmony_ci%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3 249fd4e5da5Sopenharmony_ci%f64vec4_1234 = OpConstantComposite %f64vec4 %f64_1 %f64_2 %f64_3 %f64_4 250fd4e5da5Sopenharmony_ci 251fd4e5da5Sopenharmony_ci%u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1 252fd4e5da5Sopenharmony_ci 253fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool 254fd4e5da5Sopenharmony_ci%false = OpConstantFalse %bool 255fd4e5da5Sopenharmony_ci 256fd4e5da5Sopenharmony_ci%f32ptr_func = OpTypePointer Function %f32 257fd4e5da5Sopenharmony_ci%u32ptr_func = OpTypePointer Function %u32 258fd4e5da5Sopenharmony_ci%f32ptr_gen = OpTypePointer Generic %f32 259fd4e5da5Sopenharmony_ci%f32ptr_inp = OpTypePointer Input %f32 260fd4e5da5Sopenharmony_ci%f32ptr_wg = OpTypePointer Workgroup %f32 261fd4e5da5Sopenharmony_ci%f32ptr_cwg = OpTypePointer CrossWorkgroup %f32 262fd4e5da5Sopenharmony_ci 263fd4e5da5Sopenharmony_ci%f32inp = OpVariable %f32ptr_inp Input 264fd4e5da5Sopenharmony_ci 265fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 266fd4e5da5Sopenharmony_ci%main_entry = OpLabel)"; 267fd4e5da5Sopenharmony_ci 268fd4e5da5Sopenharmony_ci const std::string after_body = 269fd4e5da5Sopenharmony_ci R"( 270fd4e5da5Sopenharmony_ciOpReturn 271fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 272fd4e5da5Sopenharmony_ci 273fd4e5da5Sopenharmony_ci return capabilities + capabilities_and_extensions + 274fd4e5da5Sopenharmony_ci after_extension_before_body + body + after_body; 275fd4e5da5Sopenharmony_ci} 276fd4e5da5Sopenharmony_ci 277fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToUSuccess) { 278fd4e5da5Sopenharmony_ci const std::string body = R"( 279fd4e5da5Sopenharmony_ci%val1 = OpConvertFToU %u32 %f32_1 280fd4e5da5Sopenharmony_ci%val2 = OpConvertFToU %u32 %f64_0 281fd4e5da5Sopenharmony_ci%val3 = OpConvertFToU %u32vec2 %f32vec2_01 282fd4e5da5Sopenharmony_ci)"; 283fd4e5da5Sopenharmony_ci 284fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 285fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 286fd4e5da5Sopenharmony_ci} 287fd4e5da5Sopenharmony_ci 288fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToUWrongResultType) { 289fd4e5da5Sopenharmony_ci const std::string body = R"( 290fd4e5da5Sopenharmony_ci%val = OpConvertFToU %s32 %f32_1 291fd4e5da5Sopenharmony_ci)"; 292fd4e5da5Sopenharmony_ci 293fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 294fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 295fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 296fd4e5da5Sopenharmony_ci HasSubstr("Expected unsigned int scalar or vector type as Result " 297fd4e5da5Sopenharmony_ci "Type: ConvertFToU")); 298fd4e5da5Sopenharmony_ci} 299fd4e5da5Sopenharmony_ci 300fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToUWrongInputType) { 301fd4e5da5Sopenharmony_ci const std::string body = R"( 302fd4e5da5Sopenharmony_ci%val = OpConvertFToU %u32 %u32_1 303fd4e5da5Sopenharmony_ci)"; 304fd4e5da5Sopenharmony_ci 305fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 306fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 307fd4e5da5Sopenharmony_ci EXPECT_THAT( 308fd4e5da5Sopenharmony_ci getDiagnosticString(), 309fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be float scalar or vector: ConvertFToU")); 310fd4e5da5Sopenharmony_ci} 311fd4e5da5Sopenharmony_ci 312fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToUDifferentDimension) { 313fd4e5da5Sopenharmony_ci const std::string body = R"( 314fd4e5da5Sopenharmony_ci%val = OpConvertFToU %u32 %f32vec2_01 315fd4e5da5Sopenharmony_ci)"; 316fd4e5da5Sopenharmony_ci 317fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 318fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 319fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 320fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 321fd4e5da5Sopenharmony_ci "Type: ConvertFToU")); 322fd4e5da5Sopenharmony_ci} 323fd4e5da5Sopenharmony_ci 324fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToSSuccess) { 325fd4e5da5Sopenharmony_ci const std::string body = R"( 326fd4e5da5Sopenharmony_ci%val1 = OpConvertFToS %s32 %f32_1 327fd4e5da5Sopenharmony_ci%val2 = OpConvertFToS %u32 %f64_0 328fd4e5da5Sopenharmony_ci%val3 = OpConvertFToS %s32vec2 %f32vec2_01 329fd4e5da5Sopenharmony_ci)"; 330fd4e5da5Sopenharmony_ci 331fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 332fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 333fd4e5da5Sopenharmony_ci} 334fd4e5da5Sopenharmony_ci 335fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToSWrongResultType) { 336fd4e5da5Sopenharmony_ci const std::string body = R"( 337fd4e5da5Sopenharmony_ci%val = OpConvertFToS %bool %f32_1 338fd4e5da5Sopenharmony_ci)"; 339fd4e5da5Sopenharmony_ci 340fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 341fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 342fd4e5da5Sopenharmony_ci EXPECT_THAT( 343fd4e5da5Sopenharmony_ci getDiagnosticString(), 344fd4e5da5Sopenharmony_ci HasSubstr( 345fd4e5da5Sopenharmony_ci "Expected int scalar or vector type as Result Type: ConvertFToS")); 346fd4e5da5Sopenharmony_ci} 347fd4e5da5Sopenharmony_ci 348fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToSWrongInputType) { 349fd4e5da5Sopenharmony_ci const std::string body = R"( 350fd4e5da5Sopenharmony_ci%val = OpConvertFToS %s32 %u32_1 351fd4e5da5Sopenharmony_ci)"; 352fd4e5da5Sopenharmony_ci 353fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 354fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 355fd4e5da5Sopenharmony_ci EXPECT_THAT( 356fd4e5da5Sopenharmony_ci getDiagnosticString(), 357fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be float scalar or vector: ConvertFToS")); 358fd4e5da5Sopenharmony_ci} 359fd4e5da5Sopenharmony_ci 360fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertFToSDifferentDimension) { 361fd4e5da5Sopenharmony_ci const std::string body = R"( 362fd4e5da5Sopenharmony_ci%val = OpConvertFToS %u32 %f32vec2_01 363fd4e5da5Sopenharmony_ci)"; 364fd4e5da5Sopenharmony_ci 365fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 366fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 367fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 368fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 369fd4e5da5Sopenharmony_ci "Type: ConvertFToS")); 370fd4e5da5Sopenharmony_ci} 371fd4e5da5Sopenharmony_ci 372fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertSToFSuccess) { 373fd4e5da5Sopenharmony_ci const std::string body = R"( 374fd4e5da5Sopenharmony_ci%val1 = OpConvertSToF %f32 %u32_1 375fd4e5da5Sopenharmony_ci%val2 = OpConvertSToF %f32 %s64_0 376fd4e5da5Sopenharmony_ci%val3 = OpConvertSToF %f32vec2 %s32vec2_01 377fd4e5da5Sopenharmony_ci)"; 378fd4e5da5Sopenharmony_ci 379fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 380fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 381fd4e5da5Sopenharmony_ci} 382fd4e5da5Sopenharmony_ci 383fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertSToFWrongResultType) { 384fd4e5da5Sopenharmony_ci const std::string body = R"( 385fd4e5da5Sopenharmony_ci%val = OpConvertSToF %u32 %s32_1 386fd4e5da5Sopenharmony_ci)"; 387fd4e5da5Sopenharmony_ci 388fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 389fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 390fd4e5da5Sopenharmony_ci EXPECT_THAT( 391fd4e5da5Sopenharmony_ci getDiagnosticString(), 392fd4e5da5Sopenharmony_ci HasSubstr( 393fd4e5da5Sopenharmony_ci "Expected float scalar or vector type as Result Type: ConvertSToF")); 394fd4e5da5Sopenharmony_ci} 395fd4e5da5Sopenharmony_ci 396fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertSToFWrongInputType) { 397fd4e5da5Sopenharmony_ci const std::string body = R"( 398fd4e5da5Sopenharmony_ci%val = OpConvertSToF %f32 %f32_1 399fd4e5da5Sopenharmony_ci)"; 400fd4e5da5Sopenharmony_ci 401fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 402fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 403fd4e5da5Sopenharmony_ci EXPECT_THAT( 404fd4e5da5Sopenharmony_ci getDiagnosticString(), 405fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be int scalar or vector: ConvertSToF")); 406fd4e5da5Sopenharmony_ci} 407fd4e5da5Sopenharmony_ci 408fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertSToFDifferentDimension) { 409fd4e5da5Sopenharmony_ci const std::string body = R"( 410fd4e5da5Sopenharmony_ci%val = OpConvertSToF %f32 %u32vec2_01 411fd4e5da5Sopenharmony_ci)"; 412fd4e5da5Sopenharmony_ci 413fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 414fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 415fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 416fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 417fd4e5da5Sopenharmony_ci "Type: ConvertSToF")); 418fd4e5da5Sopenharmony_ci} 419fd4e5da5Sopenharmony_ci 420fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, UConvertSuccess) { 421fd4e5da5Sopenharmony_ci const std::string body = R"( 422fd4e5da5Sopenharmony_ci%val1 = OpUConvert %u32 %u64_1 423fd4e5da5Sopenharmony_ci%val2 = OpUConvert %u64 %s32_0 424fd4e5da5Sopenharmony_ci%val3 = OpUConvert %u64vec2 %s32vec2_01 425fd4e5da5Sopenharmony_ci)"; 426fd4e5da5Sopenharmony_ci 427fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 428fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 429fd4e5da5Sopenharmony_ci} 430fd4e5da5Sopenharmony_ci 431fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, UConvertWrongResultType) { 432fd4e5da5Sopenharmony_ci const std::string body = R"( 433fd4e5da5Sopenharmony_ci%val = OpUConvert %s32 %s32_1 434fd4e5da5Sopenharmony_ci)"; 435fd4e5da5Sopenharmony_ci 436fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 437fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 438fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 439fd4e5da5Sopenharmony_ci HasSubstr("Expected unsigned int scalar or vector type as Result " 440fd4e5da5Sopenharmony_ci "Type: UConvert")); 441fd4e5da5Sopenharmony_ci} 442fd4e5da5Sopenharmony_ci 443fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, UConvertWrongInputType) { 444fd4e5da5Sopenharmony_ci const std::string body = R"( 445fd4e5da5Sopenharmony_ci%val = OpUConvert %u32 %f32_1 446fd4e5da5Sopenharmony_ci)"; 447fd4e5da5Sopenharmony_ci 448fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 449fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 450fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 451fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be int scalar or vector: UConvert")); 452fd4e5da5Sopenharmony_ci} 453fd4e5da5Sopenharmony_ci 454fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, UConvertDifferentDimension) { 455fd4e5da5Sopenharmony_ci const std::string body = R"( 456fd4e5da5Sopenharmony_ci%val = OpUConvert %u32 %u32vec2_01 457fd4e5da5Sopenharmony_ci)"; 458fd4e5da5Sopenharmony_ci 459fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 460fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 461fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 462fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 463fd4e5da5Sopenharmony_ci "Type: UConvert")); 464fd4e5da5Sopenharmony_ci} 465fd4e5da5Sopenharmony_ci 466fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, UConvertSameBitWidth) { 467fd4e5da5Sopenharmony_ci const std::string body = R"( 468fd4e5da5Sopenharmony_ci%val = OpUConvert %u32 %s32_1 469fd4e5da5Sopenharmony_ci)"; 470fd4e5da5Sopenharmony_ci 471fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 472fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 473fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 474fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have different bit width from " 475fd4e5da5Sopenharmony_ci "Result Type: UConvert")); 476fd4e5da5Sopenharmony_ci} 477fd4e5da5Sopenharmony_ci 478fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SConvertSuccess) { 479fd4e5da5Sopenharmony_ci const std::string body = R"( 480fd4e5da5Sopenharmony_ci%val1 = OpSConvert %s32 %u64_1 481fd4e5da5Sopenharmony_ci%val2 = OpSConvert %s64 %s32_0 482fd4e5da5Sopenharmony_ci%val3 = OpSConvert %u64vec2 %s32vec2_01 483fd4e5da5Sopenharmony_ci)"; 484fd4e5da5Sopenharmony_ci 485fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 486fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 487fd4e5da5Sopenharmony_ci} 488fd4e5da5Sopenharmony_ci 489fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SConvertWrongResultType) { 490fd4e5da5Sopenharmony_ci const std::string body = R"( 491fd4e5da5Sopenharmony_ci%val = OpSConvert %f32 %s32_1 492fd4e5da5Sopenharmony_ci)"; 493fd4e5da5Sopenharmony_ci 494fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 495fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 496fd4e5da5Sopenharmony_ci EXPECT_THAT( 497fd4e5da5Sopenharmony_ci getDiagnosticString(), 498fd4e5da5Sopenharmony_ci HasSubstr("Expected int scalar or vector type as Result Type: SConvert")); 499fd4e5da5Sopenharmony_ci} 500fd4e5da5Sopenharmony_ci 501fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SConvertWrongInputType) { 502fd4e5da5Sopenharmony_ci const std::string body = R"( 503fd4e5da5Sopenharmony_ci%val = OpSConvert %u32 %f32_1 504fd4e5da5Sopenharmony_ci)"; 505fd4e5da5Sopenharmony_ci 506fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 507fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 508fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 509fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be int scalar or vector: SConvert")); 510fd4e5da5Sopenharmony_ci} 511fd4e5da5Sopenharmony_ci 512fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SConvertDifferentDimension) { 513fd4e5da5Sopenharmony_ci const std::string body = R"( 514fd4e5da5Sopenharmony_ci%val = OpSConvert %s32 %u32vec2_01 515fd4e5da5Sopenharmony_ci)"; 516fd4e5da5Sopenharmony_ci 517fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 518fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 519fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 520fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 521fd4e5da5Sopenharmony_ci "Type: SConvert")); 522fd4e5da5Sopenharmony_ci} 523fd4e5da5Sopenharmony_ci 524fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SConvertSameBitWidth) { 525fd4e5da5Sopenharmony_ci const std::string body = R"( 526fd4e5da5Sopenharmony_ci%val = OpSConvert %u32 %s32_1 527fd4e5da5Sopenharmony_ci)"; 528fd4e5da5Sopenharmony_ci 529fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 530fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 531fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 532fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have different bit width from " 533fd4e5da5Sopenharmony_ci "Result Type: SConvert")); 534fd4e5da5Sopenharmony_ci} 535fd4e5da5Sopenharmony_ci 536fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, FConvertSuccess) { 537fd4e5da5Sopenharmony_ci const std::string body = R"( 538fd4e5da5Sopenharmony_ci%val1 = OpFConvert %f32 %f64_1 539fd4e5da5Sopenharmony_ci%val2 = OpFConvert %f64 %f32_0 540fd4e5da5Sopenharmony_ci%val3 = OpFConvert %f64vec2 %f32vec2_01 541fd4e5da5Sopenharmony_ci)"; 542fd4e5da5Sopenharmony_ci 543fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 544fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 545fd4e5da5Sopenharmony_ci} 546fd4e5da5Sopenharmony_ci 547fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, FConvertWrongResultType) { 548fd4e5da5Sopenharmony_ci const std::string body = R"( 549fd4e5da5Sopenharmony_ci%val = OpFConvert %u32 %f32_1 550fd4e5da5Sopenharmony_ci)"; 551fd4e5da5Sopenharmony_ci 552fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 553fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 554fd4e5da5Sopenharmony_ci EXPECT_THAT( 555fd4e5da5Sopenharmony_ci getDiagnosticString(), 556fd4e5da5Sopenharmony_ci HasSubstr( 557fd4e5da5Sopenharmony_ci "Expected float scalar or vector type as Result Type: FConvert")); 558fd4e5da5Sopenharmony_ci} 559fd4e5da5Sopenharmony_ci 560fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, FConvertWrongInputType) { 561fd4e5da5Sopenharmony_ci const std::string body = R"( 562fd4e5da5Sopenharmony_ci%val = OpFConvert %f32 %u64_1 563fd4e5da5Sopenharmony_ci)"; 564fd4e5da5Sopenharmony_ci 565fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 566fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 567fd4e5da5Sopenharmony_ci EXPECT_THAT( 568fd4e5da5Sopenharmony_ci getDiagnosticString(), 569fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be float scalar or vector: FConvert")); 570fd4e5da5Sopenharmony_ci} 571fd4e5da5Sopenharmony_ci 572fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, FConvertDifferentDimension) { 573fd4e5da5Sopenharmony_ci const std::string body = R"( 574fd4e5da5Sopenharmony_ci%val = OpFConvert %f64 %f32vec2_01 575fd4e5da5Sopenharmony_ci)"; 576fd4e5da5Sopenharmony_ci 577fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 578fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 579fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 580fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result " 581fd4e5da5Sopenharmony_ci "Type: FConvert")); 582fd4e5da5Sopenharmony_ci} 583fd4e5da5Sopenharmony_ci 584fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, FConvertSameBitWidth) { 585fd4e5da5Sopenharmony_ci const std::string body = R"( 586fd4e5da5Sopenharmony_ci%val = OpFConvert %f32 %f32_1 587fd4e5da5Sopenharmony_ci)"; 588fd4e5da5Sopenharmony_ci 589fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 590fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 591fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 592fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have different bit width from " 593fd4e5da5Sopenharmony_ci "Result Type: FConvert")); 594fd4e5da5Sopenharmony_ci} 595fd4e5da5Sopenharmony_ci 596fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, QuantizeToF16Success) { 597fd4e5da5Sopenharmony_ci const std::string body = R"( 598fd4e5da5Sopenharmony_ci%val1 = OpQuantizeToF16 %f32 %f32_1 599fd4e5da5Sopenharmony_ci%val2 = OpQuantizeToF16 %f32 %f32_0 600fd4e5da5Sopenharmony_ci%val3 = OpQuantizeToF16 %f32vec2 %f32vec2_01 601fd4e5da5Sopenharmony_ci)"; 602fd4e5da5Sopenharmony_ci 603fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 604fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 605fd4e5da5Sopenharmony_ci} 606fd4e5da5Sopenharmony_ci 607fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, QuantizeToF16WrongResultType) { 608fd4e5da5Sopenharmony_ci const std::string body = R"( 609fd4e5da5Sopenharmony_ci%val = OpQuantizeToF16 %u32 %f32_1 610fd4e5da5Sopenharmony_ci)"; 611fd4e5da5Sopenharmony_ci 612fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 613fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 614fd4e5da5Sopenharmony_ci EXPECT_THAT( 615fd4e5da5Sopenharmony_ci getDiagnosticString(), 616fd4e5da5Sopenharmony_ci HasSubstr("Expected 32-bit float scalar or vector type as Result Type: " 617fd4e5da5Sopenharmony_ci "QuantizeToF16")); 618fd4e5da5Sopenharmony_ci} 619fd4e5da5Sopenharmony_ci 620fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, QuantizeToF16WrongResultTypeBitWidth) { 621fd4e5da5Sopenharmony_ci const std::string body = R"( 622fd4e5da5Sopenharmony_ci%val = OpQuantizeToF16 %u64 %f64_1 623fd4e5da5Sopenharmony_ci)"; 624fd4e5da5Sopenharmony_ci 625fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 626fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 627fd4e5da5Sopenharmony_ci EXPECT_THAT( 628fd4e5da5Sopenharmony_ci getDiagnosticString(), 629fd4e5da5Sopenharmony_ci HasSubstr("Expected 32-bit float scalar or vector type as Result Type: " 630fd4e5da5Sopenharmony_ci "QuantizeToF16")); 631fd4e5da5Sopenharmony_ci} 632fd4e5da5Sopenharmony_ci 633fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, QuantizeToF16WrongInputType) { 634fd4e5da5Sopenharmony_ci const std::string body = R"( 635fd4e5da5Sopenharmony_ci%val = OpQuantizeToF16 %f32 %f64_1 636fd4e5da5Sopenharmony_ci)"; 637fd4e5da5Sopenharmony_ci 638fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body).c_str()); 639fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 640fd4e5da5Sopenharmony_ci EXPECT_THAT( 641fd4e5da5Sopenharmony_ci getDiagnosticString(), 642fd4e5da5Sopenharmony_ci HasSubstr( 643fd4e5da5Sopenharmony_ci "Expected input type to be equal to Result Type: QuantizeToF16")); 644fd4e5da5Sopenharmony_ci} 645fd4e5da5Sopenharmony_ci 646fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUSuccess) { 647fd4e5da5Sopenharmony_ci const std::string body = R"( 648fd4e5da5Sopenharmony_ci%ptr = OpVariable %f32ptr_func Function 649fd4e5da5Sopenharmony_ci%val1 = OpConvertPtrToU %u32 %ptr 650fd4e5da5Sopenharmony_ci%val2 = OpConvertPtrToU %u64 %ptr 651fd4e5da5Sopenharmony_ci)"; 652fd4e5da5Sopenharmony_ci 653fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 654fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 655fd4e5da5Sopenharmony_ci} 656fd4e5da5Sopenharmony_ci 657fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUWrongResultType) { 658fd4e5da5Sopenharmony_ci const std::string body = R"( 659fd4e5da5Sopenharmony_ci%ptr = OpVariable %f32ptr_func Function 660fd4e5da5Sopenharmony_ci%val = OpConvertPtrToU %f32 %ptr 661fd4e5da5Sopenharmony_ci)"; 662fd4e5da5Sopenharmony_ci 663fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 664fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 665fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 666fd4e5da5Sopenharmony_ci HasSubstr("Expected unsigned int scalar type as Result Type: " 667fd4e5da5Sopenharmony_ci "ConvertPtrToU")); 668fd4e5da5Sopenharmony_ci} 669fd4e5da5Sopenharmony_ci 670fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUNotPointer) { 671fd4e5da5Sopenharmony_ci const std::string body = R"( 672fd4e5da5Sopenharmony_ci%val = OpConvertPtrToU %u32 %f32_1 673fd4e5da5Sopenharmony_ci)"; 674fd4e5da5Sopenharmony_ci 675fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 676fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 677fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 678fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer: ConvertPtrToU")); 679fd4e5da5Sopenharmony_ci} 680fd4e5da5Sopenharmony_ci 681fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SatConvertSToUSuccess) { 682fd4e5da5Sopenharmony_ci const std::string body = R"( 683fd4e5da5Sopenharmony_ci%val1 = OpSatConvertSToU %u32 %u64_2 684fd4e5da5Sopenharmony_ci%val2 = OpSatConvertSToU %u64 %u32_1 685fd4e5da5Sopenharmony_ci%val3 = OpSatConvertSToU %u64vec2 %u32vec2_12 686fd4e5da5Sopenharmony_ci)"; 687fd4e5da5Sopenharmony_ci 688fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 689fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 690fd4e5da5Sopenharmony_ci} 691fd4e5da5Sopenharmony_ci 692fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SatConvertSToUWrongResultType) { 693fd4e5da5Sopenharmony_ci const std::string body = R"( 694fd4e5da5Sopenharmony_ci%val = OpSatConvertSToU %f32 %u32_1 695fd4e5da5Sopenharmony_ci)"; 696fd4e5da5Sopenharmony_ci 697fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 698fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 699fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 700fd4e5da5Sopenharmony_ci HasSubstr("Expected int scalar or vector type as Result Type: " 701fd4e5da5Sopenharmony_ci "SatConvertSToU")); 702fd4e5da5Sopenharmony_ci} 703fd4e5da5Sopenharmony_ci 704fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SatConvertSToUWrongInputType) { 705fd4e5da5Sopenharmony_ci const std::string body = R"( 706fd4e5da5Sopenharmony_ci%val = OpSatConvertSToU %u32 %f32_1 707fd4e5da5Sopenharmony_ci)"; 708fd4e5da5Sopenharmony_ci 709fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 710fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 711fd4e5da5Sopenharmony_ci EXPECT_THAT( 712fd4e5da5Sopenharmony_ci getDiagnosticString(), 713fd4e5da5Sopenharmony_ci HasSubstr("Expected int scalar or vector as input: SatConvertSToU")); 714fd4e5da5Sopenharmony_ci} 715fd4e5da5Sopenharmony_ci 716fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, SatConvertSToUDifferentDimension) { 717fd4e5da5Sopenharmony_ci const std::string body = R"( 718fd4e5da5Sopenharmony_ci%val = OpSatConvertSToU %u32 %u32vec2_12 719fd4e5da5Sopenharmony_ci)"; 720fd4e5da5Sopenharmony_ci 721fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 722fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 723fd4e5da5Sopenharmony_ci EXPECT_THAT( 724fd4e5da5Sopenharmony_ci getDiagnosticString(), 725fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have the same dimension as Result Type: " 726fd4e5da5Sopenharmony_ci "SatConvertSToU")); 727fd4e5da5Sopenharmony_ci} 728fd4e5da5Sopenharmony_ci 729fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrSuccess) { 730fd4e5da5Sopenharmony_ci const std::string body = R"( 731fd4e5da5Sopenharmony_ci%val1 = OpConvertUToPtr %f32ptr_func %u32_1 732fd4e5da5Sopenharmony_ci%val2 = OpConvertUToPtr %f32ptr_func %u64_1 733fd4e5da5Sopenharmony_ci)"; 734fd4e5da5Sopenharmony_ci 735fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 736fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 737fd4e5da5Sopenharmony_ci} 738fd4e5da5Sopenharmony_ci 739fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrWrongResultType) { 740fd4e5da5Sopenharmony_ci const std::string body = R"( 741fd4e5da5Sopenharmony_ci%val = OpConvertUToPtr %f32 %u32_1 742fd4e5da5Sopenharmony_ci)"; 743fd4e5da5Sopenharmony_ci 744fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 745fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 746fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 747fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be a pointer: ConvertUToPtr")); 748fd4e5da5Sopenharmony_ci} 749fd4e5da5Sopenharmony_ci 750fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrNotInt) { 751fd4e5da5Sopenharmony_ci const std::string body = R"( 752fd4e5da5Sopenharmony_ci%val = OpConvertUToPtr %f32ptr_func %f32_1 753fd4e5da5Sopenharmony_ci)"; 754fd4e5da5Sopenharmony_ci 755fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 756fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 757fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 758fd4e5da5Sopenharmony_ci HasSubstr("Expected int scalar as input: ConvertUToPtr")); 759fd4e5da5Sopenharmony_ci} 760fd4e5da5Sopenharmony_ci 761fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrNotIntScalar) { 762fd4e5da5Sopenharmony_ci const std::string body = R"( 763fd4e5da5Sopenharmony_ci%val = OpConvertUToPtr %f32ptr_func %u32vec2_12 764fd4e5da5Sopenharmony_ci)"; 765fd4e5da5Sopenharmony_ci 766fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 767fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 768fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 769fd4e5da5Sopenharmony_ci HasSubstr("Expected int scalar as input: ConvertUToPtr")); 770fd4e5da5Sopenharmony_ci} 771fd4e5da5Sopenharmony_ci 772fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericSuccess) { 773fd4e5da5Sopenharmony_ci const std::string body = R"( 774fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 775fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32ptr_gen %ptr_func 776fd4e5da5Sopenharmony_ci)"; 777fd4e5da5Sopenharmony_ci 778fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 779fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 780fd4e5da5Sopenharmony_ci} 781fd4e5da5Sopenharmony_ci 782fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericWrongResultType) { 783fd4e5da5Sopenharmony_ci const std::string body = R"( 784fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 785fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32 %ptr_func 786fd4e5da5Sopenharmony_ci)"; 787fd4e5da5Sopenharmony_ci 788fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 789fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 790fd4e5da5Sopenharmony_ci EXPECT_THAT( 791fd4e5da5Sopenharmony_ci getDiagnosticString(), 792fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be a pointer: PtrCastToGeneric")); 793fd4e5da5Sopenharmony_ci} 794fd4e5da5Sopenharmony_ci 795fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericWrongResultStorageClass) { 796fd4e5da5Sopenharmony_ci const std::string body = R"( 797fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 798fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32ptr_func %ptr_func 799fd4e5da5Sopenharmony_ci)"; 800fd4e5da5Sopenharmony_ci 801fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 802fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 803fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 804fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to have storage class Generic: " 805fd4e5da5Sopenharmony_ci "PtrCastToGeneric")); 806fd4e5da5Sopenharmony_ci} 807fd4e5da5Sopenharmony_ci 808fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericWrongInputType) { 809fd4e5da5Sopenharmony_ci const std::string body = R"( 810fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 811fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32ptr_gen %f32 812fd4e5da5Sopenharmony_ci)"; 813fd4e5da5Sopenharmony_ci 814fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 815fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); 816fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 817fd4e5da5Sopenharmony_ci HasSubstr("Operand '4[%float]' cannot be a " 818fd4e5da5Sopenharmony_ci "type")); 819fd4e5da5Sopenharmony_ci} 820fd4e5da5Sopenharmony_ci 821fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericWrongInputStorageClass) { 822fd4e5da5Sopenharmony_ci const std::string body = R"( 823fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32ptr_gen %f32inp 824fd4e5da5Sopenharmony_ci)"; 825fd4e5da5Sopenharmony_ci 826fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 827fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 828fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 829fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have storage class Workgroup, " 830fd4e5da5Sopenharmony_ci "CrossWorkgroup or Function: PtrCastToGeneric")); 831fd4e5da5Sopenharmony_ci} 832fd4e5da5Sopenharmony_ci 833fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, PtrCastToGenericPointToDifferentType) { 834fd4e5da5Sopenharmony_ci const std::string body = R"( 835fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %u32ptr_func Function 836fd4e5da5Sopenharmony_ci%val = OpPtrCastToGeneric %f32ptr_gen %ptr_func 837fd4e5da5Sopenharmony_ci)"; 838fd4e5da5Sopenharmony_ci 839fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 840fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 841fd4e5da5Sopenharmony_ci EXPECT_THAT( 842fd4e5da5Sopenharmony_ci getDiagnosticString(), 843fd4e5da5Sopenharmony_ci HasSubstr("Expected input and Result Type to point to the same type: " 844fd4e5da5Sopenharmony_ci "PtrCastToGeneric")); 845fd4e5da5Sopenharmony_ci} 846fd4e5da5Sopenharmony_ci 847fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrSuccess) { 848fd4e5da5Sopenharmony_ci const std::string body = R"( 849fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 850fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 851fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %f32ptr_func %ptr_gen 852fd4e5da5Sopenharmony_ci%ptr_wg = OpGenericCastToPtr %f32ptr_wg %ptr_gen 853fd4e5da5Sopenharmony_ci%ptr_cwg = OpGenericCastToPtr %f32ptr_cwg %ptr_gen 854fd4e5da5Sopenharmony_ci)"; 855fd4e5da5Sopenharmony_ci 856fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 857fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 858fd4e5da5Sopenharmony_ci} 859fd4e5da5Sopenharmony_ci 860fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrWrongResultType) { 861fd4e5da5Sopenharmony_ci const std::string body = R"( 862fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 863fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 864fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %f32 %ptr_gen 865fd4e5da5Sopenharmony_ci)"; 866fd4e5da5Sopenharmony_ci 867fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 868fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 869fd4e5da5Sopenharmony_ci EXPECT_THAT( 870fd4e5da5Sopenharmony_ci getDiagnosticString(), 871fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be a pointer: GenericCastToPtr")); 872fd4e5da5Sopenharmony_ci} 873fd4e5da5Sopenharmony_ci 874fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrWrongResultStorageClass) { 875fd4e5da5Sopenharmony_ci const std::string body = R"( 876fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 877fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 878fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %f32ptr_gen %ptr_gen 879fd4e5da5Sopenharmony_ci)"; 880fd4e5da5Sopenharmony_ci 881fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 882fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 883fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 884fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to have storage class Workgroup, " 885fd4e5da5Sopenharmony_ci "CrossWorkgroup or Function: GenericCastToPtr")); 886fd4e5da5Sopenharmony_ci} 887fd4e5da5Sopenharmony_ci 888fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrWrongInputType) { 889fd4e5da5Sopenharmony_ci const std::string body = R"( 890fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 891fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 892fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %f32ptr_func %f32_1 893fd4e5da5Sopenharmony_ci)"; 894fd4e5da5Sopenharmony_ci 895fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 896fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 897fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 898fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer: GenericCastToPtr")); 899fd4e5da5Sopenharmony_ci} 900fd4e5da5Sopenharmony_ci 901fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrWrongInputStorageClass) { 902fd4e5da5Sopenharmony_ci const std::string body = R"( 903fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 904fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %f32ptr_func %ptr_func 905fd4e5da5Sopenharmony_ci)"; 906fd4e5da5Sopenharmony_ci 907fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 908fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 909fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 910fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have storage class Generic: " 911fd4e5da5Sopenharmony_ci "GenericCastToPtr")); 912fd4e5da5Sopenharmony_ci} 913fd4e5da5Sopenharmony_ci 914fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrPointToDifferentType) { 915fd4e5da5Sopenharmony_ci const std::string body = R"( 916fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 917fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 918fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtr %u32ptr_func %ptr_gen 919fd4e5da5Sopenharmony_ci)"; 920fd4e5da5Sopenharmony_ci 921fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 922fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 923fd4e5da5Sopenharmony_ci EXPECT_THAT( 924fd4e5da5Sopenharmony_ci getDiagnosticString(), 925fd4e5da5Sopenharmony_ci HasSubstr("Expected input and Result Type to point to the same type: " 926fd4e5da5Sopenharmony_ci "GenericCastToPtr")); 927fd4e5da5Sopenharmony_ci} 928fd4e5da5Sopenharmony_ci 929fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitSuccess) { 930fd4e5da5Sopenharmony_ci const std::string body = R"( 931fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 932fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 933fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_gen Function 934fd4e5da5Sopenharmony_ci%ptr_wg = OpGenericCastToPtrExplicit %f32ptr_wg %ptr_gen Workgroup 935fd4e5da5Sopenharmony_ci%ptr_cwg = OpGenericCastToPtrExplicit %f32ptr_cwg %ptr_gen CrossWorkgroup 936fd4e5da5Sopenharmony_ci)"; 937fd4e5da5Sopenharmony_ci 938fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 939fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 940fd4e5da5Sopenharmony_ci} 941fd4e5da5Sopenharmony_ci 942fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitWrongResultType) { 943fd4e5da5Sopenharmony_ci const std::string body = R"( 944fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 945fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 946fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32 %ptr_gen Function 947fd4e5da5Sopenharmony_ci)"; 948fd4e5da5Sopenharmony_ci 949fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 950fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 951fd4e5da5Sopenharmony_ci EXPECT_THAT( 952fd4e5da5Sopenharmony_ci getDiagnosticString(), 953fd4e5da5Sopenharmony_ci HasSubstr( 954fd4e5da5Sopenharmony_ci "Expected Result Type to be a pointer: GenericCastToPtrExplicit")); 955fd4e5da5Sopenharmony_ci} 956fd4e5da5Sopenharmony_ci 957fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitResultStorageClassDiffers) { 958fd4e5da5Sopenharmony_ci const std::string body = R"( 959fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 960fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 961fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_gen Workgroup 962fd4e5da5Sopenharmony_ci)"; 963fd4e5da5Sopenharmony_ci 964fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 965fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 966fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 967fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be of target storage class: " 968fd4e5da5Sopenharmony_ci "GenericCastToPtrExplicit")); 969fd4e5da5Sopenharmony_ci} 970fd4e5da5Sopenharmony_ci 971fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitWrongResultStorageClass) { 972fd4e5da5Sopenharmony_ci const std::string body = R"( 973fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 974fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 975fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_gen %ptr_gen Generic 976fd4e5da5Sopenharmony_ci)"; 977fd4e5da5Sopenharmony_ci 978fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 979fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 980fd4e5da5Sopenharmony_ci EXPECT_THAT( 981fd4e5da5Sopenharmony_ci getDiagnosticString(), 982fd4e5da5Sopenharmony_ci HasSubstr("Expected target storage class to be Workgroup, " 983fd4e5da5Sopenharmony_ci "CrossWorkgroup or Function: GenericCastToPtrExplicit")); 984fd4e5da5Sopenharmony_ci} 985fd4e5da5Sopenharmony_ci 986fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitWrongInputType) { 987fd4e5da5Sopenharmony_ci const std::string body = R"( 988fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 989fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 990fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %f32_1 Function 991fd4e5da5Sopenharmony_ci)"; 992fd4e5da5Sopenharmony_ci 993fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 994fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 995fd4e5da5Sopenharmony_ci EXPECT_THAT( 996fd4e5da5Sopenharmony_ci getDiagnosticString(), 997fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer: GenericCastToPtrExplicit")); 998fd4e5da5Sopenharmony_ci} 999fd4e5da5Sopenharmony_ci 1000fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitWrongInputStorageClass) { 1001fd4e5da5Sopenharmony_ci const std::string body = R"( 1002fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 1003fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %f32ptr_func %ptr_func Function 1004fd4e5da5Sopenharmony_ci)"; 1005fd4e5da5Sopenharmony_ci 1006fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1007fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1008fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1009fd4e5da5Sopenharmony_ci HasSubstr("Expected input to have storage class Generic: " 1010fd4e5da5Sopenharmony_ci "GenericCastToPtrExplicit")); 1011fd4e5da5Sopenharmony_ci} 1012fd4e5da5Sopenharmony_ci 1013fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, GenericCastToPtrExplicitPointToDifferentType) { 1014fd4e5da5Sopenharmony_ci const std::string body = R"( 1015fd4e5da5Sopenharmony_ci%ptr_func = OpVariable %f32ptr_func Function 1016fd4e5da5Sopenharmony_ci%ptr_gen = OpPtrCastToGeneric %f32ptr_gen %ptr_func 1017fd4e5da5Sopenharmony_ci%ptr_func2 = OpGenericCastToPtrExplicit %u32ptr_func %ptr_gen Function 1018fd4e5da5Sopenharmony_ci)"; 1019fd4e5da5Sopenharmony_ci 1020fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1021fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1022fd4e5da5Sopenharmony_ci EXPECT_THAT( 1023fd4e5da5Sopenharmony_ci getDiagnosticString(), 1024fd4e5da5Sopenharmony_ci HasSubstr("Expected input and Result Type to point to the same type: " 1025fd4e5da5Sopenharmony_ci "GenericCastToPtrExplicit")); 1026fd4e5da5Sopenharmony_ci} 1027fd4e5da5Sopenharmony_ci 1028fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatConversionSuccess) { 1029fd4e5da5Sopenharmony_ci const std::string body = 1030fd4e5da5Sopenharmony_ci R"( 1031fd4e5da5Sopenharmony_ciOpCapability Shader 1032fd4e5da5Sopenharmony_ciOpCapability Float16 1033fd4e5da5Sopenharmony_ciOpCapability Int16 1034fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixNV 1035fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_cooperative_matrix" 1036fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1037fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1038fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1039fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1040fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1041fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1042fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1043fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1044fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1045fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1046fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1047fd4e5da5Sopenharmony_ci 1048fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1049fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1050fd4e5da5Sopenharmony_ci 1051fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 1052fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_8 %u32_8 1053fd4e5da5Sopenharmony_ci%u16mat = OpTypeCooperativeMatrixNV %u16 %subgroup %u32_8 %u32_8 1054fd4e5da5Sopenharmony_ci%u32mat = OpTypeCooperativeMatrixNV %u32 %subgroup %u32_8 %u32_8 1055fd4e5da5Sopenharmony_ci%s16mat = OpTypeCooperativeMatrixNV %s16 %subgroup %u32_8 %u32_8 1056fd4e5da5Sopenharmony_ci%s32mat = OpTypeCooperativeMatrixNV %s32 %subgroup %u32_8 %u32_8 1057fd4e5da5Sopenharmony_ci 1058fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1059fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1 1060fd4e5da5Sopenharmony_ci%u16_1 = OpConstant %u16 1 1061fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1 1062fd4e5da5Sopenharmony_ci%s16_1 = OpConstant %s16 1 1063fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1 1064fd4e5da5Sopenharmony_ci 1065fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1066fd4e5da5Sopenharmony_ci%f32mat_1 = OpConstantComposite %f32mat %f32_1 1067fd4e5da5Sopenharmony_ci%u16mat_1 = OpConstantComposite %u16mat %u16_1 1068fd4e5da5Sopenharmony_ci%u32mat_1 = OpConstantComposite %u32mat %u32_1 1069fd4e5da5Sopenharmony_ci%s16mat_1 = OpConstantComposite %s16mat %s16_1 1070fd4e5da5Sopenharmony_ci%s32mat_1 = OpConstantComposite %s32mat %s32_1 1071fd4e5da5Sopenharmony_ci 1072fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1073fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1074fd4e5da5Sopenharmony_ci 1075fd4e5da5Sopenharmony_ci%val11 = OpConvertFToU %u16mat %f16mat_1 1076fd4e5da5Sopenharmony_ci%val12 = OpConvertFToU %u32mat %f16mat_1 1077fd4e5da5Sopenharmony_ci%val13 = OpConvertFToS %s16mat %f16mat_1 1078fd4e5da5Sopenharmony_ci%val14 = OpConvertFToS %s32mat %f16mat_1 1079fd4e5da5Sopenharmony_ci%val15 = OpFConvert %f32mat %f16mat_1 1080fd4e5da5Sopenharmony_ci 1081fd4e5da5Sopenharmony_ci%val21 = OpConvertFToU %u16mat %f32mat_1 1082fd4e5da5Sopenharmony_ci%val22 = OpConvertFToU %u32mat %f32mat_1 1083fd4e5da5Sopenharmony_ci%val23 = OpConvertFToS %s16mat %f32mat_1 1084fd4e5da5Sopenharmony_ci%val24 = OpConvertFToS %s32mat %f32mat_1 1085fd4e5da5Sopenharmony_ci%val25 = OpFConvert %f16mat %f32mat_1 1086fd4e5da5Sopenharmony_ci 1087fd4e5da5Sopenharmony_ci%val31 = OpConvertUToF %f16mat %u16mat_1 1088fd4e5da5Sopenharmony_ci%val32 = OpConvertUToF %f32mat %u16mat_1 1089fd4e5da5Sopenharmony_ci%val33 = OpUConvert %u32mat %u16mat_1 1090fd4e5da5Sopenharmony_ci%val34 = OpSConvert %s32mat %u16mat_1 1091fd4e5da5Sopenharmony_ci 1092fd4e5da5Sopenharmony_ci%val41 = OpConvertSToF %f16mat %s16mat_1 1093fd4e5da5Sopenharmony_ci%val42 = OpConvertSToF %f32mat %s16mat_1 1094fd4e5da5Sopenharmony_ci%val43 = OpUConvert %u32mat %s16mat_1 1095fd4e5da5Sopenharmony_ci%val44 = OpSConvert %s32mat %s16mat_1 1096fd4e5da5Sopenharmony_ci 1097fd4e5da5Sopenharmony_ciOpReturn 1098fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1099fd4e5da5Sopenharmony_ci 1100fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1101fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1102fd4e5da5Sopenharmony_ci} 1103fd4e5da5Sopenharmony_ci 1104fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatConversionShapesMismatchFail) { 1105fd4e5da5Sopenharmony_ci const std::string body = 1106fd4e5da5Sopenharmony_ci R"( 1107fd4e5da5Sopenharmony_ciOpCapability Shader 1108fd4e5da5Sopenharmony_ciOpCapability Float16 1109fd4e5da5Sopenharmony_ciOpCapability Int16 1110fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixNV 1111fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_cooperative_matrix" 1112fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1113fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1114fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1115fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1116fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1117fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1118fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1119fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1120fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1121fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1122fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1123fd4e5da5Sopenharmony_ci 1124fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1125fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4 1126fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1127fd4e5da5Sopenharmony_ci 1128fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 1129fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_4 %u32_4 1130fd4e5da5Sopenharmony_ci 1131fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1132fd4e5da5Sopenharmony_ci 1133fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1134fd4e5da5Sopenharmony_ci 1135fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1136fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1137fd4e5da5Sopenharmony_ci 1138fd4e5da5Sopenharmony_ci%val15 = OpFConvert %f32mat %f16mat_1 1139fd4e5da5Sopenharmony_ci 1140fd4e5da5Sopenharmony_ciOpReturn 1141fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1142fd4e5da5Sopenharmony_ci 1143fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1144fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1145fd4e5da5Sopenharmony_ci EXPECT_THAT( 1146fd4e5da5Sopenharmony_ci getDiagnosticString(), 1147fd4e5da5Sopenharmony_ci HasSubstr( 1148fd4e5da5Sopenharmony_ci "Expected rows of Matrix type and Result Type to be identical")); 1149fd4e5da5Sopenharmony_ci} 1150fd4e5da5Sopenharmony_ci 1151fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatConversionShapesMismatchPass) { 1152fd4e5da5Sopenharmony_ci const std::string body = R"( 1153fd4e5da5Sopenharmony_ciOpCapability Shader 1154fd4e5da5Sopenharmony_ciOpCapability Float16 1155fd4e5da5Sopenharmony_ciOpCapability Int16 1156fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixNV 1157fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_cooperative_matrix" 1158fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1159fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1160fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1161fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1162fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1163fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1164fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1165fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1166fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1167fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1168fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1169fd4e5da5Sopenharmony_ci 1170fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1171fd4e5da5Sopenharmony_ci%u32_4 = OpSpecConstant %u32 4 1172fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1173fd4e5da5Sopenharmony_ci 1174fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixNV %f16 %subgroup %u32_8 %u32_8 1175fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixNV %f32 %subgroup %u32_4 %u32_4 1176fd4e5da5Sopenharmony_ci 1177fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1178fd4e5da5Sopenharmony_ci 1179fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1180fd4e5da5Sopenharmony_ci 1181fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1182fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1183fd4e5da5Sopenharmony_ci 1184fd4e5da5Sopenharmony_ci%val15 = OpFConvert %f32mat %f16mat_1 1185fd4e5da5Sopenharmony_ci 1186fd4e5da5Sopenharmony_ciOpReturn 1187fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1188fd4e5da5Sopenharmony_ci 1189fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1190fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1191fd4e5da5Sopenharmony_ci} 1192fd4e5da5Sopenharmony_ci 1193fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatKHRConversionSuccess) { 1194fd4e5da5Sopenharmony_ci const std::string body = R"( 1195fd4e5da5Sopenharmony_ciOpCapability Shader 1196fd4e5da5Sopenharmony_ciOpCapability Float16 1197fd4e5da5Sopenharmony_ciOpCapability Int16 1198fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixKHR 1199fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_cooperative_matrix" 1200fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model" 1201fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1202fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1203fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1204fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1205fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1206fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1207fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1208fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1209fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1210fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1211fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1212fd4e5da5Sopenharmony_ci 1213fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1214fd4e5da5Sopenharmony_ci%use_A = OpConstant %u32 0 1215fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1216fd4e5da5Sopenharmony_ci 1217fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A 1218fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_A 1219fd4e5da5Sopenharmony_ci%u16mat = OpTypeCooperativeMatrixKHR %u16 %subgroup %u32_8 %u32_8 %use_A 1220fd4e5da5Sopenharmony_ci%u32mat = OpTypeCooperativeMatrixKHR %u32 %subgroup %u32_8 %u32_8 %use_A 1221fd4e5da5Sopenharmony_ci%s16mat = OpTypeCooperativeMatrixKHR %s16 %subgroup %u32_8 %u32_8 %use_A 1222fd4e5da5Sopenharmony_ci%s32mat = OpTypeCooperativeMatrixKHR %s32 %subgroup %u32_8 %u32_8 %use_A 1223fd4e5da5Sopenharmony_ci 1224fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1225fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1 1226fd4e5da5Sopenharmony_ci%u16_1 = OpConstant %u16 1 1227fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1 1228fd4e5da5Sopenharmony_ci%s16_1 = OpConstant %s16 1 1229fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1 1230fd4e5da5Sopenharmony_ci 1231fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1232fd4e5da5Sopenharmony_ci%f32mat_1 = OpConstantComposite %f32mat %f32_1 1233fd4e5da5Sopenharmony_ci%u16mat_1 = OpConstantComposite %u16mat %u16_1 1234fd4e5da5Sopenharmony_ci%u32mat_1 = OpConstantComposite %u32mat %u32_1 1235fd4e5da5Sopenharmony_ci%s16mat_1 = OpConstantComposite %s16mat %s16_1 1236fd4e5da5Sopenharmony_ci%s32mat_1 = OpConstantComposite %s32mat %s32_1 1237fd4e5da5Sopenharmony_ci 1238fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1239fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1240fd4e5da5Sopenharmony_ci 1241fd4e5da5Sopenharmony_ci%val11 = OpConvertFToU %u16mat %f16mat_1 1242fd4e5da5Sopenharmony_ci%val12 = OpConvertFToU %u32mat %f16mat_1 1243fd4e5da5Sopenharmony_ci%val13 = OpConvertFToS %s16mat %f16mat_1 1244fd4e5da5Sopenharmony_ci%val14 = OpConvertFToS %s32mat %f16mat_1 1245fd4e5da5Sopenharmony_ci%val15 = OpFConvert %f32mat %f16mat_1 1246fd4e5da5Sopenharmony_ci 1247fd4e5da5Sopenharmony_ci%val21 = OpConvertFToU %u16mat %f32mat_1 1248fd4e5da5Sopenharmony_ci%val22 = OpConvertFToU %u32mat %f32mat_1 1249fd4e5da5Sopenharmony_ci%val23 = OpConvertFToS %s16mat %f32mat_1 1250fd4e5da5Sopenharmony_ci%val24 = OpConvertFToS %s32mat %f32mat_1 1251fd4e5da5Sopenharmony_ci%val25 = OpFConvert %f16mat %f32mat_1 1252fd4e5da5Sopenharmony_ci 1253fd4e5da5Sopenharmony_ci%val31 = OpConvertUToF %f16mat %u16mat_1 1254fd4e5da5Sopenharmony_ci%val32 = OpConvertUToF %f32mat %u16mat_1 1255fd4e5da5Sopenharmony_ci%val33 = OpUConvert %u32mat %u16mat_1 1256fd4e5da5Sopenharmony_ci%val34 = OpSConvert %s32mat %u16mat_1 1257fd4e5da5Sopenharmony_ci 1258fd4e5da5Sopenharmony_ci%val41 = OpConvertSToF %f16mat %s16mat_1 1259fd4e5da5Sopenharmony_ci%val42 = OpConvertSToF %f32mat %s16mat_1 1260fd4e5da5Sopenharmony_ci%val43 = OpUConvert %u32mat %s16mat_1 1261fd4e5da5Sopenharmony_ci%val44 = OpSConvert %s32mat %s16mat_1 1262fd4e5da5Sopenharmony_ci 1263fd4e5da5Sopenharmony_ciOpReturn 1264fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1265fd4e5da5Sopenharmony_ci 1266fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1267fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1268fd4e5da5Sopenharmony_ci} 1269fd4e5da5Sopenharmony_ci 1270fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatKHRConversionUseMismatchFail) { 1271fd4e5da5Sopenharmony_ci const std::string body = R"( 1272fd4e5da5Sopenharmony_ciOpCapability Shader 1273fd4e5da5Sopenharmony_ciOpCapability Float16 1274fd4e5da5Sopenharmony_ciOpCapability Int16 1275fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixKHR 1276fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_cooperative_matrix" 1277fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model" 1278fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1279fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1280fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1281fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1282fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1283fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1284fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1285fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1286fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1287fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1288fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1289fd4e5da5Sopenharmony_ci 1290fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1291fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4 1292fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1293fd4e5da5Sopenharmony_ci%use_A = OpConstant %u32 0 1294fd4e5da5Sopenharmony_ci%use_B = OpConstant %u32 1 1295fd4e5da5Sopenharmony_ci 1296fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A 1297fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixKHR %f32 %subgroup %u32_8 %u32_8 %use_B 1298fd4e5da5Sopenharmony_ci 1299fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1300fd4e5da5Sopenharmony_ci 1301fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1302fd4e5da5Sopenharmony_ci 1303fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1304fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1305fd4e5da5Sopenharmony_ci 1306fd4e5da5Sopenharmony_ci%val1 = OpFConvert %f32mat %f16mat_1 1307fd4e5da5Sopenharmony_ci 1308fd4e5da5Sopenharmony_ciOpReturn 1309fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1310fd4e5da5Sopenharmony_ci 1311fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1312fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1313fd4e5da5Sopenharmony_ci EXPECT_THAT( 1314fd4e5da5Sopenharmony_ci getDiagnosticString(), 1315fd4e5da5Sopenharmony_ci HasSubstr("Expected Use of Matrix type and Result Type to be identical")); 1316fd4e5da5Sopenharmony_ci} 1317fd4e5da5Sopenharmony_ci 1318fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, CoopMatKHRConversionScopeMismatchFail) { 1319fd4e5da5Sopenharmony_ci const std::string body = R"( 1320fd4e5da5Sopenharmony_ciOpCapability Shader 1321fd4e5da5Sopenharmony_ciOpCapability Float16 1322fd4e5da5Sopenharmony_ciOpCapability Int16 1323fd4e5da5Sopenharmony_ciOpCapability CooperativeMatrixKHR 1324fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_cooperative_matrix" 1325fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model" 1326fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1327fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" 1328fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1329fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void 1330fd4e5da5Sopenharmony_ci%bool = OpTypeBool 1331fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16 1332fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32 1333fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0 1334fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0 1335fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1 1336fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1 1337fd4e5da5Sopenharmony_ci 1338fd4e5da5Sopenharmony_ci%u32_8 = OpConstant %u32 8 1339fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4 1340fd4e5da5Sopenharmony_ci%subgroup = OpConstant %u32 3 1341fd4e5da5Sopenharmony_ci%workgroup = OpConstant %u32 2 1342fd4e5da5Sopenharmony_ci%use_A = OpConstant %u32 0 1343fd4e5da5Sopenharmony_ci 1344fd4e5da5Sopenharmony_ci%f16mat = OpTypeCooperativeMatrixKHR %f16 %subgroup %u32_8 %u32_8 %use_A 1345fd4e5da5Sopenharmony_ci%f32mat = OpTypeCooperativeMatrixKHR %f32 %workgroup %u32_8 %u32_8 %use_A 1346fd4e5da5Sopenharmony_ci 1347fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1 1348fd4e5da5Sopenharmony_ci 1349fd4e5da5Sopenharmony_ci%f16mat_1 = OpConstantComposite %f16mat %f16_1 1350fd4e5da5Sopenharmony_ci 1351fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func 1352fd4e5da5Sopenharmony_ci%main_entry = OpLabel 1353fd4e5da5Sopenharmony_ci 1354fd4e5da5Sopenharmony_ci%val1 = OpFConvert %f32mat %f16mat_1 1355fd4e5da5Sopenharmony_ci 1356fd4e5da5Sopenharmony_ciOpReturn 1357fd4e5da5Sopenharmony_ciOpFunctionEnd)"; 1358fd4e5da5Sopenharmony_ci 1359fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1360fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1361fd4e5da5Sopenharmony_ci EXPECT_THAT( 1362fd4e5da5Sopenharmony_ci getDiagnosticString(), 1363fd4e5da5Sopenharmony_ci HasSubstr("Expected scopes of Matrix and Result Type to be identical")); 1364fd4e5da5Sopenharmony_ci} 1365fd4e5da5Sopenharmony_ci 1366fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastSuccess) { 1367fd4e5da5Sopenharmony_ci const std::string body = R"( 1368fd4e5da5Sopenharmony_ci%ptr = OpVariable %f32ptr_func Function 1369fd4e5da5Sopenharmony_ci%val1 = OpBitcast %u32 %ptr 1370fd4e5da5Sopenharmony_ci%val2 = OpBitcast %u64 %ptr 1371fd4e5da5Sopenharmony_ci%val3 = OpBitcast %f32ptr_func %u32_1 1372fd4e5da5Sopenharmony_ci%val4 = OpBitcast %f32ptr_wg %u64_1 1373fd4e5da5Sopenharmony_ci%val5 = OpBitcast %f32 %u32_1 1374fd4e5da5Sopenharmony_ci%val6 = OpBitcast %f32vec2 %u32vec2_12 1375fd4e5da5Sopenharmony_ci%val7 = OpBitcast %f32vec2 %u64_1 1376fd4e5da5Sopenharmony_ci%val8 = OpBitcast %f64 %u32vec2_12 1377fd4e5da5Sopenharmony_ci%val9 = OpBitcast %f32vec4 %f64vec2_12 1378fd4e5da5Sopenharmony_ci)"; 1379fd4e5da5Sopenharmony_ci 1380fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1381fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1382fd4e5da5Sopenharmony_ci} 1383fd4e5da5Sopenharmony_ci 1384fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastSuccessSPV1p5) { 1385fd4e5da5Sopenharmony_ci const std::string body = R"( 1386fd4e5da5Sopenharmony_ci%ptr = OpVariable %f32ptr_func Function 1387fd4e5da5Sopenharmony_ci%val1 = OpBitcast %u32 %ptr 1388fd4e5da5Sopenharmony_ci%val2 = OpBitcast %u64 %ptr 1389fd4e5da5Sopenharmony_ci%val3 = OpBitcast %f32ptr_func %u32_1 1390fd4e5da5Sopenharmony_ci%val4 = OpBitcast %f32ptr_wg %u64_1 1391fd4e5da5Sopenharmony_ci%val5 = OpBitcast %f32 %u32_1 1392fd4e5da5Sopenharmony_ci%val6 = OpBitcast %f32vec2 %u32vec2_12 1393fd4e5da5Sopenharmony_ci%val7 = OpBitcast %f32vec2 %u64_1 1394fd4e5da5Sopenharmony_ci%val8 = OpBitcast %f64 %u32vec2_12 1395fd4e5da5Sopenharmony_ci%val9 = OpBitcast %f32vec4 %f64vec2_12 1396fd4e5da5Sopenharmony_ci%val10 = OpBitcast %u32ptr_func %u32vec2_01 1397fd4e5da5Sopenharmony_ci%val11 = OpBitcast %u32vec2 %ptr 1398fd4e5da5Sopenharmony_ci)"; 1399fd4e5da5Sopenharmony_ci 1400fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); 1401fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); 1402fd4e5da5Sopenharmony_ci} 1403fd4e5da5Sopenharmony_ci 1404fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastSuccessPhysicalStorageBufferKHR) { 1405fd4e5da5Sopenharmony_ci const std::string body = R"( 1406fd4e5da5Sopenharmony_ci%ptr = OpVariable %f32ptr_func Function 1407fd4e5da5Sopenharmony_ci%val1 = OpBitcast %u32 %ptr 1408fd4e5da5Sopenharmony_ci%val2 = OpBitcast %u64 %ptr 1409fd4e5da5Sopenharmony_ci%val3 = OpBitcast %f32ptr_func %u32_1 1410fd4e5da5Sopenharmony_ci%val4 = OpBitcast %f32ptr_wg %u64_1 1411fd4e5da5Sopenharmony_ci%val5 = OpBitcast %f32 %u32_1 1412fd4e5da5Sopenharmony_ci%val6 = OpBitcast %f32vec2 %u32vec2_12 1413fd4e5da5Sopenharmony_ci%val7 = OpBitcast %f32vec2 %u64_1 1414fd4e5da5Sopenharmony_ci%val8 = OpBitcast %f64 %u32vec2_12 1415fd4e5da5Sopenharmony_ci%val9 = OpBitcast %f32vec4 %f64vec2_12 1416fd4e5da5Sopenharmony_ci%val10 = OpBitcast %u32ptr_func %u32vec2_01 1417fd4e5da5Sopenharmony_ci%val11 = OpBitcast %u32vec2 %ptr 1418fd4e5da5Sopenharmony_ci)"; 1419fd4e5da5Sopenharmony_ci 1420fd4e5da5Sopenharmony_ci CompileSuccessfully( 1421fd4e5da5Sopenharmony_ci GenerateKernelCode(body, 1422fd4e5da5Sopenharmony_ci "\nOpExtension \"SPV_KHR_physical_storage_buffer\"") 1423fd4e5da5Sopenharmony_ci .c_str()); 1424fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1425fd4e5da5Sopenharmony_ci} 1426fd4e5da5Sopenharmony_ci 1427fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastInputHasNoType) { 1428fd4e5da5Sopenharmony_ci const std::string body = R"( 1429fd4e5da5Sopenharmony_ci%val = OpBitcast %u32 %f32 1430fd4e5da5Sopenharmony_ci)"; 1431fd4e5da5Sopenharmony_ci 1432fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1433fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); 1434fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1435fd4e5da5Sopenharmony_ci HasSubstr("Operand '4[%float]' cannot be a " 1436fd4e5da5Sopenharmony_ci "type")); 1437fd4e5da5Sopenharmony_ci} 1438fd4e5da5Sopenharmony_ci 1439fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastWrongResultType) { 1440fd4e5da5Sopenharmony_ci const std::string body = R"( 1441fd4e5da5Sopenharmony_ci%val = OpBitcast %bool %f32_1 1442fd4e5da5Sopenharmony_ci)"; 1443fd4e5da5Sopenharmony_ci 1444fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1445fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1446fd4e5da5Sopenharmony_ci EXPECT_THAT( 1447fd4e5da5Sopenharmony_ci getDiagnosticString(), 1448fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be a pointer or int or float vector " 1449fd4e5da5Sopenharmony_ci "or scalar type: Bitcast")); 1450fd4e5da5Sopenharmony_ci} 1451fd4e5da5Sopenharmony_ci 1452fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastWrongInputType) { 1453fd4e5da5Sopenharmony_ci const std::string body = R"( 1454fd4e5da5Sopenharmony_ci%val = OpBitcast %u32 %true 1455fd4e5da5Sopenharmony_ci)"; 1456fd4e5da5Sopenharmony_ci 1457fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1458fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1459fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1460fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer or int or float vector " 1461fd4e5da5Sopenharmony_ci "or scalar: Bitcast")); 1462fd4e5da5Sopenharmony_ci} 1463fd4e5da5Sopenharmony_ci 1464fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongInputType) { 1465fd4e5da5Sopenharmony_ci const std::string body = R"( 1466fd4e5da5Sopenharmony_ci%val = OpBitcast %u32ptr_func %f32_1 1467fd4e5da5Sopenharmony_ci)"; 1468fd4e5da5Sopenharmony_ci 1469fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1470fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1471fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1472fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer or int scalar if " 1473fd4e5da5Sopenharmony_ci "Result Type is pointer: Bitcast")); 1474fd4e5da5Sopenharmony_ci} 1475fd4e5da5Sopenharmony_ci 1476fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongInputTypeSPV1p5) { 1477fd4e5da5Sopenharmony_ci const std::string body = R"( 1478fd4e5da5Sopenharmony_ci%val = OpBitcast %u32ptr_func %f32_1 1479fd4e5da5Sopenharmony_ci)"; 1480fd4e5da5Sopenharmony_ci 1481fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); 1482fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, 1483fd4e5da5Sopenharmony_ci ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); 1484fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1485fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer, int scalar or 32-bit " 1486fd4e5da5Sopenharmony_ci "int vector if Result Type is pointer: Bitcast")); 1487fd4e5da5Sopenharmony_ci} 1488fd4e5da5Sopenharmony_ci 1489fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongInputTypePhysicalStorageBufferKHR) { 1490fd4e5da5Sopenharmony_ci const std::string body = R"( 1491fd4e5da5Sopenharmony_ci%val = OpBitcast %u32ptr_func %f32_1 1492fd4e5da5Sopenharmony_ci)"; 1493fd4e5da5Sopenharmony_ci 1494fd4e5da5Sopenharmony_ci CompileSuccessfully( 1495fd4e5da5Sopenharmony_ci GenerateKernelCode(body, 1496fd4e5da5Sopenharmony_ci "\nOpExtension \"SPV_KHR_physical_storage_buffer\"") 1497fd4e5da5Sopenharmony_ci .c_str()); 1498fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1499fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1500fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer, int scalar or 32-bit " 1501fd4e5da5Sopenharmony_ci "int vector if Result Type is pointer: Bitcast")); 1502fd4e5da5Sopenharmony_ci} 1503fd4e5da5Sopenharmony_ci 1504fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongInputTypeIntVectorSPV1p5) { 1505fd4e5da5Sopenharmony_ci const std::string body = R"( 1506fd4e5da5Sopenharmony_ci%val = OpBitcast %u32ptr_func %u64vec2_01 1507fd4e5da5Sopenharmony_ci)"; 1508fd4e5da5Sopenharmony_ci 1509fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); 1510fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, 1511fd4e5da5Sopenharmony_ci ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); 1512fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1513fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer, int scalar or 32-bit " 1514fd4e5da5Sopenharmony_ci "int vector if Result Type is pointer: Bitcast")); 1515fd4e5da5Sopenharmony_ci} 1516fd4e5da5Sopenharmony_ci 1517fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, 1518fd4e5da5Sopenharmony_ci BitcastPtrWrongInputTypeIntVectorPhysicalStorageBufferKHR) { 1519fd4e5da5Sopenharmony_ci const std::string body = R"( 1520fd4e5da5Sopenharmony_ci%val = OpBitcast %u32ptr_func %u64vec2_01 1521fd4e5da5Sopenharmony_ci)"; 1522fd4e5da5Sopenharmony_ci 1523fd4e5da5Sopenharmony_ci CompileSuccessfully( 1524fd4e5da5Sopenharmony_ci GenerateKernelCode(body, 1525fd4e5da5Sopenharmony_ci "\nOpExtension \"SPV_KHR_physical_storage_buffer\"") 1526fd4e5da5Sopenharmony_ci .c_str()); 1527fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1528fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1529fd4e5da5Sopenharmony_ci HasSubstr("Expected input to be a pointer, int scalar or 32-bit " 1530fd4e5da5Sopenharmony_ci "int vector if Result Type is pointer: Bitcast")); 1531fd4e5da5Sopenharmony_ci} 1532fd4e5da5Sopenharmony_ci 1533fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongResultType) { 1534fd4e5da5Sopenharmony_ci const std::string body = R"( 1535fd4e5da5Sopenharmony_ci%val = OpBitcast %f32 %f32inp 1536fd4e5da5Sopenharmony_ci)"; 1537fd4e5da5Sopenharmony_ci 1538fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1539fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1540fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1541fd4e5da5Sopenharmony_ci HasSubstr("Pointer can only be converted to another pointer or " 1542fd4e5da5Sopenharmony_ci "int scalar: Bitcast")); 1543fd4e5da5Sopenharmony_ci} 1544fd4e5da5Sopenharmony_ci 1545fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongResultTypeSPV1p5) { 1546fd4e5da5Sopenharmony_ci const std::string body = R"( 1547fd4e5da5Sopenharmony_ci%val = OpBitcast %f32 %f32inp 1548fd4e5da5Sopenharmony_ci)"; 1549fd4e5da5Sopenharmony_ci 1550fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); 1551fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, 1552fd4e5da5Sopenharmony_ci ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); 1553fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1554fd4e5da5Sopenharmony_ci HasSubstr("Pointer can only be converted to another pointer, int " 1555fd4e5da5Sopenharmony_ci "scalar or 32-bit int vector: Bitcast")); 1556fd4e5da5Sopenharmony_ci} 1557fd4e5da5Sopenharmony_ci 1558fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongResultTypePhysicalStorageBufferKHR) { 1559fd4e5da5Sopenharmony_ci const std::string body = R"( 1560fd4e5da5Sopenharmony_ci%val = OpBitcast %f32 %f32inp 1561fd4e5da5Sopenharmony_ci)"; 1562fd4e5da5Sopenharmony_ci 1563fd4e5da5Sopenharmony_ci CompileSuccessfully( 1564fd4e5da5Sopenharmony_ci GenerateKernelCode(body, 1565fd4e5da5Sopenharmony_ci "\nOpExtension \"SPV_KHR_physical_storage_buffer\"") 1566fd4e5da5Sopenharmony_ci .c_str()); 1567fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1568fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1569fd4e5da5Sopenharmony_ci HasSubstr("Pointer can only be converted to another pointer, int " 1570fd4e5da5Sopenharmony_ci "scalar or 32-bit int vector: Bitcast")); 1571fd4e5da5Sopenharmony_ci} 1572fd4e5da5Sopenharmony_ci 1573fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastPtrWrongResultTypeIntVectorSPV1p5) { 1574fd4e5da5Sopenharmony_ci const std::string body = R"( 1575fd4e5da5Sopenharmony_ci%val = OpBitcast %u64vec2 %f32inp 1576fd4e5da5Sopenharmony_ci)"; 1577fd4e5da5Sopenharmony_ci 1578fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str(), SPV_ENV_UNIVERSAL_1_5); 1579fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, 1580fd4e5da5Sopenharmony_ci ValidateInstructions(SPV_ENV_UNIVERSAL_1_5)); 1581fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1582fd4e5da5Sopenharmony_ci HasSubstr("Pointer can only be converted to another pointer, int " 1583fd4e5da5Sopenharmony_ci "scalar or 32-bit int vector: Bitcast")); 1584fd4e5da5Sopenharmony_ci} 1585fd4e5da5Sopenharmony_ci 1586fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, 1587fd4e5da5Sopenharmony_ci BitcastPtrWrongResultTypeIntVectorPhysicalStorageBufferKHR) { 1588fd4e5da5Sopenharmony_ci const std::string body = R"( 1589fd4e5da5Sopenharmony_ci%val = OpBitcast %u64vec2 %f32inp 1590fd4e5da5Sopenharmony_ci)"; 1591fd4e5da5Sopenharmony_ci 1592fd4e5da5Sopenharmony_ci CompileSuccessfully( 1593fd4e5da5Sopenharmony_ci GenerateKernelCode(body, 1594fd4e5da5Sopenharmony_ci "\nOpExtension \"SPV_KHR_physical_storage_buffer\"") 1595fd4e5da5Sopenharmony_ci .c_str()); 1596fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1597fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1598fd4e5da5Sopenharmony_ci HasSubstr("Pointer can only be converted to another pointer, int " 1599fd4e5da5Sopenharmony_ci "scalar or 32-bit int vector: Bitcast")); 1600fd4e5da5Sopenharmony_ci} 1601fd4e5da5Sopenharmony_ci 1602fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, BitcastDifferentTotalBitWidth) { 1603fd4e5da5Sopenharmony_ci const std::string body = R"( 1604fd4e5da5Sopenharmony_ci%val = OpBitcast %f32 %u64_1 1605fd4e5da5Sopenharmony_ci)"; 1606fd4e5da5Sopenharmony_ci 1607fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateKernelCode(body).c_str()); 1608fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1609fd4e5da5Sopenharmony_ci EXPECT_THAT( 1610fd4e5da5Sopenharmony_ci getDiagnosticString(), 1611fd4e5da5Sopenharmony_ci HasSubstr( 1612fd4e5da5Sopenharmony_ci "Expected input to have the same total bit width as Result Type: " 1613fd4e5da5Sopenharmony_ci "Bitcast")); 1614fd4e5da5Sopenharmony_ci} 1615fd4e5da5Sopenharmony_ci 1616fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrInputIsAType) { 1617fd4e5da5Sopenharmony_ci const std::string spirv = R"( 1618fd4e5da5Sopenharmony_ciOpCapability Addresses 1619fd4e5da5Sopenharmony_ciOpCapability Shader 1620fd4e5da5Sopenharmony_ciOpCapability Linkage 1621fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450 1622fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1623fd4e5da5Sopenharmony_ci%ptr_int = OpTypePointer Function %int 1624fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1625fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1626fd4e5da5Sopenharmony_ci%func = OpFunction %void None %voidfn 1627fd4e5da5Sopenharmony_ci%entry = OpLabel 1628fd4e5da5Sopenharmony_ci%1 = OpConvertUToPtr %ptr_int %int 1629fd4e5da5Sopenharmony_ciOpReturn 1630fd4e5da5Sopenharmony_ciOpFunctionEnd 1631fd4e5da5Sopenharmony_ci)"; 1632fd4e5da5Sopenharmony_ci 1633fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 1634fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); 1635fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand '1[%uint]' cannot be a " 1636fd4e5da5Sopenharmony_ci "type")); 1637fd4e5da5Sopenharmony_ci} 1638fd4e5da5Sopenharmony_ci 1639fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrPSBSuccess) { 1640fd4e5da5Sopenharmony_ci const std::string body = R"( 1641fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1642fd4e5da5Sopenharmony_ciOpCapability Int64 1643fd4e5da5Sopenharmony_ciOpCapability Shader 1644fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1645fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1646fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1647fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1648fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1649fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %uint64 1 1650fd4e5da5Sopenharmony_ci%ptr = OpTypePointer PhysicalStorageBuffer %uint64 1651fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1652fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1653fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1654fd4e5da5Sopenharmony_ci%entry = OpLabel 1655fd4e5da5Sopenharmony_ci%val1 = OpConvertUToPtr %ptr %u64_1 1656fd4e5da5Sopenharmony_ciOpReturn 1657fd4e5da5Sopenharmony_ciOpFunctionEnd 1658fd4e5da5Sopenharmony_ci)"; 1659fd4e5da5Sopenharmony_ci 1660fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1661fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1662fd4e5da5Sopenharmony_ci} 1663fd4e5da5Sopenharmony_ci 1664fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrPSBStorageClass) { 1665fd4e5da5Sopenharmony_ci const std::string body = R"( 1666fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1667fd4e5da5Sopenharmony_ciOpCapability Int64 1668fd4e5da5Sopenharmony_ciOpCapability Shader 1669fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1670fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1671fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1672fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1673fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1674fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %uint64 1 1675fd4e5da5Sopenharmony_ci%ptr = OpTypePointer Function %uint64 1676fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1677fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1678fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1679fd4e5da5Sopenharmony_ci%entry = OpLabel 1680fd4e5da5Sopenharmony_ci%val1 = OpConvertUToPtr %ptr %u64_1 1681fd4e5da5Sopenharmony_ci%val2 = OpConvertPtrToU %uint64 %val1 1682fd4e5da5Sopenharmony_ciOpReturn 1683fd4e5da5Sopenharmony_ciOpFunctionEnd 1684fd4e5da5Sopenharmony_ci)"; 1685fd4e5da5Sopenharmony_ci 1686fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1687fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1688fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1689fd4e5da5Sopenharmony_ci HasSubstr("Pointer storage class must be " 1690fd4e5da5Sopenharmony_ci "PhysicalStorageBuffer: ConvertUToPtr")); 1691fd4e5da5Sopenharmony_ci} 1692fd4e5da5Sopenharmony_ci 1693fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToPtrVulkanWrongWidth) { 1694fd4e5da5Sopenharmony_ci const std::string body = R"( 1695fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1696fd4e5da5Sopenharmony_ciOpCapability Int64 1697fd4e5da5Sopenharmony_ciOpCapability Shader 1698fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1699fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1700fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1701fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1702fd4e5da5Sopenharmony_ci%uint32 = OpTypeInt 32 0 1703fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1704fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %uint32 1 1705fd4e5da5Sopenharmony_ci%ptr = OpTypePointer PhysicalStorageBuffer %uint64 1706fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1707fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1708fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1709fd4e5da5Sopenharmony_ci%entry = OpLabel 1710fd4e5da5Sopenharmony_ci%val1 = OpConvertUToPtr %ptr %u32_1 1711fd4e5da5Sopenharmony_ciOpReturn 1712fd4e5da5Sopenharmony_ciOpFunctionEnd 1713fd4e5da5Sopenharmony_ci)"; 1714fd4e5da5Sopenharmony_ci 1715fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1716fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0)); 1717fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1718fd4e5da5Sopenharmony_ci AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710")); 1719fd4e5da5Sopenharmony_ci EXPECT_THAT( 1720fd4e5da5Sopenharmony_ci getDiagnosticString(), 1721fd4e5da5Sopenharmony_ci HasSubstr("PhysicalStorageBuffer64 addressing mode requires the input " 1722fd4e5da5Sopenharmony_ci "integer to have a 64-bit width for Vulkan environment.")); 1723fd4e5da5Sopenharmony_ci} 1724fd4e5da5Sopenharmony_ci 1725fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUPSBSuccess) { 1726fd4e5da5Sopenharmony_ci const std::string body = R"( 1727fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1728fd4e5da5Sopenharmony_ciOpCapability Int64 1729fd4e5da5Sopenharmony_ciOpCapability Shader 1730fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1731fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1732fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1733fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1734fd4e5da5Sopenharmony_ciOpDecorate %val1 RestrictPointer 1735fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1736fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %uint64 1 1737fd4e5da5Sopenharmony_ci%ptr = OpTypePointer PhysicalStorageBuffer %uint64 1738fd4e5da5Sopenharmony_ci%pptr_f = OpTypePointer Function %ptr 1739fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1740fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1741fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1742fd4e5da5Sopenharmony_ci%entry = OpLabel 1743fd4e5da5Sopenharmony_ci%val1 = OpVariable %pptr_f Function 1744fd4e5da5Sopenharmony_ci%val2 = OpLoad %ptr %val1 1745fd4e5da5Sopenharmony_ci%val3 = OpConvertPtrToU %uint64 %val2 1746fd4e5da5Sopenharmony_ciOpReturn 1747fd4e5da5Sopenharmony_ciOpFunctionEnd 1748fd4e5da5Sopenharmony_ci)"; 1749fd4e5da5Sopenharmony_ci 1750fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1751fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1752fd4e5da5Sopenharmony_ci} 1753fd4e5da5Sopenharmony_ci 1754fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUPSBStorageClass) { 1755fd4e5da5Sopenharmony_ci const std::string body = R"( 1756fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1757fd4e5da5Sopenharmony_ciOpCapability Int64 1758fd4e5da5Sopenharmony_ciOpCapability Shader 1759fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1760fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1761fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1762fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1763fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1764fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %uint64 1 1765fd4e5da5Sopenharmony_ci%ptr = OpTypePointer Function %uint64 1766fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1767fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1768fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1769fd4e5da5Sopenharmony_ci%entry = OpLabel 1770fd4e5da5Sopenharmony_ci%val1 = OpVariable %ptr Function 1771fd4e5da5Sopenharmony_ci%val2 = OpConvertPtrToU %uint64 %val1 1772fd4e5da5Sopenharmony_ciOpReturn 1773fd4e5da5Sopenharmony_ciOpFunctionEnd 1774fd4e5da5Sopenharmony_ci)"; 1775fd4e5da5Sopenharmony_ci 1776fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1777fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1778fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1779fd4e5da5Sopenharmony_ci HasSubstr("Pointer storage class must be " 1780fd4e5da5Sopenharmony_ci "PhysicalStorageBuffer: ConvertPtrToU")); 1781fd4e5da5Sopenharmony_ci} 1782fd4e5da5Sopenharmony_ci 1783fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertPtrToUVulkanWrongWidth) { 1784fd4e5da5Sopenharmony_ci const std::string body = R"( 1785fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses 1786fd4e5da5Sopenharmony_ciOpCapability Int64 1787fd4e5da5Sopenharmony_ciOpCapability Shader 1788fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer" 1789fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450 1790fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" 1791fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft 1792fd4e5da5Sopenharmony_ciOpDecorate %val1 RestrictPointer 1793fd4e5da5Sopenharmony_ci%uint32 = OpTypeInt 32 0 1794fd4e5da5Sopenharmony_ci%uint64 = OpTypeInt 64 0 1795fd4e5da5Sopenharmony_ci%ptr = OpTypePointer PhysicalStorageBuffer %uint64 1796fd4e5da5Sopenharmony_ci%pptr_f = OpTypePointer Function %ptr 1797fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1798fd4e5da5Sopenharmony_ci%voidfn = OpTypeFunction %void 1799fd4e5da5Sopenharmony_ci%main = OpFunction %void None %voidfn 1800fd4e5da5Sopenharmony_ci%entry = OpLabel 1801fd4e5da5Sopenharmony_ci%val1 = OpVariable %pptr_f Function 1802fd4e5da5Sopenharmony_ci%val2 = OpLoad %ptr %val1 1803fd4e5da5Sopenharmony_ci%val3 = OpConvertPtrToU %uint32 %val2 1804fd4e5da5Sopenharmony_ciOpReturn 1805fd4e5da5Sopenharmony_ciOpFunctionEnd 1806fd4e5da5Sopenharmony_ci)"; 1807fd4e5da5Sopenharmony_ci 1808fd4e5da5Sopenharmony_ci CompileSuccessfully(body.c_str()); 1809fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0)); 1810fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1811fd4e5da5Sopenharmony_ci AnyVUID("VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710")); 1812fd4e5da5Sopenharmony_ci EXPECT_THAT( 1813fd4e5da5Sopenharmony_ci getDiagnosticString(), 1814fd4e5da5Sopenharmony_ci HasSubstr("PhysicalStorageBuffer64 addressing mode requires the result " 1815fd4e5da5Sopenharmony_ci "integer type to have a 64-bit width for Vulkan environment.")); 1816fd4e5da5Sopenharmony_ci} 1817fd4e5da5Sopenharmony_ci 1818fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureU32Vec2) { 1819fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1820fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1821fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1822fd4e5da5Sopenharmony_ci)"; 1823fd4e5da5Sopenharmony_ci const std::string types = R"( 1824fd4e5da5Sopenharmony_ci%u32vec2ptr_func = OpTypePointer Function %u32vec2 1825fd4e5da5Sopenharmony_ci%typeAS = OpTypeAccelerationStructureKHR 1826fd4e5da5Sopenharmony_ci)"; 1827fd4e5da5Sopenharmony_ci const std::string body = R"( 1828fd4e5da5Sopenharmony_ci%asHandle = OpVariable %u32vec2ptr_func Function 1829fd4e5da5Sopenharmony_ci%load = OpLoad %u32vec2 %asHandle 1830fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeAS %load 1831fd4e5da5Sopenharmony_ci)"; 1832fd4e5da5Sopenharmony_ci 1833fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1834fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1835fd4e5da5Sopenharmony_ci} 1836fd4e5da5Sopenharmony_ci 1837fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureSuccessU64) { 1838fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1839fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1840fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1841fd4e5da5Sopenharmony_ci)"; 1842fd4e5da5Sopenharmony_ci const std::string types = R"( 1843fd4e5da5Sopenharmony_ci%u64_func = OpTypePointer Function %u64 1844fd4e5da5Sopenharmony_ci%typeAS = OpTypeAccelerationStructureKHR 1845fd4e5da5Sopenharmony_ci)"; 1846fd4e5da5Sopenharmony_ci const std::string body = R"( 1847fd4e5da5Sopenharmony_ci%asHandle = OpVariable %u64_func Function 1848fd4e5da5Sopenharmony_ci%load = OpLoad %u64 %asHandle 1849fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeAS %load 1850fd4e5da5Sopenharmony_ci)"; 1851fd4e5da5Sopenharmony_ci 1852fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1853fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()); 1854fd4e5da5Sopenharmony_ci} 1855fd4e5da5Sopenharmony_ci 1856fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureResult) { 1857fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1858fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1859fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1860fd4e5da5Sopenharmony_ci)"; 1861fd4e5da5Sopenharmony_ci const std::string types = R"( 1862fd4e5da5Sopenharmony_ci%u32vec2ptr_func = OpTypePointer Function %u32vec2 1863fd4e5da5Sopenharmony_ci%typeRQ = OpTypeRayQueryKHR 1864fd4e5da5Sopenharmony_ci)"; 1865fd4e5da5Sopenharmony_ci const std::string body = R"( 1866fd4e5da5Sopenharmony_ci%asHandle = OpVariable %u32vec2ptr_func Function 1867fd4e5da5Sopenharmony_ci%load = OpLoad %u32vec2 %asHandle 1868fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeRQ %load 1869fd4e5da5Sopenharmony_ci)"; 1870fd4e5da5Sopenharmony_ci 1871fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1872fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1873fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1874fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to be a Acceleration Structure")); 1875fd4e5da5Sopenharmony_ci} 1876fd4e5da5Sopenharmony_ci 1877fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureU32) { 1878fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1879fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1880fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1881fd4e5da5Sopenharmony_ci)"; 1882fd4e5da5Sopenharmony_ci const std::string types = R"( 1883fd4e5da5Sopenharmony_ci%u32ptr_func = OpTypePointer Function %u32 1884fd4e5da5Sopenharmony_ci%typeAS = OpTypeAccelerationStructureKHR 1885fd4e5da5Sopenharmony_ci)"; 1886fd4e5da5Sopenharmony_ci const std::string body = R"( 1887fd4e5da5Sopenharmony_ci%asHandle = OpVariable %u32ptr_func Function 1888fd4e5da5Sopenharmony_ci%load = OpLoad %u32 %asHandle 1889fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeAS %load 1890fd4e5da5Sopenharmony_ci)"; 1891fd4e5da5Sopenharmony_ci 1892fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1893fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1894fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1895fd4e5da5Sopenharmony_ci HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " 1896fd4e5da5Sopenharmony_ci "uint vector as input")); 1897fd4e5da5Sopenharmony_ci} 1898fd4e5da5Sopenharmony_ci 1899fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureS64) { 1900fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1901fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1902fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1903fd4e5da5Sopenharmony_ci)"; 1904fd4e5da5Sopenharmony_ci const std::string types = R"( 1905fd4e5da5Sopenharmony_ci%s64ptr_func = OpTypePointer Function %s64 1906fd4e5da5Sopenharmony_ci%typeAS = OpTypeAccelerationStructureKHR 1907fd4e5da5Sopenharmony_ci)"; 1908fd4e5da5Sopenharmony_ci const std::string body = R"( 1909fd4e5da5Sopenharmony_ci%asHandle = OpVariable %s64ptr_func Function 1910fd4e5da5Sopenharmony_ci%load = OpLoad %s64 %asHandle 1911fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeAS %load 1912fd4e5da5Sopenharmony_ci)"; 1913fd4e5da5Sopenharmony_ci 1914fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1915fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1916fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1917fd4e5da5Sopenharmony_ci HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " 1918fd4e5da5Sopenharmony_ci "uint vector as input")); 1919fd4e5da5Sopenharmony_ci} 1920fd4e5da5Sopenharmony_ci 1921fd4e5da5Sopenharmony_ciTEST_F(ValidateConversion, ConvertUToAccelerationStructureS32Vec2) { 1922fd4e5da5Sopenharmony_ci const std::string extensions = R"( 1923fd4e5da5Sopenharmony_ciOpCapability RayQueryKHR 1924fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_query" 1925fd4e5da5Sopenharmony_ci)"; 1926fd4e5da5Sopenharmony_ci const std::string types = R"( 1927fd4e5da5Sopenharmony_ci%s32vec2ptr_func = OpTypePointer Function %s32vec2 1928fd4e5da5Sopenharmony_ci%typeAS = OpTypeAccelerationStructureKHR 1929fd4e5da5Sopenharmony_ci)"; 1930fd4e5da5Sopenharmony_ci const std::string body = R"( 1931fd4e5da5Sopenharmony_ci%asHandle = OpVariable %s32vec2ptr_func Function 1932fd4e5da5Sopenharmony_ci%load = OpLoad %s32vec2 %asHandle 1933fd4e5da5Sopenharmony_ci%val = OpConvertUToAccelerationStructureKHR %typeAS %load 1934fd4e5da5Sopenharmony_ci)"; 1935fd4e5da5Sopenharmony_ci 1936fd4e5da5Sopenharmony_ci CompileSuccessfully(GenerateShaderCode(body, extensions, "", types).c_str()); 1937fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()); 1938fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 1939fd4e5da5Sopenharmony_ci HasSubstr("Expected 64-bit uint scalar or 2-component 32-bit " 1940fd4e5da5Sopenharmony_ci "uint vector as input")); 1941fd4e5da5Sopenharmony_ci} 1942fd4e5da5Sopenharmony_ci 1943fd4e5da5Sopenharmony_ciusing ValidateSmallConversions = spvtest::ValidateBase<std::string>; 1944fd4e5da5Sopenharmony_ci 1945fd4e5da5Sopenharmony_ciCodeGenerator GetSmallConversionsCodeGenerator() { 1946fd4e5da5Sopenharmony_ci CodeGenerator generator; 1947fd4e5da5Sopenharmony_ci generator.capabilities_ = R"( 1948fd4e5da5Sopenharmony_ciOpCapability Shader 1949fd4e5da5Sopenharmony_ciOpCapability Linkage 1950fd4e5da5Sopenharmony_ciOpCapability UniformAndStorageBuffer16BitAccess 1951fd4e5da5Sopenharmony_ciOpCapability UniformAndStorageBuffer8BitAccess 1952fd4e5da5Sopenharmony_ci)"; 1953fd4e5da5Sopenharmony_ci generator.extensions_ = R"( 1954fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_16bit_storage" 1955fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_8bit_storage" 1956fd4e5da5Sopenharmony_ci)"; 1957fd4e5da5Sopenharmony_ci generator.memory_model_ = "OpMemoryModel Logical GLSL450\n"; 1958fd4e5da5Sopenharmony_ci generator.before_types_ = R"( 1959fd4e5da5Sopenharmony_ciOpDecorate %char_block Block 1960fd4e5da5Sopenharmony_ciOpMemberDecorate %char_block 0 Offset 0 1961fd4e5da5Sopenharmony_ciOpDecorate %short_block Block 1962fd4e5da5Sopenharmony_ciOpMemberDecorate %short_block 0 Offset 0 1963fd4e5da5Sopenharmony_ciOpDecorate %half_block Block 1964fd4e5da5Sopenharmony_ciOpMemberDecorate %half_block 0 Offset 0 1965fd4e5da5Sopenharmony_ciOpDecorate %int_block Block 1966fd4e5da5Sopenharmony_ciOpMemberDecorate %int_block 0 Offset 0 1967fd4e5da5Sopenharmony_ciOpDecorate %float_block Block 1968fd4e5da5Sopenharmony_ciOpMemberDecorate %float_block 0 Offset 0 1969fd4e5da5Sopenharmony_ci)"; 1970fd4e5da5Sopenharmony_ci generator.types_ = R"( 1971fd4e5da5Sopenharmony_ci%void = OpTypeVoid 1972fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0 1973fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0 1974fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1 1975fd4e5da5Sopenharmony_ci%int2 = OpTypeVector %int 2 1976fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32 1977fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0 1978fd4e5da5Sopenharmony_ci%float2 = OpTypeVector %float 2 1979fd4e5da5Sopenharmony_ci%char = OpTypeInt 8 0 1980fd4e5da5Sopenharmony_ci%char2 = OpTypeVector %char 2 1981fd4e5da5Sopenharmony_ci%short = OpTypeInt 16 0 1982fd4e5da5Sopenharmony_ci%short2 = OpTypeVector %short 2 1983fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16 1984fd4e5da5Sopenharmony_ci%half2 = OpTypeVector %half 2 1985fd4e5da5Sopenharmony_ci%char_block = OpTypeStruct %char2 1986fd4e5da5Sopenharmony_ci%short_block = OpTypeStruct %short2 1987fd4e5da5Sopenharmony_ci%half_block = OpTypeStruct %half2 1988fd4e5da5Sopenharmony_ci%int_block = OpTypeStruct %int2 1989fd4e5da5Sopenharmony_ci%float_block = OpTypeStruct %float2 1990fd4e5da5Sopenharmony_ci%ptr_ssbo_char_block = OpTypePointer StorageBuffer %char_block 1991fd4e5da5Sopenharmony_ci%ptr_ssbo_char2 = OpTypePointer StorageBuffer %char2 1992fd4e5da5Sopenharmony_ci%ptr_ssbo_char = OpTypePointer StorageBuffer %char 1993fd4e5da5Sopenharmony_ci%ptr_ssbo_short_block = OpTypePointer StorageBuffer %short_block 1994fd4e5da5Sopenharmony_ci%ptr_ssbo_short2 = OpTypePointer StorageBuffer %short2 1995fd4e5da5Sopenharmony_ci%ptr_ssbo_short = OpTypePointer StorageBuffer %short 1996fd4e5da5Sopenharmony_ci%ptr_ssbo_half_block = OpTypePointer StorageBuffer %half_block 1997fd4e5da5Sopenharmony_ci%ptr_ssbo_half2 = OpTypePointer StorageBuffer %half2 1998fd4e5da5Sopenharmony_ci%ptr_ssbo_half = OpTypePointer StorageBuffer %half 1999fd4e5da5Sopenharmony_ci%ptr_ssbo_int_block = OpTypePointer StorageBuffer %int_block 2000fd4e5da5Sopenharmony_ci%ptr_ssbo_int2 = OpTypePointer StorageBuffer %int2 2001fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int 2002fd4e5da5Sopenharmony_ci%ptr_ssbo_float_block = OpTypePointer StorageBuffer %float_block 2003fd4e5da5Sopenharmony_ci%ptr_ssbo_float2 = OpTypePointer StorageBuffer %float2 2004fd4e5da5Sopenharmony_ci%ptr_ssbo_float = OpTypePointer StorageBuffer %float 2005fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void 2006fd4e5da5Sopenharmony_ci%char_var = OpVariable %ptr_ssbo_char_block StorageBuffer 2007fd4e5da5Sopenharmony_ci%short_var = OpVariable %ptr_ssbo_short_block StorageBuffer 2008fd4e5da5Sopenharmony_ci%half_var = OpVariable %ptr_ssbo_half_block StorageBuffer 2009fd4e5da5Sopenharmony_ci%int_var = OpVariable %ptr_ssbo_int_block StorageBuffer 2010fd4e5da5Sopenharmony_ci%float_var = OpVariable %ptr_ssbo_float_block StorageBuffer 2011fd4e5da5Sopenharmony_ci)"; 2012fd4e5da5Sopenharmony_ci generator.after_types_ = R"( 2013fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn 2014fd4e5da5Sopenharmony_ci%entry = OpLabel 2015fd4e5da5Sopenharmony_ci%char2_gep = OpAccessChain %ptr_ssbo_char2 %char_var %int_0 2016fd4e5da5Sopenharmony_ci%ld_char2 = OpLoad %char2 %char2_gep 2017fd4e5da5Sopenharmony_ci%char_gep = OpAccessChain %ptr_ssbo_char %char_var %int_0 %int_0 2018fd4e5da5Sopenharmony_ci%ld_char = OpLoad %char %char_gep 2019fd4e5da5Sopenharmony_ci%short2_gep = OpAccessChain %ptr_ssbo_short2 %short_var %int_0 2020fd4e5da5Sopenharmony_ci%ld_short2 = OpLoad %short2 %short2_gep 2021fd4e5da5Sopenharmony_ci%short_gep = OpAccessChain %ptr_ssbo_short %short_var %int_0 %int_0 2022fd4e5da5Sopenharmony_ci%ld_short = OpLoad %short %short_gep 2023fd4e5da5Sopenharmony_ci%half2_gep = OpAccessChain %ptr_ssbo_half2 %half_var %int_0 2024fd4e5da5Sopenharmony_ci%ld_half2 = OpLoad %half2 %half2_gep 2025fd4e5da5Sopenharmony_ci%half_gep = OpAccessChain %ptr_ssbo_half %half_var %int_0 %int_0 2026fd4e5da5Sopenharmony_ci%ld_half = OpLoad %half %half_gep 2027fd4e5da5Sopenharmony_ci%int2_gep = OpAccessChain %ptr_ssbo_int2 %int_var %int_0 2028fd4e5da5Sopenharmony_ci%ld_int2 = OpLoad %int2 %int2_gep 2029fd4e5da5Sopenharmony_ci%int_gep = OpAccessChain %ptr_ssbo_int %int_var %int_0 %int_0 2030fd4e5da5Sopenharmony_ci%ld_int = OpLoad %int %int_gep 2031fd4e5da5Sopenharmony_ci%float2_gep = OpAccessChain %ptr_ssbo_float2 %float_var %int_0 2032fd4e5da5Sopenharmony_ci%ld_float2 = OpLoad %float2 %float2_gep 2033fd4e5da5Sopenharmony_ci%float_gep = OpAccessChain %ptr_ssbo_float %float_var %int_0 %int_0 2034fd4e5da5Sopenharmony_ci%ld_float = OpLoad %float %float_gep 2035fd4e5da5Sopenharmony_ci)"; 2036fd4e5da5Sopenharmony_ci generator.add_at_the_end_ = R"( 2037fd4e5da5Sopenharmony_ciOpReturn 2038fd4e5da5Sopenharmony_ciOpFunctionEnd 2039fd4e5da5Sopenharmony_ci)"; 2040fd4e5da5Sopenharmony_ci return generator; 2041fd4e5da5Sopenharmony_ci} 2042fd4e5da5Sopenharmony_ci 2043fd4e5da5Sopenharmony_ciTEST_P(ValidateSmallConversions, Instruction) { 2044fd4e5da5Sopenharmony_ci CodeGenerator generator = GetSmallConversionsCodeGenerator(); 2045fd4e5da5Sopenharmony_ci generator.after_types_ += GetParam() + "\n"; 2046fd4e5da5Sopenharmony_ci CompileSuccessfully(generator.Build(), SPV_ENV_UNIVERSAL_1_3); 2047fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, 2048fd4e5da5Sopenharmony_ci ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); 2049fd4e5da5Sopenharmony_ci EXPECT_THAT( 2050fd4e5da5Sopenharmony_ci getDiagnosticString(), 2051fd4e5da5Sopenharmony_ci HasSubstr( 2052fd4e5da5Sopenharmony_ci "8- or 16-bit types can only be used with width-only conversions")); 2053fd4e5da5Sopenharmony_ci} 2054fd4e5da5Sopenharmony_ci 2055fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(SmallConversionInstructions, ValidateSmallConversions, 2056fd4e5da5Sopenharmony_ci Values("%inst = OpConvertFToU %char %ld_float", 2057fd4e5da5Sopenharmony_ci "%inst = OpConvertFToU %char2 %ld_float2", 2058fd4e5da5Sopenharmony_ci "%inst = OpConvertFToU %short %ld_float", 2059fd4e5da5Sopenharmony_ci "%inst = OpConvertFToU %short2 %ld_float2", 2060fd4e5da5Sopenharmony_ci "%inst = OpConvertFToU %int %ld_half", 2061fd4e5da5Sopenharmony_ci "%inst = OpConvertFToU %int2 %ld_half2", 2062fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %char %ld_float", 2063fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %char2 %ld_float2", 2064fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %short %ld_float", 2065fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %short2 %ld_float2", 2066fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %int %ld_half", 2067fd4e5da5Sopenharmony_ci "%inst = OpConvertFToS %int2 %ld_half2", 2068fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %float %ld_char", 2069fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %float2 %ld_char2", 2070fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %float %ld_short", 2071fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %float2 %ld_short2", 2072fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %half %ld_int", 2073fd4e5da5Sopenharmony_ci "%inst = OpConvertSToF %half2 %ld_int2", 2074fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %float %ld_char", 2075fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %float2 %ld_char2", 2076fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %float %ld_short", 2077fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %float2 %ld_short2", 2078fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %half %ld_int", 2079fd4e5da5Sopenharmony_ci "%inst = OpConvertUToF %half2 %ld_int2", 2080fd4e5da5Sopenharmony_ci "%inst = OpBitcast %half %ld_short", 2081fd4e5da5Sopenharmony_ci "%inst = OpBitcast %half2 %ld_short2", 2082fd4e5da5Sopenharmony_ci "%inst = OpBitcast %short %ld_half", 2083fd4e5da5Sopenharmony_ci "%inst = OpBitcast %short2 %ld_half2")); 2084fd4e5da5Sopenharmony_ci 2085fd4e5da5Sopenharmony_ci} // namespace 2086fd4e5da5Sopenharmony_ci} // namespace val 2087fd4e5da5Sopenharmony_ci} // namespace spvtools 2088