vktSpvAsmInstructionTests.cpp revision 1aece182cbef9abde8437aaf23ee959f3b5e61e0
1/*------------------------------------------------------------------------- 2 * Vulkan Conformance Tests 3 * ------------------------ 4 * 5 * Copyright (c) 2015 Google Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and/or associated documentation files (the 9 * "Materials"), to deal in the Materials without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sublicense, and/or sell copies of the Materials, and to 12 * permit persons to whom the Materials are furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice(s) and this permission notice shall be 16 * included in all copies or substantial portions of the Materials. 17 * 18 * The Materials are Confidential Information as defined by the 19 * Khronos Membership Agreement until designated non-confidential by 20 * Khronos, at which point this condition clause shall be removed. 21 * 22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 29 * 30 *//*! 31 * \file 32 * \brief SPIR-V Assembly Tests for Instructions (special opcode/operand) 33 *//*--------------------------------------------------------------------*/ 34 35#include "vktSpvAsmInstructionTests.hpp" 36 37#include "tcuCommandLine.hpp" 38#include "tcuFormatUtil.hpp" 39#include "tcuRGBA.hpp" 40#include "tcuStringTemplate.hpp" 41#include "tcuTestLog.hpp" 42#include "tcuVectorUtil.hpp" 43 44#include "vkDefs.hpp" 45#include "vkDeviceUtil.hpp" 46#include "vkMemUtil.hpp" 47#include "vkPlatform.hpp" 48#include "vkPrograms.hpp" 49#include "vkQueryUtil.hpp" 50#include "vkRef.hpp" 51#include "vkRefUtil.hpp" 52#include "vkStrUtil.hpp" 53#include "vkTypeUtil.hpp" 54 55#include "deRandom.hpp" 56#include "deStringUtil.hpp" 57#include "deUniquePtr.hpp" 58#include "tcuStringTemplate.hpp" 59 60#include <cmath> 61#include "vktSpvAsmComputeShaderCase.hpp" 62#include "vktSpvAsmComputeShaderTestUtil.hpp" 63#include "vktTestCaseUtil.hpp" 64 65#include <cmath> 66#include <limits> 67#include <map> 68#include <string> 69#include <sstream> 70 71namespace vkt 72{ 73namespace SpirVAssembly 74{ 75 76namespace 77{ 78 79using namespace vk; 80using std::map; 81using std::string; 82using std::vector; 83using tcu::IVec3; 84using tcu::IVec4; 85using tcu::RGBA; 86using tcu::TestLog; 87using tcu::TestStatus; 88using tcu::Vec4; 89using de::UniquePtr; 90using tcu::StringTemplate; 91using tcu::Vec4; 92 93typedef Unique<VkShaderModule> ModuleHandleUp; 94typedef de::SharedPtr<ModuleHandleUp> ModuleHandleSp; 95 96template<typename T> T randomScalar (de::Random& rnd, T minValue, T maxValue); 97template<> inline float randomScalar (de::Random& rnd, float minValue, float maxValue) { return rnd.getFloat(minValue, maxValue); } 98template<> inline deInt32 randomScalar (de::Random& rnd, deInt32 minValue, deInt32 maxValue) { return rnd.getInt(minValue, maxValue); } 99 100template<typename T> 101static void fillRandomScalars (de::Random& rnd, T minValue, T maxValue, void* dst, int numValues, int offset = 0) 102{ 103 T* const typedPtr = (T*)dst; 104 for (int ndx = 0; ndx < numValues; ndx++) 105 typedPtr[offset + ndx] = randomScalar<T>(rnd, minValue, maxValue); 106} 107 108struct CaseParameter 109{ 110 const char* name; 111 string param; 112 113 CaseParameter (const char* case_, const string& param_) : name(case_), param(param_) {} 114}; 115 116// Assembly code used for testing OpNop, OpConstant{Null|Composite}, Op[No]Line, OpSource[Continued], OpSourceExtension, OpUndef is based on GLSL source code: 117// 118// #version 430 119// 120// layout(std140, set = 0, binding = 0) readonly buffer Input { 121// float elements[]; 122// } input_data; 123// layout(std140, set = 0, binding = 1) writeonly buffer Output { 124// float elements[]; 125// } output_data; 126// 127// layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; 128// 129// void main() { 130// uint x = gl_GlobalInvocationID.x; 131// output_data.elements[x] = -input_data.elements[x]; 132// } 133 134static const char* const s_ShaderPreamble = 135 "OpCapability Shader\n" 136 "OpMemoryModel Logical GLSL450\n" 137 "OpEntryPoint GLCompute %main \"main\" %id\n" 138 "OpExecutionMode %main LocalSize 1 1 1\n"; 139 140static const char* const s_CommonTypes = 141 "%bool = OpTypeBool\n" 142 "%void = OpTypeVoid\n" 143 "%voidf = OpTypeFunction %void\n" 144 "%u32 = OpTypeInt 32 0\n" 145 "%i32 = OpTypeInt 32 1\n" 146 "%f32 = OpTypeFloat 32\n" 147 "%uvec3 = OpTypeVector %u32 3\n" 148 "%fvec3 = OpTypeVector %f32 3\n" 149 "%uvec3ptr = OpTypePointer Input %uvec3\n" 150 "%f32ptr = OpTypePointer Uniform %f32\n" 151 "%f32arr = OpTypeRuntimeArray %f32\n"; 152 153// Declares two uniform variables (indata, outdata) of type "struct { float[] }". Depends on type "f32arr" (for "float[]"). 154static const char* const s_InputOutputBuffer = 155 "%inbuf = OpTypeStruct %f32arr\n" 156 "%inbufptr = OpTypePointer Uniform %inbuf\n" 157 "%indata = OpVariable %inbufptr Uniform\n" 158 "%outbuf = OpTypeStruct %f32arr\n" 159 "%outbufptr = OpTypePointer Uniform %outbuf\n" 160 "%outdata = OpVariable %outbufptr Uniform\n"; 161 162// Declares buffer type and layout for uniform variables indata and outdata. Both of them are SSBO bounded to descriptor set 0. 163// indata is at binding point 0, while outdata is at 1. 164static const char* const s_InputOutputBufferTraits = 165 "OpDecorate %inbuf BufferBlock\n" 166 "OpDecorate %indata DescriptorSet 0\n" 167 "OpDecorate %indata Binding 0\n" 168 "OpDecorate %outbuf BufferBlock\n" 169 "OpDecorate %outdata DescriptorSet 0\n" 170 "OpDecorate %outdata Binding 1\n" 171 "OpDecorate %f32arr ArrayStride 4\n" 172 "OpMemberDecorate %inbuf 0 Offset 0\n" 173 "OpMemberDecorate %outbuf 0 Offset 0\n"; 174 175tcu::TestCaseGroup* createOpNopGroup (tcu::TestContext& testCtx) 176{ 177 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnop", "Test the OpNop instruction")); 178 ComputeShaderSpec spec; 179 de::Random rnd (deStringHash(group->getName())); 180 const int numElements = 100; 181 vector<float> positiveFloats (numElements, 0); 182 vector<float> negativeFloats (numElements, 0); 183 184 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 185 186 for (size_t ndx = 0; ndx < numElements; ++ndx) 187 negativeFloats[ndx] = -positiveFloats[ndx]; 188 189 spec.assembly = 190 string(s_ShaderPreamble) + 191 192 "OpSource GLSL 430\n" 193 "OpName %main \"main\"\n" 194 "OpName %id \"gl_GlobalInvocationID\"\n" 195 196 "OpDecorate %id BuiltIn GlobalInvocationId\n" 197 198 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) 199 200 + string(s_InputOutputBuffer) + 201 202 "%id = OpVariable %uvec3ptr Input\n" 203 "%zero = OpConstant %i32 0\n" 204 205 "%main = OpFunction %void None %voidf\n" 206 "%label = OpLabel\n" 207 "%idval = OpLoad %uvec3 %id\n" 208 "%x = OpCompositeExtract %u32 %idval 0\n" 209 210 " OpNop\n" // Inside a function body 211 212 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 213 "%inval = OpLoad %f32 %inloc\n" 214 "%neg = OpFNegate %f32 %inval\n" 215 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 216 " OpStore %outloc %neg\n" 217 " OpReturn\n" 218 " OpFunctionEnd\n"; 219 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 220 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 221 spec.numWorkGroups = IVec3(numElements, 1, 1); 222 223 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNop appearing at different places", spec)); 224 225 return group.release(); 226} 227 228tcu::TestCaseGroup* createOpLineGroup (tcu::TestContext& testCtx) 229{ 230 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opline", "Test the OpLine instruction")); 231 ComputeShaderSpec spec; 232 de::Random rnd (deStringHash(group->getName())); 233 const int numElements = 100; 234 vector<float> positiveFloats (numElements, 0); 235 vector<float> negativeFloats (numElements, 0); 236 237 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 238 239 for (size_t ndx = 0; ndx < numElements; ++ndx) 240 negativeFloats[ndx] = -positiveFloats[ndx]; 241 242 spec.assembly = 243 string(s_ShaderPreamble) + 244 245 "%fname1 = OpString \"negateInputs.comp\"\n" 246 "%fname2 = OpString \"negateInputs\"\n" 247 248 "OpSource GLSL 430\n" 249 "OpName %main \"main\"\n" 250 "OpName %id \"gl_GlobalInvocationID\"\n" 251 252 "OpDecorate %id BuiltIn GlobalInvocationId\n" 253 254 + string(s_InputOutputBufferTraits) + 255 256 "OpLine %fname1 0 0\n" // At the earliest possible position 257 258 + string(s_CommonTypes) + string(s_InputOutputBuffer) + 259 260 "OpLine %fname1 0 1\n" // Multiple OpLines in sequence 261 "OpLine %fname2 1 0\n" // Different filenames 262 "OpLine %fname1 1000 100000\n" 263 264 "%id = OpVariable %uvec3ptr Input\n" 265 "%zero = OpConstant %i32 0\n" 266 267 "OpLine %fname1 1 1\n" // Before a function 268 269 "%main = OpFunction %void None %voidf\n" 270 "%label = OpLabel\n" 271 272 "OpLine %fname1 1 1\n" // In a function 273 274 "%idval = OpLoad %uvec3 %id\n" 275 "%x = OpCompositeExtract %u32 %idval 0\n" 276 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 277 "%inval = OpLoad %f32 %inloc\n" 278 "%neg = OpFNegate %f32 %inval\n" 279 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 280 " OpStore %outloc %neg\n" 281 " OpReturn\n" 282 " OpFunctionEnd\n"; 283 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 284 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 285 spec.numWorkGroups = IVec3(numElements, 1, 1); 286 287 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpLine appearing at different places", spec)); 288 289 return group.release(); 290} 291 292tcu::TestCaseGroup* createOpNoLineGroup (tcu::TestContext& testCtx) 293{ 294 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opnoline", "Test the OpNoLine instruction")); 295 ComputeShaderSpec spec; 296 de::Random rnd (deStringHash(group->getName())); 297 const int numElements = 100; 298 vector<float> positiveFloats (numElements, 0); 299 vector<float> negativeFloats (numElements, 0); 300 301 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 302 303 for (size_t ndx = 0; ndx < numElements; ++ndx) 304 negativeFloats[ndx] = -positiveFloats[ndx]; 305 306 spec.assembly = 307 string(s_ShaderPreamble) + 308 309 "%fname = OpString \"negateInputs.comp\"\n" 310 311 "OpSource GLSL 430\n" 312 "OpName %main \"main\"\n" 313 "OpName %id \"gl_GlobalInvocationID\"\n" 314 315 "OpDecorate %id BuiltIn GlobalInvocationId\n" 316 317 + string(s_InputOutputBufferTraits) + 318 319 "OpNoLine\n" // At the earliest possible position, without preceding OpLine 320 321 + string(s_CommonTypes) + string(s_InputOutputBuffer) + 322 323 "OpLine %fname 0 1\n" 324 "OpNoLine\n" // Immediately following a preceding OpLine 325 326 "OpLine %fname 1000 1\n" 327 328 "%id = OpVariable %uvec3ptr Input\n" 329 "%zero = OpConstant %i32 0\n" 330 331 "OpNoLine\n" // Contents after the previous OpLine 332 333 "%main = OpFunction %void None %voidf\n" 334 "%label = OpLabel\n" 335 "%idval = OpLoad %uvec3 %id\n" 336 "%x = OpCompositeExtract %u32 %idval 0\n" 337 338 "OpNoLine\n" // Multiple OpNoLine 339 "OpNoLine\n" 340 "OpNoLine\n" 341 342 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 343 "%inval = OpLoad %f32 %inloc\n" 344 "%neg = OpFNegate %f32 %inval\n" 345 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 346 " OpStore %outloc %neg\n" 347 " OpReturn\n" 348 " OpFunctionEnd\n"; 349 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 350 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 351 spec.numWorkGroups = IVec3(numElements, 1, 1); 352 353 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpNoLine appearing at different places", spec)); 354 355 return group.release(); 356} 357 358tcu::TestCaseGroup* createNoContractionGroup (tcu::TestContext& testCtx) 359{ 360 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration")); 361 vector<CaseParameter> cases; 362 const int numElements = 100; 363 vector<float> inputFloats1 (numElements, 0); 364 vector<float> inputFloats2 (numElements, 0); 365 vector<float> outputFloats (numElements, 0); 366 const StringTemplate shaderTemplate ( 367 string(s_ShaderPreamble) + 368 369 "OpName %main \"main\"\n" 370 "OpName %id \"gl_GlobalInvocationID\"\n" 371 372 "OpDecorate %id BuiltIn GlobalInvocationId\n" 373 374 "${DECORATION}\n" 375 376 "OpDecorate %inbuf1 BufferBlock\n" 377 "OpDecorate %indata1 DescriptorSet 0\n" 378 "OpDecorate %indata1 Binding 0\n" 379 "OpDecorate %inbuf2 BufferBlock\n" 380 "OpDecorate %indata2 DescriptorSet 0\n" 381 "OpDecorate %indata2 Binding 1\n" 382 "OpDecorate %outbuf BufferBlock\n" 383 "OpDecorate %outdata DescriptorSet 0\n" 384 "OpDecorate %outdata Binding 2\n" 385 "OpDecorate %f32arr ArrayStride 4\n" 386 "OpMemberDecorate %inbuf1 0 Offset 0\n" 387 "OpMemberDecorate %inbuf2 0 Offset 0\n" 388 "OpMemberDecorate %outbuf 0 Offset 0\n" 389 390 + string(s_CommonTypes) + 391 392 "%inbuf1 = OpTypeStruct %f32arr\n" 393 "%inbufptr1 = OpTypePointer Uniform %inbuf1\n" 394 "%indata1 = OpVariable %inbufptr1 Uniform\n" 395 "%inbuf2 = OpTypeStruct %f32arr\n" 396 "%inbufptr2 = OpTypePointer Uniform %inbuf2\n" 397 "%indata2 = OpVariable %inbufptr2 Uniform\n" 398 "%outbuf = OpTypeStruct %f32arr\n" 399 "%outbufptr = OpTypePointer Uniform %outbuf\n" 400 "%outdata = OpVariable %outbufptr Uniform\n" 401 402 "%id = OpVariable %uvec3ptr Input\n" 403 "%zero = OpConstant %i32 0\n" 404 "%c_f_m1 = OpConstant %f32 -1.\n" 405 406 "%main = OpFunction %void None %voidf\n" 407 "%label = OpLabel\n" 408 "%idval = OpLoad %uvec3 %id\n" 409 "%x = OpCompositeExtract %u32 %idval 0\n" 410 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n" 411 "%inval1 = OpLoad %f32 %inloc1\n" 412 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n" 413 "%inval2 = OpLoad %f32 %inloc2\n" 414 "%mul = OpFMul %f32 %inval1 %inval2\n" 415 "%add = OpFAdd %f32 %mul %c_f_m1\n" 416 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 417 " OpStore %outloc %add\n" 418 " OpReturn\n" 419 " OpFunctionEnd\n"); 420 421 cases.push_back(CaseParameter("multiplication", "OpDecorate %mul NoContraction")); 422 cases.push_back(CaseParameter("addition", "OpDecorate %add NoContraction")); 423 cases.push_back(CaseParameter("both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction")); 424 425 for (size_t ndx = 0; ndx < numElements; ++ndx) 426 { 427 inputFloats1[ndx] = 1.f + std::ldexp(1.f, -23); // 1 + 2^-23. 428 inputFloats2[ndx] = 1.f - std::ldexp(1.f, -23); // 1 - 2^-23. 429 // Result for (1 + 2^-23) * (1 - 2^-23) - 1. With NoContraction, the multiplication will be 430 // conducted separately and the result is rounded to 1. So the final result will be 0.f. 431 // If the operation is combined into a precise fused multiply-add, then the result would be 432 // 2^-46 (0xa8800000). 433 outputFloats[ndx] = 0.f; 434 } 435 436 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 437 { 438 map<string, string> specializations; 439 ComputeShaderSpec spec; 440 441 specializations["DECORATION"] = cases[caseNdx].param; 442 spec.assembly = shaderTemplate.specialize(specializations); 443 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1))); 444 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2))); 445 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 446 spec.numWorkGroups = IVec3(numElements, 1, 1); 447 448 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 449 } 450 return group.release(); 451} 452 453tcu::TestCaseGroup* createOpFRemGroup (tcu::TestContext& testCtx) 454{ 455 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opfrem", "Test the OpFRem instruction")); 456 ComputeShaderSpec spec; 457 de::Random rnd (deStringHash(group->getName())); 458 const int numElements = 200; 459 vector<float> inputFloats1 (numElements, 0); 460 vector<float> inputFloats2 (numElements, 0); 461 vector<float> outputFloats (numElements, 0); 462 463 fillRandomScalars(rnd, -10000.f, 10000.f, &inputFloats1[0], numElements); 464 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats2[0], numElements); 465 466 for (size_t ndx = 0; ndx < numElements; ++ndx) 467 { 468 // Guard against divisors near zero. 469 if (std::fabs(inputFloats2[ndx]) < 1e-3) 470 inputFloats2[ndx] = 8.f; 471 472 // The return value of std::fmod() has the same sign as its first operand, which is how OpFRem spec'd. 473 outputFloats[ndx] = std::fmod(inputFloats1[ndx], inputFloats2[ndx]); 474 } 475 476 spec.assembly = 477 string(s_ShaderPreamble) + 478 479 "OpName %main \"main\"\n" 480 "OpName %id \"gl_GlobalInvocationID\"\n" 481 482 "OpDecorate %id BuiltIn GlobalInvocationId\n" 483 484 "OpDecorate %inbuf1 BufferBlock\n" 485 "OpDecorate %indata1 DescriptorSet 0\n" 486 "OpDecorate %indata1 Binding 0\n" 487 "OpDecorate %inbuf2 BufferBlock\n" 488 "OpDecorate %indata2 DescriptorSet 0\n" 489 "OpDecorate %indata2 Binding 1\n" 490 "OpDecorate %outbuf BufferBlock\n" 491 "OpDecorate %outdata DescriptorSet 0\n" 492 "OpDecorate %outdata Binding 2\n" 493 "OpDecorate %f32arr ArrayStride 4\n" 494 "OpMemberDecorate %inbuf1 0 Offset 0\n" 495 "OpMemberDecorate %inbuf2 0 Offset 0\n" 496 "OpMemberDecorate %outbuf 0 Offset 0\n" 497 498 + string(s_CommonTypes) + 499 500 "%inbuf1 = OpTypeStruct %f32arr\n" 501 "%inbufptr1 = OpTypePointer Uniform %inbuf1\n" 502 "%indata1 = OpVariable %inbufptr1 Uniform\n" 503 "%inbuf2 = OpTypeStruct %f32arr\n" 504 "%inbufptr2 = OpTypePointer Uniform %inbuf2\n" 505 "%indata2 = OpVariable %inbufptr2 Uniform\n" 506 "%outbuf = OpTypeStruct %f32arr\n" 507 "%outbufptr = OpTypePointer Uniform %outbuf\n" 508 "%outdata = OpVariable %outbufptr Uniform\n" 509 510 "%id = OpVariable %uvec3ptr Input\n" 511 "%zero = OpConstant %i32 0\n" 512 513 "%main = OpFunction %void None %voidf\n" 514 "%label = OpLabel\n" 515 "%idval = OpLoad %uvec3 %id\n" 516 "%x = OpCompositeExtract %u32 %idval 0\n" 517 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n" 518 "%inval1 = OpLoad %f32 %inloc1\n" 519 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n" 520 "%inval2 = OpLoad %f32 %inloc2\n" 521 "%rem = OpFRem %f32 %inval1 %inval2\n" 522 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 523 " OpStore %outloc %rem\n" 524 " OpReturn\n" 525 " OpFunctionEnd\n"; 526 527 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1))); 528 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2))); 529 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 530 spec.numWorkGroups = IVec3(numElements, 1, 1); 531 532 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "", spec)); 533 534 return group.release(); 535} 536 537// Copy contents in the input buffer to the output buffer. 538tcu::TestCaseGroup* createOpCopyMemoryGroup (tcu::TestContext& testCtx) 539{ 540 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopymemory", "Test the OpCopyMemory instruction")); 541 de::Random rnd (deStringHash(group->getName())); 542 const int numElements = 100; 543 544 // The following case adds vec4(0., 0.5, 1.5, 2.5) to each of the elements in the input buffer and writes output to the output buffer. 545 ComputeShaderSpec spec1; 546 vector<Vec4> inputFloats1 (numElements); 547 vector<Vec4> outputFloats1 (numElements); 548 549 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats1[0], numElements * 4); 550 551 for (size_t ndx = 0; ndx < numElements; ++ndx) 552 outputFloats1[ndx] = inputFloats1[ndx] + Vec4(0.f, 0.5f, 1.5f, 2.5f); 553 554 spec1.assembly = 555 string(s_ShaderPreamble) + 556 557 "OpName %main \"main\"\n" 558 "OpName %id \"gl_GlobalInvocationID\"\n" 559 560 "OpDecorate %id BuiltIn GlobalInvocationId\n" 561 562 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 563 564 "%vec4 = OpTypeVector %f32 4\n" 565 "%vec4ptr_u = OpTypePointer Uniform %vec4\n" 566 "%vec4ptr_f = OpTypePointer Function %vec4\n" 567 "%vec4arr = OpTypeRuntimeArray %vec4\n" 568 "%inbuf = OpTypeStruct %vec4arr\n" 569 "%inbufptr = OpTypePointer Uniform %inbuf\n" 570 "%indata = OpVariable %inbufptr Uniform\n" 571 "%outbuf = OpTypeStruct %vec4arr\n" 572 "%outbufptr = OpTypePointer Uniform %outbuf\n" 573 "%outdata = OpVariable %outbufptr Uniform\n" 574 575 "%id = OpVariable %uvec3ptr Input\n" 576 "%zero = OpConstant %i32 0\n" 577 "%c_f_0 = OpConstant %f32 0.\n" 578 "%c_f_0_5 = OpConstant %f32 0.5\n" 579 "%c_f_1_5 = OpConstant %f32 1.5\n" 580 "%c_f_2_5 = OpConstant %f32 2.5\n" 581 "%c_vec4 = OpConstantComposite %vec4 %c_f_0 %c_f_0_5 %c_f_1_5 %c_f_2_5\n" 582 583 "%main = OpFunction %void None %voidf\n" 584 "%label = OpLabel\n" 585 "%v_vec4 = OpVariable %vec4ptr_f Function\n" 586 "%idval = OpLoad %uvec3 %id\n" 587 "%x = OpCompositeExtract %u32 %idval 0\n" 588 "%inloc = OpAccessChain %vec4ptr_u %indata %zero %x\n" 589 "%outloc = OpAccessChain %vec4ptr_u %outdata %zero %x\n" 590 " OpCopyMemory %v_vec4 %inloc\n" 591 "%v_vec4_val = OpLoad %vec4 %v_vec4\n" 592 "%add = OpFAdd %vec4 %v_vec4_val %c_vec4\n" 593 " OpStore %outloc %add\n" 594 " OpReturn\n" 595 " OpFunctionEnd\n"; 596 597 spec1.inputs.push_back(BufferSp(new Vec4Buffer(inputFloats1))); 598 spec1.outputs.push_back(BufferSp(new Vec4Buffer(outputFloats1))); 599 spec1.numWorkGroups = IVec3(numElements, 1, 1); 600 601 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector", "OpCopyMemory elements of vector type", spec1)); 602 603 // The following case copies a float[100] variable from the input buffer to the output buffer. 604 ComputeShaderSpec spec2; 605 vector<float> inputFloats2 (numElements); 606 vector<float> outputFloats2 (numElements); 607 608 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats2[0], numElements); 609 610 for (size_t ndx = 0; ndx < numElements; ++ndx) 611 outputFloats2[ndx] = inputFloats2[ndx]; 612 613 spec2.assembly = 614 string(s_ShaderPreamble) + 615 616 "OpName %main \"main\"\n" 617 "OpName %id \"gl_GlobalInvocationID\"\n" 618 619 "OpDecorate %id BuiltIn GlobalInvocationId\n" 620 621 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 622 623 "%hundred = OpConstant %u32 100\n" 624 "%f32arr100 = OpTypeArray %f32 %hundred\n" 625 "%f32arr100ptr_f = OpTypePointer Function %f32arr100\n" 626 "%f32arr100ptr_u = OpTypePointer Uniform %f32arr100\n" 627 "%inbuf = OpTypeStruct %f32arr100\n" 628 "%inbufptr = OpTypePointer Uniform %inbuf\n" 629 "%indata = OpVariable %inbufptr Uniform\n" 630 "%outbuf = OpTypeStruct %f32arr100\n" 631 "%outbufptr = OpTypePointer Uniform %outbuf\n" 632 "%outdata = OpVariable %outbufptr Uniform\n" 633 634 "%id = OpVariable %uvec3ptr Input\n" 635 "%zero = OpConstant %i32 0\n" 636 637 "%main = OpFunction %void None %voidf\n" 638 "%label = OpLabel\n" 639 "%var = OpVariable %f32arr100ptr_f Function\n" 640 "%inarr = OpAccessChain %f32arr100ptr_u %indata %zero\n" 641 "%outarr = OpAccessChain %f32arr100ptr_u %outdata %zero\n" 642 " OpCopyMemory %var %inarr\n" 643 " OpCopyMemory %outarr %var\n" 644 " OpReturn\n" 645 " OpFunctionEnd\n"; 646 647 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2))); 648 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2))); 649 spec2.numWorkGroups = IVec3(1, 1, 1); 650 651 group->addChild(new SpvAsmComputeShaderCase(testCtx, "array", "OpCopyMemory elements of array type", spec2)); 652 653 // The following case copies a struct{vec4, vec4, vec4, vec4} variable from the input buffer to the output buffer. 654 ComputeShaderSpec spec3; 655 vector<float> inputFloats3 (16); 656 vector<float> outputFloats3 (16); 657 658 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats3[0], 16); 659 660 for (size_t ndx = 0; ndx < 16; ++ndx) 661 outputFloats3[ndx] = inputFloats3[ndx]; 662 663 spec3.assembly = 664 string(s_ShaderPreamble) + 665 666 "OpName %main \"main\"\n" 667 "OpName %id \"gl_GlobalInvocationID\"\n" 668 669 "OpDecorate %id BuiltIn GlobalInvocationId\n" 670 "OpMemberDecorate %inbuf 0 Offset 0\n" 671 "OpMemberDecorate %inbuf 1 Offset 16\n" 672 "OpMemberDecorate %inbuf 2 Offset 32\n" 673 "OpMemberDecorate %inbuf 3 Offset 48\n" 674 "OpMemberDecorate %outbuf 0 Offset 0\n" 675 "OpMemberDecorate %outbuf 1 Offset 16\n" 676 "OpMemberDecorate %outbuf 2 Offset 32\n" 677 "OpMemberDecorate %outbuf 3 Offset 48\n" 678 679 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 680 681 "%vec4 = OpTypeVector %f32 4\n" 682 "%inbuf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n" 683 "%inbufptr = OpTypePointer Uniform %inbuf\n" 684 "%indata = OpVariable %inbufptr Uniform\n" 685 "%outbuf = OpTypeStruct %vec4 %vec4 %vec4 %vec4\n" 686 "%outbufptr = OpTypePointer Uniform %outbuf\n" 687 "%outdata = OpVariable %outbufptr Uniform\n" 688 "%vec4stptr = OpTypePointer Function %inbuf\n" 689 690 "%id = OpVariable %uvec3ptr Input\n" 691 "%zero = OpConstant %i32 0\n" 692 693 "%main = OpFunction %void None %voidf\n" 694 "%label = OpLabel\n" 695 "%var = OpVariable %vec4stptr Function\n" 696 " OpCopyMemory %var %indata\n" 697 " OpCopyMemory %outdata %var\n" 698 " OpReturn\n" 699 " OpFunctionEnd\n"; 700 701 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3))); 702 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3))); 703 spec3.numWorkGroups = IVec3(1, 1, 1); 704 705 group->addChild(new SpvAsmComputeShaderCase(testCtx, "struct", "OpCopyMemory elements of struct type", spec3)); 706 707 // The following case negates multiple float variables from the input buffer and stores the results to the output buffer. 708 ComputeShaderSpec spec4; 709 vector<float> inputFloats4 (numElements); 710 vector<float> outputFloats4 (numElements); 711 712 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats4[0], numElements); 713 714 for (size_t ndx = 0; ndx < numElements; ++ndx) 715 outputFloats4[ndx] = -inputFloats4[ndx]; 716 717 spec4.assembly = 718 string(s_ShaderPreamble) + 719 720 "OpName %main \"main\"\n" 721 "OpName %id \"gl_GlobalInvocationID\"\n" 722 723 "OpDecorate %id BuiltIn GlobalInvocationId\n" 724 725 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 726 727 "%f32ptr_f = OpTypePointer Function %f32\n" 728 "%id = OpVariable %uvec3ptr Input\n" 729 "%zero = OpConstant %i32 0\n" 730 731 "%main = OpFunction %void None %voidf\n" 732 "%label = OpLabel\n" 733 "%var = OpVariable %f32ptr_f Function\n" 734 "%idval = OpLoad %uvec3 %id\n" 735 "%x = OpCompositeExtract %u32 %idval 0\n" 736 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 737 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 738 " OpCopyMemory %var %inloc\n" 739 "%val = OpLoad %f32 %var\n" 740 "%neg = OpFNegate %f32 %val\n" 741 " OpStore %outloc %neg\n" 742 " OpReturn\n" 743 " OpFunctionEnd\n"; 744 745 spec4.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4))); 746 spec4.outputs.push_back(BufferSp(new Float32Buffer(outputFloats4))); 747 spec4.numWorkGroups = IVec3(numElements, 1, 1); 748 749 group->addChild(new SpvAsmComputeShaderCase(testCtx, "float", "OpCopyMemory elements of float type", spec4)); 750 751 return group.release(); 752} 753 754tcu::TestCaseGroup* createOpCopyObjectGroup (tcu::TestContext& testCtx) 755{ 756 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opcopyobject", "Test the OpCopyObject instruction")); 757 ComputeShaderSpec spec; 758 de::Random rnd (deStringHash(group->getName())); 759 const int numElements = 100; 760 vector<float> inputFloats (numElements, 0); 761 vector<float> outputFloats (numElements, 0); 762 763 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements); 764 765 for (size_t ndx = 0; ndx < numElements; ++ndx) 766 outputFloats[ndx] = inputFloats[ndx] + 7.5f; 767 768 spec.assembly = 769 string(s_ShaderPreamble) + 770 771 "OpName %main \"main\"\n" 772 "OpName %id \"gl_GlobalInvocationID\"\n" 773 774 "OpDecorate %id BuiltIn GlobalInvocationId\n" 775 776 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 777 778 "%fvec3 = OpTypeVector %f32 3\n" 779 "%fmat = OpTypeMatrix %fvec3 3\n" 780 "%three = OpConstant %u32 3\n" 781 "%farr = OpTypeArray %f32 %three\n" 782 "%fst = OpTypeStruct %f32 %f32\n" 783 784 + string(s_InputOutputBuffer) + 785 786 "%id = OpVariable %uvec3ptr Input\n" 787 "%zero = OpConstant %i32 0\n" 788 "%c_f = OpConstant %f32 1.5\n" 789 "%c_fvec3 = OpConstantComposite %fvec3 %c_f %c_f %c_f\n" 790 "%c_fmat = OpConstantComposite %fmat %c_fvec3 %c_fvec3 %c_fvec3\n" 791 "%c_farr = OpConstantComposite %farr %c_f %c_f %c_f\n" 792 "%c_fst = OpConstantComposite %fst %c_f %c_f\n" 793 794 "%main = OpFunction %void None %voidf\n" 795 "%label = OpLabel\n" 796 "%c_f_copy = OpCopyObject %f32 %c_f\n" 797 "%c_fvec3_copy = OpCopyObject %fvec3 %c_fvec3\n" 798 "%c_fmat_copy = OpCopyObject %fmat %c_fmat\n" 799 "%c_farr_copy = OpCopyObject %farr %c_farr\n" 800 "%c_fst_copy = OpCopyObject %fst %c_fst\n" 801 "%fvec3_elem = OpCompositeExtract %f32 %c_fvec3_copy 0\n" 802 "%fmat_elem = OpCompositeExtract %f32 %c_fmat_copy 1 2\n" 803 "%farr_elem = OpCompositeExtract %f32 %c_fmat_copy 2\n" 804 "%fst_elem = OpCompositeExtract %f32 %c_fmat_copy 1\n" 805 // Add up. 1.5 * 5 = 7.5. 806 "%add1 = OpFAdd %f32 %c_f_copy %fvec3_elem\n" 807 "%add2 = OpFAdd %f32 %add1 %fmat_elem\n" 808 "%add3 = OpFAdd %f32 %add2 %farr_elem\n" 809 "%add4 = OpFAdd %f32 %add3 %fst_elem\n" 810 811 "%idval = OpLoad %uvec3 %id\n" 812 "%x = OpCompositeExtract %u32 %idval 0\n" 813 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 814 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 815 "%inval = OpLoad %f32 %inloc\n" 816 "%add = OpFAdd %f32 %add4 %inval\n" 817 " OpStore %outloc %add\n" 818 " OpReturn\n" 819 " OpFunctionEnd\n"; 820 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 821 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 822 spec.numWorkGroups = IVec3(numElements, 1, 1); 823 824 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "OpCopyObject on different types", spec)); 825 826 return group.release(); 827} 828// Assembly code used for testing OpUnreachable is based on GLSL source code: 829// 830// #version 430 831// 832// layout(std140, set = 0, binding = 0) readonly buffer Input { 833// float elements[]; 834// } input_data; 835// layout(std140, set = 0, binding = 1) writeonly buffer Output { 836// float elements[]; 837// } output_data; 838// 839// void not_called_func() { 840// // place OpUnreachable here 841// } 842// 843// uint modulo4(uint val) { 844// switch (val % uint(4)) { 845// case 0: return 3; 846// case 1: return 2; 847// case 2: return 1; 848// case 3: return 0; 849// default: return 100; // place OpUnreachable here 850// } 851// } 852// 853// uint const5() { 854// return 5; 855// // place OpUnreachable here 856// } 857// 858// void main() { 859// uint x = gl_GlobalInvocationID.x; 860// if (const5() > modulo4(1000)) { 861// output_data.elements[x] = -input_data.elements[x]; 862// } else { 863// // place OpUnreachable here 864// output_data.elements[x] = input_data.elements[x]; 865// } 866// } 867 868tcu::TestCaseGroup* createOpUnreachableGroup (tcu::TestContext& testCtx) 869{ 870 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opunreachable", "Test the OpUnreachable instruction")); 871 ComputeShaderSpec spec; 872 de::Random rnd (deStringHash(group->getName())); 873 const int numElements = 100; 874 vector<float> positiveFloats (numElements, 0); 875 vector<float> negativeFloats (numElements, 0); 876 877 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 878 879 for (size_t ndx = 0; ndx < numElements; ++ndx) 880 negativeFloats[ndx] = -positiveFloats[ndx]; 881 882 spec.assembly = 883 string(s_ShaderPreamble) + 884 885 "OpSource GLSL 430\n" 886 "OpName %main \"main\"\n" 887 "OpName %func_not_called_func \"not_called_func(\"\n" 888 "OpName %func_modulo4 \"modulo4(u1;\"\n" 889 "OpName %func_const5 \"const5(\"\n" 890 "OpName %id \"gl_GlobalInvocationID\"\n" 891 892 "OpDecorate %id BuiltIn GlobalInvocationId\n" 893 894 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 895 896 "%u32ptr = OpTypePointer Function %u32\n" 897 "%uintfuint = OpTypeFunction %u32 %u32ptr\n" 898 "%unitf = OpTypeFunction %u32\n" 899 900 "%id = OpVariable %uvec3ptr Input\n" 901 "%zero = OpConstant %u32 0\n" 902 "%one = OpConstant %u32 1\n" 903 "%two = OpConstant %u32 2\n" 904 "%three = OpConstant %u32 3\n" 905 "%four = OpConstant %u32 4\n" 906 "%five = OpConstant %u32 5\n" 907 "%hundred = OpConstant %u32 100\n" 908 "%thousand = OpConstant %u32 1000\n" 909 910 + string(s_InputOutputBuffer) + 911 912 // Main() 913 "%main = OpFunction %void None %voidf\n" 914 "%main_entry = OpLabel\n" 915 "%idval = OpLoad %uvec3 %id\n" 916 "%x = OpCompositeExtract %u32 %idval 0\n" 917 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 918 "%inval = OpLoad %f32 %inloc\n" 919 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 920 "%ret_const5 = OpFunctionCall %u32 %func_const5\n" 921 "%ret_modulo4 = OpFunctionCall %u32 %func_modulo4 %thousand\n" 922 "%cmp_gt = OpUGreaterThan %bool %ret_const5 %ret_modulo4\n" 923 " OpSelectionMerge %if_end None\n" 924 " OpBranchConditional %cmp_gt %if_true %if_false\n" 925 "%if_true = OpLabel\n" 926 "%negate = OpFNegate %f32 %inval\n" 927 " OpStore %outloc %negate\n" 928 " OpBranch %if_end\n" 929 "%if_false = OpLabel\n" 930 " OpUnreachable\n" // Unreachable else branch for if statement 931 "%if_end = OpLabel\n" 932 " OpReturn\n" 933 " OpFunctionEnd\n" 934 935 // not_called_function() 936 "%func_not_called_func = OpFunction %void None %voidf\n" 937 "%not_called_func_entry = OpLabel\n" 938 " OpUnreachable\n" // Unreachable entry block in not called static function 939 " OpFunctionEnd\n" 940 941 // modulo4() 942 "%func_modulo4 = OpFunction %u32 None %uintfuint\n" 943 "%valptr = OpFunctionParameter %u32ptr\n" 944 "%modulo4_entry = OpLabel\n" 945 "%val = OpLoad %u32 %valptr\n" 946 "%modulo = OpUMod %u32 %val %four\n" 947 " OpSelectionMerge %switch_merge None\n" 948 " OpSwitch %modulo %default 0 %case0 1 %case1 2 %case2 3 %case3\n" 949 "%case0 = OpLabel\n" 950 " OpReturnValue %three\n" 951 "%case1 = OpLabel\n" 952 " OpReturnValue %two\n" 953 "%case2 = OpLabel\n" 954 " OpReturnValue %one\n" 955 "%case3 = OpLabel\n" 956 " OpReturnValue %zero\n" 957 "%default = OpLabel\n" 958 " OpUnreachable\n" // Unreachable default case for switch statement 959 "%switch_merge = OpLabel\n" 960 " OpUnreachable\n" // Unreachable merge block for switch statement 961 " OpFunctionEnd\n" 962 963 // const5() 964 "%func_const5 = OpFunction %u32 None %unitf\n" 965 "%const5_entry = OpLabel\n" 966 " OpReturnValue %five\n" 967 "%unreachable = OpLabel\n" 968 " OpUnreachable\n" // Unreachable block in function 969 " OpFunctionEnd\n"; 970 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 971 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 972 spec.numWorkGroups = IVec3(numElements, 1, 1); 973 974 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "OpUnreachable appearing at different places", spec)); 975 976 return group.release(); 977} 978 979// Assembly code used for testing decoration group is based on GLSL source code: 980// 981// #version 430 982// 983// layout(std140, set = 0, binding = 0) readonly buffer Input0 { 984// float elements[]; 985// } input_data0; 986// layout(std140, set = 0, binding = 1) readonly buffer Input1 { 987// float elements[]; 988// } input_data1; 989// layout(std140, set = 0, binding = 2) readonly buffer Input2 { 990// float elements[]; 991// } input_data2; 992// layout(std140, set = 0, binding = 3) readonly buffer Input3 { 993// float elements[]; 994// } input_data3; 995// layout(std140, set = 0, binding = 4) readonly buffer Input4 { 996// float elements[]; 997// } input_data4; 998// layout(std140, set = 0, binding = 5) writeonly buffer Output { 999// float elements[]; 1000// } output_data; 1001// 1002// void main() { 1003// uint x = gl_GlobalInvocationID.x; 1004// output_data.elements[x] = input_data0.elements[x] + input_data1.elements[x] + input_data2.elements[x] + input_data3.elements[x] + input_data4.elements[x]; 1005// } 1006tcu::TestCaseGroup* createDecorationGroupGroup (tcu::TestContext& testCtx) 1007{ 1008 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Test the OpDecorationGroup & OpGroupDecorate instruction")); 1009 ComputeShaderSpec spec; 1010 de::Random rnd (deStringHash(group->getName())); 1011 const int numElements = 100; 1012 vector<float> inputFloats0 (numElements, 0); 1013 vector<float> inputFloats1 (numElements, 0); 1014 vector<float> inputFloats2 (numElements, 0); 1015 vector<float> inputFloats3 (numElements, 0); 1016 vector<float> inputFloats4 (numElements, 0); 1017 vector<float> outputFloats (numElements, 0); 1018 1019 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats0[0], numElements); 1020 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats1[0], numElements); 1021 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats2[0], numElements); 1022 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats3[0], numElements); 1023 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats4[0], numElements); 1024 1025 for (size_t ndx = 0; ndx < numElements; ++ndx) 1026 outputFloats[ndx] = inputFloats0[ndx] + inputFloats1[ndx] + inputFloats2[ndx] + inputFloats3[ndx] + inputFloats4[ndx]; 1027 1028 spec.assembly = 1029 string(s_ShaderPreamble) + 1030 1031 "OpSource GLSL 430\n" 1032 "OpName %main \"main\"\n" 1033 "OpName %id \"gl_GlobalInvocationID\"\n" 1034 1035 // Not using group decoration on variable. 1036 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1037 // Not using group decoration on type. 1038 "OpDecorate %f32arr ArrayStride 4\n" 1039 1040 "OpDecorate %groups BufferBlock\n" 1041 "OpDecorate %groupm Offset 0\n" 1042 "%groups = OpDecorationGroup\n" 1043 "%groupm = OpDecorationGroup\n" 1044 1045 // Group decoration on multiple structs. 1046 "OpGroupDecorate %groups %outbuf %inbuf0 %inbuf1 %inbuf2 %inbuf3 %inbuf4\n" 1047 // Group decoration on multiple struct members. 1048 "OpGroupMemberDecorate %groupm %outbuf 0 %inbuf0 0 %inbuf1 0 %inbuf2 0 %inbuf3 0 %inbuf4 0\n" 1049 1050 "OpDecorate %group1 DescriptorSet 0\n" 1051 "OpDecorate %group3 DescriptorSet 0\n" 1052 "OpDecorate %group3 NonWritable\n" 1053 "OpDecorate %group3 Restrict\n" 1054 "%group0 = OpDecorationGroup\n" 1055 "%group1 = OpDecorationGroup\n" 1056 "%group3 = OpDecorationGroup\n" 1057 1058 // Applying the same decoration group multiple times. 1059 "OpGroupDecorate %group1 %outdata\n" 1060 "OpGroupDecorate %group1 %outdata\n" 1061 "OpGroupDecorate %group1 %outdata\n" 1062 "OpDecorate %outdata DescriptorSet 0\n" 1063 "OpDecorate %outdata Binding 5\n" 1064 // Applying decoration group containing nothing. 1065 "OpGroupDecorate %group0 %indata0\n" 1066 "OpDecorate %indata0 DescriptorSet 0\n" 1067 "OpDecorate %indata0 Binding 0\n" 1068 // Applying decoration group containing one decoration. 1069 "OpGroupDecorate %group1 %indata1\n" 1070 "OpDecorate %indata1 Binding 1\n" 1071 // Applying decoration group containing multiple decorations. 1072 "OpGroupDecorate %group3 %indata2 %indata3\n" 1073 "OpDecorate %indata2 Binding 2\n" 1074 "OpDecorate %indata3 Binding 3\n" 1075 // Applying multiple decoration groups (with overlapping). 1076 "OpGroupDecorate %group0 %indata4\n" 1077 "OpGroupDecorate %group1 %indata4\n" 1078 "OpGroupDecorate %group3 %indata4\n" 1079 "OpDecorate %indata4 Binding 4\n" 1080 1081 + string(s_CommonTypes) + 1082 1083 "%id = OpVariable %uvec3ptr Input\n" 1084 "%zero = OpConstant %i32 0\n" 1085 1086 "%outbuf = OpTypeStruct %f32arr\n" 1087 "%outbufptr = OpTypePointer Uniform %outbuf\n" 1088 "%outdata = OpVariable %outbufptr Uniform\n" 1089 "%inbuf0 = OpTypeStruct %f32arr\n" 1090 "%inbuf0ptr = OpTypePointer Uniform %inbuf0\n" 1091 "%indata0 = OpVariable %inbuf0ptr Uniform\n" 1092 "%inbuf1 = OpTypeStruct %f32arr\n" 1093 "%inbuf1ptr = OpTypePointer Uniform %inbuf1\n" 1094 "%indata1 = OpVariable %inbuf1ptr Uniform\n" 1095 "%inbuf2 = OpTypeStruct %f32arr\n" 1096 "%inbuf2ptr = OpTypePointer Uniform %inbuf2\n" 1097 "%indata2 = OpVariable %inbuf2ptr Uniform\n" 1098 "%inbuf3 = OpTypeStruct %f32arr\n" 1099 "%inbuf3ptr = OpTypePointer Uniform %inbuf3\n" 1100 "%indata3 = OpVariable %inbuf3ptr Uniform\n" 1101 "%inbuf4 = OpTypeStruct %f32arr\n" 1102 "%inbufptr = OpTypePointer Uniform %inbuf4\n" 1103 "%indata4 = OpVariable %inbufptr Uniform\n" 1104 1105 "%main = OpFunction %void None %voidf\n" 1106 "%label = OpLabel\n" 1107 "%idval = OpLoad %uvec3 %id\n" 1108 "%x = OpCompositeExtract %u32 %idval 0\n" 1109 "%inloc0 = OpAccessChain %f32ptr %indata0 %zero %x\n" 1110 "%inloc1 = OpAccessChain %f32ptr %indata1 %zero %x\n" 1111 "%inloc2 = OpAccessChain %f32ptr %indata2 %zero %x\n" 1112 "%inloc3 = OpAccessChain %f32ptr %indata3 %zero %x\n" 1113 "%inloc4 = OpAccessChain %f32ptr %indata4 %zero %x\n" 1114 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1115 "%inval0 = OpLoad %f32 %inloc0\n" 1116 "%inval1 = OpLoad %f32 %inloc1\n" 1117 "%inval2 = OpLoad %f32 %inloc2\n" 1118 "%inval3 = OpLoad %f32 %inloc3\n" 1119 "%inval4 = OpLoad %f32 %inloc4\n" 1120 "%add0 = OpFAdd %f32 %inval0 %inval1\n" 1121 "%add1 = OpFAdd %f32 %add0 %inval2\n" 1122 "%add2 = OpFAdd %f32 %add1 %inval3\n" 1123 "%add = OpFAdd %f32 %add2 %inval4\n" 1124 " OpStore %outloc %add\n" 1125 " OpReturn\n" 1126 " OpFunctionEnd\n"; 1127 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats0))); 1128 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats1))); 1129 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats2))); 1130 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats3))); 1131 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats4))); 1132 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 1133 spec.numWorkGroups = IVec3(numElements, 1, 1); 1134 1135 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "decoration group cases", spec)); 1136 1137 return group.release(); 1138} 1139 1140struct SpecConstantTwoIntCase 1141{ 1142 const char* caseName; 1143 const char* scDefinition0; 1144 const char* scDefinition1; 1145 const char* scResultType; 1146 const char* scOperation; 1147 deInt32 scActualValue0; 1148 deInt32 scActualValue1; 1149 const char* resultOperation; 1150 vector<deInt32> expectedOutput; 1151 1152 SpecConstantTwoIntCase (const char* name, 1153 const char* definition0, 1154 const char* definition1, 1155 const char* resultType, 1156 const char* operation, 1157 deInt32 value0, 1158 deInt32 value1, 1159 const char* resultOp, 1160 const vector<deInt32>& output) 1161 : caseName (name) 1162 , scDefinition0 (definition0) 1163 , scDefinition1 (definition1) 1164 , scResultType (resultType) 1165 , scOperation (operation) 1166 , scActualValue0 (value0) 1167 , scActualValue1 (value1) 1168 , resultOperation (resultOp) 1169 , expectedOutput (output) {} 1170}; 1171 1172tcu::TestCaseGroup* createSpecConstantGroup (tcu::TestContext& testCtx) 1173{ 1174 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction")); 1175 vector<SpecConstantTwoIntCase> cases; 1176 de::Random rnd (deStringHash(group->getName())); 1177 const int numElements = 100; 1178 vector<deInt32> inputInts (numElements, 0); 1179 vector<deInt32> outputInts1 (numElements, 0); 1180 vector<deInt32> outputInts2 (numElements, 0); 1181 vector<deInt32> outputInts3 (numElements, 0); 1182 vector<deInt32> outputInts4 (numElements, 0); 1183 const StringTemplate shaderTemplate ( 1184 string(s_ShaderPreamble) + 1185 1186 "OpName %main \"main\"\n" 1187 "OpName %id \"gl_GlobalInvocationID\"\n" 1188 1189 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1190 "OpDecorate %sc_0 SpecId 0\n" 1191 "OpDecorate %sc_1 SpecId 1\n" 1192 1193 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 1194 1195 "%i32ptr = OpTypePointer Uniform %i32\n" 1196 "%i32arr = OpTypeRuntimeArray %i32\n" 1197 "%boolptr = OpTypePointer Uniform %bool\n" 1198 "%boolarr = OpTypeRuntimeArray %bool\n" 1199 "%inbuf = OpTypeStruct %i32arr\n" 1200 "%inbufptr = OpTypePointer Uniform %inbuf\n" 1201 "%indata = OpVariable %inbufptr Uniform\n" 1202 "%outbuf = OpTypeStruct %i32arr\n" 1203 "%outbufptr = OpTypePointer Uniform %outbuf\n" 1204 "%outdata = OpVariable %outbufptr Uniform\n" 1205 1206 "%id = OpVariable %uvec3ptr Input\n" 1207 "%zero = OpConstant %i32 0\n" 1208 1209 "%sc_0 = OpSpecConstant${SC_DEF0}\n" 1210 "%sc_1 = OpSpecConstant${SC_DEF1}\n" 1211 "%sc_final = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n" 1212 1213 "%main = OpFunction %void None %voidf\n" 1214 "%label = OpLabel\n" 1215 "%idval = OpLoad %uvec3 %id\n" 1216 "%x = OpCompositeExtract %u32 %idval 0\n" 1217 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n" 1218 "%inval = OpLoad %i32 %inloc\n" 1219 "%final = ${GEN_RESULT}\n" 1220 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n" 1221 " OpStore %outloc %final\n" 1222 " OpReturn\n" 1223 " OpFunctionEnd\n"); 1224 1225 fillRandomScalars(rnd, -65536, 65536, &inputInts[0], numElements); 1226 1227 for (size_t ndx = 0; ndx < numElements; ++ndx) 1228 { 1229 outputInts1[ndx] = inputInts[ndx] + 42; 1230 outputInts2[ndx] = inputInts[ndx]; 1231 outputInts3[ndx] = inputInts[ndx] - 11200; 1232 outputInts4[ndx] = inputInts[ndx] + 1; 1233 } 1234 1235 const char addScToInput[] = "OpIAdd %i32 %inval %sc_final"; 1236 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_final %inval %zero"; 1237 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_final %zero %inval"; 1238 1239 cases.push_back(SpecConstantTwoIntCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 62, -20, addScToInput, outputInts1)); 1240 cases.push_back(SpecConstantTwoIntCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 100, 58, addScToInput, outputInts1)); 1241 cases.push_back(SpecConstantTwoIntCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -2, -21, addScToInput, outputInts1)); 1242 cases.push_back(SpecConstantTwoIntCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, -3, addScToInput, outputInts1)); 1243 cases.push_back(SpecConstantTwoIntCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 3, addScToInput, outputInts1)); 1244 cases.push_back(SpecConstantTwoIntCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 7, 3, addScToInput, outputInts4)); 1245 cases.push_back(SpecConstantTwoIntCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 7, 3, addScToInput, outputInts4)); 1246 cases.push_back(SpecConstantTwoIntCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 342, 50, addScToInput, outputInts1)); 1247 cases.push_back(SpecConstantTwoIntCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 42, 63, addScToInput, outputInts1)); 1248 cases.push_back(SpecConstantTwoIntCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 34, 8, addScToInput, outputInts1)); 1249 cases.push_back(SpecConstantTwoIntCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseXor %sc_0 %sc_1", 18, 56, addScToInput, outputInts1)); 1250 cases.push_back(SpecConstantTwoIntCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 168, 2, addScToInput, outputInts1)); 1251 cases.push_back(SpecConstantTwoIntCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", 168, 2, addScToInput, outputInts1)); 1252 cases.push_back(SpecConstantTwoIntCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 21, 1, addScToInput, outputInts1)); 1253 cases.push_back(SpecConstantTwoIntCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputInts2)); 1254 cases.push_back(SpecConstantTwoIntCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputInts2)); 1255 cases.push_back(SpecConstantTwoIntCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2)); 1256 cases.push_back(SpecConstantTwoIntCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputInts2)); 1257 cases.push_back(SpecConstantTwoIntCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputInts2)); 1258 cases.push_back(SpecConstantTwoIntCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputInts2)); 1259 cases.push_back(SpecConstantTwoIntCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputInts2)); 1260 cases.push_back(SpecConstantTwoIntCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputInts2)); 1261 cases.push_back(SpecConstantTwoIntCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputInts2)); 1262 cases.push_back(SpecConstantTwoIntCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2)); 1263 cases.push_back(SpecConstantTwoIntCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2)); 1264 cases.push_back(SpecConstantTwoIntCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputInts2)); 1265 cases.push_back(SpecConstantTwoIntCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputInts2)); 1266 cases.push_back(SpecConstantTwoIntCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -42, 0, addScToInput, outputInts1)); 1267 cases.push_back(SpecConstantTwoIntCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -43, 0, addScToInput, outputInts1)); 1268 cases.push_back(SpecConstantTwoIntCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputInts2)); 1269 cases.push_back(SpecConstantTwoIntCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %zero", 1, 42, addScToInput, outputInts1)); 1270 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths. 1271 1272 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 1273 { 1274 map<string, string> specializations; 1275 ComputeShaderSpec spec; 1276 1277 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0; 1278 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1; 1279 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType; 1280 specializations["SC_OP"] = cases[caseNdx].scOperation; 1281 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation; 1282 1283 spec.assembly = shaderTemplate.specialize(specializations); 1284 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts))); 1285 spec.outputs.push_back(BufferSp(new Int32Buffer(cases[caseNdx].expectedOutput))); 1286 spec.numWorkGroups = IVec3(numElements, 1, 1); 1287 spec.specConstants.push_back(cases[caseNdx].scActualValue0); 1288 spec.specConstants.push_back(cases[caseNdx].scActualValue1); 1289 1290 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].caseName, cases[caseNdx].caseName, spec)); 1291 } 1292 1293 ComputeShaderSpec spec; 1294 1295 spec.assembly = 1296 string(s_ShaderPreamble) + 1297 1298 "OpName %main \"main\"\n" 1299 "OpName %id \"gl_GlobalInvocationID\"\n" 1300 1301 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1302 "OpDecorate %sc_0 SpecId 0\n" 1303 "OpDecorate %sc_1 SpecId 1\n" 1304 "OpDecorate %sc_2 SpecId 2\n" 1305 1306 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 1307 1308 "%ivec3 = OpTypeVector %i32 3\n" 1309 "%i32ptr = OpTypePointer Uniform %i32\n" 1310 "%i32arr = OpTypeRuntimeArray %i32\n" 1311 "%boolptr = OpTypePointer Uniform %bool\n" 1312 "%boolarr = OpTypeRuntimeArray %bool\n" 1313 "%inbuf = OpTypeStruct %i32arr\n" 1314 "%inbufptr = OpTypePointer Uniform %inbuf\n" 1315 "%indata = OpVariable %inbufptr Uniform\n" 1316 "%outbuf = OpTypeStruct %i32arr\n" 1317 "%outbufptr = OpTypePointer Uniform %outbuf\n" 1318 "%outdata = OpVariable %outbufptr Uniform\n" 1319 1320 "%id = OpVariable %uvec3ptr Input\n" 1321 "%zero = OpConstant %i32 0\n" 1322 "%ivec3_0 = OpConstantComposite %ivec3 %zero %zero %zero\n" 1323 1324 "%sc_0 = OpSpecConstant %i32 0\n" 1325 "%sc_1 = OpSpecConstant %i32 0\n" 1326 "%sc_2 = OpSpecConstant %i32 0\n" 1327 "%sc_vec3_0 = OpSpecConstantOp %ivec3 CompositeInsert %sc_0 %ivec3_0 0\n" // (sc_0, 0, 0) 1328 "%sc_vec3_1 = OpSpecConstantOp %ivec3 CompositeInsert %sc_1 %ivec3_0 1\n" // (0, sc_1, 0) 1329 "%sc_vec3_2 = OpSpecConstantOp %ivec3 CompositeInsert %sc_2 %ivec3_0 2\n" // (0, 0, sc_2) 1330 "%sc_vec3_01 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1) 1331 "%sc_vec3_012 = OpSpecConstantOp %ivec3 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1) 1332 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2 1333 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0 1334 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1 1335 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0) 1336 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n" // (sc_2 - sc_0) * sc_1 1337 1338 "%main = OpFunction %void None %voidf\n" 1339 "%label = OpLabel\n" 1340 "%idval = OpLoad %uvec3 %id\n" 1341 "%x = OpCompositeExtract %u32 %idval 0\n" 1342 "%inloc = OpAccessChain %i32ptr %indata %zero %x\n" 1343 "%inval = OpLoad %i32 %inloc\n" 1344 "%final = OpIAdd %i32 %inval %sc_final\n" 1345 "%outloc = OpAccessChain %i32ptr %outdata %zero %x\n" 1346 " OpStore %outloc %final\n" 1347 " OpReturn\n" 1348 " OpFunctionEnd\n"; 1349 spec.inputs.push_back(BufferSp(new Int32Buffer(inputInts))); 1350 spec.outputs.push_back(BufferSp(new Int32Buffer(outputInts3))); 1351 spec.numWorkGroups = IVec3(numElements, 1, 1); 1352 spec.specConstants.push_back(123); 1353 spec.specConstants.push_back(56); 1354 spec.specConstants.push_back(-77); 1355 1356 group->addChild(new SpvAsmComputeShaderCase(testCtx, "vector_related", "VectorShuffle, CompositeExtract, & CompositeInsert", spec)); 1357 1358 return group.release(); 1359} 1360 1361tcu::TestCaseGroup* createOpPhiGroup (tcu::TestContext& testCtx) 1362{ 1363 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction")); 1364 ComputeShaderSpec spec1; 1365 ComputeShaderSpec spec2; 1366 ComputeShaderSpec spec3; 1367 de::Random rnd (deStringHash(group->getName())); 1368 const int numElements = 100; 1369 vector<float> inputFloats (numElements, 0); 1370 vector<float> outputFloats1 (numElements, 0); 1371 vector<float> outputFloats2 (numElements, 0); 1372 vector<float> outputFloats3 (numElements, 0); 1373 1374 fillRandomScalars(rnd, -300.f, 300.f, &inputFloats[0], numElements); 1375 1376 for (size_t ndx = 0; ndx < numElements; ++ndx) 1377 { 1378 switch (ndx % 3) 1379 { 1380 case 0: outputFloats1[ndx] = inputFloats[ndx] + 5.5f; break; 1381 case 1: outputFloats1[ndx] = inputFloats[ndx] + 20.5f; break; 1382 case 2: outputFloats1[ndx] = inputFloats[ndx] + 1.75f; break; 1383 default: break; 1384 } 1385 outputFloats2[ndx] = inputFloats[ndx] + 6.5f * 3; 1386 outputFloats3[ndx] = 8.5f - inputFloats[ndx]; 1387 } 1388 1389 spec1.assembly = 1390 string(s_ShaderPreamble) + 1391 1392 "OpSource GLSL 430\n" 1393 "OpName %main \"main\"\n" 1394 "OpName %id \"gl_GlobalInvocationID\"\n" 1395 1396 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1397 1398 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1399 1400 "%id = OpVariable %uvec3ptr Input\n" 1401 "%zero = OpConstant %i32 0\n" 1402 "%three = OpConstant %u32 3\n" 1403 "%constf5p5 = OpConstant %f32 5.5\n" 1404 "%constf20p5 = OpConstant %f32 20.5\n" 1405 "%constf1p75 = OpConstant %f32 1.75\n" 1406 "%constf8p5 = OpConstant %f32 8.5\n" 1407 "%constf6p5 = OpConstant %f32 6.5\n" 1408 1409 "%main = OpFunction %void None %voidf\n" 1410 "%entry = OpLabel\n" 1411 "%idval = OpLoad %uvec3 %id\n" 1412 "%x = OpCompositeExtract %u32 %idval 0\n" 1413 "%selector = OpUMod %u32 %x %three\n" 1414 " OpSelectionMerge %phi None\n" 1415 " OpSwitch %selector %default 0 %case0 1 %case1 2 %case2\n" 1416 1417 // Case 1 before OpPhi. 1418 "%case1 = OpLabel\n" 1419 " OpBranch %phi\n" 1420 1421 "%default = OpLabel\n" 1422 " OpUnreachable\n" 1423 1424 "%phi = OpLabel\n" 1425 "%operand = OpPhi %f32 %constf1p75 %case2 %constf20p5 %case1 %constf5p5 %case0\n" // not in the order of blocks 1426 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 1427 "%inval = OpLoad %f32 %inloc\n" 1428 "%add = OpFAdd %f32 %inval %operand\n" 1429 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1430 " OpStore %outloc %add\n" 1431 " OpReturn\n" 1432 1433 // Case 0 after OpPhi. 1434 "%case0 = OpLabel\n" 1435 " OpBranch %phi\n" 1436 1437 1438 // Case 2 after OpPhi. 1439 "%case2 = OpLabel\n" 1440 " OpBranch %phi\n" 1441 1442 " OpFunctionEnd\n"; 1443 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1444 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1))); 1445 spec1.numWorkGroups = IVec3(numElements, 1, 1); 1446 1447 group->addChild(new SpvAsmComputeShaderCase(testCtx, "block", "out-of-order and unreachable blocks for OpPhi", spec1)); 1448 1449 spec2.assembly = 1450 string(s_ShaderPreamble) + 1451 1452 "OpName %main \"main\"\n" 1453 "OpName %id \"gl_GlobalInvocationID\"\n" 1454 1455 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1456 1457 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1458 1459 "%id = OpVariable %uvec3ptr Input\n" 1460 "%zero = OpConstant %i32 0\n" 1461 "%one = OpConstant %i32 1\n" 1462 "%three = OpConstant %i32 3\n" 1463 "%constf6p5 = OpConstant %f32 6.5\n" 1464 1465 "%main = OpFunction %void None %voidf\n" 1466 "%entry = OpLabel\n" 1467 "%idval = OpLoad %uvec3 %id\n" 1468 "%x = OpCompositeExtract %u32 %idval 0\n" 1469 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 1470 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1471 "%inval = OpLoad %f32 %inloc\n" 1472 " OpBranch %phi\n" 1473 1474 "%phi = OpLabel\n" 1475 "%step = OpPhi %i32 %zero %entry %step_next %phi\n" 1476 "%accum = OpPhi %f32 %inval %entry %accum_next %phi\n" 1477 "%step_next = OpIAdd %i32 %step %one\n" 1478 "%accum_next = OpFAdd %f32 %accum %constf6p5\n" 1479 "%still_loop = OpSLessThan %bool %step %three\n" 1480 " OpLoopMerge %exit %phi None\n" 1481 " OpBranchConditional %still_loop %phi %exit\n" 1482 1483 "%exit = OpLabel\n" 1484 " OpStore %outloc %accum\n" 1485 " OpReturn\n" 1486 " OpFunctionEnd\n"; 1487 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1488 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2))); 1489 spec2.numWorkGroups = IVec3(numElements, 1, 1); 1490 1491 group->addChild(new SpvAsmComputeShaderCase(testCtx, "induction", "The usual way induction variables are handled in LLVM IR", spec2)); 1492 1493 spec3.assembly = 1494 string(s_ShaderPreamble) + 1495 1496 "OpName %main \"main\"\n" 1497 "OpName %id \"gl_GlobalInvocationID\"\n" 1498 1499 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1500 1501 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1502 1503 "%f32ptr_f = OpTypePointer Function %f32\n" 1504 "%id = OpVariable %uvec3ptr Input\n" 1505 "%true = OpConstantTrue %bool\n" 1506 "%false = OpConstantFalse %bool\n" 1507 "%zero = OpConstant %i32 0\n" 1508 "%constf8p5 = OpConstant %f32 8.5\n" 1509 1510 "%main = OpFunction %void None %voidf\n" 1511 "%entry = OpLabel\n" 1512 "%b = OpVariable %f32ptr_f Function %constf8p5\n" 1513 "%idval = OpLoad %uvec3 %id\n" 1514 "%x = OpCompositeExtract %u32 %idval 0\n" 1515 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 1516 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1517 "%a_init = OpLoad %f32 %inloc\n" 1518 "%b_init = OpLoad %f32 %b\n" 1519 " OpBranch %phi\n" 1520 1521 "%phi = OpLabel\n" 1522 "%still_loop = OpPhi %bool %true %entry %false %phi\n" 1523 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n" 1524 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n" 1525 " OpLoopMerge %exit %phi None\n" 1526 " OpBranchConditional %still_loop %phi %exit\n" 1527 1528 "%exit = OpLabel\n" 1529 "%sub = OpFSub %f32 %a_next %b_next\n" 1530 " OpStore %outloc %sub\n" 1531 " OpReturn\n" 1532 " OpFunctionEnd\n"; 1533 spec3.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1534 spec3.outputs.push_back(BufferSp(new Float32Buffer(outputFloats3))); 1535 spec3.numWorkGroups = IVec3(numElements, 1, 1); 1536 1537 group->addChild(new SpvAsmComputeShaderCase(testCtx, "swap", "Swap the values of two variables using OpPhi", spec3)); 1538 1539 return group.release(); 1540} 1541 1542// Assembly code used for testing block order is based on GLSL source code: 1543// 1544// #version 430 1545// 1546// layout(std140, set = 0, binding = 0) readonly buffer Input { 1547// float elements[]; 1548// } input_data; 1549// layout(std140, set = 0, binding = 1) writeonly buffer Output { 1550// float elements[]; 1551// } output_data; 1552// 1553// void main() { 1554// uint x = gl_GlobalInvocationID.x; 1555// output_data.elements[x] = input_data.elements[x]; 1556// if (x > uint(50)) { 1557// switch (x % uint(3)) { 1558// case 0: output_data.elements[x] += 1.5f; break; 1559// case 1: output_data.elements[x] += 42.f; break; 1560// case 2: output_data.elements[x] -= 27.f; break; 1561// default: break; 1562// } 1563// } else { 1564// output_data.elements[x] = -input_data.elements[x]; 1565// } 1566// } 1567tcu::TestCaseGroup* createBlockOrderGroup (tcu::TestContext& testCtx) 1568{ 1569 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "block_order", "Test block orders")); 1570 ComputeShaderSpec spec; 1571 de::Random rnd (deStringHash(group->getName())); 1572 const int numElements = 100; 1573 vector<float> inputFloats (numElements, 0); 1574 vector<float> outputFloats (numElements, 0); 1575 1576 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements); 1577 1578 for (size_t ndx = 0; ndx <= 50; ++ndx) 1579 outputFloats[ndx] = -inputFloats[ndx]; 1580 1581 for (size_t ndx = 51; ndx < numElements; ++ndx) 1582 { 1583 switch (ndx % 3) 1584 { 1585 case 0: outputFloats[ndx] = inputFloats[ndx] + 1.5f; break; 1586 case 1: outputFloats[ndx] = inputFloats[ndx] + 42.f; break; 1587 case 2: outputFloats[ndx] = inputFloats[ndx] - 27.f; break; 1588 default: break; 1589 } 1590 } 1591 1592 spec.assembly = 1593 string(s_ShaderPreamble) + 1594 1595 "OpSource GLSL 430\n" 1596 "OpName %main \"main\"\n" 1597 "OpName %id \"gl_GlobalInvocationID\"\n" 1598 1599 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1600 1601 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 1602 1603 "%u32ptr = OpTypePointer Function %u32\n" 1604 "%u32ptr_input = OpTypePointer Input %u32\n" 1605 1606 + string(s_InputOutputBuffer) + 1607 1608 "%id = OpVariable %uvec3ptr Input\n" 1609 "%zero = OpConstant %i32 0\n" 1610 "%const3 = OpConstant %u32 3\n" 1611 "%const50 = OpConstant %u32 50\n" 1612 "%constf1p5 = OpConstant %f32 1.5\n" 1613 "%constf27 = OpConstant %f32 27.0\n" 1614 "%constf42 = OpConstant %f32 42.0\n" 1615 1616 "%main = OpFunction %void None %voidf\n" 1617 1618 // entry block. 1619 "%entry = OpLabel\n" 1620 1621 // Create a temporary variable to hold the value of gl_GlobalInvocationID.x. 1622 "%xvar = OpVariable %u32ptr Function\n" 1623 "%xptr = OpAccessChain %u32ptr_input %id %zero\n" 1624 "%x = OpLoad %u32 %xptr\n" 1625 " OpStore %xvar %x\n" 1626 1627 "%cmp = OpUGreaterThan %bool %x %const50\n" 1628 " OpSelectionMerge %if_merge None\n" 1629 " OpBranchConditional %cmp %if_true %if_false\n" 1630 1631 // Merge block for switch-statement: placed at the beginning. 1632 "%switch_merge = OpLabel\n" 1633 " OpBranch %if_merge\n" 1634 1635 // Case 1 for switch-statement. 1636 "%case1 = OpLabel\n" 1637 "%x_1 = OpLoad %u32 %xvar\n" 1638 "%inloc_1 = OpAccessChain %f32ptr %indata %zero %x_1\n" 1639 "%inval_1 = OpLoad %f32 %inloc_1\n" 1640 "%addf42 = OpFAdd %f32 %inval_1 %constf42\n" 1641 "%outloc_1 = OpAccessChain %f32ptr %outdata %zero %x_1\n" 1642 " OpStore %outloc_1 %addf42\n" 1643 " OpBranch %switch_merge\n" 1644 1645 // False branch for if-statement: placed in the middle of switch cases and before true branch. 1646 "%if_false = OpLabel\n" 1647 "%x_f = OpLoad %u32 %xvar\n" 1648 "%inloc_f = OpAccessChain %f32ptr %indata %zero %x_f\n" 1649 "%inval_f = OpLoad %f32 %inloc_f\n" 1650 "%negate = OpFNegate %f32 %inval_f\n" 1651 "%outloc_f = OpAccessChain %f32ptr %outdata %zero %x_f\n" 1652 " OpStore %outloc_f %negate\n" 1653 " OpBranch %if_merge\n" 1654 1655 // Merge block for if-statement: placed in the middle of true and false branch. 1656 "%if_merge = OpLabel\n" 1657 " OpReturn\n" 1658 1659 // True branch for if-statement: placed in the middle of swtich cases and after the false branch. 1660 "%if_true = OpLabel\n" 1661 "%xval_t = OpLoad %u32 %xvar\n" 1662 "%mod = OpUMod %u32 %xval_t %const3\n" 1663 " OpSelectionMerge %switch_merge None\n" 1664 " OpSwitch %mod %default 0 %case0 1 %case1 2 %case2\n" 1665 1666 // Case 2 for switch-statement. 1667 "%case2 = OpLabel\n" 1668 "%x_2 = OpLoad %u32 %xvar\n" 1669 "%inloc_2 = OpAccessChain %f32ptr %indata %zero %x_2\n" 1670 "%inval_2 = OpLoad %f32 %inloc_2\n" 1671 "%subf27 = OpFSub %f32 %inval_2 %constf27\n" 1672 "%outloc_2 = OpAccessChain %f32ptr %outdata %zero %x_2\n" 1673 " OpStore %outloc_2 %subf27\n" 1674 " OpBranch %switch_merge\n" 1675 1676 // Default case for switch-statement: placed in the middle of normal cases. 1677 "%default = OpLabel\n" 1678 " OpBranch %switch_merge\n" 1679 1680 // Case 0 for switch-statement: out of order. 1681 "%case0 = OpLabel\n" 1682 "%x_0 = OpLoad %u32 %xvar\n" 1683 "%inloc_0 = OpAccessChain %f32ptr %indata %zero %x_0\n" 1684 "%inval_0 = OpLoad %f32 %inloc_0\n" 1685 "%addf1p5 = OpFAdd %f32 %inval_0 %constf1p5\n" 1686 "%outloc_0 = OpAccessChain %f32ptr %outdata %zero %x_0\n" 1687 " OpStore %outloc_0 %addf1p5\n" 1688 " OpBranch %switch_merge\n" 1689 1690 " OpFunctionEnd\n"; 1691 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1692 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 1693 spec.numWorkGroups = IVec3(numElements, 1, 1); 1694 1695 group->addChild(new SpvAsmComputeShaderCase(testCtx, "all", "various out-of-order blocks", spec)); 1696 1697 return group.release(); 1698} 1699 1700tcu::TestCaseGroup* createMultipleShaderGroup (tcu::TestContext& testCtx) 1701{ 1702 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "multiple_shaders", "Test multiple shaders in the same module")); 1703 ComputeShaderSpec spec1; 1704 ComputeShaderSpec spec2; 1705 de::Random rnd (deStringHash(group->getName())); 1706 const int numElements = 100; 1707 vector<float> inputFloats (numElements, 0); 1708 vector<float> outputFloats1 (numElements, 0); 1709 vector<float> outputFloats2 (numElements, 0); 1710 fillRandomScalars(rnd, -500.f, 500.f, &inputFloats[0], numElements); 1711 1712 for (size_t ndx = 0; ndx < numElements; ++ndx) 1713 { 1714 outputFloats1[ndx] = inputFloats[ndx] + inputFloats[ndx]; 1715 outputFloats2[ndx] = -inputFloats[ndx]; 1716 } 1717 1718 const string assembly( 1719 "OpCapability Shader\n" 1720 "OpMemoryModel Logical GLSL450\n" 1721 "OpEntryPoint GLCompute %comp_main1 \"entrypoint1\" %id\n" 1722 "OpEntryPoint GLCompute %comp_main2 \"entrypoint2\" %id\n" 1723 // A module cannot have two OpEntryPoint instructions with the same Execution Model and the same Name string. 1724 "OpEntryPoint Vertex %vert_main \"entrypoint2\" %vert_builtins %vertexID %instanceID\n" 1725 "OpExecutionMode %comp_main1 LocalSize 1 1 1\n" 1726 "OpExecutionMode %comp_main2 LocalSize 1 1 1\n" 1727 1728 "OpName %comp_main1 \"entrypoint1\"\n" 1729 "OpName %comp_main2 \"entrypoint2\"\n" 1730 "OpName %vert_main \"entrypoint2\"\n" 1731 "OpName %id \"gl_GlobalInvocationID\"\n" 1732 "OpName %vert_builtin_st \"gl_PerVertex\"\n" 1733 "OpName %vertexID \"gl_VertexID\"\n" 1734 "OpName %instanceID \"gl_InstanceID\"\n" 1735 "OpMemberName %vert_builtin_st 0 \"gl_Position\"\n" 1736 "OpMemberName %vert_builtin_st 1 \"gl_PointSize\"\n" 1737 "OpMemberName %vert_builtin_st 2 \"gl_ClipDistance\"\n" 1738 1739 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1740 "OpDecorate %vertexID BuiltIn VertexId\n" 1741 "OpDecorate %instanceID BuiltIn InstanceId\n" 1742 "OpDecorate %vert_builtin_st Block\n" 1743 "OpMemberDecorate %vert_builtin_st 0 BuiltIn Position\n" 1744 "OpMemberDecorate %vert_builtin_st 1 BuiltIn PointSize\n" 1745 "OpMemberDecorate %vert_builtin_st 2 BuiltIn ClipDistance\n" 1746 1747 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1748 1749 "%zero = OpConstant %i32 0\n" 1750 "%one = OpConstant %u32 1\n" 1751 "%c_f32_1 = OpConstant %f32 1\n" 1752 1753 "%i32ptr = OpTypePointer Input %i32\n" 1754 "%vec4 = OpTypeVector %f32 4\n" 1755 "%vec4ptr = OpTypePointer Output %vec4\n" 1756 "%f32arr1 = OpTypeArray %f32 %one\n" 1757 "%vert_builtin_st = OpTypeStruct %vec4 %f32 %f32arr1\n" 1758 "%vert_builtin_st_ptr = OpTypePointer Output %vert_builtin_st\n" 1759 "%vert_builtins = OpVariable %vert_builtin_st_ptr Output\n" 1760 1761 "%id = OpVariable %uvec3ptr Input\n" 1762 "%vertexID = OpVariable %i32ptr Input\n" 1763 "%instanceID = OpVariable %i32ptr Input\n" 1764 "%c_vec4_1 = OpConstantComposite %vec4 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" 1765 1766 // gl_Position = vec4(1.); 1767 "%vert_main = OpFunction %void None %voidf\n" 1768 "%vert_entry = OpLabel\n" 1769 "%position = OpAccessChain %vec4ptr %vert_builtins %zero\n" 1770 " OpStore %position %c_vec4_1\n" 1771 " OpReturn\n" 1772 " OpFunctionEnd\n" 1773 1774 // Double inputs. 1775 "%comp_main1 = OpFunction %void None %voidf\n" 1776 "%comp1_entry = OpLabel\n" 1777 "%idval1 = OpLoad %uvec3 %id\n" 1778 "%x1 = OpCompositeExtract %u32 %idval1 0\n" 1779 "%inloc1 = OpAccessChain %f32ptr %indata %zero %x1\n" 1780 "%inval1 = OpLoad %f32 %inloc1\n" 1781 "%add = OpFAdd %f32 %inval1 %inval1\n" 1782 "%outloc1 = OpAccessChain %f32ptr %outdata %zero %x1\n" 1783 " OpStore %outloc1 %add\n" 1784 " OpReturn\n" 1785 " OpFunctionEnd\n" 1786 1787 // Negate inputs. 1788 "%comp_main2 = OpFunction %void None %voidf\n" 1789 "%comp2_entry = OpLabel\n" 1790 "%idval2 = OpLoad %uvec3 %id\n" 1791 "%x2 = OpCompositeExtract %u32 %idval2 0\n" 1792 "%inloc2 = OpAccessChain %f32ptr %indata %zero %x2\n" 1793 "%inval2 = OpLoad %f32 %inloc2\n" 1794 "%neg = OpFNegate %f32 %inval2\n" 1795 "%outloc2 = OpAccessChain %f32ptr %outdata %zero %x2\n" 1796 " OpStore %outloc2 %neg\n" 1797 " OpReturn\n" 1798 " OpFunctionEnd\n"); 1799 1800 spec1.assembly = assembly; 1801 spec1.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1802 spec1.outputs.push_back(BufferSp(new Float32Buffer(outputFloats1))); 1803 spec1.numWorkGroups = IVec3(numElements, 1, 1); 1804 spec1.entryPoint = "entrypoint1"; 1805 1806 spec2.assembly = assembly; 1807 spec2.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1808 spec2.outputs.push_back(BufferSp(new Float32Buffer(outputFloats2))); 1809 spec2.numWorkGroups = IVec3(numElements, 1, 1); 1810 spec2.entryPoint = "entrypoint2"; 1811 1812 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader1", "multiple shaders in the same module", spec1)); 1813 group->addChild(new SpvAsmComputeShaderCase(testCtx, "shader2", "multiple shaders in the same module", spec2)); 1814 1815 return group.release(); 1816} 1817 1818inline std::string makeLongUTF8String (size_t num4ByteChars) 1819{ 1820 // An example of a longest valid UTF-8 character. Be explicit about the 1821 // character type because Microsoft compilers can otherwise interpret the 1822 // character string as being over wide (16-bit) characters. Ideally, we 1823 // would just use a C++11 UTF-8 string literal, but we want to support older 1824 // Microsoft compilers. 1825 const std::basic_string<char> earthAfrica("\xF0\x9F\x8C\x8D"); 1826 std::string longString; 1827 longString.reserve(num4ByteChars * 4); 1828 for (size_t count = 0; count < num4ByteChars; count++) 1829 { 1830 longString += earthAfrica; 1831 } 1832 return longString; 1833} 1834 1835tcu::TestCaseGroup* createOpSourceGroup (tcu::TestContext& testCtx) 1836{ 1837 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsource", "Tests the OpSource & OpSourceContinued instruction")); 1838 vector<CaseParameter> cases; 1839 de::Random rnd (deStringHash(group->getName())); 1840 const int numElements = 100; 1841 vector<float> positiveFloats (numElements, 0); 1842 vector<float> negativeFloats (numElements, 0); 1843 const StringTemplate shaderTemplate ( 1844 "OpCapability Shader\n" 1845 "OpMemoryModel Logical GLSL450\n" 1846 1847 "OpEntryPoint GLCompute %main \"main\" %id\n" 1848 "OpExecutionMode %main LocalSize 1 1 1\n" 1849 1850 "${SOURCE}\n" 1851 1852 "OpName %main \"main\"\n" 1853 "OpName %id \"gl_GlobalInvocationID\"\n" 1854 1855 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1856 1857 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1858 1859 "%id = OpVariable %uvec3ptr Input\n" 1860 "%zero = OpConstant %i32 0\n" 1861 1862 "%main = OpFunction %void None %voidf\n" 1863 "%label = OpLabel\n" 1864 "%idval = OpLoad %uvec3 %id\n" 1865 "%x = OpCompositeExtract %u32 %idval 0\n" 1866 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 1867 "%inval = OpLoad %f32 %inloc\n" 1868 "%neg = OpFNegate %f32 %inval\n" 1869 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1870 " OpStore %outloc %neg\n" 1871 " OpReturn\n" 1872 " OpFunctionEnd\n"); 1873 1874 cases.push_back(CaseParameter("unknown_source", "OpSource Unknown 0")); 1875 cases.push_back(CaseParameter("wrong_source", "OpSource OpenCL_C 210")); 1876 cases.push_back(CaseParameter("normal_filename", "%fname = OpString \"filename\"\n" 1877 "OpSource GLSL 430 %fname")); 1878 cases.push_back(CaseParameter("empty_filename", "%fname = OpString \"\"\n" 1879 "OpSource GLSL 430 %fname")); 1880 cases.push_back(CaseParameter("normal_source_code", "%fname = OpString \"filename\"\n" 1881 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"")); 1882 cases.push_back(CaseParameter("empty_source_code", "%fname = OpString \"filename\"\n" 1883 "OpSource GLSL 430 %fname \"\"")); 1884 cases.push_back(CaseParameter("long_source_code", "%fname = OpString \"filename\"\n" 1885 "OpSource GLSL 430 %fname \"" + makeLongUTF8String(65530) + "ccc\"")); // word count: 65535 1886 cases.push_back(CaseParameter("utf8_source_code", "%fname = OpString \"filename\"\n" 1887 "OpSource GLSL 430 %fname \"\xE2\x98\x82\xE2\x98\x85\"")); // umbrella & black star symbol 1888 cases.push_back(CaseParameter("normal_sourcecontinued", "%fname = OpString \"filename\"\n" 1889 "OpSource GLSL 430 %fname \"#version 430\nvo\"\n" 1890 "OpSourceContinued \"id main() {}\"")); 1891 cases.push_back(CaseParameter("empty_sourcecontinued", "%fname = OpString \"filename\"\n" 1892 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n" 1893 "OpSourceContinued \"\"")); 1894 cases.push_back(CaseParameter("long_sourcecontinued", "%fname = OpString \"filename\"\n" 1895 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n" 1896 "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\"")); // word count: 65535 1897 cases.push_back(CaseParameter("utf8_sourcecontinued", "%fname = OpString \"filename\"\n" 1898 "OpSource GLSL 430 %fname \"#version 430\nvoid main() {}\"\n" 1899 "OpSourceContinued \"\xE2\x98\x8E\xE2\x9A\x91\"")); // white telephone & black flag symbol 1900 cases.push_back(CaseParameter("multi_sourcecontinued", "%fname = OpString \"filename\"\n" 1901 "OpSource GLSL 430 %fname \"#version 430\n\"\n" 1902 "OpSourceContinued \"void\"\n" 1903 "OpSourceContinued \"main()\"\n" 1904 "OpSourceContinued \"{}\"")); 1905 cases.push_back(CaseParameter("empty_source_before_sourcecontinued", "%fname = OpString \"filename\"\n" 1906 "OpSource GLSL 430 %fname \"\"\n" 1907 "OpSourceContinued \"#version 430\nvoid main() {}\"")); 1908 1909 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 1910 1911 for (size_t ndx = 0; ndx < numElements; ++ndx) 1912 negativeFloats[ndx] = -positiveFloats[ndx]; 1913 1914 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 1915 { 1916 map<string, string> specializations; 1917 ComputeShaderSpec spec; 1918 1919 specializations["SOURCE"] = cases[caseNdx].param; 1920 spec.assembly = shaderTemplate.specialize(specializations); 1921 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 1922 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 1923 spec.numWorkGroups = IVec3(numElements, 1, 1); 1924 1925 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 1926 } 1927 1928 return group.release(); 1929} 1930 1931tcu::TestCaseGroup* createOpSourceExtensionGroup (tcu::TestContext& testCtx) 1932{ 1933 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opsourceextension", "Tests the OpSource instruction")); 1934 vector<CaseParameter> cases; 1935 de::Random rnd (deStringHash(group->getName())); 1936 const int numElements = 100; 1937 vector<float> inputFloats (numElements, 0); 1938 vector<float> outputFloats (numElements, 0); 1939 const StringTemplate shaderTemplate ( 1940 string(s_ShaderPreamble) + 1941 1942 "OpSourceExtension \"${EXTENSION}\"\n" 1943 1944 "OpName %main \"main\"\n" 1945 "OpName %id \"gl_GlobalInvocationID\"\n" 1946 1947 "OpDecorate %id BuiltIn GlobalInvocationId\n" 1948 1949 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 1950 1951 "%id = OpVariable %uvec3ptr Input\n" 1952 "%zero = OpConstant %i32 0\n" 1953 1954 "%main = OpFunction %void None %voidf\n" 1955 "%label = OpLabel\n" 1956 "%idval = OpLoad %uvec3 %id\n" 1957 "%x = OpCompositeExtract %u32 %idval 0\n" 1958 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 1959 "%inval = OpLoad %f32 %inloc\n" 1960 "%neg = OpFNegate %f32 %inval\n" 1961 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 1962 " OpStore %outloc %neg\n" 1963 " OpReturn\n" 1964 " OpFunctionEnd\n"); 1965 1966 cases.push_back(CaseParameter("empty_extension", "")); 1967 cases.push_back(CaseParameter("real_extension", "GL_ARB_texture_rectangle")); 1968 cases.push_back(CaseParameter("fake_extension", "GL_ARB_im_the_ultimate_extension")); 1969 cases.push_back(CaseParameter("utf8_extension", "GL_ARB_\xE2\x98\x82\xE2\x98\x85")); 1970 cases.push_back(CaseParameter("long_extension", makeLongUTF8String(65533) + "ccc")); // word count: 65535 1971 1972 fillRandomScalars(rnd, -200.f, 200.f, &inputFloats[0], numElements); 1973 1974 for (size_t ndx = 0; ndx < numElements; ++ndx) 1975 outputFloats[ndx] = -inputFloats[ndx]; 1976 1977 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 1978 { 1979 map<string, string> specializations; 1980 ComputeShaderSpec spec; 1981 1982 specializations["EXTENSION"] = cases[caseNdx].param; 1983 spec.assembly = shaderTemplate.specialize(specializations); 1984 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 1985 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 1986 spec.numWorkGroups = IVec3(numElements, 1, 1); 1987 1988 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 1989 } 1990 1991 return group.release(); 1992} 1993 1994// Checks that a compute shader can generate a constant null value of various types, without exercising a computation on it. 1995tcu::TestCaseGroup* createOpConstantNullGroup (tcu::TestContext& testCtx) 1996{ 1997 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnull", "Tests the OpConstantNull instruction")); 1998 vector<CaseParameter> cases; 1999 de::Random rnd (deStringHash(group->getName())); 2000 const int numElements = 100; 2001 vector<float> positiveFloats (numElements, 0); 2002 vector<float> negativeFloats (numElements, 0); 2003 const StringTemplate shaderTemplate ( 2004 string(s_ShaderPreamble) + 2005 2006 "OpSource GLSL 430\n" 2007 "OpName %main \"main\"\n" 2008 "OpName %id \"gl_GlobalInvocationID\"\n" 2009 2010 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2011 2012 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2013 2014 "${TYPE}\n" 2015 "%null = OpConstantNull %type\n" 2016 2017 "%id = OpVariable %uvec3ptr Input\n" 2018 "%zero = OpConstant %i32 0\n" 2019 2020 "%main = OpFunction %void None %voidf\n" 2021 "%label = OpLabel\n" 2022 "%idval = OpLoad %uvec3 %id\n" 2023 "%x = OpCompositeExtract %u32 %idval 0\n" 2024 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2025 "%inval = OpLoad %f32 %inloc\n" 2026 "%neg = OpFNegate %f32 %inval\n" 2027 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2028 " OpStore %outloc %neg\n" 2029 " OpReturn\n" 2030 " OpFunctionEnd\n"); 2031 2032 cases.push_back(CaseParameter("bool", "%type = OpTypeBool")); 2033 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1")); 2034 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0")); 2035 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32")); 2036 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4")); 2037 cases.push_back(CaseParameter("vec3bool", "%type = OpTypeVector %bool 3")); 2038 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2")); 2039 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3")); 2040 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n" 2041 "%type = OpTypeArray %i32 %100")); 2042 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32")); 2043 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32")); 2044 2045 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 2046 2047 for (size_t ndx = 0; ndx < numElements; ++ndx) 2048 negativeFloats[ndx] = -positiveFloats[ndx]; 2049 2050 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 2051 { 2052 map<string, string> specializations; 2053 ComputeShaderSpec spec; 2054 2055 specializations["TYPE"] = cases[caseNdx].param; 2056 spec.assembly = shaderTemplate.specialize(specializations); 2057 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 2058 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 2059 spec.numWorkGroups = IVec3(numElements, 1, 1); 2060 2061 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 2062 } 2063 2064 return group.release(); 2065} 2066 2067// Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it. 2068tcu::TestCaseGroup* createOpConstantCompositeGroup (tcu::TestContext& testCtx) 2069{ 2070 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "Tests the OpConstantComposite instruction")); 2071 vector<CaseParameter> cases; 2072 de::Random rnd (deStringHash(group->getName())); 2073 const int numElements = 100; 2074 vector<float> positiveFloats (numElements, 0); 2075 vector<float> negativeFloats (numElements, 0); 2076 const StringTemplate shaderTemplate ( 2077 string(s_ShaderPreamble) + 2078 2079 "OpSource GLSL 430\n" 2080 "OpName %main \"main\"\n" 2081 "OpName %id \"gl_GlobalInvocationID\"\n" 2082 2083 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2084 2085 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2086 2087 "%id = OpVariable %uvec3ptr Input\n" 2088 "%zero = OpConstant %i32 0\n" 2089 2090 "${CONSTANT}\n" 2091 2092 "%main = OpFunction %void None %voidf\n" 2093 "%label = OpLabel\n" 2094 "%idval = OpLoad %uvec3 %id\n" 2095 "%x = OpCompositeExtract %u32 %idval 0\n" 2096 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2097 "%inval = OpLoad %f32 %inloc\n" 2098 "%neg = OpFNegate %f32 %inval\n" 2099 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2100 " OpStore %outloc %neg\n" 2101 " OpReturn\n" 2102 " OpFunctionEnd\n"); 2103 2104 cases.push_back(CaseParameter("vector", "%five = OpConstant %u32 5\n" 2105 "%const = OpConstantComposite %uvec3 %five %zero %five")); 2106 cases.push_back(CaseParameter("matrix", "%m3uvec3 = OpTypeMatrix %fvec3 3\n" 2107 "%ten = OpConstant %u32 10\n" 2108 "%vec = OpConstantComposite %uvec3 %ten %zero %ten\n" 2109 "%mat = OpConstantComposite %m3uvec3 %vec %vec %vec")); 2110 cases.push_back(CaseParameter("struct", "%m2vec3 = OpTypeMatrix %fvec3 2\n" 2111 "%struct = OpTypeStruct %u32 %f32 %uvec3 %m2vec3\n" 2112 "%one = OpConstant %u32 1\n" 2113 "%point5 = OpConstant %f32 0.5\n" 2114 "%vec = OpConstantComposite %uvec3 %one %one %zero\n" 2115 "%mat = OpConstantComposite %m2vec3 %vec %vec\n" 2116 "%const = OpConstantComposite %struct %one %point5 %vec %mat")); 2117 cases.push_back(CaseParameter("nested_struct", "%st1 = OpTypeStruct %u32 %f32\n" 2118 "%st2 = OpTypeStruct %i32 %i32\n" 2119 "%struct = OpTypeStruct %st1 %st2\n" 2120 "%point5 = OpConstant %f32 0.5\n" 2121 "%one = OpConstant %u32 1\n" 2122 "%ten = OpConstant %i32 10\n" 2123 "%st1val = OpConstantComposite %st1 %one %point5\n" 2124 "%st2val = OpConstantComposite %st2 %ten %ten\n" 2125 "%const = OpConstantComposite %struct %st1val %st2val")); 2126 2127 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 2128 2129 for (size_t ndx = 0; ndx < numElements; ++ndx) 2130 negativeFloats[ndx] = -positiveFloats[ndx]; 2131 2132 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 2133 { 2134 map<string, string> specializations; 2135 ComputeShaderSpec spec; 2136 2137 specializations["CONSTANT"] = cases[caseNdx].param; 2138 spec.assembly = shaderTemplate.specialize(specializations); 2139 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 2140 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 2141 spec.numWorkGroups = IVec3(numElements, 1, 1); 2142 2143 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 2144 } 2145 2146 return group.release(); 2147} 2148 2149// Creates a floating point number with the given exponent, and significand 2150// bits set. It can only create normalized numbers. Only the least significant 2151// 24 bits of the significand will be examined. The final bit of the 2152// significand will also be ignored. This allows alignment to be written 2153// similarly to C99 hex-floats. 2154// For example if you wanted to write 0x1.7f34p-12 you would call 2155// constructNormalizedFloat(-12, 0x7f3400) 2156float constructNormalizedFloat (deInt32 exponent, deUint32 significand) 2157{ 2158 float f = 1.0f; 2159 2160 for (deInt32 idx = 0; idx < 23; ++idx) 2161 { 2162 f += ((significand & 0x800000) == 0) ? 0.f : std::ldexp(1.0f, -idx); 2163 significand <<= 1; 2164 } 2165 2166 return std::ldexp(f, exponent); 2167} 2168 2169// Compare instruction for the OpQuantizeF16 compute exact case. 2170// Returns true if the output is what is expected from the test case. 2171bool compareOpQuantizeF16ComputeExactCase (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs) 2172{ 2173 if (outputAllocs.size() != 1) 2174 return false; 2175 2176 // We really just need this for size because we cannot compare Nans. 2177 const BufferSp& expectedOutput = expectedOutputs[0]; 2178 const float* outputAsFloat = static_cast<const float*>(outputAllocs[0]->getHostPtr());; 2179 2180 if (expectedOutput->getNumBytes() != 4*sizeof(float)) { 2181 return false; 2182 } 2183 2184 if (*outputAsFloat != constructNormalizedFloat(8, 0x304000) && 2185 *outputAsFloat != constructNormalizedFloat(8, 0x300000)) { 2186 return false; 2187 } 2188 2189 if (*outputAsFloat != -constructNormalizedFloat(-7, 0x600000) && 2190 *outputAsFloat != -constructNormalizedFloat(-7, 0x604000)) { 2191 return false; 2192 } 2193 2194 if (*outputAsFloat != constructNormalizedFloat(2, 0x01C000) && 2195 *outputAsFloat != constructNormalizedFloat(2, 0x020000)) { 2196 return false; 2197 } 2198 2199 if (*outputAsFloat != constructNormalizedFloat(1, 0xFFC000) && 2200 *outputAsFloat != constructNormalizedFloat(2, 0x000000)) { 2201 return false; 2202 } 2203 2204 return true; 2205} 2206 2207// Checks that every output from a test-case is a float NaN. 2208bool compareNan (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs) 2209{ 2210 if (outputAllocs.size() != 1) 2211 return false; 2212 2213 // We really just need this for size because we cannot compare Nans. 2214 const BufferSp& expectedOutput = expectedOutputs[0]; 2215 const float* output_as_float = static_cast<const float*>(outputAllocs[0]->getHostPtr());; 2216 2217 for (size_t idx = 0; idx < expectedOutput->getNumBytes() / sizeof(float); ++idx) 2218 { 2219 if (!isnan(output_as_float[idx])) 2220 { 2221 return false; 2222 } 2223 } 2224 2225 return true; 2226} 2227 2228// Checks that a compute shader can generate a constant composite value of various types, without exercising a computation on it. 2229tcu::TestCaseGroup* createOpQuantizeToF16Group (tcu::TestContext& testCtx) 2230{ 2231 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opquantize", "Tests the OpQuantizeToF16 instruction")); 2232 2233 const std::string shader ( 2234 string(s_ShaderPreamble) + 2235 2236 "OpSource GLSL 430\n" 2237 "OpName %main \"main\"\n" 2238 "OpName %id \"gl_GlobalInvocationID\"\n" 2239 2240 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2241 2242 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2243 2244 "%id = OpVariable %uvec3ptr Input\n" 2245 "%zero = OpConstant %i32 0\n" 2246 2247 "%main = OpFunction %void None %voidf\n" 2248 "%label = OpLabel\n" 2249 "%idval = OpLoad %uvec3 %id\n" 2250 "%x = OpCompositeExtract %u32 %idval 0\n" 2251 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2252 "%inval = OpLoad %f32 %inloc\n" 2253 "%quant = OpQuantizeToF16 %f32 %inval\n" 2254 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2255 " OpStore %outloc %quant\n" 2256 " OpReturn\n" 2257 " OpFunctionEnd\n"); 2258 2259 { 2260 ComputeShaderSpec spec; 2261 const deUint32 numElements = 100; 2262 vector<float> infinities; 2263 vector<float> results; 2264 2265 infinities.reserve(numElements); 2266 results.reserve(numElements); 2267 2268 for (size_t idx = 0; idx < numElements; ++idx) 2269 { 2270 switch(idx % 4) 2271 { 2272 case 0: 2273 infinities.push_back(std::numeric_limits<float>::infinity()); 2274 results.push_back(std::numeric_limits<float>::infinity()); 2275 break; 2276 case 1: 2277 infinities.push_back(-std::numeric_limits<float>::infinity()); 2278 results.push_back(-std::numeric_limits<float>::infinity()); 2279 break; 2280 case 2: 2281 infinities.push_back(std::ldexp(1.0f, 16)); 2282 results.push_back(std::numeric_limits<float>::infinity()); 2283 break; 2284 case 3: 2285 infinities.push_back(std::ldexp(-1.0f, 32)); 2286 results.push_back(-std::numeric_limits<float>::infinity()); 2287 break; 2288 } 2289 } 2290 2291 spec.inputs.push_back(BufferSp(new Float32Buffer(infinities))); 2292 spec.outputs.push_back(BufferSp(new Float32Buffer(results))); 2293 spec.numWorkGroups = IVec3(numElements, 1, 1); 2294 2295 group->addChild(new SpvAsmComputeShaderCase( 2296 testCtx, "infinities", "Check that infinities propagated and created", spec)); 2297 } 2298 2299 { 2300 ComputeShaderSpec spec; 2301 vector<float> nans; 2302 const deUint32 numElements = 100; 2303 2304 nans.reserve(numElements); 2305 2306 for (size_t idx = 0; idx < numElements; ++idx) 2307 { 2308 if (idx % 2 == 0) 2309 { 2310 nans.push_back(std::numeric_limits<float>::quiet_NaN()); 2311 } 2312 else 2313 { 2314 nans.push_back(-std::numeric_limits<float>::quiet_NaN()); 2315 } 2316 } 2317 2318 spec.inputs.push_back(BufferSp(new Float32Buffer(nans))); 2319 spec.outputs.push_back(BufferSp(new Float32Buffer(nans))); 2320 spec.numWorkGroups = IVec3(numElements, 1, 1); 2321 spec.verifyIO = &compareNan; 2322 2323 group->addChild(new SpvAsmComputeShaderCase( 2324 testCtx, "propagated_nans", "Check that nans are propagated", spec)); 2325 } 2326 2327 { 2328 ComputeShaderSpec spec; 2329 vector<float> small; 2330 vector<float> zeros; 2331 const deUint32 numElements = 100; 2332 2333 small.reserve(numElements); 2334 zeros.reserve(numElements); 2335 2336 for (size_t idx = 0; idx < numElements; ++idx) 2337 { 2338 switch(idx % 6) 2339 { 2340 case 0: 2341 small.push_back(0.f); 2342 zeros.push_back(0.f); 2343 break; 2344 case 1: 2345 small.push_back(-0.f); 2346 zeros.push_back(-0.f); 2347 break; 2348 case 2: 2349 small.push_back(std::ldexp(1.0f, -16)); 2350 zeros.push_back(0.f); 2351 break; 2352 case 3: 2353 small.push_back(std::ldexp(-1.0f, -32)); 2354 zeros.push_back(-0.f); 2355 break; 2356 case 4: 2357 small.push_back(std::ldexp(1.0f, -127)); 2358 zeros.push_back(0.f); 2359 break; 2360 case 5: 2361 small.push_back(-std::ldexp(1.0f, -128)); 2362 zeros.push_back(-0.f); 2363 break; 2364 } 2365 } 2366 2367 spec.inputs.push_back(BufferSp(new Float32Buffer(small))); 2368 spec.outputs.push_back(BufferSp(new Float32Buffer(zeros))); 2369 spec.numWorkGroups = IVec3(numElements, 1, 1); 2370 2371 group->addChild(new SpvAsmComputeShaderCase( 2372 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec)); 2373 } 2374 2375 { 2376 ComputeShaderSpec spec; 2377 vector<float> exact; 2378 const deUint32 numElements = 200; 2379 2380 exact.reserve(numElements); 2381 2382 for (size_t idx = 0; idx < numElements; ++idx) 2383 exact.push_back(static_cast<float>(idx - 100)); 2384 2385 spec.inputs.push_back(BufferSp(new Float32Buffer(exact))); 2386 spec.outputs.push_back(BufferSp(new Float32Buffer(exact))); 2387 spec.numWorkGroups = IVec3(numElements, 1, 1); 2388 2389 group->addChild(new SpvAsmComputeShaderCase( 2390 testCtx, "exact", "Check that values exactly preserved where appropriate", spec)); 2391 } 2392 2393 { 2394 ComputeShaderSpec spec; 2395 vector<float> inputs; 2396 const deUint32 numElements = 4; 2397 2398 inputs.push_back(constructNormalizedFloat(8, 0x300300)); 2399 inputs.push_back(-constructNormalizedFloat(-7, 0x600800)); 2400 inputs.push_back(constructNormalizedFloat(2, 0x01E000)); 2401 inputs.push_back(constructNormalizedFloat(1, 0xFFE000)); 2402 2403 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase; 2404 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2405 spec.outputs.push_back(BufferSp(new Float32Buffer(inputs))); 2406 spec.numWorkGroups = IVec3(numElements, 1, 1); 2407 2408 group->addChild(new SpvAsmComputeShaderCase( 2409 testCtx, "rounded", "Check that are rounded when needed", spec)); 2410 } 2411 2412 return group.release(); 2413} 2414 2415// Performs a bitwise copy of source to the destination type Dest. 2416template <typename Dest, typename Src> 2417Dest bitwiseCast(Src source) 2418{ 2419 Dest dest; 2420 DE_STATIC_ASSERT(sizeof(source) == sizeof(dest)); 2421 deMemcpy(&dest, &source, sizeof(dest)); 2422 return dest; 2423} 2424 2425tcu::TestCaseGroup* createSpecConstantOpQuantizeToF16Group (tcu::TestContext& testCtx) 2426{ 2427 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop_opquantize", "Tests the OpQuantizeToF16 opcode for the OpSpecConstantOp instruction")); 2428 2429 const std::string shader ( 2430 string(s_ShaderPreamble) + 2431 2432 "OpName %main \"main\"\n" 2433 "OpName %id \"gl_GlobalInvocationID\"\n" 2434 2435 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2436 2437 "OpDecorate %sc_0 SpecId 0\n" 2438 "OpDecorate %sc_1 SpecId 1\n" 2439 "OpDecorate %sc_2 SpecId 2\n" 2440 "OpDecorate %sc_3 SpecId 3\n" 2441 "OpDecorate %sc_4 SpecId 4\n" 2442 "OpDecorate %sc_5 SpecId 5\n" 2443 2444 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2445 2446 "%id = OpVariable %uvec3ptr Input\n" 2447 "%zero = OpConstant %i32 0\n" 2448 "%c_u32_6 = OpConstant %u32 6\n" 2449 2450 "%sc_0 = OpSpecConstant %f32 0.\n" 2451 "%sc_1 = OpSpecConstant %f32 0.\n" 2452 "%sc_2 = OpSpecConstant %f32 0.\n" 2453 "%sc_3 = OpSpecConstant %f32 0.\n" 2454 "%sc_4 = OpSpecConstant %f32 0.\n" 2455 "%sc_5 = OpSpecConstant %f32 0.\n" 2456 2457 "%sc_0_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_0\n" 2458 "%sc_1_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_1\n" 2459 "%sc_2_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_2\n" 2460 "%sc_3_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_3\n" 2461 "%sc_4_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_4\n" 2462 "%sc_5_quant = OpSpecConstantOp %f32 QuantizeToF16 %sc_5\n" 2463 2464 "%main = OpFunction %void None %voidf\n" 2465 "%label = OpLabel\n" 2466 "%idval = OpLoad %uvec3 %id\n" 2467 "%x = OpCompositeExtract %u32 %idval 0\n" 2468 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2469 "%selector = OpUMod %u32 %x %c_u32_6\n" 2470 " OpSelectionMerge %exit None\n" 2471 " OpSwitch %selector %exit 0 %case0 1 %case1 2 %case2 3 %case3 4 %case4 5 %case5\n" 2472 2473 "%case0 = OpLabel\n" 2474 " OpStore %outloc %sc_0_quant\n" 2475 " OpBranch %exit\n" 2476 2477 "%case1 = OpLabel\n" 2478 " OpStore %outloc %sc_1_quant\n" 2479 " OpBranch %exit\n" 2480 2481 "%case2 = OpLabel\n" 2482 " OpStore %outloc %sc_2_quant\n" 2483 " OpBranch %exit\n" 2484 2485 "%case3 = OpLabel\n" 2486 " OpStore %outloc %sc_3_quant\n" 2487 " OpBranch %exit\n" 2488 2489 "%case4 = OpLabel\n" 2490 " OpStore %outloc %sc_4_quant\n" 2491 " OpBranch %exit\n" 2492 2493 "%case5 = OpLabel\n" 2494 " OpStore %outloc %sc_5_quant\n" 2495 " OpBranch %exit\n" 2496 2497 "%exit = OpLabel\n" 2498 " OpReturn\n" 2499 2500 " OpFunctionEnd\n"); 2501 2502 { 2503 ComputeShaderSpec spec; 2504 const deUint8 numCases = 4; 2505 vector<float> inputs (numCases, 0.f); 2506 vector<float> outputs; 2507 2508 spec.numWorkGroups = IVec3(numCases, 1, 1); 2509 2510 spec.specConstants.push_back(bitwiseCast<deUint32>(std::numeric_limits<float>::infinity())); 2511 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::numeric_limits<float>::infinity())); 2512 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, 16))); 2513 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, 32))); 2514 2515 outputs.push_back(std::numeric_limits<float>::infinity()); 2516 outputs.push_back(-std::numeric_limits<float>::infinity()); 2517 outputs.push_back(std::numeric_limits<float>::infinity()); 2518 outputs.push_back(-std::numeric_limits<float>::infinity()); 2519 2520 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2521 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs))); 2522 2523 group->addChild(new SpvAsmComputeShaderCase( 2524 testCtx, "infinities", "Check that infinities propagated and created", spec)); 2525 } 2526 2527 { 2528 ComputeShaderSpec spec; 2529 const deUint8 numCases = 2; 2530 vector<float> inputs (numCases, 0.f); 2531 vector<float> outputs; 2532 2533 spec.numWorkGroups = IVec3(numCases, 1, 1); 2534 spec.verifyIO = &compareNan; 2535 2536 outputs.push_back(std::numeric_limits<float>::quiet_NaN()); 2537 outputs.push_back(-std::numeric_limits<float>::quiet_NaN()); 2538 2539 for (deUint8 idx = 0; idx < numCases; ++idx) 2540 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx])); 2541 2542 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2543 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs))); 2544 2545 group->addChild(new SpvAsmComputeShaderCase( 2546 testCtx, "propagated_nans", "Check that nans are propagated", spec)); 2547 } 2548 2549 { 2550 ComputeShaderSpec spec; 2551 const deUint8 numCases = 6; 2552 vector<float> inputs (numCases, 0.f); 2553 vector<float> outputs; 2554 2555 spec.numWorkGroups = IVec3(numCases, 1, 1); 2556 2557 spec.specConstants.push_back(bitwiseCast<deUint32>(0.f)); 2558 spec.specConstants.push_back(bitwiseCast<deUint32>(-0.f)); 2559 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -16))); 2560 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(-1.0f, -32))); 2561 spec.specConstants.push_back(bitwiseCast<deUint32>(std::ldexp(1.0f, -127))); 2562 spec.specConstants.push_back(bitwiseCast<deUint32>(-std::ldexp(1.0f, -128))); 2563 2564 outputs.push_back(0.f); 2565 outputs.push_back(-0.f); 2566 outputs.push_back(0.f); 2567 outputs.push_back(-0.f); 2568 outputs.push_back(0.f); 2569 outputs.push_back(-0.f); 2570 2571 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2572 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs))); 2573 2574 group->addChild(new SpvAsmComputeShaderCase( 2575 testCtx, "flush_to_zero", "Check that values are zeroed correctly", spec)); 2576 } 2577 2578 { 2579 ComputeShaderSpec spec; 2580 const deUint8 numCases = 6; 2581 vector<float> inputs (numCases, 0.f); 2582 vector<float> outputs; 2583 2584 spec.numWorkGroups = IVec3(numCases, 1, 1); 2585 2586 for (deUint8 idx = 0; idx < 6; ++idx) 2587 { 2588 const float f = static_cast<float>(idx * 10 - 30) / 4.f; 2589 spec.specConstants.push_back(bitwiseCast<deUint32>(f)); 2590 outputs.push_back(f); 2591 } 2592 2593 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2594 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs))); 2595 2596 group->addChild(new SpvAsmComputeShaderCase( 2597 testCtx, "exact", "Check that values exactly preserved where appropriate", spec)); 2598 } 2599 2600 { 2601 ComputeShaderSpec spec; 2602 const deUint8 numCases = 4; 2603 vector<float> inputs (numCases, 0.f); 2604 vector<float> outputs; 2605 2606 spec.numWorkGroups = IVec3(numCases, 1, 1); 2607 spec.verifyIO = &compareOpQuantizeF16ComputeExactCase; 2608 2609 outputs.push_back(constructNormalizedFloat(8, 0x300300)); 2610 outputs.push_back(-constructNormalizedFloat(-7, 0x600800)); 2611 outputs.push_back(constructNormalizedFloat(2, 0x01E000)); 2612 outputs.push_back(constructNormalizedFloat(1, 0xFFE000)); 2613 2614 for (deUint8 idx = 0; idx < numCases; ++idx) 2615 spec.specConstants.push_back(bitwiseCast<deUint32>(outputs[idx])); 2616 2617 spec.inputs.push_back(BufferSp(new Float32Buffer(inputs))); 2618 spec.outputs.push_back(BufferSp(new Float32Buffer(outputs))); 2619 2620 group->addChild(new SpvAsmComputeShaderCase( 2621 testCtx, "rounded", "Check that are rounded when needed", spec)); 2622 } 2623 2624 return group.release(); 2625} 2626 2627// Checks that constant null/composite values can be used in computation. 2628tcu::TestCaseGroup* createOpConstantUsageGroup (tcu::TestContext& testCtx) 2629{ 2630 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opconstantnullcomposite", "Spotcheck the OpConstantNull & OpConstantComposite instruction")); 2631 ComputeShaderSpec spec; 2632 de::Random rnd (deStringHash(group->getName())); 2633 const int numElements = 100; 2634 vector<float> positiveFloats (numElements, 0); 2635 vector<float> negativeFloats (numElements, 0); 2636 2637 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 2638 2639 for (size_t ndx = 0; ndx < numElements; ++ndx) 2640 negativeFloats[ndx] = -positiveFloats[ndx]; 2641 2642 spec.assembly = 2643 "OpCapability Shader\n" 2644 "%std450 = OpExtInstImport \"GLSL.std.450\"\n" 2645 "OpMemoryModel Logical GLSL450\n" 2646 "OpEntryPoint GLCompute %main \"main\" %id\n" 2647 "OpExecutionMode %main LocalSize 1 1 1\n" 2648 2649 "OpSource GLSL 430\n" 2650 "OpName %main \"main\"\n" 2651 "OpName %id \"gl_GlobalInvocationID\"\n" 2652 2653 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2654 2655 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + 2656 2657 "%fvec3 = OpTypeVector %f32 3\n" 2658 "%fmat = OpTypeMatrix %fvec3 3\n" 2659 "%ten = OpConstant %u32 10\n" 2660 "%f32arr10 = OpTypeArray %f32 %ten\n" 2661 "%fst = OpTypeStruct %f32 %f32\n" 2662 2663 + string(s_InputOutputBuffer) + 2664 2665 "%id = OpVariable %uvec3ptr Input\n" 2666 "%zero = OpConstant %i32 0\n" 2667 2668 // Create a bunch of null values 2669 "%unull = OpConstantNull %u32\n" 2670 "%fnull = OpConstantNull %f32\n" 2671 "%vnull = OpConstantNull %fvec3\n" 2672 "%mnull = OpConstantNull %fmat\n" 2673 "%anull = OpConstantNull %f32arr10\n" 2674 "%snull = OpConstantComposite %fst %fnull %fnull\n" 2675 2676 "%main = OpFunction %void None %voidf\n" 2677 "%label = OpLabel\n" 2678 "%idval = OpLoad %uvec3 %id\n" 2679 "%x = OpCompositeExtract %u32 %idval 0\n" 2680 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2681 "%inval = OpLoad %f32 %inloc\n" 2682 "%neg = OpFNegate %f32 %inval\n" 2683 2684 // Get the abs() of (a certain element of) those null values 2685 "%unull_cov = OpConvertUToF %f32 %unull\n" 2686 "%unull_abs = OpExtInst %f32 %std450 FAbs %unull_cov\n" 2687 "%fnull_abs = OpExtInst %f32 %std450 FAbs %fnull\n" 2688 "%vnull_0 = OpCompositeExtract %f32 %vnull 0\n" 2689 "%vnull_abs = OpExtInst %f32 %std450 FAbs %vnull_0\n" 2690 "%mnull_12 = OpCompositeExtract %f32 %mnull 1 2\n" 2691 "%mnull_abs = OpExtInst %f32 %std450 FAbs %mnull_12\n" 2692 "%anull_3 = OpCompositeExtract %f32 %anull 3\n" 2693 "%anull_abs = OpExtInst %f32 %std450 FAbs %anull_3\n" 2694 "%snull_1 = OpCompositeExtract %f32 %snull 1\n" 2695 "%snull_abs = OpExtInst %f32 %std450 FAbs %snull_1\n" 2696 2697 // Add them all 2698 "%add1 = OpFAdd %f32 %neg %unull_abs\n" 2699 "%add2 = OpFAdd %f32 %add1 %fnull_abs\n" 2700 "%add3 = OpFAdd %f32 %add2 %vnull_abs\n" 2701 "%add4 = OpFAdd %f32 %add3 %mnull_abs\n" 2702 "%add5 = OpFAdd %f32 %add4 %anull_abs\n" 2703 "%final = OpFAdd %f32 %add5 %snull_abs\n" 2704 2705 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2706 " OpStore %outloc %final\n" // write to output 2707 " OpReturn\n" 2708 " OpFunctionEnd\n"; 2709 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 2710 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 2711 spec.numWorkGroups = IVec3(numElements, 1, 1); 2712 2713 group->addChild(new SpvAsmComputeShaderCase(testCtx, "spotcheck", "Check that values constructed via OpConstantNull & OpConstantComposite can be used", spec)); 2714 2715 return group.release(); 2716} 2717 2718// Assembly code used for testing loop control is based on GLSL source code: 2719// #version 430 2720// 2721// layout(std140, set = 0, binding = 0) readonly buffer Input { 2722// float elements[]; 2723// } input_data; 2724// layout(std140, set = 0, binding = 1) writeonly buffer Output { 2725// float elements[]; 2726// } output_data; 2727// 2728// void main() { 2729// uint x = gl_GlobalInvocationID.x; 2730// output_data.elements[x] = input_data.elements[x]; 2731// for (uint i = 0; i < 4; ++i) 2732// output_data.elements[x] += 1.f; 2733// } 2734tcu::TestCaseGroup* createLoopControlGroup (tcu::TestContext& testCtx) 2735{ 2736 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "loop_control", "Tests loop control cases")); 2737 vector<CaseParameter> cases; 2738 de::Random rnd (deStringHash(group->getName())); 2739 const int numElements = 100; 2740 vector<float> inputFloats (numElements, 0); 2741 vector<float> outputFloats (numElements, 0); 2742 const StringTemplate shaderTemplate ( 2743 string(s_ShaderPreamble) + 2744 2745 "OpSource GLSL 430\n" 2746 "OpName %main \"main\"\n" 2747 "OpName %id \"gl_GlobalInvocationID\"\n" 2748 2749 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2750 2751 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2752 2753 "%u32ptr = OpTypePointer Function %u32\n" 2754 2755 "%id = OpVariable %uvec3ptr Input\n" 2756 "%zero = OpConstant %i32 0\n" 2757 "%uzero = OpConstant %u32 0\n" 2758 "%one = OpConstant %i32 1\n" 2759 "%constf1 = OpConstant %f32 1.0\n" 2760 "%four = OpConstant %u32 4\n" 2761 2762 "%main = OpFunction %void None %voidf\n" 2763 "%entry = OpLabel\n" 2764 "%i = OpVariable %u32ptr Function\n" 2765 " OpStore %i %uzero\n" 2766 2767 "%idval = OpLoad %uvec3 %id\n" 2768 "%x = OpCompositeExtract %u32 %idval 0\n" 2769 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2770 "%inval = OpLoad %f32 %inloc\n" 2771 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2772 " OpStore %outloc %inval\n" 2773 " OpBranch %loop_entry\n" 2774 2775 "%loop_entry = OpLabel\n" 2776 "%i_val = OpLoad %u32 %i\n" 2777 "%cmp_lt = OpULessThan %bool %i_val %four\n" 2778 " OpLoopMerge %loop_merge %loop_entry ${CONTROL}\n" 2779 " OpBranchConditional %cmp_lt %loop_body %loop_merge\n" 2780 "%loop_body = OpLabel\n" 2781 "%outval = OpLoad %f32 %outloc\n" 2782 "%addf1 = OpFAdd %f32 %outval %constf1\n" 2783 " OpStore %outloc %addf1\n" 2784 "%new_i = OpIAdd %u32 %i_val %one\n" 2785 " OpStore %i %new_i\n" 2786 " OpBranch %loop_entry\n" 2787 "%loop_merge = OpLabel\n" 2788 " OpReturn\n" 2789 " OpFunctionEnd\n"); 2790 2791 cases.push_back(CaseParameter("none", "None")); 2792 cases.push_back(CaseParameter("unroll", "Unroll")); 2793 cases.push_back(CaseParameter("dont_unroll", "DontUnroll")); 2794 cases.push_back(CaseParameter("unroll_dont_unroll", "Unroll|DontUnroll")); 2795 2796 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements); 2797 2798 for (size_t ndx = 0; ndx < numElements; ++ndx) 2799 outputFloats[ndx] = inputFloats[ndx] + 4.f; 2800 2801 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 2802 { 2803 map<string, string> specializations; 2804 ComputeShaderSpec spec; 2805 2806 specializations["CONTROL"] = cases[caseNdx].param; 2807 spec.assembly = shaderTemplate.specialize(specializations); 2808 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 2809 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 2810 spec.numWorkGroups = IVec3(numElements, 1, 1); 2811 2812 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 2813 } 2814 2815 return group.release(); 2816} 2817 2818// Assembly code used for testing selection control is based on GLSL source code: 2819// #version 430 2820// 2821// layout(std140, set = 0, binding = 0) readonly buffer Input { 2822// float elements[]; 2823// } input_data; 2824// layout(std140, set = 0, binding = 1) writeonly buffer Output { 2825// float elements[]; 2826// } output_data; 2827// 2828// void main() { 2829// uint x = gl_GlobalInvocationID.x; 2830// float val = input_data.elements[x]; 2831// if (val > 10.f) 2832// output_data.elements[x] = val + 1.f; 2833// else 2834// output_data.elements[x] = val - 1.f; 2835// } 2836tcu::TestCaseGroup* createSelectionControlGroup (tcu::TestContext& testCtx) 2837{ 2838 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_control", "Tests selection control cases")); 2839 vector<CaseParameter> cases; 2840 de::Random rnd (deStringHash(group->getName())); 2841 const int numElements = 100; 2842 vector<float> inputFloats (numElements, 0); 2843 vector<float> outputFloats (numElements, 0); 2844 const StringTemplate shaderTemplate ( 2845 string(s_ShaderPreamble) + 2846 2847 "OpSource GLSL 430\n" 2848 "OpName %main \"main\"\n" 2849 "OpName %id \"gl_GlobalInvocationID\"\n" 2850 2851 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2852 2853 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2854 2855 "%id = OpVariable %uvec3ptr Input\n" 2856 "%zero = OpConstant %i32 0\n" 2857 "%constf1 = OpConstant %f32 1.0\n" 2858 "%constf10 = OpConstant %f32 10.0\n" 2859 2860 "%main = OpFunction %void None %voidf\n" 2861 "%entry = OpLabel\n" 2862 "%idval = OpLoad %uvec3 %id\n" 2863 "%x = OpCompositeExtract %u32 %idval 0\n" 2864 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2865 "%inval = OpLoad %f32 %inloc\n" 2866 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2867 "%cmp_gt = OpFOrdGreaterThan %bool %inval %constf10\n" 2868 2869 " OpSelectionMerge %if_end ${CONTROL}\n" 2870 " OpBranchConditional %cmp_gt %if_true %if_false\n" 2871 "%if_true = OpLabel\n" 2872 "%addf1 = OpFAdd %f32 %inval %constf1\n" 2873 " OpStore %outloc %addf1\n" 2874 " OpBranch %if_end\n" 2875 "%if_false = OpLabel\n" 2876 "%subf1 = OpFSub %f32 %inval %constf1\n" 2877 " OpStore %outloc %subf1\n" 2878 " OpBranch %if_end\n" 2879 "%if_end = OpLabel\n" 2880 " OpReturn\n" 2881 " OpFunctionEnd\n"); 2882 2883 cases.push_back(CaseParameter("none", "None")); 2884 cases.push_back(CaseParameter("flatten", "Flatten")); 2885 cases.push_back(CaseParameter("dont_flatten", "DontFlatten")); 2886 cases.push_back(CaseParameter("flatten_dont_flatten", "DontFlatten|Flatten")); 2887 2888 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements); 2889 2890 for (size_t ndx = 0; ndx < numElements; ++ndx) 2891 outputFloats[ndx] = inputFloats[ndx] + (inputFloats[ndx] > 10.f ? 1.f : -1.f); 2892 2893 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 2894 { 2895 map<string, string> specializations; 2896 ComputeShaderSpec spec; 2897 2898 specializations["CONTROL"] = cases[caseNdx].param; 2899 spec.assembly = shaderTemplate.specialize(specializations); 2900 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 2901 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 2902 spec.numWorkGroups = IVec3(numElements, 1, 1); 2903 2904 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 2905 } 2906 2907 return group.release(); 2908} 2909 2910// Assembly code used for testing function control is based on GLSL source code: 2911// 2912// #version 430 2913// 2914// layout(std140, set = 0, binding = 0) readonly buffer Input { 2915// float elements[]; 2916// } input_data; 2917// layout(std140, set = 0, binding = 1) writeonly buffer Output { 2918// float elements[]; 2919// } output_data; 2920// 2921// float const10() { return 10.f; } 2922// 2923// void main() { 2924// uint x = gl_GlobalInvocationID.x; 2925// output_data.elements[x] = input_data.elements[x] + const10(); 2926// } 2927tcu::TestCaseGroup* createFunctionControlGroup (tcu::TestContext& testCtx) 2928{ 2929 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "function_control", "Tests function control cases")); 2930 vector<CaseParameter> cases; 2931 de::Random rnd (deStringHash(group->getName())); 2932 const int numElements = 100; 2933 vector<float> inputFloats (numElements, 0); 2934 vector<float> outputFloats (numElements, 0); 2935 const StringTemplate shaderTemplate ( 2936 string(s_ShaderPreamble) + 2937 2938 "OpSource GLSL 430\n" 2939 "OpName %main \"main\"\n" 2940 "OpName %func_const10 \"const10(\"\n" 2941 "OpName %id \"gl_GlobalInvocationID\"\n" 2942 2943 "OpDecorate %id BuiltIn GlobalInvocationId\n" 2944 2945 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 2946 2947 "%f32f = OpTypeFunction %f32\n" 2948 "%id = OpVariable %uvec3ptr Input\n" 2949 "%zero = OpConstant %i32 0\n" 2950 "%constf10 = OpConstant %f32 10.0\n" 2951 2952 "%main = OpFunction %void None %voidf\n" 2953 "%entry = OpLabel\n" 2954 "%idval = OpLoad %uvec3 %id\n" 2955 "%x = OpCompositeExtract %u32 %idval 0\n" 2956 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 2957 "%inval = OpLoad %f32 %inloc\n" 2958 "%ret_10 = OpFunctionCall %f32 %func_const10\n" 2959 "%fadd = OpFAdd %f32 %inval %ret_10\n" 2960 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 2961 " OpStore %outloc %fadd\n" 2962 " OpReturn\n" 2963 " OpFunctionEnd\n" 2964 2965 "%func_const10 = OpFunction %f32 ${CONTROL} %f32f\n" 2966 "%label = OpLabel\n" 2967 " OpReturnValue %constf10\n" 2968 " OpFunctionEnd\n"); 2969 2970 cases.push_back(CaseParameter("none", "None")); 2971 cases.push_back(CaseParameter("inline", "Inline")); 2972 cases.push_back(CaseParameter("dont_inline", "DontInline")); 2973 cases.push_back(CaseParameter("pure", "Pure")); 2974 cases.push_back(CaseParameter("const", "Const")); 2975 cases.push_back(CaseParameter("inline_pure", "Inline|Pure")); 2976 cases.push_back(CaseParameter("const_dont_inline", "Const|DontInline")); 2977 cases.push_back(CaseParameter("inline_dont_inline", "Inline|DontInline")); 2978 cases.push_back(CaseParameter("pure_inline_dont_inline", "Pure|Inline|DontInline")); 2979 2980 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements); 2981 2982 for (size_t ndx = 0; ndx < numElements; ++ndx) 2983 outputFloats[ndx] = inputFloats[ndx] + 10.f; 2984 2985 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 2986 { 2987 map<string, string> specializations; 2988 ComputeShaderSpec spec; 2989 2990 specializations["CONTROL"] = cases[caseNdx].param; 2991 spec.assembly = shaderTemplate.specialize(specializations); 2992 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 2993 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 2994 spec.numWorkGroups = IVec3(numElements, 1, 1); 2995 2996 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 2997 } 2998 2999 return group.release(); 3000} 3001 3002tcu::TestCaseGroup* createMemoryAccessGroup (tcu::TestContext& testCtx) 3003{ 3004 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "memory_access", "Tests memory access cases")); 3005 vector<CaseParameter> cases; 3006 de::Random rnd (deStringHash(group->getName())); 3007 const int numElements = 100; 3008 vector<float> inputFloats (numElements, 0); 3009 vector<float> outputFloats (numElements, 0); 3010 const StringTemplate shaderTemplate ( 3011 string(s_ShaderPreamble) + 3012 3013 "OpSource GLSL 430\n" 3014 "OpName %main \"main\"\n" 3015 "OpName %id \"gl_GlobalInvocationID\"\n" 3016 3017 "OpDecorate %id BuiltIn GlobalInvocationId\n" 3018 3019 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 3020 3021 "%f32ptr_f = OpTypePointer Function %f32\n" 3022 3023 "%id = OpVariable %uvec3ptr Input\n" 3024 "%zero = OpConstant %i32 0\n" 3025 "%four = OpConstant %i32 4\n" 3026 3027 "%main = OpFunction %void None %voidf\n" 3028 "%label = OpLabel\n" 3029 "%copy = OpVariable %f32ptr_f Function\n" 3030 "%idval = OpLoad %uvec3 %id ${ACCESS}\n" 3031 "%x = OpCompositeExtract %u32 %idval 0\n" 3032 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 3033 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 3034 " OpCopyMemory %copy %inloc ${ACCESS}\n" 3035 "%val1 = OpLoad %f32 %copy\n" 3036 "%val2 = OpLoad %f32 %inloc\n" 3037 "%add = OpFAdd %f32 %val1 %val2\n" 3038 " OpStore %outloc %add ${ACCESS}\n" 3039 " OpReturn\n" 3040 " OpFunctionEnd\n"); 3041 3042 cases.push_back(CaseParameter("null", "")); 3043 cases.push_back(CaseParameter("none", "None")); 3044 cases.push_back(CaseParameter("volatile", "Volatile")); 3045 cases.push_back(CaseParameter("aligned", "Aligned 4")); 3046 cases.push_back(CaseParameter("nontemporal", "Nontemporal")); 3047 cases.push_back(CaseParameter("aligned_nontemporal", "Aligned|Nontemporal 4")); 3048 cases.push_back(CaseParameter("aligned_volatile", "Volatile|Aligned 4")); 3049 3050 fillRandomScalars(rnd, -100.f, 100.f, &inputFloats[0], numElements); 3051 3052 for (size_t ndx = 0; ndx < numElements; ++ndx) 3053 outputFloats[ndx] = inputFloats[ndx] + inputFloats[ndx]; 3054 3055 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 3056 { 3057 map<string, string> specializations; 3058 ComputeShaderSpec spec; 3059 3060 specializations["ACCESS"] = cases[caseNdx].param; 3061 spec.assembly = shaderTemplate.specialize(specializations); 3062 spec.inputs.push_back(BufferSp(new Float32Buffer(inputFloats))); 3063 spec.outputs.push_back(BufferSp(new Float32Buffer(outputFloats))); 3064 spec.numWorkGroups = IVec3(numElements, 1, 1); 3065 3066 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 3067 } 3068 3069 return group.release(); 3070} 3071 3072// Checks that we can get undefined values for various types, without exercising a computation with it. 3073tcu::TestCaseGroup* createOpUndefGroup (tcu::TestContext& testCtx) 3074{ 3075 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opundef", "Tests the OpUndef instruction")); 3076 vector<CaseParameter> cases; 3077 de::Random rnd (deStringHash(group->getName())); 3078 const int numElements = 100; 3079 vector<float> positiveFloats (numElements, 0); 3080 vector<float> negativeFloats (numElements, 0); 3081 const StringTemplate shaderTemplate ( 3082 string(s_ShaderPreamble) + 3083 3084 "OpSource GLSL 430\n" 3085 "OpName %main \"main\"\n" 3086 "OpName %id \"gl_GlobalInvocationID\"\n" 3087 3088 "OpDecorate %id BuiltIn GlobalInvocationId\n" 3089 3090 + string(s_InputOutputBufferTraits) + string(s_CommonTypes) + string(s_InputOutputBuffer) + 3091 3092 "${TYPE}\n" 3093 3094 "%id = OpVariable %uvec3ptr Input\n" 3095 "%zero = OpConstant %i32 0\n" 3096 3097 "%main = OpFunction %void None %voidf\n" 3098 "%label = OpLabel\n" 3099 3100 "%undef = OpUndef %type\n" 3101 3102 "%idval = OpLoad %uvec3 %id\n" 3103 "%x = OpCompositeExtract %u32 %idval 0\n" 3104 3105 "%inloc = OpAccessChain %f32ptr %indata %zero %x\n" 3106 "%inval = OpLoad %f32 %inloc\n" 3107 "%neg = OpFNegate %f32 %inval\n" 3108 "%outloc = OpAccessChain %f32ptr %outdata %zero %x\n" 3109 " OpStore %outloc %neg\n" 3110 " OpReturn\n" 3111 " OpFunctionEnd\n"); 3112 3113 cases.push_back(CaseParameter("bool", "%type = OpTypeBool")); 3114 cases.push_back(CaseParameter("sint32", "%type = OpTypeInt 32 1")); 3115 cases.push_back(CaseParameter("uint32", "%type = OpTypeInt 32 0")); 3116 cases.push_back(CaseParameter("float32", "%type = OpTypeFloat 32")); 3117 cases.push_back(CaseParameter("vec4float32", "%type = OpTypeVector %f32 4")); 3118 cases.push_back(CaseParameter("vec2uint32", "%type = OpTypeVector %u32 2")); 3119 cases.push_back(CaseParameter("matrix", "%type = OpTypeMatrix %fvec3 3")); 3120 cases.push_back(CaseParameter("image", "%type = OpTypeImage %f32 2D 0 0 0 0 Unknown")); 3121 cases.push_back(CaseParameter("sampler", "%type = OpTypeSampler")); 3122 cases.push_back(CaseParameter("sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 0 Unknown\n" 3123 "%type = OpTypeSampledImage %img")); 3124 cases.push_back(CaseParameter("array", "%100 = OpConstant %u32 100\n" 3125 "%type = OpTypeArray %i32 %100")); 3126 cases.push_back(CaseParameter("runtimearray", "%type = OpTypeRuntimeArray %f32")); 3127 cases.push_back(CaseParameter("struct", "%type = OpTypeStruct %f32 %i32 %u32")); 3128 cases.push_back(CaseParameter("pointer", "%type = OpTypePointer Function %i32")); 3129 3130 fillRandomScalars(rnd, 1.f, 100.f, &positiveFloats[0], numElements); 3131 3132 for (size_t ndx = 0; ndx < numElements; ++ndx) 3133 negativeFloats[ndx] = -positiveFloats[ndx]; 3134 3135 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 3136 { 3137 map<string, string> specializations; 3138 ComputeShaderSpec spec; 3139 3140 specializations["TYPE"] = cases[caseNdx].param; 3141 spec.assembly = shaderTemplate.specialize(specializations); 3142 spec.inputs.push_back(BufferSp(new Float32Buffer(positiveFloats))); 3143 spec.outputs.push_back(BufferSp(new Float32Buffer(negativeFloats))); 3144 spec.numWorkGroups = IVec3(numElements, 1, 1); 3145 3146 group->addChild(new SpvAsmComputeShaderCase(testCtx, cases[caseNdx].name, cases[caseNdx].name, spec)); 3147 } 3148 3149 return group.release(); 3150} 3151typedef std::pair<std::string, VkShaderStageFlagBits> EntryToStage; 3152typedef map<string, vector<EntryToStage> > ModuleMap; 3153typedef map<VkShaderStageFlagBits, vector<deInt32> > StageToSpecConstantMap; 3154 3155// Context for a specific test instantiation. For example, an instantiation 3156// may test colors yellow/magenta/cyan/mauve in a tesselation shader 3157// with an entry point named 'main_to_the_main' 3158struct InstanceContext 3159{ 3160 // Map of modules to what entry_points we care to use from those modules. 3161 ModuleMap moduleMap; 3162 RGBA inputColors[4]; 3163 RGBA outputColors[4]; 3164 // Concrete SPIR-V code to test via boilerplate specialization. 3165 map<string, string> testCodeFragments; 3166 StageToSpecConstantMap specConstants; 3167 bool hasTessellation; 3168 VkShaderStageFlagBits requiredStages; 3169 3170 InstanceContext (const RGBA (&inputs)[4], const RGBA (&outputs)[4], const map<string, string>& testCodeFragments_, const StageToSpecConstantMap& specConstants_) 3171 : testCodeFragments (testCodeFragments_) 3172 , specConstants (specConstants_) 3173 , hasTessellation (false) 3174 , requiredStages (static_cast<VkShaderStageFlagBits>(0)) 3175 { 3176 inputColors[0] = inputs[0]; 3177 inputColors[1] = inputs[1]; 3178 inputColors[2] = inputs[2]; 3179 inputColors[3] = inputs[3]; 3180 3181 outputColors[0] = outputs[0]; 3182 outputColors[1] = outputs[1]; 3183 outputColors[2] = outputs[2]; 3184 outputColors[3] = outputs[3]; 3185 } 3186 3187 InstanceContext (const InstanceContext& other) 3188 : moduleMap (other.moduleMap) 3189 , testCodeFragments (other.testCodeFragments) 3190 , specConstants (other.specConstants) 3191 , hasTessellation (other.hasTessellation) 3192 , requiredStages (other.requiredStages) 3193 { 3194 inputColors[0] = other.inputColors[0]; 3195 inputColors[1] = other.inputColors[1]; 3196 inputColors[2] = other.inputColors[2]; 3197 inputColors[3] = other.inputColors[3]; 3198 3199 outputColors[0] = other.outputColors[0]; 3200 outputColors[1] = other.outputColors[1]; 3201 outputColors[2] = other.outputColors[2]; 3202 outputColors[3] = other.outputColors[3]; 3203 } 3204}; 3205 3206// A description of a shader to be used for a single stage of the graphics pipeline. 3207struct ShaderElement 3208{ 3209 // The module that contains this shader entrypoint. 3210 string moduleName; 3211 3212 // The name of the entrypoint. 3213 string entryName; 3214 3215 // Which shader stage this entry point represents. 3216 VkShaderStageFlagBits stage; 3217 3218 ShaderElement (const string& moduleName_, const string& entryPoint_, VkShaderStageFlagBits shaderStage_) 3219 : moduleName(moduleName_) 3220 , entryName(entryPoint_) 3221 , stage(shaderStage_) 3222 { 3223 } 3224}; 3225 3226void getDefaultColors (RGBA (&colors)[4]) 3227{ 3228 colors[0] = RGBA::white(); 3229 colors[1] = RGBA::red(); 3230 colors[2] = RGBA::green(); 3231 colors[3] = RGBA::blue(); 3232} 3233 3234void getHalfColorsFullAlpha (RGBA (&colors)[4]) 3235{ 3236 colors[0] = RGBA(127, 127, 127, 255); 3237 colors[1] = RGBA(127, 0, 0, 255); 3238 colors[2] = RGBA(0, 127, 0, 255); 3239 colors[3] = RGBA(0, 0, 127, 255); 3240} 3241 3242void getInvertedDefaultColors (RGBA (&colors)[4]) 3243{ 3244 colors[0] = RGBA(0, 0, 0, 255); 3245 colors[1] = RGBA(0, 255, 255, 255); 3246 colors[2] = RGBA(255, 0, 255, 255); 3247 colors[3] = RGBA(255, 255, 0, 255); 3248} 3249 3250// Turns a statically sized array of ShaderElements into an instance-context 3251// by setting up the mapping of modules to their contained shaders and stages. 3252// The inputs and expected outputs are given by inputColors and outputColors 3253template<size_t N> 3254InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, const StageToSpecConstantMap& specConstants) 3255{ 3256 InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants); 3257 for (size_t i = 0; i < N; ++i) 3258 { 3259 ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage)); 3260 ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage); 3261 } 3262 return ctx; 3263} 3264 3265template<size_t N> 3266inline InstanceContext createInstanceContext (const ShaderElement (&elements)[N], RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments) 3267{ 3268 return createInstanceContext(elements, inputColors, outputColors, testCodeFragments, StageToSpecConstantMap()); 3269} 3270 3271// The same as createInstanceContext above, but with default colors. 3272template<size_t N> 3273InstanceContext createInstanceContext (const ShaderElement (&elements)[N], const map<string, string>& testCodeFragments) 3274{ 3275 RGBA defaultColors[4]; 3276 getDefaultColors(defaultColors); 3277 return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments); 3278} 3279 3280// For the current InstanceContext, constructs the required modules and shader stage create infos. 3281void createPipelineShaderStages (const DeviceInterface& vk, const VkDevice vkDevice, InstanceContext& instance, Context& context, vector<ModuleHandleSp>& modules, vector<VkPipelineShaderStageCreateInfo>& createInfos) 3282{ 3283 for (ModuleMap::const_iterator moduleNdx = instance.moduleMap.begin(); moduleNdx != instance.moduleMap.end(); ++moduleNdx) 3284 { 3285 const ModuleHandleSp mod(new Unique<VkShaderModule>(createShaderModule(vk, vkDevice, context.getBinaryCollection().get(moduleNdx->first), 0))); 3286 modules.push_back(ModuleHandleSp(mod)); 3287 for (vector<EntryToStage>::const_iterator shaderNdx = moduleNdx->second.begin(); shaderNdx != moduleNdx->second.end(); ++shaderNdx) 3288 { 3289 const EntryToStage& stage = *shaderNdx; 3290 const VkPipelineShaderStageCreateInfo shaderParam = 3291 { 3292 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType; 3293 DE_NULL, // const void* pNext; 3294 (VkPipelineShaderStageCreateFlags)0, 3295 stage.second, // VkShaderStageFlagBits stage; 3296 **modules.back(), // VkShaderModule module; 3297 stage.first.c_str(), // const char* pName; 3298 (const VkSpecializationInfo*)DE_NULL, 3299 }; 3300 createInfos.push_back(shaderParam); 3301 } 3302 } 3303} 3304 3305#define SPIRV_ASSEMBLY_TYPES \ 3306 "%void = OpTypeVoid\n" \ 3307 "%bool = OpTypeBool\n" \ 3308 \ 3309 "%i32 = OpTypeInt 32 1\n" \ 3310 "%u32 = OpTypeInt 32 0\n" \ 3311 \ 3312 "%f32 = OpTypeFloat 32\n" \ 3313 "%v3f32 = OpTypeVector %f32 3\n" \ 3314 "%v4f32 = OpTypeVector %f32 4\n" \ 3315 \ 3316 "%v4f32_function = OpTypeFunction %v4f32 %v4f32\n" \ 3317 "%fun = OpTypeFunction %void\n" \ 3318 \ 3319 "%ip_f32 = OpTypePointer Input %f32\n" \ 3320 "%ip_i32 = OpTypePointer Input %i32\n" \ 3321 "%ip_v3f32 = OpTypePointer Input %v3f32\n" \ 3322 "%ip_v4f32 = OpTypePointer Input %v4f32\n" \ 3323 \ 3324 "%op_f32 = OpTypePointer Output %f32\n" \ 3325 "%op_v4f32 = OpTypePointer Output %v4f32\n" \ 3326 \ 3327 "%fp_f32 = OpTypePointer Function %f32\n" \ 3328 "%fp_i32 = OpTypePointer Function %i32\n" \ 3329 "%fp_v4f32 = OpTypePointer Function %v4f32\n" 3330 3331#define SPIRV_ASSEMBLY_CONSTANTS \ 3332 "%c_f32_1 = OpConstant %f32 1.0\n" \ 3333 "%c_f32_0 = OpConstant %f32 0.0\n" \ 3334 "%c_f32_0_5 = OpConstant %f32 0.5\n" \ 3335 "%c_f32_n1 = OpConstant %f32 -1.\n" \ 3336 "%c_f32_7 = OpConstant %f32 7.0\n" \ 3337 "%c_f32_8 = OpConstant %f32 8.0\n" \ 3338 "%c_i32_0 = OpConstant %i32 0\n" \ 3339 "%c_i32_1 = OpConstant %i32 1\n" \ 3340 "%c_i32_2 = OpConstant %i32 2\n" \ 3341 "%c_i32_3 = OpConstant %i32 3\n" \ 3342 "%c_i32_4 = OpConstant %i32 4\n" \ 3343 "%c_u32_0 = OpConstant %u32 0\n" \ 3344 "%c_u32_1 = OpConstant %u32 1\n" \ 3345 "%c_u32_2 = OpConstant %u32 2\n" \ 3346 "%c_u32_3 = OpConstant %u32 3\n" \ 3347 "%c_u32_32 = OpConstant %u32 32\n" \ 3348 "%c_u32_4 = OpConstant %u32 4\n" \ 3349 "%c_u32_31_bits = OpConstant %u32 0x7FFFFFFF\n" \ 3350 "%c_v4f32_1_1_1_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" \ 3351 "%c_v4f32_1_0_0_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_1\n" \ 3352 "%c_v4f32_0_5_0_5_0_5_0_5 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5\n" 3353 3354#define SPIRV_ASSEMBLY_ARRAYS \ 3355 "%a1f32 = OpTypeArray %f32 %c_u32_1\n" \ 3356 "%a2f32 = OpTypeArray %f32 %c_u32_2\n" \ 3357 "%a3v4f32 = OpTypeArray %v4f32 %c_u32_3\n" \ 3358 "%a4f32 = OpTypeArray %f32 %c_u32_4\n" \ 3359 "%a32v4f32 = OpTypeArray %v4f32 %c_u32_32\n" \ 3360 "%ip_a3v4f32 = OpTypePointer Input %a3v4f32\n" \ 3361 "%ip_a32v4f32 = OpTypePointer Input %a32v4f32\n" \ 3362 "%op_a2f32 = OpTypePointer Output %a2f32\n" \ 3363 "%op_a3v4f32 = OpTypePointer Output %a3v4f32\n" \ 3364 "%op_a4f32 = OpTypePointer Output %a4f32\n" 3365 3366// Creates vertex-shader assembly by specializing a boilerplate StringTemplate 3367// on fragments, which must (at least) map "testfun" to an OpFunction definition 3368// for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed 3369// with "BP_" to avoid collisions with fragments. 3370// 3371// It corresponds roughly to this GLSL: 3372//; 3373// layout(location = 0) in vec4 position; 3374// layout(location = 1) in vec4 color; 3375// layout(location = 1) out highp vec4 vtxColor; 3376// void main (void) { gl_Position = position; vtxColor = test_func(color); } 3377string makeVertexShaderAssembly(const map<string, string>& fragments) 3378{ 3379// \todo [2015-11-23 awoloszyn] Remove OpName once these have stabalized 3380 static const char vertexShaderBoilerplate[] = 3381 "OpCapability Shader\n" 3382 "OpMemoryModel Logical GLSL450\n" 3383 "OpEntryPoint Vertex %main \"main\" %BP_stream %BP_position %BP_vtx_color %BP_color %BP_gl_VertexID %BP_gl_InstanceID\n" 3384 "${debug:opt}\n" 3385 "OpName %main \"main\"\n" 3386 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n" 3387 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n" 3388 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n" 3389 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n" 3390 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n" 3391 "OpName %test_code \"testfun(vf4;\"\n" 3392 "OpName %BP_stream \"\"\n" 3393 "OpName %BP_position \"position\"\n" 3394 "OpName %BP_vtx_color \"vtxColor\"\n" 3395 "OpName %BP_color \"color\"\n" 3396 "OpName %BP_gl_VertexID \"gl_VertexID\"\n" 3397 "OpName %BP_gl_InstanceID \"gl_InstanceID\"\n" 3398 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n" 3399 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n" 3400 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n" 3401 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n" 3402 "OpDecorate %BP_gl_PerVertex Block\n" 3403 "OpDecorate %BP_position Location 0\n" 3404 "OpDecorate %BP_vtx_color Location 1\n" 3405 "OpDecorate %BP_color Location 1\n" 3406 "OpDecorate %BP_gl_VertexID BuiltIn VertexId\n" 3407 "OpDecorate %BP_gl_InstanceID BuiltIn InstanceId\n" 3408 "${decoration:opt}\n" 3409 SPIRV_ASSEMBLY_TYPES 3410 SPIRV_ASSEMBLY_CONSTANTS 3411 SPIRV_ASSEMBLY_ARRAYS 3412 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3413 "%BP_op_gl_PerVertex = OpTypePointer Output %BP_gl_PerVertex\n" 3414 "%BP_stream = OpVariable %BP_op_gl_PerVertex Output\n" 3415 "%BP_position = OpVariable %ip_v4f32 Input\n" 3416 "%BP_vtx_color = OpVariable %op_v4f32 Output\n" 3417 "%BP_color = OpVariable %ip_v4f32 Input\n" 3418 "%BP_gl_VertexID = OpVariable %ip_i32 Input\n" 3419 "%BP_gl_InstanceID = OpVariable %ip_i32 Input\n" 3420 "${pre_main:opt}\n" 3421 "%main = OpFunction %void None %fun\n" 3422 "%BP_label = OpLabel\n" 3423 "%BP_pos = OpLoad %v4f32 %BP_position\n" 3424 "%BP_gl_pos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n" 3425 "OpStore %BP_gl_pos %BP_pos\n" 3426 "%BP_col = OpLoad %v4f32 %BP_color\n" 3427 "%BP_col_transformed = OpFunctionCall %v4f32 %test_code %BP_col\n" 3428 "OpStore %BP_vtx_color %BP_col_transformed\n" 3429 "OpReturn\n" 3430 "OpFunctionEnd\n" 3431 "${testfun}\n"; 3432 return tcu::StringTemplate(vertexShaderBoilerplate).specialize(fragments); 3433} 3434 3435// Creates tess-control-shader assembly by specializing a boilerplate 3436// StringTemplate on fragments, which must (at least) map "testfun" to an 3437// OpFunction definition for %test_code that takes and returns a %v4f32. 3438// Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments. 3439// 3440// It roughly corresponds to the following GLSL. 3441// 3442// #version 450 3443// layout(vertices = 3) out; 3444// layout(location = 1) in vec4 in_color[]; 3445// layout(location = 1) out vec4 out_color[]; 3446// 3447// void main() { 3448// out_color[gl_InvocationID] = testfun(in_color[gl_InvocationID]); 3449// gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; 3450// if (gl_InvocationID == 0) { 3451// gl_TessLevelOuter[0] = 1.0; 3452// gl_TessLevelOuter[1] = 1.0; 3453// gl_TessLevelOuter[2] = 1.0; 3454// gl_TessLevelInner[0] = 1.0; 3455// } 3456// } 3457string makeTessControlShaderAssembly (const map<string, string>& fragments) 3458{ 3459 static const char tessControlShaderBoilerplate[] = 3460 "OpCapability Tessellation\n" 3461 "OpMemoryModel Logical GLSL450\n" 3462 "OpEntryPoint TessellationControl %BP_main \"main\" %BP_out_color %BP_gl_InvocationID %BP_in_color %BP_gl_out %BP_gl_in %BP_gl_TessLevelOuter %BP_gl_TessLevelInner\n" 3463 "OpExecutionMode %BP_main OutputVertices 3\n" 3464 "${debug:opt}\n" 3465 "OpName %BP_main \"main\"\n" 3466 "OpName %test_code \"testfun(vf4;\"\n" 3467 "OpName %BP_out_color \"out_color\"\n" 3468 "OpName %BP_gl_InvocationID \"gl_InvocationID\"\n" 3469 "OpName %BP_in_color \"in_color\"\n" 3470 "OpName %BP_gl_PerVertex \"gl_PerVertex\"\n" 3471 "OpMemberName %BP_gl_PerVertex 0 \"gl_Position\"\n" 3472 "OpMemberName %BP_gl_PerVertex 1 \"gl_PointSize\"\n" 3473 "OpMemberName %BP_gl_PerVertex 2 \"gl_ClipDistance\"\n" 3474 "OpMemberName %BP_gl_PerVertex 3 \"gl_CullDistance\"\n" 3475 "OpName %BP_gl_out \"gl_out\"\n" 3476 "OpName %BP_gl_PVOut \"gl_PerVertex\"\n" 3477 "OpMemberName %BP_gl_PVOut 0 \"gl_Position\"\n" 3478 "OpMemberName %BP_gl_PVOut 1 \"gl_PointSize\"\n" 3479 "OpMemberName %BP_gl_PVOut 2 \"gl_ClipDistance\"\n" 3480 "OpMemberName %BP_gl_PVOut 3 \"gl_CullDistance\"\n" 3481 "OpName %BP_gl_in \"gl_in\"\n" 3482 "OpName %BP_gl_TessLevelOuter \"gl_TessLevelOuter\"\n" 3483 "OpName %BP_gl_TessLevelInner \"gl_TessLevelInner\"\n" 3484 "OpDecorate %BP_out_color Location 1\n" 3485 "OpDecorate %BP_gl_InvocationID BuiltIn InvocationId\n" 3486 "OpDecorate %BP_in_color Location 1\n" 3487 "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n" 3488 "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n" 3489 "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n" 3490 "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n" 3491 "OpDecorate %BP_gl_PerVertex Block\n" 3492 "OpMemberDecorate %BP_gl_PVOut 0 BuiltIn Position\n" 3493 "OpMemberDecorate %BP_gl_PVOut 1 BuiltIn PointSize\n" 3494 "OpMemberDecorate %BP_gl_PVOut 2 BuiltIn ClipDistance\n" 3495 "OpMemberDecorate %BP_gl_PVOut 3 BuiltIn CullDistance\n" 3496 "OpDecorate %BP_gl_PVOut Block\n" 3497 "OpDecorate %BP_gl_TessLevelOuter Patch\n" 3498 "OpDecorate %BP_gl_TessLevelOuter BuiltIn TessLevelOuter\n" 3499 "OpDecorate %BP_gl_TessLevelInner Patch\n" 3500 "OpDecorate %BP_gl_TessLevelInner BuiltIn TessLevelInner\n" 3501 "${decoration:opt}\n" 3502 SPIRV_ASSEMBLY_TYPES 3503 SPIRV_ASSEMBLY_CONSTANTS 3504 SPIRV_ASSEMBLY_ARRAYS 3505 "%BP_out_color = OpVariable %op_a3v4f32 Output\n" 3506 "%BP_gl_InvocationID = OpVariable %ip_i32 Input\n" 3507 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n" 3508 "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3509 "%BP_a3_gl_PerVertex = OpTypeArray %BP_gl_PerVertex %c_u32_3\n" 3510 "%BP_op_a3_gl_PerVertex = OpTypePointer Output %BP_a3_gl_PerVertex\n" 3511 "%BP_gl_out = OpVariable %BP_op_a3_gl_PerVertex Output\n" 3512 "%BP_gl_PVOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3513 "%BP_a32_gl_PVOut = OpTypeArray %BP_gl_PVOut %c_u32_32\n" 3514 "%BP_ip_a32_gl_PVOut = OpTypePointer Input %BP_a32_gl_PVOut\n" 3515 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PVOut Input\n" 3516 "%BP_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" 3517 "%BP_gl_TessLevelInner = OpVariable %op_a2f32 Output\n" 3518 "${pre_main:opt}\n" 3519 3520 "%BP_main = OpFunction %void None %fun\n" 3521 "%BP_label = OpLabel\n" 3522 3523 "%BP_gl_Invoc = OpLoad %i32 %BP_gl_InvocationID\n" 3524 3525 "%BP_in_col_loc = OpAccessChain %ip_v4f32 %BP_in_color %BP_gl_Invoc\n" 3526 "%BP_out_col_loc = OpAccessChain %op_v4f32 %BP_out_color %BP_gl_Invoc\n" 3527 "%BP_in_col_val = OpLoad %v4f32 %BP_in_col_loc\n" 3528 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_in_col_val\n" 3529 "OpStore %BP_out_col_loc %BP_clr_transformed\n" 3530 3531 "%BP_in_pos_loc = OpAccessChain %ip_v4f32 %BP_gl_in %BP_gl_Invoc %c_i32_0\n" 3532 "%BP_out_pos_loc = OpAccessChain %op_v4f32 %BP_gl_out %BP_gl_Invoc %c_i32_0\n" 3533 "%BP_in_pos_val = OpLoad %v4f32 %BP_in_pos_loc\n" 3534 "OpStore %BP_out_pos_loc %BP_in_pos_val\n" 3535 3536 "%BP_cmp = OpIEqual %bool %BP_gl_Invoc %c_i32_0\n" 3537 "OpSelectionMerge %BP_merge_label None\n" 3538 "OpBranchConditional %BP_cmp %BP_if_label %BP_merge_label\n" 3539 "%BP_if_label = OpLabel\n" 3540 "%BP_gl_TessLevelOuterPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_0\n" 3541 "%BP_gl_TessLevelOuterPos_1 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_1\n" 3542 "%BP_gl_TessLevelOuterPos_2 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_2\n" 3543 "%BP_gl_TessLevelInnerPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelInner %c_i32_0\n" 3544 "OpStore %BP_gl_TessLevelOuterPos_0 %c_f32_1\n" 3545 "OpStore %BP_gl_TessLevelOuterPos_1 %c_f32_1\n" 3546 "OpStore %BP_gl_TessLevelOuterPos_2 %c_f32_1\n" 3547 "OpStore %BP_gl_TessLevelInnerPos_0 %c_f32_1\n" 3548 "OpBranch %BP_merge_label\n" 3549 "%BP_merge_label = OpLabel\n" 3550 "OpReturn\n" 3551 "OpFunctionEnd\n" 3552 "${testfun}\n"; 3553 return tcu::StringTemplate(tessControlShaderBoilerplate).specialize(fragments); 3554} 3555 3556// Creates tess-evaluation-shader assembly by specializing a boilerplate 3557// StringTemplate on fragments, which must (at least) map "testfun" to an 3558// OpFunction definition for %test_code that takes and returns a %v4f32. 3559// Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments. 3560// 3561// It roughly corresponds to the following glsl. 3562// 3563// #version 450 3564// 3565// layout(triangles, equal_spacing, ccw) in; 3566// layout(location = 1) in vec4 in_color[]; 3567// layout(location = 1) out vec4 out_color; 3568// 3569// #define interpolate(val) 3570// vec4(gl_TessCoord.x) * val[0] + vec4(gl_TessCoord.y) * val[1] + 3571// vec4(gl_TessCoord.z) * val[2] 3572// 3573// void main() { 3574// gl_Position = vec4(gl_TessCoord.x) * gl_in[0].gl_Position + 3575// vec4(gl_TessCoord.y) * gl_in[1].gl_Position + 3576// vec4(gl_TessCoord.z) * gl_in[2].gl_Position; 3577// out_color = testfun(interpolate(in_color)); 3578// } 3579string makeTessEvalShaderAssembly(const map<string, string>& fragments) 3580{ 3581 static const char tessEvalBoilerplate[] = 3582 "OpCapability Tessellation\n" 3583 "OpMemoryModel Logical GLSL450\n" 3584 "OpEntryPoint TessellationEvaluation %BP_main \"main\" %BP_stream %BP_gl_TessCoord %BP_gl_in %BP_out_color %BP_in_color\n" 3585 "OpExecutionMode %BP_main Triangles\n" 3586 "OpExecutionMode %BP_main SpacingEqual\n" 3587 "OpExecutionMode %BP_main VertexOrderCcw\n" 3588 "${debug:opt}\n" 3589 "OpName %BP_main \"main\"\n" 3590 "OpName %test_code \"testfun(vf4;\"\n" 3591 "OpName %BP_gl_PerVertexOut \"gl_PerVertex\"\n" 3592 "OpMemberName %BP_gl_PerVertexOut 0 \"gl_Position\"\n" 3593 "OpMemberName %BP_gl_PerVertexOut 1 \"gl_PointSize\"\n" 3594 "OpMemberName %BP_gl_PerVertexOut 2 \"gl_ClipDistance\"\n" 3595 "OpMemberName %BP_gl_PerVertexOut 3 \"gl_CullDistance\"\n" 3596 "OpName %BP_stream \"\"\n" 3597 "OpName %BP_gl_TessCoord \"gl_TessCoord\"\n" 3598 "OpName %BP_gl_PerVertexIn \"gl_PerVertex\"\n" 3599 "OpMemberName %BP_gl_PerVertexIn 0 \"gl_Position\"\n" 3600 "OpMemberName %BP_gl_PerVertexIn 1 \"gl_PointSize\"\n" 3601 "OpMemberName %BP_gl_PerVertexIn 2 \"gl_ClipDistance\"\n" 3602 "OpMemberName %BP_gl_PerVertexIn 3 \"gl_CullDistance\"\n" 3603 "OpName %BP_gl_in \"gl_in\"\n" 3604 "OpName %BP_out_color \"out_color\"\n" 3605 "OpName %BP_in_color \"in_color\"\n" 3606 "OpMemberDecorate %BP_gl_PerVertexOut 0 BuiltIn Position\n" 3607 "OpMemberDecorate %BP_gl_PerVertexOut 1 BuiltIn PointSize\n" 3608 "OpMemberDecorate %BP_gl_PerVertexOut 2 BuiltIn ClipDistance\n" 3609 "OpMemberDecorate %BP_gl_PerVertexOut 3 BuiltIn CullDistance\n" 3610 "OpDecorate %BP_gl_PerVertexOut Block\n" 3611 "OpDecorate %BP_gl_TessCoord BuiltIn TessCoord\n" 3612 "OpMemberDecorate %BP_gl_PerVertexIn 0 BuiltIn Position\n" 3613 "OpMemberDecorate %BP_gl_PerVertexIn 1 BuiltIn PointSize\n" 3614 "OpMemberDecorate %BP_gl_PerVertexIn 2 BuiltIn ClipDistance\n" 3615 "OpMemberDecorate %BP_gl_PerVertexIn 3 BuiltIn CullDistance\n" 3616 "OpDecorate %BP_gl_PerVertexIn Block\n" 3617 "OpDecorate %BP_out_color Location 1\n" 3618 "OpDecorate %BP_in_color Location 1\n" 3619 "${decoration:opt}\n" 3620 SPIRV_ASSEMBLY_TYPES 3621 SPIRV_ASSEMBLY_CONSTANTS 3622 SPIRV_ASSEMBLY_ARRAYS 3623 "%BP_gl_PerVertexOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3624 "%BP_op_gl_PerVertexOut = OpTypePointer Output %BP_gl_PerVertexOut\n" 3625 "%BP_stream = OpVariable %BP_op_gl_PerVertexOut Output\n" 3626 "%BP_gl_TessCoord = OpVariable %ip_v3f32 Input\n" 3627 "%BP_gl_PerVertexIn = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3628 "%BP_a32_gl_PerVertexIn = OpTypeArray %BP_gl_PerVertexIn %c_u32_32\n" 3629 "%BP_ip_a32_gl_PerVertexIn = OpTypePointer Input %BP_a32_gl_PerVertexIn\n" 3630 "%BP_gl_in = OpVariable %BP_ip_a32_gl_PerVertexIn Input\n" 3631 "%BP_out_color = OpVariable %op_v4f32 Output\n" 3632 "%BP_in_color = OpVariable %ip_a32v4f32 Input\n" 3633 "${pre_main:opt}\n" 3634 "%BP_main = OpFunction %void None %fun\n" 3635 "%BP_label = OpLabel\n" 3636 "%BP_gl_TC_0 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_0\n" 3637 "%BP_gl_TC_1 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_1\n" 3638 "%BP_gl_TC_2 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_2\n" 3639 "%BP_gl_in_gl_Pos_0 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n" 3640 "%BP_gl_in_gl_Pos_1 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n" 3641 "%BP_gl_in_gl_Pos_2 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n" 3642 3643 "%BP_gl_OPos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n" 3644 "%BP_in_color_0 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n" 3645 "%BP_in_color_1 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n" 3646 "%BP_in_color_2 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n" 3647 3648 "%BP_TC_W_0 = OpLoad %f32 %BP_gl_TC_0\n" 3649 "%BP_TC_W_1 = OpLoad %f32 %BP_gl_TC_1\n" 3650 "%BP_TC_W_2 = OpLoad %f32 %BP_gl_TC_2\n" 3651 "%BP_v4f32_TC_0 = OpCompositeConstruct %v4f32 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0\n" 3652 "%BP_v4f32_TC_1 = OpCompositeConstruct %v4f32 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1\n" 3653 "%BP_v4f32_TC_2 = OpCompositeConstruct %v4f32 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2\n" 3654 3655 "%BP_gl_IP_0 = OpLoad %v4f32 %BP_gl_in_gl_Pos_0\n" 3656 "%BP_gl_IP_1 = OpLoad %v4f32 %BP_gl_in_gl_Pos_1\n" 3657 "%BP_gl_IP_2 = OpLoad %v4f32 %BP_gl_in_gl_Pos_2\n" 3658 3659 "%BP_IP_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_gl_IP_0\n" 3660 "%BP_IP_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_gl_IP_1\n" 3661 "%BP_IP_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_gl_IP_2\n" 3662 3663 "%BP_pos_sum_0 = OpFAdd %v4f32 %BP_IP_W_0 %BP_IP_W_1\n" 3664 "%BP_pos_sum_1 = OpFAdd %v4f32 %BP_pos_sum_0 %BP_IP_W_2\n" 3665 3666 "OpStore %BP_gl_OPos %BP_pos_sum_1\n" 3667 3668 "%BP_IC_0 = OpLoad %v4f32 %BP_in_color_0\n" 3669 "%BP_IC_1 = OpLoad %v4f32 %BP_in_color_1\n" 3670 "%BP_IC_2 = OpLoad %v4f32 %BP_in_color_2\n" 3671 3672 "%BP_IC_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_IC_0\n" 3673 "%BP_IC_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_IC_1\n" 3674 "%BP_IC_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_IC_2\n" 3675 3676 "%BP_col_sum_0 = OpFAdd %v4f32 %BP_IC_W_0 %BP_IC_W_1\n" 3677 "%BP_col_sum_1 = OpFAdd %v4f32 %BP_col_sum_0 %BP_IC_W_2\n" 3678 3679 "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_col_sum_1\n" 3680 3681 "OpStore %BP_out_color %BP_clr_transformed\n" 3682 "OpReturn\n" 3683 "OpFunctionEnd\n" 3684 "${testfun}\n"; 3685 return tcu::StringTemplate(tessEvalBoilerplate).specialize(fragments); 3686} 3687 3688// Creates geometry-shader assembly by specializing a boilerplate StringTemplate 3689// on fragments, which must (at least) map "testfun" to an OpFunction definition 3690// for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed 3691// with "BP_" to avoid collisions with fragments. 3692// 3693// Derived from this GLSL: 3694// 3695// #version 450 3696// layout(triangles) in; 3697// layout(triangle_strip, max_vertices = 3) out; 3698// 3699// layout(location = 1) in vec4 in_color[]; 3700// layout(location = 1) out vec4 out_color; 3701// 3702// void main() { 3703// gl_Position = gl_in[0].gl_Position; 3704// out_color = test_fun(in_color[0]); 3705// EmitVertex(); 3706// gl_Position = gl_in[1].gl_Position; 3707// out_color = test_fun(in_color[1]); 3708// EmitVertex(); 3709// gl_Position = gl_in[2].gl_Position; 3710// out_color = test_fun(in_color[2]); 3711// EmitVertex(); 3712// EndPrimitive(); 3713// } 3714string makeGeometryShaderAssembly(const map<string, string>& fragments) 3715{ 3716 static const char geometryShaderBoilerplate[] = 3717 "OpCapability Geometry\n" 3718 "OpMemoryModel Logical GLSL450\n" 3719 "OpEntryPoint Geometry %BP_main \"main\" %BP_out_gl_position %BP_gl_in %BP_out_color %BP_in_color\n" 3720 "OpExecutionMode %BP_main Triangles\n" 3721 "OpExecutionMode %BP_main Invocations 0\n" 3722 "OpExecutionMode %BP_main OutputTriangleStrip\n" 3723 "OpExecutionMode %BP_main OutputVertices 3\n" 3724 "${debug:opt}\n" 3725 "OpName %BP_main \"main\"\n" 3726 "OpName %BP_per_vertex_in \"gl_PerVertex\"\n" 3727 "OpMemberName %BP_per_vertex_in 0 \"gl_Position\"\n" 3728 "OpMemberName %BP_per_vertex_in 1 \"gl_PointSize\"\n" 3729 "OpMemberName %BP_per_vertex_in 2 \"gl_ClipDistance\"\n" 3730 "OpMemberName %BP_per_vertex_in 3 \"gl_CullDistance\"\n" 3731 "OpName %BP_gl_in \"gl_in\"\n" 3732 "OpName %BP_out_color \"out_color\"\n" 3733 "OpName %BP_in_color \"in_color\"\n" 3734 "OpName %test_code \"testfun(vf4;\"\n" 3735 "OpDecorate %BP_out_gl_position BuiltIn Position\n" 3736 "OpMemberDecorate %BP_per_vertex_in 0 BuiltIn Position\n" 3737 "OpMemberDecorate %BP_per_vertex_in 1 BuiltIn PointSize\n" 3738 "OpMemberDecorate %BP_per_vertex_in 2 BuiltIn ClipDistance\n" 3739 "OpMemberDecorate %BP_per_vertex_in 3 BuiltIn CullDistance\n" 3740 "OpDecorate %BP_per_vertex_in Block\n" 3741 "OpDecorate %BP_out_color Location 1\n" 3742 "OpDecorate %BP_out_color Stream 0\n" 3743 "OpDecorate %BP_in_color Location 1\n" 3744 "${decoration:opt}\n" 3745 SPIRV_ASSEMBLY_TYPES 3746 SPIRV_ASSEMBLY_CONSTANTS 3747 SPIRV_ASSEMBLY_ARRAYS 3748 "%BP_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 3749 "%BP_a3_per_vertex_in = OpTypeArray %BP_per_vertex_in %c_u32_3\n" 3750 "%BP_ip_a3_per_vertex_in = OpTypePointer Input %BP_a3_per_vertex_in\n" 3751 3752 "%BP_gl_in = OpVariable %BP_ip_a3_per_vertex_in Input\n" 3753 "%BP_out_color = OpVariable %op_v4f32 Output\n" 3754 "%BP_in_color = OpVariable %ip_a3v4f32 Input\n" 3755 "%BP_out_gl_position = OpVariable %op_v4f32 Output\n" 3756 "${pre_main:opt}\n" 3757 3758 "%BP_main = OpFunction %void None %fun\n" 3759 "%BP_label = OpLabel\n" 3760 "%BP_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n" 3761 "%BP_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n" 3762 "%BP_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n" 3763 3764 "%BP_in_position_0 = OpLoad %v4f32 %BP_gl_in_0_gl_position\n" 3765 "%BP_in_position_1 = OpLoad %v4f32 %BP_gl_in_1_gl_position\n" 3766 "%BP_in_position_2 = OpLoad %v4f32 %BP_gl_in_2_gl_position \n" 3767 3768 "%BP_in_color_0_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n" 3769 "%BP_in_color_1_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n" 3770 "%BP_in_color_2_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n" 3771 3772 "%BP_in_color_0 = OpLoad %v4f32 %BP_in_color_0_ptr\n" 3773 "%BP_in_color_1 = OpLoad %v4f32 %BP_in_color_1_ptr\n" 3774 "%BP_in_color_2 = OpLoad %v4f32 %BP_in_color_2_ptr\n" 3775 3776 "%BP_transformed_in_color_0 = OpFunctionCall %v4f32 %test_code %BP_in_color_0\n" 3777 "%BP_transformed_in_color_1 = OpFunctionCall %v4f32 %test_code %BP_in_color_1\n" 3778 "%BP_transformed_in_color_2 = OpFunctionCall %v4f32 %test_code %BP_in_color_2\n" 3779 3780 3781 "OpStore %BP_out_gl_position %BP_in_position_0\n" 3782 "OpStore %BP_out_color %BP_transformed_in_color_0\n" 3783 "OpEmitVertex\n" 3784 3785 "OpStore %BP_out_gl_position %BP_in_position_1\n" 3786 "OpStore %BP_out_color %BP_transformed_in_color_1\n" 3787 "OpEmitVertex\n" 3788 3789 "OpStore %BP_out_gl_position %BP_in_position_2\n" 3790 "OpStore %BP_out_color %BP_transformed_in_color_2\n" 3791 "OpEmitVertex\n" 3792 3793 "OpEndPrimitive\n" 3794 "OpReturn\n" 3795 "OpFunctionEnd\n" 3796 "${testfun}\n"; 3797 return tcu::StringTemplate(geometryShaderBoilerplate).specialize(fragments); 3798} 3799 3800// Creates fragment-shader assembly by specializing a boilerplate StringTemplate 3801// on fragments, which must (at least) map "testfun" to an OpFunction definition 3802// for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed 3803// with "BP_" to avoid collisions with fragments. 3804// 3805// Derived from this GLSL: 3806// 3807// layout(location = 1) in highp vec4 vtxColor; 3808// layout(location = 0) out highp vec4 fragColor; 3809// highp vec4 testfun(highp vec4 x) { return x; } 3810// void main(void) { fragColor = testfun(vtxColor); } 3811// 3812// with modifications including passing vtxColor by value and ripping out 3813// testfun() definition. 3814string makeFragmentShaderAssembly(const map<string, string>& fragments) 3815{ 3816 static const char fragmentShaderBoilerplate[] = 3817 "OpCapability Shader\n" 3818 "OpMemoryModel Logical GLSL450\n" 3819 "OpEntryPoint Fragment %BP_main \"main\" %BP_vtxColor %BP_fragColor\n" 3820 "OpExecutionMode %BP_main OriginUpperLeft\n" 3821 "${debug:opt}\n" 3822 "OpName %BP_main \"main\"\n" 3823 "OpName %BP_fragColor \"fragColor\"\n" 3824 "OpName %BP_vtxColor \"vtxColor\"\n" 3825 "OpName %test_code \"testfun(vf4;\"\n" 3826 "OpDecorate %BP_fragColor Location 0\n" 3827 "OpDecorate %BP_vtxColor Location 1\n" 3828 "${decoration:opt}\n" 3829 SPIRV_ASSEMBLY_TYPES 3830 SPIRV_ASSEMBLY_CONSTANTS 3831 SPIRV_ASSEMBLY_ARRAYS 3832 "%BP_fragColor = OpVariable %op_v4f32 Output\n" 3833 "%BP_vtxColor = OpVariable %ip_v4f32 Input\n" 3834 "${pre_main:opt}\n" 3835 "%BP_main = OpFunction %void None %fun\n" 3836 "%BP_label_main = OpLabel\n" 3837 "%BP_tmp1 = OpLoad %v4f32 %BP_vtxColor\n" 3838 "%BP_tmp2 = OpFunctionCall %v4f32 %test_code %BP_tmp1\n" 3839 "OpStore %BP_fragColor %BP_tmp2\n" 3840 "OpReturn\n" 3841 "OpFunctionEnd\n" 3842 "${testfun}\n"; 3843 return tcu::StringTemplate(fragmentShaderBoilerplate).specialize(fragments); 3844} 3845 3846// Creates fragments that specialize into a simple pass-through shader (of any kind). 3847map<string, string> passthruFragments(void) 3848{ 3849 map<string, string> fragments; 3850 fragments["testfun"] = 3851 // A %test_code function that returns its argument unchanged. 3852 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 3853 "%param1 = OpFunctionParameter %v4f32\n" 3854 "%label_testfun = OpLabel\n" 3855 "OpReturnValue %param1\n" 3856 "OpFunctionEnd\n"; 3857 return fragments; 3858} 3859 3860// Adds shader assembly text to dst.spirvAsmSources for all shader kinds. 3861// Vertex shader gets custom code from context, the rest are pass-through. 3862void addShaderCodeCustomVertex(vk::SourceCollections& dst, InstanceContext context) 3863{ 3864 map<string, string> passthru = passthruFragments(); 3865 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(context.testCodeFragments); 3866 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru); 3867} 3868 3869// Adds shader assembly text to dst.spirvAsmSources for all shader kinds. 3870// Tessellation control shader gets custom code from context, the rest are 3871// pass-through. 3872void addShaderCodeCustomTessControl(vk::SourceCollections& dst, InstanceContext context) 3873{ 3874 map<string, string> passthru = passthruFragments(); 3875 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru); 3876 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(context.testCodeFragments); 3877 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(passthru); 3878 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru); 3879} 3880 3881// Adds shader assembly text to dst.spirvAsmSources for all shader kinds. 3882// Tessellation evaluation shader gets custom code from context, the rest are 3883// pass-through. 3884void addShaderCodeCustomTessEval(vk::SourceCollections& dst, InstanceContext context) 3885{ 3886 map<string, string> passthru = passthruFragments(); 3887 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru); 3888 dst.spirvAsmSources.add("tessc") << makeTessControlShaderAssembly(passthru); 3889 dst.spirvAsmSources.add("tesse") << makeTessEvalShaderAssembly(context.testCodeFragments); 3890 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru); 3891} 3892 3893// Adds shader assembly text to dst.spirvAsmSources for all shader kinds. 3894// Geometry shader gets custom code from context, the rest are pass-through. 3895void addShaderCodeCustomGeometry(vk::SourceCollections& dst, InstanceContext context) 3896{ 3897 map<string, string> passthru = passthruFragments(); 3898 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru); 3899 dst.spirvAsmSources.add("geom") << makeGeometryShaderAssembly(context.testCodeFragments); 3900 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(passthru); 3901} 3902 3903// Adds shader assembly text to dst.spirvAsmSources for all shader kinds. 3904// Fragment shader gets custom code from context, the rest are pass-through. 3905void addShaderCodeCustomFragment(vk::SourceCollections& dst, InstanceContext context) 3906{ 3907 map<string, string> passthru = passthruFragments(); 3908 dst.spirvAsmSources.add("vert") << makeVertexShaderAssembly(passthru); 3909 dst.spirvAsmSources.add("frag") << makeFragmentShaderAssembly(context.testCodeFragments); 3910} 3911 3912void createCombinedModule(vk::SourceCollections& dst, InstanceContext) 3913{ 3914 // \todo [2015-12-07 awoloszyn] Make tessellation / geometry conditional 3915 // \todo [2015-12-07 awoloszyn] Remove OpName and OpMemberName at some point 3916 dst.spirvAsmSources.add("module") << 3917 "OpCapability Shader\n" 3918 "OpCapability Geometry\n" 3919 "OpCapability Tessellation\n" 3920 "OpMemoryModel Logical GLSL450\n" 3921 3922 "OpEntryPoint Vertex %vert_main \"main\" %vert_Position %vert_vtxColor %vert_color %vert_vtxPosition %vert_vertex_id %vert_instance_id\n" 3923 "OpEntryPoint Geometry %geom_main \"main\" %geom_out_gl_position %geom_gl_in %geom_out_color %geom_in_color\n" 3924 "OpEntryPoint TessellationControl %tessc_main \"main\" %tessc_out_color %tessc_gl_InvocationID %tessc_in_color %tessc_out_position %tessc_in_position %tessc_gl_TessLevelOuter %tessc_gl_TessLevelInner\n" 3925 "OpEntryPoint TessellationEvaluation %tesse_main \"main\" %tesse_stream %tesse_gl_tessCoord %tesse_in_position %tesse_out_color %tesse_in_color \n" 3926 "OpEntryPoint Fragment %frag_main \"main\" %frag_vtxColor %frag_fragColor\n" 3927 3928 "OpExecutionMode %geom_main Triangles\n" 3929 "OpExecutionMode %geom_main Invocations 0\n" 3930 "OpExecutionMode %geom_main OutputTriangleStrip\n" 3931 "OpExecutionMode %geom_main OutputVertices 3\n" 3932 3933 "OpExecutionMode %tessc_main OutputVertices 3\n" 3934 3935 "OpExecutionMode %tesse_main Triangles\n" 3936 3937 "OpExecutionMode %frag_main OriginUpperLeft\n" 3938 3939 "; Vertex decorations\n" 3940 "OpName %vert_main \"main\"\n" 3941 "OpName %vert_vtxPosition \"vtxPosition\"\n" 3942 "OpName %vert_Position \"position\"\n" 3943 "OpName %vert_vtxColor \"vtxColor\"\n" 3944 "OpName %vert_color \"color\"\n" 3945 "OpName %vert_vertex_id \"gl_VertexID\"\n" 3946 "OpName %vert_instance_id \"gl_InstanceID\"\n" 3947 "OpDecorate %vert_vtxPosition Location 2\n" 3948 "OpDecorate %vert_Position Location 0\n" 3949 "OpDecorate %vert_vtxColor Location 1\n" 3950 "OpDecorate %vert_color Location 1\n" 3951 "OpDecorate %vert_vertex_id BuiltIn VertexId\n" 3952 "OpDecorate %vert_instance_id BuiltIn InstanceId\n" 3953 3954 "; Geometry decorations\n" 3955 "OpName %geom_main \"main\"\n" 3956 "OpName %geom_per_vertex_in \"gl_PerVertex\"\n" 3957 "OpMemberName %geom_per_vertex_in 0 \"gl_Position\"\n" 3958 "OpMemberName %geom_per_vertex_in 1 \"gl_PointSize\"\n" 3959 "OpMemberName %geom_per_vertex_in 2 \"gl_ClipDistance\"\n" 3960 "OpMemberName %geom_per_vertex_in 3 \"gl_CullDistance\"\n" 3961 "OpName %geom_gl_in \"gl_in\"\n" 3962 "OpName %geom_out_color \"out_color\"\n" 3963 "OpName %geom_in_color \"in_color\"\n" 3964 "OpDecorate %geom_out_gl_position BuiltIn Position\n" 3965 "OpMemberDecorate %geom_per_vertex_in 0 BuiltIn Position\n" 3966 "OpMemberDecorate %geom_per_vertex_in 1 BuiltIn PointSize\n" 3967 "OpMemberDecorate %geom_per_vertex_in 2 BuiltIn ClipDistance\n" 3968 "OpMemberDecorate %geom_per_vertex_in 3 BuiltIn CullDistance\n" 3969 "OpDecorate %geom_per_vertex_in Block\n" 3970 "OpDecorate %geom_out_color Location 1\n" 3971 "OpDecorate %geom_out_color Stream 0\n" 3972 "OpDecorate %geom_in_color Location 1\n" 3973 3974 "; Tessellation Control decorations\n" 3975 "OpName %tessc_main \"main\"\n" 3976 "OpName %tessc_out_color \"out_color\"\n" 3977 "OpName %tessc_gl_InvocationID \"gl_InvocationID\"\n" 3978 "OpName %tessc_in_color \"in_color\"\n" 3979 "OpName %tessc_out_position \"out_position\"\n" 3980 "OpName %tessc_in_position \"in_position\"\n" 3981 "OpName %tessc_gl_TessLevelOuter \"gl_TessLevelOuter\"\n" 3982 "OpName %tessc_gl_TessLevelInner \"gl_TessLevelInner\"\n" 3983 "OpDecorate %tessc_out_color Location 1\n" 3984 "OpDecorate %tessc_gl_InvocationID BuiltIn InvocationId\n" 3985 "OpDecorate %tessc_in_color Location 1\n" 3986 "OpDecorate %tessc_out_position Location 2\n" 3987 "OpDecorate %tessc_in_position Location 2\n" 3988 "OpDecorate %tessc_gl_TessLevelOuter Patch\n" 3989 "OpDecorate %tessc_gl_TessLevelOuter BuiltIn TessLevelOuter\n" 3990 "OpDecorate %tessc_gl_TessLevelInner Patch\n" 3991 "OpDecorate %tessc_gl_TessLevelInner BuiltIn TessLevelInner\n" 3992 3993 "; Tessellation Evaluation decorations\n" 3994 "OpName %tesse_main \"main\"\n" 3995 "OpName %tesse_per_vertex_out \"gl_PerVertex\"\n" 3996 "OpMemberName %tesse_per_vertex_out 0 \"gl_Position\"\n" 3997 "OpMemberName %tesse_per_vertex_out 1 \"gl_PointSize\"\n" 3998 "OpMemberName %tesse_per_vertex_out 2 \"gl_ClipDistance\"\n" 3999 "OpMemberName %tesse_per_vertex_out 3 \"gl_CullDistance\"\n" 4000 "OpName %tesse_stream \"\"\n" 4001 "OpName %tesse_gl_tessCoord \"gl_TessCoord\"\n" 4002 "OpName %tesse_in_position \"in_position\"\n" 4003 "OpName %tesse_out_color \"out_color\"\n" 4004 "OpName %tesse_in_color \"in_color\"\n" 4005 "OpMemberDecorate %tesse_per_vertex_out 0 BuiltIn Position\n" 4006 "OpMemberDecorate %tesse_per_vertex_out 1 BuiltIn PointSize\n" 4007 "OpMemberDecorate %tesse_per_vertex_out 2 BuiltIn ClipDistance\n" 4008 "OpMemberDecorate %tesse_per_vertex_out 3 BuiltIn CullDistance\n" 4009 "OpDecorate %tesse_per_vertex_out Block\n" 4010 "OpDecorate %tesse_gl_tessCoord BuiltIn TessCoord\n" 4011 "OpDecorate %tesse_in_position Location 2\n" 4012 "OpDecorate %tesse_out_color Location 1\n" 4013 "OpDecorate %tesse_in_color Location 1\n" 4014 4015 "; Fragment decorations\n" 4016 "OpName %frag_main \"main\"\n" 4017 "OpName %frag_fragColor \"fragColor\"\n" 4018 "OpName %frag_vtxColor \"vtxColor\"\n" 4019 "OpDecorate %frag_fragColor Location 0\n" 4020 "OpDecorate %frag_vtxColor Location 1\n" 4021 4022 SPIRV_ASSEMBLY_TYPES 4023 SPIRV_ASSEMBLY_CONSTANTS 4024 SPIRV_ASSEMBLY_ARRAYS 4025 4026 "; Vertex Variables\n" 4027 "%vert_vtxPosition = OpVariable %op_v4f32 Output\n" 4028 "%vert_Position = OpVariable %ip_v4f32 Input\n" 4029 "%vert_vtxColor = OpVariable %op_v4f32 Output\n" 4030 "%vert_color = OpVariable %ip_v4f32 Input\n" 4031 "%vert_vertex_id = OpVariable %ip_i32 Input\n" 4032 "%vert_instance_id = OpVariable %ip_i32 Input\n" 4033 4034 "; Geometry Variables\n" 4035 "%geom_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 4036 "%geom_a3_per_vertex_in = OpTypeArray %geom_per_vertex_in %c_u32_3\n" 4037 "%geom_ip_a3_per_vertex_in = OpTypePointer Input %geom_a3_per_vertex_in\n" 4038 "%geom_gl_in = OpVariable %geom_ip_a3_per_vertex_in Input\n" 4039 "%geom_out_color = OpVariable %op_v4f32 Output\n" 4040 "%geom_in_color = OpVariable %ip_a3v4f32 Input\n" 4041 "%geom_out_gl_position = OpVariable %op_v4f32 Output\n" 4042 4043 "; Tessellation Control Variables\n" 4044 "%tessc_out_color = OpVariable %op_a3v4f32 Output\n" 4045 "%tessc_gl_InvocationID = OpVariable %ip_i32 Input\n" 4046 "%tessc_in_color = OpVariable %ip_a32v4f32 Input\n" 4047 "%tessc_out_position = OpVariable %op_a3v4f32 Output\n" 4048 "%tessc_in_position = OpVariable %ip_a32v4f32 Input\n" 4049 "%tessc_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" 4050 "%tessc_gl_TessLevelInner = OpVariable %op_a2f32 Output\n" 4051 4052 "; Tessellation Evaluation Decorations\n" 4053 "%tesse_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 4054 "%tesse_op_per_vertex_out = OpTypePointer Output %tesse_per_vertex_out\n" 4055 "%tesse_stream = OpVariable %tesse_op_per_vertex_out Output\n" 4056 "%tesse_gl_tessCoord = OpVariable %ip_v3f32 Input\n" 4057 "%tesse_in_position = OpVariable %ip_a32v4f32 Input\n" 4058 "%tesse_out_color = OpVariable %op_v4f32 Output\n" 4059 "%tesse_in_color = OpVariable %ip_a32v4f32 Input\n" 4060 4061 "; Fragment Variables\n" 4062 "%frag_fragColor = OpVariable %op_v4f32 Output\n" 4063 "%frag_vtxColor = OpVariable %ip_v4f32 Input\n" 4064 4065 "; Vertex Entry\n" 4066 "%vert_main = OpFunction %void None %fun\n" 4067 "%vert_label = OpLabel\n" 4068 "%vert_tmp_position = OpLoad %v4f32 %vert_Position\n" 4069 "OpStore %vert_vtxPosition %vert_tmp_position\n" 4070 "%vert_tmp_color = OpLoad %v4f32 %vert_color\n" 4071 "OpStore %vert_vtxColor %vert_tmp_color\n" 4072 "OpReturn\n" 4073 "OpFunctionEnd\n" 4074 4075 "; Geometry Entry\n" 4076 "%geom_main = OpFunction %void None %fun\n" 4077 "%geom_label = OpLabel\n" 4078 "%geom_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_0 %c_i32_0\n" 4079 "%geom_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_1 %c_i32_0\n" 4080 "%geom_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_2 %c_i32_0\n" 4081 "%geom_in_position_0 = OpLoad %v4f32 %geom_gl_in_0_gl_position\n" 4082 "%geom_in_position_1 = OpLoad %v4f32 %geom_gl_in_1_gl_position\n" 4083 "%geom_in_position_2 = OpLoad %v4f32 %geom_gl_in_2_gl_position \n" 4084 "%geom_in_color_0_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_0\n" 4085 "%geom_in_color_1_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_1\n" 4086 "%geom_in_color_2_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_2\n" 4087 "%geom_in_color_0 = OpLoad %v4f32 %geom_in_color_0_ptr\n" 4088 "%geom_in_color_1 = OpLoad %v4f32 %geom_in_color_1_ptr\n" 4089 "%geom_in_color_2 = OpLoad %v4f32 %geom_in_color_2_ptr\n" 4090 "OpStore %geom_out_gl_position %geom_in_position_0\n" 4091 "OpStore %geom_out_color %geom_in_color_0\n" 4092 "OpEmitVertex\n" 4093 "OpStore %geom_out_gl_position %geom_in_position_1\n" 4094 "OpStore %geom_out_color %geom_in_color_1\n" 4095 "OpEmitVertex\n" 4096 "OpStore %geom_out_gl_position %geom_in_position_2\n" 4097 "OpStore %geom_out_color %geom_in_color_2\n" 4098 "OpEmitVertex\n" 4099 "OpEndPrimitive\n" 4100 "OpReturn\n" 4101 "OpFunctionEnd\n" 4102 4103 "; Tessellation Control Entry\n" 4104 "%tessc_main = OpFunction %void None %fun\n" 4105 "%tessc_label = OpLabel\n" 4106 "%tessc_invocation_id = OpLoad %i32 %tessc_gl_InvocationID\n" 4107 "%tessc_in_color_ptr = OpAccessChain %ip_v4f32 %tessc_in_color %tessc_invocation_id\n" 4108 "%tessc_in_position_ptr = OpAccessChain %ip_v4f32 %tessc_in_position %tessc_invocation_id\n" 4109 "%tessc_in_color_val = OpLoad %v4f32 %tessc_in_color_ptr\n" 4110 "%tessc_in_position_val = OpLoad %v4f32 %tessc_in_position_ptr\n" 4111 "%tessc_out_color_ptr = OpAccessChain %op_v4f32 %tessc_out_color %tessc_invocation_id\n" 4112 "%tessc_out_position_ptr = OpAccessChain %op_v4f32 %tessc_out_position %tessc_invocation_id\n" 4113 "OpStore %tessc_out_color_ptr %tessc_in_color_val\n" 4114 "OpStore %tessc_out_position_ptr %tessc_in_position_val\n" 4115 "%tessc_is_first_invocation = OpIEqual %bool %tessc_invocation_id %c_i32_0\n" 4116 "OpSelectionMerge %tessc_merge_label None\n" 4117 "OpBranchConditional %tessc_is_first_invocation %tessc_first_invocation %tessc_merge_label\n" 4118 "%tessc_first_invocation = OpLabel\n" 4119 "%tessc_tess_outer_0 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_0\n" 4120 "%tessc_tess_outer_1 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_1\n" 4121 "%tessc_tess_outer_2 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_2\n" 4122 "%tessc_tess_inner = OpAccessChain %op_f32 %tessc_gl_TessLevelInner %c_i32_0\n" 4123 "OpStore %tessc_tess_outer_0 %c_f32_1\n" 4124 "OpStore %tessc_tess_outer_1 %c_f32_1\n" 4125 "OpStore %tessc_tess_outer_2 %c_f32_1\n" 4126 "OpStore %tessc_tess_inner %c_f32_1\n" 4127 "OpBranch %tessc_merge_label\n" 4128 "%tessc_merge_label = OpLabel\n" 4129 "OpReturn\n" 4130 "OpFunctionEnd\n" 4131 4132 "; Tessellation Evaluation Entry\n" 4133 "%tesse_main = OpFunction %void None %fun\n" 4134 "%tesse_label = OpLabel\n" 4135 "%tesse_tc_0_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_0\n" 4136 "%tesse_tc_1_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_1\n" 4137 "%tesse_tc_2_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_2\n" 4138 "%tesse_tc_0 = OpLoad %f32 %tesse_tc_0_ptr\n" 4139 "%tesse_tc_1 = OpLoad %f32 %tesse_tc_1_ptr\n" 4140 "%tesse_tc_2 = OpLoad %f32 %tesse_tc_2_ptr\n" 4141 "%tesse_in_pos_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_0\n" 4142 "%tesse_in_pos_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_1\n" 4143 "%tesse_in_pos_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_2\n" 4144 "%tesse_in_pos_0 = OpLoad %v4f32 %tesse_in_pos_0_ptr\n" 4145 "%tesse_in_pos_1 = OpLoad %v4f32 %tesse_in_pos_1_ptr\n" 4146 "%tesse_in_pos_2 = OpLoad %v4f32 %tesse_in_pos_2_ptr\n" 4147 "%tesse_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_pos_0\n" 4148 "%tesse_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_pos_1\n" 4149 "%tesse_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_pos_2\n" 4150 "%tesse_out_pos_ptr = OpAccessChain %op_v4f32 %tesse_stream %c_i32_0\n" 4151 "%tesse_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse_in_pos_0_weighted %tesse_in_pos_1_weighted\n" 4152 "%tesse_computed_out = OpFAdd %v4f32 %tesse_in_pos_0_plus_pos_1 %tesse_in_pos_2_weighted\n" 4153 "OpStore %tesse_out_pos_ptr %tesse_computed_out\n" 4154 "%tesse_in_clr_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_0\n" 4155 "%tesse_in_clr_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_1\n" 4156 "%tesse_in_clr_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_2\n" 4157 "%tesse_in_clr_0 = OpLoad %v4f32 %tesse_in_clr_0_ptr\n" 4158 "%tesse_in_clr_1 = OpLoad %v4f32 %tesse_in_clr_1_ptr\n" 4159 "%tesse_in_clr_2 = OpLoad %v4f32 %tesse_in_clr_2_ptr\n" 4160 "%tesse_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_0 %tesse_in_clr_0\n" 4161 "%tesse_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_1 %tesse_in_clr_1\n" 4162 "%tesse_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse_tc_2 %tesse_in_clr_2\n" 4163 "%tesse_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse_in_clr_0_weighted %tesse_in_clr_1_weighted\n" 4164 "%tesse_computed_clr = OpFAdd %v4f32 %tesse_in_clr_0_plus_col_1 %tesse_in_clr_2_weighted\n" 4165 "OpStore %tesse_out_color %tesse_computed_clr\n" 4166 "OpReturn\n" 4167 "OpFunctionEnd\n" 4168 4169 "; Fragment Entry\n" 4170 "%frag_main = OpFunction %void None %fun\n" 4171 "%frag_label_main = OpLabel\n" 4172 "%frag_tmp1 = OpLoad %v4f32 %frag_vtxColor\n" 4173 "OpStore %frag_fragColor %frag_tmp1\n" 4174 "OpReturn\n" 4175 "OpFunctionEnd\n"; 4176} 4177 4178// This has two shaders of each stage. The first 4179// is a passthrough, the second inverts the color. 4180void createMultipleEntries(vk::SourceCollections& dst, InstanceContext) 4181{ 4182 dst.spirvAsmSources.add("vert") << 4183 // This module contains 2 vertex shaders. One that is a passthrough 4184 // and a second that inverts the color of the output (1.0 - color). 4185 "OpCapability Shader\n" 4186 "OpMemoryModel Logical GLSL450\n" 4187 "OpEntryPoint Vertex %main \"vert1\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n" 4188 "OpEntryPoint Vertex %main2 \"vert2\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n" 4189 4190 "OpName %main \"frag1\"\n" 4191 "OpName %main2 \"frag2\"\n" 4192 "OpName %vtxPosition \"vtxPosition\"\n" 4193 "OpName %Position \"position\"\n" 4194 "OpName %vtxColor \"vtxColor\"\n" 4195 "OpName %color \"color\"\n" 4196 "OpName %vertex_id \"gl_VertexID\"\n" 4197 "OpName %instance_id \"gl_InstanceID\"\n" 4198 4199 "OpDecorate %vtxPosition Location 2\n" 4200 "OpDecorate %Position Location 0\n" 4201 "OpDecorate %vtxColor Location 1\n" 4202 "OpDecorate %color Location 1\n" 4203 "OpDecorate %vertex_id BuiltIn VertexId\n" 4204 "OpDecorate %instance_id BuiltIn InstanceId\n" 4205 SPIRV_ASSEMBLY_TYPES 4206 SPIRV_ASSEMBLY_CONSTANTS 4207 SPIRV_ASSEMBLY_ARRAYS 4208 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 4209 "%vtxPosition = OpVariable %op_v4f32 Output\n" 4210 "%Position = OpVariable %ip_v4f32 Input\n" 4211 "%vtxColor = OpVariable %op_v4f32 Output\n" 4212 "%color = OpVariable %ip_v4f32 Input\n" 4213 "%vertex_id = OpVariable %ip_i32 Input\n" 4214 "%instance_id = OpVariable %ip_i32 Input\n" 4215 4216 "%main = OpFunction %void None %fun\n" 4217 "%label = OpLabel\n" 4218 "%tmp_position = OpLoad %v4f32 %Position\n" 4219 "OpStore %vtxPosition %tmp_position\n" 4220 "%tmp_color = OpLoad %v4f32 %color\n" 4221 "OpStore %vtxColor %tmp_color\n" 4222 "OpReturn\n" 4223 "OpFunctionEnd\n" 4224 4225 "%main2 = OpFunction %void None %fun\n" 4226 "%label2 = OpLabel\n" 4227 "%tmp_position2 = OpLoad %v4f32 %Position\n" 4228 "OpStore %vtxPosition %tmp_position2\n" 4229 "%tmp_color2 = OpLoad %v4f32 %color\n" 4230 "%tmp_color3 = OpFSub %v4f32 %cval %tmp_color2\n" 4231 "OpStore %vtxColor %tmp_color3\n" 4232 "OpReturn\n" 4233 "OpFunctionEnd\n"; 4234 4235 dst.spirvAsmSources.add("frag") << 4236 // This is a single module that contains 2 fragment shaders. 4237 // One that passes color through and the other that inverts the output 4238 // color (1.0 - color). 4239 "OpCapability Shader\n" 4240 "OpMemoryModel Logical GLSL450\n" 4241 "OpEntryPoint Fragment %main \"frag1\" %vtxColor %fragColor\n" 4242 "OpEntryPoint Fragment %main2 \"frag2\" %vtxColor %fragColor\n" 4243 "OpExecutionMode %main OriginUpperLeft\n" 4244 "OpExecutionMode %main2 OriginUpperLeft\n" 4245 4246 "OpName %main \"frag1\"\n" 4247 "OpName %main2 \"frag2\"\n" 4248 "OpName %fragColor \"fragColor\"\n" 4249 "OpName %vtxColor \"vtxColor\"\n" 4250 "OpDecorate %fragColor Location 0\n" 4251 "OpDecorate %vtxColor Location 1\n" 4252 SPIRV_ASSEMBLY_TYPES 4253 SPIRV_ASSEMBLY_CONSTANTS 4254 SPIRV_ASSEMBLY_ARRAYS 4255 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 4256 "%fragColor = OpVariable %op_v4f32 Output\n" 4257 "%vtxColor = OpVariable %ip_v4f32 Input\n" 4258 4259 "%main = OpFunction %void None %fun\n" 4260 "%label_main = OpLabel\n" 4261 "%tmp1 = OpLoad %v4f32 %vtxColor\n" 4262 "OpStore %fragColor %tmp1\n" 4263 "OpReturn\n" 4264 "OpFunctionEnd\n" 4265 4266 "%main2 = OpFunction %void None %fun\n" 4267 "%label_main2 = OpLabel\n" 4268 "%tmp2 = OpLoad %v4f32 %vtxColor\n" 4269 "%tmp3 = OpFSub %v4f32 %cval %tmp2\n" 4270 "OpStore %fragColor %tmp3\n" 4271 "OpReturn\n" 4272 "OpFunctionEnd\n"; 4273 4274 dst.spirvAsmSources.add("geom") << 4275 "OpCapability Geometry\n" 4276 "OpMemoryModel Logical GLSL450\n" 4277 "OpEntryPoint Geometry %geom1_main \"geom1\" %out_gl_position %gl_in %out_color %in_color\n" 4278 "OpEntryPoint Geometry %geom2_main \"geom2\" %out_gl_position %gl_in %out_color %in_color\n" 4279 "OpExecutionMode %geom1_main Triangles\n" 4280 "OpExecutionMode %geom2_main Triangles\n" 4281 "OpExecutionMode %geom1_main Invocations 0\n" 4282 "OpExecutionMode %geom2_main Invocations 0\n" 4283 "OpExecutionMode %geom1_main OutputTriangleStrip\n" 4284 "OpExecutionMode %geom2_main OutputTriangleStrip\n" 4285 "OpExecutionMode %geom1_main OutputVertices 3\n" 4286 "OpExecutionMode %geom2_main OutputVertices 3\n" 4287 "OpName %geom1_main \"geom1\"\n" 4288 "OpName %geom2_main \"geom2\"\n" 4289 "OpName %per_vertex_in \"gl_PerVertex\"\n" 4290 "OpMemberName %per_vertex_in 0 \"gl_Position\"\n" 4291 "OpMemberName %per_vertex_in 1 \"gl_PointSize\"\n" 4292 "OpMemberName %per_vertex_in 2 \"gl_ClipDistance\"\n" 4293 "OpMemberName %per_vertex_in 3 \"gl_CullDistance\"\n" 4294 "OpName %gl_in \"gl_in\"\n" 4295 "OpName %out_color \"out_color\"\n" 4296 "OpName %in_color \"in_color\"\n" 4297 "OpDecorate %out_gl_position BuiltIn Position\n" 4298 "OpMemberDecorate %per_vertex_in 0 BuiltIn Position\n" 4299 "OpMemberDecorate %per_vertex_in 1 BuiltIn PointSize\n" 4300 "OpMemberDecorate %per_vertex_in 2 BuiltIn ClipDistance\n" 4301 "OpMemberDecorate %per_vertex_in 3 BuiltIn CullDistance\n" 4302 "OpDecorate %per_vertex_in Block\n" 4303 "OpDecorate %out_color Location 1\n" 4304 "OpDecorate %out_color Stream 0\n" 4305 "OpDecorate %in_color Location 1\n" 4306 SPIRV_ASSEMBLY_TYPES 4307 SPIRV_ASSEMBLY_CONSTANTS 4308 SPIRV_ASSEMBLY_ARRAYS 4309 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 4310 "%per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 4311 "%a3_per_vertex_in = OpTypeArray %per_vertex_in %c_u32_3\n" 4312 "%ip_a3_per_vertex_in = OpTypePointer Input %a3_per_vertex_in\n" 4313 "%gl_in = OpVariable %ip_a3_per_vertex_in Input\n" 4314 "%out_color = OpVariable %op_v4f32 Output\n" 4315 "%in_color = OpVariable %ip_a3v4f32 Input\n" 4316 "%out_gl_position = OpVariable %op_v4f32 Output\n" 4317 4318 "%geom1_main = OpFunction %void None %fun\n" 4319 "%geom1_label = OpLabel\n" 4320 "%geom1_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n" 4321 "%geom1_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n" 4322 "%geom1_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n" 4323 "%geom1_in_position_0 = OpLoad %v4f32 %geom1_gl_in_0_gl_position\n" 4324 "%geom1_in_position_1 = OpLoad %v4f32 %geom1_gl_in_1_gl_position\n" 4325 "%geom1_in_position_2 = OpLoad %v4f32 %geom1_gl_in_2_gl_position \n" 4326 "%geom1_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" 4327 "%geom1_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" 4328 "%geom1_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" 4329 "%geom1_in_color_0 = OpLoad %v4f32 %geom1_in_color_0_ptr\n" 4330 "%geom1_in_color_1 = OpLoad %v4f32 %geom1_in_color_1_ptr\n" 4331 "%geom1_in_color_2 = OpLoad %v4f32 %geom1_in_color_2_ptr\n" 4332 "OpStore %out_gl_position %geom1_in_position_0\n" 4333 "OpStore %out_color %geom1_in_color_0\n" 4334 "OpEmitVertex\n" 4335 "OpStore %out_gl_position %geom1_in_position_1\n" 4336 "OpStore %out_color %geom1_in_color_1\n" 4337 "OpEmitVertex\n" 4338 "OpStore %out_gl_position %geom1_in_position_2\n" 4339 "OpStore %out_color %geom1_in_color_2\n" 4340 "OpEmitVertex\n" 4341 "OpEndPrimitive\n" 4342 "OpReturn\n" 4343 "OpFunctionEnd\n" 4344 4345 "%geom2_main = OpFunction %void None %fun\n" 4346 "%geom2_label = OpLabel\n" 4347 "%geom2_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n" 4348 "%geom2_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n" 4349 "%geom2_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n" 4350 "%geom2_in_position_0 = OpLoad %v4f32 %geom2_gl_in_0_gl_position\n" 4351 "%geom2_in_position_1 = OpLoad %v4f32 %geom2_gl_in_1_gl_position\n" 4352 "%geom2_in_position_2 = OpLoad %v4f32 %geom2_gl_in_2_gl_position \n" 4353 "%geom2_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" 4354 "%geom2_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" 4355 "%geom2_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" 4356 "%geom2_in_color_0 = OpLoad %v4f32 %geom2_in_color_0_ptr\n" 4357 "%geom2_in_color_1 = OpLoad %v4f32 %geom2_in_color_1_ptr\n" 4358 "%geom2_in_color_2 = OpLoad %v4f32 %geom2_in_color_2_ptr\n" 4359 "%geom2_transformed_in_color_0 = OpFSub %v4f32 %cval %geom2_in_color_0\n" 4360 "%geom2_transformed_in_color_1 = OpFSub %v4f32 %cval %geom2_in_color_1\n" 4361 "%geom2_transformed_in_color_2 = OpFSub %v4f32 %cval %geom2_in_color_2\n" 4362 "OpStore %out_gl_position %geom2_in_position_0\n" 4363 "OpStore %out_color %geom2_transformed_in_color_0\n" 4364 "OpEmitVertex\n" 4365 "OpStore %out_gl_position %geom2_in_position_1\n" 4366 "OpStore %out_color %geom2_transformed_in_color_1\n" 4367 "OpEmitVertex\n" 4368 "OpStore %out_gl_position %geom2_in_position_2\n" 4369 "OpStore %out_color %geom2_transformed_in_color_2\n" 4370 "OpEmitVertex\n" 4371 "OpEndPrimitive\n" 4372 "OpReturn\n" 4373 "OpFunctionEnd\n"; 4374 4375 dst.spirvAsmSources.add("tessc") << 4376 "OpCapability Tessellation\n" 4377 "OpMemoryModel Logical GLSL450\n" 4378 "OpEntryPoint TessellationControl %tessc1_main \"tessc1\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n" 4379 "OpEntryPoint TessellationControl %tessc2_main \"tessc2\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n" 4380 "OpExecutionMode %tessc1_main OutputVertices 3\n" 4381 "OpExecutionMode %tessc2_main OutputVertices 3\n" 4382 "OpName %tessc1_main \"tessc1\"\n" 4383 "OpName %tessc2_main \"tessc2\"\n" 4384 "OpName %out_color \"out_color\"\n" 4385 "OpName %gl_InvocationID \"gl_InvocationID\"\n" 4386 "OpName %in_color \"in_color\"\n" 4387 "OpName %out_position \"out_position\"\n" 4388 "OpName %in_position \"in_position\"\n" 4389 "OpName %gl_TessLevelOuter \"gl_TessLevelOuter\"\n" 4390 "OpName %gl_TessLevelInner \"gl_TessLevelInner\"\n" 4391 "OpDecorate %out_color Location 1\n" 4392 "OpDecorate %gl_InvocationID BuiltIn InvocationId\n" 4393 "OpDecorate %in_color Location 1\n" 4394 "OpDecorate %out_position Location 2\n" 4395 "OpDecorate %in_position Location 2\n" 4396 "OpDecorate %gl_TessLevelOuter Patch\n" 4397 "OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter\n" 4398 "OpDecorate %gl_TessLevelInner Patch\n" 4399 "OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner\n" 4400 SPIRV_ASSEMBLY_TYPES 4401 SPIRV_ASSEMBLY_CONSTANTS 4402 SPIRV_ASSEMBLY_ARRAYS 4403 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 4404 "%out_color = OpVariable %op_a3v4f32 Output\n" 4405 "%gl_InvocationID = OpVariable %ip_i32 Input\n" 4406 "%in_color = OpVariable %ip_a32v4f32 Input\n" 4407 "%out_position = OpVariable %op_a3v4f32 Output\n" 4408 "%in_position = OpVariable %ip_a32v4f32 Input\n" 4409 "%gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" 4410 "%gl_TessLevelInner = OpVariable %op_a2f32 Output\n" 4411 4412 "%tessc1_main = OpFunction %void None %fun\n" 4413 "%tessc1_label = OpLabel\n" 4414 "%tessc1_invocation_id = OpLoad %i32 %gl_InvocationID\n" 4415 "%tessc1_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc1_invocation_id\n" 4416 "%tessc1_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc1_invocation_id\n" 4417 "%tessc1_in_color_val = OpLoad %v4f32 %tessc1_in_color_ptr\n" 4418 "%tessc1_in_position_val = OpLoad %v4f32 %tessc1_in_position_ptr\n" 4419 "%tessc1_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc1_invocation_id\n" 4420 "%tessc1_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc1_invocation_id\n" 4421 "OpStore %tessc1_out_color_ptr %tessc1_in_color_val\n" 4422 "OpStore %tessc1_out_position_ptr %tessc1_in_position_val\n" 4423 "%tessc1_is_first_invocation = OpIEqual %bool %tessc1_invocation_id %c_i32_0\n" 4424 "OpSelectionMerge %tessc1_merge_label None\n" 4425 "OpBranchConditional %tessc1_is_first_invocation %tessc1_first_invocation %tessc1_merge_label\n" 4426 "%tessc1_first_invocation = OpLabel\n" 4427 "%tessc1_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n" 4428 "%tessc1_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n" 4429 "%tessc1_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n" 4430 "%tessc1_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n" 4431 "OpStore %tessc1_tess_outer_0 %c_f32_1\n" 4432 "OpStore %tessc1_tess_outer_1 %c_f32_1\n" 4433 "OpStore %tessc1_tess_outer_2 %c_f32_1\n" 4434 "OpStore %tessc1_tess_inner %c_f32_1\n" 4435 "OpBranch %tessc1_merge_label\n" 4436 "%tessc1_merge_label = OpLabel\n" 4437 "OpReturn\n" 4438 "OpFunctionEnd\n" 4439 4440 "%tessc2_main = OpFunction %void None %fun\n" 4441 "%tessc2_label = OpLabel\n" 4442 "%tessc2_invocation_id = OpLoad %i32 %gl_InvocationID\n" 4443 "%tessc2_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc2_invocation_id\n" 4444 "%tessc2_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc2_invocation_id\n" 4445 "%tessc2_in_color_val = OpLoad %v4f32 %tessc2_in_color_ptr\n" 4446 "%tessc2_in_position_val = OpLoad %v4f32 %tessc2_in_position_ptr\n" 4447 "%tessc2_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc2_invocation_id\n" 4448 "%tessc2_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc2_invocation_id\n" 4449 "%tessc2_transformed_color = OpFSub %v4f32 %cval %tessc2_in_color_val\n" 4450 "OpStore %tessc2_out_color_ptr %tessc2_transformed_color\n" 4451 "OpStore %tessc2_out_position_ptr %tessc2_in_position_val\n" 4452 "%tessc2_is_first_invocation = OpIEqual %bool %tessc2_invocation_id %c_i32_0\n" 4453 "OpSelectionMerge %tessc2_merge_label None\n" 4454 "OpBranchConditional %tessc2_is_first_invocation %tessc2_first_invocation %tessc2_merge_label\n" 4455 "%tessc2_first_invocation = OpLabel\n" 4456 "%tessc2_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n" 4457 "%tessc2_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n" 4458 "%tessc2_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n" 4459 "%tessc2_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n" 4460 "OpStore %tessc2_tess_outer_0 %c_f32_1\n" 4461 "OpStore %tessc2_tess_outer_1 %c_f32_1\n" 4462 "OpStore %tessc2_tess_outer_2 %c_f32_1\n" 4463 "OpStore %tessc2_tess_inner %c_f32_1\n" 4464 "OpBranch %tessc2_merge_label\n" 4465 "%tessc2_merge_label = OpLabel\n" 4466 "OpReturn\n" 4467 "OpFunctionEnd\n"; 4468 4469 dst.spirvAsmSources.add("tesse") << 4470 "OpCapability Tessellation\n" 4471 "OpMemoryModel Logical GLSL450\n" 4472 "OpEntryPoint TessellationEvaluation %tesse1_main \"tesse1\" %stream %gl_tessCoord %in_position %out_color %in_color \n" 4473 "OpEntryPoint TessellationEvaluation %tesse2_main \"tesse2\" %stream %gl_tessCoord %in_position %out_color %in_color \n" 4474 "OpExecutionMode %tesse1_main Triangles\n" 4475 "OpExecutionMode %tesse2_main Triangles\n" 4476 "OpName %tesse1_main \"tesse1\"\n" 4477 "OpName %tesse2_main \"tesse2\"\n" 4478 "OpName %per_vertex_out \"gl_PerVertex\"\n" 4479 "OpMemberName %per_vertex_out 0 \"gl_Position\"\n" 4480 "OpMemberName %per_vertex_out 1 \"gl_PointSize\"\n" 4481 "OpMemberName %per_vertex_out 2 \"gl_ClipDistance\"\n" 4482 "OpMemberName %per_vertex_out 3 \"gl_CullDistance\"\n" 4483 "OpName %stream \"\"\n" 4484 "OpName %gl_tessCoord \"gl_TessCoord\"\n" 4485 "OpName %in_position \"in_position\"\n" 4486 "OpName %out_color \"out_color\"\n" 4487 "OpName %in_color \"in_color\"\n" 4488 "OpMemberDecorate %per_vertex_out 0 BuiltIn Position\n" 4489 "OpMemberDecorate %per_vertex_out 1 BuiltIn PointSize\n" 4490 "OpMemberDecorate %per_vertex_out 2 BuiltIn ClipDistance\n" 4491 "OpMemberDecorate %per_vertex_out 3 BuiltIn CullDistance\n" 4492 "OpDecorate %per_vertex_out Block\n" 4493 "OpDecorate %gl_tessCoord BuiltIn TessCoord\n" 4494 "OpDecorate %in_position Location 2\n" 4495 "OpDecorate %out_color Location 1\n" 4496 "OpDecorate %in_color Location 1\n" 4497 SPIRV_ASSEMBLY_TYPES 4498 SPIRV_ASSEMBLY_CONSTANTS 4499 SPIRV_ASSEMBLY_ARRAYS 4500 "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 4501 "%per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" 4502 "%op_per_vertex_out = OpTypePointer Output %per_vertex_out\n" 4503 "%stream = OpVariable %op_per_vertex_out Output\n" 4504 "%gl_tessCoord = OpVariable %ip_v3f32 Input\n" 4505 "%in_position = OpVariable %ip_a32v4f32 Input\n" 4506 "%out_color = OpVariable %op_v4f32 Output\n" 4507 "%in_color = OpVariable %ip_a32v4f32 Input\n" 4508 4509 "%tesse1_main = OpFunction %void None %fun\n" 4510 "%tesse1_label = OpLabel\n" 4511 "%tesse1_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n" 4512 "%tesse1_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n" 4513 "%tesse1_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n" 4514 "%tesse1_tc_0 = OpLoad %f32 %tesse1_tc_0_ptr\n" 4515 "%tesse1_tc_1 = OpLoad %f32 %tesse1_tc_1_ptr\n" 4516 "%tesse1_tc_2 = OpLoad %f32 %tesse1_tc_2_ptr\n" 4517 "%tesse1_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n" 4518 "%tesse1_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n" 4519 "%tesse1_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n" 4520 "%tesse1_in_pos_0 = OpLoad %v4f32 %tesse1_in_pos_0_ptr\n" 4521 "%tesse1_in_pos_1 = OpLoad %v4f32 %tesse1_in_pos_1_ptr\n" 4522 "%tesse1_in_pos_2 = OpLoad %v4f32 %tesse1_in_pos_2_ptr\n" 4523 "%tesse1_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_pos_0\n" 4524 "%tesse1_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_pos_1\n" 4525 "%tesse1_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_pos_2\n" 4526 "%tesse1_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n" 4527 "%tesse1_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse1_in_pos_0_weighted %tesse1_in_pos_1_weighted\n" 4528 "%tesse1_computed_out = OpFAdd %v4f32 %tesse1_in_pos_0_plus_pos_1 %tesse1_in_pos_2_weighted\n" 4529 "OpStore %tesse1_out_pos_ptr %tesse1_computed_out\n" 4530 "%tesse1_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" 4531 "%tesse1_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" 4532 "%tesse1_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" 4533 "%tesse1_in_clr_0 = OpLoad %v4f32 %tesse1_in_clr_0_ptr\n" 4534 "%tesse1_in_clr_1 = OpLoad %v4f32 %tesse1_in_clr_1_ptr\n" 4535 "%tesse1_in_clr_2 = OpLoad %v4f32 %tesse1_in_clr_2_ptr\n" 4536 "%tesse1_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_0 %tesse1_in_clr_0\n" 4537 "%tesse1_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_1 %tesse1_in_clr_1\n" 4538 "%tesse1_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_tc_2 %tesse1_in_clr_2\n" 4539 "%tesse1_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse1_in_clr_0_weighted %tesse1_in_clr_1_weighted\n" 4540 "%tesse1_computed_clr = OpFAdd %v4f32 %tesse1_in_clr_0_plus_col_1 %tesse1_in_clr_2_weighted\n" 4541 "OpStore %out_color %tesse1_computed_clr\n" 4542 "OpReturn\n" 4543 "OpFunctionEnd\n" 4544 4545 "%tesse2_main = OpFunction %void None %fun\n" 4546 "%tesse2_label = OpLabel\n" 4547 "%tesse2_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n" 4548 "%tesse2_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n" 4549 "%tesse2_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n" 4550 "%tesse2_tc_0 = OpLoad %f32 %tesse2_tc_0_ptr\n" 4551 "%tesse2_tc_1 = OpLoad %f32 %tesse2_tc_1_ptr\n" 4552 "%tesse2_tc_2 = OpLoad %f32 %tesse2_tc_2_ptr\n" 4553 "%tesse2_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n" 4554 "%tesse2_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n" 4555 "%tesse2_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n" 4556 "%tesse2_in_pos_0 = OpLoad %v4f32 %tesse2_in_pos_0_ptr\n" 4557 "%tesse2_in_pos_1 = OpLoad %v4f32 %tesse2_in_pos_1_ptr\n" 4558 "%tesse2_in_pos_2 = OpLoad %v4f32 %tesse2_in_pos_2_ptr\n" 4559 "%tesse2_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_pos_0\n" 4560 "%tesse2_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_pos_1\n" 4561 "%tesse2_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_pos_2\n" 4562 "%tesse2_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n" 4563 "%tesse2_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse2_in_pos_0_weighted %tesse2_in_pos_1_weighted\n" 4564 "%tesse2_computed_out = OpFAdd %v4f32 %tesse2_in_pos_0_plus_pos_1 %tesse2_in_pos_2_weighted\n" 4565 "OpStore %tesse2_out_pos_ptr %tesse2_computed_out\n" 4566 "%tesse2_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" 4567 "%tesse2_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" 4568 "%tesse2_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" 4569 "%tesse2_in_clr_0 = OpLoad %v4f32 %tesse2_in_clr_0_ptr\n" 4570 "%tesse2_in_clr_1 = OpLoad %v4f32 %tesse2_in_clr_1_ptr\n" 4571 "%tesse2_in_clr_2 = OpLoad %v4f32 %tesse2_in_clr_2_ptr\n" 4572 "%tesse2_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_0 %tesse2_in_clr_0\n" 4573 "%tesse2_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_1 %tesse2_in_clr_1\n" 4574 "%tesse2_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_tc_2 %tesse2_in_clr_2\n" 4575 "%tesse2_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse2_in_clr_0_weighted %tesse2_in_clr_1_weighted\n" 4576 "%tesse2_computed_clr = OpFAdd %v4f32 %tesse2_in_clr_0_plus_col_1 %tesse2_in_clr_2_weighted\n" 4577 "%tesse2_clr_transformed = OpFSub %v4f32 %cval %tesse2_computed_clr\n" 4578 "OpStore %out_color %tesse2_clr_transformed\n" 4579 "OpReturn\n" 4580 "OpFunctionEnd\n"; 4581} 4582 4583// Sets up and runs a Vulkan pipeline, then spot-checks the resulting image. 4584// Feeds the pipeline a set of colored triangles, which then must occur in the 4585// rendered image. The surface is cleared before executing the pipeline, so 4586// whatever the shaders draw can be directly spot-checked. 4587TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance) 4588{ 4589 const VkDevice vkDevice = context.getDevice(); 4590 const DeviceInterface& vk = context.getDeviceInterface(); 4591 const VkQueue queue = context.getUniversalQueue(); 4592 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 4593 const tcu::IVec2 renderSize (256, 256); 4594 vector<ModuleHandleSp> modules; 4595 map<VkShaderStageFlagBits, VkShaderModule> moduleByStage; 4596 const int testSpecificSeed = 31354125; 4597 const int seed = context.getTestContext().getCommandLine().getBaseSeed() ^ testSpecificSeed; 4598 bool supportsGeometry = false; 4599 bool supportsTessellation = false; 4600 bool hasTessellation = false; 4601 4602 const VkPhysicalDeviceFeatures& features = context.getDeviceFeatures(); 4603 supportsGeometry = features.geometryShader; 4604 supportsTessellation = features.tessellationShader; 4605 hasTessellation = (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) || 4606 (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); 4607 4608 if (hasTessellation && !supportsTessellation) 4609 { 4610 throw tcu::NotSupportedError(std::string("Tessellation not supported")); 4611 } 4612 4613 if ((instance.requiredStages & VK_SHADER_STAGE_GEOMETRY_BIT) && 4614 !supportsGeometry) 4615 { 4616 throw tcu::NotSupportedError(std::string("Geometry not supported")); 4617 } 4618 4619 de::Random(seed).shuffle(instance.inputColors, instance.inputColors+4); 4620 de::Random(seed).shuffle(instance.outputColors, instance.outputColors+4); 4621 const Vec4 vertexData[] = 4622 { 4623 // Upper left corner: 4624 Vec4(-1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(), 4625 Vec4(-0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[0].toVec(), 4626 Vec4(-1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[0].toVec(), 4627 4628 // Upper right corner: 4629 Vec4(+0.5f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(), 4630 Vec4(+1.0f, -1.0f, 0.0f, 1.0f), instance.inputColors[1].toVec(), 4631 Vec4(+1.0f, -0.5f, 0.0f, 1.0f), instance.inputColors[1].toVec(), 4632 4633 // Lower left corner: 4634 Vec4(-1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[2].toVec(), 4635 Vec4(-0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(), 4636 Vec4(-1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[2].toVec(), 4637 4638 // Lower right corner: 4639 Vec4(+1.0f, +0.5f, 0.0f, 1.0f), instance.inputColors[3].toVec(), 4640 Vec4(+1.0f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec(), 4641 Vec4(+0.5f, +1.0f, 0.0f, 1.0f), instance.inputColors[3].toVec() 4642 }; 4643 const size_t singleVertexDataSize = 2 * sizeof(Vec4); 4644 const size_t vertexCount = sizeof(vertexData) / singleVertexDataSize; 4645 4646 const VkBufferCreateInfo vertexBufferParams = 4647 { 4648 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType; 4649 DE_NULL, // const void* pNext; 4650 0u, // VkBufferCreateFlags flags; 4651 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size; 4652 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage; 4653 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 4654 1u, // deUint32 queueFamilyCount; 4655 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices; 4656 }; 4657 const Unique<VkBuffer> vertexBuffer (createBuffer(vk, vkDevice, &vertexBufferParams)); 4658 const UniquePtr<Allocation> vertexBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible)); 4659 4660 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferMemory->getMemory(), vertexBufferMemory->getOffset())); 4661 4662 const VkDeviceSize imageSizeBytes = (VkDeviceSize)(sizeof(deUint32)*renderSize.x()*renderSize.y()); 4663 const VkBufferCreateInfo readImageBufferParams = 4664 { 4665 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType; 4666 DE_NULL, // const void* pNext; 4667 0u, // VkBufferCreateFlags flags; 4668 imageSizeBytes, // VkDeviceSize size; 4669 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage; 4670 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 4671 1u, // deUint32 queueFamilyCount; 4672 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices; 4673 }; 4674 const Unique<VkBuffer> readImageBuffer (createBuffer(vk, vkDevice, &readImageBufferParams)); 4675 const UniquePtr<Allocation> readImageBufferMemory (context.getDefaultAllocator().allocate(getBufferMemoryRequirements(vk, vkDevice, *readImageBuffer), MemoryRequirement::HostVisible)); 4676 4677 VK_CHECK(vk.bindBufferMemory(vkDevice, *readImageBuffer, readImageBufferMemory->getMemory(), readImageBufferMemory->getOffset())); 4678 4679 const VkImageCreateInfo imageParams = 4680 { 4681 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 4682 DE_NULL, // const void* pNext; 4683 0u, // VkImageCreateFlags flags; 4684 VK_IMAGE_TYPE_2D, // VkImageType imageType; 4685 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format; 4686 { renderSize.x(), renderSize.y(), 1 }, // VkExtent3D extent; 4687 1u, // deUint32 mipLevels; 4688 1u, // deUint32 arraySize; 4689 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples; 4690 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 4691 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage; 4692 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 4693 1u, // deUint32 queueFamilyCount; 4694 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices; 4695 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 4696 }; 4697 4698 const Unique<VkImage> image (createImage(vk, vkDevice, &imageParams)); 4699 const UniquePtr<Allocation> imageMemory (context.getDefaultAllocator().allocate(getImageMemoryRequirements(vk, vkDevice, *image), MemoryRequirement::Any)); 4700 4701 VK_CHECK(vk.bindImageMemory(vkDevice, *image, imageMemory->getMemory(), imageMemory->getOffset())); 4702 4703 const VkAttachmentDescription colorAttDesc = 4704 { 4705 0u, // VkAttachmentDescriptionFlags flags; 4706 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format; 4707 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples; 4708 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp; 4709 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp; 4710 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp; 4711 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp; 4712 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout; 4713 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout; 4714 }; 4715 const VkAttachmentReference colorAttRef = 4716 { 4717 0u, // deUint32 attachment; 4718 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout layout; 4719 }; 4720 const VkSubpassDescription subpassDesc = 4721 { 4722 0u, // VkSubpassDescriptionFlags flags; 4723 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint; 4724 0u, // deUint32 inputCount; 4725 DE_NULL, // const VkAttachmentReference* pInputAttachments; 4726 1u, // deUint32 colorCount; 4727 &colorAttRef, // const VkAttachmentReference* pColorAttachments; 4728 DE_NULL, // const VkAttachmentReference* pResolveAttachments; 4729 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment; 4730 0u, // deUint32 preserveCount; 4731 DE_NULL, // const VkAttachmentReference* pPreserveAttachments; 4732 4733 }; 4734 const VkRenderPassCreateInfo renderPassParams = 4735 { 4736 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType; 4737 DE_NULL, // const void* pNext; 4738 (VkRenderPassCreateFlags)0, 4739 1u, // deUint32 attachmentCount; 4740 &colorAttDesc, // const VkAttachmentDescription* pAttachments; 4741 1u, // deUint32 subpassCount; 4742 &subpassDesc, // const VkSubpassDescription* pSubpasses; 4743 0u, // deUint32 dependencyCount; 4744 DE_NULL, // const VkSubpassDependency* pDependencies; 4745 }; 4746 const Unique<VkRenderPass> renderPass (createRenderPass(vk, vkDevice, &renderPassParams)); 4747 4748 const VkImageViewCreateInfo colorAttViewParams = 4749 { 4750 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType; 4751 DE_NULL, // const void* pNext; 4752 0u, // VkImageViewCreateFlags flags; 4753 *image, // VkImage image; 4754 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType; 4755 VK_FORMAT_R8G8B8A8_UNORM, // VkFormat format; 4756 { 4757 VK_COMPONENT_SWIZZLE_R, 4758 VK_COMPONENT_SWIZZLE_G, 4759 VK_COMPONENT_SWIZZLE_B, 4760 VK_COMPONENT_SWIZZLE_A 4761 }, // VkChannelMapping channels; 4762 { 4763 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask; 4764 0u, // deUint32 baseMipLevel; 4765 1u, // deUint32 mipLevels; 4766 0u, // deUint32 baseArrayLayer; 4767 1u, // deUint32 arraySize; 4768 }, // VkImageSubresourceRange subresourceRange; 4769 }; 4770 const Unique<VkImageView> colorAttView (createImageView(vk, vkDevice, &colorAttViewParams)); 4771 4772 4773 // Pipeline layout 4774 const VkPipelineLayoutCreateInfo pipelineLayoutParams = 4775 { 4776 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType; 4777 DE_NULL, // const void* pNext; 4778 (VkPipelineLayoutCreateFlags)0, 4779 0u, // deUint32 descriptorSetCount; 4780 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts; 4781 0u, // deUint32 pushConstantRangeCount; 4782 DE_NULL, // const VkPushConstantRange* pPushConstantRanges; 4783 }; 4784 const Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, vkDevice, &pipelineLayoutParams)); 4785 4786 // Pipeline 4787 vector<VkPipelineShaderStageCreateInfo> shaderStageParams; 4788 // We need these vectors to make sure that information about specialization constants for each stage can outlive createGraphicsPipeline(). 4789 vector<vector<VkSpecializationMapEntry> > specConstantEntries; 4790 vector<VkSpecializationInfo> specializationInfos; 4791 createPipelineShaderStages(vk, vkDevice, instance, context, modules, shaderStageParams); 4792 4793 // And we don't want the reallocation of these vectors to invalidate pointers pointing to their contents. 4794 specConstantEntries.reserve(shaderStageParams.size()); 4795 specializationInfos.reserve(shaderStageParams.size()); 4796 4797 // Patch the specialization info field in PipelineShaderStageCreateInfos. 4798 for (vector<VkPipelineShaderStageCreateInfo>::iterator stageInfo = shaderStageParams.begin(); stageInfo != shaderStageParams.end(); ++stageInfo) 4799 { 4800 const StageToSpecConstantMap::const_iterator stageIt = instance.specConstants.find(stageInfo->stage); 4801 4802 if (stageIt != instance.specConstants.end()) 4803 { 4804 const size_t numSpecConstants = stageIt->second.size(); 4805 vector<VkSpecializationMapEntry> entries; 4806 VkSpecializationInfo specInfo; 4807 4808 entries.resize(numSpecConstants); 4809 4810 // Only support 32-bit integers as spec constants now. And their constant IDs are numbered sequentially starting from 0. 4811 for (size_t ndx = 0; ndx < numSpecConstants; ++ndx) 4812 { 4813 entries[ndx].constantID = (deUint32)ndx; 4814 entries[ndx].offset = deUint32(ndx * sizeof(deInt32)); 4815 entries[ndx].size = sizeof(deInt32); 4816 } 4817 4818 specConstantEntries.push_back(entries); 4819 4820 specInfo.mapEntryCount = (deUint32)numSpecConstants; 4821 specInfo.pMapEntries = specConstantEntries.back().data(); 4822 specInfo.dataSize = numSpecConstants * sizeof(deInt32); 4823 specInfo.pData = stageIt->second.data(); 4824 specializationInfos.push_back(specInfo); 4825 4826 stageInfo->pSpecializationInfo = &specializationInfos.back(); 4827 } 4828 } 4829 const VkPipelineDepthStencilStateCreateInfo depthStencilParams = 4830 { 4831 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType; 4832 DE_NULL, // const void* pNext; 4833 (VkPipelineDepthStencilStateCreateFlags)0, 4834 DE_FALSE, // deUint32 depthTestEnable; 4835 DE_FALSE, // deUint32 depthWriteEnable; 4836 VK_COMPARE_OP_ALWAYS, // VkCompareOp depthCompareOp; 4837 DE_FALSE, // deUint32 depthBoundsTestEnable; 4838 DE_FALSE, // deUint32 stencilTestEnable; 4839 { 4840 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp; 4841 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp; 4842 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp; 4843 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp; 4844 0u, // deUint32 stencilCompareMask; 4845 0u, // deUint32 stencilWriteMask; 4846 0u, // deUint32 stencilReference; 4847 }, // VkStencilOpState front; 4848 { 4849 VK_STENCIL_OP_KEEP, // VkStencilOp stencilFailOp; 4850 VK_STENCIL_OP_KEEP, // VkStencilOp stencilPassOp; 4851 VK_STENCIL_OP_KEEP, // VkStencilOp stencilDepthFailOp; 4852 VK_COMPARE_OP_ALWAYS, // VkCompareOp stencilCompareOp; 4853 0u, // deUint32 stencilCompareMask; 4854 0u, // deUint32 stencilWriteMask; 4855 0u, // deUint32 stencilReference; 4856 }, // VkStencilOpState back; 4857 -1.0f, // float minDepthBounds; 4858 +1.0f, // float maxDepthBounds; 4859 }; 4860 const VkViewport viewport0 = 4861 { 4862 0.0f, // float originX; 4863 0.0f, // float originY; 4864 (float)renderSize.x(), // float width; 4865 (float)renderSize.y(), // float height; 4866 0.0f, // float minDepth; 4867 1.0f, // float maxDepth; 4868 }; 4869 const VkRect2D scissor0 = 4870 { 4871 { 4872 0u, // deInt32 x; 4873 0u, // deInt32 y; 4874 }, // VkOffset2D offset; 4875 { 4876 renderSize.x(), // deInt32 width; 4877 renderSize.y(), // deInt32 height; 4878 }, // VkExtent2D extent; 4879 }; 4880 const VkPipelineViewportStateCreateInfo viewportParams = 4881 { 4882 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType; 4883 DE_NULL, // const void* pNext; 4884 (VkPipelineViewportStateCreateFlags)0, 4885 1u, // deUint32 viewportCount; 4886 &viewport0, 4887 1u, 4888 &scissor0 4889 }; 4890 const VkSampleMask sampleMask = ~0u; 4891 const VkPipelineMultisampleStateCreateInfo multisampleParams = 4892 { 4893 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType; 4894 DE_NULL, // const void* pNext; 4895 (VkPipelineMultisampleStateCreateFlags)0, 4896 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterSamples; 4897 DE_FALSE, // deUint32 sampleShadingEnable; 4898 0.0f, // float minSampleShading; 4899 &sampleMask, // const VkSampleMask* pSampleMask; 4900 DE_FALSE, // VkBool32 alphaToCoverageEnable; 4901 DE_FALSE, // VkBool32 alphaToOneEnable; 4902 }; 4903 const VkPipelineRasterizationStateCreateInfo rasterParams = 4904 { 4905 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType; 4906 DE_NULL, // const void* pNext; 4907 (VkPipelineRasterizationStateCreateFlags)0, 4908 DE_TRUE, // deUint32 depthClipEnable; 4909 DE_FALSE, // deUint32 rasterizerDiscardEnable; 4910 VK_POLYGON_MODE_FILL, // VkFillMode fillMode; 4911 VK_CULL_MODE_NONE, // VkCullMode cullMode; 4912 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace; 4913 VK_FALSE, // VkBool32 depthBiasEnable; 4914 0.0f, // float depthBias; 4915 0.0f, // float depthBiasClamp; 4916 0.0f, // float slopeScaledDepthBias; 4917 1.0f, // float lineWidth; 4918 }; 4919 const VkPrimitiveTopology topology = hasTessellation? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; 4920 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyParams = 4921 { 4922 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType; 4923 DE_NULL, // const void* pNext; 4924 (VkPipelineInputAssemblyStateCreateFlags)0, 4925 topology, // VkPrimitiveTopology topology; 4926 DE_FALSE, // deUint32 primitiveRestartEnable; 4927 }; 4928 const VkVertexInputBindingDescription vertexBinding0 = 4929 { 4930 0u, // deUint32 binding; 4931 deUint32(singleVertexDataSize), // deUint32 strideInBytes; 4932 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate; 4933 }; 4934 const VkVertexInputAttributeDescription vertexAttrib0[2] = 4935 { 4936 { 4937 0u, // deUint32 location; 4938 0u, // deUint32 binding; 4939 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format; 4940 0u // deUint32 offsetInBytes; 4941 }, 4942 { 4943 1u, // deUint32 location; 4944 0u, // deUint32 binding; 4945 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format; 4946 sizeof(Vec4), // deUint32 offsetInBytes; 4947 } 4948 }; 4949 4950 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams = 4951 { 4952 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType; 4953 DE_NULL, // const void* pNext; 4954 (VkPipelineVertexInputStateCreateFlags)0, 4955 1u, // deUint32 bindingCount; 4956 &vertexBinding0, // const VkVertexInputBindingDescription* pVertexBindingDescriptions; 4957 2u, // deUint32 attributeCount; 4958 vertexAttrib0, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions; 4959 }; 4960 const VkPipelineColorBlendAttachmentState attBlendParams = 4961 { 4962 DE_FALSE, // deUint32 blendEnable; 4963 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor; 4964 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor; 4965 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor; 4966 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha; 4967 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha; 4968 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha; 4969 (VK_COLOR_COMPONENT_R_BIT| 4970 VK_COLOR_COMPONENT_G_BIT| 4971 VK_COLOR_COMPONENT_B_BIT| 4972 VK_COLOR_COMPONENT_A_BIT), // VkChannelFlags channelWriteMask; 4973 }; 4974 const VkPipelineColorBlendStateCreateInfo blendParams = 4975 { 4976 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType; 4977 DE_NULL, // const void* pNext; 4978 (VkPipelineColorBlendStateCreateFlags)0, 4979 DE_FALSE, // VkBool32 logicOpEnable; 4980 VK_LOGIC_OP_COPY, // VkLogicOp logicOp; 4981 1u, // deUint32 attachmentCount; 4982 &attBlendParams, // const VkPipelineColorBlendAttachmentState* pAttachments; 4983 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4]; 4984 }; 4985 const VkPipelineDynamicStateCreateInfo dynamicStateInfo = 4986 { 4987 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType; 4988 DE_NULL, // const void* pNext; 4989 (VkPipelineDynamicStateCreateFlags)0, 4990 0u, // deUint32 dynamicStateCount; 4991 DE_NULL // const VkDynamicState* pDynamicStates; 4992 }; 4993 4994 const VkPipelineTessellationStateCreateInfo tessellationState = 4995 { 4996 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, 4997 DE_NULL, 4998 (VkPipelineTesselationStateCreateFlags)0, 4999 3u 5000 }; 5001 5002 const VkPipelineTessellationStateCreateInfo* tessellationInfo = hasTessellation ? &tessellationState: DE_NULL; 5003 const VkGraphicsPipelineCreateInfo pipelineParams = 5004 { 5005 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType; 5006 DE_NULL, // const void* pNext; 5007 0u, // VkPipelineCreateFlags flags; 5008 (deUint32)shaderStageParams.size(), // deUint32 stageCount; 5009 &shaderStageParams[0], // const VkPipelineShaderStageCreateInfo* pStages; 5010 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState; 5011 &inputAssemblyParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState; 5012 tessellationInfo, // const VkPipelineTessellationStateCreateInfo* pTessellationState; 5013 &viewportParams, // const VkPipelineViewportStateCreateInfo* pViewportState; 5014 &rasterParams, // const VkPipelineRasterStateCreateInfo* pRasterState; 5015 &multisampleParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState; 5016 &depthStencilParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState; 5017 &blendParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState; 5018 &dynamicStateInfo, // const VkPipelineDynamicStateCreateInfo* pDynamicState; 5019 *pipelineLayout, // VkPipelineLayout layout; 5020 *renderPass, // VkRenderPass renderPass; 5021 0u, // deUint32 subpass; 5022 DE_NULL, // VkPipeline basePipelineHandle; 5023 0u, // deInt32 basePipelineIndex; 5024 }; 5025 5026 const Unique<VkPipeline> pipeline (createGraphicsPipeline(vk, vkDevice, DE_NULL, &pipelineParams)); 5027 5028 // Framebuffer 5029 const VkFramebufferCreateInfo framebufferParams = 5030 { 5031 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType; 5032 DE_NULL, // const void* pNext; 5033 (VkFramebufferCreateFlags)0, 5034 *renderPass, // VkRenderPass renderPass; 5035 1u, // deUint32 attachmentCount; 5036 &*colorAttView, // const VkImageView* pAttachments; 5037 (deUint32)renderSize.x(), // deUint32 width; 5038 (deUint32)renderSize.y(), // deUint32 height; 5039 1u, // deUint32 layers; 5040 }; 5041 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, vkDevice, &framebufferParams)); 5042 5043 const VkCommandPoolCreateInfo cmdPoolParams = 5044 { 5045 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 5046 DE_NULL, // const void* pNext; 5047 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCmdPoolCreateFlags flags; 5048 queueFamilyIndex, // deUint32 queueFamilyIndex; 5049 }; 5050 const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 5051 5052 // Command buffer 5053 const VkCommandBufferAllocateInfo cmdBufParams = 5054 { 5055 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 5056 DE_NULL, // const void* pNext; 5057 *cmdPool, // VkCmdPool pool; 5058 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCmdBufferLevel level; 5059 1u, // deUint32 count; 5060 }; 5061 const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 5062 5063 const VkCommandBufferBeginInfo cmdBufBeginParams = 5064 { 5065 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType; 5066 DE_NULL, // const void* pNext; 5067 (VkCommandBufferUsageFlags)0, 5068 DE_NULL, // VkRenderPass renderPass; 5069 0u, // deUint32 subpass; 5070 DE_NULL, // VkFramebuffer framebuffer; 5071 VK_FALSE, // VkBool32 occlusionQueryEnable; 5072 (VkQueryControlFlags)0, 5073 (VkQueryPipelineStatisticFlags)0, 5074 }; 5075 5076 // Record commands 5077 VK_CHECK(vk.beginCommandBuffer(*cmdBuf, &cmdBufBeginParams)); 5078 5079 { 5080 const VkMemoryBarrier vertFlushBarrier = 5081 { 5082 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // VkStructureType sType; 5083 DE_NULL, // const void* pNext; 5084 VK_ACCESS_HOST_WRITE_BIT, // VkMemoryOutputFlags outputMask; 5085 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, // VkMemoryInputFlags inputMask; 5086 }; 5087 const VkImageMemoryBarrier colorAttBarrier = 5088 { 5089 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType; 5090 DE_NULL, // const void* pNext; 5091 0u, // VkMemoryOutputFlags outputMask; 5092 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryInputFlags inputMask; 5093 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout; 5094 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout; 5095 queueFamilyIndex, // deUint32 srcQueueFamilyIndex; 5096 queueFamilyIndex, // deUint32 destQueueFamilyIndex; 5097 *image, // VkImage image; 5098 { 5099 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect; 5100 0u, // deUint32 baseMipLevel; 5101 1u, // deUint32 mipLevels; 5102 0u, // deUint32 baseArraySlice; 5103 1u, // deUint32 arraySize; 5104 } // VkImageSubresourceRange subresourceRange; 5105 }; 5106 const void* barriers[] = { &vertFlushBarrier, &colorAttBarrier }; 5107 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers); 5108 } 5109 5110 { 5111 const VkClearValue clearValue = makeClearValueColorF32(0.125f, 0.25f, 0.75f, 1.0f); 5112 const VkRenderPassBeginInfo passBeginParams = 5113 { 5114 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType; 5115 DE_NULL, // const void* pNext; 5116 *renderPass, // VkRenderPass renderPass; 5117 *framebuffer, // VkFramebuffer framebuffer; 5118 { { 0, 0 }, { renderSize.x(), renderSize.y() } }, // VkRect2D renderArea; 5119 1u, // deUint32 clearValueCount; 5120 &clearValue, // const VkClearValue* pClearValues; 5121 }; 5122 vk.cmdBeginRenderPass(*cmdBuf, &passBeginParams, VK_SUBPASS_CONTENTS_INLINE); 5123 } 5124 5125 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 5126 { 5127 const VkDeviceSize bindingOffset = 0; 5128 vk.cmdBindVertexBuffers(*cmdBuf, 0u, 1u, &vertexBuffer.get(), &bindingOffset); 5129 } 5130 vk.cmdDraw(*cmdBuf, deUint32(vertexCount), 1u /*run pipeline once*/, 0u /*first vertex*/, 0u /*first instanceIndex*/); 5131 vk.cmdEndRenderPass(*cmdBuf); 5132 5133 { 5134 const VkImageMemoryBarrier renderFinishBarrier = 5135 { 5136 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType; 5137 DE_NULL, // const void* pNext; 5138 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryOutputFlags outputMask; 5139 VK_ACCESS_TRANSFER_READ_BIT, // VkMemoryInputFlags inputMask; 5140 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout; 5141 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout; 5142 queueFamilyIndex, // deUint32 srcQueueFamilyIndex; 5143 queueFamilyIndex, // deUint32 destQueueFamilyIndex; 5144 *image, // VkImage image; 5145 { 5146 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask; 5147 0u, // deUint32 baseMipLevel; 5148 1u, // deUint32 mipLevels; 5149 0u, // deUint32 baseArraySlice; 5150 1u, // deUint32 arraySize; 5151 } // VkImageSubresourceRange subresourceRange; 5152 }; 5153 const void* barriers[] = { &renderFinishBarrier }; 5154 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers); 5155 } 5156 5157 { 5158 const VkBufferImageCopy copyParams = 5159 { 5160 (VkDeviceSize)0u, // VkDeviceSize bufferOffset; 5161 (deUint32)renderSize.x(), // deUint32 bufferRowLength; 5162 (deUint32)renderSize.y(), // deUint32 bufferImageHeight; 5163 { 5164 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspect aspect; 5165 0u, // deUint32 mipLevel; 5166 0u, // deUint32 arrayLayer; 5167 1u, // deUint32 arraySize; 5168 }, // VkImageSubresourceCopy imageSubresource; 5169 { 0u, 0u, 0u }, // VkOffset3D imageOffset; 5170 { renderSize.x(), renderSize.y(), 1u } // VkExtent3D imageExtent; 5171 }; 5172 vk.cmdCopyImageToBuffer(*cmdBuf, *image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *readImageBuffer, 1u, ©Params); 5173 } 5174 5175 { 5176 const VkBufferMemoryBarrier copyFinishBarrier = 5177 { 5178 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType; 5179 DE_NULL, // const void* pNext; 5180 VK_ACCESS_TRANSFER_WRITE_BIT, // VkMemoryOutputFlags outputMask; 5181 VK_ACCESS_HOST_READ_BIT, // VkMemoryInputFlags inputMask; 5182 queueFamilyIndex, // deUint32 srcQueueFamilyIndex; 5183 queueFamilyIndex, // deUint32 destQueueFamilyIndex; 5184 *readImageBuffer, // VkBuffer buffer; 5185 0u, // VkDeviceSize offset; 5186 imageSizeBytes // VkDeviceSize size; 5187 }; 5188 const void* barriers[] = { ©FinishBarrier }; 5189 vk.cmdPipelineBarrier(*cmdBuf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, DE_FALSE, (deUint32)DE_LENGTH_OF_ARRAY(barriers), barriers); 5190 } 5191 5192 VK_CHECK(vk.endCommandBuffer(*cmdBuf)); 5193 5194 // Upload vertex data 5195 { 5196 const VkMappedMemoryRange range = 5197 { 5198 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType; 5199 DE_NULL, // const void* pNext; 5200 vertexBufferMemory->getMemory(), // VkDeviceMemory mem; 5201 0, // VkDeviceSize offset; 5202 (VkDeviceSize)sizeof(vertexData), // VkDeviceSize size; 5203 }; 5204 void* vertexBufPtr = vertexBufferMemory->getHostPtr(); 5205 5206 deMemcpy(vertexBufPtr, &vertexData[0], sizeof(vertexData)); 5207 VK_CHECK(vk.flushMappedMemoryRanges(vkDevice, 1u, &range)); 5208 } 5209 5210 // Submit & wait for completion 5211 { 5212 const VkFenceCreateInfo fenceParams = 5213 { 5214 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType; 5215 DE_NULL, // const void* pNext; 5216 0u, // VkFenceCreateFlags flags; 5217 }; 5218 const Unique<VkFence> fence (createFence(vk, vkDevice, &fenceParams)); 5219 const VkSubmitInfo submitInfo = 5220 { 5221 VK_STRUCTURE_TYPE_SUBMIT_INFO, 5222 DE_NULL, 5223 0u, 5224 (const VkSemaphore*)DE_NULL, 5225 1u, 5226 &cmdBuf.get(), 5227 0u, 5228 (const VkSemaphore*)DE_NULL, 5229 }; 5230 5231 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence)); 5232 VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), DE_TRUE, ~0ull)); 5233 } 5234 5235 const void* imagePtr = readImageBufferMemory->getHostPtr(); 5236 const tcu::ConstPixelBufferAccess pixelBuffer(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), 5237 renderSize.x(), renderSize.y(), 1, imagePtr); 5238 // Log image 5239 { 5240 const VkMappedMemoryRange range = 5241 { 5242 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType; 5243 DE_NULL, // const void* pNext; 5244 readImageBufferMemory->getMemory(), // VkDeviceMemory mem; 5245 0, // VkDeviceSize offset; 5246 imageSizeBytes, // VkDeviceSize size; 5247 }; 5248 5249 VK_CHECK(vk.invalidateMappedMemoryRanges(vkDevice, 1u, &range)); 5250 context.getTestContext().getLog() << TestLog::Image("Result", "Result", pixelBuffer); 5251 } 5252 5253 const RGBA threshold(1, 1, 1, 1); 5254 const RGBA upperLeft(pixelBuffer.getPixel(1, 1)); 5255 if (!tcu::compareThreshold(upperLeft, instance.outputColors[0], threshold)) 5256 return TestStatus::fail("Upper left corner mismatch"); 5257 5258 const RGBA upperRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, 1)); 5259 if (!tcu::compareThreshold(upperRight, instance.outputColors[1], threshold)) 5260 return TestStatus::fail("Upper right corner mismatch"); 5261 5262 const RGBA lowerLeft(pixelBuffer.getPixel(1, pixelBuffer.getHeight() - 1)); 5263 if (!tcu::compareThreshold(lowerLeft, instance.outputColors[2], threshold)) 5264 return TestStatus::fail("Lower left corner mismatch"); 5265 5266 const RGBA lowerRight(pixelBuffer.getPixel(pixelBuffer.getWidth() - 1, pixelBuffer.getHeight() - 1)); 5267 if (!tcu::compareThreshold(lowerRight, instance.outputColors[3], threshold)) 5268 return TestStatus::fail("Lower right corner mismatch"); 5269 5270 return TestStatus::pass("Rendered output matches input"); 5271} 5272 5273void createTestsForAllStages (const std::string& name, const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, const vector<deInt32>& specConstants, tcu::TestCaseGroup* tests) 5274{ 5275 const ShaderElement vertFragPipelineStages[] = 5276 { 5277 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT), 5278 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT), 5279 }; 5280 5281 const ShaderElement tessPipelineStages[] = 5282 { 5283 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT), 5284 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT), 5285 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT), 5286 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT), 5287 }; 5288 5289 const ShaderElement geomPipelineStages[] = 5290 { 5291 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT), 5292 ShaderElement("geom", "main", VK_SHADER_STAGE_GEOMETRY_BIT), 5293 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT), 5294 }; 5295 5296 StageToSpecConstantMap specConstantMap; 5297 5298 specConstantMap[VK_SHADER_STAGE_VERTEX_BIT] = specConstants; 5299 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_vert", "", addShaderCodeCustomVertex, runAndVerifyDefaultPipeline, 5300 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap)); 5301 5302 specConstantMap.clear(); 5303 specConstantMap[VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT] = specConstants; 5304 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tessc", "", addShaderCodeCustomTessControl, runAndVerifyDefaultPipeline, 5305 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap)); 5306 5307 specConstantMap.clear(); 5308 specConstantMap[VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT] = specConstants; 5309 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_tesse", "", addShaderCodeCustomTessEval, runAndVerifyDefaultPipeline, 5310 createInstanceContext(tessPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap)); 5311 5312 specConstantMap.clear(); 5313 specConstantMap[VK_SHADER_STAGE_GEOMETRY_BIT] = specConstants; 5314 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_geom", "", addShaderCodeCustomGeometry, runAndVerifyDefaultPipeline, 5315 createInstanceContext(geomPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap)); 5316 5317 specConstantMap.clear(); 5318 specConstantMap[VK_SHADER_STAGE_FRAGMENT_BIT] = specConstants; 5319 addFunctionCaseWithPrograms<InstanceContext>(tests, name + "_frag", "", addShaderCodeCustomFragment, runAndVerifyDefaultPipeline, 5320 createInstanceContext(vertFragPipelineStages, inputColors, outputColors, testCodeFragments, specConstantMap)); 5321} 5322 5323inline void createTestsForAllStages (const std::string& name, const RGBA (&inputColors)[4], const RGBA (&outputColors)[4], const map<string, string>& testCodeFragments, tcu::TestCaseGroup* tests) 5324{ 5325 vector<deInt32> noSpecConstants; 5326 createTestsForAllStages(name, inputColors, outputColors, testCodeFragments, noSpecConstants, tests); 5327} 5328 5329} // anonymous 5330 5331tcu::TestCaseGroup* createOpSourceTests (tcu::TestContext& testCtx) 5332{ 5333 struct NameCodePair { string name, code; }; 5334 RGBA defaultColors[4]; 5335 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsource", "OpSource instruction")); 5336 const std::string opsourceGLSLWithFile = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile "; 5337 map<string, string> fragments = passthruFragments(); 5338 const NameCodePair tests[] = 5339 { 5340 {"unknown", "OpSource Unknown 321"}, 5341 {"essl", "OpSource ESSL 310"}, 5342 {"glsl", "OpSource GLSL 450"}, 5343 {"opencl_cpp", "OpSource OpenCL_CPP 120"}, 5344 {"opencl_c", "OpSource OpenCL_C 120"}, 5345 {"multiple", "OpSource GLSL 450\nOpSource GLSL 450"}, 5346 {"file", opsourceGLSLWithFile}, 5347 {"source", opsourceGLSLWithFile + "\"void main(){}\""}, 5348 // Longest possible source string: SPIR-V limits instructions to 65535 5349 // words, of which the first 4 are opsourceGLSLWithFile; the rest will 5350 // contain 65530 UTF8 characters (one word each) plus one last word 5351 // containing 3 ASCII characters and \0. 5352 {"longsource", opsourceGLSLWithFile + '"' + makeLongUTF8String(65530) + "ccc" + '"'} 5353 }; 5354 5355 getDefaultColors(defaultColors); 5356 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx) 5357 { 5358 fragments["debug"] = tests[testNdx].code; 5359 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get()); 5360 } 5361 5362 return opSourceTests.release(); 5363} 5364 5365tcu::TestCaseGroup* createOpSourceContinuedTests (tcu::TestContext& testCtx) 5366{ 5367 struct NameCodePair { string name, code; }; 5368 RGBA defaultColors[4]; 5369 de::MovePtr<tcu::TestCaseGroup> opSourceTests (new tcu::TestCaseGroup(testCtx, "opsourcecontinued", "OpSourceContinued instruction")); 5370 map<string, string> fragments = passthruFragments(); 5371 const std::string opsource = "%opsrcfile = OpString \"foo.vert\"\nOpSource GLSL 450 %opsrcfile \"void main(){}\"\n"; 5372 const NameCodePair tests[] = 5373 { 5374 {"empty", opsource + "OpSourceContinued \"\""}, 5375 {"short", opsource + "OpSourceContinued \"abcde\""}, 5376 {"multiple", opsource + "OpSourceContinued \"abcde\"\nOpSourceContinued \"fghij\""}, 5377 // Longest possible source string: SPIR-V limits instructions to 65535 5378 // words, of which the first one is OpSourceContinued/length; the rest 5379 // will contain 65533 UTF8 characters (one word each) plus one last word 5380 // containing 3 ASCII characters and \0. 5381 {"long", opsource + "OpSourceContinued \"" + makeLongUTF8String(65533) + "ccc\""} 5382 }; 5383 5384 getDefaultColors(defaultColors); 5385 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx) 5386 { 5387 fragments["debug"] = tests[testNdx].code; 5388 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opSourceTests.get()); 5389 } 5390 5391 return opSourceTests.release(); 5392} 5393 5394tcu::TestCaseGroup* createOpNoLineTests(tcu::TestContext& testCtx) 5395{ 5396 RGBA defaultColors[4]; 5397 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opnoline", "OpNoLine instruction")); 5398 map<string, string> fragments; 5399 getDefaultColors(defaultColors); 5400 fragments["debug"] = 5401 "%name = OpString \"name\"\n"; 5402 5403 fragments["pre_main"] = 5404 "OpNoLine\n" 5405 "OpNoLine\n" 5406 "OpLine %name 1 1\n" 5407 "OpNoLine\n" 5408 "OpLine %name 1 1\n" 5409 "OpLine %name 1 1\n" 5410 "%second_function = OpFunction %v4f32 None %v4f32_function\n" 5411 "OpNoLine\n" 5412 "OpLine %name 1 1\n" 5413 "OpNoLine\n" 5414 "OpLine %name 1 1\n" 5415 "OpLine %name 1 1\n" 5416 "%second_param1 = OpFunctionParameter %v4f32\n" 5417 "OpNoLine\n" 5418 "OpNoLine\n" 5419 "%label_secondfunction = OpLabel\n" 5420 "OpNoLine\n" 5421 "OpReturnValue %second_param1\n" 5422 "OpFunctionEnd\n" 5423 "OpNoLine\n" 5424 "OpNoLine\n"; 5425 5426 fragments["testfun"] = 5427 // A %test_code function that returns its argument unchanged. 5428 "OpNoLine\n" 5429 "OpNoLine\n" 5430 "OpLine %name 1 1\n" 5431 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5432 "OpNoLine\n" 5433 "%param1 = OpFunctionParameter %v4f32\n" 5434 "OpNoLine\n" 5435 "OpNoLine\n" 5436 "%label_testfun = OpLabel\n" 5437 "OpNoLine\n" 5438 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n" 5439 "OpReturnValue %val1\n" 5440 "OpFunctionEnd\n" 5441 "OpLine %name 1 1\n" 5442 "OpNoLine\n"; 5443 5444 createTestsForAllStages("opnoline", defaultColors, defaultColors, fragments, opLineTests.get()); 5445 5446 return opLineTests.release(); 5447} 5448 5449 5450tcu::TestCaseGroup* createOpLineTests(tcu::TestContext& testCtx) 5451{ 5452 RGBA defaultColors[4]; 5453 de::MovePtr<tcu::TestCaseGroup> opLineTests (new tcu::TestCaseGroup(testCtx, "opline", "OpLine instruction")); 5454 map<string, string> fragments; 5455 std::vector<std::pair<std::string, std::string> > problemStrings; 5456 5457 problemStrings.push_back(std::make_pair<std::string, std::string>("empty_name", "")); 5458 problemStrings.push_back(std::make_pair<std::string, std::string>("short_name", "short_name")); 5459 problemStrings.push_back(std::make_pair<std::string, std::string>("long_name", makeLongUTF8String(65530) + "ccc")); 5460 getDefaultColors(defaultColors); 5461 5462 fragments["debug"] = 5463 "%other_name = OpString \"other_name\"\n"; 5464 5465 fragments["pre_main"] = 5466 "OpLine %file_name 32 0\n" 5467 "OpLine %file_name 32 32\n" 5468 "OpLine %file_name 32 40\n" 5469 "OpLine %other_name 32 40\n" 5470 "OpLine %other_name 0 100\n" 5471 "OpLine %other_name 0 4294967295\n" 5472 "OpLine %other_name 4294967295 0\n" 5473 "OpLine %other_name 32 40\n" 5474 "OpLine %file_name 0 0\n" 5475 "%second_function = OpFunction %v4f32 None %v4f32_function\n" 5476 "OpLine %file_name 1 0\n" 5477 "%second_param1 = OpFunctionParameter %v4f32\n" 5478 "OpLine %file_name 1 3\n" 5479 "OpLine %file_name 1 2\n" 5480 "%label_secondfunction = OpLabel\n" 5481 "OpLine %file_name 0 2\n" 5482 "OpReturnValue %second_param1\n" 5483 "OpFunctionEnd\n" 5484 "OpLine %file_name 0 2\n" 5485 "OpLine %file_name 0 2\n"; 5486 5487 fragments["testfun"] = 5488 // A %test_code function that returns its argument unchanged. 5489 "OpLine %file_name 1 0\n" 5490 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5491 "OpLine %file_name 16 330\n" 5492 "%param1 = OpFunctionParameter %v4f32\n" 5493 "OpLine %file_name 14 442\n" 5494 "%label_testfun = OpLabel\n" 5495 "OpLine %file_name 11 1024\n" 5496 "%val1 = OpFunctionCall %v4f32 %second_function %param1\n" 5497 "OpLine %file_name 2 97\n" 5498 "OpReturnValue %val1\n" 5499 "OpFunctionEnd\n" 5500 "OpLine %file_name 5 32\n"; 5501 5502 for (size_t i = 0; i < problemStrings.size(); ++i) 5503 { 5504 map<string, string> testFragments = fragments; 5505 testFragments["debug"] += "%file_name = OpString \"" + problemStrings[i].second + "\"\n"; 5506 createTestsForAllStages(string("opline") + "_" + problemStrings[i].first, defaultColors, defaultColors, testFragments, opLineTests.get()); 5507 } 5508 5509 return opLineTests.release(); 5510} 5511 5512tcu::TestCaseGroup* createOpConstantNullTests(tcu::TestContext& testCtx) 5513{ 5514 de::MovePtr<tcu::TestCaseGroup> opConstantNullTests (new tcu::TestCaseGroup(testCtx, "opconstantnull", "OpConstantNull instruction")); 5515 RGBA colors[4]; 5516 5517 5518 const char functionStart[] = 5519 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5520 "%param1 = OpFunctionParameter %v4f32\n" 5521 "%lbl = OpLabel\n"; 5522 5523 const char functionEnd[] = 5524 "OpReturnValue %transformed_param\n" 5525 "OpFunctionEnd\n"; 5526 5527 struct NameConstantsCode 5528 { 5529 string name; 5530 string constants; 5531 string code; 5532 }; 5533 5534 NameConstantsCode tests[] = 5535 { 5536 { 5537 "vec4", 5538 "%cnull = OpConstantNull %v4f32\n", 5539 "%transformed_param = OpFAdd %v4f32 %param1 %cnull\n" 5540 }, 5541 { 5542 "float", 5543 "%cnull = OpConstantNull %f32\n", 5544 "%vp = OpVariable %fp_v4f32 Function\n" 5545 "%v = OpLoad %v4f32 %vp\n" 5546 "%v0 = OpVectorInsertDynamic %v4f32 %v %cnull %c_i32_0\n" 5547 "%v1 = OpVectorInsertDynamic %v4f32 %v0 %cnull %c_i32_1\n" 5548 "%v2 = OpVectorInsertDynamic %v4f32 %v1 %cnull %c_i32_2\n" 5549 "%v3 = OpVectorInsertDynamic %v4f32 %v2 %cnull %c_i32_3\n" 5550 "%transformed_param = OpFAdd %v4f32 %param1 %v3\n" 5551 }, 5552 { 5553 "bool", 5554 "%cnull = OpConstantNull %bool\n", 5555 "%v = OpVariable %fp_v4f32 Function\n" 5556 " OpStore %v %param1\n" 5557 " OpSelectionMerge %false_label None\n" 5558 " OpBranchConditional %cnull %true_label %false_label\n" 5559 "%true_label = OpLabel\n" 5560 " OpStore %v %c_v4f32_0_5_0_5_0_5_0_5\n" 5561 " OpBranch %false_label\n" 5562 "%false_label = OpLabel\n" 5563 "%transformed_param = OpLoad %v4f32 %v\n" 5564 }, 5565 { 5566 "i32", 5567 "%cnull = OpConstantNull %i32\n", 5568 "%v = OpVariable %fp_v4f32 Function %c_v4f32_0_5_0_5_0_5_0_5\n" 5569 "%b = OpIEqual %bool %cnull %c_i32_0\n" 5570 " OpSelectionMerge %false_label None\n" 5571 " OpBranchConditional %b %true_label %false_label\n" 5572 "%true_label = OpLabel\n" 5573 " OpStore %v %param1\n" 5574 " OpBranch %false_label\n" 5575 "%false_label = OpLabel\n" 5576 "%transformed_param = OpLoad %v4f32 %v\n" 5577 }, 5578 { 5579 "struct", 5580 "%stype = OpTypeStruct %f32 %v4f32\n" 5581 "%fp_stype = OpTypePointer Function %stype\n" 5582 "%cnull = OpConstantNull %stype\n", 5583 "%v = OpVariable %fp_stype Function %cnull\n" 5584 "%f = OpAccessChain %fp_v4f32 %v %c_i32_1\n" 5585 "%f_val = OpLoad %v4f32 %f\n" 5586 "%transformed_param = OpFAdd %v4f32 %param1 %f_val\n" 5587 }, 5588 { 5589 "array", 5590 "%a4_v4f32 = OpTypeArray %v4f32 %c_u32_4\n" 5591 "%fp_a4_v4f32 = OpTypePointer Function %a4_v4f32\n" 5592 "%cnull = OpConstantNull %a4_v4f32\n", 5593 "%v = OpVariable %fp_a4_v4f32 Function %cnull\n" 5594 "%f = OpAccessChain %fp_v4f32 %v %c_u32_0\n" 5595 "%f1 = OpAccessChain %fp_v4f32 %v %c_u32_1\n" 5596 "%f2 = OpAccessChain %fp_v4f32 %v %c_u32_2\n" 5597 "%f3 = OpAccessChain %fp_v4f32 %v %c_u32_3\n" 5598 "%f_val = OpLoad %v4f32 %f\n" 5599 "%f1_val = OpLoad %v4f32 %f1\n" 5600 "%f2_val = OpLoad %v4f32 %f2\n" 5601 "%f3_val = OpLoad %v4f32 %f3\n" 5602 "%t0 = OpFAdd %v4f32 %param1 %f_val\n" 5603 "%t1 = OpFAdd %v4f32 %t0 %f1_val\n" 5604 "%t2 = OpFAdd %v4f32 %t1 %f2_val\n" 5605 "%transformed_param = OpFAdd %v4f32 %t2 %f3_val\n" 5606 }, 5607 { 5608 "matrix", 5609 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n" 5610 "%cnull = OpConstantNull %mat4x4_f32\n", 5611 // Our null matrix * any vector should result in a zero vector. 5612 "%v = OpVectorTimesMatrix %v4f32 %param1 %cnull\n" 5613 "%transformed_param = OpFAdd %v4f32 %param1 %v\n" 5614 } 5615 }; 5616 5617 getHalfColorsFullAlpha(colors); 5618 5619 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx) 5620 { 5621 map<string, string> fragments; 5622 fragments["pre_main"] = tests[testNdx].constants; 5623 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd; 5624 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, opConstantNullTests.get()); 5625 } 5626 return opConstantNullTests.release(); 5627} 5628tcu::TestCaseGroup* createOpConstantCompositeTests(tcu::TestContext& testCtx) 5629{ 5630 de::MovePtr<tcu::TestCaseGroup> opConstantCompositeTests (new tcu::TestCaseGroup(testCtx, "opconstantcomposite", "OpConstantComposite instruction")); 5631 RGBA inputColors[4]; 5632 RGBA outputColors[4]; 5633 5634 5635 const char functionStart[] = 5636 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5637 "%param1 = OpFunctionParameter %v4f32\n" 5638 "%lbl = OpLabel\n"; 5639 5640 const char functionEnd[] = 5641 "OpReturnValue %transformed_param\n" 5642 "OpFunctionEnd\n"; 5643 5644 struct NameConstantsCode 5645 { 5646 string name; 5647 string constants; 5648 string code; 5649 }; 5650 5651 NameConstantsCode tests[] = 5652 { 5653 { 5654 "vec4", 5655 5656 "%cval = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_0\n", 5657 "%transformed_param = OpFAdd %v4f32 %param1 %cval\n" 5658 }, 5659 { 5660 "struct", 5661 5662 "%stype = OpTypeStruct %v4f32 %f32\n" 5663 "%fp_stype = OpTypePointer Function %stype\n" 5664 "%f32_n_1 = OpConstant %f32 -1.0\n" 5665 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5 5666 "%cvec = OpConstantComposite %v4f32 %f32_1_5 %f32_1_5 %f32_1_5 %c_f32_1\n" 5667 "%cval = OpConstantComposite %stype %cvec %f32_n_1\n", 5668 5669 "%v = OpVariable %fp_stype Function %cval\n" 5670 "%vec_ptr = OpAccessChain %fp_v4f32 %v %c_u32_0\n" 5671 "%f32_ptr = OpAccessChain %fp_v4f32 %v %c_u32_1\n" 5672 "%vec_val = OpLoad %v4f32 %vec_ptr\n" 5673 "%f32_val = OpLoad %v4f32 %f32_ptr\n" 5674 "%tmp1 = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_1 %f32_val\n" // vec4(-1) 5675 "%tmp2 = OpFAdd %v4f32 %tmp1 %param1\n" // param1 + vec4(-1) 5676 "%transformed_param = OpFAdd %v4f32 %tmp2 %vec_val\n" // param1 + vec4(-1) + vec4(1.5, 1.5, 1.5, 1.0) 5677 }, 5678 { 5679 // [1|0|0|0.5] [x] = x + 0.5 5680 // [0|1|0|0.5] [y] = y + 0.5 5681 // [0|0|1|0.5] [z] = z + 0.5 5682 // [0|0|0|1 ] [1] = 1 5683 "matrix", 5684 5685 "%mat4x4_f32 = OpTypeMatrix %v4f32 4\n" 5686 "%v4f32_1_0_0_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_0 %c_f32_0 %c_f32_0\n" 5687 "%v4f32_0_1_0_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_1 %c_f32_0 %c_f32_0\n" 5688 "%v4f32_0_0_1_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_1 %c_f32_0\n" 5689 "%v4f32_0_5_0_5_0_5_1 = OpConstantComposite %v4f32 %c_f32_0_5 %c_f32_0_5 %c_f32_0_5 %c_f32_1\n" 5690 "%cval = OpConstantComposite %mat4x4_f32 %v4f32_1_0_0_0 %v4f32_0_1_0_0 %v4f32_0_0_1_0 %v4f32_0_5_0_5_0_5_1\n", 5691 5692 "%transformed_param = OpMatrixTimesVector %v4f32 %cval %param1\n" 5693 }, 5694 { 5695 "array", 5696 5697 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 5698 "%fp_a4f32 = OpTypePointer Function %a4f32\n" 5699 "%f32_n_1 = OpConstant %f32 -1.0\n" 5700 "%f32_1_5 = OpConstant %f32 !0x3fc00000\n" // +1.5 5701 "%carr = OpConstantComposite %a4f32 %c_f32_0 %f32_n_1 %f32_1_5 %c_f32_0\n", 5702 5703 "%v = OpVariable %fp_a4f32 Function %carr\n" 5704 "%f = OpAccessChain %fp_f32 %v %c_u32_0\n" 5705 "%f1 = OpAccessChain %fp_f32 %v %c_u32_1\n" 5706 "%f2 = OpAccessChain %fp_f32 %v %c_u32_2\n" 5707 "%f3 = OpAccessChain %fp_f32 %v %c_u32_3\n" 5708 "%f_val = OpLoad %f32 %f\n" 5709 "%f1_val = OpLoad %f32 %f1\n" 5710 "%f2_val = OpLoad %f32 %f2\n" 5711 "%f3_val = OpLoad %f32 %f3\n" 5712 "%ftot1 = OpFAdd %f32 %f_val %f1_val\n" 5713 "%ftot2 = OpFAdd %f32 %ftot1 %f2_val\n" 5714 "%ftot3 = OpFAdd %f32 %ftot2 %f3_val\n" // 0 - 1 + 1.5 + 0 5715 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %ftot3\n" 5716 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n" 5717 }, 5718 { 5719 // 5720 // [ 5721 // { 5722 // 0.0, 5723 // [ 1.0, 1.0, 1.0, 1.0] 5724 // }, 5725 // { 5726 // 1.0, 5727 // [ 0.0, 0.5, 0.0, 0.0] 5728 // }, // ^^^ 5729 // { 5730 // 0.0, 5731 // [ 1.0, 1.0, 1.0, 1.0] 5732 // } 5733 // ] 5734 "array_of_struct_of_array", 5735 5736 "%c_v4f32_1_1_1_0 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" 5737 "%fp_a4f32 = OpTypePointer Function %a4f32\n" 5738 "%stype = OpTypeStruct %f32 %a4f32\n" 5739 "%a3stype = OpTypeArray %stype %c_u32_3\n" 5740 "%fp_a3stype = OpTypePointer Function %a3stype\n" 5741 "%ca4f32_0 = OpConstantComposite %a4f32 %c_f32_0 %c_f32_0_5 %c_f32_0 %c_f32_0\n" 5742 "%ca4f32_1 = OpConstantComposite %a4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" 5743 "%cstype1 = OpConstantComposite %stype %c_f32_0 %ca4f32_1\n" 5744 "%cstype2 = OpConstantComposite %stype %c_f32_1 %ca4f32_0\n" 5745 "%carr = OpConstantComposite %a3stype %cstype1 %cstype2 %cstype1", 5746 5747 "%v = OpVariable %fp_a3stype Function %carr\n" 5748 "%f = OpAccessChain %fp_f32 %v %c_u32_1 %c_u32_1 %c_u32_1\n" 5749 "%add_vec = OpVectorTimesScalar %v4f32 %c_v4f32_1_1_1_0 %f\n" 5750 "%transformed_param = OpFAdd %v4f32 %param1 %add_vec\n" 5751 } 5752 }; 5753 5754 getHalfColorsFullAlpha(inputColors); 5755 outputColors[0] = RGBA(255, 255, 255, 255); 5756 outputColors[1] = RGBA(255, 127, 127, 255); 5757 outputColors[2] = RGBA(127, 255, 127, 255); 5758 outputColors[3] = RGBA(127, 127, 255, 255); 5759 5760 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameConstantsCode); ++testNdx) 5761 { 5762 map<string, string> fragments; 5763 fragments["pre_main"] = tests[testNdx].constants; 5764 fragments["testfun"] = string(functionStart) + tests[testNdx].code + functionEnd; 5765 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, opConstantCompositeTests.get()); 5766 } 5767 return opConstantCompositeTests.release(); 5768} 5769 5770tcu::TestCaseGroup* createSelectionBlockOrderTests(tcu::TestContext& testCtx) 5771{ 5772 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "selection_block_order", "Out-of-order blocks for selection")); 5773 RGBA inputColors[4]; 5774 RGBA outputColors[4]; 5775 map<string, string> fragments; 5776 5777 // vec4 test_code(vec4 param) { 5778 // vec4 result = param; 5779 // for (int i = 0; i < 4; ++i) { 5780 // if (i == 0) result[i] = 0.; 5781 // else result[i] = 1. - result[i]; 5782 // } 5783 // return result; 5784 // } 5785 const char function[] = 5786 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5787 "%param1 = OpFunctionParameter %v4f32\n" 5788 "%lbl = OpLabel\n" 5789 "%iptr = OpVariable %fp_i32 Function\n" 5790 " OpStore %iptr %c_i32_0\n" 5791 "%result = OpVariable %fp_v4f32 Function\n" 5792 " OpStore %result %param1\n" 5793 " OpBranch %loop\n" 5794 5795 // Loop entry block. 5796 "%loop = OpLabel\n" 5797 "%ival = OpLoad %i32 %iptr\n" 5798 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n" 5799 " OpLoopMerge %exit %loop None\n" 5800 " OpBranchConditional %lt_4 %if_entry %exit\n" 5801 5802 // Merge block for loop. 5803 "%exit = OpLabel\n" 5804 "%ret = OpLoad %v4f32 %result\n" 5805 " OpReturnValue %ret\n" 5806 5807 // If-statement entry block. 5808 "%if_entry = OpLabel\n" 5809 "%loc = OpAccessChain %fp_f32 %result %ival\n" 5810 "%eq_0 = OpIEqual %bool %ival %c_i32_0\n" 5811 " OpSelectionMerge %if_exit None\n" 5812 " OpBranchConditional %eq_0 %if_true %if_false\n" 5813 5814 // False branch for if-statement. 5815 "%if_false = OpLabel\n" 5816 "%val = OpLoad %f32 %loc\n" 5817 "%sub = OpFSub %f32 %c_f32_1 %val\n" 5818 " OpStore %loc %sub\n" 5819 " OpBranch %if_exit\n" 5820 5821 // Merge block for if-statement. 5822 "%if_exit = OpLabel\n" 5823 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n" 5824 " OpStore %iptr %ival_next\n" 5825 " OpBranch %loop\n" 5826 5827 // True branch for if-statement. 5828 "%if_true = OpLabel\n" 5829 " OpStore %loc %c_f32_0\n" 5830 " OpBranch %if_exit\n" 5831 5832 " OpFunctionEnd\n"; 5833 5834 fragments["testfun"] = function; 5835 5836 inputColors[0] = RGBA(127, 127, 127, 0); 5837 inputColors[1] = RGBA(127, 0, 0, 0); 5838 inputColors[2] = RGBA(0, 127, 0, 0); 5839 inputColors[3] = RGBA(0, 0, 127, 0); 5840 5841 outputColors[0] = RGBA(0, 128, 128, 255); 5842 outputColors[1] = RGBA(0, 255, 255, 255); 5843 outputColors[2] = RGBA(0, 128, 255, 255); 5844 outputColors[3] = RGBA(0, 255, 128, 255); 5845 5846 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get()); 5847 5848 return group.release(); 5849} 5850 5851tcu::TestCaseGroup* createSwitchBlockOrderTests(tcu::TestContext& testCtx) 5852{ 5853 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "switch_block_order", "Out-of-order blocks for switch")); 5854 RGBA inputColors[4]; 5855 RGBA outputColors[4]; 5856 map<string, string> fragments; 5857 5858 const char typesAndConstants[] = 5859 "%c_f32_p2 = OpConstant %f32 0.2\n" 5860 "%c_f32_p4 = OpConstant %f32 0.4\n" 5861 "%c_f32_p6 = OpConstant %f32 0.6\n" 5862 "%c_f32_p8 = OpConstant %f32 0.8\n"; 5863 5864 // vec4 test_code(vec4 param) { 5865 // vec4 result = param; 5866 // for (int i = 0; i < 4; ++i) { 5867 // switch (i) { 5868 // case 0: result[i] += .2; break; 5869 // case 1: result[i] += .6; break; 5870 // case 2: result[i] += .4; break; 5871 // case 3: result[i] += .8; break; 5872 // default: break; // unreachable 5873 // } 5874 // } 5875 // return result; 5876 // } 5877 const char function[] = 5878 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5879 "%param1 = OpFunctionParameter %v4f32\n" 5880 "%lbl = OpLabel\n" 5881 "%iptr = OpVariable %fp_i32 Function\n" 5882 " OpStore %iptr %c_i32_0\n" 5883 "%result = OpVariable %fp_v4f32 Function\n" 5884 " OpStore %result %param1\n" 5885 " OpBranch %loop\n" 5886 5887 // Loop entry block. 5888 "%loop = OpLabel\n" 5889 "%ival = OpLoad %i32 %iptr\n" 5890 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n" 5891 " OpLoopMerge %exit %loop None\n" 5892 " OpBranchConditional %lt_4 %switch_entry %exit\n" 5893 5894 // Merge block for loop. 5895 "%exit = OpLabel\n" 5896 "%ret = OpLoad %v4f32 %result\n" 5897 " OpReturnValue %ret\n" 5898 5899 // Switch-statement entry block. 5900 "%switch_entry = OpLabel\n" 5901 "%loc = OpAccessChain %fp_f32 %result %ival\n" 5902 "%val = OpLoad %f32 %loc\n" 5903 " OpSelectionMerge %switch_exit None\n" 5904 " OpSwitch %ival %switch_default 0 %case0 1 %case1 2 %case2 3 %case3\n" 5905 5906 "%case2 = OpLabel\n" 5907 "%addp4 = OpFAdd %f32 %val %c_f32_p4\n" 5908 " OpStore %loc %addp4\n" 5909 " OpBranch %switch_exit\n" 5910 5911 "%switch_default = OpLabel\n" 5912 " OpUnreachable\n" 5913 5914 "%case3 = OpLabel\n" 5915 "%addp8 = OpFAdd %f32 %val %c_f32_p8\n" 5916 " OpStore %loc %addp8\n" 5917 " OpBranch %switch_exit\n" 5918 5919 "%case0 = OpLabel\n" 5920 "%addp2 = OpFAdd %f32 %val %c_f32_p2\n" 5921 " OpStore %loc %addp2\n" 5922 " OpBranch %switch_exit\n" 5923 5924 // Merge block for switch-statement. 5925 "%switch_exit = OpLabel\n" 5926 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n" 5927 " OpStore %iptr %ival_next\n" 5928 " OpBranch %loop\n" 5929 5930 "%case1 = OpLabel\n" 5931 "%addp6 = OpFAdd %f32 %val %c_f32_p6\n" 5932 " OpStore %loc %addp6\n" 5933 " OpBranch %switch_exit\n" 5934 5935 " OpFunctionEnd\n"; 5936 5937 fragments["pre_main"] = typesAndConstants; 5938 fragments["testfun"] = function; 5939 5940 inputColors[0] = RGBA(127, 27, 127, 51); 5941 inputColors[1] = RGBA(127, 0, 0, 51); 5942 inputColors[2] = RGBA(0, 27, 0, 51); 5943 inputColors[3] = RGBA(0, 0, 127, 51); 5944 5945 outputColors[0] = RGBA(178, 180, 229, 255); 5946 outputColors[1] = RGBA(178, 153, 102, 255); 5947 outputColors[2] = RGBA(51, 180, 102, 255); 5948 outputColors[3] = RGBA(51, 153, 229, 255); 5949 5950 createTestsForAllStages("out_of_order", inputColors, outputColors, fragments, group.get()); 5951 5952 return group.release(); 5953} 5954 5955tcu::TestCaseGroup* createDecorationGroupTests(tcu::TestContext& testCtx) 5956{ 5957 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "decoration_group", "Decoration group tests")); 5958 RGBA inputColors[4]; 5959 RGBA outputColors[4]; 5960 map<string, string> fragments; 5961 5962 const char decorations[] = 5963 "OpDecorate %array_group ArrayStride 4\n" 5964 "OpDecorate %struct_member_group Offset 0\n" 5965 "%array_group = OpDecorationGroup\n" 5966 "%struct_member_group = OpDecorationGroup\n" 5967 5968 "OpDecorate %group1 RelaxedPrecision\n" 5969 "OpDecorate %group3 RelaxedPrecision\n" 5970 "OpDecorate %group3 Invariant\n" 5971 "OpDecorate %group3 Restrict\n" 5972 "%group0 = OpDecorationGroup\n" 5973 "%group1 = OpDecorationGroup\n" 5974 "%group3 = OpDecorationGroup\n"; 5975 5976 const char typesAndConstants[] = 5977 "%a3f32 = OpTypeArray %f32 %c_u32_3\n" 5978 "%struct1 = OpTypeStruct %a3f32\n" 5979 "%struct2 = OpTypeStruct %a3f32\n" 5980 "%fp_struct1 = OpTypePointer Function %struct1\n" 5981 "%fp_struct2 = OpTypePointer Function %struct2\n" 5982 "%c_f32_2 = OpConstant %f32 2.\n" 5983 "%c_f32_n2 = OpConstant %f32 -2.\n" 5984 5985 "%c_a3f32_1 = OpConstantComposite %a3f32 %c_f32_1 %c_f32_2 %c_f32_1\n" 5986 "%c_a3f32_2 = OpConstantComposite %a3f32 %c_f32_n1 %c_f32_n2 %c_f32_n1\n" 5987 "%c_struct1 = OpConstantComposite %struct1 %c_a3f32_1\n" 5988 "%c_struct2 = OpConstantComposite %struct2 %c_a3f32_2\n"; 5989 5990 const char function[] = 5991 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 5992 "%param = OpFunctionParameter %v4f32\n" 5993 "%entry = OpLabel\n" 5994 "%result = OpVariable %fp_v4f32 Function\n" 5995 " OpStore %result %param\n" 5996 "%v_struct1 = OpVariable %fp_struct1 Function\n" 5997 " OpStore %v_struct1 %c_struct1\n" 5998 "%v_struct2 = OpVariable %fp_struct2 Function\n" 5999 " OpStore %v_struct2 %c_struct2\n" 6000 "%ptr1 = OpAccessChain %fp_f32 %v_struct1 %c_i32_0 %c_i32_1\n" 6001 "%val1 = OpLoad %f32 %ptr1\n" 6002 "%ptr2 = OpAccessChain %fp_f32 %v_struct2 %c_i32_0 %c_i32_2\n" 6003 "%val2 = OpLoad %f32 %ptr2\n" 6004 "%addvalues = OpFAdd %f32 %val1 %val2\n" 6005 "%ptr = OpAccessChain %fp_f32 %result %c_i32_1\n" 6006 "%val = OpLoad %f32 %ptr\n" 6007 "%addresult = OpFAdd %f32 %addvalues %val\n" 6008 " OpStore %ptr %addresult\n" 6009 "%ret = OpLoad %v4f32 %result\n" 6010 " OpReturnValue %ret\n" 6011 " OpFunctionEnd\n"; 6012 6013 struct CaseNameDecoration 6014 { 6015 string name; 6016 string decoration; 6017 }; 6018 6019 CaseNameDecoration tests[] = 6020 { 6021 { 6022 "same_decoration_group_on_multiple_types", 6023 "OpGroupMemberDecorate %struct_member_group %struct1 0 %struct2 0\n" 6024 }, 6025 { 6026 "empty_decoration_group", 6027 "OpGroupDecorate %group0 %a3f32\n" 6028 "OpGroupDecorate %group0 %result\n" 6029 }, 6030 { 6031 "one_element_decoration_group", 6032 "OpGroupDecorate %array_group %a3f32\n" 6033 }, 6034 { 6035 "multiple_elements_decoration_group", 6036 "OpGroupDecorate %group3 %v_struct1\n" 6037 }, 6038 { 6039 "multiple_decoration_groups_on_same_variable", 6040 "OpGroupDecorate %group0 %v_struct2\n" 6041 "OpGroupDecorate %group1 %v_struct2\n" 6042 "OpGroupDecorate %group3 %v_struct2\n" 6043 }, 6044 { 6045 "same_decoration_group_multiple_times", 6046 "OpGroupDecorate %group1 %addvalues\n" 6047 "OpGroupDecorate %group1 %addvalues\n" 6048 "OpGroupDecorate %group1 %addvalues\n" 6049 }, 6050 6051 }; 6052 6053 getHalfColorsFullAlpha(inputColors); 6054 getHalfColorsFullAlpha(outputColors); 6055 6056 for (size_t idx = 0; idx < (sizeof(tests) / sizeof(tests[0])); ++idx) 6057 { 6058 fragments["decoration"] = decorations + tests[idx].decoration; 6059 fragments["pre_main"] = typesAndConstants; 6060 fragments["testfun"] = function; 6061 6062 createTestsForAllStages(tests[idx].name, inputColors, outputColors, fragments, group.get()); 6063 } 6064 6065 return group.release(); 6066} 6067 6068struct SpecConstantTwoIntGraphicsCase 6069{ 6070 const char* caseName; 6071 const char* scDefinition0; 6072 const char* scDefinition1; 6073 const char* scResultType; 6074 const char* scOperation; 6075 deInt32 scActualValue0; 6076 deInt32 scActualValue1; 6077 const char* resultOperation; 6078 RGBA expectedColors[4]; 6079 6080 SpecConstantTwoIntGraphicsCase (const char* name, 6081 const char* definition0, 6082 const char* definition1, 6083 const char* resultType, 6084 const char* operation, 6085 deInt32 value0, 6086 deInt32 value1, 6087 const char* resultOp, 6088 const RGBA (&output)[4]) 6089 : caseName (name) 6090 , scDefinition0 (definition0) 6091 , scDefinition1 (definition1) 6092 , scResultType (resultType) 6093 , scOperation (operation) 6094 , scActualValue0 (value0) 6095 , scActualValue1 (value1) 6096 , resultOperation (resultOp) 6097 { 6098 expectedColors[0] = output[0]; 6099 expectedColors[1] = output[1]; 6100 expectedColors[2] = output[2]; 6101 expectedColors[3] = output[3]; 6102 } 6103}; 6104 6105tcu::TestCaseGroup* createSpecConstantTests (tcu::TestContext& testCtx) 6106{ 6107 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opspecconstantop", "Test the OpSpecConstantOp instruction")); 6108 vector<SpecConstantTwoIntGraphicsCase> cases; 6109 RGBA inputColors[4]; 6110 RGBA outputColors0[4]; 6111 RGBA outputColors1[4]; 6112 RGBA outputColors2[4]; 6113 6114 const char decorations1[] = 6115 "OpDecorate %sc_0 SpecId 0\n" 6116 "OpDecorate %sc_1 SpecId 1\n"; 6117 6118 const char typesAndConstants1[] = 6119 "%sc_0 = OpSpecConstant${SC_DEF0}\n" 6120 "%sc_1 = OpSpecConstant${SC_DEF1}\n" 6121 "%sc_op = OpSpecConstantOp ${SC_RESULT_TYPE} ${SC_OP}\n"; 6122 6123 const char function1[] = 6124 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6125 "%param = OpFunctionParameter %v4f32\n" 6126 "%label = OpLabel\n" 6127 "%result = OpVariable %fp_v4f32 Function\n" 6128 " OpStore %result %param\n" 6129 "%gen = ${GEN_RESULT}\n" 6130 "%index = OpIAdd %i32 %gen %c_i32_1\n" 6131 "%loc = OpAccessChain %fp_f32 %result %index\n" 6132 "%val = OpLoad %f32 %loc\n" 6133 "%add = OpFAdd %f32 %val %c_f32_0_5\n" 6134 " OpStore %loc %add\n" 6135 "%ret = OpLoad %v4f32 %result\n" 6136 " OpReturnValue %ret\n" 6137 " OpFunctionEnd\n"; 6138 6139 inputColors[0] = RGBA(127, 127, 127, 255); 6140 inputColors[1] = RGBA(127, 0, 0, 255); 6141 inputColors[2] = RGBA(0, 127, 0, 255); 6142 inputColors[3] = RGBA(0, 0, 127, 255); 6143 6144 // Derived from inputColors[x] by adding 128 to inputColors[x][0]. 6145 outputColors0[0] = RGBA(255, 127, 127, 255); 6146 outputColors0[1] = RGBA(255, 0, 0, 255); 6147 outputColors0[2] = RGBA(128, 127, 0, 255); 6148 outputColors0[3] = RGBA(128, 0, 127, 255); 6149 6150 // Derived from inputColors[x] by adding 128 to inputColors[x][1]. 6151 outputColors1[0] = RGBA(127, 255, 127, 255); 6152 outputColors1[1] = RGBA(127, 128, 0, 255); 6153 outputColors1[2] = RGBA(0, 255, 0, 255); 6154 outputColors1[3] = RGBA(0, 128, 127, 255); 6155 6156 // Derived from inputColors[x] by adding 128 to inputColors[x][2]. 6157 outputColors2[0] = RGBA(127, 127, 255, 255); 6158 outputColors2[1] = RGBA(127, 0, 128, 255); 6159 outputColors2[2] = RGBA(0, 127, 128, 255); 6160 outputColors2[3] = RGBA(0, 0, 255, 255); 6161 6162 const char addZeroToSc[] = "OpIAdd %i32 %c_i32_0 %sc_op"; 6163 const char selectTrueUsingSc[] = "OpSelect %i32 %sc_op %c_i32_1 %c_i32_0"; 6164 const char selectFalseUsingSc[] = "OpSelect %i32 %sc_op %c_i32_0 %c_i32_1"; 6165 6166 cases.push_back(SpecConstantTwoIntGraphicsCase("iadd", " %i32 0", " %i32 0", "%i32", "IAdd %sc_0 %sc_1", 19, -20, addZeroToSc, outputColors0)); 6167 cases.push_back(SpecConstantTwoIntGraphicsCase("isub", " %i32 0", " %i32 0", "%i32", "ISub %sc_0 %sc_1", 19, 20, addZeroToSc, outputColors0)); 6168 cases.push_back(SpecConstantTwoIntGraphicsCase("imul", " %i32 0", " %i32 0", "%i32", "IMul %sc_0 %sc_1", -1, -1, addZeroToSc, outputColors2)); 6169 cases.push_back(SpecConstantTwoIntGraphicsCase("sdiv", " %i32 0", " %i32 0", "%i32", "SDiv %sc_0 %sc_1", -126, 126, addZeroToSc, outputColors0)); 6170 cases.push_back(SpecConstantTwoIntGraphicsCase("udiv", " %i32 0", " %i32 0", "%i32", "UDiv %sc_0 %sc_1", 126, 126, addZeroToSc, outputColors2)); 6171 cases.push_back(SpecConstantTwoIntGraphicsCase("srem", " %i32 0", " %i32 0", "%i32", "SRem %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2)); 6172 cases.push_back(SpecConstantTwoIntGraphicsCase("smod", " %i32 0", " %i32 0", "%i32", "SMod %sc_0 %sc_1", 3, 2, addZeroToSc, outputColors2)); 6173 cases.push_back(SpecConstantTwoIntGraphicsCase("umod", " %i32 0", " %i32 0", "%i32", "UMod %sc_0 %sc_1", 1001, 500, addZeroToSc, outputColors2)); 6174 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseand", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x33, 0x0d, addZeroToSc, outputColors2)); 6175 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwiseor", " %i32 0", " %i32 0", "%i32", "BitwiseOr %sc_0 %sc_1", 0, 1, addZeroToSc, outputColors2)); 6176 cases.push_back(SpecConstantTwoIntGraphicsCase("bitwisexor", " %i32 0", " %i32 0", "%i32", "BitwiseAnd %sc_0 %sc_1", 0x2e, 0x2f, addZeroToSc, outputColors2)); 6177 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightlogical", " %i32 0", " %i32 0", "%i32", "ShiftRightLogical %sc_0 %sc_1", 2, 1, addZeroToSc, outputColors2)); 6178 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftrightarithmetic", " %i32 0", " %i32 0", "%i32", "ShiftRightArithmetic %sc_0 %sc_1", -4, 2, addZeroToSc, outputColors0)); 6179 cases.push_back(SpecConstantTwoIntGraphicsCase("shiftleftlogical", " %i32 0", " %i32 0", "%i32", "ShiftLeftLogical %sc_0 %sc_1", 1, 0, addZeroToSc, outputColors2)); 6180 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthan", " %i32 0", " %i32 0", "%bool", "SLessThan %sc_0 %sc_1", -20, -10, selectTrueUsingSc, outputColors2)); 6181 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthan", " %i32 0", " %i32 0", "%bool", "ULessThan %sc_0 %sc_1", 10, 20, selectTrueUsingSc, outputColors2)); 6182 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthan", " %i32 0", " %i32 0", "%bool", "SGreaterThan %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2)); 6183 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthan", " %i32 0", " %i32 0", "%bool", "UGreaterThan %sc_0 %sc_1", 10, 5, selectTrueUsingSc, outputColors2)); 6184 cases.push_back(SpecConstantTwoIntGraphicsCase("slessthanequal", " %i32 0", " %i32 0", "%bool", "SLessThanEqual %sc_0 %sc_1", -10, -10, selectTrueUsingSc, outputColors2)); 6185 cases.push_back(SpecConstantTwoIntGraphicsCase("ulessthanequal", " %i32 0", " %i32 0", "%bool", "ULessThanEqual %sc_0 %sc_1", 50, 100, selectTrueUsingSc, outputColors2)); 6186 cases.push_back(SpecConstantTwoIntGraphicsCase("sgreaterthanequal", " %i32 0", " %i32 0", "%bool", "SGreaterThanEqual %sc_0 %sc_1", -1000, 50, selectFalseUsingSc, outputColors2)); 6187 cases.push_back(SpecConstantTwoIntGraphicsCase("ugreaterthanequal", " %i32 0", " %i32 0", "%bool", "UGreaterThanEqual %sc_0 %sc_1", 10, 10, selectTrueUsingSc, outputColors2)); 6188 cases.push_back(SpecConstantTwoIntGraphicsCase("iequal", " %i32 0", " %i32 0", "%bool", "IEqual %sc_0 %sc_1", 42, 24, selectFalseUsingSc, outputColors2)); 6189 cases.push_back(SpecConstantTwoIntGraphicsCase("logicaland", "True %bool", "True %bool", "%bool", "LogicalAnd %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2)); 6190 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalor", "False %bool", "False %bool", "%bool", "LogicalOr %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2)); 6191 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalequal", "True %bool", "True %bool", "%bool", "LogicalEqual %sc_0 %sc_1", 0, 1, selectFalseUsingSc, outputColors2)); 6192 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnotequal", "False %bool", "False %bool", "%bool", "LogicalNotEqual %sc_0 %sc_1", 1, 0, selectTrueUsingSc, outputColors2)); 6193 cases.push_back(SpecConstantTwoIntGraphicsCase("snegate", " %i32 0", " %i32 0", "%i32", "SNegate %sc_0", -1, 0, addZeroToSc, outputColors2)); 6194 cases.push_back(SpecConstantTwoIntGraphicsCase("not", " %i32 0", " %i32 0", "%i32", "Not %sc_0", -2, 0, addZeroToSc, outputColors2)); 6195 cases.push_back(SpecConstantTwoIntGraphicsCase("logicalnot", "False %bool", "False %bool", "%bool", "LogicalNot %sc_0", 1, 0, selectFalseUsingSc, outputColors2)); 6196 cases.push_back(SpecConstantTwoIntGraphicsCase("select", "False %bool", " %i32 0", "%i32", "Select %sc_0 %sc_1 %c_i32_0", 1, 1, addZeroToSc, outputColors2)); 6197 // OpSConvert, OpFConvert: these two instructions involve ints/floats of different bitwidths. 6198 // \todo[2015-12-1 antiagainst] OpQuantizeToF16 6199 6200 for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx) 6201 { 6202 map<string, string> specializations; 6203 map<string, string> fragments; 6204 vector<deInt32> specConstants; 6205 6206 specializations["SC_DEF0"] = cases[caseNdx].scDefinition0; 6207 specializations["SC_DEF1"] = cases[caseNdx].scDefinition1; 6208 specializations["SC_RESULT_TYPE"] = cases[caseNdx].scResultType; 6209 specializations["SC_OP"] = cases[caseNdx].scOperation; 6210 specializations["GEN_RESULT"] = cases[caseNdx].resultOperation; 6211 6212 fragments["decoration"] = tcu::StringTemplate(decorations1).specialize(specializations); 6213 fragments["pre_main"] = tcu::StringTemplate(typesAndConstants1).specialize(specializations); 6214 fragments["testfun"] = tcu::StringTemplate(function1).specialize(specializations); 6215 6216 specConstants.push_back(cases[caseNdx].scActualValue0); 6217 specConstants.push_back(cases[caseNdx].scActualValue1); 6218 6219 createTestsForAllStages(cases[caseNdx].caseName, inputColors, cases[caseNdx].expectedColors, fragments, specConstants, group.get()); 6220 } 6221 6222 const char decorations2[] = 6223 "OpDecorate %sc_0 SpecId 0\n" 6224 "OpDecorate %sc_1 SpecId 1\n" 6225 "OpDecorate %sc_2 SpecId 2\n"; 6226 6227 const char typesAndConstants2[] = 6228 "%v3i32 = OpTypeVector %i32 3\n" 6229 6230 "%sc_0 = OpSpecConstant %i32 0\n" 6231 "%sc_1 = OpSpecConstant %i32 0\n" 6232 "%sc_2 = OpSpecConstant %i32 0\n" 6233 6234 "%vec3_0 = OpConstantComposite %v3i32 %c_i32_0 %c_i32_0 %c_i32_0\n" 6235 "%sc_vec3_0 = OpSpecConstantOp %v3i32 CompositeInsert %sc_0 %vec3_0 0\n" // (sc_0, 0, 0) 6236 "%sc_vec3_1 = OpSpecConstantOp %v3i32 CompositeInsert %sc_1 %vec3_0 1\n" // (0, sc_1, 0) 6237 "%sc_vec3_2 = OpSpecConstantOp %v3i32 CompositeInsert %sc_2 %vec3_0 2\n" // (0, 0, sc_2) 6238 "%sc_vec3_01 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_0 %sc_vec3_1 1 0 4\n" // (0, sc_0, sc_1) 6239 "%sc_vec3_012 = OpSpecConstantOp %v3i32 VectorShuffle %sc_vec3_01 %sc_vec3_2 5 1 2\n" // (sc_2, sc_0, sc_1) 6240 "%sc_ext_0 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 0\n" // sc_2 6241 "%sc_ext_1 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 1\n" // sc_0 6242 "%sc_ext_2 = OpSpecConstantOp %i32 CompositeExtract %sc_vec3_012 2\n" // sc_1 6243 "%sc_sub = OpSpecConstantOp %i32 ISub %sc_ext_0 %sc_ext_1\n" // (sc_2 - sc_0) 6244 "%sc_final = OpSpecConstantOp %i32 IMul %sc_sub %sc_ext_2\n"; // (sc_2 - sc_0) * sc_1 6245 6246 const char function2[] = 6247 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6248 "%param = OpFunctionParameter %v4f32\n" 6249 "%label = OpLabel\n" 6250 "%result = OpVariable %fp_v4f32 Function\n" 6251 " OpStore %result %param\n" 6252 "%loc = OpAccessChain %fp_f32 %result %sc_final\n" 6253 "%val = OpLoad %f32 %loc\n" 6254 "%add = OpFAdd %f32 %val %c_f32_0_5\n" 6255 " OpStore %loc %add\n" 6256 "%ret = OpLoad %v4f32 %result\n" 6257 " OpReturnValue %ret\n" 6258 " OpFunctionEnd\n"; 6259 6260 map<string, string> fragments; 6261 vector<deInt32> specConstants; 6262 6263 fragments["decoration"] = decorations2; 6264 fragments["pre_main"] = typesAndConstants2; 6265 fragments["testfun"] = function2; 6266 6267 specConstants.push_back(56789); 6268 specConstants.push_back(-2); 6269 specConstants.push_back(56788); 6270 6271 createTestsForAllStages("vector_related", inputColors, outputColors2, fragments, specConstants, group.get()); 6272 6273 return group.release(); 6274} 6275 6276tcu::TestCaseGroup* createOpPhiTests(tcu::TestContext& testCtx) 6277{ 6278 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "opphi", "Test the OpPhi instruction")); 6279 RGBA inputColors[4]; 6280 RGBA outputColors1[4]; 6281 RGBA outputColors2[4]; 6282 RGBA outputColors3[4]; 6283 map<string, string> fragments1; 6284 map<string, string> fragments2; 6285 map<string, string> fragments3; 6286 6287 const char typesAndConstants1[] = 6288 "%c_f32_p2 = OpConstant %f32 0.2\n" 6289 "%c_f32_p4 = OpConstant %f32 0.4\n" 6290 "%c_f32_p6 = OpConstant %f32 0.6\n" 6291 "%c_f32_p8 = OpConstant %f32 0.8\n"; 6292 6293 // vec4 test_code(vec4 param) { 6294 // vec4 result = param; 6295 // for (int i = 0; i < 4; ++i) { 6296 // float operand; 6297 // switch (i) { 6298 // case 0: operand = .2; break; 6299 // case 1: operand = .6; break; 6300 // case 2: operand = .4; break; 6301 // case 3: operand = .0; break; 6302 // default: break; // unreachable 6303 // } 6304 // result[i] += operand; 6305 // } 6306 // return result; 6307 // } 6308 const char function1[] = 6309 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6310 "%param1 = OpFunctionParameter %v4f32\n" 6311 "%lbl = OpLabel\n" 6312 "%iptr = OpVariable %fp_i32 Function\n" 6313 " OpStore %iptr %c_i32_0\n" 6314 "%result = OpVariable %fp_v4f32 Function\n" 6315 " OpStore %result %param1\n" 6316 " OpBranch %loop\n" 6317 6318 "%loop = OpLabel\n" 6319 "%ival = OpLoad %i32 %iptr\n" 6320 "%lt_4 = OpSLessThan %bool %ival %c_i32_4\n" 6321 " OpLoopMerge %exit %loop None\n" 6322 " OpBranchConditional %lt_4 %entry %exit\n" 6323 6324 "%entry = OpLabel\n" 6325 "%loc = OpAccessChain %fp_f32 %result %ival\n" 6326 "%val = OpLoad %f32 %loc\n" 6327 " OpSelectionMerge %phi None\n" 6328 " OpSwitch %ival %default 0 %case0 1 %case1 2 %case2 3 %case3\n" 6329 6330 "%case0 = OpLabel\n" 6331 " OpBranch %phi\n" 6332 "%case1 = OpLabel\n" 6333 " OpBranch %phi\n" 6334 "%case2 = OpLabel\n" 6335 " OpBranch %phi\n" 6336 "%case3 = OpLabel\n" 6337 " OpBranch %phi\n" 6338 6339 "%default = OpLabel\n" 6340 " OpUnreachable\n" 6341 6342 "%phi = OpLabel\n" 6343 "%operand = OpPhi %f32 %c_f32_p4 %case2 %c_f32_p6 %case1 %c_f32_p2 %case0 %c_f32_0 %case3\n" // not in the order of blocks 6344 "%add = OpFAdd %f32 %val %operand\n" 6345 " OpStore %loc %add\n" 6346 "%ival_next = OpIAdd %i32 %ival %c_i32_1\n" 6347 " OpStore %iptr %ival_next\n" 6348 " OpBranch %loop\n" 6349 6350 "%exit = OpLabel\n" 6351 "%ret = OpLoad %v4f32 %result\n" 6352 " OpReturnValue %ret\n" 6353 6354 " OpFunctionEnd\n"; 6355 6356 fragments1["pre_main"] = typesAndConstants1; 6357 fragments1["testfun"] = function1; 6358 6359 getHalfColorsFullAlpha(inputColors); 6360 6361 outputColors1[0] = RGBA(178, 180, 229, 255); 6362 outputColors1[1] = RGBA(178, 153, 102, 255); 6363 outputColors1[2] = RGBA(51, 180, 102, 255); 6364 outputColors1[3] = RGBA(51, 153, 229, 255); 6365 6366 createTestsForAllStages("out_of_order", inputColors, outputColors1, fragments1, group.get()); 6367 6368 const char typesAndConstants2[] = 6369 "%c_f32_p2 = OpConstant %f32 0.2\n"; 6370 6371 // Add .4 to the second element of the given parameter. 6372 const char function2[] = 6373 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6374 "%param = OpFunctionParameter %v4f32\n" 6375 "%entry = OpLabel\n" 6376 "%result = OpVariable %fp_v4f32 Function\n" 6377 " OpStore %result %param\n" 6378 "%loc = OpAccessChain %fp_f32 %result %c_i32_1\n" 6379 "%val = OpLoad %f32 %loc\n" 6380 " OpBranch %phi\n" 6381 6382 "%phi = OpLabel\n" 6383 "%step = OpPhi %i32 %c_i32_0 %entry %step_next %phi\n" 6384 "%accum = OpPhi %f32 %val %entry %accum_next %phi\n" 6385 "%step_next = OpIAdd %i32 %step %c_i32_1\n" 6386 "%accum_next = OpFAdd %f32 %accum %c_f32_p2\n" 6387 "%still_loop = OpSLessThan %bool %step %c_i32_2\n" 6388 " OpLoopMerge %exit %phi None\n" 6389 " OpBranchConditional %still_loop %phi %exit\n" 6390 6391 "%exit = OpLabel\n" 6392 " OpStore %loc %accum\n" 6393 "%ret = OpLoad %v4f32 %result\n" 6394 " OpReturnValue %ret\n" 6395 6396 " OpFunctionEnd\n"; 6397 6398 fragments2["pre_main"] = typesAndConstants2; 6399 fragments2["testfun"] = function2; 6400 6401 outputColors2[0] = RGBA(127, 229, 127, 255); 6402 outputColors2[1] = RGBA(127, 102, 0, 255); 6403 outputColors2[2] = RGBA(0, 229, 0, 255); 6404 outputColors2[3] = RGBA(0, 102, 127, 255); 6405 6406 createTestsForAllStages("induction", inputColors, outputColors2, fragments2, group.get()); 6407 6408 const char typesAndConstants3[] = 6409 "%true = OpConstantTrue %bool\n" 6410 "%false = OpConstantFalse %bool\n" 6411 "%c_f32_p2 = OpConstant %f32 0.2\n"; 6412 6413 // Swap the second and the third element of the given parameter. 6414 const char function3[] = 6415 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6416 "%param = OpFunctionParameter %v4f32\n" 6417 "%entry = OpLabel\n" 6418 "%result = OpVariable %fp_v4f32 Function\n" 6419 " OpStore %result %param\n" 6420 "%a_loc = OpAccessChain %fp_f32 %result %c_i32_1\n" 6421 "%a_init = OpLoad %f32 %a_loc\n" 6422 "%b_loc = OpAccessChain %fp_f32 %result %c_i32_2\n" 6423 "%b_init = OpLoad %f32 %b_loc\n" 6424 " OpBranch %phi\n" 6425 6426 "%phi = OpLabel\n" 6427 "%still_loop = OpPhi %bool %true %entry %false %phi\n" 6428 "%a_next = OpPhi %f32 %a_init %entry %b_next %phi\n" 6429 "%b_next = OpPhi %f32 %b_init %entry %a_next %phi\n" 6430 " OpLoopMerge %exit %phi None\n" 6431 " OpBranchConditional %still_loop %phi %exit\n" 6432 6433 "%exit = OpLabel\n" 6434 " OpStore %a_loc %a_next\n" 6435 " OpStore %b_loc %b_next\n" 6436 "%ret = OpLoad %v4f32 %result\n" 6437 " OpReturnValue %ret\n" 6438 6439 " OpFunctionEnd\n"; 6440 6441 fragments3["pre_main"] = typesAndConstants3; 6442 fragments3["testfun"] = function3; 6443 6444 outputColors3[0] = RGBA(127, 127, 127, 255); 6445 outputColors3[1] = RGBA(127, 0, 0, 255); 6446 outputColors3[2] = RGBA(0, 0, 127, 255); 6447 outputColors3[3] = RGBA(0, 127, 0, 255); 6448 6449 createTestsForAllStages("swap", inputColors, outputColors3, fragments3, group.get()); 6450 6451 return group.release(); 6452} 6453 6454tcu::TestCaseGroup* createNoContractionTests(tcu::TestContext& testCtx) 6455{ 6456 de::MovePtr<tcu::TestCaseGroup> group (new tcu::TestCaseGroup(testCtx, "nocontraction", "Test the NoContraction decoration")); 6457 RGBA inputColors[4]; 6458 RGBA outputColors[4]; 6459 6460 // With NoContraction, (1 + 2^-23) * (1 - 2^-23) - 1 should be conducted as a multiplication and an addition separately. 6461 // For the multiplication, the result is 1 - 2^-46, which is out of the precision range for 32-bit float. (32-bit float 6462 // only have 23-bit fraction.) So it will be rounded to 1. Then the final result is 0. On the contrary, the result will 6463 // be 2^-46, which is a normalized number perfectly representable as 32-bit float. 6464 const char constantsAndTypes[] = 6465 "%c_vec4_0 = OpConstantComposite %v4f32 %c_f32_0 %c_f32_0 %c_f32_0 %c_f32_1\n" 6466 "%c_vec4_1 = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_1\n" 6467 "%c_f32_1pl2_23 = OpConstant %f32 0x1.000002p+0\n" // 1 + 2^-23 6468 "%c_f32_1mi2_23 = OpConstant %f32 0x1.fffffcp-1\n" // 1 - 2^-23 6469 ; 6470 6471 const char function[] = 6472 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6473 "%param = OpFunctionParameter %v4f32\n" 6474 "%label = OpLabel\n" 6475 "%var1 = OpVariable %fp_f32 Function %c_f32_1pl2_23\n" 6476 "%var2 = OpVariable %fp_f32 Function\n" 6477 "%red = OpCompositeExtract %f32 %param 0\n" 6478 "%plus_red = OpFAdd %f32 %c_f32_1mi2_23 %red\n" 6479 " OpStore %var2 %plus_red\n" 6480 "%val1 = OpLoad %f32 %var1\n" 6481 "%val2 = OpLoad %f32 %var2\n" 6482 "%mul = OpFMul %f32 %val1 %val2\n" 6483 "%add = OpFAdd %f32 %mul %c_f32_n1\n" 6484 "%is0 = OpFOrdEqual %bool %add %c_f32_0\n" 6485 "%ret = OpSelect %v4f32 %is0 %c_vec4_0 %c_vec4_1\n" 6486 " OpReturnValue %ret\n" 6487 " OpFunctionEnd\n"; 6488 6489 struct CaseNameDecoration 6490 { 6491 string name; 6492 string decoration; 6493 }; 6494 6495 6496 CaseNameDecoration tests[] = { 6497 {"multiplication", "OpDecorate %mul NoContraction"}, 6498 {"addition", "OpDecorate %add NoContraction"}, 6499 {"both", "OpDecorate %mul NoContraction\nOpDecorate %add NoContraction"}, 6500 }; 6501 6502 getHalfColorsFullAlpha(inputColors); 6503 6504 for (deUint8 idx = 0; idx < 4; ++idx) 6505 { 6506 inputColors[idx].setRed(0); 6507 outputColors[idx] = RGBA(0, 0, 0, 255); 6508 } 6509 6510 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(CaseNameDecoration); ++testNdx) 6511 { 6512 map<string, string> fragments; 6513 6514 fragments["decoration"] = tests[testNdx].decoration; 6515 fragments["pre_main"] = constantsAndTypes; 6516 fragments["testfun"] = function; 6517 6518 createTestsForAllStages(tests[testNdx].name, inputColors, outputColors, fragments, group.get()); 6519 } 6520 6521 return group.release(); 6522} 6523 6524tcu::TestCaseGroup* createMemoryAccessTests(tcu::TestContext& testCtx) 6525{ 6526 de::MovePtr<tcu::TestCaseGroup> memoryAccessTests (new tcu::TestCaseGroup(testCtx, "opmemoryaccess", "Memory Semantics")); 6527 RGBA colors[4]; 6528 6529 const char constantsAndTypes[] = 6530 "%c_a2f32_1 = OpConstantComposite %a2f32 %c_f32_1 %c_f32_1\n" 6531 "%fp_a2f32 = OpTypePointer Function %a2f32\n" 6532 "%stype = OpTypeStruct %v4f32 %a2f32 %f32\n" 6533 "%fp_stype = OpTypePointer Function %stype\n"; 6534 6535 const char function[] = 6536 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6537 "%param1 = OpFunctionParameter %v4f32\n" 6538 "%lbl = OpLabel\n" 6539 "%v1 = OpVariable %fp_v4f32 Function\n" 6540 " OpStore %v1 %c_v4f32_1_1_1_1\n" 6541 "%v2 = OpVariable %fp_a2f32 Function\n" 6542 " OpStore %v2 %c_a2f32_1\n" 6543 "%v3 = OpVariable %fp_f32 Function\n" 6544 " OpStore %v3 %c_f32_1\n" 6545 6546 "%v = OpVariable %fp_stype Function\n" 6547 "%vv = OpVariable %fp_stype Function\n" 6548 "%vvv = OpVariable %fp_f32 Function\n" 6549 6550 "%p_v4f32 = OpAccessChain %fp_v4f32 %v %c_u32_0\n" 6551 "%p_a2f32 = OpAccessChain %fp_a2f32 %v %c_u32_1\n" 6552 "%p_f32 = OpAccessChain %fp_f32 %v %c_u32_2\n" 6553 "%v1_v = OpLoad %v4f32 %v1 ${access_type}\n" 6554 "%v2_v = OpLoad %a2f32 %v2 ${access_type}\n" 6555 "%v3_v = OpLoad %f32 %v3 ${access_type}\n" 6556 6557 " OpStore %p_v4f32 %v1_v ${access_type}\n" 6558 " OpStore %p_a2f32 %v2_v ${access_type}\n" 6559 " OpStore %p_f32 %v3_v ${access_type}\n" 6560 6561 " OpCopyMemory %vv %v ${access_type}\n" 6562 " OpCopyMemory %vvv %p_f32 ${access_type}\n" 6563 6564 "%p_f32_2 = OpAccessChain %fp_f32 %vv %c_u32_2\n" 6565 "%v_f32_2 = OpLoad %f32 %p_f32_2\n" 6566 "%v_f32_3 = OpLoad %f32 %vvv\n" 6567 6568 "%ret1 = OpVectorTimesScalar %v4f32 %param1 %v_f32_2\n" 6569 "%ret2 = OpVectorTimesScalar %v4f32 %ret1 %v_f32_3\n" 6570 " OpReturnValue %ret2\n" 6571 " OpFunctionEnd\n"; 6572 6573 struct NameMemoryAccess 6574 { 6575 string name; 6576 string accessType; 6577 }; 6578 6579 6580 NameMemoryAccess tests[] = 6581 { 6582 { "none", "" }, 6583 { "volatile", "Volatile" }, 6584 { "aligned", "Aligned 1" }, 6585 { "volatile_aligned", "Volatile|Aligned 1" }, 6586 { "nontemporal_aligned", "Nontemporal|Aligned 1" }, 6587 { "volatile_nontemporal", "Volatile|Nontemporal" }, 6588 { "volatile_nontermporal_aligned", "Volatile|Nontemporal|Aligned 1" }, 6589 }; 6590 6591 getHalfColorsFullAlpha(colors); 6592 6593 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameMemoryAccess); ++testNdx) 6594 { 6595 map<string, string> fragments; 6596 map<string, string> memoryAccess; 6597 memoryAccess["access_type"] = tests[testNdx].accessType; 6598 6599 fragments["pre_main"] = constantsAndTypes; 6600 fragments["testfun"] = tcu::StringTemplate(function).specialize(memoryAccess); 6601 createTestsForAllStages(tests[testNdx].name, colors, colors, fragments, memoryAccessTests.get()); 6602 } 6603 return memoryAccessTests.release(); 6604} 6605tcu::TestCaseGroup* createOpUndefTests(tcu::TestContext& testCtx) 6606{ 6607 de::MovePtr<tcu::TestCaseGroup> opUndefTests (new tcu::TestCaseGroup(testCtx, "opundef", "Test OpUndef")); 6608 RGBA defaultColors[4]; 6609 map<string, string> fragments; 6610 getDefaultColors(defaultColors); 6611 6612 // First, simple cases that don't do anything with the OpUndef result. 6613 fragments["testfun"] = 6614 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6615 "%param1 = OpFunctionParameter %v4f32\n" 6616 "%label_testfun = OpLabel\n" 6617 "%undef = OpUndef %type\n" 6618 "OpReturnValue %param1\n" 6619 "OpFunctionEnd\n" 6620 ; 6621 struct NameCodePair { string name, code; }; 6622 const NameCodePair tests[] = 6623 { 6624 {"bool", "%type = OpTypeBool"}, 6625 {"vec2uint32", "%type = OpTypeVector %u32 2"}, 6626 {"image", "%type = OpTypeImage %f32 2D 0 0 0 0 Unknown"}, 6627 {"sampler", "%type = OpTypeSampler"}, 6628 {"sampledimage", "%img = OpTypeImage %f32 2D 0 0 0 0 Unknown\n" "%type = OpTypeSampledImage %img"}, 6629 {"pointer", "%type = OpTypePointer Function %i32"}, 6630 {"runtimearray", "%type = OpTypeRuntimeArray %f32"}, 6631 {"array", "%c_u32_100 = OpConstant %u32 100\n" "%type = OpTypeArray %i32 %c_u32_100"}, 6632 {"struct", "%type = OpTypeStruct %f32 %i32 %u32"}}; 6633 for (size_t testNdx = 0; testNdx < sizeof(tests) / sizeof(NameCodePair); ++testNdx) 6634 { 6635 fragments["pre_main"] = tests[testNdx].code; 6636 createTestsForAllStages(tests[testNdx].name, defaultColors, defaultColors, fragments, opUndefTests.get()); 6637 } 6638 fragments.clear(); 6639 6640 fragments["testfun"] = 6641 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6642 "%param1 = OpFunctionParameter %v4f32\n" 6643 "%label_testfun = OpLabel\n" 6644 "%undef = OpUndef %f32\n" 6645 "%zero = OpFMul %f32 %undef %c_f32_0\n" 6646 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 6647 "%b = OpFAdd %f32 %a %zero\n" 6648 "%ret = OpVectorInsertDynamic %v4f32 %param1 %b %c_i32_0\n" 6649 "OpReturnValue %ret\n" 6650 "OpFunctionEnd\n" 6651 ; 6652 createTestsForAllStages("float32", defaultColors, defaultColors, fragments, opUndefTests.get()); 6653 6654 fragments["testfun"] = 6655 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6656 "%param1 = OpFunctionParameter %v4f32\n" 6657 "%label_testfun = OpLabel\n" 6658 "%undef = OpUndef %i32\n" 6659 "%zero = OpIMul %i32 %undef %c_i32_0\n" 6660 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n" 6661 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n" 6662 "OpReturnValue %ret\n" 6663 "OpFunctionEnd\n" 6664 ; 6665 createTestsForAllStages("sint32", defaultColors, defaultColors, fragments, opUndefTests.get()); 6666 6667 fragments["testfun"] = 6668 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6669 "%param1 = OpFunctionParameter %v4f32\n" 6670 "%label_testfun = OpLabel\n" 6671 "%undef = OpUndef %u32\n" 6672 "%zero = OpIMul %u32 %undef %c_i32_0\n" 6673 "%a = OpVectorExtractDynamic %f32 %param1 %zero\n" 6674 "%ret = OpVectorInsertDynamic %v4f32 %param1 %a %c_i32_0\n" 6675 "OpReturnValue %ret\n" 6676 "OpFunctionEnd\n" 6677 ; 6678 createTestsForAllStages("uint32", defaultColors, defaultColors, fragments, opUndefTests.get()); 6679 6680 fragments["testfun"] = 6681 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6682 "%param1 = OpFunctionParameter %v4f32\n" 6683 "%label_testfun = OpLabel\n" 6684 "%undef = OpUndef %v4f32\n" 6685 "%vzero = OpVectorTimesScalar %v4f32 %undef %c_f32_0\n" 6686 "%zero_0 = OpVectorExtractDynamic %f32 %vzero %c_i32_0\n" 6687 "%zero_1 = OpVectorExtractDynamic %f32 %vzero %c_i32_1\n" 6688 "%zero_2 = OpVectorExtractDynamic %f32 %vzero %c_i32_2\n" 6689 "%zero_3 = OpVectorExtractDynamic %f32 %vzero %c_i32_3\n" 6690 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 6691 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n" 6692 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n" 6693 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n" 6694 "%sum_0 = OpFAdd %f32 %param1_0 %zero_0\n" 6695 "%sum_1 = OpFAdd %f32 %param1_1 %zero_1\n" 6696 "%sum_2 = OpFAdd %f32 %param1_2 %zero_2\n" 6697 "%sum_3 = OpFAdd %f32 %param1_3 %zero_3\n" 6698 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n" 6699 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n" 6700 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n" 6701 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n" 6702 "OpReturnValue %ret\n" 6703 "OpFunctionEnd\n" 6704 ; 6705 createTestsForAllStages("vec4float32", defaultColors, defaultColors, fragments, opUndefTests.get()); 6706 6707 fragments["pre_main"] = 6708 "%v2f32 = OpTypeVector %f32 2\n" 6709 "%m2x2f32 = OpTypeMatrix %v2f32 2\n"; 6710 fragments["testfun"] = 6711 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6712 "%param1 = OpFunctionParameter %v4f32\n" 6713 "%label_testfun = OpLabel\n" 6714 "%undef = OpUndef %m2x2f32\n" 6715 "%mzero = OpMatrixTimesScalar %m2x2f32 %undef %c_f32_0\n" 6716 "%zero_0 = OpCompositeExtract %f32 %mzero 0 0\n" 6717 "%zero_1 = OpCompositeExtract %f32 %mzero 0 1\n" 6718 "%zero_2 = OpCompositeExtract %f32 %mzero 1 0\n" 6719 "%zero_3 = OpCompositeExtract %f32 %mzero 1 1\n" 6720 "%param1_0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 6721 "%param1_1 = OpVectorExtractDynamic %f32 %param1 %c_i32_1\n" 6722 "%param1_2 = OpVectorExtractDynamic %f32 %param1 %c_i32_2\n" 6723 "%param1_3 = OpVectorExtractDynamic %f32 %param1 %c_i32_3\n" 6724 "%sum_0 = OpFAdd %f32 %param1_0 %zero_0\n" 6725 "%sum_1 = OpFAdd %f32 %param1_1 %zero_1\n" 6726 "%sum_2 = OpFAdd %f32 %param1_2 %zero_2\n" 6727 "%sum_3 = OpFAdd %f32 %param1_3 %zero_3\n" 6728 "%ret3 = OpVectorInsertDynamic %v4f32 %param1 %sum_3 %c_i32_3\n" 6729 "%ret2 = OpVectorInsertDynamic %v4f32 %ret3 %sum_2 %c_i32_2\n" 6730 "%ret1 = OpVectorInsertDynamic %v4f32 %ret2 %sum_1 %c_i32_1\n" 6731 "%ret = OpVectorInsertDynamic %v4f32 %ret1 %sum_0 %c_i32_0\n" 6732 "OpReturnValue %ret\n" 6733 "OpFunctionEnd\n" 6734 ; 6735 createTestsForAllStages("matrix", defaultColors, defaultColors, fragments, opUndefTests.get()); 6736 6737 return opUndefTests.release(); 6738} 6739 6740void createOpQuantizeSingleOptionTests(tcu::TestCaseGroup* testCtx) 6741{ 6742 const RGBA inputColors[4] = 6743 { 6744 RGBA(0, 0, 0, 255), 6745 RGBA(0, 0, 255, 255), 6746 RGBA(0, 255, 0, 255), 6747 RGBA(0, 255, 255, 255) 6748 }; 6749 6750 const RGBA expectedColors[4] = 6751 { 6752 RGBA(255, 0, 0, 255), 6753 RGBA(255, 0, 0, 255), 6754 RGBA(255, 0, 0, 255), 6755 RGBA(255, 0, 0, 255) 6756 }; 6757 6758 const struct SingleFP16Possibility 6759 { 6760 const char* name; 6761 const char* constant; // Value to assign to %test_constant. 6762 float valueAsFloat; 6763 const char* condition; // Must assign to %cond an expression that evaluates to true after %c = OpQuantizeToF16(%test_constant + 0). 6764 } tests[] = 6765 { 6766 { 6767 "negative", 6768 "-0x1.3p1\n", 6769 -constructNormalizedFloat(1, 0x300000), 6770 "%cond = OpFOrdEqual %bool %c %test_constant\n" 6771 }, // -19 6772 { 6773 "positive", 6774 "0x1.0p7\n", 6775 constructNormalizedFloat(7, 0x000000), 6776 "%cond = OpFOrdEqual %bool %c %test_constant\n" 6777 }, // +128 6778 // SPIR-V requires that OpQuantizeToF16 flushes 6779 // any numbers that would end up denormalized in F16 to zero. 6780 { 6781 "denorm", 6782 "0x0.0006p-126\n", 6783 std::ldexp(1.5f, -140), 6784 "%cond = OpFOrdEqual %bool %c %c_f32_0\n" 6785 }, // denorm 6786 { 6787 "negative_denorm", 6788 "-0x0.0006p-126\n", 6789 -std::ldexp(1.5f, -140), 6790 "%cond = OpFOrdEqual %bool %c %c_f32_0\n" 6791 }, // -denorm 6792 { 6793 "too_small", 6794 "0x1.0p-16\n", 6795 std::ldexp(1.0f, -16), 6796 "%cond = OpFOrdEqual %bool %c %c_f32_0\n" 6797 }, // too small positive 6798 { 6799 "negative_too_small", 6800 "-0x1.0p-32\n", 6801 -std::ldexp(1.0f, -32), 6802 "%cond = OpFOrdEqual %bool %c %c_f32_0\n" 6803 }, // too small negative 6804 { 6805 "negative_inf", 6806 "-0x1.0p128\n", 6807 -std::ldexp(1.0f, 128), 6808 6809 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n" 6810 "%inf = OpIsInf %bool %c\n" 6811 "%cond = OpLogicalAnd %bool %gz %inf\n" 6812 }, // -inf to -inf 6813 { 6814 "inf", 6815 "0x1.0p128\n", 6816 std::ldexp(1.0f, 128), 6817 6818 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n" 6819 "%inf = OpIsInf %bool %c\n" 6820 "%cond = OpLogicalAnd %bool %gz %inf\n" 6821 }, // +inf to +inf 6822 { 6823 "round_to_negative_inf", 6824 "-0x1.0p32\n", 6825 -std::ldexp(1.0f, 32), 6826 6827 "%gz = OpFOrdLessThan %bool %c %c_f32_0\n" 6828 "%inf = OpIsInf %bool %c\n" 6829 "%cond = OpLogicalAnd %bool %gz %inf\n" 6830 }, // round to -inf 6831 { 6832 "round_to_inf", 6833 "0x1.0p16\n", 6834 std::ldexp(1.0f, 16), 6835 6836 "%gz = OpFOrdGreaterThan %bool %c %c_f32_0\n" 6837 "%inf = OpIsInf %bool %c\n" 6838 "%cond = OpLogicalAnd %bool %gz %inf\n" 6839 }, // round to +inf 6840 { 6841 "nan", 6842 "0x1.1p128\n", 6843 std::numeric_limits<float>::quiet_NaN(), 6844 6845 // Can't use %c, because NaN+0 isn't necessarily a NaN (Vulkan spec A.4). 6846 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n" 6847 "%nan = OpIsNan %bool %direct_quant\n" 6848 "%as_int = OpBitcast %i32 %direct_quant\n" 6849 "%positive = OpSGreaterThan %bool %as_int %c_i32_0\n" 6850 "%cond = OpLogicalAnd %bool %nan %positive\n" 6851 }, // nan 6852 { 6853 "negative_nan", 6854 "-0x1.0001p128\n", 6855 std::numeric_limits<float>::quiet_NaN(), 6856 6857 // Can't use %c, because NaN+0 isn't necessarily a NaN (Vulkan spec A.4). 6858 "%direct_quant = OpQuantizeToF16 %f32 %test_constant\n" 6859 "%nan = OpIsNan %bool %direct_quant\n" 6860 "%as_int = OpBitcast %i32 %direct_quant\n" 6861 "%negative = OpSLessThan %bool %as_int %c_i32_0\n" 6862 "%cond = OpLogicalAnd %bool %nan %negative\n" 6863 } // -nan 6864 }; 6865 const char* constants = 6866 "%test_constant = OpConstant %f32 "; // The value will be test.constant. 6867 6868 StringTemplate function ( 6869 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6870 "%param1 = OpFunctionParameter %v4f32\n" 6871 "%label_testfun = OpLabel\n" 6872 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 6873 "%b = OpFAdd %f32 %test_constant %a\n" 6874 "%c = OpQuantizeToF16 %f32 %b\n" 6875 "${condition}\n" 6876 "%retval = OpSelect %v4f32 %cond %c_v4f32_1_0_0_1 %param1" 6877 " OpReturnValue %retval\n" 6878 "OpFunctionEnd\n" 6879 ); 6880 6881 const char* specDecorations = "OpDecorate %test_constant SpecId 0\n"; 6882 const char* specConstants = 6883 "%test_constant = OpSpecConstant %f32 0.\n" 6884 "%c = OpSpecConstantOp %f32 QuantizeToF16 %test_constant\n"; 6885 6886 StringTemplate specConstantFunction( 6887 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6888 "%param1 = OpFunctionParameter %v4f32\n" 6889 "%label_testfun = OpLabel\n" 6890 "${condition}\n" 6891 "%retval = OpSelect %v4f32 %cond %c_v4f32_1_0_0_1 %param1" 6892 " OpReturnValue %retval\n" 6893 "OpFunctionEnd\n" 6894 ); 6895 6896 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) 6897 { 6898 map<string, string> codeSpecialization; 6899 map<string, string> fragments; 6900 codeSpecialization["condition"] = tests[idx].condition; 6901 fragments["testfun"] = function.specialize(codeSpecialization); 6902 fragments["pre_main"] = string(constants) + tests[idx].constant + "\n"; 6903 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx); 6904 } 6905 6906 for (size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) 6907 { 6908 map<string, string> codeSpecialization; 6909 map<string, string> fragments; 6910 vector<deInt32> passConstants; 6911 deInt32 specConstant; 6912 6913 codeSpecialization["condition"] = tests[idx].condition; 6914 fragments["testfun"] = specConstantFunction.specialize(codeSpecialization); 6915 fragments["decoration"] = specDecorations; 6916 fragments["pre_main"] = specConstants; 6917 6918 memcpy(&specConstant, &tests[idx].valueAsFloat, sizeof(float)); 6919 passConstants.push_back(specConstant); 6920 6921 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx); 6922 } 6923} 6924 6925void createOpQuantizeTwoPossibilityTests(tcu::TestCaseGroup* testCtx) 6926{ 6927 RGBA inputColors[4] = { 6928 RGBA(0, 0, 0, 255), 6929 RGBA(0, 0, 255, 255), 6930 RGBA(0, 255, 0, 255), 6931 RGBA(0, 255, 255, 255) 6932 }; 6933 6934 RGBA expectedColors[4] = 6935 { 6936 RGBA(255, 0, 0, 255), 6937 RGBA(255, 0, 0, 255), 6938 RGBA(255, 0, 0, 255), 6939 RGBA(255, 0, 0, 255) 6940 }; 6941 6942 struct DualFP16Possibility 6943 { 6944 const char* name; 6945 const char* input; 6946 float inputAsFloat; 6947 const char* possibleOutput1; 6948 const char* possibleOutput2; 6949 } tests[] = { 6950 { 6951 "positive_round_up_or_round_down", 6952 "0x1.3003p8", 6953 constructNormalizedFloat(8, 0x300300), 6954 "0x1.304p8", 6955 "0x1.3p8" 6956 }, 6957 { 6958 "negative_round_up_or_round_down", 6959 "-0x1.6008p-7", 6960 -constructNormalizedFloat(8, 0x600800), 6961 "-0x1.6p-7", 6962 "-0x1.604p-7" 6963 }, 6964 { 6965 "carry_bit", 6966 "0x1.01ep2", 6967 constructNormalizedFloat(8, 0x01e000), 6968 "0x1.01cp2", 6969 "0x1.02p2" 6970 }, 6971 { 6972 "carry_to_exponent", 6973 "0x1.feep1", 6974 constructNormalizedFloat(8, 0xfee000), 6975 "0x1.ffcp1", 6976 "0x1.0p2" 6977 }, 6978 }; 6979 StringTemplate constants ( 6980 "%input_const = OpConstant %f32 ${input}\n" 6981 "%possible_solution1 = OpConstant %f32 ${output1}\n" 6982 "%possible_solution2 = OpConstant %f32 ${output2}\n" 6983 ); 6984 6985 StringTemplate specConstants ( 6986 "%input_const = OpSpecConstant %f32 0.\n" 6987 "%possible_solution1 = OpConstant %f32 ${output1}\n" 6988 "%possible_solution2 = OpConstant %f32 ${output2}\n" 6989 ); 6990 6991 const char* specDecorations = "OpDecorate %input_const SpecId 0\n"; 6992 6993 const char* function = 6994 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 6995 "%param1 = OpFunctionParameter %v4f32\n" 6996 "%label_testfun = OpLabel\n" 6997 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 6998 // For the purposes of this test we assume that 0.f will always get 6999 // faithfully passed through the pipeline stages. 7000 "%b = OpFAdd %f32 %input_const %a\n" 7001 "%c = OpQuantizeToF16 %f32 %b\n" 7002 "%eq_1 = OpFOrdEqual %bool %c %possible_solution1\n" 7003 "%eq_2 = OpFOrdEqual %bool %c %possible_solution2\n" 7004 "%cond = OpLogicalOr %bool %eq_1 %eq_2\n" 7005 "%retval = OpSelect %v4f32 %cond %c_v4f32_1_0_0_1 %param1" 7006 " OpReturnValue %retval\n" 7007 "OpFunctionEnd\n"; 7008 7009 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) { 7010 map<string, string> fragments; 7011 map<string, string> constantSpecialization; 7012 7013 constantSpecialization["input"] = tests[idx].input; 7014 constantSpecialization["output1"] = tests[idx].possibleOutput1; 7015 constantSpecialization["output2"] = tests[idx].possibleOutput2; 7016 fragments["testfun"] = function; 7017 fragments["pre_main"] = constants.specialize(constantSpecialization); 7018 createTestsForAllStages(tests[idx].name, inputColors, expectedColors, fragments, testCtx); 7019 } 7020 7021 for(size_t idx = 0; idx < (sizeof(tests)/sizeof(tests[0])); ++idx) { 7022 map<string, string> fragments; 7023 map<string, string> constantSpecialization; 7024 vector<deInt32> passConstants; 7025 deInt32 specConstant; 7026 7027 constantSpecialization["output1"] = tests[idx].possibleOutput1; 7028 constantSpecialization["output2"] = tests[idx].possibleOutput2; 7029 fragments["testfun"] = function; 7030 fragments["decoration"] = specDecorations; 7031 fragments["pre_main"] = specConstants.specialize(constantSpecialization); 7032 7033 memcpy(&specConstant, &tests[idx].inputAsFloat, sizeof(float)); 7034 passConstants.push_back(specConstant); 7035 7036 createTestsForAllStages(string("spec_const_") + tests[idx].name, inputColors, expectedColors, fragments, passConstants, testCtx); 7037 } 7038} 7039 7040tcu::TestCaseGroup* createOpQuantizeTests(tcu::TestContext& testCtx) 7041{ 7042 de::MovePtr<tcu::TestCaseGroup> opQuantizeTests (new tcu::TestCaseGroup(testCtx, "opquantize", "Test OpQuantizeToF16")); 7043 createOpQuantizeSingleOptionTests(opQuantizeTests.get()); 7044 createOpQuantizeTwoPossibilityTests(opQuantizeTests.get()); 7045 return opQuantizeTests.release(); 7046} 7047 7048struct ShaderPermutation 7049{ 7050 deUint8 vertexPermutation; 7051 deUint8 geometryPermutation; 7052 deUint8 tesscPermutation; 7053 deUint8 tessePermutation; 7054 deUint8 fragmentPermutation; 7055}; 7056 7057ShaderPermutation getShaderPermutation(deUint8 inputValue) 7058{ 7059 ShaderPermutation permutation = 7060 { 7061 static_cast<deUint8>(inputValue & 0x10? 1u: 0u), 7062 static_cast<deUint8>(inputValue & 0x08? 1u: 0u), 7063 static_cast<deUint8>(inputValue & 0x04? 1u: 0u), 7064 static_cast<deUint8>(inputValue & 0x02? 1u: 0u), 7065 static_cast<deUint8>(inputValue & 0x01? 1u: 0u) 7066 }; 7067 return permutation; 7068} 7069 7070tcu::TestCaseGroup* createModuleTests(tcu::TestContext& testCtx) 7071{ 7072 RGBA defaultColors[4]; 7073 RGBA invertedColors[4]; 7074 de::MovePtr<tcu::TestCaseGroup> moduleTests (new tcu::TestCaseGroup(testCtx, "module", "Multiple entry points into shaders")); 7075 7076 const ShaderElement combinedPipeline[] = 7077 { 7078 ShaderElement("module", "main", VK_SHADER_STAGE_VERTEX_BIT), 7079 ShaderElement("module", "main", VK_SHADER_STAGE_GEOMETRY_BIT), 7080 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT), 7081 ShaderElement("module", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT), 7082 ShaderElement("module", "main", VK_SHADER_STAGE_FRAGMENT_BIT) 7083 }; 7084 7085 getDefaultColors(defaultColors); 7086 getInvertedDefaultColors(invertedColors); 7087 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), "same_module", "", createCombinedModule, runAndVerifyDefaultPipeline, createInstanceContext(combinedPipeline, map<string, string>())); 7088 7089 const char* numbers[] = 7090 { 7091 "1", "2" 7092 }; 7093 7094 for (deInt8 idx = 0; idx < 32; ++idx) 7095 { 7096 ShaderPermutation permutation = getShaderPermutation(idx); 7097 string name = string("vert") + numbers[permutation.vertexPermutation] + "_geom" + numbers[permutation.geometryPermutation] + "_tessc" + numbers[permutation.tesscPermutation] + "_tesse" + numbers[permutation.tessePermutation] + "_frag" + numbers[permutation.fragmentPermutation]; 7098 const ShaderElement pipeline[] = 7099 { 7100 ShaderElement("vert", string("vert") + numbers[permutation.vertexPermutation], VK_SHADER_STAGE_VERTEX_BIT), 7101 ShaderElement("geom", string("geom") + numbers[permutation.geometryPermutation], VK_SHADER_STAGE_GEOMETRY_BIT), 7102 ShaderElement("tessc", string("tessc") + numbers[permutation.tesscPermutation], VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT), 7103 ShaderElement("tesse", string("tesse") + numbers[permutation.tessePermutation], VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT), 7104 ShaderElement("frag", string("frag") + numbers[permutation.fragmentPermutation], VK_SHADER_STAGE_FRAGMENT_BIT) 7105 }; 7106 7107 // If there are an even number of swaps, then it should be no-op. 7108 // If there are an odd number, the color should be flipped. 7109 if ((permutation.vertexPermutation + permutation.geometryPermutation + permutation.tesscPermutation + permutation.tessePermutation + permutation.fragmentPermutation) % 2 == 0) 7110 { 7111 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, defaultColors, map<string, string>())); 7112 } 7113 else 7114 { 7115 addFunctionCaseWithPrograms<InstanceContext>(moduleTests.get(), name, "", createMultipleEntries, runAndVerifyDefaultPipeline, createInstanceContext(pipeline, defaultColors, invertedColors, map<string, string>())); 7116 } 7117 } 7118 return moduleTests.release(); 7119} 7120 7121tcu::TestCaseGroup* createLoopTests(tcu::TestContext& testCtx) 7122{ 7123 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "loop", "Looping control flow")); 7124 RGBA defaultColors[4]; 7125 getDefaultColors(defaultColors); 7126 map<string, string> fragments; 7127 fragments["pre_main"] = 7128 "%c_f32_5 = OpConstant %f32 5.\n"; 7129 7130 // A loop with a single block. The Continue Target is the loop block 7131 // itself. In SPIR-V terms, the "loop construct" contains no blocks at all 7132 // -- the "continue construct" forms the entire loop. 7133 fragments["testfun"] = 7134 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7135 "%param1 = OpFunctionParameter %v4f32\n" 7136 7137 "%entry = OpLabel\n" 7138 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7139 "OpBranch %loop\n" 7140 7141 ";adds and subtracts 1.0 to %val in alternate iterations\n" 7142 "%loop = OpLabel\n" 7143 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n" 7144 "%delta = OpPhi %f32 %c_f32_1 %entry %minus_delta %loop\n" 7145 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n" 7146 "%val = OpFAdd %f32 %val1 %delta\n" 7147 "%minus_delta = OpFSub %f32 %c_f32_0 %delta\n" 7148 "%count__ = OpISub %i32 %count %c_i32_1\n" 7149 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n" 7150 "OpLoopMerge %exit %loop None\n" 7151 "OpBranchConditional %again %loop %exit\n" 7152 7153 "%exit = OpLabel\n" 7154 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n" 7155 "OpReturnValue %result\n" 7156 7157 "OpFunctionEnd\n" 7158 ; 7159 createTestsForAllStages("single_block", defaultColors, defaultColors, fragments, testGroup.get()); 7160 7161 // Body comprised of multiple basic blocks. 7162 const StringTemplate multiBlock( 7163 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7164 "%param1 = OpFunctionParameter %v4f32\n" 7165 7166 "%entry = OpLabel\n" 7167 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7168 "OpBranch %loop\n" 7169 7170 ";adds and subtracts 1.0 to %val in alternate iterations\n" 7171 "%loop = OpLabel\n" 7172 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %gather\n" 7173 "%delta = OpPhi %f32 %c_f32_1 %entry %delta_next %gather\n" 7174 "%val1 = OpPhi %f32 %val0 %entry %val %gather\n" 7175 // There are several possibilities for the Continue Target below. Each 7176 // will be specialized into a separate test case. 7177 "OpLoopMerge %exit ${continue_target} None\n" 7178 "OpBranch %if\n" 7179 7180 "%if = OpLabel\n" 7181 ";delta_next = (delta > 0) ? -1 : 1;\n" 7182 "%gt0 = OpFOrdGreaterThan %bool %delta %c_f32_0\n" 7183 "OpSelectionMerge %gather DontFlatten\n" 7184 "OpBranchConditional %gt0 %even %odd ;tells us if %count is even or odd\n" 7185 7186 "%odd = OpLabel\n" 7187 "OpBranch %gather\n" 7188 7189 "%even = OpLabel\n" 7190 "OpBranch %gather\n" 7191 7192 "%gather = OpLabel\n" 7193 "%delta_next = OpPhi %f32 %c_f32_n1 %even %c_f32_1 %odd\n" 7194 "%val = OpFAdd %f32 %val1 %delta\n" 7195 "%count__ = OpISub %i32 %count %c_i32_1\n" 7196 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n" 7197 "OpBranchConditional %again %loop %exit\n" 7198 7199 "%exit = OpLabel\n" 7200 "%result = OpVectorInsertDynamic %v4f32 %param1 %val %c_i32_0\n" 7201 "OpReturnValue %result\n" 7202 7203 "OpFunctionEnd\n"); 7204 7205 map<string, string> continue_target; 7206 7207 // The Continue Target is the loop block itself. 7208 continue_target["continue_target"] = "%loop"; 7209 fragments["testfun"] = multiBlock.specialize(continue_target); 7210 createTestsForAllStages("multi_block_continue_construct", defaultColors, defaultColors, fragments, testGroup.get()); 7211 7212 // The Continue Target is at the end of the loop. 7213 continue_target["continue_target"] = "%gather"; 7214 fragments["testfun"] = multiBlock.specialize(continue_target); 7215 createTestsForAllStages("multi_block_loop_construct", defaultColors, defaultColors, fragments, testGroup.get()); 7216 7217 // A loop with continue statement. 7218 fragments["testfun"] = 7219 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7220 "%param1 = OpFunctionParameter %v4f32\n" 7221 7222 "%entry = OpLabel\n" 7223 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7224 "OpBranch %loop\n" 7225 7226 ";adds 4, 3, and 1 to %val0 (skips 2)\n" 7227 "%loop = OpLabel\n" 7228 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n" 7229 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n" 7230 "OpLoopMerge %exit %continue None\n" 7231 "OpBranch %if\n" 7232 7233 "%if = OpLabel\n" 7234 ";skip if %count==2\n" 7235 "%eq2 = OpIEqual %bool %count %c_i32_2\n" 7236 "OpSelectionMerge %continue DontFlatten\n" 7237 "OpBranchConditional %eq2 %continue %body\n" 7238 7239 "%body = OpLabel\n" 7240 "%fcount = OpConvertSToF %f32 %count\n" 7241 "%val2 = OpFAdd %f32 %val1 %fcount\n" 7242 "OpBranch %continue\n" 7243 7244 "%continue = OpLabel\n" 7245 "%val = OpPhi %f32 %val2 %body %val1 %if\n" 7246 "%count__ = OpISub %i32 %count %c_i32_1\n" 7247 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n" 7248 "OpBranchConditional %again %loop %exit\n" 7249 7250 "%exit = OpLabel\n" 7251 "%same = OpFSub %f32 %val %c_f32_8\n" 7252 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n" 7253 "OpReturnValue %result\n" 7254 "OpFunctionEnd\n"; 7255 createTestsForAllStages("continue", defaultColors, defaultColors, fragments, testGroup.get()); 7256 7257 // A loop with early exit. May be specialized with either break or return. 7258 StringTemplate earlyExitLoop( 7259 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7260 "%param1 = OpFunctionParameter %v4f32\n" 7261 7262 "%entry = OpLabel\n" 7263 ";param1 components are between 0 and 1, so dot product is 4 or less\n" 7264 "%dot = OpDot %f32 %param1 %param1\n" 7265 "%div = OpFDiv %f32 %dot %c_f32_5\n" 7266 "%zero = OpConvertFToU %u32 %div\n" 7267 "%two = OpIAdd %i32 %zero %c_i32_2\n" 7268 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7269 "OpBranch %loop\n" 7270 7271 ";adds 4 and 3 to %val0 (exits early)\n" 7272 "%loop = OpLabel\n" 7273 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %continue\n" 7274 "%val1 = OpPhi %f32 %val0 %entry %val %continue\n" 7275 "OpLoopMerge %exit %continue None\n" 7276 "OpBranch %if\n" 7277 7278 "%if = OpLabel\n" 7279 ";end loop if %count==%two\n" 7280 "%above2 = OpSGreaterThan %bool %count %two\n" 7281 "OpSelectionMerge %continue DontFlatten\n" 7282 // This can either branch to %exit or to another block with OpReturnValue %param1. 7283 "OpBranchConditional %above2 %body ${branch_destination}\n" 7284 7285 "%body = OpLabel\n" 7286 "%fcount = OpConvertSToF %f32 %count\n" 7287 "%val2 = OpFAdd %f32 %val1 %fcount\n" 7288 "OpBranch %continue\n" 7289 7290 "%continue = OpLabel\n" 7291 "%val = OpPhi %f32 %val2 %body %val1 %if\n" 7292 "%count__ = OpISub %i32 %count %c_i32_1\n" 7293 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n" 7294 "OpBranchConditional %again %loop %exit\n" 7295 7296 "%exit = OpLabel\n" 7297 "%same = OpFSub %f32 %val %c_f32_7\n" 7298 "%result = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n" 7299 "OpReturnValue %result\n" 7300 "OpFunctionEnd\n"); 7301 7302 map<string, string> branch_destination; 7303 7304 // A loop with break. 7305 branch_destination["branch_destination"] = "%exit"; 7306 fragments["testfun"] = earlyExitLoop.specialize(branch_destination); 7307 createTestsForAllStages("break", defaultColors, defaultColors, fragments, testGroup.get()); 7308 7309 // A loop with return. 7310 branch_destination["branch_destination"] = "%early_exit\n" 7311 "%early_exit = OpLabel\n" 7312 "OpReturnValue %param1\n"; 7313 fragments["testfun"] = earlyExitLoop.specialize(branch_destination); 7314 createTestsForAllStages("return", defaultColors, defaultColors, fragments, testGroup.get()); 7315 7316 return testGroup.release(); 7317} 7318 7319// Adds a new test to group using custom fragments for the tessellation-control 7320// stage and passthrough fragments for all other stages. Uses default colors 7321// for input and expected output. 7322void addTessCtrlTest(tcu::TestCaseGroup* group, const char* name, const map<string, string>& fragments) 7323{ 7324 RGBA defaultColors[4]; 7325 getDefaultColors(defaultColors); 7326 const ShaderElement pipelineStages[] = 7327 { 7328 ShaderElement("vert", "main", VK_SHADER_STAGE_VERTEX_BIT), 7329 ShaderElement("tessc", "main", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT), 7330 ShaderElement("tesse", "main", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT), 7331 ShaderElement("geom", "main", VK_SHADER_STAGE_GEOMETRY_BIT), 7332 ShaderElement("frag", "main", VK_SHADER_STAGE_FRAGMENT_BIT), 7333 }; 7334 7335 addFunctionCaseWithPrograms<InstanceContext>(group, name, "", addShaderCodeCustomTessControl, 7336 runAndVerifyDefaultPipeline, createInstanceContext( 7337 pipelineStages, defaultColors, defaultColors, fragments, StageToSpecConstantMap())); 7338} 7339 7340// A collection of tests putting OpControlBarrier in places GLSL forbids but SPIR-V allows. 7341tcu::TestCaseGroup* createBarrierTests(tcu::TestContext& testCtx) 7342{ 7343 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "barrier", "OpControlBarrier")); 7344 map<string, string> fragments; 7345 7346 // A barrier inside a function body. 7347 fragments["pre_main"] = 7348 "%Workgroup = OpConstant %i32 2\n" 7349 "%SequentiallyConsistent = OpConstant %i32 0x10\n"; 7350 fragments["testfun"] = 7351 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7352 "%param1 = OpFunctionParameter %v4f32\n" 7353 "%label_testfun = OpLabel\n" 7354 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7355 "OpReturnValue %param1\n" 7356 "OpFunctionEnd\n"; 7357 addTessCtrlTest(testGroup.get(), "in_function", fragments); 7358 7359 // Common setup code for the following tests. 7360 fragments["pre_main"] = 7361 "%Workgroup = OpConstant %i32 2\n" 7362 "%SequentiallyConsistent = OpConstant %i32 0x10\n" 7363 "%c_f32_5 = OpConstant %f32 5.\n"; 7364 const string setupPercentZero = // Begins %test_code function with code that sets %zero to 0u but cannot be optimized away. 7365 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7366 "%param1 = OpFunctionParameter %v4f32\n" 7367 "%entry = OpLabel\n" 7368 ";param1 components are between 0 and 1, so dot product is 4 or less\n" 7369 "%dot = OpDot %f32 %param1 %param1\n" 7370 "%div = OpFDiv %f32 %dot %c_f32_5\n" 7371 "%zero = OpConvertFToU %u32 %div\n"; 7372 7373 // Barriers inside OpSwitch branches. 7374 fragments["testfun"] = 7375 setupPercentZero + 7376 "OpSelectionMerge %switch_exit None\n" 7377 "OpSwitch %zero %switch_default 0 %case0 1 %case1 ;should always go to %case0\n" 7378 7379 "%case1 = OpLabel\n" 7380 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n" 7381 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7382 "%wrong_branch_alert1 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n" 7383 "OpBranch %switch_exit\n" 7384 7385 "%switch_default = OpLabel\n" 7386 "%wrong_branch_alert2 = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n" 7387 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n" 7388 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7389 "OpBranch %switch_exit\n" 7390 7391 "%case0 = OpLabel\n" 7392 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7393 "OpBranch %switch_exit\n" 7394 7395 "%switch_exit = OpLabel\n" 7396 "%ret = OpPhi %v4f32 %param1 %case0 %wrong_branch_alert1 %case1 %wrong_branch_alert2 %switch_default\n" 7397 "OpReturnValue %ret\n" 7398 "OpFunctionEnd\n"; 7399 addTessCtrlTest(testGroup.get(), "in_switch", fragments); 7400 7401 // Barriers inside if-then-else. 7402 fragments["testfun"] = 7403 setupPercentZero + 7404 "%eq0 = OpIEqual %bool %zero %c_u32_0\n" 7405 "OpSelectionMerge %exit DontFlatten\n" 7406 "OpBranchConditional %eq0 %then %else\n" 7407 7408 "%else = OpLabel\n" 7409 ";This barrier should never be executed, but its presence makes test failure more likely when there's a bug.\n" 7410 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7411 "%wrong_branch_alert = OpVectorInsertDynamic %v4f32 %param1 %c_f32_0_5 %c_i32_0\n" 7412 "OpBranch %exit\n" 7413 7414 "%then = OpLabel\n" 7415 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7416 "OpBranch %exit\n" 7417 7418 "%exit = OpLabel\n" 7419 "%ret = OpPhi %v4f32 %param1 %then %wrong_branch_alert %else\n" 7420 "OpReturnValue %ret\n" 7421 "OpFunctionEnd\n"; 7422 addTessCtrlTest(testGroup.get(), "in_if", fragments); 7423 7424 // A barrier after control-flow reconvergence, tempting the compiler to attempt something like this: 7425 // http://lists.llvm.org/pipermail/llvm-dev/2009-October/026317.html. 7426 fragments["testfun"] = 7427 setupPercentZero + 7428 "%thread_id = OpLoad %i32 %BP_gl_InvocationID\n" 7429 "%thread0 = OpIEqual %bool %thread_id %c_i32_0\n" 7430 "OpSelectionMerge %exit DontFlatten\n" 7431 "OpBranchConditional %thread0 %then %else\n" 7432 7433 "%else = OpLabel\n" 7434 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7435 "OpBranch %exit\n" 7436 7437 "%then = OpLabel\n" 7438 "%val1 = OpVectorExtractDynamic %f32 %param1 %zero\n" 7439 "OpBranch %exit\n" 7440 7441 "%exit = OpLabel\n" 7442 "%val = OpPhi %f32 %val0 %else %val1 %then\n" 7443 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7444 "%ret = OpVectorInsertDynamic %v4f32 %param1 %val %zero\n" 7445 "OpReturnValue %ret\n" 7446 "OpFunctionEnd\n"; 7447 addTessCtrlTest(testGroup.get(), "after_divergent_if", fragments); 7448 7449 // A barrier inside a loop. 7450 fragments["pre_main"] = 7451 "%Workgroup = OpConstant %i32 2\n" 7452 "%SequentiallyConsistent = OpConstant %i32 0x10\n" 7453 "%c_f32_10 = OpConstant %f32 10.\n"; 7454 fragments["testfun"] = 7455 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7456 "%param1 = OpFunctionParameter %v4f32\n" 7457 "%entry = OpLabel\n" 7458 "%val0 = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7459 "OpBranch %loop\n" 7460 7461 ";adds 4, 3, 2, and 1 to %val0\n" 7462 "%loop = OpLabel\n" 7463 "%count = OpPhi %i32 %c_i32_4 %entry %count__ %loop\n" 7464 "%val1 = OpPhi %f32 %val0 %entry %val %loop\n" 7465 "OpControlBarrier %Workgroup %Workgroup %SequentiallyConsistent\n" 7466 "%fcount = OpConvertSToF %f32 %count\n" 7467 "%val = OpFAdd %f32 %val1 %fcount\n" 7468 "%count__ = OpISub %i32 %count %c_i32_1\n" 7469 "%again = OpSGreaterThan %bool %count__ %c_i32_0\n" 7470 "OpLoopMerge %exit %loop None\n" 7471 "OpBranchConditional %again %loop %exit\n" 7472 7473 "%exit = OpLabel\n" 7474 "%same = OpFSub %f32 %val %c_f32_10\n" 7475 "%ret = OpVectorInsertDynamic %v4f32 %param1 %same %c_i32_0\n" 7476 "OpReturnValue %ret\n" 7477 "OpFunctionEnd\n"; 7478 addTessCtrlTest(testGroup.get(), "in_loop", fragments); 7479 7480 return testGroup.release(); 7481} 7482 7483// Test for the OpFRem instruction. 7484tcu::TestCaseGroup* createFRemTests(tcu::TestContext& testCtx) 7485{ 7486 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "frem", "OpFRem")); 7487 map<string, string> fragments; 7488 RGBA inputColors[4]; 7489 RGBA outputColors[4]; 7490 7491 fragments["pre_main"] = 7492 "%c_f32_3 = OpConstant %f32 3.0\n" 7493 "%c_f32_n3 = OpConstant %f32 -3.0\n" 7494 "%c_f32_4 = OpConstant %f32 4.0\n" 7495 "%c_f32_p75 = OpConstant %f32 0.75\n" 7496 "%c_v4f32_p75_p75_p75_p75 = OpConstantComposite %v4f32 %c_f32_p75 %c_f32_p75 %c_f32_p75 %c_f32_p75 \n" 7497 "%c_v4f32_4_4_4_4 = OpConstantComposite %v4f32 %c_f32_4 %c_f32_4 %c_f32_4 %c_f32_4\n" 7498 "%c_v4f32_3_n3_3_n3 = OpConstantComposite %v4f32 %c_f32_3 %c_f32_n3 %c_f32_3 %c_f32_n3\n"; 7499 7500 // The test does the following. 7501 // vec4 result = (param1 * 8.0) - 4.0; 7502 // return (frem(result.x,3) + 0.75, frem(result.y, -3) + 0.75, 0, 1) 7503 fragments["testfun"] = 7504 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7505 "%param1 = OpFunctionParameter %v4f32\n" 7506 "%label_testfun = OpLabel\n" 7507 "%v_times_8 = OpVectorTimesScalar %v4f32 %param1 %c_f32_8\n" 7508 "%minus_4 = OpFSub %v4f32 %v_times_8 %c_v4f32_4_4_4_4\n" 7509 "%frem = OpFRem %v4f32 %minus_4 %c_v4f32_3_n3_3_n3\n" 7510 "%added = OpFAdd %v4f32 %frem %c_v4f32_p75_p75_p75_p75\n" 7511 "%xyz_1 = OpVectorInsertDynamic %v4f32 %added %c_f32_1 %c_i32_3\n" 7512 "%xy_0_1 = OpVectorInsertDynamic %v4f32 %xyz_1 %c_f32_0 %c_i32_2\n" 7513 "OpReturnValue %xy_0_1\n" 7514 "OpFunctionEnd\n"; 7515 7516 7517 inputColors[0] = RGBA(16, 16, 0, 255); 7518 inputColors[1] = RGBA(232, 232, 0, 255); 7519 inputColors[2] = RGBA(232, 16, 0, 255); 7520 inputColors[3] = RGBA(16, 232, 0, 255); 7521 7522 outputColors[0] = RGBA(64, 64, 0, 255); 7523 outputColors[1] = RGBA(255, 255, 0, 255); 7524 outputColors[2] = RGBA(255, 64, 0, 255); 7525 outputColors[3] = RGBA(64, 255, 0, 255); 7526 7527 createTestsForAllStages("frem", inputColors, outputColors, fragments, testGroup.get()); 7528 return testGroup.release(); 7529} 7530 7531tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx) 7532{ 7533 de::MovePtr<tcu::TestCaseGroup> instructionTests (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands")); 7534 de::MovePtr<tcu::TestCaseGroup> computeTests (new tcu::TestCaseGroup(testCtx, "compute", "Compute Instructions with special opcodes/operands")); 7535 de::MovePtr<tcu::TestCaseGroup> graphicsTests (new tcu::TestCaseGroup(testCtx, "graphics", "Graphics Instructions with special opcodes/operands")); 7536 7537 computeTests->addChild(createOpNopGroup(testCtx)); 7538 computeTests->addChild(createOpLineGroup(testCtx)); 7539 computeTests->addChild(createOpNoLineGroup(testCtx)); 7540 computeTests->addChild(createOpConstantNullGroup(testCtx)); 7541 computeTests->addChild(createOpConstantCompositeGroup(testCtx)); 7542 computeTests->addChild(createOpConstantUsageGroup(testCtx)); 7543 computeTests->addChild(createSpecConstantGroup(testCtx)); 7544 computeTests->addChild(createOpSourceGroup(testCtx)); 7545 computeTests->addChild(createOpSourceExtensionGroup(testCtx)); 7546 computeTests->addChild(createDecorationGroupGroup(testCtx)); 7547 computeTests->addChild(createOpPhiGroup(testCtx)); 7548 computeTests->addChild(createLoopControlGroup(testCtx)); 7549 computeTests->addChild(createFunctionControlGroup(testCtx)); 7550 computeTests->addChild(createSelectionControlGroup(testCtx)); 7551 computeTests->addChild(createBlockOrderGroup(testCtx)); 7552 computeTests->addChild(createMultipleShaderGroup(testCtx)); 7553 computeTests->addChild(createMemoryAccessGroup(testCtx)); 7554 computeTests->addChild(createOpCopyMemoryGroup(testCtx)); 7555 computeTests->addChild(createOpCopyObjectGroup(testCtx)); 7556 computeTests->addChild(createNoContractionGroup(testCtx)); 7557 computeTests->addChild(createOpUndefGroup(testCtx)); 7558 computeTests->addChild(createOpUnreachableGroup(testCtx)); 7559 computeTests ->addChild(createOpQuantizeToF16Group(testCtx)); 7560 computeTests ->addChild(createOpFRemGroup(testCtx)); 7561 7562 RGBA defaultColors[4]; 7563 getDefaultColors(defaultColors); 7564 7565 de::MovePtr<tcu::TestCaseGroup> opnopTests (new tcu::TestCaseGroup(testCtx, "opnop", "Test OpNop")); 7566 map<string, string> opNopFragments; 7567 opNopFragments["testfun"] = 7568 "%test_code = OpFunction %v4f32 None %v4f32_function\n" 7569 "%param1 = OpFunctionParameter %v4f32\n" 7570 "%label_testfun = OpLabel\n" 7571 "OpNop\n" 7572 "OpNop\n" 7573 "OpNop\n" 7574 "OpNop\n" 7575 "OpNop\n" 7576 "OpNop\n" 7577 "OpNop\n" 7578 "OpNop\n" 7579 "%a = OpVectorExtractDynamic %f32 %param1 %c_i32_0\n" 7580 "%b = OpFAdd %f32 %a %a\n" 7581 "OpNop\n" 7582 "%c = OpFSub %f32 %b %a\n" 7583 "%ret = OpVectorInsertDynamic %v4f32 %param1 %c %c_i32_0\n" 7584 "OpNop\n" 7585 "OpNop\n" 7586 "OpReturnValue %ret\n" 7587 "OpFunctionEnd\n" 7588 ; 7589 createTestsForAllStages("opnop", defaultColors, defaultColors, opNopFragments, opnopTests.get()); 7590 7591 7592 graphicsTests->addChild(opnopTests.release()); 7593 graphicsTests->addChild(createOpSourceTests(testCtx)); 7594 graphicsTests->addChild(createOpSourceContinuedTests(testCtx)); 7595 graphicsTests->addChild(createOpLineTests(testCtx)); 7596 graphicsTests->addChild(createOpNoLineTests(testCtx)); 7597 graphicsTests->addChild(createOpConstantNullTests(testCtx)); 7598 graphicsTests->addChild(createOpConstantCompositeTests(testCtx)); 7599 graphicsTests->addChild(createMemoryAccessTests(testCtx)); 7600 graphicsTests->addChild(createOpUndefTests(testCtx)); 7601 graphicsTests->addChild(createSelectionBlockOrderTests(testCtx)); 7602 graphicsTests->addChild(createModuleTests(testCtx)); 7603 graphicsTests->addChild(createSwitchBlockOrderTests(testCtx)); 7604 graphicsTests->addChild(createOpPhiTests(testCtx)); 7605 graphicsTests->addChild(createNoContractionTests(testCtx)); 7606 graphicsTests->addChild(createOpQuantizeTests(testCtx)); 7607 graphicsTests->addChild(createLoopTests(testCtx)); 7608 graphicsTests->addChild(createSpecConstantTests(testCtx)); 7609 graphicsTests->addChild(createSpecConstantOpQuantizeToF16Group(testCtx)); 7610 graphicsTests->addChild(createBarrierTests(testCtx)); 7611 graphicsTests->addChild(createDecorationGroupTests(testCtx)); 7612 graphicsTests->addChild(createFRemTests(testCtx)); 7613 7614 instructionTests->addChild(computeTests.release()); 7615 instructionTests->addChild(graphicsTests.release()); 7616 7617 return instructionTests.release(); 7618} 7619 7620} // SpirVAssembly 7621} // vkt 7622