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"
56 class DrawIndexed : public DrawTestsBaseClass
59 DrawIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
60 virtual tcu::TestStatus iterate (void);
63 class DrawInstancedIndexed : public DrawIndexed
66 DrawInstancedIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology);
67 virtual tcu::TestStatus iterate (void);
70 DrawIndexed::DrawIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
71 : DrawTestsBaseClass(context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
73 m_topology = topology;
75 /*0*/ m_data.push_back(Vec4RGBA(tcu::Vec4( -0.3f, 0.3f, 1.0f, 1.0f), vec4Blue()));
76 /*1*/ m_data.push_back(Vec4RGBA(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), vec4Blue()));
77 /*2*/ m_data.push_back(Vec4RGBA(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), vec4Blue()));
78 /*3*/ m_data.push_back(Vec4RGBA(tcu::Vec4( 1.0f, -1.0f, 1.0f, 1.0f), vec4Blue()));
79 /*4*/ m_data.push_back(Vec4RGBA(tcu::Vec4( -0.3f, -0.3f, 1.0f, 1.0f), vec4Blue()));
80 /*5*/ m_data.push_back(Vec4RGBA(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), vec4Blue()));
81 /*6*/ m_data.push_back(Vec4RGBA(tcu::Vec4( 0.3f, -0.3f, 1.0f, 1.0f), vec4Blue()));
82 /*7*/ m_data.push_back(Vec4RGBA(tcu::Vec4( 0.3f, 0.3f, 1.0f, 1.0f), vec4Blue()));
83 /*8*/ m_data.push_back(Vec4RGBA(tcu::Vec4( -1.0f, 1.0f, 1.0f, 1.0f), vec4Blue()));
87 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
88 m_indexes.push_back(0);
89 m_indexes.push_back(0);
90 m_indexes.push_back(2);
91 m_indexes.push_back(0);
92 m_indexes.push_back(6);
93 m_indexes.push_back(6);
94 m_indexes.push_back(0);
95 m_indexes.push_back(7);
97 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
98 m_indexes.push_back(0);
99 m_indexes.push_back(0);
100 m_indexes.push_back(2);
101 m_indexes.push_back(0);
102 m_indexes.push_back(6);
103 m_indexes.push_back(5);
104 m_indexes.push_back(0);
105 m_indexes.push_back(7);
112 DrawTestsBaseClass::initialize();
115 tcu::TestStatus DrawIndexed::iterate (void)
117 tcu::TestLog &log = m_context.getTestContext().getLog();
118 const vk::VkQueue queue = m_context.getUniversalQueue();
122 const vk::VkDeviceSize dataSize = m_indexes.size() * sizeof(deUint32);
123 m_indexBuffer = Buffer::createAndAlloc(m_vk, m_context.getDevice(), BufferCreateInfo(dataSize,
124 vk::VK_BUFFER_USAGE_INDEX_BUFFER_BIT), m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
126 unsigned char *ptr = reinterpret_cast<unsigned char *>(m_indexBuffer->getBoundMemory().getHostPtr());
127 deMemcpy(ptr, &m_indexes[0], dataSize);
129 vk::flushMappedMemoryRange(m_vk, m_context.getDevice(),
130 m_vertexBuffer->getBoundMemory().getMemory(),
131 m_vertexBuffer->getBoundMemory().getOffset(),
134 const vk::VkDeviceSize vertexBufferOffset = 0;
135 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
136 const vk::VkBuffer indexBuffer = m_indexBuffer->object();
137 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
138 m_vk.cmdBindIndexBuffer(*m_cmdBuffer, indexBuffer, 0, vk::VK_INDEX_TYPE_UINT32);
140 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
142 m_vk.cmdDrawIndexed(*m_cmdBuffer, 6, 1, 2, 0, 0);
144 m_vk.cmdEndRenderPass(*m_cmdBuffer);
145 m_vk.endCommandBuffer(*m_cmdBuffer);
147 const vk::VkCommandBuffer cmdBuffer = *m_cmdBuffer;
149 vk::VkSubmitInfo submitInfo =
151 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
152 DE_NULL, // const void* pNext;
153 0, // deUint32 waitSemaphoreCount;
154 DE_NULL, // const VkSemaphore* pWaitSemaphores;
155 1, // deUint32 commandBufferCount;
156 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
157 0, // deUint32 signalSemaphoreCount;
158 DE_NULL // const VkSemaphore* pSignalSemaphores;
161 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
163 VK_CHECK(m_vk.queueWaitIdle(queue));
166 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
167 referenceFrame.allocLevel(0);
169 const deInt32 frameWidth = referenceFrame.getWidth();
170 const deInt32 frameHeight = referenceFrame.getHeight();
172 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
174 for (int y = 0; y < frameHeight; y++)
176 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
178 for (int x = 0; x < frameWidth; x++)
180 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
182 if ((yCoord >= -0.3f && yCoord <= 0.3f && xCoord >= -0.3f && xCoord <= 0.3f))
183 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
187 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
188 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
189 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
191 qpTestResult res = QP_TEST_RESULT_PASS;
193 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
194 referenceFrame.getLevel(0), renderedFrame, 0.05f,
195 tcu::COMPARE_LOG_RESULT)) {
196 res = QP_TEST_RESULT_FAIL;
199 return tcu::TestStatus(res, qpGetTestResultName(res));
202 DrawInstancedIndexed::DrawInstancedIndexed (Context &context, ShaderMap shaders, vk::VkPrimitiveTopology topology)
203 : DrawIndexed (context, shaders, topology)
207 tcu::TestStatus DrawInstancedIndexed::iterate (void)
209 tcu::TestLog &log = m_context.getTestContext().getLog();
210 const vk::VkQueue queue = m_context.getUniversalQueue();
214 const vk::VkDeviceSize dataSize = m_indexes.size() * sizeof(deUint32);
215 m_indexBuffer = Buffer::createAndAlloc(m_vk, m_context.getDevice(), BufferCreateInfo(dataSize, vk::VK_BUFFER_USAGE_INDEX_BUFFER_BIT),
216 m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
218 unsigned char *ptr = reinterpret_cast<unsigned char *>(m_indexBuffer->getBoundMemory().getHostPtr());
219 deMemcpy(ptr, &m_indexes[0], dataSize);
221 vk::flushMappedMemoryRange(m_vk, m_context.getDevice(),
222 m_vertexBuffer->getBoundMemory().getMemory(),
223 m_vertexBuffer->getBoundMemory().getOffset(),
226 const vk::VkDeviceSize vertexBufferOffset = 0;
227 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
228 const vk::VkBuffer indexBuffer = m_indexBuffer->object();
229 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
230 m_vk.cmdBindIndexBuffer(*m_cmdBuffer, indexBuffer, 0, vk::VK_INDEX_TYPE_UINT32);
232 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
236 case vk::VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
238 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
240 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
242 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
243 m_vk.cmdDrawIndexed(*m_cmdBuffer, 6, 4, 2, 0, 2);
245 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
246 m_vk.cmdDrawIndexed(*m_cmdBuffer, 4, 4, 2, 0, 2);
248 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
250 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
252 case vk::VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
254 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
256 case vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
258 case vk::VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
260 case vk::VK_PRIMITIVE_TOPOLOGY_LAST:
266 m_vk.cmdEndRenderPass(*m_cmdBuffer);
267 m_vk.endCommandBuffer(*m_cmdBuffer);
269 vk::VkSubmitInfo submitInfo =
271 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
272 DE_NULL, // const void* pNext;
273 0, // deUint32 waitSemaphoreCount;
274 DE_NULL, // const VkSemaphore* pWaitSemaphores;
275 1, // deUint32 commandBufferCount;
276 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
277 0, // deUint32 signalSemaphoreCount;
278 DE_NULL // const VkSemaphore* pSignalSemaphores;
280 VK_CHECK(m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL));
282 VK_CHECK(m_vk.queueWaitIdle(queue));
285 VK_CHECK(m_vk.queueWaitIdle(queue));
287 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
288 referenceFrame.allocLevel(0);
290 const deInt32 frameWidth = referenceFrame.getWidth();
291 const deInt32 frameHeight = referenceFrame.getHeight();
293 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
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 >= -0.6f && yCoord <= 0.3f && xCoord >= -0.3f && xCoord <= 0.6f))
304 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
308 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
309 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
310 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
312 qpTestResult res = QP_TEST_RESULT_PASS;
314 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
315 referenceFrame.getLevel(0), renderedFrame, 0.05f,
316 tcu::COMPARE_LOG_RESULT)) {
317 res = QP_TEST_RESULT_FAIL;
320 return tcu::TestStatus(res, qpGetTestResultName(res));
326 DrawIndexedTests::DrawIndexedTests (tcu::TestContext &testCtx)
327 : TestCaseGroup (testCtx, "indexed_draw", "drawing indexed geometry")
329 /* Left blank on purpose */
332 DrawIndexedTests::~DrawIndexedTests (void) {}
334 void DrawIndexedTests::init (void)
336 ShaderMap shaderPaths;
337 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetch.vert";
338 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
339 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_indexed_triangle_list", "Draws indexed triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
340 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_indexed_triangle_strip", "Draws indexed triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));
342 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/draw/VertexFetchWithInstance.vert";
343 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/draw/VertexFetch.frag";
344 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_instanced_indexed_triangle_list", "Draws indexed triangle list", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST));
345 addChild(new InstanceFactory<DrawIndexed>(m_testCtx, "draw_instanced_indexed_triangle_strip", "Draws indexed triangle strip", shaderPaths, vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP));