xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/texture/vktTextureTexelBufferTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2020 The Khronos Group Inc.
6  * Copyright (c) 2020 Google Inc.
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 Texel buffer tests.
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktTextureTexelBufferTests.hpp"
26 #include "vktAmberTestCase.hpp"
27 #include "vktTestGroupUtil.hpp"
28 
29 using namespace vk;
30 
31 namespace vkt
32 {
33 namespace texture
34 {
35 namespace
36 {
37 
createUniformTexelBufferTests(tcu::TestContext & testCtx)38 tcu::TestCaseGroup *createUniformTexelBufferTests(tcu::TestContext &testCtx)
39 {
40     de::MovePtr<tcu::TestCaseGroup> uniform(new tcu::TestCaseGroup(testCtx, "uniform"));
41 
42     // .srgb
43     {
44         tcu::TestCaseGroup *const srgb = new tcu::TestCaseGroup(testCtx, "srgb");
45         static const char dataDir[]    = "texture/texel_buffer/uniform/srgb";
46 
47         static const struct
48         {
49             std::string testName;
50             VkFormat format;
51         } cases[] = {{"r8g8b8a8_srgb", VK_FORMAT_R8G8B8A8_SRGB}, {"b8g8r8a8_srgb", VK_FORMAT_B8G8R8A8_SRGB},
52                      {"b8g8r8_srgb", VK_FORMAT_B8G8R8_SRGB},     {"r8g8b8_srgb", VK_FORMAT_R8G8B8_SRGB},
53                      {"r8g8_srgb", VK_FORMAT_R8G8_SRGB},         {"r8_srgb", VK_FORMAT_R8_SRGB}};
54 
55         uniform->addChild(srgb);
56 
57         for (int i = 0; i < DE_LENGTH_OF_ARRAY(cases); ++i)
58         {
59             const std::string fileName         = cases[i].testName + ".amber";
60             const VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
61 
62             const uint32_t width  = 8;
63             const uint32_t height = 8;
64 
65             VkImageCreateInfo imageParams = {
66                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, //  VkStructureType         sType;
67                 DE_NULL,                             //  const void*             pNext;
68                 DE_NULL,                             //  VkImageCreateFlags      flags;
69                 VK_IMAGE_TYPE_2D,                    //  VkImageType             imageType;
70                 cases[i].format,                     //  VkFormat                format;
71                 VkExtent3D({width, height, 1u}),     //  VkExtent3D              extent;
72                 1u,                                  //  uint32_t                mipLevels;
73                 1u,                                  //  uint32_t                arrayLayers;
74                 VK_SAMPLE_COUNT_1_BIT,               //  VkSampleCountFlagBits   samples;
75                 VK_IMAGE_TILING_OPTIMAL,             //  VkImageTiling           tiling;
76                 usageFlags,                          //  VkImageUsageFlags       usage;
77                 VK_SHARING_MODE_EXCLUSIVE,           //  VkSharingMode           sharingMode;
78                 0u,                                  //  uint32_t                queueFamilyIndexCount;
79                 DE_NULL,                             //  const uint32_t*         pQueueFamilyIndices;
80                 VK_IMAGE_LAYOUT_UNDEFINED,           //  VkImageLayout           initialLayout;
81             };
82 
83             std::vector<VkImageCreateInfo> imageRequirements;
84             imageRequirements.push_back(imageParams);
85 
86             std::vector<cts_amber::BufferRequirement> bufferRequirements;
87             bufferRequirements.push_back({cases[i].format, VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT});
88 
89             cts_amber::AmberTestCase *testCase =
90                 cts_amber::createAmberTestCase(testCtx, cases[i].testName.c_str(), dataDir, fileName,
91                                                std::vector<std::string>(), imageRequirements, bufferRequirements);
92             srgb->addChild(testCase);
93         }
94     }
95 
96     // .packed
97 #ifndef CTS_USES_VULKANSC
98     {
99         // Test uniform texel buffer with packed formats
100         tcu::TestCaseGroup *const packed = new tcu::TestCaseGroup(testCtx, "packed");
101         static const char dataDir[]      = "texture/texel_buffer/uniform/packed";
102 
103         static const std::string cases[] = {
104             "a2b10g10r10-uint-pack32", "a2b10g10r10-unorm-pack32", "a8b8g8r8-sint-pack32",   "a8b8g8r8-snorm-pack32",
105             "a8b8g8r8-uint-pack32",    "a8b8g8r8-unorm-pack32",    "b10g11r11-ufloat-pack32"};
106 
107         uniform->addChild(packed);
108 
109         for (int i = 0; i < DE_LENGTH_OF_ARRAY(cases); ++i)
110         {
111             const std::string fileName = cases[i] + ".amber";
112             cts_amber::AmberTestCase *testCase =
113                 cts_amber::createAmberTestCase(testCtx, cases[i].c_str(), dataDir, fileName);
114 
115             packed->addChild(testCase);
116         }
117     }
118 #endif
119 
120     // .snorm
121 #ifndef CTS_USES_VULKANSC
122     {
123         // Test uniform texel buffer with SNORM formats
124         tcu::TestCaseGroup *const snorm = new tcu::TestCaseGroup(testCtx, "snorm");
125         static const char dataDir[]     = "texture/texel_buffer/uniform/snorm";
126 
127         static const struct
128         {
129             std::string testName;
130             bool mandatoryFormat;
131             VkFormat format;
132         } cases[] = {{"b8g8r8-snorm", false, VK_FORMAT_B8G8R8_SNORM},
133                      {"b8g8r8a8-snorm", false, VK_FORMAT_B8G8R8A8_SINT},
134                      {"r16-snorm", false, VK_FORMAT_R16_SNORM},
135                      {"r16g16-snorm", false, VK_FORMAT_R16G16_SNORM},
136                      {"r16g16b16-snorm", false, VK_FORMAT_R16G16B16_SNORM},
137                      {"r16g16b16a16-snorm", false, VK_FORMAT_R16G16B16A16_SNORM},
138                      {"r8-snorm", true, VK_FORMAT_R8_SNORM},
139                      {"r8g8-snorm", true, VK_FORMAT_R8G8_SNORM},
140                      {"r8g8b8-snorm", false, VK_FORMAT_R8G8B8_SNORM},
141                      {"r8g8b8a8-snorm", false, VK_FORMAT_R8G8B8A8_SNORM}};
142 
143         uniform->addChild(snorm);
144 
145         for (const auto &c : cases)
146         {
147             const std::string fileName = c.testName + ".amber";
148             std::vector<cts_amber::BufferRequirement> bufferRequirements;
149 
150             if (!c.mandatoryFormat)
151                 bufferRequirements.push_back({c.format, VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT});
152 
153             cts_amber::AmberTestCase *testCase = cts_amber::createAmberTestCase(
154                 testCtx, c.testName.c_str(), dataDir, fileName, std::vector<std::string>(),
155                 std::vector<vk::VkImageCreateInfo>(), bufferRequirements);
156 
157             snorm->addChild(testCase);
158         }
159     }
160 #endif
161 
162     return uniform.release();
163 }
164 
165 } // namespace
166 
createTextureTexelBufferTests(tcu::TestContext & testCtx)167 tcu::TestCaseGroup *createTextureTexelBufferTests(tcu::TestContext &testCtx)
168 {
169     de::MovePtr<tcu::TestCaseGroup> texelBuffer(new tcu::TestCaseGroup(testCtx, "texel_buffer"));
170 
171     texelBuffer->addChild(createUniformTexelBufferTests(testCtx));
172 
173     return texelBuffer.release();
174 }
175 
176 } // namespace texture
177 } // namespace vkt
178