From 6ae3c9086c8ee6dcbdc7fb61e1d2fecc04f4c98c Mon Sep 17 00:00:00 2001 From: David Neto Date: Thu, 14 Sep 2017 18:03:37 -0400 Subject: [PATCH] Test reading compute shader builtin vars by component - Adds a test of reading compute shader builtin variables by component. These get test case name suffix of "_component". - Previous behaviour, reading the whole builtin variable, is preserved in cases but without an extra suffix. - WorkgroupSize builtin is made specializable to prevent Glslang from constant folding its value. Affects: Components: Vulkan dEQP-VK.compute.builtin_var.* VK-GL-CTS issue: 694 Change-Id: Ia783babf4ba5e24fc58bc9d19594bb7d921de7c9 --- android/cts/master/vk-master.txt | 5 ++ .../compute/vktComputeShaderBuiltinVarTests.cpp | 98 +++++++++++++++------- external/vulkancts/mustpass/1.0.3/vk-default.txt | 5 ++ 3 files changed, 76 insertions(+), 32 deletions(-) diff --git a/android/cts/master/vk-master.txt b/android/cts/master/vk-master.txt index eb1443d..94c3ec3 100644 --- a/android/cts/master/vk-master.txt +++ b/android/cts/master/vk-master.txt @@ -201975,6 +201975,11 @@ dEQP-VK.compute.builtin_var.work_group_size dEQP-VK.compute.builtin_var.work_group_id dEQP-VK.compute.builtin_var.local_invocation_id dEQP-VK.compute.builtin_var.global_invocation_id +dEQP-VK.compute.builtin_var.num_work_groups_component +dEQP-VK.compute.builtin_var.work_group_size_component +dEQP-VK.compute.builtin_var.work_group_id_component +dEQP-VK.compute.builtin_var.local_invocation_id_component +dEQP-VK.compute.builtin_var.global_invocation_id_component dEQP-VK.compute.builtin_var.local_invocation_index dEQP-VK.image.store.with_format.1d.r32g32b32a32_sfloat dEQP-VK.image.store.with_format.1d.r16g16b16a16_sfloat diff --git a/external/vulkancts/modules/vulkan/compute/vktComputeShaderBuiltinVarTests.cpp b/external/vulkancts/modules/vulkan/compute/vktComputeShaderBuiltinVarTests.cpp index b5b949b..1523140 100644 --- a/external/vulkancts/modules/vulkan/compute/vktComputeShaderBuiltinVarTests.cpp +++ b/external/vulkancts/modules/vulkan/compute/vktComputeShaderBuiltinVarTests.cpp @@ -143,7 +143,7 @@ private: class ComputeBuiltinVarCase : public vkt::TestCase { public: - ComputeBuiltinVarCase (tcu::TestContext& context, const char* name, const char* varName, glu::DataType varType); + ComputeBuiltinVarCase (tcu::TestContext& context, const string& name, const char* varName, glu::DataType varType, bool readByComponent); ~ComputeBuiltinVarCase (void); TestInstance* createInstance (Context& context) const @@ -155,7 +155,7 @@ public: virtual UVec3 computeReference (const UVec3& numWorkGroups, const UVec3& workGroupSize, const UVec3& workGroupID, const UVec3& localInvocationID) const = 0; protected: - string genBuiltinVarSource (const string& varName, glu::DataType varType, const UVec3& localSize) const; + string genBuiltinVarSource (const string& varName, glu::DataType varType, const UVec3& localSize, bool readByComponent) const; vector m_subCases; private: @@ -164,16 +164,18 @@ private: const string m_varName; const glu::DataType m_varType; int m_subCaseNdx; + bool m_readByComponent; ComputeBuiltinVarCase (const ComputeBuiltinVarCase& other); ComputeBuiltinVarCase& operator= (const ComputeBuiltinVarCase& other); }; -ComputeBuiltinVarCase::ComputeBuiltinVarCase (tcu::TestContext& context, const char* name, const char* varName, glu::DataType varType) - : TestCase (context, name, varName) - , m_varName (varName) - , m_varType (varType) - , m_subCaseNdx (0) +ComputeBuiltinVarCase::ComputeBuiltinVarCase (tcu::TestContext& context, const string& name, const char* varName, glu::DataType varType, bool readByComponent) + : TestCase (context, name + (readByComponent ? "_component" : ""), varName) + , m_varName (varName) + , m_varType (varType) + , m_subCaseNdx (0) + , m_readByComponent (readByComponent) { } @@ -189,17 +191,23 @@ void ComputeBuiltinVarCase::initPrograms (SourceCollections& programCollection) const SubCase& subCase = m_subCases[i]; std::ostringstream name; name << s_prefixProgramName << i; - programCollection.glslSources.add(name.str()) << glu::ComputeSource(genBuiltinVarSource(m_varName, m_varType, subCase.localSize()).c_str()); + programCollection.glslSources.add(name.str()) << glu::ComputeSource(genBuiltinVarSource(m_varName, m_varType, subCase.localSize(), m_readByComponent).c_str()); } } -string ComputeBuiltinVarCase::genBuiltinVarSource (const string& varName, glu::DataType varType, const UVec3& localSize) const +string ComputeBuiltinVarCase::genBuiltinVarSource (const string& varName, glu::DataType varType, const UVec3& localSize, bool readByComponent) const { std::ostringstream src; src << "#version 310 es\n" - << "layout (local_size_x = " << localSize.x() << ", local_size_y = " << localSize.y() << ", local_size_z = " << localSize.z() << ") in;\n" - << "layout(set = 0, binding = 0) uniform Stride\n" + << "layout (local_size_x = " << localSize.x() << ", local_size_y = " << localSize.y() << ", local_size_z = " << localSize.z() << ") in;\n"; + + // For the gl_WorkGroupSize case, force it to be specialized so that + // Glslang can't just bypass the read of the builtin variable. + // We will not override these spec constants. + src << "layout (local_size_x_id = 0, local_size_y_id = 1, local_size_z_id = 2) in;\n"; + + src << "layout(set = 0, binding = 0) uniform Stride\n" << "{\n" << " uvec2 u_stride;\n" << "}stride;\n" @@ -210,9 +218,29 @@ string ComputeBuiltinVarCase::genBuiltinVarSource (const string& varName, glu::D << "\n" << "void main (void)\n" << "{\n" - << " highp uint offset = stride.u_stride.x*gl_GlobalInvocationID.z + stride.u_stride.y*gl_GlobalInvocationID.y + gl_GlobalInvocationID.x;\n" - << " sb_out.result[offset] = " << varName << ";\n" - << "}\n"; + << " highp uint offset = stride.u_stride.x*gl_GlobalInvocationID.z + stride.u_stride.y*gl_GlobalInvocationID.y + gl_GlobalInvocationID.x;\n"; + + if (readByComponent && varType != glu::TYPE_UINT) { + switch(varType) + { + case glu::TYPE_UINT_VEC4: + src << " sb_out.result[offset].w = " << varName << ".w;\n"; + // Fall through + case glu::TYPE_UINT_VEC3: + src << " sb_out.result[offset].z = " << varName << ".z;\n"; + // Fall through + case glu::TYPE_UINT_VEC2: + src << " sb_out.result[offset].y = " << varName << ".y;\n" + << " sb_out.result[offset].x = " << varName << ".x;\n"; + break; + default: + DE_ASSERT("Illegal data type"); + break; + } + } else { + src << " sb_out.result[offset] = " << varName << ";\n"; + } + src << "}\n"; return src.str(); } @@ -220,8 +248,8 @@ string ComputeBuiltinVarCase::genBuiltinVarSource (const string& varName, glu::D class NumWorkGroupsCase : public ComputeBuiltinVarCase { public: - NumWorkGroupsCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "num_work_groups", "gl_NumWorkGroups", glu::TYPE_UINT_VEC3) + NumWorkGroupsCase (tcu::TestContext& context, bool readByCompnent) + : ComputeBuiltinVarCase(context, "num_work_groups", "gl_NumWorkGroups", glu::TYPE_UINT_VEC3, readByCompnent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(52, 1, 1))); @@ -244,8 +272,8 @@ public: class WorkGroupSizeCase : public ComputeBuiltinVarCase { public: - WorkGroupSizeCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "work_group_size", "gl_WorkGroupSize", glu::TYPE_UINT_VEC3) + WorkGroupSizeCase (tcu::TestContext& context, bool readByComponent) + : ComputeBuiltinVarCase(context, "work_group_size", "gl_WorkGroupSize", glu::TYPE_UINT_VEC3, readByComponent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(2, 7, 3))); @@ -271,8 +299,8 @@ public: class WorkGroupIDCase : public ComputeBuiltinVarCase { public: - WorkGroupIDCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "work_group_id", "gl_WorkGroupID", glu::TYPE_UINT_VEC3) + WorkGroupIDCase (tcu::TestContext& context, bool readbyComponent) + : ComputeBuiltinVarCase(context, "work_group_id", "gl_WorkGroupID", glu::TYPE_UINT_VEC3, readbyComponent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(52, 1, 1))); @@ -294,8 +322,8 @@ public: class LocalInvocationIDCase : public ComputeBuiltinVarCase { public: - LocalInvocationIDCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "local_invocation_id", "gl_LocalInvocationID", glu::TYPE_UINT_VEC3) + LocalInvocationIDCase (tcu::TestContext& context, bool readByComponent) + : ComputeBuiltinVarCase(context, "local_invocation_id", "gl_LocalInvocationID", glu::TYPE_UINT_VEC3, readByComponent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(2, 7, 3))); @@ -320,8 +348,8 @@ public: class GlobalInvocationIDCase : public ComputeBuiltinVarCase { public: - GlobalInvocationIDCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "global_invocation_id", "gl_GlobalInvocationID", glu::TYPE_UINT_VEC3) + GlobalInvocationIDCase (tcu::TestContext& context, bool readByComponent) + : ComputeBuiltinVarCase(context, "global_invocation_id", "gl_GlobalInvocationID", glu::TYPE_UINT_VEC3, readByComponent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(52, 1, 1))); @@ -343,8 +371,8 @@ public: class LocalInvocationIndexCase : public ComputeBuiltinVarCase { public: - LocalInvocationIndexCase (tcu::TestContext& context) - : ComputeBuiltinVarCase(context, "local_invocation_index", "gl_LocalInvocationIndex", glu::TYPE_UINT) + LocalInvocationIndexCase (tcu::TestContext& context, bool readByComponent) + : ComputeBuiltinVarCase(context, "local_invocation_index", "gl_LocalInvocationIndex", glu::TYPE_UINT, readByComponent) { m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 1, 1))); m_subCases.push_back(SubCase(UVec3(1, 1, 1), UVec3(1, 39, 1))); @@ -546,12 +574,18 @@ ComputeShaderBuiltinVarTests::ComputeShaderBuiltinVarTests (tcu::TestContext& co void ComputeShaderBuiltinVarTests::init (void) { - addChild(new NumWorkGroupsCase(this->getTestContext())); - addChild(new WorkGroupSizeCase(this->getTestContext())); - addChild(new WorkGroupIDCase(this->getTestContext())); - addChild(new LocalInvocationIDCase(this->getTestContext())); - addChild(new GlobalInvocationIDCase(this->getTestContext())); - addChild(new LocalInvocationIndexCase(this->getTestContext())); + // Builtin variables with vector values should be read whole and by component. + for (int i = 0; i < 2; i++) + { + const bool readByComponent = (i != 0); + addChild(new NumWorkGroupsCase(this->getTestContext(), readByComponent)); + addChild(new WorkGroupSizeCase(this->getTestContext(), readByComponent)); + addChild(new WorkGroupIDCase(this->getTestContext(), readByComponent)); + addChild(new LocalInvocationIDCase(this->getTestContext(), readByComponent)); + addChild(new GlobalInvocationIDCase(this->getTestContext(), readByComponent)); + } + // Local invocation index is already just a scalar. + addChild(new LocalInvocationIndexCase(this->getTestContext(), false)); } } // anonymous diff --git a/external/vulkancts/mustpass/1.0.3/vk-default.txt b/external/vulkancts/mustpass/1.0.3/vk-default.txt index 9ba2712..d1d5d1b 100644 --- a/external/vulkancts/mustpass/1.0.3/vk-default.txt +++ b/external/vulkancts/mustpass/1.0.3/vk-default.txt @@ -201960,6 +201960,11 @@ dEQP-VK.compute.builtin_var.work_group_size dEQP-VK.compute.builtin_var.work_group_id dEQP-VK.compute.builtin_var.local_invocation_id dEQP-VK.compute.builtin_var.global_invocation_id +dEQP-VK.compute.builtin_var.num_work_groups_component +dEQP-VK.compute.builtin_var.work_group_size_component +dEQP-VK.compute.builtin_var.work_group_id_component +dEQP-VK.compute.builtin_var.local_invocation_id_component +dEQP-VK.compute.builtin_var.global_invocation_id_component dEQP-VK.compute.builtin_var.local_invocation_index dEQP-VK.image.store.with_format.1d.r32g32b32a32_sfloat dEQP-VK.image.store.with_format.1d.r16g16b16a16_sfloat -- 2.7.4