Skip to content

Commit

Permalink
library: Add host image copy test
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Oct 2, 2024
1 parent 7dd1f97 commit b6c40ed
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
46 changes: 46 additions & 0 deletions library/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ set_target_properties(VpLibrary_test_generated_library PROPERTIES FOLDER "Profil

add_dependencies(VpLibrary_test_generated_library VpGenerated)

add_custom_target(VpLibrary_test_generated_host_image_copy_library
COMMAND Python3::Interpreter ${SOLUTION_SCRIPT}
--api ${API_TYPE}
--registry ${VULKAN_HEADERS_INSTALL_DIR}/${CMAKE_INSTALL_DATADIR}/vulkan/registry/vk.xml
--input ${PROJECT_SOURCE_DIR}/library/test/profiles_host_image_copy
--output-library-inc ${PROJECT_SOURCE_DIR}/library/test
--output-library-filename "test_vulkan_profiles_host_image_copy"
--validate
VERBATIM
SOURCES ${SOLUTION_SCRIPT} ${CMAKE_CURRENT_LIST_DIR}/profiles
DEPENDS ${SOLUTION_SCRIPT} ${CMAKE_CURRENT_LIST_DIR}/profiles)

set_target_properties(VpLibrary_test_generated_host_image_copy_library PROPERTIES FOLDER "Profiles API library")

add_dependencies(VpLibrary_test_generated_host_image_copy_library VpGenerated)

# The release source is in ../source/vulkan_profiles.cpp, but the debug source (with
# verbose messages during profile validation) is in ../source/debug/vulkan_profiles.cpp.
set(vulkan_profiles_source ../source$<$<CONFIG:Debug>:/debug>/vulkan_profiles.cpp)
Expand Down Expand Up @@ -85,6 +101,35 @@ function(add_unit_test_object NAME)
set_target_properties(${TEST_NAME_WS} PROPERTIES FOLDER "Profiles API library")
endfunction(add_unit_test_object)

function(add_unit_test_host_image_copy NAME)
set(TEST_FILE ./${NAME}.cpp)
set(TEST_NAME VpLibrary_${NAME})
set(TEST_NAME_OBJECT VpLibrary_${NAME}_object)

# add_executable(${TEST_NAME} ${TEST_FILE})
# if(MSVC)
# target_compile_options(${TEST_NAME} PRIVATE /bigobj)
# endif()
# target_compile_definitions(${TEST_NAME} PUBLIC "VK_ENABLE_BETA_EXTENSIONS=1")
# target_include_directories(${TEST_NAME} PUBLIC "${vulkan-headers_SOURCE_DIR}/include")
# target_link_libraries(${TEST_NAME} PRIVATE ${test_libraries})
# add_dependencies(${TEST_NAME} VpGenerated VpLibrary_test_generated_host_image_copy_library)
# add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} --gtest_catch_exceptions=0)
# set_target_properties(${TEST_NAME} PROPERTIES FOLDER "Profiles API library")

add_executable(${TEST_NAME_OBJECT} ${TEST_FILE})
if(MSVC)
target_compile_options(${TEST_NAME_OBJECT} PRIVATE /bigobj)
endif()
target_compile_definitions(${TEST_NAME_OBJECT} PUBLIC "VK_ENABLE_BETA_EXTENSIONS=1")
target_compile_definitions(${TEST_NAME_OBJECT} PUBLIC "VP_USE_OBJECT=1")
target_include_directories(${TEST_NAME_OBJECT} PUBLIC "${vulkan-headers_SOURCE_DIR}/include")
target_link_libraries(${TEST_NAME_OBJECT} PRIVATE ${test_libraries})
add_dependencies(${TEST_NAME_OBJECT} VpGenerated VpLibrary_test_generated_host_image_copy_library)
add_test(NAME ${TEST_NAME_OBJECT} COMMAND ${TEST_NAME_OBJECT} --gtest_catch_exceptions=0)
set_target_properties(${TEST_NAME_OBJECT} PROPERTIES FOLDER "Profiles API library")
endfunction(add_unit_test_host_image_copy)

add_unit_test(test_api_reflection)
if(NOT APPLE)
add_unit_test_object(test_api_profile_object)
Expand Down Expand Up @@ -216,4 +261,5 @@ add_unit_test_simple(test_mocked_api_create_device)

if (NOT ANDROID)
add_unit_test_simple(test_mocked_api_generated_library)
add_unit_test_simple(test_mocked_api_generated_host_image_copy)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "https://schema.khronos.org/vulkan/profiles-0.8.2-290.json#",
"capabilities": {
"block": {
"extensions": {
"VK_EXT_host_image_copy": 1
},
"properties": {
"VkPhysicalDeviceHostImageCopyPropertiesEXT": {
"pCopySrcLayouts": [ "VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL" ],
"pCopyDstLayouts": [ "VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL" ],
"optimalTilingLayoutUUID": [ 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, 207 ],
"identicalMemoryTypeRequirements": true
}
}
}
},
"profiles": {
"VP_LUNARG_test_host_image_copy_basic": {
"version": 1,
"api-version": "1.3.204",
"label": "Test Profile Variants",
"description": "Test.",
"contributors": {
"Christophe Riccio": {
"company": "LunarG",
"email": "[email protected]",
"github": "christophe-lunarg",
"contact": true
}
},
"history": [
{
"revision": 1,
"date": "2023-10-31",
"author": "Christophe Riccio",
"comment": "Initial revision"
}
],
"capabilities": [
"block"
]
}
}
}
92 changes: 92 additions & 0 deletions library/test/test_mocked_api_generated_host_image_copy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2021-2024 Valve Corporation
* Copyright (c) 2021-2024 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.
*
* Authors:
* - Christophe Riccio <[email protected]>
* - Daniel Rakos <[email protected]>
*/

#include "mock_vulkan_api.hpp"
#include "test_vulkan_profiles_host_image_copy.hpp"

#ifdef VP_USE_OBJECT
struct Capabilities {
VpCapabilities handle = VK_NULL_HANDLE;

Capabilities() {
VpVulkanFunctions vulkanFunctions;
vulkanFunctions.GetInstanceProcAddr = vkGetInstanceProcAddr;
vulkanFunctions.GetDeviceProcAddr = vkGetDeviceProcAddr;
vulkanFunctions.EnumerateInstanceVersion = vkEnumerateInstanceVersion;
vulkanFunctions.EnumerateInstanceExtensionProperties = vkEnumerateInstanceExtensionProperties;
vulkanFunctions.EnumerateDeviceExtensionProperties = vkEnumerateDeviceExtensionProperties;
vulkanFunctions.GetPhysicalDeviceFeatures2 = vkGetPhysicalDeviceFeatures2;
vulkanFunctions.GetPhysicalDeviceProperties2 = vkGetPhysicalDeviceProperties2;
vulkanFunctions.GetPhysicalDeviceFormatProperties2 = vkGetPhysicalDeviceFormatProperties2;
vulkanFunctions.GetPhysicalDeviceQueueFamilyProperties2 = vkGetPhysicalDeviceQueueFamilyProperties2;
vulkanFunctions.CreateInstance = vkCreateInstance;
vulkanFunctions.CreateDevice = vkCreateDevice;

VpCapabilitiesCreateInfo createInfo;
createInfo.apiVersion = VK_API_VERSION_1_1;
createInfo.flags = VP_PROFILE_CREATE_STATIC_BIT;
createInfo.pVulkanFunctions = &vulkanFunctions;

vpCreateCapabilities(&createInfo, nullptr, &handle);
}

~Capabilities() { vpDestroyCapabilities(handle, nullptr); }
};
#endif//

TEST(mocked_api_generated_library_host_image_library, check_support_profile) {
MockVulkanAPI mock;

const VpProfileProperties profile{VP_LUNARG_TEST_HOST_IMAGE_COPY_BASIC_NAME, VP_LUNARG_TEST_HOST_IMAGE_COPY_BASIC_SPEC_VERSION};

uint32_t extensions_count = 0;
vpGetProfileDeviceExtensionProperties(&profile, nullptr, &extensions_count, nullptr);
std::vector<VkExtensionProperties> extensions(extensions_count);
vpGetProfileDeviceExtensionProperties(&profile, nullptr, &extensions_count, &extensions[0]);

VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, nullptr};
vpGetProfileFeatures(&profile, nullptr, &features);

VkPhysicalDeviceHostImageCopyPropertiesEXT props_host_image_copy{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_PROPERTIES_EXT, nullptr};

VkPhysicalDeviceProperties2 props{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &props_host_image_copy};
vpGetProfileProperties(&profile, nullptr, &props);

EXPECT_EQ(props.properties.limits.maxImageDimension1D, 0);
EXPECT_EQ(props.properties.limits.maxImageDimension2D, 4096);
EXPECT_EQ(props.properties.limits.maxImageDimension3D, 4096);
EXPECT_EQ(props.properties.limits.maxImageDimensionCube, 4096);

mock.SetDeviceExtensions(mock.vkPhysicalDevice, extensions);
mock.SetInstanceAPIVersion(VK_API_VERSION_1_3);
mock.SetDeviceAPIVersion(VK_API_VERSION_1_3);
mock.SetFeatures({VK_STRUCT(features)});
mock.SetProperties({VK_STRUCT(props)});
mock.SetDeviceExtensions(mock.vkPhysicalDevice, extensions);

VkBool32 supported = VK_FALSE;
VkBool32 result = vpGetPhysicalDeviceProfileSupport(mock.vkInstance, mock.vkPhysicalDevice, &profile, &supported);

EXPECT_EQ(result, VK_SUCCESS);
EXPECT_EQ(supported, VK_TRUE);
}
53 changes: 53 additions & 0 deletions library/test/test_mocked_api_get_physdev_profile_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,3 +1024,56 @@ TEST(mocked_api_get_physdev_profile_support, vulkan13_supported_version) {
EXPECT_EQ(result, VK_SUCCESS);
EXPECT_EQ(supported, VK_TRUE);
}

TEST(mocked_api_get_physdev_profile_support, host_image_copy) {
MockVulkanAPI mock;

#ifdef WITH_DEBUG_MESSAGES
MockDebugMessageCallback cb({});
#endif

// Unsupported version
mock.SetInstanceAPIVersion(VK_API_VERSION_1_3);
mock.SetDeviceAPIVersion(VK_API_VERSION_1_3);

mock.SetDeviceExtensions(mock.vkPhysicalDevice, {
VK_EXT(VK_KHR_GLOBAL_PRIORITY),
});

const VpProfileProperties profile{VP_KHR_ROADMAP_2022_NAME, VP_KHR_ROADMAP_2022_SPEC_VERSION};

VkPhysicalDeviceVulkan13Features vulkan13Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
VkPhysicalDeviceVulkan12Features vulkan12Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, &vulkan13Features};
VkPhysicalDeviceVulkan11Features vulkan11Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES, &vulkan12Features};
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &vulkan11Features};
vpGetProfileFeatures(&profile, nullptr, &features);

mock.SetFeatures({VK_STRUCT(features), VK_STRUCT(vulkan11Features), VK_STRUCT(vulkan12Features), VK_STRUCT(vulkan13Features)});

VkPhysicalDeviceVulkan13Properties vulkan13Properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_PROPERTIES};
VkPhysicalDeviceVulkan12Properties vulkan12Properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES,
&vulkan13Properties};
VkPhysicalDeviceVulkan11Properties vulkan11Properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES,
&vulkan12Properties};
VkPhysicalDeviceProperties2 props{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &vulkan11Properties};
vpGetProfileProperties(&profile, nullptr, &props);

mock.SetProperties(
{VK_STRUCT(props), VK_STRUCT(vulkan11Properties), VK_STRUCT(vulkan12Properties), VK_STRUCT(vulkan13Properties)});

uint32_t formatCount;
vpGetProfileFormats(&profile, nullptr, &formatCount, nullptr);
std::vector<VkFormat> formats(formatCount);
vpGetProfileFormats(&profile, nullptr, &formatCount, formats.data());
for (size_t i = 0; i < formatCount; ++i) {
VkFormatProperties2KHR formatProps{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR};
vpGetProfileFormatProperties(&profile, nullptr, formats[i], &formatProps);
mock.AddFormat(formats[i], {VK_STRUCT(formatProps)});
}

VkBool32 supported = VK_TRUE;
VkResult result = vpGetPhysicalDeviceProfileSupport(mock.vkInstance, mock.vkPhysicalDevice, &profile, &supported);

EXPECT_EQ(result, VK_SUCCESS);
EXPECT_EQ(supported, VK_TRUE);
}

0 comments on commit b6c40ed

Please sign in to comment.