1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Simple Draw Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktDrawSimpleTest.hpp"
38 #include "vktTestCaseUtil.hpp"
39 #include "vktDrawTestCaseUtil.hpp"
41 #include "vktDrawBaseClass.hpp"
43 #include "tcuTestLog.hpp"
44 #include "tcuResource.hpp"
45 #include "tcuImageCompare.hpp"
46 #include "tcuTextureUtil.hpp"
47 #include "tcuRGBA.hpp"
57 class SimpleDraw : public DrawTestsBaseClass
60 SimpleDraw (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
61 virtual tcu::TestStatus iterate (void);
64 class SimpleDrawInstanced : public SimpleDraw
67 SimpleDrawInstanced (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
68 tcu::TestStatus iterate (void);
71 SimpleDraw::SimpleDraw (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
72 : DrawTestsBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
74 m_topology = topology;
78 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
79 m_data.push_back(PositionColorVertex(tcu::Vec4( 1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
80 m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
81 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
82 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
83 m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
84 m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
85 m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
86 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
87 m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
89 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
90 m_data.push_back(PositionColorVertex(tcu::Vec4( 1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
91 m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
92 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
93 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
94 m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
95 m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
96 m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
97 m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
99 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
100 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
101 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
102 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
103 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
104 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
105 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
106 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
107 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
108 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
109 DE_FATAL("Topology not implemented");
112 DE_FATAL("Unknown topology");
118 tcu::TestStatus SimpleDraw::iterate (void)
120 tcu::TestLog &log = m_context.getTestContext().getLog();
121 const vk::VkQueue queue = m_context.getUniversalQueue();
125 const vk::VkDeviceSize vertexBufferOffset = 0;
126 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
128 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
129 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
133 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
134 m_vk.cmdDraw(*m_cmdBuffer, 6, 1, 2, 0);
136 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
137 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 2, 0);
139 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
140 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
141 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
142 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
143 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
144 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
145 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
146 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
147 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
148 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
149 DE_FATAL("Topology not implemented");
152 DE_FATAL("Unknown topology");
156 m_vk.cmdEndRenderPass(*m_cmdBuffer);
157 m_vk.endCommandBuffer(*m_cmdBuffer);
159 vk::VkSubmitInfo submitInfo =
161 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
162 DE_NULL, // const void* pNext;
163 0, // deUint32 waitSemaphoreCount;
164 DE_NULL, // const VkSemaphore* pWaitSemaphores;
165 1, // deUint32 commandBufferCount;
166 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
167 0, // deUint32 signalSemaphoreCount;
168 DE_NULL // const VkSemaphore* pSignalSemaphores;
170 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
172 VK_CHECK(m_vk.queueWaitIdle(queue));
175 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
177 referenceFrame.allocLevel(0);
179 const deInt32 frameWidth = referenceFrame.getWidth();
180 const deInt32 frameHeight = referenceFrame.getHeight();
182 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
184 ReferenceImageCoordinates refCoords;
186 for (int y = 0; y < frameHeight; y++)
188 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
190 for (int x = 0; x < frameWidth; x++)
192 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
194 if ((yCoord >= refCoords.bottom &&
195 yCoord <= refCoords.top &&
196 xCoord >= refCoords.left &&
197 xCoord <= refCoords.right))
198 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
202 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
203 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
204 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
206 qpTestResult res = QP_TEST_RESULT_PASS;
208 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
209 referenceFrame.getLevel(0), renderedFrame, 0.05f,
210 tcu::COMPARE_LOG_RESULT)) {
211 res = QP_TEST_RESULT_FAIL;
214 return tcu::TestStatus(res, qpGetTestResultName(res));
218 SimpleDrawInstanced::SimpleDrawInstanced (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
219 : SimpleDraw (context, shaders, topology) {}
221 tcu::TestStatus SimpleDrawInstanced::iterate (void)
223 tcu::TestLog &log = m_context.getTestContext().getLog();
225 const vk::VkQueue queue = m_context.getUniversalQueue();
229 const vk::VkDeviceSize vertexBufferOffset = 0;
230 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
232 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
234 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
238 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
239 m_vk.cmdDraw(*m_cmdBuffer, 6, 4, 2, 2);
241 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
242 m_vk.cmdDraw(*m_cmdBuffer, 4, 4, 2, 2);
244 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
245 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
246 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
247 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
248 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
249 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
250 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
251 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
252 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
253 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
254 DE_FATAL("Topology not implemented");
257 DE_FATAL("Unknown topology");
261 m_vk.cmdEndRenderPass(*m_cmdBuffer);
262 m_vk.endCommandBuffer(*m_cmdBuffer);
264 vk::VkSubmitInfo submitInfo =
266 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
267 DE_NULL, // const void* pNext;
268 0, // deUint32 waitSemaphoreCount;
269 DE_NULL, // const VkSemaphore* pWaitSemaphores;
270 1, // deUint32 commandBufferCount;
271 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
272 0, // deUint32 signalSemaphoreCount;
273 DE_NULL // const VkSemaphore* pSignalSemaphores;
275 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
277 VK_CHECK(m_vk.queueWaitIdle(queue));
280 VK_CHECK(m_vk.queueWaitIdle(queue));
282 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
284 referenceFrame.allocLevel(0);
286 const deInt32 frameWidth = referenceFrame.getWidth();
287 const deInt32 frameHeight = referenceFrame.getHeight();
289 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
291 ReferenceImageInstancedCoordinates refInstancedCoords;
293 for (int y = 0; y < frameHeight; y++)
295 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
297 for (int x = 0; x < frameWidth; x++)
299 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
301 if ((yCoord >= refInstancedCoords.bottom &&
302 yCoord <= refInstancedCoords.top &&
303 xCoord >= refInstancedCoords.left &&
304 xCoord <= refInstancedCoords.right))
305 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
309 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
310 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
311 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
313 qpTestResult res = QP_TEST_RESULT_PASS;
315 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
316 referenceFrame.getLevel(0), renderedFrame, 0.05f,
317 tcu::COMPARE_LOG_RESULT)) {
318 res = QP_TEST_RESULT_FAIL;
321 return tcu::TestStatus(res, qpGetTestResultName(res));
326 SimpleDrawTests::SimpleDrawTests (tcu::TestContext &testCtx)
327 : TestCaseGroup (testCtx, "simple_draw", "drawing simple geometry")
329 /* Left blank on purpose */
332 SimpleDrawTests::~SimpleDrawTests (void) {}
335 void SimpleDrawTests::init (void)
337 ShaderMap shaderPaths;
338 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetch.vert";
339 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
341 addChild(new InstanceFactory<SimpleDraw>(m_testCtx, "simple_draw_triangle_list", "Draws triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
342 addChild(new InstanceFactory<SimpleDraw>(m_testCtx, "simple_draw_triangle_strip", "Draws triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));
344 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetchWithInstance.vert";
345 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
347 addChild(new InstanceFactory<SimpleDrawInstanced>(m_testCtx, "simple_draw_instanced_triangle_list", "Draws an instanced triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
348 addChild(new InstanceFactory<SimpleDrawInstanced>(m_testCtx, "simple_draw_instanced_triangle_strip", "Draws an instanced triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));