Add tests for initialized and uninitialized cases.
authorGabor Abraham <gabraham.u-szeged@partner.samsung.com>
Tue, 19 Jul 2016 14:07:10 +0000 (16:07 +0200)
committerPyry Haulos <phaulos@google.com>
Tue, 30 Aug 2016 17:50:21 +0000 (10:50 -0700)
Change-Id: I0eaddc7d5ebafc4532536d810bf4b30b38985d19

android/cts/master/com.drawelements.deqp.vk.xml
android/cts/master/vk-master.txt
external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmInstructionTests.cpp
external/vulkancts/mustpass/1.0.1/vk-default.txt

index 2021dda99cc5304367cebc1957965177e12080d6..6ec1fd39cedbd43e9ee04a73ca7547335180fe59 100644 (file)
                                                        </Test>
                                                </TestCase>
                                        </TestSuite>
+                                       <TestSuite name="shader_default_output">
+                                               <TestCase name="int">
+                                                       <Test name="initialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                                       <Test name="uninitialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                               </TestCase>
+                                               <TestCase name="uint">
+                                                       <Test name="initialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                                       <Test name="uninitialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                               </TestCase>
+                                               <TestCase name="float">
+                                                       <Test name="initialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                                       <Test name="uninitialized">
+                                                               <TestInstance/>
+                                                       </Test>
+                                               </TestCase>
+                                       </TestSuite>
                                </TestSuite>
                                <TestSuite name="graphics">
                                        <TestCase name="opnop">
index bf57c2657efebece49b583dcdd8bf49a86cd5468..724df6fa42d74a3cc4e8be68d7d9c9867d8ca48c 100644 (file)
@@ -77604,6 +77604,12 @@ dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_3x
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x2
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x3
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x4
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.int.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.int.uninitialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.uint.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.uint.uninitialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.float.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.float.uninitialized
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_vert
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_tessc
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_tesse
index f186e4f97ae818043134aedd0689e97abf22a6bf..dc6f16d7e98666ec3eaeb77ff0fd644efb120a00 100644 (file)
@@ -8741,6 +8741,195 @@ tcu::TestCaseGroup* createOpInBoundsAccessChainGroup (tcu::TestContext& testCtx)
        return group.release();
 }
 
+// If the params missing, uninitialized case
+const string specializeDefaultOutputShaderTemplate (const NumberType type, const map<string, string>& params = map<string, string>())
+{
+       map<string, string> parameters(params);
+
+       parameters["typeDeclaration"] = getAssemblyTypeDeclaration(type);
+
+       // Declare the const value, and use it in the initializer
+       if (params.find("constValue") != params.end())
+       {
+               parameters["constDeclaration"]          = "%const      = OpConstant %in_type " + params.at("constValue") + "\n";
+               parameters["variableInitializer"]       = "%const";
+       }
+       // Uninitialized case
+       else
+       {
+               parameters["constDeclaration"]          = "";
+               parameters["variableInitializer"]       = "";
+       }
+
+       return StringTemplate(
+               "OpCapability Shader\n"
+               "OpMemoryModel Logical GLSL450\n"
+               "OpEntryPoint GLCompute %main \"main\" %id\n"
+               "OpExecutionMode %main LocalSize 1 1 1\n"
+               "OpSource GLSL 430\n"
+               "OpName %main           \"main\"\n"
+               "OpName %id             \"gl_GlobalInvocationID\"\n"
+               // Decorators
+               "OpDecorate %id BuiltIn GlobalInvocationId\n"
+               "OpDecorate %indata DescriptorSet 0\n"
+               "OpDecorate %indata Binding 0\n"
+               "OpDecorate %outdata DescriptorSet 0\n"
+               "OpDecorate %outdata Binding 1\n"
+               "OpDecorate %in_arr ArrayStride 4\n"
+               "OpDecorate %in_buf BufferBlock\n"
+               "OpMemberDecorate %in_buf 0 Offset 0\n"
+               // Base types
+               "%void       = OpTypeVoid\n"
+               "%voidf      = OpTypeFunction %void\n"
+               "%u32        = OpTypeInt 32 0\n"
+               "%i32        = OpTypeInt 32 1\n"
+               "%uvec3      = OpTypeVector %u32 3\n"
+               "%uvec3ptr   = OpTypePointer Input %uvec3\n"
+               // Custom types
+               "%in_type    = ${typeDeclaration}\n"
+               // "%const      = OpConstant %in_type ${constValue}\n"
+               "${constDeclaration}\n"
+               // Derived types
+               "%in_ptr     = OpTypePointer Uniform %in_type\n"
+               "%in_arr     = OpTypeRuntimeArray %in_type\n"
+               "%in_buf     = OpTypeStruct %in_arr\n"
+               "%in_bufptr  = OpTypePointer Uniform %in_buf\n"
+               "%indata     = OpVariable %in_bufptr Uniform\n"
+               "%outdata    = OpVariable %in_bufptr Uniform\n"
+               "%id         = OpVariable %uvec3ptr Input\n"
+               "%var_ptr    = OpTypePointer Function %in_type\n"
+               // Constants
+               "%zero       = OpConstant %i32 0\n"
+               // Main function
+               "%main       = OpFunction %void None %voidf\n"
+               "%label      = OpLabel\n"
+               "%idval      = OpLoad %uvec3 %id\n"
+               "%x          = OpCompositeExtract %u32 %idval 0\n"
+               "%inloc      = OpAccessChain %in_ptr %indata %zero %x\n"
+               "%outloc     = OpAccessChain %in_ptr %outdata %zero %x\n"
+
+               "%out_var    = OpVariable %var_ptr Function ${variableInitializer}\n"
+               "%outval     = OpLoad %in_type %out_var\n"
+               "              OpStore %outloc %outval\n"
+               "              OpReturn\n"
+               "              OpFunctionEnd\n"
+       ).specialize(parameters);
+}
+
+bool compareFloats (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog& log)
+{
+       DE_ASSERT(outputAllocs.size() != 0);
+       DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
+
+       // Use custom epsilon because of the float->string conversion
+       const float     epsilon = 0.00001f;
+
+       for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
+       {
+               float expected;
+               memcpy(&expected, expectedOutputs[outputNdx]->data(), expectedOutputs[outputNdx]->getNumBytes());
+
+               float actual;
+               memcpy(&actual, outputAllocs[outputNdx]->getHostPtr(), expectedOutputs[outputNdx]->getNumBytes());
+
+               // Test with epsilon
+               if (fabs(expected - actual) > epsilon)
+               {
+                       log << TestLog::Message << "Error: The actual and expected values not matching."
+                               << " Expected: " << expected << " Actual: " << actual << " Epsilon: " << epsilon << TestLog::EndMessage;
+                       return false;
+               }
+       }
+       return true;
+}
+
+// Checks if the driver crash with uninitialized cases
+bool passthruVerify (const std::vector<BufferSp>&, const vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, TestLog&)
+{
+       DE_ASSERT(outputAllocs.size() != 0);
+       DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
+
+       // Copy and discard the result.
+       for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
+       {
+               size_t width = expectedOutputs[outputNdx]->getNumBytes();
+
+               vector<char> data(width);
+               memcpy(&data[0], outputAllocs[outputNdx]->getHostPtr(), width);
+       }
+       return true;
+}
+
+tcu::TestCaseGroup* createShaderDefaultOutputGroup (tcu::TestContext& testCtx)
+{
+       de::MovePtr<tcu::TestCaseGroup> group   (new tcu::TestCaseGroup(testCtx, "shader_default_output", "Test shader default output."));
+       de::Random                                              rnd             (deStringHash(group->getName()));
+
+       for (int type = TYPE_INT; type != TYPE_END; ++type)
+       {
+               NumberType                                              numberType      = NumberType(type);
+               const string                                    typeName        = getNumberTypeName(numberType);
+               const string                                    description     = "Test the OpVariable initializer with " + typeName + ".";
+               de::MovePtr<tcu::TestCaseGroup> subGroup        (new tcu::TestCaseGroup(testCtx, typeName.c_str(), description.c_str()));
+
+               // 2 similar subcases (initialized and uninitialized)
+               for (int subCase = 0; subCase < 2; ++subCase)
+               {
+                       ComputeShaderSpec spec;
+                       spec.numWorkGroups = IVec3(1, 1, 1);
+
+                       map<string, string>                             params;
+
+                       switch (numberType)
+                       {
+                               case TYPE_INT:
+                               {
+                                       deInt32 number = getInt(rnd);
+                                       spec.inputs.push_back(createCompositeBuffer<deInt32>(number));
+                                       spec.outputs.push_back(createCompositeBuffer<deInt32>(number));
+                                       params["constValue"] = numberToString(number);
+                                       break;
+                               }
+                               case TYPE_UINT:
+                               {
+                                       deUint32 number = rnd.getUint32();
+                                       spec.inputs.push_back(createCompositeBuffer<deUint32>(number));
+                                       spec.outputs.push_back(createCompositeBuffer<deUint32>(number));
+                                       params["constValue"] = numberToString(number);
+                                       break;
+                               }
+                               case TYPE_FLOAT:
+                               {
+                                       float number = rnd.getFloat();
+                                       spec.inputs.push_back(createCompositeBuffer<float>(number));
+                                       spec.outputs.push_back(createCompositeBuffer<float>(number));
+                                       spec.verifyIO = &compareFloats;
+                                       params["constValue"] = numberToString(number);
+                                       break;
+                               }
+                               default:
+                                       DE_ASSERT(false);
+                       }
+
+                       // Initialized subcase
+                       if (!subCase)
+                       {
+                               spec.assembly = specializeDefaultOutputShaderTemplate(numberType, params);
+                               subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "initialized", "OpVariable initializer tests.", spec));
+                       }
+                       // Uninitialized subcase
+                       else
+                       {
+                               spec.assembly = specializeDefaultOutputShaderTemplate(numberType);
+                               spec.verifyIO = &passthruVerify;
+                               subGroup->addChild(new SpvAsmComputeShaderCase(testCtx, "uninitialized", "OpVariable initializer tests.", spec));
+                       }
+               }
+               group->addChild(subGroup.release());
+       }
+       return group.release();
+}
+
 tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
 {
        de::MovePtr<tcu::TestCaseGroup> instructionTests        (new tcu::TestCaseGroup(testCtx, "instruction", "Instructions with special opcodes/operands"));
@@ -8777,6 +8966,7 @@ tcu::TestCaseGroup* createInstructionTests (tcu::TestContext& testCtx)
        computeTests->addChild(createUConvertTests(testCtx));
        computeTests->addChild(createOpCompositeInsertGroup(testCtx));
        computeTests->addChild(createOpInBoundsAccessChainGroup(testCtx));
+       computeTests->addChild(createShaderDefaultOutputGroup(testCtx));
 
        RGBA defaultColors[4];
        getDefaultColors(defaultColors);
index 34b9ea98573388de736f64a391974a5d74bedf11..122934f0a775cbea360d1ddc304c145483f0019d 100644 (file)
@@ -71466,6 +71466,12 @@ dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_3x
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x2
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x3
 dEQP-VK.spirv_assembly.instruction.compute.opinboundsaccesschain.float.matrix_4x4
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.int.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.int.uninitialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.uint.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.uint.uninitialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.float.initialized
+dEQP-VK.spirv_assembly.instruction.compute.shader_default_output.float.uninitialized
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_vert
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_tessc
 dEQP-VK.spirv_assembly.instruction.graphics.opnop.opnop_tesse