1fd4e5da5Sopenharmony_ci// Copyright (c) 2019 The Khronos Group 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// Validation tests for OpenCL env specific checks 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include <string> 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_ci#include "gmock/gmock.h" 20fd4e5da5Sopenharmony_ci#include "test/val/val_fixtures.h" 21fd4e5da5Sopenharmony_ci 22fd4e5da5Sopenharmony_cinamespace spvtools { 23fd4e5da5Sopenharmony_cinamespace val { 24fd4e5da5Sopenharmony_cinamespace { 25fd4e5da5Sopenharmony_ci 26fd4e5da5Sopenharmony_ciusing testing::Eq; 27fd4e5da5Sopenharmony_ciusing testing::HasSubstr; 28fd4e5da5Sopenharmony_ci 29fd4e5da5Sopenharmony_ciusing ValidateOpenCL = spvtest::ValidateBase<bool>; 30fd4e5da5Sopenharmony_ci 31fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NonPhysicalAddressingModelBad) { 32fd4e5da5Sopenharmony_ci std::string spirv = R"( 33fd4e5da5Sopenharmony_ci OpCapability Kernel 34fd4e5da5Sopenharmony_ci OpMemoryModel Logical OpenCL 35fd4e5da5Sopenharmony_ci)"; 36fd4e5da5Sopenharmony_ci 37fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 38fd4e5da5Sopenharmony_ci 39fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 40fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 41fd4e5da5Sopenharmony_ci HasSubstr("Addressing model must be Physical32 or Physical64 " 42fd4e5da5Sopenharmony_ci "in the OpenCL environment.\n OpMemoryModel Logical " 43fd4e5da5Sopenharmony_ci "OpenCL\n")); 44fd4e5da5Sopenharmony_ci} 45fd4e5da5Sopenharmony_ci 46fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NonOpenCLMemoryModelBad) { 47fd4e5da5Sopenharmony_ci std::string spirv = R"( 48fd4e5da5Sopenharmony_ci OpCapability Kernel 49fd4e5da5Sopenharmony_ci OpCapability Addresses 50fd4e5da5Sopenharmony_ci OpCapability VulkanMemoryModelKHR 51fd4e5da5Sopenharmony_ci OpExtension "SPV_KHR_vulkan_memory_model" 52fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 VulkanKHR 53fd4e5da5Sopenharmony_ci)"; 54fd4e5da5Sopenharmony_ci 55fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 56fd4e5da5Sopenharmony_ci 57fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 58fd4e5da5Sopenharmony_ci EXPECT_THAT( 59fd4e5da5Sopenharmony_ci getDiagnosticString(), 60fd4e5da5Sopenharmony_ci HasSubstr("Memory model must be OpenCL in the OpenCL environment.")); 61fd4e5da5Sopenharmony_ci} 62fd4e5da5Sopenharmony_ci 63fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NonVoidSampledTypeImageBad) { 64fd4e5da5Sopenharmony_ci std::string spirv = R"( 65fd4e5da5Sopenharmony_ci OpCapability Addresses 66fd4e5da5Sopenharmony_ci OpCapability Kernel 67fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 OpenCL 68fd4e5da5Sopenharmony_ci %1 = OpTypeInt 32 0 69fd4e5da5Sopenharmony_ci %2 = OpTypeImage %1 2D 0 0 0 0 Unknown ReadOnly 70fd4e5da5Sopenharmony_ci)"; 71fd4e5da5Sopenharmony_ci 72fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 73fd4e5da5Sopenharmony_ci 74fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 75fd4e5da5Sopenharmony_ci EXPECT_THAT( 76fd4e5da5Sopenharmony_ci getDiagnosticString(), 77fd4e5da5Sopenharmony_ci HasSubstr("Sampled Type must be OpTypeVoid in the OpenCL environment." 78fd4e5da5Sopenharmony_ci "\n %2 = OpTypeImage %uint 2D 0 0 0 0 Unknown ReadOnly\n")); 79fd4e5da5Sopenharmony_ci} 80fd4e5da5Sopenharmony_ci 81fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NonZeroMSImageBad) { 82fd4e5da5Sopenharmony_ci std::string spirv = R"( 83fd4e5da5Sopenharmony_ci OpCapability Addresses 84fd4e5da5Sopenharmony_ci OpCapability Kernel 85fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 OpenCL 86fd4e5da5Sopenharmony_ci %1 = OpTypeVoid 87fd4e5da5Sopenharmony_ci %2 = OpTypeImage %1 2D 0 0 1 0 Unknown ReadOnly 88fd4e5da5Sopenharmony_ci)"; 89fd4e5da5Sopenharmony_ci 90fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 91fd4e5da5Sopenharmony_ci 92fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 93fd4e5da5Sopenharmony_ci EXPECT_THAT( 94fd4e5da5Sopenharmony_ci getDiagnosticString(), 95fd4e5da5Sopenharmony_ci HasSubstr("MS must be 0 in the OpenCL environment." 96fd4e5da5Sopenharmony_ci "\n %2 = OpTypeImage %void 2D 0 0 1 0 Unknown ReadOnly\n")); 97fd4e5da5Sopenharmony_ci} 98fd4e5da5Sopenharmony_ci 99fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, Non1D2DArrayedImageBad) { 100fd4e5da5Sopenharmony_ci std::string spirv = R"( 101fd4e5da5Sopenharmony_ci OpCapability Addresses 102fd4e5da5Sopenharmony_ci OpCapability Kernel 103fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 OpenCL 104fd4e5da5Sopenharmony_ci %1 = OpTypeVoid 105fd4e5da5Sopenharmony_ci %2 = OpTypeImage %1 3D 0 1 0 0 Unknown ReadOnly 106fd4e5da5Sopenharmony_ci)"; 107fd4e5da5Sopenharmony_ci 108fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 109fd4e5da5Sopenharmony_ci 110fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 111fd4e5da5Sopenharmony_ci EXPECT_THAT( 112fd4e5da5Sopenharmony_ci getDiagnosticString(), 113fd4e5da5Sopenharmony_ci HasSubstr("In the OpenCL environment, Arrayed may only be set to 1 " 114fd4e5da5Sopenharmony_ci "when Dim is either 1D or 2D." 115fd4e5da5Sopenharmony_ci "\n %2 = OpTypeImage %void 3D 0 1 0 0 Unknown ReadOnly\n")); 116fd4e5da5Sopenharmony_ci} 117fd4e5da5Sopenharmony_ci 118fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NonZeroSampledImageBad) { 119fd4e5da5Sopenharmony_ci std::string spirv = R"( 120fd4e5da5Sopenharmony_ci OpCapability Addresses 121fd4e5da5Sopenharmony_ci OpCapability Kernel 122fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 OpenCL 123fd4e5da5Sopenharmony_ci %1 = OpTypeVoid 124fd4e5da5Sopenharmony_ci %2 = OpTypeImage %1 3D 0 0 0 1 Unknown ReadOnly 125fd4e5da5Sopenharmony_ci)"; 126fd4e5da5Sopenharmony_ci 127fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 128fd4e5da5Sopenharmony_ci 129fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 130fd4e5da5Sopenharmony_ci EXPECT_THAT( 131fd4e5da5Sopenharmony_ci getDiagnosticString(), 132fd4e5da5Sopenharmony_ci HasSubstr("Sampled must be 0 in the OpenCL environment." 133fd4e5da5Sopenharmony_ci "\n %2 = OpTypeImage %void 3D 0 0 0 1 Unknown ReadOnly\n")); 134fd4e5da5Sopenharmony_ci} 135fd4e5da5Sopenharmony_ci 136fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, NoAccessQualifierImageBad) { 137fd4e5da5Sopenharmony_ci std::string spirv = R"( 138fd4e5da5Sopenharmony_ci OpCapability Addresses 139fd4e5da5Sopenharmony_ci OpCapability Kernel 140fd4e5da5Sopenharmony_ci OpMemoryModel Physical32 OpenCL 141fd4e5da5Sopenharmony_ci %1 = OpTypeVoid 142fd4e5da5Sopenharmony_ci %2 = OpTypeImage %1 3D 0 0 0 0 Unknown 143fd4e5da5Sopenharmony_ci)"; 144fd4e5da5Sopenharmony_ci 145fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 146fd4e5da5Sopenharmony_ci 147fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 148fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 149fd4e5da5Sopenharmony_ci HasSubstr("In the OpenCL environment, the optional " 150fd4e5da5Sopenharmony_ci "Access Qualifier must be present." 151fd4e5da5Sopenharmony_ci "\n %2 = OpTypeImage %void 3D 0 0 0 0 Unknown\n")); 152fd4e5da5Sopenharmony_ci} 153fd4e5da5Sopenharmony_ci 154fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageWriteWithOptionalImageOperandsBad) { 155fd4e5da5Sopenharmony_ci std::string spirv = R"( 156fd4e5da5Sopenharmony_ci OpCapability Addresses 157fd4e5da5Sopenharmony_ci OpCapability Kernel 158fd4e5da5Sopenharmony_ci OpCapability ImageBasic 159fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 160fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "test" 161fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 162fd4e5da5Sopenharmony_ci %uint_7 = OpConstant %uint 7 163fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 164fd4e5da5Sopenharmony_ci %uint_1 = OpConstant %uint 1 165fd4e5da5Sopenharmony_ci %uint_2 = OpConstant %uint 2 166fd4e5da5Sopenharmony_ci %uint_4 = OpConstant %uint 4 167fd4e5da5Sopenharmony_ci %void = OpTypeVoid 168fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown WriteOnly 169fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 170fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 171fd4e5da5Sopenharmony_ci %v4uint = OpTypeVector %uint 4 172fd4e5da5Sopenharmony_ci %12 = OpConstantComposite %v2uint %uint_7 %uint_3 173fd4e5da5Sopenharmony_ci %17 = OpConstantComposite %v4uint %uint_1 %uint_2 %uint_3 %uint_4 174fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 175fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 176fd4e5da5Sopenharmony_ci %entry = OpLabel 177fd4e5da5Sopenharmony_ci OpImageWrite %img %12 %17 ConstOffset %12 178fd4e5da5Sopenharmony_ci OpReturn 179fd4e5da5Sopenharmony_ci OpFunctionEnd 180fd4e5da5Sopenharmony_ci)"; 181fd4e5da5Sopenharmony_ci 182fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 183fd4e5da5Sopenharmony_ci 184fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 185fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 186fd4e5da5Sopenharmony_ci HasSubstr("Optional Image Operands are not allowed in the " 187fd4e5da5Sopenharmony_ci "OpenCL environment." 188fd4e5da5Sopenharmony_ci "\n OpImageWrite %15 %13 %14 ConstOffset %13\n")); 189fd4e5da5Sopenharmony_ci} 190fd4e5da5Sopenharmony_ci 191fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageReadWithConstOffsetBad) { 192fd4e5da5Sopenharmony_ci std::string spirv = R"( 193fd4e5da5Sopenharmony_ci OpCapability Addresses 194fd4e5da5Sopenharmony_ci OpCapability Kernel 195fd4e5da5Sopenharmony_ci OpCapability ImageBasic 196fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 197fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 198fd4e5da5Sopenharmony_ci OpName %img "img" 199fd4e5da5Sopenharmony_ci OpName %coord "coord" 200fd4e5da5Sopenharmony_ci OpName %call "call" 201fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 202fd4e5da5Sopenharmony_ci %uint_7 = OpConstant %uint 7 203fd4e5da5Sopenharmony_ci %uint_3 = OpConstant %uint 3 204fd4e5da5Sopenharmony_ci %void = OpTypeVoid 205fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 206fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 207fd4e5da5Sopenharmony_ci %v4uint = OpTypeVector %uint 4 208fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 209fd4e5da5Sopenharmony_ci %coord = OpConstantComposite %v2uint %uint_7 %uint_3 210fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 211fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 212fd4e5da5Sopenharmony_ci %entry = OpLabel 213fd4e5da5Sopenharmony_ci %call = OpImageRead %v4uint %img %coord ConstOffset %coord 214fd4e5da5Sopenharmony_ci OpReturn 215fd4e5da5Sopenharmony_ci OpFunctionEnd 216fd4e5da5Sopenharmony_ci)"; 217fd4e5da5Sopenharmony_ci 218fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 219fd4e5da5Sopenharmony_ci 220fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 221fd4e5da5Sopenharmony_ci EXPECT_THAT( 222fd4e5da5Sopenharmony_ci getDiagnosticString(), 223fd4e5da5Sopenharmony_ci HasSubstr( 224fd4e5da5Sopenharmony_ci "ConstOffset image operand not allowed in the OpenCL environment." 225fd4e5da5Sopenharmony_ci "\n %call = OpImageRead %v4uint %img %coord ConstOffset %coord\n")); 226fd4e5da5Sopenharmony_ci} 227fd4e5da5Sopenharmony_ci 228fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_NonDepthScalarFloatResult_Bad) { 229fd4e5da5Sopenharmony_ci std::string spirv = R"( 230fd4e5da5Sopenharmony_ci OpCapability Addresses 231fd4e5da5Sopenharmony_ci OpCapability Kernel 232fd4e5da5Sopenharmony_ci OpCapability ImageBasic 233fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 234fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 235fd4e5da5Sopenharmony_ci OpName %img "img" 236fd4e5da5Sopenharmony_ci OpName %coord "coord" 237fd4e5da5Sopenharmony_ci OpName %call "call" 238fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 239fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 240fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 241fd4e5da5Sopenharmony_ci %void = OpTypeVoid 242fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 243fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 244fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 245fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 246fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 247fd4e5da5Sopenharmony_ci %entry = OpLabel 248fd4e5da5Sopenharmony_ci %call = OpImageRead %float %img %coord 249fd4e5da5Sopenharmony_ci OpReturn 250fd4e5da5Sopenharmony_ci OpFunctionEnd 251fd4e5da5Sopenharmony_ci)"; 252fd4e5da5Sopenharmony_ci 253fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 254fd4e5da5Sopenharmony_ci 255fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 256fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 257fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to have 4 components")); 258fd4e5da5Sopenharmony_ci} 259fd4e5da5Sopenharmony_ci 260fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_NonDepthScalarIntResult_Bad) { 261fd4e5da5Sopenharmony_ci std::string spirv = R"( 262fd4e5da5Sopenharmony_ci OpCapability Addresses 263fd4e5da5Sopenharmony_ci OpCapability Kernel 264fd4e5da5Sopenharmony_ci OpCapability ImageBasic 265fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 266fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 267fd4e5da5Sopenharmony_ci OpName %img "img" 268fd4e5da5Sopenharmony_ci OpName %coord "coord" 269fd4e5da5Sopenharmony_ci OpName %call "call" 270fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 271fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 272fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 273fd4e5da5Sopenharmony_ci %void = OpTypeVoid 274fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 275fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 276fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 277fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 278fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 279fd4e5da5Sopenharmony_ci %entry = OpLabel 280fd4e5da5Sopenharmony_ci %call = OpImageRead %uint %img %coord 281fd4e5da5Sopenharmony_ci OpReturn 282fd4e5da5Sopenharmony_ci OpFunctionEnd 283fd4e5da5Sopenharmony_ci)"; 284fd4e5da5Sopenharmony_ci 285fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 286fd4e5da5Sopenharmony_ci 287fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 288fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 289fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to have 4 components")); 290fd4e5da5Sopenharmony_ci} 291fd4e5da5Sopenharmony_ci 292fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_NonDepthVector3FloatResult_Bad) { 293fd4e5da5Sopenharmony_ci std::string spirv = R"( 294fd4e5da5Sopenharmony_ci OpCapability Addresses 295fd4e5da5Sopenharmony_ci OpCapability Kernel 296fd4e5da5Sopenharmony_ci OpCapability ImageBasic 297fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 298fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 299fd4e5da5Sopenharmony_ci OpName %img "img" 300fd4e5da5Sopenharmony_ci OpName %coord "coord" 301fd4e5da5Sopenharmony_ci OpName %call "call" 302fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 303fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 304fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 305fd4e5da5Sopenharmony_ci %void = OpTypeVoid 306fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 307fd4e5da5Sopenharmony_ci %v3float = OpTypeVector %float 3 308fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 309fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 310fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 311fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 312fd4e5da5Sopenharmony_ci %entry = OpLabel 313fd4e5da5Sopenharmony_ci %call = OpImageRead %v3float %img %coord 314fd4e5da5Sopenharmony_ci OpReturn 315fd4e5da5Sopenharmony_ci OpFunctionEnd 316fd4e5da5Sopenharmony_ci)"; 317fd4e5da5Sopenharmony_ci 318fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 319fd4e5da5Sopenharmony_ci 320fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 321fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 322fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type to have 4 components")); 323fd4e5da5Sopenharmony_ci} 324fd4e5da5Sopenharmony_ci 325fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_NonDepthVector4FloatResult_Ok) { 326fd4e5da5Sopenharmony_ci std::string spirv = R"( 327fd4e5da5Sopenharmony_ci OpCapability Addresses 328fd4e5da5Sopenharmony_ci OpCapability Kernel 329fd4e5da5Sopenharmony_ci OpCapability ImageBasic 330fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 331fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 332fd4e5da5Sopenharmony_ci OpName %img "img" 333fd4e5da5Sopenharmony_ci OpName %coord "coord" 334fd4e5da5Sopenharmony_ci OpName %call "call" 335fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 336fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 337fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 338fd4e5da5Sopenharmony_ci %void = OpTypeVoid 339fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 340fd4e5da5Sopenharmony_ci %v4float = OpTypeVector %float 4 341fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 342fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 343fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 344fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 345fd4e5da5Sopenharmony_ci %entry = OpLabel 346fd4e5da5Sopenharmony_ci %call = OpImageRead %v4float %img %coord 347fd4e5da5Sopenharmony_ci OpReturn 348fd4e5da5Sopenharmony_ci OpFunctionEnd 349fd4e5da5Sopenharmony_ci)"; 350fd4e5da5Sopenharmony_ci 351fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 352fd4e5da5Sopenharmony_ci 353fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 354fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), Eq("")); 355fd4e5da5Sopenharmony_ci} 356fd4e5da5Sopenharmony_ci 357fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_NonDepthVector4IntResult_Ok) { 358fd4e5da5Sopenharmony_ci std::string spirv = R"( 359fd4e5da5Sopenharmony_ci OpCapability Addresses 360fd4e5da5Sopenharmony_ci OpCapability Kernel 361fd4e5da5Sopenharmony_ci OpCapability ImageBasic 362fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 363fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 364fd4e5da5Sopenharmony_ci OpName %img "img" 365fd4e5da5Sopenharmony_ci OpName %coord "coord" 366fd4e5da5Sopenharmony_ci OpName %call "call" 367fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 368fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 369fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 370fd4e5da5Sopenharmony_ci %void = OpTypeVoid 371fd4e5da5Sopenharmony_ci %v4uint = OpTypeVector %uint 4 372fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 373fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 374fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 375fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 376fd4e5da5Sopenharmony_ci %entry = OpLabel 377fd4e5da5Sopenharmony_ci %call = OpImageRead %v4uint %img %coord 378fd4e5da5Sopenharmony_ci OpReturn 379fd4e5da5Sopenharmony_ci OpFunctionEnd 380fd4e5da5Sopenharmony_ci)"; 381fd4e5da5Sopenharmony_ci 382fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 383fd4e5da5Sopenharmony_ci 384fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 385fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), Eq("")); 386fd4e5da5Sopenharmony_ci} 387fd4e5da5Sopenharmony_ci 388fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_DepthScalarFloatResult_Ok) { 389fd4e5da5Sopenharmony_ci std::string spirv = R"( 390fd4e5da5Sopenharmony_ci OpCapability Addresses 391fd4e5da5Sopenharmony_ci OpCapability Kernel 392fd4e5da5Sopenharmony_ci OpCapability ImageBasic 393fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 394fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 395fd4e5da5Sopenharmony_ci OpName %img "img" 396fd4e5da5Sopenharmony_ci OpName %coord "coord" 397fd4e5da5Sopenharmony_ci OpName %call "call" 398fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 399fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 400fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 401fd4e5da5Sopenharmony_ci %void = OpTypeVoid 402fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 403fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 1 0 0 0 Unknown ReadOnly 404fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 405fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 406fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 407fd4e5da5Sopenharmony_ci %entry = OpLabel 408fd4e5da5Sopenharmony_ci %call = OpImageRead %float %img %coord 409fd4e5da5Sopenharmony_ci OpReturn 410fd4e5da5Sopenharmony_ci OpFunctionEnd 411fd4e5da5Sopenharmony_ci)"; 412fd4e5da5Sopenharmony_ci 413fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 414fd4e5da5Sopenharmony_ci 415fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 416fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), Eq("")); 417fd4e5da5Sopenharmony_ci} 418fd4e5da5Sopenharmony_ci 419fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_DepthScalarIntResult_Bad) { 420fd4e5da5Sopenharmony_ci std::string spirv = R"( 421fd4e5da5Sopenharmony_ci OpCapability Addresses 422fd4e5da5Sopenharmony_ci OpCapability Kernel 423fd4e5da5Sopenharmony_ci OpCapability ImageBasic 424fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 425fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 426fd4e5da5Sopenharmony_ci OpName %img "img" 427fd4e5da5Sopenharmony_ci OpName %coord "coord" 428fd4e5da5Sopenharmony_ci OpName %call "call" 429fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 430fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 431fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 432fd4e5da5Sopenharmony_ci %void = OpTypeVoid 433fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 434fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 1 0 0 0 Unknown ReadOnly 435fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 436fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 437fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 438fd4e5da5Sopenharmony_ci %entry = OpLabel 439fd4e5da5Sopenharmony_ci %call = OpImageRead %uint %img %coord 440fd4e5da5Sopenharmony_ci OpReturn 441fd4e5da5Sopenharmony_ci OpFunctionEnd 442fd4e5da5Sopenharmony_ci)"; 443fd4e5da5Sopenharmony_ci 444fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 445fd4e5da5Sopenharmony_ci 446fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 447fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 448fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type from a depth image " 449fd4e5da5Sopenharmony_ci "read to result in a scalar float value")); 450fd4e5da5Sopenharmony_ci} 451fd4e5da5Sopenharmony_ci 452fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageRead_DepthVectorFloatResult_Bad) { 453fd4e5da5Sopenharmony_ci std::string spirv = R"( 454fd4e5da5Sopenharmony_ci OpCapability Addresses 455fd4e5da5Sopenharmony_ci OpCapability Kernel 456fd4e5da5Sopenharmony_ci OpCapability ImageBasic 457fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 458fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 459fd4e5da5Sopenharmony_ci OpName %img "img" 460fd4e5da5Sopenharmony_ci OpName %coord "coord" 461fd4e5da5Sopenharmony_ci OpName %call "call" 462fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 463fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 464fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 465fd4e5da5Sopenharmony_ci %void = OpTypeVoid 466fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 467fd4e5da5Sopenharmony_ci %v4float = OpTypeVector %float 4 468fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 1 0 0 0 Unknown ReadOnly 469fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 470fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 471fd4e5da5Sopenharmony_ci %img = OpFunctionParameter %3 472fd4e5da5Sopenharmony_ci %entry = OpLabel 473fd4e5da5Sopenharmony_ci %call = OpImageRead %v4float %img %coord 474fd4e5da5Sopenharmony_ci OpReturn 475fd4e5da5Sopenharmony_ci OpFunctionEnd 476fd4e5da5Sopenharmony_ci)"; 477fd4e5da5Sopenharmony_ci 478fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 479fd4e5da5Sopenharmony_ci 480fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 481fd4e5da5Sopenharmony_ci EXPECT_THAT(getDiagnosticString(), 482fd4e5da5Sopenharmony_ci HasSubstr("Expected Result Type from a depth image " 483fd4e5da5Sopenharmony_ci "read to result in a scalar float value")); 484fd4e5da5Sopenharmony_ci} 485fd4e5da5Sopenharmony_ci 486fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL, ImageSampleExplicitLodWithConstOffsetBad) { 487fd4e5da5Sopenharmony_ci std::string spirv = R"( 488fd4e5da5Sopenharmony_ci OpCapability Addresses 489fd4e5da5Sopenharmony_ci OpCapability Kernel 490fd4e5da5Sopenharmony_ci OpCapability ImageBasic 491fd4e5da5Sopenharmony_ci OpCapability LiteralSampler 492fd4e5da5Sopenharmony_ci OpMemoryModel Physical64 OpenCL 493fd4e5da5Sopenharmony_ci OpEntryPoint Kernel %5 "image_kernel" 494fd4e5da5Sopenharmony_ci OpName %img "img" 495fd4e5da5Sopenharmony_ci OpName %coord "coord" 496fd4e5da5Sopenharmony_ci OpName %call "call" 497fd4e5da5Sopenharmony_ci %uint = OpTypeInt 32 0 498fd4e5da5Sopenharmony_ci %v2uint = OpTypeVector %uint 2 499fd4e5da5Sopenharmony_ci %coord = OpConstantNull %v2uint 500fd4e5da5Sopenharmony_ci %void = OpTypeVoid 501fd4e5da5Sopenharmony_ci %3 = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly 502fd4e5da5Sopenharmony_ci %4 = OpTypeFunction %void %3 503fd4e5da5Sopenharmony_ci %8 = OpTypeSampler 504fd4e5da5Sopenharmony_ci %10 = OpTypeSampledImage %3 505fd4e5da5Sopenharmony_ci %v4uint = OpTypeVector %uint 4 506fd4e5da5Sopenharmony_ci %float = OpTypeFloat 32 507fd4e5da5Sopenharmony_ci %9 = OpConstantSampler %8 None 0 Nearest 508fd4e5da5Sopenharmony_ci %float_0 = OpConstant %float 0 509fd4e5da5Sopenharmony_ci %5 = OpFunction %void None %4 510fd4e5da5Sopenharmony_ci %6 = OpFunctionParameter %3 511fd4e5da5Sopenharmony_ci %entry = OpLabel 512fd4e5da5Sopenharmony_ci %img = OpSampledImage %10 %6 %9 513fd4e5da5Sopenharmony_ci %call = OpImageSampleExplicitLod %v4uint %img %coord 514fd4e5da5Sopenharmony_ci Lod|ConstOffset %float_0 %coord 515fd4e5da5Sopenharmony_ci OpReturn 516fd4e5da5Sopenharmony_ci OpFunctionEnd 517fd4e5da5Sopenharmony_ci)"; 518fd4e5da5Sopenharmony_ci 519fd4e5da5Sopenharmony_ci CompileSuccessfully(spirv); 520fd4e5da5Sopenharmony_ci 521fd4e5da5Sopenharmony_ci EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_1_2)); 522fd4e5da5Sopenharmony_ci EXPECT_THAT( 523fd4e5da5Sopenharmony_ci getDiagnosticString(), 524fd4e5da5Sopenharmony_ci HasSubstr( 525fd4e5da5Sopenharmony_ci "ConstOffset image operand not allowed in the OpenCL environment." 526fd4e5da5Sopenharmony_ci "\n %call = OpImageSampleExplicitLod %v4uint %img " 527fd4e5da5Sopenharmony_ci "%coord Lod|ConstOffset %float_0 %coord\n")); 528fd4e5da5Sopenharmony_ci} 529fd4e5da5Sopenharmony_ci 530fd4e5da5Sopenharmony_ci} // namespace 531fd4e5da5Sopenharmony_ci} // namespace val 532fd4e5da5Sopenharmony_ci} // namespace spvtools 533