1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Clipping tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktClippingTests.hpp"
25 #include "vktTestCase.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vktClippingUtil.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkTypeUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "deUniquePtr.hpp"
33 #include "deStringUtil.hpp"
34 #include "deRandom.hpp"
51 RENDER_SIZE_LARGE = 128,
52 NUM_RENDER_PIXELS = RENDER_SIZE * RENDER_SIZE,
53 NUM_PATCH_CONTROL_POINTS = 3,
54 MAX_NUM_SHADER_MODULES = 5,
55 MAX_CLIP_DISTANCES = 8,
56 MAX_CULL_DISTANCES = 8,
57 MAX_COMBINED_CLIP_AND_CULL_DISTANCES = 8,
62 VkShaderStageFlagBits stage;
63 const ProgramBinary* binary;
65 Shader (const VkShaderStageFlagBits stage_, const ProgramBinary& binary_)
72 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
73 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
74 //! Clip coords (-1,-1) map to viewport coords (0, 0).
78 DrawContext (Context& context,
79 const std::vector<Shader>& shaders,
80 const std::vector<Vec4>& vertices,
81 const VkPrimitiveTopology primitiveTopology,
82 const deUint32 renderSize = static_cast<deUint32>(RENDER_SIZE),
83 const bool depthClampEnable = false,
84 const bool blendEnable = false,
85 const float lineWidth = 1.0f);
88 tcu::ConstPixelBufferAccess getColorPixels (void) const;
92 const VkFormat m_colorFormat;
93 const VkImageSubresourceRange m_colorSubresourceRange;
94 const UVec2 m_renderSize;
95 const VkExtent3D m_imageExtent;
96 const VkPrimitiveTopology m_primitiveTopology;
97 const bool m_depthClampEnable;
98 const bool m_blendEnable;
99 const deUint32 m_numVertices;
100 const float m_lineWidth;
101 const deUint32 m_numPatchControlPoints;
102 MovePtr<Buffer> m_vertexBuffer;
103 MovePtr<Image> m_colorImage;
104 MovePtr<Buffer> m_colorAttachmentBuffer;
105 Move<VkImageView> m_colorImageView;
106 Move<VkRenderPass> m_renderPass;
107 Move<VkFramebuffer> m_framebuffer;
108 Move<VkPipelineLayout> m_pipelineLayout;
109 Move<VkPipeline> m_pipeline;
110 Move<VkCommandPool> m_cmdPool;
111 Move<VkCommandBuffer> m_cmdBuffer;
112 Move<VkShaderModule> m_shaderModules[MAX_NUM_SHADER_MODULES];
114 DrawContext (const DrawContext&); // "deleted"
115 DrawContext& operator= (const DrawContext&); // "deleted"
118 DrawContext::DrawContext (Context& context,
119 const std::vector<Shader>& shaders,
120 const std::vector<Vec4>& vertices,
121 const VkPrimitiveTopology primitiveTopology,
122 const deUint32 renderSize,
123 const bool depthClampEnable,
124 const bool blendEnable,
125 const float lineWidth)
126 : m_context (context)
127 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
128 , m_colorSubresourceRange (makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u))
129 , m_renderSize (renderSize, renderSize)
130 , m_imageExtent (makeExtent3D(m_renderSize.x(), m_renderSize.y(), 1u))
131 , m_primitiveTopology (primitiveTopology)
132 , m_depthClampEnable (depthClampEnable)
133 , m_blendEnable (blendEnable)
134 , m_numVertices (static_cast<deUint32>(vertices.size()))
135 , m_lineWidth (lineWidth)
136 , m_numPatchControlPoints (NUM_PATCH_CONTROL_POINTS) // we're treating patches as triangles
138 const DeviceInterface& vk = m_context.getDeviceInterface();
139 const VkDevice device = m_context.getDevice();
140 Allocator& allocator = m_context.getDefaultAllocator();
144 m_cmdPool = makeCommandPool(vk, device, m_context.getUniversalQueueFamilyIndex());
145 m_cmdBuffer = makeCommandBuffer(vk, device, *m_cmdPool);
148 // Color attachment image
150 const VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
151 const VkImageCreateInfo imageCreateInfo =
153 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
154 DE_NULL, // const void* pNext;
155 (VkImageCreateFlags)0, // VkImageCreateFlags flags;
156 VK_IMAGE_TYPE_2D, // VkImageType imageType;
157 m_colorFormat, // VkFormat format;
158 m_imageExtent, // VkExtent3D extent;
159 1u, // uint32_t mipLevels;
160 1u, // uint32_t arrayLayers;
161 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
162 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
163 usage, // VkImageUsageFlags usage;
164 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
165 VK_QUEUE_FAMILY_IGNORED, // uint32_t queueFamilyIndexCount;
166 DE_NULL, // const uint32_t* pQueueFamilyIndices;
167 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
170 m_colorImage = MovePtr<Image>(new Image(vk, device, allocator, imageCreateInfo, MemoryRequirement::Any));
171 m_colorImageView = makeImageView(vk, device, **m_colorImage, VK_IMAGE_VIEW_TYPE_2D, m_colorFormat, m_colorSubresourceRange);
173 // Buffer to copy attachment data after rendering
175 const VkDeviceSize bitmapSize = tcu::getPixelSize(mapVkFormat(m_colorFormat)) * m_renderSize.x() * m_renderSize.y();
176 m_colorAttachmentBuffer = MovePtr<Buffer>(new Buffer(
177 vk, device, allocator, makeBufferCreateInfo(bitmapSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible));
180 const Allocation& alloc = m_colorAttachmentBuffer->getAllocation();
181 deMemset(alloc.getHostPtr(), 0, (size_t)bitmapSize);
182 flushMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset(), bitmapSize);
188 const VkDeviceSize bufferSize = vertices.size() * sizeof(vertices[0]);
189 m_vertexBuffer = MovePtr<Buffer>(new Buffer(
190 vk, device, allocator, makeBufferCreateInfo(bufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), MemoryRequirement::HostVisible));
192 const Allocation& alloc = m_vertexBuffer->getAllocation();
193 deMemcpy(alloc.getHostPtr(), &vertices[0], (size_t)bufferSize);
194 flushMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset(), bufferSize);
199 m_pipelineLayout = makePipelineLayoutWithoutDescriptors(vk, device);
204 const VkAttachmentDescription colorAttachmentDescription =
206 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
207 m_colorFormat, // VkFormat format;
208 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
209 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
210 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
211 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
212 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
213 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
214 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
217 const VkAttachmentReference colorAttachmentReference =
219 0u, // deUint32 attachment;
220 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
223 const VkAttachmentReference depthAttachmentReference =
225 VK_ATTACHMENT_UNUSED, // deUint32 attachment;
226 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout layout;
229 const VkSubpassDescription subpassDescription =
231 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
232 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
233 0u, // deUint32 inputAttachmentCount;
234 DE_NULL, // const VkAttachmentReference* pInputAttachments;
235 1u, // deUint32 colorAttachmentCount;
236 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
237 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
238 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment;
239 0u, // deUint32 preserveAttachmentCount;
240 DE_NULL // const deUint32* pPreserveAttachments;
243 const VkRenderPassCreateInfo renderPassInfo =
245 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
246 DE_NULL, // const void* pNext;
247 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
248 1u, // deUint32 attachmentCount;
249 &colorAttachmentDescription, // const VkAttachmentDescription* pAttachments;
250 1u, // deUint32 subpassCount;
251 &subpassDescription, // const VkSubpassDescription* pSubpasses;
252 0u, // deUint32 dependencyCount;
253 DE_NULL // const VkSubpassDependency* pDependencies;
256 m_renderPass = createRenderPass(vk, device, &renderPassInfo);
261 const VkFramebufferCreateInfo framebufferInfo = {
262 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
263 DE_NULL, // const void* pNext;
264 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
265 *m_renderPass, // VkRenderPass renderPass;
266 1u, // uint32_t attachmentCount;
267 &m_colorImageView.get(), // const VkImageView* pAttachments;
268 m_renderSize.x(), // uint32_t width;
269 m_renderSize.y(), // uint32_t height;
270 1u, // uint32_t layers;
273 m_framebuffer = createFramebuffer(vk, device, &framebufferInfo);
278 const deUint32 vertexStride = sizeof(Vec4);
279 const VkFormat vertexFormat = VK_FORMAT_R32G32B32A32_SFLOAT;
281 const VkVertexInputBindingDescription bindingDesc =
283 0u, // uint32_t binding;
284 vertexStride, // uint32_t stride;
285 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate;
287 const VkVertexInputAttributeDescription attributeDesc =
289 0u, // uint32_t location;
290 0u, // uint32_t binding;
291 vertexFormat, // VkFormat format;
292 0u, // uint32_t offset;
295 const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
297 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
298 DE_NULL, // const void* pNext;
299 (VkPipelineVertexInputStateCreateFlags)0, // VkPipelineVertexInputStateCreateFlags flags;
300 1u, // uint32_t vertexBindingDescriptionCount;
301 &bindingDesc, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
302 1u, // uint32_t vertexAttributeDescriptionCount;
303 &attributeDesc, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
306 const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
308 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
309 DE_NULL, // const void* pNext;
310 (VkPipelineInputAssemblyStateCreateFlags)0, // VkPipelineInputAssemblyStateCreateFlags flags;
311 m_primitiveTopology, // VkPrimitiveTopology topology;
312 VK_FALSE, // VkBool32 primitiveRestartEnable;
315 const VkPipelineTessellationStateCreateInfo pipelineTessellationStateInfo =
317 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, // VkStructureType sType;
318 DE_NULL, // const void* pNext;
319 (VkPipelineTessellationStateCreateFlags)0, // VkPipelineTessellationStateCreateFlags flags;
320 m_numPatchControlPoints, // uint32_t patchControlPoints;
323 const VkViewport viewport = makeViewport(
325 static_cast<float>(m_renderSize.x()), static_cast<float>(m_renderSize.y()),
328 const VkRect2D scissor = {
330 makeExtent2D(m_renderSize.x(), m_renderSize.y()),
333 const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
335 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
336 DE_NULL, // const void* pNext;
337 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags;
338 1u, // uint32_t viewportCount;
339 &viewport, // const VkViewport* pViewports;
340 1u, // uint32_t scissorCount;
341 &scissor, // const VkRect2D* pScissors;
344 const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
346 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
347 DE_NULL, // const void* pNext;
348 (VkPipelineRasterizationStateCreateFlags)0, // VkPipelineRasterizationStateCreateFlags flags;
349 m_depthClampEnable, // VkBool32 depthClampEnable;
350 VK_FALSE, // VkBool32 rasterizerDiscardEnable;
351 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
352 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
353 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
354 VK_FALSE, // VkBool32 depthBiasEnable;
355 0.0f, // float depthBiasConstantFactor;
356 0.0f, // float depthBiasClamp;
357 0.0f, // float depthBiasSlopeFactor;
358 m_lineWidth, // float lineWidth;
361 const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
363 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
364 DE_NULL, // const void* pNext;
365 (VkPipelineMultisampleStateCreateFlags)0, // VkPipelineMultisampleStateCreateFlags flags;
366 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
367 VK_FALSE, // VkBool32 sampleShadingEnable;
368 0.0f, // float minSampleShading;
369 DE_NULL, // const VkSampleMask* pSampleMask;
370 VK_FALSE, // VkBool32 alphaToCoverageEnable;
371 VK_FALSE // VkBool32 alphaToOneEnable;
374 const VkStencilOpState stencilOpState = makeStencilOpState(
375 VK_STENCIL_OP_KEEP, // stencil fail
376 VK_STENCIL_OP_KEEP, // depth & stencil pass
377 VK_STENCIL_OP_KEEP, // depth only fail
378 VK_COMPARE_OP_NEVER, // compare op
383 const VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo =
385 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
386 DE_NULL, // const void* pNext;
387 (VkPipelineDepthStencilStateCreateFlags)0, // VkPipelineDepthStencilStateCreateFlags flags;
388 VK_FALSE, // VkBool32 depthTestEnable;
389 VK_FALSE, // VkBool32 depthWriteEnable;
390 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
391 VK_FALSE, // VkBool32 depthBoundsTestEnable;
392 VK_FALSE, // VkBool32 stencilTestEnable;
393 stencilOpState, // VkStencilOpState front;
394 stencilOpState, // VkStencilOpState back;
395 0.0f, // float minDepthBounds;
396 1.0f, // float maxDepthBounds;
399 const VkColorComponentFlags colorComponentsAll = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
400 const VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState =
402 m_blendEnable, // VkBool32 blendEnable;
403 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcColorBlendFactor;
404 VK_BLEND_FACTOR_ONE, // VkBlendFactor dstColorBlendFactor;
405 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
406 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcAlphaBlendFactor;
407 VK_BLEND_FACTOR_ONE, // VkBlendFactor dstAlphaBlendFactor;
408 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
409 colorComponentsAll, // VkColorComponentFlags colorWriteMask;
412 const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
414 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
415 DE_NULL, // const void* pNext;
416 (VkPipelineColorBlendStateCreateFlags)0, // VkPipelineColorBlendStateCreateFlags flags;
417 VK_FALSE, // VkBool32 logicOpEnable;
418 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
419 1u, // deUint32 attachmentCount;
420 &pipelineColorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
421 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConstants[4];
424 // Create shader stages
426 std::vector<VkPipelineShaderStageCreateInfo> shaderStages;
427 VkShaderStageFlags stageFlags = (VkShaderStageFlags)0;
429 DE_ASSERT(shaders.size() <= MAX_NUM_SHADER_MODULES);
430 for (deUint32 shaderNdx = 0; shaderNdx < shaders.size(); ++shaderNdx)
432 m_shaderModules[shaderNdx] = createShaderModule(vk, device, *shaders[shaderNdx].binary, (VkShaderModuleCreateFlags)0);
434 const VkPipelineShaderStageCreateInfo pipelineShaderStageInfo =
436 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
437 DE_NULL, // const void* pNext;
438 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
439 shaders[shaderNdx].stage, // VkShaderStageFlagBits stage;
440 *m_shaderModules[shaderNdx], // VkShaderModule module;
441 "main", // const char* pName;
442 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
445 shaderStages.push_back(pipelineShaderStageInfo);
446 stageFlags |= shaders[shaderNdx].stage;
450 (m_primitiveTopology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) ||
451 (stageFlags & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)));
453 const bool tessellationEnabled = (m_primitiveTopology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST);
454 const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
456 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
457 DE_NULL, // const void* pNext;
458 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
459 static_cast<deUint32>(shaderStages.size()), // deUint32 stageCount;
460 &shaderStages[0], // const VkPipelineShaderStageCreateInfo* pStages;
461 &vertexInputStateInfo, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
462 &pipelineInputAssemblyStateInfo, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
463 (tessellationEnabled ? &pipelineTessellationStateInfo : DE_NULL), // const VkPipelineTessellationStateCreateInfo* pTessellationState;
464 &pipelineViewportStateInfo, // const VkPipelineViewportStateCreateInfo* pViewportState;
465 &pipelineRasterizationStateInfo, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
466 &pipelineMultisampleStateInfo, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
467 &pipelineDepthStencilStateInfo, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
468 &pipelineColorBlendStateInfo, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
469 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
470 *m_pipelineLayout, // VkPipelineLayout layout;
471 *m_renderPass, // VkRenderPass renderPass;
472 0u, // deUint32 subpass;
473 DE_NULL, // VkPipeline basePipelineHandle;
474 0, // deInt32 basePipelineIndex;
477 m_pipeline = createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo);
482 const VkDeviceSize zeroOffset = 0ull;
484 beginCommandBuffer(vk, *m_cmdBuffer);
488 const VkClearValue clearValue = makeClearValueColor(Vec4(0.0f, 0.0f, 0.0f, 1.0f));
489 const VkRect2D renderArea =
492 makeExtent2D(m_renderSize.x(), m_renderSize.y())
495 const VkRenderPassBeginInfo renderPassBeginInfo = {
496 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
497 DE_NULL, // const void* pNext;
498 *m_renderPass, // VkRenderPass renderPass;
499 *m_framebuffer, // VkFramebuffer framebuffer;
500 renderArea, // VkRect2D renderArea;
501 1u, // uint32_t clearValueCount;
502 &clearValue, // const VkClearValue* pClearValues;
505 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
508 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
509 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &(**m_vertexBuffer), &zeroOffset);
511 vk.cmdDraw(*m_cmdBuffer, m_numVertices, 1u, 0u, 1u);
512 vk.cmdEndRenderPass(*m_cmdBuffer);
514 // Barrier: draw -> copy from image
516 const VkImageMemoryBarrier barrier = makeImageMemoryBarrier(
517 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
518 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
519 **m_colorImage, m_colorSubresourceRange);
521 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0,
522 0u, DE_NULL, 0u, DE_NULL, 1u, &barrier);
526 const VkBufferImageCopy copyRegion = makeBufferImageCopy(makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u), m_imageExtent);
527 vk.cmdCopyImageToBuffer(*m_cmdBuffer, **m_colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, **m_colorAttachmentBuffer, 1u, ©Region);
530 // Barrier: copy to buffer -> host read
532 const VkBufferMemoryBarrier barrier = makeBufferMemoryBarrier(
533 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT,
534 **m_colorAttachmentBuffer, 0ull, VK_WHOLE_SIZE);
536 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0,
537 0u, DE_NULL, 1u, &barrier, 0u, DE_NULL);
540 endCommandBuffer(vk, *m_cmdBuffer);
544 void DrawContext::draw (void)
546 const DeviceInterface& vk = m_context.getDeviceInterface();
547 const VkDevice device = m_context.getDevice();
548 const VkQueue queue = m_context.getUniversalQueue();
549 tcu::TestLog& log = m_context.getTestContext().getLog();
551 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
553 log << tcu::LogImageSet("attachments", "") << tcu::LogImage("color0", "", getColorPixels()) << tcu::TestLog::EndImageSet;
556 tcu::ConstPixelBufferAccess DrawContext::getColorPixels (void) const
558 const DeviceInterface& vk = m_context.getDeviceInterface();
559 const VkDevice device = m_context.getDevice();
561 const Allocation& alloc = m_colorAttachmentBuffer->getAllocation();
562 invalidateMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset(), VK_WHOLE_SIZE);
564 return tcu::ConstPixelBufferAccess(mapVkFormat(m_colorFormat), m_imageExtent.width, m_imageExtent.height, m_imageExtent.depth, alloc.getHostPtr());
567 std::vector<Vec4> genVertices (const VkPrimitiveTopology topology, const Vec4& offset, const float slope)
569 const float p = 1.0f;
570 const float hp = 0.5f;
571 const float z = 0.0f;
572 const float w = 1.0f;
574 std::vector<Vec4> vertices;
576 // We're setting adjacent vertices to zero where needed, as we don't use them in meaningful way.
580 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
581 vertices.push_back(offset + Vec4(0.0f, 0.0f, slope/2.0f + z, w));
582 vertices.push_back(offset + Vec4( -hp, -hp, z, w));
583 vertices.push_back(offset + Vec4( hp, -hp, slope + z, w));
584 vertices.push_back(offset + Vec4( -hp, hp, z, w));
585 vertices.push_back(offset + Vec4( hp, hp, slope + z, w));
588 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
589 vertices.push_back(offset + Vec4(-p, -p, z, w));
590 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // line 0
591 vertices.push_back(offset + Vec4( p, p, slope + z, w));
592 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // line 1
593 vertices.push_back(offset + Vec4( p, -p, slope + z, w));
594 vertices.push_back(offset + Vec4(-p, p, z, w)); // line 2
597 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
598 vertices.push_back(Vec4());
599 vertices.push_back(offset + Vec4(-p, -p, z, w));
600 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // line 0
601 vertices.push_back(Vec4());
602 vertices.push_back(Vec4());
603 vertices.push_back(offset + Vec4( p, p, slope + z, w));
604 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // line 1
605 vertices.push_back(Vec4());
606 vertices.push_back(Vec4());
607 vertices.push_back(offset + Vec4( p, -p, slope + z, w));
608 vertices.push_back(offset + Vec4(-p, p, z, w)); // line 2
609 vertices.push_back(Vec4());
612 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
613 vertices.push_back(offset + Vec4(-p, -p, z, w));
614 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // line 0
615 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // line 1
616 vertices.push_back(offset + Vec4(-p, p, z, w)); // line 2
619 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
620 vertices.push_back(Vec4());
621 vertices.push_back(offset + Vec4(-p, -p, z, w));
622 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // line 0
623 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // line 1
624 vertices.push_back(offset + Vec4(-p, p, z, w)); // line 2
625 vertices.push_back(Vec4());
628 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
629 vertices.push_back(offset + Vec4( p, -p, slope + z, w));
630 vertices.push_back(offset + Vec4(-p, -p, z, w));
631 vertices.push_back(offset + Vec4(-p, p, z, w)); // triangle 0
632 vertices.push_back(offset + Vec4(-p, p, z, w));
633 vertices.push_back(offset + Vec4( p, p, slope + z, w));
634 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // triangle 1
637 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
638 vertices.push_back(offset + Vec4( p, -p, slope + z, w));
639 vertices.push_back(Vec4());
640 vertices.push_back(offset + Vec4(-p, -p, z, w));
641 vertices.push_back(Vec4());
642 vertices.push_back(offset + Vec4(-p, p, z, w)); // triangle 0
643 vertices.push_back(Vec4());
644 vertices.push_back(offset + Vec4(-p, p, z, w));
645 vertices.push_back(Vec4());
646 vertices.push_back(offset + Vec4( p, p, slope + z, w));
647 vertices.push_back(Vec4());
648 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // triangle 1
649 vertices.push_back(Vec4());
652 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
653 vertices.push_back(offset + Vec4(-p, -p, z, w));
654 vertices.push_back(offset + Vec4(-p, p, z, w));
655 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // triangle 0
656 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // triangle 1
659 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
660 vertices.push_back(offset + Vec4(-p, -p, z, w));
661 vertices.push_back(Vec4());
662 vertices.push_back(offset + Vec4(-p, p, z, w));
663 vertices.push_back(Vec4());
664 vertices.push_back(offset + Vec4( p, -p, slope + z, w)); // triangle 0
665 vertices.push_back(Vec4());
666 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // triangle 1
667 vertices.push_back(Vec4());
670 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
671 vertices.push_back(offset + Vec4( p, -p, slope + z, w));
672 vertices.push_back(offset + Vec4(-p, -p, z, w));
673 vertices.push_back(offset + Vec4(-p, p, z, w)); // triangle 0
674 vertices.push_back(offset + Vec4( p, p, slope + z, w)); // triangle 1
677 case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
688 bool inline isColorInRange (const Vec4& color, const Vec4& minColor, const Vec4& maxColor)
690 return (minColor.x() <= color.x() && color.x() <= maxColor.x())
691 && (minColor.y() <= color.y() && color.y() <= maxColor.y())
692 && (minColor.z() <= color.z() && color.z() <= maxColor.z())
693 && (minColor.w() <= color.w() && color.w() <= maxColor.w());
696 //! Count pixels that match color within threshold, in the specified region.
697 int countPixels (const tcu::ConstPixelBufferAccess pixels, const IVec2& regionOffset, const IVec2& regionSize, const Vec4& color, const Vec4& colorThreshold)
699 const Vec4 minColor = color - colorThreshold;
700 const Vec4 maxColor = color + colorThreshold;
701 const int xEnd = regionOffset.x() + regionSize.x();
702 const int yEnd = regionOffset.y() + regionSize.y();
705 DE_ASSERT(xEnd <= pixels.getWidth());
706 DE_ASSERT(yEnd <= pixels.getHeight());
708 for (int y = regionOffset.y(); y < yEnd; ++y)
709 for (int x = regionOffset.x(); x < xEnd; ++x)
711 if (isColorInRange(pixels.getPixel(x, y), minColor, maxColor))
718 int countPixels (const tcu::ConstPixelBufferAccess pixels, const Vec4& color, const Vec4& colorThreshold)
720 return countPixels(pixels, IVec2(), IVec2(pixels.getWidth(), pixels.getHeight()), color, colorThreshold);
723 //! Clipping against the default clip volume.
727 //! Used by wide lines test.
730 LINE_ORIENTATION_AXIS_ALIGNED,
731 LINE_ORIENTATION_DIAGONAL,
734 void addProgramsWithPointSize (SourceCollections& programCollection, const float pointSize)
738 const bool usePointSize = pointSize > 1.0f;
740 std::ostringstream src;
741 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
743 << "layout(location = 0) in vec4 v_position;\n"
745 << "out gl_PerVertex {\n"
746 << " vec4 gl_Position;\n"
747 << (usePointSize ? " float gl_PointSize;\n" : "")
750 << "void main (void)\n"
752 << " gl_Position = v_position;\n"
753 << (usePointSize ? " gl_PointSize = " + de::floatToString(pointSize, 1) + ";\n" : "")
756 programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
761 std::ostringstream src;
762 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
764 << "layout(location = 0) out vec4 o_color;\n"
766 << "void main (void)\n"
768 << " o_color = vec4(1.0, gl_FragCoord.z, 0.0, 1.0);\n"
771 programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
775 void initPrograms (SourceCollections& programCollection, const VkPrimitiveTopology topology)
778 addProgramsWithPointSize(programCollection, 1.0f);
781 void initPrograms (SourceCollections& programCollection, const LineOrientation lineOrientation)
783 DE_UNREF(lineOrientation);
784 addProgramsWithPointSize(programCollection, 1.0f);
787 void initProgramsPointSize (SourceCollections& programCollection)
789 addProgramsWithPointSize(programCollection, 0.75f * RENDER_SIZE);
792 //! Primitives fully inside the clip volume.
793 tcu::TestStatus testPrimitivesInside (Context& context, const VkPrimitiveTopology topology)
795 int minExpectedBlackPixels = 0;
799 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
800 // We draw only 5 points.
801 minExpectedBlackPixels = NUM_RENDER_PIXELS - 5;
804 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
805 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
806 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
807 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
808 // Allow for some error.
809 minExpectedBlackPixels = NUM_RENDER_PIXELS - 3 * RENDER_SIZE;
812 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
813 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
814 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
815 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
816 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
817 // All render area should be covered.
818 minExpectedBlackPixels = 0;
826 std::vector<Shader> shaders;
827 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
828 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
830 tcu::TestLog& log = context.getTestContext().getLog();
835 const char* const desc;
839 { "Draw primitives at near clipping plane, z = 0.0", 0.0f, },
840 { "Draw primitives at z = 0.5", 0.5f, },
841 { "Draw primitives at far clipping plane, z = 1.0", 1.0f, },
844 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
846 log << tcu::TestLog::Message << cases[caseNdx].desc << tcu::TestLog::EndMessage;
848 const std::vector<Vec4> vertices = genVertices(topology, Vec4(0.0f, 0.0f, cases[caseNdx].zPos, 0.0f), 0.0f);
849 DrawContext drawContext(context, shaders, vertices, topology);
852 const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
853 if (numBlackPixels >= minExpectedBlackPixels)
857 return (numPassed == DE_LENGTH_OF_ARRAY(cases) ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
860 //! Primitives fully outside the clip volume.
861 tcu::TestStatus testPrimitivesOutside (Context& context, const VkPrimitiveTopology topology)
863 std::vector<Shader> shaders;
864 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
865 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
867 tcu::TestLog& log = context.getTestContext().getLog();
872 const char* const desc;
876 { "Draw primitives in front of the near clipping plane, z < 0.0", -0.5f, },
877 { "Draw primitives behind the far clipping plane, z > 1.0", 1.5f, },
880 log << tcu::TestLog::Message << "Drawing primitives outside the clip volume. Expecting an empty image." << tcu::TestLog::EndMessage;
882 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
884 log << tcu::TestLog::Message << cases[caseNdx].desc << tcu::TestLog::EndMessage;
886 const std::vector<Vec4> vertices = genVertices(topology, Vec4(0.0f, 0.0f, cases[caseNdx].zPos, 0.0f), 0.0f);
887 DrawContext drawContext(context, shaders, vertices, topology);
890 // All pixels must be black -- nothing is drawn.
891 const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
892 if (numBlackPixels == NUM_RENDER_PIXELS)
896 return (numPassed == DE_LENGTH_OF_ARRAY(cases) ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
899 //! Primitives partially outside the clip volume, but depth clamped
900 tcu::TestStatus testPrimitivesDepthClamp (Context& context, const VkPrimitiveTopology topology)
902 requireFeatures(context.getInstanceInterface(), context.getPhysicalDevice(), FEATURE_DEPTH_CLAMP);
904 std::vector<Shader> shaders;
905 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
906 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
908 const int numCases = 4;
909 const IVec2 regionSize = IVec2(RENDER_SIZE/2, RENDER_SIZE); //! size of the clamped region
910 const int regionPixels = regionSize.x() * regionSize.y();
911 tcu::TestLog& log = context.getTestContext().getLog();
916 const char* const desc;
918 bool depthClampEnable;
923 { "Draw primitives intersecting the near clipping plane, depth clamp disabled", -0.5f, false, IVec2(0, 0), Vec4(0.0f, 0.0f, 0.0f, 1.0f) },
924 { "Draw primitives intersecting the near clipping plane, depth clamp enabled", -0.5f, true, IVec2(0, 0), Vec4(1.0f, 0.0f, 0.0f, 1.0f) },
925 { "Draw primitives intersecting the far clipping plane, depth clamp disabled", 0.5f, false, IVec2(RENDER_SIZE/2, 0), Vec4(0.0f, 0.0f, 0.0f, 1.0f) },
926 { "Draw primitives intersecting the far clipping plane, depth clamp enabled", 0.5f, true, IVec2(RENDER_SIZE/2, 0), Vec4(1.0f, 1.0f, 0.0f, 1.0f) },
929 // Per case minimum number of colored pixels.
930 int caseMinPixels[numCases] = { 0, 0, 0, 0 };
934 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
935 caseMinPixels[0] = caseMinPixels[2] = regionPixels - 1;
936 caseMinPixels[1] = caseMinPixels[3] = 2;
939 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
940 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
941 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
942 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
943 caseMinPixels[0] = regionPixels;
944 caseMinPixels[1] = RENDER_SIZE - 2;
945 caseMinPixels[2] = regionPixels;
946 caseMinPixels[3] = 2 * (RENDER_SIZE - 2);
949 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
950 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
951 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
952 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
953 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
954 caseMinPixels[0] = caseMinPixels[1] = caseMinPixels[2] = caseMinPixels[3] = regionPixels;
962 for (int caseNdx = 0; caseNdx < numCases; ++caseNdx)
964 log << tcu::TestLog::Message << cases[caseNdx].desc << tcu::TestLog::EndMessage;
966 const std::vector<Vec4> vertices = genVertices(topology, Vec4(0.0f, 0.0f, cases[caseNdx].zPos, 0.0f), 1.0f);
967 DrawContext drawContext(context, shaders, vertices, topology, static_cast<deUint32>(RENDER_SIZE), cases[caseNdx].depthClampEnable);
970 const int numPixels = countPixels(drawContext.getColorPixels(), cases[caseNdx].regionOffset, regionSize, cases[caseNdx].color, Vec4());
972 if (numPixels >= caseMinPixels[caseNdx])
976 return (numPassed == numCases ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
979 //! Large point clipping
980 //! Spec: If the primitive under consideration is a point, then clipping passes it unchanged if it lies within the clip volume;
981 //! otherwise, it is discarded.
982 tcu::TestStatus testLargePoints (Context& context)
984 requireFeatures(context.getInstanceInterface(), context.getPhysicalDevice(), FEATURE_LARGE_POINTS);
986 std::vector<Shader> shaders;
987 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
988 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
990 std::vector<Vec4> vertices;
992 const float delta = 0.1f; // much smaller than the point size
993 const float p = 1.0f + delta;
995 vertices.push_back(Vec4( -p, -p, 0.1f, 1.0f));
996 vertices.push_back(Vec4( -p, p, 0.2f, 1.0f));
997 vertices.push_back(Vec4( p, p, 0.4f, 1.0f));
998 vertices.push_back(Vec4( p, -p, 0.6f, 1.0f));
999 vertices.push_back(Vec4(0.0f, -p, 0.8f, 1.0f));
1000 vertices.push_back(Vec4( p, 0.0f, 0.9f, 1.0f));
1001 vertices.push_back(Vec4(0.0f, p, 0.1f, 1.0f));
1002 vertices.push_back(Vec4( -p, 0.0f, 0.2f, 1.0f));
1005 tcu::TestLog& log = context.getTestContext().getLog();
1007 log << tcu::TestLog::Message << "Drawing several large points just outside the clip volume. Expecting an empty image." << tcu::TestLog::EndMessage;
1009 DrawContext drawContext(context, shaders, vertices, VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
1012 // All pixels must be black -- nothing is drawn.
1013 const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
1015 return (numBlackPixels == NUM_RENDER_PIXELS ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
1018 //! Wide line clipping
1019 //! Spec: If the primitive is a line segment, then clipping does nothing to it if it lies entirely within the clip volume, and discards it
1020 //! if it lies entirely outside the volume.
1021 tcu::TestStatus testWideLines (Context& context, const LineOrientation lineOrientation)
1023 requireFeatures(context.getInstanceInterface(), context.getPhysicalDevice(), FEATURE_WIDE_LINES);
1025 std::vector<Shader> shaders;
1026 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
1027 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
1029 const float delta = 0.1f; // much smaller than the line width
1031 std::vector<Vec4> vertices;
1032 if (lineOrientation == LINE_ORIENTATION_AXIS_ALIGNED)
1034 // Axis-aligned lines just outside the clip volume.
1035 const float p = 1.0f + delta;
1036 const float q = 0.9f;
1038 vertices.push_back(Vec4(-p, -q, 0.1f, 1.0f));
1039 vertices.push_back(Vec4(-p, q, 0.9f, 1.0f)); // line 0
1040 vertices.push_back(Vec4(-q, p, 0.1f, 1.0f));
1041 vertices.push_back(Vec4( q, p, 0.9f, 1.0f)); // line 1
1042 vertices.push_back(Vec4( p, q, 0.1f, 1.0f));
1043 vertices.push_back(Vec4( p, -q, 0.9f, 1.0f)); // line 2
1044 vertices.push_back(Vec4( q, -p, 0.1f, 1.0f));
1045 vertices.push_back(Vec4(-q, -p, 0.9f, 1.0f)); // line 3
1047 else if (lineOrientation == LINE_ORIENTATION_DIAGONAL)
1049 // Diagonal lines just outside the clip volume.
1050 const float p = 2.0f + delta;
1052 vertices.push_back(Vec4( -p, 0.0f, 0.1f, 1.0f));
1053 vertices.push_back(Vec4(0.0f, -p, 0.9f, 1.0f)); // line 0
1054 vertices.push_back(Vec4(0.0f, -p, 0.1f, 1.0f));
1055 vertices.push_back(Vec4( p, 0.0f, 0.9f, 1.0f)); // line 1
1056 vertices.push_back(Vec4( p, 0.0f, 0.1f, 1.0f));
1057 vertices.push_back(Vec4(0.0f, p, 0.9f, 1.0f)); // line 2
1058 vertices.push_back(Vec4(0.0f, p, 0.1f, 1.0f));
1059 vertices.push_back(Vec4( -p, 0.0f, 0.9f, 1.0f)); // line 3
1064 const VkPhysicalDeviceLimits limits = getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice()).limits;
1066 const float lineWidth = std::min(static_cast<float>(RENDER_SIZE), limits.lineWidthRange[1]);
1067 tcu::TestLog& log = context.getTestContext().getLog();
1069 log << tcu::TestLog::Message << "Drawing several wide lines just outside the clip volume. Expecting an empty image." << tcu::TestLog::EndMessage
1070 << tcu::TestLog::Message << "Line width is " << lineWidth << "." << tcu::TestLog::EndMessage;
1072 DrawContext drawContext(context, shaders, vertices, VK_PRIMITIVE_TOPOLOGY_LINE_LIST, static_cast<deUint32>(RENDER_SIZE), false, false, lineWidth);
1075 // All pixels must be black -- nothing is drawn.
1076 const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
1078 return (numBlackPixels == NUM_RENDER_PIXELS ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
1083 namespace ClipDistance
1086 struct CaseDefinition
1088 const VkPrimitiveTopology topology;
1089 const bool dynamicIndexing;
1090 const bool enableTessellation;
1091 const bool enableGeometry;
1092 const int numClipDistances;
1093 const int numCullDistances;
1095 CaseDefinition (const VkPrimitiveTopology topology_,
1096 const int numClipDistances_,
1097 const int numCullDistances_,
1098 const bool enableTessellation_,
1099 const bool enableGeometry_,
1100 const bool dynamicIndexing_)
1101 : topology (topology_)
1102 , dynamicIndexing (dynamicIndexing_)
1103 , enableTessellation (enableTessellation_)
1104 , enableGeometry (enableGeometry_)
1105 , numClipDistances (numClipDistances_)
1106 , numCullDistances (numCullDistances_)
1111 void initPrograms (SourceCollections& programCollection, const CaseDefinition caseDef)
1113 DE_ASSERT(caseDef.numClipDistances + caseDef.numCullDistances <= MAX_COMBINED_CLIP_AND_CULL_DISTANCES);
1115 std::string perVertexBlock;
1117 std::ostringstream str;
1118 str << "gl_PerVertex {\n"
1119 << " vec4 gl_Position;\n";
1120 if (caseDef.numClipDistances > 0)
1121 str << " float gl_ClipDistance[" << caseDef.numClipDistances << "];\n";
1122 if (caseDef.numCullDistances > 0)
1123 str << " float gl_CullDistance[" << caseDef.numCullDistances << "];\n";
1125 perVertexBlock = str.str();
1130 std::ostringstream src;
1131 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1133 << "layout(location = 0) in vec4 v_position;\n"
1134 << "layout(location = 0) out vec4 out_color;\n"
1136 << "out " << perVertexBlock << ";\n"
1138 << "void main (void)\n"
1140 << " gl_Position = v_position;\n"
1141 << " out_color = vec4(1.0, 0.5 * (v_position.x + 1.0), 0.0, 1.0);\n"
1143 << " const int barNdx = gl_VertexIndex / 6;\n";
1144 if (caseDef.dynamicIndexing)
1146 if (caseDef.numClipDistances > 0)
1147 src << " for (int i = 0; i < " << caseDef.numClipDistances << "; ++i)\n"
1148 << " gl_ClipDistance[i] = (barNdx == i ? v_position.y : 0.0);\n";
1149 if (caseDef.numCullDistances > 0)
1150 src << " for (int i = 0; i < " << caseDef.numCullDistances << "; ++i)\n"
1151 << " gl_CullDistance[i] = 0.0;\n";
1155 for (int i = 0; i < caseDef.numClipDistances; ++i)
1156 src << " gl_ClipDistance[" << i << "] = (barNdx == " << i << " ? v_position.y : 0.0);\n";
1157 for (int i = 0; i < caseDef.numCullDistances; ++i)
1158 src << " gl_CullDistance[" << i << "] = 0.0;\n"; // don't cull anything
1162 programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
1165 if (caseDef.enableTessellation)
1167 std::ostringstream src;
1168 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1170 << "layout(vertices = " << NUM_PATCH_CONTROL_POINTS << ") out;\n"
1172 << "layout(location = 0) in vec4 in_color[];\n"
1173 << "layout(location = 0) out vec4 out_color[];\n"
1175 << "in " << perVertexBlock << " gl_in[gl_MaxPatchVertices];\n"
1177 << "out " << perVertexBlock << " gl_out[];\n"
1179 << "void main (void)\n"
1181 << " gl_TessLevelInner[0] = 1.0;\n"
1182 << " gl_TessLevelInner[1] = 1.0;\n"
1184 << " gl_TessLevelOuter[0] = 1.0;\n"
1185 << " gl_TessLevelOuter[1] = 1.0;\n"
1186 << " gl_TessLevelOuter[2] = 1.0;\n"
1187 << " gl_TessLevelOuter[3] = 1.0;\n"
1189 << " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
1190 << " out_color[gl_InvocationID] = in_color[gl_InvocationID];\n"
1192 if (caseDef.dynamicIndexing)
1194 if (caseDef.numClipDistances > 0)
1195 src << " for (int i = 0; i < " << caseDef.numClipDistances << "; ++i)\n"
1196 << " gl_out[gl_InvocationID].gl_ClipDistance[i] = gl_in[gl_InvocationID].gl_ClipDistance[i];\n";
1197 if (caseDef.numCullDistances > 0)
1198 src << " for (int i = 0; i < " << caseDef.numCullDistances << "; ++i)\n"
1199 << " gl_out[gl_InvocationID].gl_CullDistance[i] = gl_in[gl_InvocationID].gl_CullDistance[i];\n";
1203 for (int i = 0; i < caseDef.numClipDistances; ++i)
1204 src << " gl_out[gl_InvocationID].gl_ClipDistance[" << i << "] = gl_in[gl_InvocationID].gl_ClipDistance[" << i << "];\n";
1205 for (int i = 0; i < caseDef.numCullDistances; ++i)
1206 src << " gl_out[gl_InvocationID].gl_CullDistance[" << i << "] = gl_in[gl_InvocationID].gl_CullDistance[" << i << "];\n";
1210 programCollection.glslSources.add("tesc") << glu::TessellationControlSource(src.str());
1213 if (caseDef.enableTessellation)
1215 DE_ASSERT(NUM_PATCH_CONTROL_POINTS == 3); // assumed in shader code
1217 std::ostringstream src;
1218 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1220 << "layout(triangles, equal_spacing, ccw) in;\n"
1222 << "layout(location = 0) in vec4 in_color[];\n"
1223 << "layout(location = 0) out vec4 out_color;\n"
1225 << "in " << perVertexBlock << " gl_in[gl_MaxPatchVertices];\n"
1227 << "out " << perVertexBlock << ";\n"
1229 << "void main (void)\n"
1231 << " vec3 px = gl_TessCoord.x * gl_in[0].gl_Position.xyz;\n"
1232 << " vec3 py = gl_TessCoord.y * gl_in[1].gl_Position.xyz;\n"
1233 << " vec3 pz = gl_TessCoord.z * gl_in[2].gl_Position.xyz;\n"
1234 << " gl_Position = vec4(px + py + pz, 1.0);\n"
1235 << " out_color = (in_color[0] + in_color[1] + in_color[2]) / 3.0;\n"
1237 if (caseDef.dynamicIndexing)
1239 if (caseDef.numClipDistances > 0)
1240 src << " for (int i = 0; i < " << caseDef.numClipDistances << "; ++i)\n"
1241 << " gl_ClipDistance[i] = gl_TessCoord.x * gl_in[0].gl_ClipDistance[i]\n"
1242 << " + gl_TessCoord.y * gl_in[1].gl_ClipDistance[i]\n"
1243 << " + gl_TessCoord.z * gl_in[2].gl_ClipDistance[i];\n";
1244 if (caseDef.numCullDistances > 0)
1245 src << " for (int i = 0; i < " << caseDef.numCullDistances << "; ++i)\n"
1246 << " gl_CullDistance[i] = gl_TessCoord.x * gl_in[0].gl_CullDistance[i]\n"
1247 << " + gl_TessCoord.y * gl_in[1].gl_CullDistance[i]\n"
1248 << " + gl_TessCoord.z * gl_in[2].gl_CullDistance[i];\n";
1252 for (int i = 0; i < caseDef.numClipDistances; ++i)
1253 src << " gl_ClipDistance[" << i << "] = gl_TessCoord.x * gl_in[0].gl_ClipDistance[" << i << "]\n"
1254 << " + gl_TessCoord.y * gl_in[1].gl_ClipDistance[" << i << "]\n"
1255 << " + gl_TessCoord.z * gl_in[2].gl_ClipDistance[" << i << "];\n";
1256 for (int i = 0; i < caseDef.numCullDistances; ++i)
1257 src << " gl_CullDistance[" << i << "] = gl_TessCoord.x * gl_in[0].gl_CullDistance[" << i << "]\n"
1258 << " + gl_TessCoord.y * gl_in[1].gl_CullDistance[" << i << "]\n"
1259 << " + gl_TessCoord.z * gl_in[2].gl_CullDistance[" << i << "];\n";
1263 programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(src.str());
1266 if (caseDef.enableGeometry)
1268 std::ostringstream src;
1269 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1271 << "layout(triangles) in;\n"
1272 << "layout(triangle_strip, max_vertices = 3) out;\n"
1274 << "layout(location = 0) in vec4 in_color[];\n"
1275 << "layout(location = 0) out vec4 out_color;\n"
1277 << "in " << perVertexBlock << " gl_in[];\n"
1279 << "out " << perVertexBlock << ";\n"
1281 << "void main (void)\n"
1283 for (int vertNdx = 0; vertNdx < 3; ++vertNdx)
1287 src << " gl_Position = gl_in[" << vertNdx << "].gl_Position;\n"
1288 << " out_color = in_color[" << vertNdx << "];\n";
1289 if (caseDef.dynamicIndexing)
1291 if (caseDef.numClipDistances > 0)
1292 src << " for (int i = 0; i < " << caseDef.numClipDistances << "; ++i)\n"
1293 << " gl_ClipDistance[i] = gl_in[" << vertNdx << "].gl_ClipDistance[i];\n";
1294 if (caseDef.numCullDistances > 0)
1295 src << " for (int i = 0; i < " << caseDef.numCullDistances << "; ++i)\n"
1296 << " gl_CullDistance[i] = gl_in[" << vertNdx << "].gl_CullDistance[i];\n";
1300 for (int i = 0; i < caseDef.numClipDistances; ++i)
1301 src << " gl_ClipDistance[" << i << "] = gl_in[" << vertNdx << "].gl_ClipDistance[" << i << "];\n";
1302 for (int i = 0; i < caseDef.numCullDistances; ++i)
1303 src << " gl_CullDistance[" << i << "] = gl_in[" << vertNdx << "].gl_CullDistance[" << i << "];\n";
1305 src << " EmitVertex();\n";
1309 programCollection.glslSources.add("geom") << glu::GeometrySource(src.str());
1314 std::ostringstream src;
1315 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1317 << "layout(location = 0) in flat vec4 in_color;\n"
1318 << "layout(location = 0) out vec4 o_color;\n"
1320 << "void main (void)\n"
1322 << " o_color = vec4(in_color.rgb + vec3(0.0, 0.0, 0.5), 1.0);\n" // mix with a constant color in case variable wasn't passed correctly through stages
1325 programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
1329 tcu::TestStatus testClipDistance (Context& context, const CaseDefinition caseDef)
1331 // Check test requirements
1333 const InstanceInterface& vki = context.getInstanceInterface();
1334 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
1335 const VkPhysicalDeviceLimits limits = getPhysicalDeviceProperties(vki, physDevice).limits;
1337 FeatureFlags requirements = (FeatureFlags)0;
1339 if (caseDef.numClipDistances > 0)
1340 requirements |= FEATURE_SHADER_CLIP_DISTANCE;
1341 if (caseDef.numCullDistances > 0)
1342 requirements |= FEATURE_SHADER_CULL_DISTANCE;
1343 if (caseDef.enableTessellation)
1344 requirements |= FEATURE_TESSELLATION_SHADER;
1345 if (caseDef.enableGeometry)
1346 requirements |= FEATURE_GEOMETRY_SHADER;
1348 requireFeatures(vki, physDevice, requirements);
1350 // Check limits for supported features
1352 if (caseDef.numClipDistances > 0 && limits.maxClipDistances < MAX_CLIP_DISTANCES)
1353 return tcu::TestStatus::fail("maxClipDistances smaller than the minimum required by the spec");
1354 if (caseDef.numCullDistances > 0 && limits.maxCullDistances < MAX_CULL_DISTANCES)
1355 return tcu::TestStatus::fail("maxCullDistances smaller than the minimum required by the spec");
1356 if (caseDef.numCullDistances > 0 && limits.maxCombinedClipAndCullDistances < MAX_COMBINED_CLIP_AND_CULL_DISTANCES)
1357 return tcu::TestStatus::fail("maxCombinedClipAndCullDistances smaller than the minimum required by the spec");
1360 std::vector<Shader> shaders;
1361 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
1362 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
1363 if (caseDef.enableTessellation)
1365 shaders.push_back(Shader(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, context.getBinaryCollection().get("tesc")));
1366 shaders.push_back(Shader(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, context.getBinaryCollection().get("tese")));
1368 if (caseDef.enableGeometry)
1369 shaders.push_back(Shader(VK_SHADER_STAGE_GEOMETRY_BIT, context.getBinaryCollection().get("geom")));
1371 const int numBars = MAX_COMBINED_CLIP_AND_CULL_DISTANCES;
1373 std::vector<Vec4> vertices;
1375 const float dx = 2.0f / numBars;
1376 for (int i = 0; i < numBars; ++i)
1378 const float x = -1.0f + dx * static_cast<float>(i);
1380 vertices.push_back(Vec4(x, -1.0f, 0.0f, 1.0f));
1381 vertices.push_back(Vec4(x, 1.0f, 0.0f, 1.0f));
1382 vertices.push_back(Vec4(x + dx, -1.0f, 0.0f, 1.0f));
1384 vertices.push_back(Vec4(x, 1.0f, 0.0f, 1.0f));
1385 vertices.push_back(Vec4(x + dx, 1.0f, 0.0f, 1.0f));
1386 vertices.push_back(Vec4(x + dx, -1.0f, 0.0f, 1.0f));
1390 tcu::TestLog& log = context.getTestContext().getLog();
1392 log << tcu::TestLog::Message << "Drawing " << numBars << " colored bars, clipping the first " << caseDef.numClipDistances << tcu::TestLog::EndMessage
1393 << tcu::TestLog::Message << "Using " << caseDef.numClipDistances << " ClipDistance(s) and " << caseDef.numCullDistances << " CullDistance(s)" << tcu::TestLog::EndMessage
1394 << tcu::TestLog::Message << "Expecting upper half of the clipped bars to be black." << tcu::TestLog::EndMessage;
1396 DrawContext drawContext(context, shaders, vertices, caseDef.topology);
1399 // Count black pixels in the whole image.
1400 const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
1401 const IVec2 clipRegion = IVec2(caseDef.numClipDistances * RENDER_SIZE / numBars, RENDER_SIZE / 2);
1402 const int expectedClippedPixels = clipRegion.x() * clipRegion.y();
1403 // Make sure the bottom half has no black pixels (possible if image became corrupted).
1404 const int guardPixels = countPixels(drawContext.getColorPixels(), IVec2(0, RENDER_SIZE/2), clipRegion, Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
1406 return (numBlackPixels == expectedClippedPixels && guardPixels == 0 ? tcu::TestStatus::pass("OK")
1407 : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
1410 } // ClipDistance ns
1412 namespace ClipDistanceComplementarity
1415 void initPrograms (SourceCollections& programCollection, const int numClipDistances)
1419 DE_ASSERT(numClipDistances > 0);
1420 const int clipDistanceLastNdx = numClipDistances - 1;
1422 std::ostringstream src;
1423 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1425 << "layout(location = 0) in vec4 v_position; // we are passing ClipDistance in w component\n"
1427 << "out gl_PerVertex {\n"
1428 << " vec4 gl_Position;\n"
1429 << " float gl_ClipDistance[" << numClipDistances << "];\n"
1432 << "void main (void)\n"
1434 << " gl_Position = vec4(v_position.xyz, 1.0);\n";
1435 for (int i = 0; i < clipDistanceLastNdx; ++i)
1436 src << " gl_ClipDistance[" << i << "] = 0.0;\n";
1437 src << " gl_ClipDistance[" << clipDistanceLastNdx << "] = v_position.w;\n"
1440 programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
1445 std::ostringstream src;
1446 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1448 << "layout(location = 0) out vec4 o_color;\n"
1450 << "void main (void)\n"
1452 << " o_color = vec4(1.0, 1.0, 1.0, 0.5);\n"
1455 programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
1459 tcu::TestStatus testComplementarity (Context& context, const int numClipDistances)
1461 // Check test requirements
1463 const InstanceInterface& vki = context.getInstanceInterface();
1464 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
1466 requireFeatures(vki, physDevice, FEATURE_SHADER_CLIP_DISTANCE);
1469 std::vector<Shader> shaders;
1470 shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT, context.getBinaryCollection().get("vert")));
1471 shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT, context.getBinaryCollection().get("frag")));
1473 std::vector<Vec4> vertices;
1475 de::Random rnd (1234);
1476 const int numSections = 16;
1477 const int numVerticesPerSection = 4; // logical verticies, due to triangle list topology we actually use 6 per section
1479 DE_ASSERT(RENDER_SIZE_LARGE % numSections == 0);
1481 std::vector<float> clipDistances(numVerticesPerSection * numSections);
1482 for (int i = 0; i < static_cast<int>(clipDistances.size()); ++i)
1483 clipDistances[i] = rnd.getFloat(-1.0f, 1.0f);
1485 // Two sets of identical primitives, but with a different ClipDistance sign.
1486 for (int setNdx = 0; setNdx < 2; ++setNdx)
1488 const float sign = (setNdx == 0 ? 1.0f : -1.0f);
1489 const float dx = 2.0f / static_cast<float>(numSections);
1491 for (int i = 0; i < numSections; ++i)
1493 const int ndxBase = numVerticesPerSection * i;
1494 const float x = -1.0f + dx * static_cast<float>(i);
1495 const Vec4 p0 = Vec4(x, -1.0f, 0.0f, sign * clipDistances[ndxBase + 0]);
1496 const Vec4 p1 = Vec4(x, 1.0f, 0.0f, sign * clipDistances[ndxBase + 1]);
1497 const Vec4 p2 = Vec4(x + dx, 1.0f, 0.0f, sign * clipDistances[ndxBase + 2]);
1498 const Vec4 p3 = Vec4(x + dx, -1.0f, 0.0f, sign * clipDistances[ndxBase + 3]);
1500 vertices.push_back(p0);
1501 vertices.push_back(p1);
1502 vertices.push_back(p2);
1504 vertices.push_back(p2);
1505 vertices.push_back(p3);
1506 vertices.push_back(p0);
1511 tcu::TestLog& log = context.getTestContext().getLog();
1513 log << tcu::TestLog::Message << "Draw two sets of primitives with blending, differing only with ClipDistance sign." << tcu::TestLog::EndMessage
1514 << tcu::TestLog::Message << "Using " << numClipDistances << " clipping plane(s), one of them possibly having negative values." << tcu::TestLog::EndMessage
1515 << tcu::TestLog::Message << "Expecting a uniform gray area, no missing (black) nor overlapped (white) pixels." << tcu::TestLog::EndMessage;
1517 DrawContext drawContext(context, shaders, vertices, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, static_cast<deUint32>(RENDER_SIZE_LARGE), false, true);
1520 const int numGrayPixels = countPixels(drawContext.getColorPixels(), Vec4(0.5f, 0.5f, 0.5f, 1.0f), Vec4(0.02f, 0.02f, 0.02f, 0.0f));
1521 const int numExpectedPixels = RENDER_SIZE_LARGE * RENDER_SIZE_LARGE;
1523 return (numGrayPixels == numExpectedPixels ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
1526 } // ClipDistanceComplementarity ns
1528 void addClippingTests (tcu::TestCaseGroup* clippingTestsGroup)
1530 tcu::TestContext& testCtx = clippingTestsGroup->getTestContext();
1532 // Clipping against the clip volume
1534 using namespace ClipVolume;
1536 static const VkPrimitiveTopology cases[] =
1538 VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
1539 VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
1540 VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY,
1541 VK_PRIMITIVE_TOPOLOGY_LINE_STRIP,
1542 VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY,
1543 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
1544 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY,
1545 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
1546 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY,
1547 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,
1550 MovePtr<tcu::TestCaseGroup> clipVolumeGroup(new tcu::TestCaseGroup(testCtx, "clip_volume", "clipping with the clip volume"));
1552 // Fully inside the clip volume
1554 MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "inside", ""));
1556 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1557 addFunctionCaseWithPrograms<VkPrimitiveTopology>(
1558 group.get(), getPrimitiveTopologyShortName(cases[caseNdx]), "", initPrograms, testPrimitivesInside, cases[caseNdx]);
1560 clipVolumeGroup->addChild(group.release());
1563 // Fully outside the clip volume
1565 MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "outside", ""));
1567 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1568 addFunctionCaseWithPrograms<VkPrimitiveTopology>(
1569 group.get(), getPrimitiveTopologyShortName(cases[caseNdx]), "", initPrograms, testPrimitivesOutside, cases[caseNdx]);
1571 clipVolumeGroup->addChild(group.release());
1576 MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "depth_clamp", ""));
1578 for (int caseNdx = 0; caseNdx < DE_LENGTH_OF_ARRAY(cases); ++caseNdx)
1579 addFunctionCaseWithPrograms<VkPrimitiveTopology>(
1580 group.get(), getPrimitiveTopologyShortName(cases[caseNdx]), "", initPrograms, testPrimitivesDepthClamp, cases[caseNdx]);
1582 clipVolumeGroup->addChild(group.release());
1585 // Large points and wide lines
1587 // \note For both points and lines, if an unsupported size/width is selected, the nearest supported size will be chosen.
1588 // We do have to check for feature support though.
1590 MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "clipped", ""));
1592 addFunctionCaseWithPrograms(group.get(), "large_points", "", initProgramsPointSize, testLargePoints);
1594 addFunctionCaseWithPrograms<LineOrientation>(group.get(), "wide_lines_axis_aligned", "", initPrograms, testWideLines, LINE_ORIENTATION_AXIS_ALIGNED);
1595 addFunctionCaseWithPrograms<LineOrientation>(group.get(), "wide_lines_diagonal", "", initPrograms, testWideLines, LINE_ORIENTATION_DIAGONAL);
1597 clipVolumeGroup->addChild(group.release());
1600 clippingTestsGroup->addChild(clipVolumeGroup.release());
1603 // User-defined clip planes
1605 MovePtr<tcu::TestCaseGroup> clipDistanceGroup(new tcu::TestCaseGroup(testCtx, "user_defined", "user-defined clip planes"));
1607 // ClipDistance, CullDistance and maxCombinedClipAndCullDistances usage
1609 using namespace ClipDistance;
1613 const char* const groupName;
1614 const char* const description;
1615 bool useCullDistance;
1618 { "clip_distance", "use ClipDistance", false },
1619 { "clip_cull_distance", "use ClipDistance and CullDistance at the same time", true },
1622 const deUint32 flagTessellation = 1u << 0;
1623 const deUint32 flagGeometry = 1u << 1;
1625 for (int groupNdx = 0; groupNdx < DE_LENGTH_OF_ARRAY(caseGroups); ++groupNdx)
1626 for (int indexingMode = 0; indexingMode < 2; ++indexingMode)
1628 const bool dynamicIndexing = (indexingMode == 1);
1629 const std::string mainGroupName = de::toString(caseGroups[groupNdx].groupName) + (dynamicIndexing ? "_dynamic_index" : "");
1631 MovePtr<tcu::TestCaseGroup> mainGroup(new tcu::TestCaseGroup(testCtx, mainGroupName.c_str(), ""));
1633 for (deUint32 shaderMask = 0u; shaderMask <= (flagTessellation | flagGeometry); ++shaderMask)
1635 const bool useTessellation = (shaderMask & flagTessellation) != 0;
1636 const bool useGeometry = (shaderMask & flagGeometry) != 0;
1637 const std::string shaderGroupName = std::string("vert") + (useTessellation ? "_tess" : "") + (useGeometry ? "_geom" : "");
1639 MovePtr<tcu::TestCaseGroup> shaderGroup(new tcu::TestCaseGroup(testCtx, shaderGroupName.c_str(), ""));
1641 for (int numClipPlanes = 1; numClipPlanes <= MAX_CLIP_DISTANCES; ++numClipPlanes)
1643 const int numCullPlanes = (caseGroups[groupNdx].useCullDistance
1644 ? std::min(static_cast<int>(MAX_CULL_DISTANCES), MAX_COMBINED_CLIP_AND_CULL_DISTANCES - numClipPlanes)
1646 const std::string caseName = de::toString(numClipPlanes) + (numCullPlanes > 0 ? "_" + de::toString(numCullPlanes) : "");
1647 const VkPrimitiveTopology topology = (useTessellation ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST : VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
1649 addFunctionCaseWithPrograms<CaseDefinition>(
1650 shaderGroup.get(), caseName, caseGroups[groupNdx].description, initPrograms, testClipDistance,
1651 CaseDefinition(topology, numClipPlanes, numCullPlanes, useTessellation, useGeometry, dynamicIndexing));
1653 mainGroup->addChild(shaderGroup.release());
1655 clipDistanceGroup->addChild(mainGroup.release());
1659 // Complementarity criterion (i.e. clipped and not clipped areas must add up to a complete primitive with no holes nor overlap)
1661 using namespace ClipDistanceComplementarity;
1663 MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "complementarity", ""));
1665 for (int numClipDistances = 1; numClipDistances <= MAX_CLIP_DISTANCES; ++numClipDistances)
1666 addFunctionCaseWithPrograms<int>(group.get(), de::toString(numClipDistances).c_str(), "", initPrograms, testComplementarity, numClipDistances);
1668 clippingTestsGroup->addChild(group.release());
1671 clippingTestsGroup->addChild(clipDistanceGroup.release());
1677 tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
1679 return createTestGroup(testCtx, "clipping", "Clipping tests", addClippingTests);