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 context.requireDeviceFunctionality("VK_EXT_conditional_rendering");
37
38 const auto& conditionalRenderingFeatures = context.getConditionalRenderingFeaturesEXT();
39
40 if (conditionalRenderingFeatures.conditionalRendering == VK_FALSE)
41 TCU_FAIL("conditionalRendering feature not supported but VK_EXT_conditional_rendering present");
42
43 if (data.conditionInherited && !conditionalRenderingFeatures.inheritedConditionalRendering)
44 TCU_THROW(NotSupportedError, "Device does not support inherited conditional rendering");
45 }
46
createConditionalRenderingBuffer(vkt::Context & context,const ConditionalData & data)47 de::SharedPtr<Draw::Buffer> createConditionalRenderingBuffer (vkt::Context& context, const ConditionalData& data)
48 {
49 // When padding the condition value, it will be surounded by two additional values with nonzero bytes in them.
50 const auto bufferSize = static_cast<vk::VkDeviceSize>(sizeof(data.conditionValue)) * (data.padConditionValue ? 3ull : 1ull);
51 const auto dataOffset = static_cast<vk::VkDeviceSize>(data.padConditionValue ? sizeof(data.conditionValue) : 0);
52 const vk::DeviceInterface& vk = context.getDeviceInterface();
53 de::SharedPtr<Draw::Buffer> buffer = Draw::Buffer::createAndAlloc(vk, context.getDevice(),
54 Draw::BufferCreateInfo(bufferSize,
55 vk::VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT),
56 context.getDefaultAllocator(),
57 vk::MemoryRequirement::HostVisible);
58
59 deUint8* conditionBufferPtr = reinterpret_cast<deUint8*>(buffer->getBoundMemory().getHostPtr()) + buffer->getBoundMemory().getOffset();
60 deMemset(conditionBufferPtr, 1, static_cast<size_t>(bufferSize));
61 deMemcpy(conditionBufferPtr + dataOffset, &data.conditionValue, sizeof(data.conditionValue));
62
63 vk::flushMappedMemoryRange( vk,
64 context.getDevice(),
65 buffer->getBoundMemory().getMemory(),
66 buffer->getBoundMemory().getOffset(),
67 VK_WHOLE_SIZE);
68 return buffer;
69 }
70
beginConditionalRendering(const vk::DeviceInterface & vk,vk::VkCommandBuffer cmdBuffer,Draw::Buffer & buffer,const ConditionalData & data)71 void beginConditionalRendering (const vk::DeviceInterface& vk, vk::VkCommandBuffer cmdBuffer, Draw::Buffer& buffer, const ConditionalData& data)
72 {
73 vk::VkConditionalRenderingBeginInfoEXT conditionalRenderingBeginInfo;
74 conditionalRenderingBeginInfo.sType = vk::VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT;
75 conditionalRenderingBeginInfo.pNext = nullptr;
76 conditionalRenderingBeginInfo.buffer = buffer.object();
77 conditionalRenderingBeginInfo.offset = static_cast<vk::VkDeviceSize>(data.padConditionValue ? sizeof(data.conditionValue) : 0u);
78 conditionalRenderingBeginInfo.flags = data.conditionInverted ? vk::VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT : 0;
79
80 vk.cmdBeginConditionalRenderingEXT(cmdBuffer, &conditionalRenderingBeginInfo);
81 }
82
operator <<(std::ostream & str,ConditionalData const & c)83 std::ostream& operator<< (std::ostream& str, ConditionalData const& c)
84 {
85 const bool conditionEnabled = c.conditionInPrimaryCommandBuffer || c.conditionInSecondaryCommandBuffer;
86 str << (conditionEnabled ? "condition" : "no_condition");
87
88 if (c.conditionInSecondaryCommandBuffer || !conditionEnabled)
89 {
90 str << "_secondary_buffer";
91 }
92
93 if (c.conditionInherited)
94 {
95 str << "_inherited";
96 }
97
98 str << "_" << (c.expectCommandExecution ? "expect_execution" : "expect_noop");
99
100 if (c.conditionInverted)
101 {
102 str << "_inverted";
103 }
104
105 if (c.padConditionValue)
106 {
107 str << "_padded";
108 }
109
110 return str;
111 }
112
113 } // conditional
114 } // vkt
115