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 Draw Indexed Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktDrawIndexedTest.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 DrawIndexed : public DrawTestsBaseClass
60 DrawIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
61 virtual tcu::TestStatus iterate (void);
64 class DrawInstancedIndexed : public DrawIndexed
67 DrawInstancedIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
68 virtual tcu::TestStatus iterate (void);
71 DrawIndexed::DrawIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
72 : DrawTestsBaseClass(context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
74 m_topology = topology;
76 /*0*/ m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
77 /*1*/ m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
78 /*2*/ m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
79 /*3*/ m_data.push_back(PositionColorVertex(tcu::Vec4( 1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
80 /*4*/ m_data.push_back(PositionColorVertex(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
81 /*5*/ m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
82 /*6*/ m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
83 /*7*/ m_data.push_back(PositionColorVertex(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
84 /*8*/ m_data.push_back(PositionColorVertex(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
88 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
89 m_indexes.push_back(0);
90 m_indexes.push_back(0);
91 m_indexes.push_back(2);
92 m_indexes.push_back(0);
93 m_indexes.push_back(6);
94 m_indexes.push_back(6);
95 m_indexes.push_back(0);
96 m_indexes.push_back(7);
98 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
99 m_indexes.push_back(0);
100 m_indexes.push_back(0);
101 m_indexes.push_back(2);
102 m_indexes.push_back(0);
103 m_indexes.push_back(6);
104 m_indexes.push_back(5);
105 m_indexes.push_back(0);
106 m_indexes.push_back(7);
109 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
110 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
111 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
112 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
113 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
114 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
115 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
116 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
117 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
118 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
119 DE_FATAL("Topology not implemented");
122 DE_FATAL("Unknown topology");
128 tcu::TestStatus DrawIndexed::iterate (void)
130 tcu::TestLog &log = m_context.getTestContext().getLog();
131 const vk::VkQueue queue = m_context.getUniversalQueue();
135 const vk::VkDeviceSize dataSize = m_indexes.size() * sizeof(deUint32);
136 m_indexBuffer = Buffer::createAndAlloc( m_vk, m_context.getDevice(),
137 BufferCreateInfo(dataSize,
138 vk::VK_BUFFER_USAGE_INDEX_BUFFER_BIT),
139 m_context.getDefaultAllocator(),
140 vk::MemoryRequirement::HostVisible);
142 deUint8* ptr = reinterpret_cast<deUint8*>(m_indexBuffer->getBoundMemory().getHostPtr());
144 deMemcpy(ptr, &m_indexes[0], static_cast<size_t>(dataSize));
146 vk::flushMappedMemoryRange(m_vk, m_context.getDevice(),
147 m_vertexBuffer->getBoundMemory().getMemory(),
148 m_vertexBuffer->getBoundMemory().getOffset(),
151 const vk::VkDeviceSize vertexBufferOffset = 0;
152 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
153 const vk::VkBuffer indexBuffer = m_indexBuffer->object();
155 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
156 m_vk.cmdBindIndexBuffer(*m_cmdBuffer, indexBuffer, 0, vk::VK_INDEX_TYPE_UINT32);
158 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
160 m_vk.cmdDrawIndexed(*m_cmdBuffer, 6, 1, 2, 0, 0);
162 m_vk.cmdEndRenderPass(*m_cmdBuffer);
163 m_vk.endCommandBuffer(*m_cmdBuffer);
165 vk::VkSubmitInfo submitInfo =
167 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
168 DE_NULL, // const void* pNext;
169 0, // deUint32 waitSemaphoreCount;
170 DE_NULL, // const VkSemaphore* pWaitSemaphores;
171 (const vk::VkPipelineStageFlags*)DE_NULL,
172 1, // deUint32 commandBufferCount;
173 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
174 0, // deUint32 signalSemaphoreCount;
175 DE_NULL // const VkSemaphore* pSignalSemaphores;
178 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
180 VK_CHECK(m_vk.queueWaitIdle(queue));
183 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
184 referenceFrame.allocLevel(0);
186 const deInt32 frameWidth = referenceFrame.getWidth();
187 const deInt32 frameHeight = referenceFrame.getHeight();
189 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
191 ReferenceImageCoordinates refCoords;
193 for (int y = 0; y < frameHeight; y++)
195 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
197 for (int x = 0; x < frameWidth; x++)
199 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
201 if ((yCoord >= refCoords.bottom &&
202 yCoord <= refCoords.top &&
203 xCoord >= refCoords.left &&
204 xCoord <= refCoords.right))
205 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
209 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
210 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
211 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
213 qpTestResult res = QP_TEST_RESULT_PASS;
215 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
216 referenceFrame.getLevel(0), renderedFrame, 0.05f,
217 tcu::COMPARE_LOG_RESULT)) {
218 res = QP_TEST_RESULT_FAIL;
221 return tcu::TestStatus(res, qpGetTestResultName(res));
224 DrawInstancedIndexed::DrawInstancedIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
225 : DrawIndexed (context, shaders, topology)
229 tcu::TestStatus DrawInstancedIndexed::iterate (void)
231 tcu::TestLog &log = m_context.getTestContext().getLog();
232 const vk::VkQueue queue = m_context.getUniversalQueue();
236 const vk::VkDeviceSize dataSize = m_indexes.size() * sizeof(deUint32);
237 m_indexBuffer = Buffer::createAndAlloc( m_vk, m_context.getDevice(),
238 BufferCreateInfo(dataSize,
239 vk::VK_BUFFER_USAGE_INDEX_BUFFER_BIT),
240 m_context.getDefaultAllocator(),
241 vk::MemoryRequirement::HostVisible);
243 deUint8* ptr = reinterpret_cast<deUint8*>(m_indexBuffer->getBoundMemory().getHostPtr());
245 deMemcpy(ptr, &m_indexes[0], static_cast<size_t>(dataSize));
246 vk::flushMappedMemoryRange(m_vk, m_context.getDevice(),
247 m_vertexBuffer->getBoundMemory().getMemory(),
248 m_vertexBuffer->getBoundMemory().getOffset(),
251 const vk::VkDeviceSize vertexBufferOffset = 0;
252 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
253 const vk::VkBuffer indexBuffer = m_indexBuffer->object();
255 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
256 m_vk.cmdBindIndexBuffer(*m_cmdBuffer, indexBuffer, 0, vk::VK_INDEX_TYPE_UINT32);
257 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
261 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
262 m_vk.cmdDrawIndexed(*m_cmdBuffer, 6, 4, 2, 0, 2);
264 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
265 m_vk.cmdDrawIndexed(*m_cmdBuffer, 4, 4, 2, 0, 2);
267 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
268 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
269 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
270 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
271 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
272 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
273 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
274 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
275 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
276 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
277 DE_FATAL("Topology not implemented");
280 DE_FATAL("Unknown topology");
284 m_vk.cmdEndRenderPass(*m_cmdBuffer);
285 m_vk.endCommandBuffer(*m_cmdBuffer);
287 vk::VkSubmitInfo submitInfo =
289 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
290 DE_NULL, // const void* pNext;
291 0, // deUint32 waitSemaphoreCount;
292 DE_NULL, // const VkSemaphore* pWaitSemaphores;
293 (const vk::VkPipelineStageFlags*)DE_NULL,
294 1, // deUint32 commandBufferCount;
295 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
296 0, // deUint32 signalSemaphoreCount;
297 DE_NULL // const VkSemaphore* pSignalSemaphores;
299 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
301 VK_CHECK(m_vk.queueWaitIdle(queue));
304 VK_CHECK(m_vk.queueWaitIdle(queue));
306 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
307 referenceFrame.allocLevel(0);
309 const deInt32 frameWidth = referenceFrame.getWidth();
310 const deInt32 frameHeight = referenceFrame.getHeight();
312 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
314 ReferenceImageInstancedCoordinates refInstancedCoords;
316 for (int y = 0; y < frameHeight; y++)
318 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
320 for (int x = 0; x < frameWidth; x++)
322 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
324 if ((yCoord >= refInstancedCoords.bottom &&
325 yCoord <= refInstancedCoords.top &&
326 xCoord >= refInstancedCoords.left &&
327 xCoord <= refInstancedCoords.right))
328 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
332 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
333 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
334 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
336 qpTestResult res = QP_TEST_RESULT_PASS;
338 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
339 referenceFrame.getLevel(0), renderedFrame, 0.05f,
340 tcu::COMPARE_LOG_RESULT)) {
341 res = QP_TEST_RESULT_FAIL;
344 return tcu::TestStatus(res, qpGetTestResultName(res));
350 DrawIndexedTests::DrawIndexedTests (tcu::TestContext &testCtx)
351 : TestCaseGroup (testCtx, "indexed_draw", "drawing indexed geometry")
353 /* Left blank on purpose */
356 DrawIndexedTests::~DrawIndexedTests (void) {}
358 void DrawIndexedTests::init (void)
360 ShaderMap shaderPaths;
361 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetch.vert";
362 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
364 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_indexed_triangle_list", "Draws indexed triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
365 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_indexed_triangle_strip", "Draws indexed triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));
367 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetchWithInstance.vert";
368 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
370 addChild(new InstanceFactory<DrawInstancedIndexed>(m_testCtx, "draw_instanced_indexed_triangle_list", "Draws indexed triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
371 addChild(new InstanceFactory<DrawInstancedIndexed>(m_testCtx, "draw_instanced_indexed_triangle_strip", "Draws indexed triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));