• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTDGCUTILCOMMON_HPP
2 #define _VKTDGCUTILCOMMON_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2024 The Khronos Group Inc.
8  * Copyright (c) 2024 Valve Corporation.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Device Generated Commands Common (NV and EXT) Utility Code
25  *//*--------------------------------------------------------------------*/
26 #include "vkDefs.hpp"
27 #include "deMemory.h"
28 
29 #include <vector>
30 
31 namespace vkt
32 {
33 namespace DGC
34 {
35 
36 // Returns true if the two memory requirements structures are equal.
37 bool equalMemoryRequirements(const vk::VkMemoryRequirements &, const vk::VkMemoryRequirements &);
38 
39 // Push back an element of any type onto an std::vector (of uint8_t, uint32_t, etc).
40 // This is helpful to push items into a pseudobuffer that should contain DGC data.
41 template <typename T, typename K>
pushBackElement(std::vector<T> & out,const K & element)42 void pushBackElement(std::vector<T> &out, const K &element)
43 {
44     constexpr auto vecItemSize = sizeof(T);
45     constexpr auto elementSize = sizeof(K);
46     constexpr auto neededItems = (elementSize + vecItemSize - 1u) / vecItemSize;
47 
48     DE_ASSERT(neededItems > 0u);
49     const auto prevSize = out.size();
50     out.resize(prevSize + neededItems);
51     const auto basePtr = &out.at(prevSize); // Important to take this after resizing, not before.
52     deMemcpy(basePtr, &element, sizeof(element));
53 };
54 
55 } // namespace DGC
56 } // namespace vkt
57 
58 #endif // _VKTDGCUTILCOMMON_HPP
59