1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
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 Simple Draw Tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktDrawSimpleTest.hpp"
26
27 #include "vktTestCaseUtil.hpp"
28 #include "vktDrawTestCaseUtil.hpp"
29
30 #include "vktDrawBaseClass.hpp"
31
32 #include "tcuTestLog.hpp"
33 #include "tcuResource.hpp"
34 #include "tcuImageCompare.hpp"
35 #include "tcuTextureUtil.hpp"
36 #include "tcuRGBA.hpp"
37
38 #include "vkDefs.hpp"
39 #include "vkCmdUtil.hpp"
40
41 namespace vkt
42 {
43 namespace Draw
44 {
45 namespace
46 {
47 class SimpleDraw : public DrawTestsBaseClass
48 {
49 public:
50 typedef TestSpecBase TestSpec;
51 SimpleDraw (Context &context, TestSpec testSpec);
52 virtual tcu::TestStatus iterate (void);
53 };
54
55 class SimpleDrawInstanced : public SimpleDraw
56 {
57 public:
58 typedef TestSpec TestSpec;
59 SimpleDrawInstanced (Context &context, TestSpec testSpec);
60 tcu::TestStatus iterate (void);
61 };
62
SimpleDraw(Context & context,TestSpec testSpec)63 SimpleDraw::SimpleDraw (Context &context, TestSpec testSpec)
64 : DrawTestsBaseClass(context, testSpec.shaders[glu::SHADERTYPE_VERTEX], testSpec.shaders[glu::SHADERTYPE_FRAGMENT], testSpec.useDynamicRendering, testSpec.topology)
65 {
66 m_data.push_back(VertexElementData(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), -1));
67 m_data.push_back(VertexElementData(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), -1));
68
69 int refVertexIndex = 2;
70
71 switch (m_topology)
72 {
73 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
74 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
75 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
76 m_data.push_back(VertexElementData(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
77 m_data.push_back(VertexElementData(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
78 m_data.push_back(VertexElementData(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
79 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
80 break;
81 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
82 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
83 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
84 m_data.push_back(VertexElementData(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
85 m_data.push_back(VertexElementData(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
86 m_data.push_back(VertexElementData(tcu::Vec4(-0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), refVertexIndex++));
87 break;
88 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
89 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
90 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
91 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
92 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
93 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
94 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
95 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
96 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
97 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
98 DE_FATAL("Topology not implemented");
99 break;
100 default:
101 DE_FATAL("Unknown topology");
102 break;
103 }
104
105 m_data.push_back(VertexElementData(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec(), -1));
106
107 initialize();
108 }
109
iterate(void)110 tcu::TestStatus SimpleDraw::iterate (void)
111 {
112 tcu::TestLog& log = m_context.getTestContext().getLog();
113 const vk::VkQueue queue = m_context.getUniversalQueue();
114 const vk::VkDevice device = m_context.getDevice();
115
116 beginRender();
117
118 const vk::VkDeviceSize vertexBufferOffset = 0;
119 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
120
121 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
122 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
123
124 switch (m_topology)
125 {
126 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
127 m_vk.cmdDraw(*m_cmdBuffer, 6, 1, 2, 0);
128 break;
129 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
130 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 2, 0);
131 break;
132 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
133 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
134 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
135 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
136 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
137 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
138 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
139 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
140 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
141 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
142 DE_FATAL("Topology not implemented");
143 break;
144 default:
145 DE_FATAL("Unknown topology");
146 break;
147 }
148
149 endRender();
150 endCommandBuffer(m_vk, *m_cmdBuffer);
151
152 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
153
154 // Validation
155 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5f + static_cast<float>(WIDTH)), (int)(0.5f + static_cast<float>(HEIGHT)));
156
157 referenceFrame.allocLevel(0);
158
159 const deInt32 frameWidth = referenceFrame.getWidth();
160 const deInt32 frameHeight = referenceFrame.getHeight();
161
162 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
163
164 ReferenceImageCoordinates refCoords;
165
166 for (int y = 0; y < frameHeight; y++)
167 {
168 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
169
170 for (int x = 0; x < frameWidth; x++)
171 {
172 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
173
174 if ((yCoord >= refCoords.bottom &&
175 yCoord <= refCoords.top &&
176 xCoord >= refCoords.left &&
177 xCoord <= refCoords.right))
178 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
179 }
180 }
181
182 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
183 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
184 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
185
186 qpTestResult res = QP_TEST_RESULT_PASS;
187
188 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
189 referenceFrame.getLevel(0), renderedFrame, 0.05f,
190 tcu::COMPARE_LOG_RESULT)) {
191 res = QP_TEST_RESULT_FAIL;
192 }
193
194 return tcu::TestStatus(res, qpGetTestResultName(res));
195
196 }
197
SimpleDrawInstanced(Context & context,TestSpec testSpec)198 SimpleDrawInstanced::SimpleDrawInstanced (Context &context, TestSpec testSpec)
199 : SimpleDraw (context, testSpec) {}
200
iterate(void)201 tcu::TestStatus SimpleDrawInstanced::iterate (void)
202 {
203 tcu::TestLog& log = m_context.getTestContext().getLog();
204 const vk::VkQueue queue = m_context.getUniversalQueue();
205 const vk::VkDevice device = m_context.getDevice();
206
207 beginRender();
208
209 const vk::VkDeviceSize vertexBufferOffset = 0;
210 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
211
212 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
213
214 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
215
216 switch (m_topology)
217 {
218 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
219 m_vk.cmdDraw(*m_cmdBuffer, 6, 4, 2, 2);
220 break;
221 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
222 m_vk.cmdDraw(*m_cmdBuffer, 4, 4, 2, 2);
223 break;
224 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
225 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
226 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
227 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
228 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
229 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
230 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
231 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
232 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
233 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
234 DE_FATAL("Topology not implemented");
235 break;
236 default:
237 DE_FATAL("Unknown topology");
238 break;
239 }
240
241 endRender();
242 endCommandBuffer(m_vk, *m_cmdBuffer);
243
244 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
245
246 // Validation
247 VK_CHECK(m_vk.queueWaitIdle(queue));
248
249 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5f + static_cast<float>(WIDTH)), (int)(0.5f + static_cast<float>(HEIGHT)));
250
251 referenceFrame.allocLevel(0);
252
253 const deInt32 frameWidth = referenceFrame.getWidth();
254 const deInt32 frameHeight = referenceFrame.getHeight();
255
256 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
257
258 ReferenceImageInstancedCoordinates refInstancedCoords;
259
260 for (int y = 0; y < frameHeight; y++)
261 {
262 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
263
264 for (int x = 0; x < frameWidth; x++)
265 {
266 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
267
268 if ((yCoord >= refInstancedCoords.bottom &&
269 yCoord <= refInstancedCoords.top &&
270 xCoord >= refInstancedCoords.left &&
271 xCoord <= refInstancedCoords.right))
272 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
273 }
274 }
275
276 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
277 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
278 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
279
280 qpTestResult res = QP_TEST_RESULT_PASS;
281
282 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
283 referenceFrame.getLevel(0), renderedFrame, 0.05f,
284 tcu::COMPARE_LOG_RESULT)) {
285 res = QP_TEST_RESULT_FAIL;
286 }
287
288 return tcu::TestStatus(res, qpGetTestResultName(res));
289 }
290
checkSupport(Context & context,SimpleDraw::TestSpec testSpec)291 void checkSupport(Context& context, SimpleDraw::TestSpec testSpec)
292 {
293 if (testSpec.useDynamicRendering)
294 context.requireDeviceFunctionality("VK_KHR_dynamic_rendering");
295 }
296
297 } // anonymous
298
SimpleDrawTests(tcu::TestContext & testCtx,bool useDynamicRendering)299 SimpleDrawTests::SimpleDrawTests (tcu::TestContext &testCtx, bool useDynamicRendering)
300 : TestCaseGroup (testCtx, "simple_draw", "drawing simple geometry")
301 , m_useDynamicRendering (useDynamicRendering)
302 {
303 /* Left blank on purpose */
304 }
305
~SimpleDrawTests(void)306 SimpleDrawTests::~SimpleDrawTests (void) {}
307
init(void)308 void SimpleDrawTests::init (void)
309 {
310 {
311 SimpleDraw::TestSpec testSpec;
312 testSpec.shaders[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetch.vert";
313 testSpec.shaders[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
314 testSpec.useDynamicRendering = m_useDynamicRendering;
315
316 testSpec.topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
317 addChild(new InstanceFactory<SimpleDraw, FunctionSupport1<SimpleDraw::TestSpec> >
318 (m_testCtx, "simple_draw_triangle_list", "Draws triangle list", testSpec, FunctionSupport1<SimpleDraw::TestSpec>::Args(checkSupport, testSpec)));
319 testSpec.topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
320 addChild(new InstanceFactory<SimpleDraw, FunctionSupport1<SimpleDraw::TestSpec> >
321 (m_testCtx, "simple_draw_triangle_strip", "Draws triangle strip", testSpec, FunctionSupport1<SimpleDraw::TestSpec>::Args(checkSupport, testSpec)));
322 }
323 {
324 SimpleDrawInstanced::TestSpec testSpec;
325 testSpec.shaders[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetchInstancedFirstInstance.vert";
326 testSpec.shaders[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
327 testSpec.useDynamicRendering = m_useDynamicRendering;
328
329 testSpec.topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
330 addChild(new InstanceFactory<SimpleDrawInstanced, FunctionSupport1<SimpleDrawInstanced::TestSpec> >
331 (m_testCtx, "simple_draw_instanced_triangle_list", "Draws an instanced triangle list", testSpec, FunctionSupport1<SimpleDrawInstanced::TestSpec>::Args(checkSupport, testSpec)));
332 testSpec.topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
333 addChild(new InstanceFactory<SimpleDrawInstanced, FunctionSupport1<SimpleDrawInstanced::TestSpec> >
334 (m_testCtx, "simple_draw_instanced_triangle_strip", "Draws an instanced triangle strip", testSpec, FunctionSupport1<SimpleDrawInstanced::TestSpec>::Args(checkSupport, testSpec)));
335 }
336 }
337
338 } // DrawTests
339 } // vkt
340