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