1 /*
2 * Copyright (c) 2015-2021 The Khronos Group Inc.
3 * Copyright (c) 2015-2021 Valve Corporation
4 * Copyright (c) 2015-2021 LunarG, Inc.
5 * Copyright (c) 2015-2021 Google, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 * Author: Cody Northrop <cnorthrop@google.com>
21 * Author: Dave Houlton <daveh@lunarg.com>
22 * Author: Jeremy Kniager <jeremyk@lunarg.com>
23 * Author: Shannon McPherson <shannon@lunarg.com>
24 * Author: John Zulauf <jzulauf@lunarg.com>
25 */
26
27 #ifndef VKLAYERTEST_H
28 #define VKLAYERTEST_H
29
30 #ifdef ANDROID
31 #include "vulkan_wrapper.h"
32 #else
33 #include <vulkan/vulkan.h>
34 #endif
35
36 #if defined(ANDROID)
37 #include <android/log.h>
38 #if defined(VALIDATION_APK)
39 #include <android_native_app_glue.h>
40 #endif
41 #endif
42
43 #include "test_common.h"
44 #include "vk_format_utils.h"
45 #include "vkrenderframework.h"
46 #include "vk_typemap_helper.h"
47
48 #include <algorithm>
49 #include <cmath>
50 #include <functional>
51 #include <limits>
52 #include <memory>
53 #include <string>
54 #include <unordered_set>
55 #include <vector>
56
57 using std::string;
58 using std::vector;
59
60 //--------------------------------------------------------------------------------------
61 // Mesh and VertexFormat Data
62 //--------------------------------------------------------------------------------------
63
64 static const char kSkipPrefix[] = " TEST SKIPPED:";
65
66 // Static arrays helper
67 template <class ElementT, size_t array_size>
size(ElementT (&)[array_size])68 size_t size(ElementT (&)[array_size]) {
69 return array_size;
70 }
71
72 // Format search helper
73 VkFormat FindSupportedDepthOnlyFormat(VkPhysicalDevice phy);
74 VkFormat FindSupportedStencilOnlyFormat(VkPhysicalDevice phy);
75 VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy);
76
77 // Returns true if *any* requested features are available.
78 // Assumption is that the framework can successfully create an image as
79 // long as at least one of the feature bits is present (excepting VTX_BUF).
80 bool ImageFormatIsSupported(VkPhysicalDevice phy, VkFormat format, VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL,
81 VkFormatFeatureFlags features = ~VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
82
83 // Returns true if format and *all* requested features are available.
84 bool ImageFormatAndFeaturesSupported(VkPhysicalDevice phy, VkFormat format, VkImageTiling tiling, VkFormatFeatureFlags features);
85
86 // Returns true if format and *all* requested features are available.
87 bool ImageFormatAndFeaturesSupported(const VkInstance inst, const VkPhysicalDevice phy, const VkImageCreateInfo info,
88 const VkFormatFeatureFlags features);
89
90 // Returns true if format and *all* requested features are available.
91 bool BufferFormatAndFeaturesSupported(VkPhysicalDevice phy, VkFormat format, VkFormatFeatureFlags features);
92
93 // Helper for checking createRenderPass2 support and adding related extensions.
94 bool CheckCreateRenderPass2Support(VkRenderFramework *renderFramework, std::vector<const char *> &device_extension_names);
95
96 // Helper for checking timeline semaphore support and initializing
97 bool CheckTimelineSemaphoreSupportAndInitState(VkRenderFramework *renderFramework);
98
99 class VkExtensionLayerTest : public VkRenderFramework {
100 public:
101 void Init(VkPhysicalDeviceFeatures *features = nullptr, VkPhysicalDeviceFeatures2 *features2 = nullptr,
102 const VkCommandPoolCreateFlags flags = 0, void *instance_pnext = nullptr);
103 bool AddSurfaceInstanceExtension();
104 bool AddSwapchainDeviceExtension();
105 VkCommandBufferObj *CommandBuffer();
106
107 bool CheckSynchronization2SupportAndInitState();
108
109 protected:
110 uint32_t m_instance_api_version = 0;
111 uint32_t m_target_api_version = 0;
112 bool m_enableWSI;
113
114 uint32_t SetTargetApiVersion(uint32_t target_api_version);
115 uint32_t DeviceValidationVersion();
116 VkExtensionLayerTest();
117 };
118
119 struct DebugUtilsLabelCheckData {
120 std::function<void(const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, DebugUtilsLabelCheckData *)> callback;
121 size_t count;
122 };
123
124 bool operator==(const VkDebugUtilsLabelEXT &rhs, const VkDebugUtilsLabelEXT &lhs);
125
126 VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
127 VkDebugUtilsMessageTypeFlagsEXT messageTypes,
128 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
129 #endif // VKLAYERTEST_H
130