1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 The Khronos Group Inc.
6 * Copyright (c) 2018 Danylo Piliaiev <danylo.piliaiev@gmail.com>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 *//*!
21 * \file
22 * \brief Conditional Rendering Test Utils
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktConditionalRenderingTestUtil.hpp"
26 #include "vktDrawCreateInfoUtil.hpp"
27 #include "vkQueryUtil.hpp"
28
29 namespace vkt
30 {
31 namespace conditional
32 {
33
checkConditionalRenderingCapabilities(vkt::Context & context,const ConditionalData & data)34 void checkConditionalRenderingCapabilities (vkt::Context& context, const ConditionalData& data)
35 {
36 if (!vk::isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_EXT_conditional_rendering"))
37 TCU_THROW(NotSupportedError, "Missing extension: VK_EXT_conditional_rendering");
38
39 if (data.useSecondaryBuffer)
40 {
41 const vk::VkPhysicalDeviceConditionalRenderingFeaturesEXT& conditionalRenderingFeatures = context.getConditionalRenderingFeatures();
42 if (!conditionalRenderingFeatures.inheritedConditionalRendering)
43 {
44 TCU_THROW(NotSupportedError, "Device does not support inherited conditional rendering");
45 }
46 }
47 }
48
createConditionalRenderingBuffer(vkt::Context & context,const ConditionalData & data)49 de::SharedPtr<Draw::Buffer> createConditionalRenderingBuffer (vkt::Context& context, const ConditionalData& data)
50 {
51 const vk::DeviceInterface& vk = context.getDeviceInterface();
52 de::SharedPtr<Draw::Buffer> buffer = Draw::Buffer::createAndAlloc(vk, context.getDevice(),
53 Draw::BufferCreateInfo(sizeof(deUint32),
54 vk::VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT),
55 context.getDefaultAllocator(),
56 vk::MemoryRequirement::HostVisible);
57
58 deUint8* conditionBufferPtr = reinterpret_cast<deUint8*>(buffer->getBoundMemory().getHostPtr());
59 *(deUint32*)(conditionBufferPtr) = data.conditionValue;
60
61 vk::flushMappedMemoryRange( vk,
62 context.getDevice(),
63 buffer->getBoundMemory().getMemory(),
64 buffer->getBoundMemory().getOffset(),
65 VK_WHOLE_SIZE);
66 return buffer;
67 }
68
beginConditionalRendering(const vk::DeviceInterface & vk,vk::VkCommandBuffer cmdBuffer,Draw::Buffer & buffer,const ConditionalData & data)69 void beginConditionalRendering (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, Draw::Buffer& buffer, const ConditionalData& data)
70 {
71 vk::VkConditionalRenderingBeginInfoEXT conditionalRenderingBeginInfo;
72 conditionalRenderingBeginInfo.sType = vk::VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT;
73 conditionalRenderingBeginInfo.pNext = DE_NULL;
74 conditionalRenderingBeginInfo.buffer = buffer.object();
75 conditionalRenderingBeginInfo.offset = 0;
76 conditionalRenderingBeginInfo.flags = data.conditionInverted ? vk::VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT : 0;
77
78 vk.cmdBeginConditionalRenderingEXT(cmdBuffer, &conditionalRenderingBeginInfo);
79 }
80
operator <<(std::ostream & str,ConditionalData const & c)81 std::ostream& operator<< (std::ostream& str, ConditionalData const& c)
82 {
83 str << (c.conditionEnabled ? "condition" : "no_condition");
84
85 if (c.useSecondaryBuffer)
86 {
87 str << "_secondary_buffer";
88 }
89
90 str << "_" << (c.expectCommandExecution ? "expect_execution" : "expect_noop");
91
92 if (c.conditionInverted)
93 {
94 str << "_inverted";
95 }
96
97 return str;
98 }
99
100 } // conditional
101 } // vkt