1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2021 The Khronos Group Inc.
6  * Copyright (c) 2016 The Android Open Source Project
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21 * \file
22 * \brief VK_KHR_format_feature_flags2 Tests.
23 *//*--------------------------------------------------------------------*/
24 
25 #include "vktApiFormatPropertiesExtendedKHRtests.hpp"
26 #include "vktTestCase.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vktTestGroupUtil.hpp"
29 #include "vkStrUtil.hpp"
30 
31 #include <iostream>
32 #include <iomanip>
33 
34 namespace
35 {
36 using namespace vk;
37 using namespace vkt;
38 
checkSupport(Context & context,const VkFormat format)39 void checkSupport(Context &context, const VkFormat format)
40 {
41     DE_UNREF(format);
42     context.requireDeviceFunctionality(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME);
43     context.requireInstanceFunctionality(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
44 }
45 
checkFlags(VkFlags64 reportedFlags,VkFlags64 requestedFlags,const char * setName)46 void checkFlags(VkFlags64 reportedFlags, VkFlags64 requestedFlags, const char *setName)
47 {
48     const auto andMask = (reportedFlags & requestedFlags);
49     if (andMask != requestedFlags)
50     {
51         // Find which bits are missing.
52         const auto missingBits = (andMask ^ requestedFlags);
53         std::ostringstream msg;
54         msg << setName << ": missing flags 0x" << std::hex << std::setw(16) << std::setfill('0') << missingBits;
55         TCU_FAIL(msg.str());
56     }
57 }
58 
test(Context & context,const VkFormat format)59 tcu::TestStatus test(Context &context, const VkFormat format)
60 {
61     const VkFormatProperties3 formatProperties(context.getFormatProperties(format));
62     const VkFormatProperties3 requiredProperties(context.getRequiredFormatProperties(format));
63 
64     checkFlags(formatProperties.bufferFeatures, requiredProperties.bufferFeatures, "Buffer features");
65     checkFlags(formatProperties.linearTilingFeatures, requiredProperties.linearTilingFeatures,
66                "Linear tiling features");
67     checkFlags(formatProperties.optimalTilingFeatures, requiredProperties.optimalTilingFeatures,
68                "Optimal tiling features");
69 
70     return tcu::TestStatus::pass("Pass");
71 }
72 
createTestCases(tcu::TestCaseGroup * group)73 void createTestCases(tcu::TestCaseGroup *group)
74 {
75     for (VkFormat format = VK_FORMAT_R4G4_UNORM_PACK8; format < VK_CORE_FORMAT_LAST;
76          format          = static_cast<VkFormat>(format + 1))
77     {
78         std::string testName = de::toLower(std::string(getFormatName(format)).substr(10));
79         addFunctionCase(group, testName, checkSupport, test, format);
80     }
81 }
82 
83 } // namespace
84 
85 namespace vkt
86 {
87 namespace api
88 {
89 
createFormatPropertiesExtendedKHRTests(tcu::TestContext & testCtx)90 tcu::TestCaseGroup *createFormatPropertiesExtendedKHRTests(tcu::TestContext &testCtx)
91 {
92     return createTestGroup(testCtx, "format_feature_flags2", createTestCases);
93 }
94 
95 } // namespace api
96 } // namespace vkt
97