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,
40 const std::string& value);
41
42 VkGraphicsPipelineCreateInfo prepareSimpleGraphicsPipelineCI (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,
51 std::vector<VkDynamicState>& dynamicStates,
52 VkPipelineLayout pipelineLayout,
53 VkRenderPass renderPass);
54 VkComputePipelineCreateInfo prepareSimpleComputePipelineCI (const VkPipelineShaderStageCreateInfo& shaderStageCreateInfo,
55 VkPipelineLayout pipelineLayout);
56 VkRenderPassCreateInfo prepareSimpleRenderPassCI (VkFormat format,
57 VkAttachmentDescription& attachmentDescription,
58 VkAttachmentReference& attachmentReference,
59 VkSubpassDescription& subpassDescription);
60 VkFormat getRenderTargetFormat (const InstanceInterface& vk,
61 const VkPhysicalDevice& device);
62
63 std::size_t calculateGraphicsPipelineHash (const VkGraphicsPipelineCreateInfo& gpCI,
64 const std::map<deUint64,std::size_t>& objectHashes);
65 std::size_t calculateComputePipelineHash (const VkComputePipelineCreateInfo& cpCI,
66 const std::map<deUint64,std::size_t>& objectHashes);
67 std::size_t calculateSamplerYcbcrConversionHash (const VkSamplerYcbcrConversionCreateInfo& scCI,
68 const std::map<deUint64, std::size_t>& objectHashes);
69 std::size_t calculateSamplerHash (const VkSamplerCreateInfo& sCI,
70 const std::map<deUint64, std::size_t>& objectHashes);
71 std::size_t calculateDescriptorSetLayoutHash (const VkDescriptorSetLayoutCreateInfo& sCI,
72 const std::map<deUint64, std::size_t>& objectHashes);
73 std::size_t calculatePipelineLayoutHash (const VkPipelineLayoutCreateInfo& pCI,
74 const std::map<deUint64, std::size_t>& objectHashes);
75 std::size_t calculateShaderModuleHash (const VkShaderModuleCreateInfo& sCI,
76 const std::map<deUint64, std::size_t>& objectHashes);
77 std::size_t calculateRenderPassHash (const VkRenderPassCreateInfo& pCI,
78 const std::map<deUint64, std::size_t>& objectHashes);
79 std::size_t calculateRenderPass2Hash (const VkRenderPassCreateInfo2& pCI,
80 const std::map<deUint64, std::size_t>& objectHashes);
81
82 template <typename T, typename... Rest>
hash_combine(std::size_t & seed,T const & v)83 inline void hash_combine(std::size_t &seed, T const &v)
84 {
85 std::hash<T> hasher;
86 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
87 }
88
89 template <typename T, typename... Rest>
hash_combine(std::size_t & seed,T const & v,Rest &&...rest)90 inline void hash_combine(std::size_t &seed, T const &v, Rest &&... rest)
91 {
92 std::hash<T> hasher;
93 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
94 hash_combine(seed, rest...);
95 }
96
97 } // vk
98
99 #endif // CTS_USES_VULKANSC
100
101 #endif // _VKSAFETYCRITICALUTIL_HPP
102