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 3, 2024
1 parent 7dd1f97 commit eec3720
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 206 deletions.
65 changes: 65 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 @@ -217,3 +262,23 @@ add_unit_test_simple(test_mocked_api_create_device)
if (NOT ANDROID)
add_unit_test_simple(test_mocked_api_generated_library)
endif()

function(add_unit_test_host_image_copy NAME)
set(TEST_FILE ./${NAME}.cpp)
set(TEST_NAME_HO VpLibrary_${NAME})

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

if (NOT ANDROID)
add_unit_test_host_image_copy(test_mocked_api_generated_host_image_copy)
add_unit_test_host_image_copy(test_mocked_api_generated_host_image_copy_object)
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"
]
}
}
}
62 changes: 62 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,62 @@
/*
* 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"

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);
}
94 changes: 94 additions & 0 deletions library/test/test_mocked_api_generated_host_image_copy_object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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]>
*/

#define VP_USE_OBJECT 1
#include "mock_vulkan_api.hpp"
#include "test_vulkan_profiles_host_image_copy.hpp"

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); }
};

TEST(mocked_api_generated_library_host_image_library_object, check_support_profile) {
Capabilities capabilities;

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(capabilities.handle, &profile, nullptr, &extensions_count, nullptr);
std::vector<VkExtensionProperties> extensions(extensions_count);
vpGetProfileDeviceExtensionProperties(capabilities.handle, &profile, nullptr, &extensions_count, &extensions[0]);

VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, nullptr};
vpGetProfileFeatures(capabilities.handle, &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(capabilities.handle, &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(capabilities.handle, mock.vkInstance, mock.vkPhysicalDevice, &profile, &supported);

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

0 comments on commit eec3720

Please sign in to comment.