COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/run_all_tests.sh
COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/run_wrap_objects_tests.sh
COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/run_loader_tests.sh
+ COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/run_extra_loader_tests.sh
COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/vkvalidatelayerdoc.sh
VERBATIM
)
set(LAYER_JSON_FILES
VkLayer_wrap_objects
+ VkLayer_test
)
set(VK_LAYER_RPATH /usr/lib/x86_64-linux-gnu/vulkan/layer:/usr/lib/i386-linux-gnu/vulkan/layer)
)
add_vk_layer(wrap_objects ${WRAP_SRCS})
+set (TEST_SRCS
+ test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../layers/vk_layer_table.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../layers/vk_layer_extension_utils.cpp
+ )
+add_vk_layer(test ${TEST_SRCS})
+
--- /dev/null
+{
+ "file_format_version" : "1.0.0",
+ "layer" : {
+ "name": "VK_LAYER_LUNARG_test",
+ "type": "GLOBAL",
+ "library_path": "./libVkLayer_test.so",
+ "api_version": "1.0.11",
+ "implementation_version": "1",
+ "description": "LunarG Test Layer",
+ "enable_environment": {
+ "ENABLE_LAYER_TEST_1": "enable"
+ },
+ "disable_environment": {
+ "DISABLE_LAYER_TEST_1": ""
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015-2016 Valve Corporation
+ * Copyright (c) 2015-2016 LunarG, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: Jeremy Hayes <jeremy@lunarg.com>
+ */
+
+#include <cassert>
+#include <iostream>
+#include <unordered_map>
+
+#include "vk_dispatch_table_helper.h"
+#include "vk_layer_data.h"
+#include "vk_layer_extension_utils.h"
+
+namespace test
+{
+
+struct layer_data {
+ VkInstance instance;
+ VkLayerInstanceDispatchTable *instance_dispatch_table;
+
+ layer_data() : instance(VK_NULL_HANDLE), instance_dispatch_table(nullptr) {};
+};
+
+static std::unordered_map<void *, layer_data *> layer_data_map;
+
+VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
+ VkInstance* pInstance)
+{
+ VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
+ assert(chain_info != nullptr);
+
+ assert(chain_info->u.pLayerInfo != nullptr);
+ PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
+ assert(fpGetInstanceProcAddr != nullptr);
+
+ PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
+ if (fpCreateInstance == nullptr)
+ {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
+ VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
+ if (result != VK_SUCCESS)
+ {
+ return result;
+ }
+
+ layer_data *instance_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
+ instance_data->instance = *pInstance;
+ instance_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
+ layer_init_instance_dispatch_table(*pInstance, instance_data->instance_dispatch_table, fpGetInstanceProcAddr);
+
+ // Marker for testing.
+ std::cout << "VK_LAYER_LUNARG_test: CreateInstance" << '\n';
+
+ return result;
+}
+
+VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator)
+{
+ dispatch_key key = get_dispatch_key(instance);
+ layer_data *instance_data = get_my_data_ptr(key, layer_data_map);
+ instance_data->instance_dispatch_table->DestroyInstance(instance, pAllocator);
+
+ delete instance_data->instance_dispatch_table;
+ layer_data_map.erase(key);
+
+ // Marker for testing.
+ std::cout << "VK_LAYER_LUNARG_test: DestroyInstance" << '\n';
+}
+
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char* funcName)
+{
+ // Return the functions that are intercepted by this layer.
+ static const struct
+ {
+ const char *name;
+ PFN_vkVoidFunction proc;
+ } core_instance_commands[] =
+ {
+ { "vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr) },
+ { "vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance) },
+ { "vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance) }
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++)
+ {
+ if (!strcmp(core_instance_commands[i].name, funcName))
+ {
+ return core_instance_commands[i].proc;
+ }
+ }
+
+ // Only call down the chain for Vulkan commands that this layer does not intercept.
+ layer_data *instance_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
+ VkLayerInstanceDispatchTable *pTable = instance_data->instance_dispatch_table;
+ if (pTable->GetInstanceProcAddr == nullptr)
+ {
+ return nullptr;
+ }
+
+ return pTable->GetInstanceProcAddr(instance, funcName);
+}
+
+}
+
+VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
+{
+ return test::GetInstanceProcAddr(instance, funcName);
+}
+
+VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName)
+{
+ return nullptr;
+}
+
+VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties)
+{
+ return VK_ERROR_LAYER_NOT_PRESENT;
+}
+
+VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties)
+{
+ return VK_ERROR_LAYER_NOT_PRESENT;
+}
--- /dev/null
+{
+ "file_format_version" : "1.0.0",
+ "layer" : {
+ "name": "VK_LAYER_LUNARG_test",
+ "type": "GLOBAL",
+ "library_path": ".\\libVkLayer_test.dll",
+ "api_version": "1.0.11",
+ "implementation_version": "1",
+ "description": "LunarG Test Layer",
+ "enable_environment": {
+ "ENABLE_LAYER_TEST_1": "enable"
+ },
+ "disable_environment": {
+ "DISABLE_LAYER_TEST_1": ""
+ }
+ }
+}
struct EnumerateInstanceLayerProperties : public CommandLine {};
struct EnumerateInstanceExtensionProperties : public CommandLine {};
+struct ImplicitLayer : public CommandLine {};
// Test groups:
// LX = lunar exchange
vkDestroyInstance(instance, nullptr);
}
+TEST(EnumerateDeviceLayerProperties, CreateInstanceWithoutLayers)
+{
+ VkInstance instance = VK_NULL_HANDLE;
+ VkResult result = vkCreateInstance(VK::InstanceCreateInfo(), VK_NULL_HANDLE, &instance);
+ ASSERT_EQ(result, VK_SUCCESS);
+
+ uint32_t physicalCount = 0;
+ result = vkEnumeratePhysicalDevices(instance, &physicalCount, nullptr);
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_GT(physicalCount, 0u);
+
+ std::unique_ptr<VkPhysicalDevice[]> physical(new VkPhysicalDevice[physicalCount]);
+ result = vkEnumeratePhysicalDevices(instance, &physicalCount, physical.get());
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_GT(physicalCount, 0u);
+
+ for(uint32_t p = 0; p < physicalCount; ++p)
+ {
+ uint32_t count = 0u;
+ result = vkEnumerateDeviceLayerProperties(physical[p], &count, nullptr);
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_EQ(count, 0u);
+ }
+
+ vkDestroyInstance(instance, nullptr);
+}
+
+TEST(EnumerateDeviceLayerProperties, CreateInstanceWithLayer)
+{
+ char const*const names[] = {"VK_LAYER_LUNARG_core_validation"}; // Temporary required due to MSVC bug.
+ auto const info = VK::InstanceCreateInfo().
+ enabledLayerCount(1).
+ ppEnabledLayerNames(names);
+
+ VkInstance instance = VK_NULL_HANDLE;
+ VkResult result = vkCreateInstance(info, VK_NULL_HANDLE, &instance);
+ ASSERT_EQ(result, VK_SUCCESS);
+
+ uint32_t physicalCount = 0;
+ result = vkEnumeratePhysicalDevices(instance, &physicalCount, nullptr);
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_GT(physicalCount, 0u);
+
+ std::unique_ptr<VkPhysicalDevice[]> physical(new VkPhysicalDevice[physicalCount]);
+ result = vkEnumeratePhysicalDevices(instance, &physicalCount, physical.get());
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_GT(physicalCount, 0u);
+
+ for(uint32_t p = 0; p < physicalCount; ++p)
+ {
+ uint32_t count = 0u;
+ result = vkEnumerateDeviceLayerProperties(physical[p], &count, nullptr);
+ ASSERT_EQ(result, VK_SUCCESS);
+ ASSERT_EQ(count, 1u);
+ }
+
+ vkDestroyInstance(instance, nullptr);
+}
+
TEST_F(EnumerateInstanceLayerProperties, Count)
{
uint32_t count = 0u;
vkDestroyInstance(instance, nullptr);
}
+TEST_F(ImplicitLayer, Present)
+{
+ auto const info = VK::InstanceCreateInfo();
+ VkInstance instance = VK_NULL_HANDLE;
+ VkResult result = vkCreateInstance(info, VK_NULL_HANDLE, &instance);
+ ASSERT_EQ(result, VK_SUCCESS);
+
+ vkDestroyInstance(instance, nullptr);
+}
+
TEST(WrapObjects, Insert)
{
VkInstance instance = VK_NULL_HANDLE;
--- /dev/null
+#!/bin/bash
+
+pushd $(dirname "$0") > /dev/null
+
+RunImplicitLayerTest()
+{
+ # Check for local implicit directory.
+ : "${HOME:?}"
+ local implicitDirectory="$HOME/.local/share/vulkan/implicit_layer.d"
+ if [ ! -d "$implicitDirectory" ]
+ then
+ mkdir -p "$implicitDirectory"
+ fi
+
+ # Check for the shared object.
+ local sharedObject="libVkLayer_test.so"
+ local layerDirectory="./layers"
+ if [ ! -f "$layerDirectory/$sharedObject" ]
+ then
+ echo "The file, $layerDirectory/$sharedObject, can not be found." >&2
+ return 1
+ fi
+
+ # Check for the json which does not include the optional enable environment variable.
+ local json="VkLayer_test.json"
+ if [ ! -f "$layerDirectory/$json" ]
+ then
+ echo "The file, $layerDirectory/$json, can not be found." >&2
+ return 1
+ fi
+
+ # Copy the test layer into the implicit directory.
+ if ! cp "$layerDirectory/$sharedObject" "$implicitDirectory/" || ! cp "$layerDirectory/$json" "$implicitDirectory/"
+ then
+ echo "unable to install test layer" >&2
+ return 1
+ fi
+
+ # Test without setting enable environment variable. The loader should not load the layer.
+ output=$(GTEST_FILTER=ImplicitLayer.Present \
+ ./vk_loader_validation_tests 2>&1)
+ if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance"
+ then
+ echo "test layer detected but enable environment variable was not set" >&2
+ return 1
+ fi
+
+ # Test enable environment variable with good value. The loader should load the layer.
+ output=$(ENABLE_LAYER_TEST_1=enable \
+ GTEST_FILTER=ImplicitLayer.Present \
+ ./vk_loader_validation_tests 2>&1)
+ if ! echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance"
+ then
+ echo "test layer not detected" >&2
+ return 1
+ fi
+
+ # Test enable environment variable with bad value. The loader should not load the layer.
+ output=$(ENABLE_LAYER_TEST_1=wrong \
+ GTEST_FILTER=ImplicitLayer.Present \
+ ./vk_loader_validation_tests 2>&1)
+ if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance"
+ then
+ echo "test layer detected but enable environment variable was set to wrong value" >&2
+ return 1
+ fi
+
+ # Test disable environment variable. The loader should not load the layer.
+ output=$(DISABLE_LAYER_TEST_1=value \
+ GTEST_FILTER=ImplicitLayer.Present \
+ ./vk_loader_validation_tests 2>&1)
+ if echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance"
+ then
+ echo "test layer detected but disable environment variable was set" >&2
+ return 1
+ fi
+
+ # Remove the enable environment variable.
+ if ! sed -i '/enable_environment\|ENABLE_LAYER_TEST_1\|},/d' "$implicitDirectory/$json"
+ then
+ echo "unable to remove enable environment variable" >&2
+ return 1
+ fi
+
+ # Test without setting enable environment variable. The loader should load the layer.
+ output=$(GTEST_FILTER=ImplicitLayer.Present \
+ ./vk_loader_validation_tests 2>&1)
+ if ! echo "$output" | grep -q "VK_LAYER_LUNARG_test: CreateInstance"
+ then
+ echo "test layer not detected" >&2
+ return 1
+ fi
+
+ # Remove the test layer.
+ if ! rm "$implicitDirectory/$sharedObject" || ! rm "$implicitDirectory/$json"
+ then
+ echo "unable to uninstall test layer" >&2
+ return 1
+ fi
+
+ echo "ImplicitLayer test PASSED"
+}
+
+! RunImplicitLayerTest && echo "ImplicitLayer test FAILED" >&2 && exit 1
+
+popd > /dev/null