1 #ifndef _VKSAFETYCRITICALUTIL_HPP
2 #define _VKSAFETYCRITICALUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan CTS Framework
5 * --------------------
6 *
7 * Copyright (c) 2021 The Khronos Group Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Vulkan SC utilities
24 *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include <map>
28 #include <vector>
29 #include <functional>
30
31 #ifdef CTS_USES_VULKANSC
32
33 namespace vk
34 {
35
36 VkDeviceObjectReservationCreateInfo resetDeviceObjectReservationCreateInfo();
37 VkPipelineOfflineCreateInfo resetPipelineOfflineCreateInfo();
38 VkPhysicalDeviceVulkanSC10Features createDefaultSC10Features();
39 void applyPipelineIdentifier(VkPipelineOfflineCreateInfo &pipelineIdentifier, const std::string &value);
40
41 VkGraphicsPipelineCreateInfo prepareSimpleGraphicsPipelineCI(
42 VkPipelineVertexInputStateCreateInfo &vertexInputStateCreateInfo,
43 std::vector<VkPipelineShaderStageCreateInfo> &shaderStageCreateInfos,
44 VkPipelineInputAssemblyStateCreateInfo &inputAssemblyStateCreateInfo,
45 VkPipelineViewportStateCreateInfo &viewPortStateCreateInfo,
46 VkPipelineRasterizationStateCreateInfo &rasterizationStateCreateInfo,
47 VkPipelineMultisampleStateCreateInfo &multisampleStateCreateInfo,
48 VkPipelineColorBlendAttachmentState &colorBlendAttachmentState,
49 VkPipelineColorBlendStateCreateInfo &colorBlendStateCreateInfo,
50 VkPipelineDynamicStateCreateInfo &dynamicStateCreateInfo, std::vector<VkDynamicState> &dynamicStates,
51 VkPipelineLayout pipelineLayout, VkRenderPass renderPass);
52 VkComputePipelineCreateInfo prepareSimpleComputePipelineCI(const VkPipelineShaderStageCreateInfo &shaderStageCreateInfo,
53 VkPipelineLayout pipelineLayout);
54 VkRenderPassCreateInfo prepareSimpleRenderPassCI(VkFormat format, VkAttachmentDescription &attachmentDescription,
55 VkAttachmentReference &attachmentReference,
56 VkSubpassDescription &subpassDescription);
57 VkFormat getRenderTargetFormat(const InstanceInterface &vk, const VkPhysicalDevice &device);
58
59 std::size_t calculateGraphicsPipelineHash(const VkGraphicsPipelineCreateInfo &gpCI,
60 const std::map<uint64_t, std::size_t> &objectHashes);
61 std::size_t calculateComputePipelineHash(const VkComputePipelineCreateInfo &cpCI,
62 const std::map<uint64_t, std::size_t> &objectHashes);
63 std::size_t calculateSamplerYcbcrConversionHash(const VkSamplerYcbcrConversionCreateInfo &scCI,
64 const std::map<uint64_t, std::size_t> &objectHashes);
65 std::size_t calculateSamplerHash(const VkSamplerCreateInfo &sCI, const std::map<uint64_t, std::size_t> &objectHashes);
66 std::size_t calculateDescriptorSetLayoutHash(const VkDescriptorSetLayoutCreateInfo &sCI,
67 const std::map<uint64_t, std::size_t> &objectHashes);
68 std::size_t calculatePipelineLayoutHash(const VkPipelineLayoutCreateInfo &pCI,
69 const std::map<uint64_t, std::size_t> &objectHashes);
70 std::size_t calculateShaderModuleHash(const VkShaderModuleCreateInfo &sCI,
71 const std::map<uint64_t, std::size_t> &objectHashes);
72 std::size_t calculateRenderPassHash(const VkRenderPassCreateInfo &pCI,
73 const std::map<uint64_t, std::size_t> &objectHashes);
74 std::size_t calculateRenderPass2Hash(const VkRenderPassCreateInfo2 &pCI,
75 const std::map<uint64_t, std::size_t> &objectHashes);
76
77 template <typename T, typename... Rest>
hash_combine(std::size_t & seed,T const & v)78 inline void hash_combine(std::size_t &seed, T const &v)
79 {
80 std::hash<T> hasher;
81 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
82 }
83
84 template <typename T, typename... Rest>
hash_combine(std::size_t & seed,T const & v,Rest &&...rest)85 inline void hash_combine(std::size_t &seed, T const &v, Rest &&...rest)
86 {
87 std::hash<T> hasher;
88 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
89 hash_combine(seed, rest...);
90 }
91
92 } // namespace vk
93
94 #endif // CTS_USES_VULKANSC
95
96 #endif // _VKSAFETYCRITICALUTIL_HPP
97