Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_layer.h « layer « framework « tests - github.com/KhronosGroup/Vulkan-Loader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d3571b431452b19e03fbab0bc90be2c3dca353a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (c) 2021-2022 The Khronos Group Inc.
 * Copyright (c) 2021-2022 Valve Corporation
 * Copyright (c) 2021-2022 LunarG, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and/or associated documentation files (the "Materials"), to
 * deal in the Materials without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Materials, and to permit persons to whom the Materials are
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice(s) and this permission notice shall be included in
 * all copies or substantial portions of the Materials.
 *
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
 * USE OR OTHER DEALINGS IN THE MATERIALS.
 *
 * Author: Charles Giessen <charles@lunarg.com>
 */

#pragma once

#include "test_util.h"

#include "layer/layer_util.h"

#include "loader/generated/vk_layer_dispatch_table.h"

/*
Interface Version 0
*/

/*
must export the following: -- always exported
vkEnumerateInstanceLayerProperties
vkEnumerateInstanceExtensionProperties
Must export the following but nothing -- always exported
vkEnumerateDeviceLayerProperties
vkEnumerateDeviceExtensionProperties
*/

// export test_layer_GetInstanceProcAddr(instance, pName)
// TEST_LAYER_EXPORT_LAYER_NAMED_GIPA
// or (single layer binary)
// export vkGetInstanceProcAddr
// TEST_LAYER_EXPORT_NO_NAME_GIPA

// export test_layer_GetDeviceProcAddr(device, pName)
// TEST_LAYER_EXPORT_LAYER_NAMED_GDPA
// or (single layer binary)
// export vkGetDeviceProcAddr
// TEST_LAYER_EXPORT_NO_NAME_GDPA

/*
Interface Version 1
*/
// export GetInstanceProcAddr
// TEST_LAYER_EXPORT_NO_PREFIX_GIPA

// export GetDeviceProcAddr
// TEST_LAYER_EXPORT_NO_PREFIX_GDPA

// Layer Manifest can override the names of the GetInstanceProcAddr and GetDeviceProcAddrfunctions

/*
Interface Version 2
*/
// export vk_layerGetPhysicalDeviceProcAddr
// TEST_LAYER_EXPORT_GET_PHYSICAL_DEVICE_PROC_ADDR

// export vkNegotiateLoaderLayerInterfaceVersion
// TEST_LAYER_EXPORT_NEGOTIATE_LOADER_LAYER_INTERFACE_VERSION

// Added manifest version 1.1.0

struct TestLayer;

// Callbacks allow tests to implement custom functionality without modifying the layer binary
// TestLayer* layer - Access to the TestLayer object itself
// void* data - pointer to test specific thing, used to pass data from the test into the TestLayer
// Returns VkResult - This value will be used as the return value of the function
using FP_layer_callback = VkResult (*)(TestLayer& layer, void* data);

struct TestLayer {
    fs::path manifest_file_path;
    uint32_t manifest_version = VK_MAKE_API_VERSION(0, 1, 1, 2);

    BUILDER_VALUE(TestLayer, bool, is_meta_layer, false)

    BUILDER_VALUE(TestLayer, uint32_t, api_version, VK_API_VERSION_1_0)
    BUILDER_VALUE(TestLayer, uint32_t, reported_layer_props, 1)
    BUILDER_VALUE(TestLayer, uint32_t, reported_extension_props, 0)
    BUILDER_VALUE(TestLayer, uint32_t, reported_instance_version, VK_API_VERSION_1_0)
    BUILDER_VALUE(TestLayer, uint32_t, implementation_version, 2)
    BUILDER_VALUE(TestLayer, uint32_t, min_implementation_version, 0)
    BUILDER_VALUE(TestLayer, std::string, description, {})

    BUILDER_VECTOR(TestLayer, std::string, alternative_function_names, alternative_function_name)

    BUILDER_VECTOR(TestLayer, Extension, instance_extensions, instance_extension)
    BUILDER_VECTOR(TestLayer, Extension, device_extensions, device_extension)

    BUILDER_VALUE(TestLayer, std::string, enable_environment, {});
    BUILDER_VALUE(TestLayer, std::string, disable_environment, {});

    BUILDER_VECTOR(TestLayer, LayerDefinition, meta_component_layers, meta_component_layer);

    BUILDER_VALUE(TestLayer, bool, intercept_vkEnumerateInstanceExtensionProperties, false)
    BUILDER_VALUE(TestLayer, bool, intercept_vkEnumerateInstanceLayerProperties, false)
    // Called in vkCreateInstance after calling down the chain & returning
    BUILDER_VALUE(TestLayer, std::function<VkResult(TestLayer& layer)>, create_instance_callback, {})
    // Called in vkCreateDevice after calling down the chain & returning
    BUILDER_VALUE(TestLayer, std::function<VkResult(TestLayer& layer)>, create_device_callback, {})

    // Physical device modifier test flags and members.  This data is primarily used to test adding, removing and
    // re-ordering physical device data in a layer.
    BUILDER_VALUE(TestLayer, bool, add_phys_devs, false)
    BUILDER_VALUE(TestLayer, bool, remove_phys_devs, false)
    BUILDER_VALUE(TestLayer, bool, reorder_phys_devs, false)
    BUILDER_VECTOR(TestLayer, VkPhysicalDevice, complete_physical_devices, complete_physical_device)
    BUILDER_VECTOR(TestLayer, VkPhysicalDevice, removed_physical_devices, removed_physical_device)
    BUILDER_VECTOR(TestLayer, VkPhysicalDevice, added_physical_devices, added_physical_device)
    BUILDER_VECTOR(TestLayer, VkPhysicalDeviceGroupProperties, complete_physical_device_groups, complete_physical_device_group)
    BUILDER_VECTOR(TestLayer, VkPhysicalDeviceGroupProperties, removed_physical_device_groups, removed_physical_device_group)
    BUILDER_VECTOR(TestLayer, VkPhysicalDeviceGroupProperties, added_physical_device_groups, added_physical_device_group)

    BUILDER_VECTOR(TestLayer, VulkanFunction, custom_physical_device_implementation_functions,
                   custom_physical_device_implementation_function)
    BUILDER_VECTOR(TestLayer, VulkanFunction, custom_device_implementation_functions, custom_device_implementation_function)

    // Only need a single map for all 'custom' function - assumes that all function names are distinct, IE there cannot be a
    // physical device and device level function with the same name
    std::unordered_map<std::string, PFN_vkVoidFunction> custom_dispatch_functions;
    std::vector<VulkanFunction> custom_physical_device_interception_functions;
    TestLayer& add_custom_physical_device_intercept_function(std::string func_name, PFN_vkVoidFunction function) {
        custom_physical_device_interception_functions.push_back({func_name, function});
        custom_dispatch_functions[func_name] = nullptr;
        return *this;
    }
    std::vector<VulkanFunction> custom_device_interception_functions;
    TestLayer& add_custom_device_interception_function(std::string func_name, PFN_vkVoidFunction function) {
        custom_device_interception_functions.push_back({func_name, function});
        custom_dispatch_functions[func_name] = nullptr;
        return *this;
    }
    PFN_vkVoidFunction get_custom_intercept_function(const char* name) {
        if (custom_dispatch_functions.count(name) > 0) {
            return custom_dispatch_functions.at(name);
        }
        return nullptr;
    }

    BUILDER_VALUE(TestLayer, bool, do_spurious_allocations_in_create_instance, false)
    void* spurious_instance_memory_allocation = nullptr;
    BUILDER_VALUE(TestLayer, bool, do_spurious_allocations_in_create_device, false)
    struct DeviceMemAlloc {
        void* allocation;
        VkDevice device;
    };
    std::vector<DeviceMemAlloc> spurious_device_memory_allocations;

    // By default query GPDPA from GIPA, don't use value given from pNext
    BUILDER_VALUE(TestLayer, bool, use_gipa_GetPhysicalDeviceProcAddr, true)

    PFN_vkGetInstanceProcAddr next_vkGetInstanceProcAddr = VK_NULL_HANDLE;
    PFN_GetPhysicalDeviceProcAddr next_GetPhysicalDeviceProcAddr = VK_NULL_HANDLE;
    PFN_vkGetDeviceProcAddr next_vkGetDeviceProcAddr = VK_NULL_HANDLE;

    VkInstance instance_handle = VK_NULL_HANDLE;
    VkLayerInstanceDispatchTable instance_dispatch_table{};

    struct Device {
        VkDevice device_handle = VK_NULL_HANDLE;
        VkLayerDispatchTable dispatch_table{};
    };
    std::vector<Device> created_devices;
};

using GetTestLayerFunc = TestLayer* (*)();
#define GET_TEST_LAYER_FUNC_STR "get_test_layer_func"

using GetNewTestLayerFunc = TestLayer* (*)();
#define RESET_LAYER_FUNC_STR "reset_layer_func"