Update Android CTS mustpass am: df293b49cd am: 41db7dc40e am: af4a755613 am: e298b3119f
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / sparse_resources / vktSparseResourcesShaderIntrinsics.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*
20  * \file  vktSparseResourcesShaderIntrinsics.cpp
21  * \brief Sparse Resources Shader Intrinsics
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktSparseResourcesShaderIntrinsicsSampled.hpp"
25 #include "vktSparseResourcesShaderIntrinsicsStorage.hpp"
26
27 using namespace vk;
28
29 namespace vkt
30 {
31 namespace sparse
32 {
33
34 tcu::TestCaseGroup* createSparseResourcesShaderIntrinsicsTests (tcu::TestContext& testCtx)
35 {
36         de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "shader_intrinsics", "Sparse Resources Shader Intrinsics"));
37
38         static const deUint32 sizeCountPerImageType = 4u;
39
40         struct ImageParameters
41         {
42                 ImageType       imageType;
43                 tcu::UVec3      imageSizes[sizeCountPerImageType];
44         };
45
46         static const ImageParameters imageParametersArray[] =
47         {
48                 { IMAGE_TYPE_2D,                { tcu::UVec3(512u, 256u, 1u),   tcu::UVec3(128u, 128u, 1u), tcu::UVec3(503u, 137u, 1u), tcu::UVec3(11u, 37u, 1u) } },
49                 { IMAGE_TYPE_2D_ARRAY,  { tcu::UVec3(512u, 256u, 6u),   tcu::UVec3(128u, 128u, 8u),     tcu::UVec3(503u, 137u, 3u),     tcu::UVec3(11u, 37u, 3u) } },
50                 { IMAGE_TYPE_CUBE,              { tcu::UVec3(256u, 256u, 1u),   tcu::UVec3(128u, 128u, 1u),     tcu::UVec3(137u, 137u, 1u),     tcu::UVec3(11u, 11u, 1u) } },
51                 { IMAGE_TYPE_CUBE_ARRAY,{ tcu::UVec3(256u, 256u, 6u),   tcu::UVec3(128u, 128u, 8u),     tcu::UVec3(137u, 137u, 3u),     tcu::UVec3(11u, 11u, 3u) } },
52                 { IMAGE_TYPE_3D,                { tcu::UVec3(256u, 256u, 16u),  tcu::UVec3(128u, 128u, 8u),     tcu::UVec3(503u, 137u, 3u),     tcu::UVec3(11u, 37u, 3u) } }
53         };
54
55         static const tcu::TextureFormat formats[] =
56         {
57                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT32),
58                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT16),
59                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT8),
60                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32),
61                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT16),
62                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT8)
63         };
64
65         static const std::string functions[SPARSE_SPIRV_FUNCTION_TYPE_LAST] =
66         {
67                 "_sparse_fetch",
68                 "_sparse_read",
69                 "_sparse_sample_explicit_lod",
70                 "_sparse_sample_implicit_lod",
71                 "_sparse_gather",
72         };
73
74         for (deUint32 functionNdx = 0; functionNdx < SPARSE_SPIRV_FUNCTION_TYPE_LAST; ++functionNdx)
75         {
76                 const SpirVFunction function = static_cast<SpirVFunction>(functionNdx);
77
78                 for (deInt32 imageTypeNdx = 0; imageTypeNdx < DE_LENGTH_OF_ARRAY(imageParametersArray); ++imageTypeNdx)
79                 {
80                         const ImageType                                 imageType = imageParametersArray[imageTypeNdx].imageType;
81                         de::MovePtr<tcu::TestCaseGroup> imageTypeGroup(new tcu::TestCaseGroup(testCtx, (getImageTypeName(imageType) + functions[functionNdx]).c_str(), ""));
82
83                         for (deInt32 formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); ++formatNdx)
84                         {
85                                 const tcu::TextureFormat&               format = formats[formatNdx];
86                                 de::MovePtr<tcu::TestCaseGroup> formatGroup(new tcu::TestCaseGroup(testCtx, getShaderImageFormatQualifier(format).c_str(), ""));
87
88                                 for (deInt32 imageSizeNdx = 0; imageSizeNdx < DE_LENGTH_OF_ARRAY(imageParametersArray[imageTypeNdx].imageSizes); ++imageSizeNdx)
89                                 {
90                                         const tcu::UVec3 imageSize = imageParametersArray[imageTypeNdx].imageSizes[imageSizeNdx];
91
92                                         std::ostringstream stream;
93                                         stream << imageSize.x() << "_" << imageSize.y() << "_" << imageSize.z();
94
95                                         switch (function)
96                                         {
97                                         case SPARSE_FETCH:
98                                                 if ((imageType == IMAGE_TYPE_CUBE) || (imageType == IMAGE_TYPE_CUBE_ARRAY)) continue;
99                                         case SPARSE_SAMPLE_EXPLICIT_LOD:
100                                         case SPARSE_SAMPLE_IMPLICIT_LOD:
101                                         case SPARSE_GATHER:
102                                                 if ((imageType == IMAGE_TYPE_CUBE) || (imageType == IMAGE_TYPE_CUBE_ARRAY) || (imageType == IMAGE_TYPE_3D)) continue;
103                                                 break;
104                                         default:
105                                                 break;
106                                         }
107
108                                         switch (function)
109                                         {
110                                         case SPARSE_FETCH:
111                                                 formatGroup->addChild(new SparseCaseOpImageSparseFetch(testCtx, stream.str(), function, imageType, imageSize, format));
112                                                 break;
113                                         case SPARSE_READ:
114                                                 formatGroup->addChild(new SparseCaseOpImageSparseRead(testCtx, stream.str(), function, imageType, imageSize, format));
115                                                 break;
116                                         case SPARSE_SAMPLE_EXPLICIT_LOD:
117                                                 formatGroup->addChild(new SparseCaseOpImageSparseSampleExplicitLod(testCtx, stream.str(), function, imageType, imageSize, format));
118                                                 break;
119                                         case SPARSE_SAMPLE_IMPLICIT_LOD:
120                                                 formatGroup->addChild(new SparseCaseOpImageSparseSampleImplicitLod(testCtx, stream.str(), function, imageType, imageSize, format));
121                                                 break;
122                                         case SPARSE_GATHER:
123                                                 formatGroup->addChild(new SparseCaseOpImageSparseGather(testCtx, stream.str(), function, imageType, imageSize, format));
124                                                 break;
125                                         default:
126                                                 DE_ASSERT(0);
127                                                 break;
128                                         }
129                                 }
130                                 imageTypeGroup->addChild(formatGroup.release());
131                         }
132                         testGroup->addChild(imageTypeGroup.release());
133                 }
134         }
135
136         return testGroup.release();
137 }
138
139 } // sparse
140 } // vkt