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 (const vk::VkPipelineStageFlags*)DE_NULL,
166 1, // deUint32 commandBufferCount;
167 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
168 0, // deUint32 signalSemaphoreCount;
169 DE_NULL // const VkSemaphore* pSignalSemaphores;
171 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
173 VK_CHECK(m_vk.queueWaitIdle(queue));
176 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
178 referenceFrame.allocLevel(0);
180 const deInt32 frameWidth = referenceFrame.getWidth();
181 const deInt32 frameHeight = referenceFrame.getHeight();
183 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
185 ReferenceImageCoordinates refCoords;
187 for (int y = 0; y < frameHeight; y++)
189 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
191 for (int x = 0; x < frameWidth; x++)
193 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
195 if ((yCoord >= refCoords.bottom &&
196 yCoord <= refCoords.top &&
197 xCoord >= refCoords.left &&
198 xCoord <= refCoords.right))
199 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
203 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
204 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
205 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
207 qpTestResult res = QP_TEST_RESULT_PASS;
209 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
210 referenceFrame.getLevel(0), renderedFrame, 0.05f,
211 tcu::COMPARE_LOG_RESULT)) {
212 res = QP_TEST_RESULT_FAIL;
215 return tcu::TestStatus(res, qpGetTestResultName(res));
219 SimpleDrawInstanced::SimpleDrawInstanced (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
220 : SimpleDraw (context, shaders, topology) {}
222 tcu::TestStatus SimpleDrawInstanced::iterate (void)
224 tcu::TestLog &log = m_context.getTestContext().getLog();
226 const vk::VkQueue queue = m_context.getUniversalQueue();
230 const vk::VkDeviceSize vertexBufferOffset = 0;
231 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
233 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
235 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
239 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
240 m_vk.cmdDraw(*m_cmdBuffer, 6, 4, 2, 2);
242 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
243 m_vk.cmdDraw(*m_cmdBuffer, 4, 4, 2, 2);
245 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
246 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
247 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
248 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
249 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
250 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
251 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
252 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
253 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
254 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
255 DE_FATAL("Topology not implemented");
258 DE_FATAL("Unknown topology");
262 m_vk.cmdEndRenderPass(*m_cmdBuffer);
263 m_vk.endCommandBuffer(*m_cmdBuffer);
265 vk::VkSubmitInfo submitInfo =
267 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
268 DE_NULL, // const void* pNext;
269 0, // deUint32 waitSemaphoreCount;
270 DE_NULL, // const VkSemaphore* pWaitSemaphores;
271 (const vk::VkPipelineStageFlags*)DE_NULL,
272 1, // deUint32 commandBufferCount;
273 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
274 0, // deUint32 signalSemaphoreCount;
275 DE_NULL // const VkSemaphore* pSignalSemaphores;
277 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
279 VK_CHECK(m_vk.queueWaitIdle(queue));
282 VK_CHECK(m_vk.queueWaitIdle(queue));
284 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
286 referenceFrame.allocLevel(0);
288 const deInt32 frameWidth = referenceFrame.getWidth();
289 const deInt32 frameHeight = referenceFrame.getHeight();
291 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
293 ReferenceImageInstancedCoordinates refInstancedCoords;
295 for (int y = 0; y < frameHeight; y++)
297 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
299 for (int x = 0; x < frameWidth; x++)
301 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
303 if ((yCoord >= refInstancedCoords.bottom &&
304 yCoord <= refInstancedCoords.top &&
305 xCoord >= refInstancedCoords.left &&
306 xCoord <= refInstancedCoords.right))
307 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
311 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
312 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
313 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
315 qpTestResult res = QP_TEST_RESULT_PASS;
317 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
318 referenceFrame.getLevel(0), renderedFrame, 0.05f,
319 tcu::COMPARE_LOG_RESULT)) {
320 res = QP_TEST_RESULT_FAIL;
323 return tcu::TestStatus(res, qpGetTestResultName(res));
328 SimpleDrawTests::SimpleDrawTests (tcu::TestContext &testCtx)
329 : TestCaseGroup (testCtx, "simple_draw", "drawing simple geometry")
331 /* Left blank on purpose */
334 SimpleDrawTests::~SimpleDrawTests (void) {}
337 void SimpleDrawTests::init (void)
339 ShaderMap shaderPaths;
340 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetch.vert";
341 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
343 addChild(new InstanceFactory<SimpleDraw>(m_testCtx, "simple_draw_triangle_list", "Draws triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
344 addChild(new InstanceFactory<SimpleDraw>(m_testCtx, "simple_draw_triangle_strip", "Draws triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));
346 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetchWithInstance.vert";
347 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
349 addChild(new InstanceFactory<SimpleDrawInstanced>(m_testCtx, "simple_draw_instanced_triangle_list", "Draws an instanced triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
350 addChild(new InstanceFactory<SimpleDrawInstanced>(m_testCtx, "simple_draw_instanced_triangle_strip", "Draws an instanced triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));