mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 07:02:25 +00:00
remove vulkan wraaper
Signed-off-by: andrew0229 <zhangzhao62@huawei.com> Change-Id: I92e7aa78b8815cecb81711ca4ae391ce9862c81e
This commit is contained in:
parent
9a6a910025
commit
6bf49875f9
2
BUILD.gn
2
BUILD.gn
@ -21,7 +21,6 @@ group("default") {
|
||||
"frameworks/dumper:gdumper",
|
||||
"frameworks/dumper:gdumper.ini",
|
||||
"frameworks/dumper:graphic_dumper_server",
|
||||
"frameworks/vulkan_wrapper:vulkan",
|
||||
]
|
||||
|
||||
if (graphic_standard_feature_bootanimation_enable) {
|
||||
@ -39,7 +38,6 @@ group("graphic_2d_test") {
|
||||
"frameworks/opengl_wrapper/test:test",
|
||||
"frameworks/surface/test:test",
|
||||
"frameworks/vulkan_layers/test:test",
|
||||
"frameworks/vulkan_wrapper/test:test",
|
||||
"rosen/modules/composer:test",
|
||||
"rosen/modules/effect/test/unittest:test",
|
||||
"rosen/test/frame_analyzer:test",
|
||||
|
@ -85,7 +85,6 @@
|
||||
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:GLESv3",
|
||||
"//foundation/graphic/graphic_2d/frameworks/surfaceimage:libnative_image",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/effect/egl:libegl_effect",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_wrapper:vulkan",
|
||||
"//third_party/vulkan-loader/openharmony:vulkan_loader",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_layers:vulkan_swapchain_layer",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_layers:vulkan_swapchain_layer_json"
|
||||
|
@ -1,92 +0,0 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Build libvulkan_wrapper.so {{{
|
||||
config("vulkan_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
defines = [
|
||||
"VK_USE_PLATFORM_OHOS_OPENHARMONY",
|
||||
"VK_NO_PROTOTYPES",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fvisibility=hidden",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
]
|
||||
}
|
||||
|
||||
config("vulkan_public_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//drivers/peripheral/base",
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface/include",
|
||||
"//foundation/graphic/graphic_2d/frameworks/inner_api/surface",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("vulkan") {
|
||||
sources = [
|
||||
"src/api_export.cpp",
|
||||
"src/driver.cpp",
|
||||
"src/driver_loader.cpp",
|
||||
"src/swapchain.cpp",
|
||||
]
|
||||
configs = [ ":vulkan_config" ]
|
||||
|
||||
public_configs = [ ":vulkan_public_config" ]
|
||||
|
||||
public_deps = [
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface:surface",
|
||||
"//third_party/vulkan-headers:vulkan_headers",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog_native:libhilog",
|
||||
]
|
||||
|
||||
output_name = "vulkan_wrapper"
|
||||
output_extension = "so"
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
license_file = "//third_party/vulkan-headers/LICENSE.txt"
|
||||
}
|
||||
|
||||
## Build libvulkan_wrapper.so }}}
|
||||
|
||||
## Build vulkan_wrapper_native_test {{{
|
||||
ohos_executable("vulkan_wrapper_native_test") {
|
||||
install_enable = true
|
||||
|
||||
sources = [ "test/vulkan_wrapper_native_test.cpp" ]
|
||||
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
defines = [
|
||||
"VK_USE_PLATFORM_OHOS_OPENHARMONY",
|
||||
"VK_NO_PROTOTYPES",
|
||||
]
|
||||
|
||||
external_deps = [ "c_utils:utils" ]
|
||||
|
||||
deps = [ "//third_party/vulkan-headers:vulkan_headers" ]
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
## Build vulkan_wrapper_native_test }}}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LIBVULKAN_DRIVER_H
|
||||
#define LIBVULKAN_DRIVER_H 1
|
||||
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
VKAPI_ATTR VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkInstance* pInstance);
|
||||
VKAPI_ATTR VkResult EnumerateInstanceExtensionProperties(const char* pLayerName,
|
||||
uint32_t* pPropertyCount, VkExtensionProperties* pProperties);
|
||||
VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName);
|
||||
VKAPI_ATTR void DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator);
|
||||
VKAPI_ATTR VkResult CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkDevice* pDevice);
|
||||
VKAPI_ATTR void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties);
|
||||
VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName);
|
||||
VKAPI_ATTR void GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
|
||||
uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties);
|
||||
VKAPI_ATTR void DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator);
|
||||
VKAPI_ATTR VkResult CreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkImage* pImage);
|
||||
VKAPI_ATTR VkResult GetSwapchainGrallocUsageOpenHarmony(VkDevice device, VkFormat format,
|
||||
VkImageUsageFlags imageUsage, uint64_t* grallocUsage);
|
||||
VKAPI_ATTR VkResult SetNativeFenceFdOpenHarmony(VkDevice device,
|
||||
int32_t nativeFenceFd, VkSemaphore semaphore, VkFence fence);
|
||||
VKAPI_ATTR VkResult GetNativeFenceFdOpenHarmony(VkQueue queue, uint32_t waitSemaphoreCount,
|
||||
const VkSemaphore* pWaitSemaphores, VkImage image, int32_t* pNativeFenceFd);
|
||||
void QueryPresentationProperties(VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDevicePresentationPropertiesOpenHarmony* presentation_properties);
|
||||
VKAPI_ATTR VkResult EnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties);
|
||||
bool IsSupportedVulkan();
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
||||
|
||||
#endif // LIBVULKAN_DRIVER_H
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#ifndef LIBVULKAN_DRIVER_LOADER_H
|
||||
#define LIBVULKAN_DRIVER_LOADER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hardware/hdi_vulkan.h"
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
typedef int32_t (*PFN_VulkanInitialize)(VulkanFuncs **funcs);
|
||||
typedef int32_t (*PFN_VulkanUnInitialize)(VulkanFuncs *funcs);
|
||||
class DriverLoader {
|
||||
public:
|
||||
static bool Load();
|
||||
static bool Unload();
|
||||
static bool LoadDriver();
|
||||
static bool UnloadDriver();
|
||||
static bool LoadDriverFromFile(std::string path);
|
||||
|
||||
static const DriverLoader& Get()
|
||||
{
|
||||
return loader_;
|
||||
}
|
||||
|
||||
static const VulkanFuncs& GetVulkanFuncs()
|
||||
{
|
||||
return *Get().vulkanFuncs_;
|
||||
}
|
||||
|
||||
static bool IsSupportedVulkan()
|
||||
{
|
||||
return Get().supported_;
|
||||
}
|
||||
|
||||
private:
|
||||
DriverLoader() : vulkanFuncs_(nullptr), vulkanUnInitializeFunc_(nullptr) {}
|
||||
DriverLoader(const DriverLoader&) = delete;
|
||||
DriverLoader& operator=(const DriverLoader&) = delete;
|
||||
|
||||
static DriverLoader loader_;
|
||||
void* handle_;
|
||||
|
||||
bool supported_;
|
||||
VulkanFuncs* vulkanFuncs_;
|
||||
PFN_VulkanUnInitialize vulkanUnInitializeFunc_;
|
||||
};
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
||||
#endif // LIBVULKAN_DRIVER_LOADER_H
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup vulkan
|
||||
* @{
|
||||
*
|
||||
* @brief Defines driver functions of the vulkan moudle.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file HDI_VULKAN_H.h
|
||||
*
|
||||
* @brief Declares the driver functions for vulkan.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
#ifndef HDI_VULKAN_H
|
||||
#define HDI_VULKAN_H
|
||||
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define HDIVULKAN_DISPATCH_MAGIC 0x01CDC0DE
|
||||
|
||||
typedef struct {
|
||||
VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceExtensionProperties)(const char* pLayerName,
|
||||
uint32_t* pPropertyCount, VkExtensionProperties* pProperties);
|
||||
VkResult (VKAPI_PTR *PFN_vkCreateInstance)(const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkInstance* pInstance);
|
||||
PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetInstanceProcAddr)(VkInstance instance, const char* pName);
|
||||
} VulkanFuncs;
|
||||
|
||||
/**
|
||||
* @brief Initialize the vulkan module to obtain the pointer to functions for memory operation.
|
||||
*
|
||||
* @param funcs Indicates the double pointer to functions for vulkan
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful.
|
||||
* otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
__attribute__((visibility("default"))) int32_t VulkanInitialize(VulkanFuncs **funcs);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the functions module to release the resource of vulkan.
|
||||
*
|
||||
* @param funcs Indicates the pointer to functions for vulkan.
|
||||
*
|
||||
* @return Returns <b>0</b> if the operation is successful.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
__attribute__((visibility("default"))) int32_t VulkanUnInitialize(VulkanFuncs *funcs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/** @} */
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#ifndef LIBVULKAN_SWAPCHAIN_H
|
||||
#define LIBVULKAN_SWAPCHAIN_H 1
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "driver.h"
|
||||
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
const VkAllocationCallbacks& GetDefaultAllocator();
|
||||
VKAPI_ATTR VkResult CreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony* pCreateInfo,
|
||||
const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
|
||||
VKAPI_ATTR void DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* allocator);
|
||||
VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev,
|
||||
uint32_t queue_family, VkSurfaceKHR surface, VkBool32* pSupported);
|
||||
VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice pdev, VkSurfaceKHR surface,
|
||||
VkSurfaceCapabilitiesKHR* capabilities);
|
||||
VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev,
|
||||
VkSurfaceKHR surface_handle, uint32_t* count, VkSurfaceFormatKHR* formats);
|
||||
VKAPI_ATTR VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev,
|
||||
VkSurfaceKHR surface, uint32_t* count, VkPresentModeKHR* modes);
|
||||
VKAPI_ATTR VkResult GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain_handle,
|
||||
uint32_t* count, VkImage* images);
|
||||
VKAPI_ATTR VkResult CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* create_info,
|
||||
const VkAllocationCallbacks* allocator, VkSwapchainKHR* swapchain_handle);
|
||||
VKAPI_ATTR void DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain_handle,
|
||||
const VkAllocationCallbacks* allocator);
|
||||
VKAPI_ATTR VkResult AcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain_handle,
|
||||
uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* image_index);
|
||||
VKAPI_ATTR VkResult AcquireNextImage2KHR(VkDevice device,
|
||||
const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex);
|
||||
|
||||
VKAPI_ATTR VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info);
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
||||
|
||||
#endif // LIBVULKAN_SWAPCHAIN_H
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#ifndef LIBVULKAN_WRAPPER_LOG_H
|
||||
#define LIBVULKAN_WRAPPER_LOG_H
|
||||
|
||||
#include <hilog/log.h>
|
||||
namespace OHOS {
|
||||
|
||||
#ifdef EGL_WRAPPER_DEBUG_ENABLE
|
||||
#define WLOGD(fmt, ...) OHOS::HiviewDFX::HiLog::Debug({ LOG_CORE, 0xD001402, "VulkanWrapper" }, \
|
||||
"<%{public}d>%{public}s: " fmt, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define WLOGD(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define WLOGI(fmt, ...) OHOS::HiviewDFX::HiLog::Info({ LOG_CORE, 0xD001402, "VulkanWrapper" }, \
|
||||
"<%{public}d>%{public}s: " fmt, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define WLOGW(fmt, ...) OHOS::HiviewDFX::HiLog::Warn({ LOG_CORE, 0xD001402, "VulkanWrapper" }, \
|
||||
"<%{public}d>%{public}s: " fmt, __LINE__, __func__, ##__VA_ARGS__)
|
||||
#define WLOGE(fmt, ...) OHOS::HiviewDFX::HiLog::Error({ LOG_CORE, 0xD001402, "VulkanWrapper" }, \
|
||||
"<%{public}d>%{public}s: " fmt, __LINE__, __func__, ##__VA_ARGS__)
|
||||
} // namespace OHOS
|
||||
#endif // LIBVULKAN_WRAPPER_LOG_H
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#include "swapchain.h"
|
||||
|
||||
extern "C" {
|
||||
__attribute__((visibility("default")))
|
||||
VKAPI_ATTR VkResult vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
|
||||
{
|
||||
return vulkan::driver::CreateInstance(pCreateInfo, pAllocator, pInstance);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
VKAPI_ATTR VkResult vkCreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface)
|
||||
{
|
||||
return vulkan::driver::CreateOHOSSurfaceOpenHarmony(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
VKAPI_ATTR VkResult vkEnumerateInstanceExtensionProperties(const char* pLayerName,
|
||||
uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
|
||||
{
|
||||
return vulkan::driver::EnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* pName)
|
||||
{
|
||||
return vulkan::driver::GetInstanceProcAddr(instance, pName);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* pName)
|
||||
{
|
||||
return vulkan::driver::GetDeviceProcAddr(device, pName);
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) bool IsSupportedVulkan()
|
||||
{
|
||||
return vulkan::driver::IsSupportedVulkan();
|
||||
}
|
||||
}
|
@ -1,305 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <malloc.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "swapchain.h"
|
||||
#include "driver_loader.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "wrapper_log.h"
|
||||
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
DriverLoader DriverLoader::loader_;
|
||||
PFN_vkGetDeviceProcAddr pfn_vkGetDeviceProcAddr = nullptr;
|
||||
PFN_vkGetPhysicalDeviceProperties2KHR fpn_vkGetPhysicalDeviceProperties2KHR = nullptr;
|
||||
PFN_vkCreateDevice pfn_vkCreateDevice = nullptr;
|
||||
PFN_vkGetNativeFenceFdOpenHarmony pfn_vkGetNativeFenceFdOpenHarmony = nullptr;
|
||||
PFN_vkGetPhysicalDeviceProperties pfn_vkGetPhysicalDeviceProperties = nullptr;
|
||||
PFN_vkGetPhysicalDeviceFeatures pfn_vkGetPhysicalDeviceFeatures = nullptr;
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties pfn_vkGetPhysicalDeviceMemoryProperties = nullptr;
|
||||
PFN_vkGetPhysicalDeviceQueueFamilyProperties pfn_vkGetPhysicalDeviceQueueFamilyProperties = nullptr;
|
||||
|
||||
bool IsSupportedVulkan()
|
||||
{
|
||||
DriverLoader::Load();
|
||||
return DriverLoader::IsSupportedVulkan();
|
||||
}
|
||||
|
||||
VkResult CreateInstance(const VkInstanceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkInstance* pInstance)
|
||||
{
|
||||
if (!DriverLoader::Load()) {
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
if (pAllocator == nullptr) {
|
||||
pAllocator = &GetDefaultAllocator();
|
||||
}
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
result = DriverLoader::GetVulkanFuncs().PFN_vkCreateInstance(pCreateInfo, pAllocator, pInstance);
|
||||
if (result != VK_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
pfn_vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkGetDeviceProcAddr"));
|
||||
fpn_vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkGetPhysicalDeviceProperties2KHR"));
|
||||
pfn_vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkCreateDevice"));
|
||||
pfn_vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkGetPhysicalDeviceProperties"));
|
||||
pfn_vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkGetPhysicalDeviceFeatures"));
|
||||
pfn_vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
pfn_vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(*pInstance,
|
||||
"vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
VkResult EnumerateInstanceExtensionProperties(const char* pLayerName,
|
||||
uint32_t* pPropertyCount, VkExtensionProperties* pProperties)
|
||||
{
|
||||
if (!DriverLoader::Load()) {
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
VkResult result = DriverLoader::GetVulkanFuncs().PFN_vkEnumerateInstanceExtensionProperties(
|
||||
pLayerName, pPropertyCount, pProperties);
|
||||
if (result != VK_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName)
|
||||
{
|
||||
if (!DriverLoader::Load()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkEnumerateInstanceExtensionProperties") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::EnumerateInstanceExtensionProperties);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkCreateInstance") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::CreateInstance);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkCreateOHOSSurfaceOpenHarmony") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::CreateOHOSSurfaceOpenHarmony);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::GetPhysicalDeviceSurfaceSupportKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::GetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkGetPhysicalDeviceSurfaceFormatsKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::GetPhysicalDeviceSurfaceFormatsKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkGetPhysicalDeviceSurfacePresentModesKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::GetPhysicalDeviceSurfacePresentModesKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkDestroySurfaceKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::DestroySurfaceKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkCreateDevice") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::CreateDevice);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkDestroyInstance") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::DestroyInstance);
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction func = DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(instance, pName);
|
||||
if (!func) {
|
||||
WLOGE("GetInstanceProcAddr %{public}s failed, please check", pName);
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
void DestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
PFN_vkDestroyInstance pfn_vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(
|
||||
DriverLoader::GetVulkanFuncs().PFN_vkGetInstanceProcAddr(instance, "vkDestroyInstance"));
|
||||
if (pfn_vkDestroyInstance) {
|
||||
pfn_vkDestroyInstance(instance, pAllocator);
|
||||
}
|
||||
|
||||
if (!DriverLoader::Unload()) {
|
||||
WLOGE("DriverLoader::Unload() failed");
|
||||
}
|
||||
}
|
||||
|
||||
VkResult CreateDevice(VkPhysicalDevice physicalDevice,
|
||||
const VkDeviceCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDevice* pDevice)
|
||||
{
|
||||
VkResult result = VK_SUCCESS;
|
||||
if (pfn_vkCreateDevice) {
|
||||
std::vector<const char*> deviceExtensions;
|
||||
|
||||
auto& ext_names = (*pCreateInfo).ppEnabledExtensionNames;
|
||||
auto& ext_count = (*pCreateInfo).enabledExtensionCount;
|
||||
for (uint32_t i = 0; i < ext_count; i++) {
|
||||
deviceExtensions.push_back(ext_names[i]);
|
||||
}
|
||||
deviceExtensions.push_back(VK_OHOS_NATIVE_BUFFER_EXTENSION_NAME);
|
||||
deviceExtensions.push_back(VK_OPENHARMONY_EXTERNAL_MEMORY_OHOS_NATIVE_BUFFER_EXTENSION_NAME);
|
||||
VkDeviceCreateInfo createInfo(*pCreateInfo);
|
||||
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size());
|
||||
createInfo.ppEnabledExtensionNames = deviceExtensions.data();
|
||||
|
||||
result = pfn_vkCreateDevice(physicalDevice, &createInfo, pAllocator, pDevice);
|
||||
}
|
||||
|
||||
if ((result == VK_SUCCESS) && (pfn_vkGetDeviceProcAddr != nullptr)) {
|
||||
pfn_vkGetNativeFenceFdOpenHarmony= reinterpret_cast<PFN_vkGetNativeFenceFdOpenHarmony>(
|
||||
pfn_vkGetDeviceProcAddr(*pDevice, "vkGetNativeFenceFdOpenHarmony"));
|
||||
if (!pfn_vkGetNativeFenceFdOpenHarmony) {
|
||||
WLOGE("vulkan::driver::CreateDevice Get vkGetNativeFenceFdOpenHarmony failed");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName)
|
||||
{
|
||||
PFN_vkVoidFunction func = nullptr;
|
||||
|
||||
if (!pfn_vkGetDeviceProcAddr) {
|
||||
WLOGE("pfn_vkGetDeviceProcAddr is null, please check");
|
||||
return nullptr;
|
||||
}
|
||||
if (std::strcmp(pName, "vkCreateSwapchainKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::CreateSwapchainKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkDestroySwapchainKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::DestroySwapchainKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkGetSwapchainImagesKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::GetSwapchainImagesKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkAcquireNextImageKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::AcquireNextImageKHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkAcquireNextImage2KHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::AcquireNextImage2KHR);
|
||||
}
|
||||
|
||||
if (std::strcmp(pName, "vkQueuePresentKHR") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(vulkan::driver::QueuePresentKHR);
|
||||
}
|
||||
func = pfn_vkGetDeviceProcAddr(device, pName);
|
||||
if (!func) {
|
||||
WLOGE("GetDeviceProcAddr %{public}s is null, please check", pName);
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
void DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
PFN_vkDestroyImage destroyImage = reinterpret_cast<PFN_vkDestroyImage>(GetDeviceProcAddr(device, "vkDestroyImage"));
|
||||
if (destroyImage) {
|
||||
return destroyImage(device, image, pAllocator);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
VkResult CreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkImage* pImage)
|
||||
{
|
||||
PFN_vkCreateImage createImage = reinterpret_cast<PFN_vkCreateImage>(GetDeviceProcAddr(device, "vkCreateImage"));
|
||||
if (createImage) {
|
||||
return createImage(device, pCreateInfo, pAllocator, pImage);
|
||||
}
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
void QueryPresentationProperties(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
VkPhysicalDevicePresentationPropertiesOpenHarmony* presentation_properties)
|
||||
{
|
||||
VkPhysicalDeviceProperties2 properties = {
|
||||
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
|
||||
presentation_properties,
|
||||
{},
|
||||
};
|
||||
|
||||
presentation_properties->sType =
|
||||
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_OPENHARMONY;
|
||||
presentation_properties->pNext = nullptr;
|
||||
presentation_properties->sharedImage = VK_FALSE;
|
||||
|
||||
GetPhysicalDeviceProperties2(physicalDevice, &properties);
|
||||
}
|
||||
|
||||
void GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties)
|
||||
{
|
||||
if (fpn_vkGetPhysicalDeviceProperties2KHR) {
|
||||
fpn_vkGetPhysicalDeviceProperties2KHR(physicalDevice, pProperties);
|
||||
}
|
||||
}
|
||||
|
||||
VkResult SetNativeFenceFdOpenHarmony(VkDevice device,
|
||||
int nativeFenceFd,
|
||||
VkSemaphore semaphore,
|
||||
VkFence fence)
|
||||
{
|
||||
PFN_vkSetNativeFenceFdOpenHarmony acquireImage = reinterpret_cast<PFN_vkSetNativeFenceFdOpenHarmony>(
|
||||
GetDeviceProcAddr(device, "vkSetNativeFenceFdOpenHarmony"));
|
||||
if (acquireImage) {
|
||||
return acquireImage(device, nativeFenceFd, semaphore, fence);
|
||||
}
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
VkResult GetNativeFenceFdOpenHarmony(
|
||||
VkQueue queue,
|
||||
uint32_t waitSemaphoreCount,
|
||||
const VkSemaphore* pWaitSemaphores,
|
||||
VkImage image,
|
||||
int* pNativeFenceFd)
|
||||
{
|
||||
if (pfn_vkGetNativeFenceFdOpenHarmony) {
|
||||
return pfn_vkGetNativeFenceFdOpenHarmony(queue, waitSemaphoreCount, pWaitSemaphores, image, pNativeFenceFd);
|
||||
}
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#include "driver_loader.h"
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include "wrapper_log.h"
|
||||
#include "directory_ex.h"
|
||||
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
#ifdef __aarch64__
|
||||
constexpr const char *VENDOR_LIB_PATH = "/vendor/lib64/chipsetsdk/";
|
||||
constexpr const char *SYSTEM_LIB_PATH = "/system/lib64/";
|
||||
#else
|
||||
constexpr const char *VENDOR_LIB_PATH = "/vendor/lib/chipsetsdk/";
|
||||
constexpr const char *SYSTEM_LIB_PATH = "/system/lib/";
|
||||
#endif
|
||||
constexpr const char *LIB_NAME = "libEGL_impl.so";
|
||||
constexpr const char *HDI_VULKAN_MODULE_INIT = "VulkanInitialize";
|
||||
constexpr const char *HDI_VULKAN_MODULE_UNINIT = "VulkanUnInitialize";
|
||||
|
||||
bool DriverLoader::Load()
|
||||
{
|
||||
static std::mutex loadLock;
|
||||
std::lock_guard<std::mutex> lock(loadLock);
|
||||
|
||||
if (loader_.vulkanFuncs_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
loader_.supported_ = false;
|
||||
|
||||
if (!LoadDriver()) {
|
||||
WLOGE("LoadDriver failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
PFN_VulkanInitialize VulkanInitializeFunc
|
||||
= reinterpret_cast<PFN_VulkanInitialize>(dlsym(loader_.handle_, HDI_VULKAN_MODULE_INIT));
|
||||
if (VulkanInitializeFunc == nullptr) {
|
||||
WLOGE("DriverLoader:: couldn't find symbol(VulkanInitializeFunc) in library : %{public}s.", dlerror());
|
||||
UnloadDriver();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (VulkanInitializeFunc(&loader_.vulkanFuncs_) != 0) {
|
||||
WLOGE("DriverLoader:: Initialize Vulkan Func fail");
|
||||
UnloadDriver();
|
||||
return false;
|
||||
}
|
||||
|
||||
loader_.vulkanUnInitializeFunc_ = reinterpret_cast<PFN_VulkanUnInitialize>(
|
||||
dlsym(loader_.handle_, HDI_VULKAN_MODULE_UNINIT));
|
||||
|
||||
if (loader_.vulkanUnInitializeFunc_ == nullptr) {
|
||||
WLOGE("DriverLoader:: couldn't find symbol(VulkanUnInitialize) in library : %{public}s.", dlerror());
|
||||
UnloadDriver();
|
||||
return false;
|
||||
}
|
||||
loader_.supported_ = true;
|
||||
WLOGI("DriverLoader:: Found Vulkan Func success");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DriverLoader::Unload()
|
||||
{
|
||||
if (loader_.vulkanUnInitializeFunc_ == nullptr) {
|
||||
WLOGE("DriverLoader::Unload can not find vulkan UnInitialize Func.");
|
||||
return false;
|
||||
}
|
||||
if (loader_.vulkanUnInitializeFunc_(loader_.vulkanFuncs_) != 0) {
|
||||
WLOGE("DriverLoader::Unload vulkan UnInitialize Func failed.");
|
||||
return false;
|
||||
}
|
||||
loader_.vulkanFuncs_ = nullptr;
|
||||
loader_.vulkanUnInitializeFunc_ = nullptr;
|
||||
WLOGD("DriverLoader::Unload vulkan UnInitialize Func successfully.");
|
||||
return UnloadDriver();
|
||||
}
|
||||
|
||||
bool DriverLoader::LoadDriver()
|
||||
{
|
||||
if (loader_.handle_ != nullptr) {
|
||||
WLOGD("handle is not null, no need to dlopen.");
|
||||
return true;
|
||||
}
|
||||
std::string venderPath = std::string(VENDOR_LIB_PATH) + std::string(LIB_NAME);
|
||||
std::string systemPath = std::string(SYSTEM_LIB_PATH) + std::string(LIB_NAME);
|
||||
if (!LoadDriverFromFile(venderPath)) {
|
||||
if (!LoadDriverFromFile(systemPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
WLOGD("DriverLoader::LoadDriver successfully.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DriverLoader::UnloadDriver()
|
||||
{
|
||||
if (loader_.handle_ == nullptr) {
|
||||
WLOGD("DriverLoader::UnloadDriver handle is null already.");
|
||||
return true;
|
||||
}
|
||||
if (dlclose(loader_.handle_) != 0) {
|
||||
WLOGE("DriverLoader::UnloadDriver dlclose failed.");
|
||||
return false;
|
||||
}
|
||||
loader_.handle_ = nullptr;
|
||||
WLOGD("DriverLoader::UnloadDriver dlclose success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DriverLoader::LoadDriverFromFile(std::string path)
|
||||
{
|
||||
std::string realPath;
|
||||
if (!OHOS::PathToRealPath(path, realPath)) {
|
||||
WLOGE("file is not in path: %{private}s", path.c_str());
|
||||
return false;
|
||||
}
|
||||
loader_.handle_ = dlopen(realPath.c_str(), RTLD_LOCAL | RTLD_NOW);
|
||||
if (loader_.handle_ == nullptr) {
|
||||
WLOGE("dlopen failed. error: %{public}s.", dlerror());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
@ -1,821 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#include "swapchain.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <new>
|
||||
#include <malloc.h>
|
||||
#include <native_window.h>
|
||||
#include <window.h>
|
||||
#include <native_buffer.h>
|
||||
#include <wrapper_log.h>
|
||||
#include <graphic_common.h>
|
||||
#include <securec.h>
|
||||
|
||||
namespace vulkan {
|
||||
namespace driver {
|
||||
namespace {
|
||||
constexpr uint32_t MIN_BUFFER_SIZE = 3;
|
||||
}
|
||||
struct Surface {
|
||||
NativeWindow* window;
|
||||
VkSwapchainKHR swapchainHandle;
|
||||
int32_t consumerUsage;
|
||||
};
|
||||
|
||||
struct Swapchain {
|
||||
Swapchain(Surface& surface, uint32_t numImages, VkPresentModeKHR presentMode, int preTransform)
|
||||
: surface(surface), numImages(numImages), mailboxMode(presentMode == VK_PRESENT_MODE_MAILBOX_KHR),
|
||||
preTransform(preTransform), frameTimestampsEnabled(false),
|
||||
shared(presentMode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR ||
|
||||
presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) {}
|
||||
|
||||
Surface& surface;
|
||||
uint32_t numImages;
|
||||
bool mailboxMode;
|
||||
int preTransform;
|
||||
bool frameTimestampsEnabled;
|
||||
bool shared;
|
||||
|
||||
struct Image {
|
||||
Image() : image(VK_NULL_HANDLE), buffer(nullptr), requestFence(-1), releaseFence(-1), requested(false) {}
|
||||
VkImage image;
|
||||
NativeWindowBuffer* buffer;
|
||||
int requestFence;
|
||||
int releaseFence;
|
||||
bool requested;
|
||||
} images[32];
|
||||
};
|
||||
|
||||
VKAPI_ATTR void* DefaultAllocate(void*, size_t size, size_t alignment, VkSystemAllocationScope)
|
||||
{
|
||||
void* ptr = nullptr;
|
||||
// Vulkan requires 'alignment' to be a power of two, but posix_memalign
|
||||
// additionally requires that it be at least sizeof(void*).
|
||||
int ret = posix_memalign(&ptr, std::max(alignment, sizeof(void*)), size);
|
||||
return ret == 0 ? ptr : nullptr;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void* DefaultReallocate(void*, void* ptr, size_t size, size_t alignment, VkSystemAllocationScope)
|
||||
{
|
||||
if (size == 0) {
|
||||
free(ptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t oldSize = ptr ? malloc_usable_size(ptr) : 0;
|
||||
if (size <= oldSize) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* newPtr = nullptr;
|
||||
if (posix_memalign(&newPtr, std::max(alignment, sizeof(void*)), size) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (ptr) {
|
||||
auto ret = memcpy_s(newPtr, size, ptr, oldSize);
|
||||
if (ret != EOK) {
|
||||
return nullptr;
|
||||
}
|
||||
free(ptr);
|
||||
}
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void DefaultFree(void*, void* ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
const VkAllocationCallbacks& GetDefaultAllocator()
|
||||
{
|
||||
static const VkAllocationCallbacks kDefaultAllocCallbacks = {
|
||||
.pUserData = nullptr,
|
||||
.pfnAllocation = DefaultAllocate,
|
||||
.pfnReallocation = DefaultReallocate,
|
||||
.pfnFree = DefaultFree,
|
||||
};
|
||||
|
||||
return kDefaultAllocCallbacks;
|
||||
}
|
||||
|
||||
VkSurfaceKHR HandleFromSurface(Surface* surface)
|
||||
{
|
||||
return VkSurfaceKHR(reinterpret_cast<uint64_t>(surface));
|
||||
}
|
||||
|
||||
Surface* SurfaceFromHandle(VkSurfaceKHR handle)
|
||||
{
|
||||
return reinterpret_cast<Surface*>(handle);
|
||||
}
|
||||
|
||||
Swapchain* SwapchainFromHandle(VkSwapchainKHR handle)
|
||||
{
|
||||
return reinterpret_cast<Swapchain*>(handle);
|
||||
}
|
||||
|
||||
VkSwapchainKHR HandleFromSwapchain(Swapchain* swapchain)
|
||||
{
|
||||
return VkSwapchainKHR(reinterpret_cast<uint64_t>(swapchain));
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult CreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony* pCreateInfo,
|
||||
const VkAllocationCallbacks* allocator,
|
||||
VkSurfaceKHR* outSurface)
|
||||
{
|
||||
if (!allocator) {
|
||||
allocator = &vulkan::driver::GetDefaultAllocator();
|
||||
}
|
||||
void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Surface), alignof(Surface),
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!mem) {
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
Surface* surface = new (mem) Surface;
|
||||
surface->window = pCreateInfo->window;
|
||||
surface->swapchainHandle = VK_NULL_HANDLE;
|
||||
int32_t res = NativeWindowHandleOpt(pCreateInfo->window, GET_USAGE, &(surface->consumerUsage));
|
||||
|
||||
if (surface->consumerUsage == 0) {
|
||||
WLOGE("native window get usage failed, error num : %{public}d", res);
|
||||
surface->~Surface();
|
||||
allocator->pfnFree(allocator->pUserData, surface);
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
|
||||
*outSurface = HandleFromSurface(surface);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR void DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surfaceHandle,
|
||||
const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
Surface* surface = SurfaceFromHandle(surfaceHandle);
|
||||
if (!surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
surface->~Surface();
|
||||
if (!allocator) {
|
||||
allocator = &vulkan::driver::GetDefaultAllocator();
|
||||
}
|
||||
allocator->pfnFree(allocator->pUserData, surface);
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice, uint32_t, VkSurfaceKHR, VkBool32* supported)
|
||||
{
|
||||
*supported = VK_TRUE;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice, VkSurfaceKHR surface,
|
||||
VkSurfaceCapabilitiesKHR* capabilities)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
uint32_t maxBufferCount = 10;
|
||||
if (surface != VK_NULL_HANDLE) {
|
||||
NativeWindow* window = SurfaceFromHandle(surface)->window;
|
||||
int err = NativeWindowHandleOpt(window, GET_BUFFER_GEOMETRY, &height, &width);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
WLOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: (%{public}d)", err);
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
maxBufferCount = window->surface->GetQueueSize();
|
||||
}
|
||||
|
||||
capabilities->minImageCount = std::min(maxBufferCount, MIN_BUFFER_SIZE);
|
||||
capabilities->maxImageCount = maxBufferCount;
|
||||
capabilities->currentExtent = VkExtent2D {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||
capabilities->minImageExtent = VkExtent2D {1, 1};
|
||||
capabilities->maxImageExtent = VkExtent2D {4096, 4096};
|
||||
capabilities->maxImageArrayLayers = 1;
|
||||
capabilities->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
|
||||
capabilities->supportedUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, VkSurfaceKHR surfaceHandle, uint32_t* count,
|
||||
VkSurfaceFormatKHR* formats)
|
||||
{
|
||||
std::vector<VkSurfaceFormatKHR> allFormats = {{VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR},
|
||||
{VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}};
|
||||
VkResult result = VK_SUCCESS;
|
||||
if (formats) {
|
||||
uint32_t transferCount = allFormats.size();
|
||||
if (transferCount > *count) {
|
||||
transferCount = *count;
|
||||
result = VK_INCOMPLETE;
|
||||
}
|
||||
std::copy(allFormats.begin(), allFormats.begin() + transferCount, formats);
|
||||
*count = transferCount;
|
||||
} else {
|
||||
*count = allFormats.size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count,
|
||||
VkPresentModeKHR* modes)
|
||||
{
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
presentModes.push_back(VK_PRESENT_MODE_MAILBOX_KHR);
|
||||
presentModes.push_back(VK_PRESENT_MODE_FIFO_KHR);
|
||||
|
||||
VkPhysicalDevicePresentationPropertiesOpenHarmony present_properties;
|
||||
QueryPresentationProperties(pdev, &present_properties);
|
||||
if (present_properties.sharedImage) {
|
||||
presentModes.push_back(VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR);
|
||||
presentModes.push_back(VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR);
|
||||
}
|
||||
|
||||
uint32_t numModes = uint32_t(presentModes.size());
|
||||
VkResult result = VK_SUCCESS;
|
||||
if (modes) {
|
||||
if (*count < numModes) {
|
||||
result = VK_INCOMPLETE;
|
||||
}
|
||||
*count = std::min(*count, numModes);
|
||||
std::copy_n(presentModes.data(), *count, modes);
|
||||
} else {
|
||||
*count = numModes;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult GetSwapchainImagesKHR(VkDevice, VkSwapchainKHR swapchainHandle, uint32_t* count, VkImage* images)
|
||||
{
|
||||
const Swapchain& swapchain = *SwapchainFromHandle(swapchainHandle);
|
||||
if (images == nullptr) {
|
||||
*count = swapchain.numImages;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult result = VK_SUCCESS;
|
||||
uint32_t numImages = swapchain.numImages;
|
||||
if (*count < swapchain.numImages) {
|
||||
numImages = *count;
|
||||
result = VK_INCOMPLETE;
|
||||
}
|
||||
for (uint32_t i = 0; i < numImages; i++) {
|
||||
images[i] = swapchain.images[i].image;
|
||||
}
|
||||
*count = numImages;
|
||||
return result;
|
||||
}
|
||||
|
||||
using namespace OHOS;
|
||||
GraphicPixelFormat GetPixelFormat(VkFormat format)
|
||||
{
|
||||
GraphicPixelFormat nativeFormat = GRAPHIC_PIXEL_FMT_RGBA_8888;
|
||||
switch (format) {
|
||||
case VK_FORMAT_R8G8B8A8_UNORM:
|
||||
case VK_FORMAT_R8G8B8A8_SRGB:
|
||||
nativeFormat = GRAPHIC_PIXEL_FMT_RGBA_8888;
|
||||
break;
|
||||
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
||||
nativeFormat = GRAPHIC_PIXEL_FMT_RGB_565;
|
||||
break;
|
||||
default:
|
||||
WLOGE("unsupported swapchain format %{public}d", format);
|
||||
break;
|
||||
}
|
||||
return nativeFormat;
|
||||
}
|
||||
|
||||
GraphicColorDataSpace GetColorDataspace(VkColorSpaceKHR colorspace)
|
||||
{
|
||||
switch (colorspace) {
|
||||
case VK_COLOR_SPACE_SRGB_NONLINEAR_KHR:
|
||||
return GRAPHIC_BT709_SRGB_FULL;
|
||||
case VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT:
|
||||
return GRAPHIC_DCI_P3_GAMMA26_FULL;
|
||||
case VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT:
|
||||
return GRAPHIC_BT709_LINEAR_EXTENDED;
|
||||
case VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT:
|
||||
return GRAPHIC_BT709_SRGB_EXTENDED;
|
||||
case VK_COLOR_SPACE_DCI_P3_LINEAR_EXT:
|
||||
return GRAPHIC_DCI_P3_LINEAR_FULL;
|
||||
case VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT:
|
||||
return GRAPHIC_DCI_P3_GAMMA26_FULL;
|
||||
case VK_COLOR_SPACE_BT709_LINEAR_EXT:
|
||||
return GRAPHIC_BT709_LINEAR_FULL;
|
||||
case VK_COLOR_SPACE_BT709_NONLINEAR_EXT:
|
||||
return GRAPHIC_BT709_SRGB_FULL;
|
||||
case VK_COLOR_SPACE_BT2020_LINEAR_EXT:
|
||||
return GRAPHIC_BT2020_LINEAR_FULL;
|
||||
case VK_COLOR_SPACE_HDR10_ST2084_EXT:
|
||||
return GRAPHIC_BT2020_ST2084_FULL;
|
||||
case VK_COLOR_SPACE_DOLBYVISION_EXT:
|
||||
return GRAPHIC_BT2020_ST2084_FULL;
|
||||
case VK_COLOR_SPACE_HDR10_HLG_EXT:
|
||||
return GRAPHIC_BT2020_HLG_FULL;
|
||||
case VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT:
|
||||
return static_cast<GraphicColorDataSpace>(GRAPHIC_GAMUT_ADOBE_RGB |
|
||||
GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRECISION_FULL);
|
||||
case VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT:
|
||||
return GRAPHIC_ADOBE_RGB_GAMMA22_FULL;
|
||||
default:
|
||||
return GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsFencePending(int fd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReleaseSwapchainImage(VkDevice device, NativeWindow* window, int releaseFence, Swapchain::Image& image,
|
||||
bool deferIfPending)
|
||||
{
|
||||
if (image.requested) {
|
||||
if (releaseFence >= 0) {
|
||||
if (image.requestFence >= 0) {
|
||||
close(image.requestFence);
|
||||
}
|
||||
} else {
|
||||
releaseFence = image.requestFence;
|
||||
}
|
||||
image.requestFence = -1;
|
||||
|
||||
if (window) {
|
||||
NativeWindowCancelBuffer(window, image.buffer);
|
||||
} else {
|
||||
if (releaseFence >= 0) {
|
||||
close(releaseFence);
|
||||
}
|
||||
}
|
||||
image.requested = false;
|
||||
}
|
||||
|
||||
if (deferIfPending && IsFencePending(image.releaseFence)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (image.releaseFence >= 0) {
|
||||
close(image.releaseFence);
|
||||
image.releaseFence = -1;
|
||||
}
|
||||
|
||||
if (image.image) {
|
||||
vulkan::driver::DestroyImage(device, image.image, nullptr);
|
||||
image.image = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void ReleaseSwapchain(VkDevice device, Swapchain* swapchain)
|
||||
{
|
||||
if (swapchain->surface.swapchainHandle != HandleFromSwapchain(swapchain)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < swapchain->numImages; i++) {
|
||||
if (!swapchain->images[i].requested) {
|
||||
ReleaseSwapchainImage(device, nullptr, -1, swapchain->images[i], true);
|
||||
}
|
||||
}
|
||||
swapchain->surface.swapchainHandle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
int TranslateVulkanToNativeTransform(VkSurfaceTransformFlagBitsKHR transform)
|
||||
{
|
||||
return ROTATE_NONE;
|
||||
}
|
||||
|
||||
static void DestroySwapchainInternal(VkDevice device, VkSwapchainKHR swapchainHandle,
|
||||
const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
Swapchain* swapchain = SwapchainFromHandle(swapchainHandle);
|
||||
if (!swapchain) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool active = swapchain->surface.swapchainHandle == swapchainHandle;
|
||||
NativeWindow* window = active ? swapchain->surface.window : nullptr;
|
||||
|
||||
for (uint32_t i = 0; i < swapchain->numImages; i++) {
|
||||
ReleaseSwapchainImage(device, window, -1, swapchain->images[i], false);
|
||||
}
|
||||
|
||||
if (active) {
|
||||
swapchain->surface.swapchainHandle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
if (!allocator) {
|
||||
allocator = &vulkan::driver::GetDefaultAllocator();
|
||||
}
|
||||
|
||||
swapchain->~Swapchain();
|
||||
allocator->pfnFree(allocator->pUserData, swapchain);
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult SetWindowInfo(const VkSwapchainCreateInfoKHR* createInfo, int32_t* numImages)
|
||||
{
|
||||
GraphicPixelFormat pixelFormat = GetPixelFormat(createInfo->imageFormat);
|
||||
Surface& surface = *SurfaceFromHandle(createInfo->surface);
|
||||
|
||||
NativeWindow* window = surface.window;
|
||||
int err = NativeWindowHandleOpt(window, SET_FORMAT, pixelFormat);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
WLOGE("native_window_set_buffers_format(%{public}d) failed: (%{public}d)", pixelFormat, err);
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
|
||||
err = NativeWindowHandleOpt(window, SET_BUFFER_GEOMETRY,
|
||||
static_cast<int>(createInfo->imageExtent.width),
|
||||
static_cast<int>(createInfo->imageExtent.height));
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
WLOGE("native_window_set_buffers_dimensions(%{public}d,%{public}d) failed: (%{public}d)",
|
||||
createInfo->imageExtent.width, createInfo->imageExtent.height, err);
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
|
||||
if (createInfo->presentMode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR ||
|
||||
createInfo->presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR) {
|
||||
*numImages = 1;
|
||||
}
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult SetSwapchainCreateInfo(VkDevice device, const VkSwapchainCreateInfoKHR* createInfo,
|
||||
int32_t* numImages)
|
||||
{
|
||||
GraphicColorDataSpace color_data_space = GetColorDataspace(createInfo->imageColorSpace);
|
||||
if (color_data_space == GRAPHIC_COLOR_DATA_SPACE_UNKNOWN) {
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
if (createInfo->oldSwapchain != VK_NULL_HANDLE) {
|
||||
ReleaseSwapchain(device, SwapchainFromHandle(createInfo->oldSwapchain));
|
||||
}
|
||||
|
||||
return SetWindowInfo(createInfo, numImages);
|
||||
}
|
||||
|
||||
void InitImageCreateInfo(const VkSwapchainCreateInfoKHR* createInfo, VkImageCreateInfo* imageCreate)
|
||||
{
|
||||
imageCreate->sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageCreate->flags = 0u;
|
||||
imageCreate->imageType = VK_IMAGE_TYPE_2D;
|
||||
imageCreate->format = createInfo->imageFormat;
|
||||
imageCreate->extent = {0, 0, 1};
|
||||
imageCreate->mipLevels = 1;
|
||||
imageCreate->arrayLayers = 1;
|
||||
imageCreate->samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageCreate->tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
imageCreate->usage = createInfo->imageUsage;
|
||||
imageCreate->sharingMode = createInfo->imageSharingMode;
|
||||
imageCreate->queueFamilyIndexCount = createInfo->queueFamilyIndexCount;
|
||||
imageCreate->pQueueFamilyIndices = createInfo->pQueueFamilyIndices;
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR VkResult CreateImages(int32_t& numImages, Swapchain* swapchain, const VkSwapchainCreateInfoKHR* createInfo,
|
||||
VkImageCreateInfo& imageCreate, VkDevice device)
|
||||
{
|
||||
Surface& surface = *SurfaceFromHandle(createInfo->surface);
|
||||
NativeWindow* window = surface.window;
|
||||
if (createInfo->oldSwapchain != VK_NULL_HANDLE) {
|
||||
WLOGI("recreate swapchain ,clean buffer queue");
|
||||
window->surface->CleanCache();
|
||||
}
|
||||
VkResult result = VK_SUCCESS;
|
||||
for (int32_t i = 0; i < numImages; i++) {
|
||||
Swapchain::Image& img = swapchain->images[i];
|
||||
|
||||
NativeWindowBuffer* buffer;
|
||||
int err = NativeWindowRequestBuffer(window, &buffer, &img.requestFence);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
WLOGE("dequeueBuffer[%{public}u] failed: (%{public}d)", i, err);
|
||||
result = VK_ERROR_SURFACE_LOST_KHR;
|
||||
break;
|
||||
}
|
||||
img.buffer = buffer;
|
||||
img.requested = true;
|
||||
imageCreate.extent = VkExtent3D {static_cast<uint32_t>(img.buffer->sfbuffer->GetSurfaceBufferWidth()),
|
||||
static_cast<uint32_t>(img.buffer->sfbuffer->GetSurfaceBufferHeight()), 1};
|
||||
((VkNativeBufferOpenHarmony*)(imageCreate.pNext))->handle = img.buffer->sfbuffer->GetBufferHandle();
|
||||
result = vulkan::driver::CreateImage(device, &imageCreate, nullptr, &img.image);
|
||||
if (result != VK_SUCCESS) {
|
||||
WLOGD("vkCreateImage native buffer failed: %{public}u", result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WLOGD("swapchain init shared %{public}d", swapchain->shared);
|
||||
for (int32_t i = 0; i < numImages; i++) {
|
||||
Swapchain::Image& img = swapchain->images[i];
|
||||
if (img.requested) {
|
||||
if (!swapchain->shared) {
|
||||
NativeWindowCancelBuffer(window, img.buffer);
|
||||
img.requestFence = -1;
|
||||
img.requested = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* createInfo,
|
||||
const VkAllocationCallbacks* allocator, VkSwapchainKHR* swapchainHandle)
|
||||
{
|
||||
Surface& surface = *SurfaceFromHandle(createInfo->surface);
|
||||
if (surface.swapchainHandle != createInfo->oldSwapchain) {
|
||||
return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
|
||||
}
|
||||
|
||||
int32_t numImages = static_cast<int32_t>(MIN_BUFFER_SIZE);
|
||||
VkResult result = SetSwapchainCreateInfo(device, createInfo, &numImages);
|
||||
if (result != VK_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
if (!allocator) {
|
||||
allocator = &vulkan::driver::GetDefaultAllocator();
|
||||
}
|
||||
|
||||
void* mem = allocator->pfnAllocation(allocator->pUserData, sizeof(Swapchain), alignof(Swapchain),
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!mem) {
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
Swapchain* swapchain = new (mem) Swapchain(surface, numImages, createInfo->presentMode,
|
||||
TranslateVulkanToNativeTransform(createInfo->preTransform));
|
||||
VkSwapchainImageCreateInfoOpenHarmony swapchainImageCreate = {
|
||||
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_OPENHARMONY,
|
||||
.pNext = nullptr,
|
||||
};
|
||||
VkNativeBufferOpenHarmony imageNativeBuffer = {
|
||||
.sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_OPENHARMONY,
|
||||
.pNext = &swapchainImageCreate,
|
||||
};
|
||||
|
||||
VkImageCreateInfo imageCreate = {
|
||||
.pNext = &imageNativeBuffer,
|
||||
};
|
||||
|
||||
InitImageCreateInfo(createInfo, &imageCreate);
|
||||
result = CreateImages(numImages, swapchain, createInfo, imageCreate, device);
|
||||
if (result != VK_SUCCESS) {
|
||||
DestroySwapchainInternal(device, HandleFromSwapchain(swapchain), allocator);
|
||||
return result;
|
||||
}
|
||||
|
||||
surface.swapchainHandle = HandleFromSwapchain(swapchain);
|
||||
*swapchainHandle = surface.swapchainHandle;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
void DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchainHandle,
|
||||
const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
DestroySwapchainInternal(device, swapchainHandle, allocator);
|
||||
}
|
||||
|
||||
|
||||
VKAPI_ATTR VkResult AcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchainHandle, uint64_t timeout,
|
||||
VkSemaphore semaphore, VkFence vkFence, uint32_t* imageIndex)
|
||||
{
|
||||
Swapchain& swapchain = *SwapchainFromHandle(swapchainHandle);
|
||||
NativeWindow* nativeWindow = swapchain.surface.window;
|
||||
VkResult result;
|
||||
|
||||
if (swapchain.surface.swapchainHandle != swapchainHandle) {
|
||||
return VK_ERROR_OUT_OF_DATE_KHR;
|
||||
}
|
||||
|
||||
if (swapchain.shared) {
|
||||
*imageIndex = 0;
|
||||
result = vulkan::driver::SetNativeFenceFdOpenHarmony(device, -1, semaphore, vkFence);
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeWindowBuffer* nativeWindowBuffer;
|
||||
int fence;
|
||||
int32_t ret = NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fence);
|
||||
if (ret != OHOS::GSERROR_OK) {
|
||||
WLOGE("dequeueBuffer failed: (%{public}d)", ret);
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
|
||||
uint32_t index = 0;
|
||||
while (index < swapchain.numImages) {
|
||||
if (swapchain.images[index].buffer->sfbuffer == nativeWindowBuffer->sfbuffer) {
|
||||
swapchain.images[index].requested = true;
|
||||
swapchain.images[index].requestFence = fence;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index == swapchain.numImages) {
|
||||
WLOGE("dequeueBuffer returned unrecognized buffer");
|
||||
if (NativeWindowCancelBuffer(nativeWindow, nativeWindowBuffer) != OHOS::GSERROR_OK) {
|
||||
WLOGE("NativeWindowCancelBuffer failed: (%{public}d)", ret);
|
||||
}
|
||||
return VK_ERROR_OUT_OF_DATE_KHR;
|
||||
}
|
||||
|
||||
result = vulkan::driver::SetNativeFenceFdOpenHarmony(device, -1, semaphore, vkFence);
|
||||
if (result != VK_SUCCESS) {
|
||||
if (NativeWindowCancelBuffer(nativeWindow, nativeWindowBuffer) != OHOS::GSERROR_OK) {
|
||||
WLOGE("NativeWindowCancelBuffer failed: (%{public}d)", ret);
|
||||
}
|
||||
swapchain.images[index].requested = false;
|
||||
swapchain.images[index].requestFence = -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
*imageIndex = index;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR
|
||||
VkResult AcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex)
|
||||
{
|
||||
return AcquireNextImageKHR(device, pAcquireInfo->swapchain, pAcquireInfo->timeout,
|
||||
pAcquireInfo->semaphore, pAcquireInfo->fence, pImageIndex);
|
||||
}
|
||||
|
||||
const VkPresentRegionKHR* GetPresentRegion(
|
||||
const VkPresentRegionKHR* regions, const Swapchain& swapchain, uint32_t index)
|
||||
{
|
||||
return (regions && !swapchain.mailboxMode) ? ®ions[index] : nullptr;
|
||||
}
|
||||
|
||||
VkResult GetReleaseFence(VkQueue queue, const VkPresentInfoKHR* presentInfo,
|
||||
Swapchain::Image& img, int32_t &fence)
|
||||
{
|
||||
VkResult result = vulkan::driver::GetNativeFenceFdOpenHarmony(queue, presentInfo->waitSemaphoreCount,
|
||||
presentInfo->pWaitSemaphores, img.image, &fence);
|
||||
if (img.releaseFence >= 0) {
|
||||
close(img.releaseFence);
|
||||
img.releaseFence = -1;
|
||||
}
|
||||
if (fence >= 0) {
|
||||
img.releaseFence = dup(fence);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Region::Rect* GetRegionRect(
|
||||
const VkAllocationCallbacks* defaultAllocator, struct Region::Rect** rects, int32_t rectangleCount)
|
||||
{
|
||||
return static_cast<struct Region::Rect*>(
|
||||
defaultAllocator->pfnReallocation(
|
||||
defaultAllocator->pUserData, *rects,
|
||||
sizeof(Region::Rect) * rectangleCount,
|
||||
alignof(Region::Rect), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND));
|
||||
}
|
||||
|
||||
void InitRegionRect(const VkRectLayerKHR* layer, struct Region::Rect* rect)
|
||||
{
|
||||
rect->x = layer->offset.x;
|
||||
rect->y = layer->offset.y;
|
||||
rect->w = layer->extent.width;
|
||||
rect->h = layer->extent.height;
|
||||
}
|
||||
|
||||
const VkPresentRegionKHR* GetPresentRegions(const VkPresentInfoKHR* presentInfo)
|
||||
{
|
||||
const VkPresentRegionsKHR* presentRegions = nullptr;
|
||||
const VkPresentRegionsKHR* nextRegions = reinterpret_cast<const VkPresentRegionsKHR*>(presentInfo->pNext);
|
||||
while (nextRegions != nullptr) {
|
||||
if (nextRegions->sType == VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR) {
|
||||
presentRegions = nextRegions;
|
||||
}
|
||||
nextRegions = reinterpret_cast<const VkPresentRegionsKHR*>(nextRegions->pNext);
|
||||
}
|
||||
|
||||
if (presentRegions == nullptr) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return presentRegions->pRegions;
|
||||
}
|
||||
}
|
||||
|
||||
VkResult FlushBuffer(const VkPresentRegionKHR* region, struct Region::Rect* rects,
|
||||
Swapchain& swapchain, Swapchain::Image& img, int32_t fence)
|
||||
{
|
||||
const VkAllocationCallbacks* defaultAllocator = &vulkan::driver::GetDefaultAllocator();
|
||||
Region localRegion;
|
||||
if (memset_s(&localRegion, sizeof(localRegion), 0, sizeof(Region)) != EOK) {
|
||||
return VK_ERROR_SURFACE_LOST_KHR;
|
||||
}
|
||||
if (region != nullptr) {
|
||||
int32_t rectangleCount = region->rectangleCount;
|
||||
if (rectangleCount > 0) {
|
||||
struct Region::Rect* tmpRects = GetRegionRect(defaultAllocator, &rects, rectangleCount);
|
||||
if (tmpRects != nullptr) {
|
||||
rects = tmpRects;
|
||||
} else {
|
||||
rectangleCount = 0;
|
||||
}
|
||||
}
|
||||
for (int32_t r = 0; r < rectangleCount; ++r) {
|
||||
InitRegionRect(®ion->pRectangles[r], &rects[r]);
|
||||
}
|
||||
|
||||
localRegion.rects = rects;
|
||||
localRegion.rectNumber = rectangleCount;
|
||||
}
|
||||
NativeWindow* window = swapchain.surface.window;
|
||||
if (img.buffer != nullptr && window != nullptr) {
|
||||
img.buffer->uiTimestamp = window->uiTimestamp;
|
||||
}
|
||||
// the acquire fence will be close by BufferQueue module
|
||||
int err = NativeWindowFlushBuffer(window, img.buffer, fence, localRegion);
|
||||
VkResult scResult = VK_SUCCESS;
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
WLOGE("queueBuffer failed: (%{public}d)", err);
|
||||
scResult = VK_ERROR_SURFACE_LOST_KHR;
|
||||
} else {
|
||||
if (img.requestFence >= 0) {
|
||||
close(img.requestFence);
|
||||
img.requestFence = -1;
|
||||
}
|
||||
img.requested = false;
|
||||
}
|
||||
|
||||
if (swapchain.shared && scResult == VK_SUCCESS) {
|
||||
NativeWindowBuffer* buffer = nullptr;
|
||||
int releaseFence = -1;
|
||||
err = NativeWindowRequestBuffer(window, &buffer, &releaseFence);
|
||||
if (err != OHOS::GSERROR_OK) {
|
||||
scResult = VK_ERROR_SURFACE_LOST_KHR;
|
||||
} else if (img.buffer != buffer) {
|
||||
scResult = VK_ERROR_SURFACE_LOST_KHR;
|
||||
} else {
|
||||
img.requestFence = releaseFence;
|
||||
img.requested = true;
|
||||
}
|
||||
}
|
||||
return scResult;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* presentInfo)
|
||||
{
|
||||
VkResult ret = VK_SUCCESS;
|
||||
|
||||
const VkPresentRegionKHR* regions = GetPresentRegions(presentInfo);
|
||||
const VkAllocationCallbacks* defaultAllocator = &vulkan::driver::GetDefaultAllocator();
|
||||
struct Region::Rect* rects = nullptr;
|
||||
|
||||
for (uint32_t i = 0; i < presentInfo->swapchainCount; i++) {
|
||||
Swapchain& swapchain = *(reinterpret_cast<Swapchain*>(presentInfo->pSwapchains[i]));
|
||||
Swapchain::Image& img = swapchain.images[presentInfo->pImageIndices[i]];
|
||||
const VkPresentRegionKHR* region = GetPresentRegion(regions, swapchain, i);
|
||||
int32_t fence = -1;
|
||||
ret = GetReleaseFence(queue, presentInfo, img, fence);
|
||||
if (swapchain.surface.swapchainHandle == presentInfo->pSwapchains[i]) {
|
||||
if (ret == VK_SUCCESS) {
|
||||
ret = FlushBuffer(region, rects, swapchain, img, fence);
|
||||
} else {
|
||||
ReleaseSwapchain(nullptr, &swapchain);
|
||||
}
|
||||
} else {
|
||||
WLOGE("QueuePresentKHR swapchainHandle != pSwapchains[%{public}d]", i);
|
||||
ReleaseSwapchainImage(nullptr, nullptr, fence, img, true);
|
||||
ret = VK_ERROR_OUT_OF_DATE_KHR;
|
||||
}
|
||||
|
||||
if (presentInfo->pResults) {
|
||||
presentInfo->pResults[i] = ret;
|
||||
}
|
||||
}
|
||||
if (rects != nullptr) {
|
||||
defaultAllocator->pfnFree(defaultAllocator->pUserData, rects);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace driver
|
||||
} // namespace vulkan
|
@ -1,21 +0,0 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"systemtest:systemtest",
|
||||
"unittest:unittest",
|
||||
]
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
module_out_path = "graphic_standard/vulkan_wrapper"
|
||||
|
||||
group("systemtest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":vulkan_wrapper_api_test" ]
|
||||
}
|
||||
|
||||
## SystemTest vulkan_wrapper_api_test {{{
|
||||
ohos_systemtest("vulkan_wrapper_api_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "vulkan_wrapper_api_test.cpp" ]
|
||||
|
||||
include_dirs = [
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface/include",
|
||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/surface",
|
||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client",
|
||||
"//foundation/window/window_manager/interfaces/innerkits",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_wrapper/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
"-Wsign-compare",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface:surface",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//foundation/window/window_manager/wmserver:libwms",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/vulkan-headers:vulkan_headers",
|
||||
"//third_party/zlib:libz",
|
||||
]
|
||||
}
|
||||
## SystemTest vulkan_wrapper_api_test }}}
|
@ -1,332 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <window.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "refbase.h"
|
||||
#include "surface.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "render_context/render_context.h"
|
||||
#include "transaction/rs_transaction.h"
|
||||
#include "ui/rs_surface_extractor.h"
|
||||
#include "ui/rs_surface_node.h"
|
||||
#include "wm/window.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
|
||||
typedef bool (*PFN_IsSupportedVulkan)();
|
||||
|
||||
class VulkanWrapperApiTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
if (libVulkan != nullptr) {
|
||||
dlclose(libVulkan);
|
||||
libVulkan = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static inline PFN_vkCreateInstance vkCreateInstance;
|
||||
static inline PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
|
||||
static inline PFN_vkCreateDevice vkCreateDevice;
|
||||
static inline PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
|
||||
static inline PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
||||
static inline PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||
static inline PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
||||
static inline PFN_vkCreateOHOSSurfaceOpenHarmony vkCreateOHOSSurfaceOpenHarmony;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceSupportKHR fpGetPhysicalDeviceSurfaceSupportKHR;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fpGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fpGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
static inline PFN_vkCreateSwapchainKHR fpCreateSwapchainKHR;
|
||||
static inline PFN_vkDestroySwapchainKHR fpDestroySwapchainKHR;
|
||||
static inline PFN_vkGetSwapchainImagesKHR fpGetSwapchainImagesKHR;
|
||||
static inline PFN_vkAcquireNextImageKHR fpAcquireNextImageKHR;
|
||||
static inline PFN_vkQueuePresentKHR fpQueuePresentKHR;
|
||||
static inline PFN_IsSupportedVulkan fpIsSupportedVulkan;
|
||||
|
||||
static inline void *libVulkan = nullptr;
|
||||
static inline VkInstance instance = nullptr;
|
||||
static inline VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||
static inline VkPhysicalDevice physicalDevice = nullptr;
|
||||
static inline VkDevice device = nullptr;
|
||||
static inline VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||
static inline bool isSupportedVulkan = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: dlopen libvulkan.so
|
||||
* @tc.desc: dlopen libvulkan.so
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, dlopen_Test, TestSize.Level1)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
const char *path = "/system/lib64/libvulkan_wrapper.so";
|
||||
#else
|
||||
const char *path = "/system/lib/libvulkan_wrapper.so";
|
||||
#endif
|
||||
libVulkan = dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||||
EXPECT_NE(libVulkan, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Load base function pointers
|
||||
* @tc.desc: Load base function pointers
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, LoadFuncPtr001, TestSize.Level1)
|
||||
{
|
||||
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(
|
||||
dlsym(libVulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
EXPECT_NE(vkEnumerateInstanceExtensionProperties, nullptr);
|
||||
vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(dlsym(libVulkan, "vkCreateInstance"));
|
||||
EXPECT_NE(vkCreateInstance, nullptr);
|
||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libVulkan, "vkGetInstanceProcAddr"));
|
||||
EXPECT_NE(vkGetInstanceProcAddr, nullptr);
|
||||
vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(dlsym(libVulkan, "vkGetDeviceProcAddr"));
|
||||
EXPECT_NE(vkGetDeviceProcAddr, nullptr);
|
||||
fpIsSupportedVulkan = reinterpret_cast<PFN_IsSupportedVulkan>(dlsym(libVulkan, "IsSupportedVulkan"));
|
||||
EXPECT_NE(fpIsSupportedVulkan, nullptr);
|
||||
isSupportedVulkan = fpIsSupportedVulkan();
|
||||
std::cout << "support vulkan :" << isSupportedVulkan << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: create vkInstance
|
||||
* @tc.desc: create vkInstance
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, createVkInstance_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
VkApplicationInfo appInfo = {};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "pApplicationName";
|
||||
appInfo.pEngineName = "pEngineName";
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
std::vector<const char*> instanceExtensions = { VK_KHR_SURFACE_EXTENSION_NAME };
|
||||
instanceExtensions.push_back(VK_OPENHARMONY_OHOS_SURFACE_EXTENSION_NAME);
|
||||
|
||||
VkInstanceCreateInfo instanceCreateInfo = {};
|
||||
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
instanceCreateInfo.pNext = NULL;
|
||||
instanceCreateInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
if (instanceExtensions.size() > 0) {
|
||||
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
|
||||
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
|
||||
}
|
||||
|
||||
VkResult err = vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(instance, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Load instance based Vulkan function pointers
|
||||
* @tc.desc: Load instance based Vulkan function pointers
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, LoadFuncPtr002, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(
|
||||
vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"));
|
||||
EXPECT_NE(vkEnumeratePhysicalDevices, nullptr);
|
||||
vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(
|
||||
vkGetInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
EXPECT_NE(vkCreateDevice, nullptr);
|
||||
vkCreateOHOSSurfaceOpenHarmony = reinterpret_cast<PFN_vkCreateOHOSSurfaceOpenHarmony>(
|
||||
vkGetInstanceProcAddr(instance, "vkCreateOHOSSurfaceOpenHarmony"));
|
||||
EXPECT_NE(vkCreateOHOSSurfaceOpenHarmony, nullptr);
|
||||
vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkDestroySurfaceKHR"));
|
||||
EXPECT_NE(vkDestroySurfaceKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceSupportKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceSupportKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfaceCapabilitiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceCapabilitiesKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceFormatsKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfacePresentModesKHR, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: create device
|
||||
* @tc.desc: create device
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, createDevice_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
uint32_t gpuCount = 0;
|
||||
VkResult err = vkEnumeratePhysicalDevices(instance, &gpuCount, nullptr);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(gpuCount, 0);
|
||||
std::vector<VkPhysicalDevice> physicalDevices(gpuCount);
|
||||
err = vkEnumeratePhysicalDevices(instance, &gpuCount, physicalDevices.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
physicalDevice = physicalDevices[0];
|
||||
|
||||
std::vector<const char*> deviceExtensions;
|
||||
deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||
VkDeviceCreateInfo deviceCreateInfo = {};
|
||||
deviceCreateInfo.enabledExtensionCount = (uint32_t)deviceExtensions.size();
|
||||
deviceCreateInfo.ppEnabledExtensionNames = deviceExtensions.data();
|
||||
|
||||
VkDevice logicalDevice;
|
||||
err = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &logicalDevice);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(logicalDevice, nullptr);
|
||||
device = logicalDevice;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Load device based Vulkan function pointers
|
||||
* @tc.desc: Load device based Vulkan function pointers
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, LoadFuncPtr003, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
fpCreateSwapchainKHR = reinterpret_cast<PFN_vkCreateSwapchainKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkCreateSwapchainKHR"));
|
||||
EXPECT_NE(fpCreateSwapchainKHR, nullptr);
|
||||
fpDestroySwapchainKHR = reinterpret_cast<PFN_vkDestroySwapchainKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkDestroySwapchainKHR"));
|
||||
EXPECT_NE(fpDestroySwapchainKHR, nullptr);
|
||||
fpGetSwapchainImagesKHR = reinterpret_cast<PFN_vkGetSwapchainImagesKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkGetSwapchainImagesKHR"));
|
||||
EXPECT_NE(fpGetSwapchainImagesKHR, nullptr);
|
||||
fpAcquireNextImageKHR = reinterpret_cast<PFN_vkAcquireNextImageKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkAcquireNextImageKHR"));
|
||||
EXPECT_NE(fpAcquireNextImageKHR, nullptr);
|
||||
fpQueuePresentKHR = reinterpret_cast<PFN_vkQueuePresentKHR>(vkGetDeviceProcAddr(device, "vkQueuePresentKHR"));
|
||||
EXPECT_NE(fpQueuePresentKHR, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: create surface
|
||||
* @tc.desc: create surface
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, createSurface_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
constexpr int windowLeft = 100;
|
||||
constexpr int windowTop = 200;
|
||||
constexpr int windowWidth = 360;
|
||||
constexpr int windowHeight = 360;
|
||||
OHOS::Rosen::Rect rect = {windowLeft, windowTop, windowWidth, windowHeight};
|
||||
OHOS::sptr<OHOS::Rosen::WindowOption> option(new OHOS::Rosen::WindowOption());
|
||||
option->SetDisplayId(0);
|
||||
option->SetWindowRect(rect);
|
||||
option->SetWindowType(OHOS::Rosen::WindowType::APP_MAIN_WINDOW_BASE);
|
||||
option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
option->SetWindowName("createSurface_test");
|
||||
OHOS::sptr<OHOS::Rosen::Window> window = OHOS::Rosen::Window::Create(option->GetWindowName(), option);
|
||||
EXPECT_NE(window, nullptr);
|
||||
|
||||
OHOS::Rosen::RSTransaction::FlushImplicitTransaction();
|
||||
window->Show();
|
||||
|
||||
auto surfaceNode = window->GetSurfaceNode();
|
||||
OHOS::sptr<OHOS::Surface> surf = surfaceNode->GetSurface();
|
||||
OHNativeWindow* nativeWindow = CreateNativeWindowFromSurface(&surf);
|
||||
EXPECT_NE(nativeWindow, nullptr);
|
||||
VkOHOSSurfaceCreateInfoOpenHarmony surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_OHOS_SURFACE_CREATE_INFO_OPENHARMONY;
|
||||
surfaceCreateInfo.window = nativeWindow;
|
||||
VkResult err = vkCreateOHOSSurfaceOpenHarmony(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: create swapChain
|
||||
* @tc.desc: create swapChain
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperApiTest, createSwapChain_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
VkSwapchainKHR oldSwapchain = swapChain;
|
||||
VkSwapchainCreateInfoKHR swapchainCI = {};
|
||||
swapchainCI.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
swapchainCI.surface = surface;
|
||||
VkSurfaceCapabilitiesKHR surfCaps;
|
||||
VkResult err = fpGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &surfCaps);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
uint32_t desiredNumberOfSwapchainImages = surfCaps.minImageCount + 1;
|
||||
swapchainCI.minImageCount = desiredNumberOfSwapchainImages;
|
||||
swapchainCI.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;
|
||||
uint32_t formatCount;
|
||||
err = fpGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, NULL);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_GT(formatCount, 0);
|
||||
std::vector<VkSurfaceFormatKHR> surfaceFormats(formatCount);
|
||||
err = fpGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, surfaceFormats.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
swapchainCI.imageColorSpace = surfaceFormats[0].colorSpace;
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
swapchainCI.imageExtent = { width, height };
|
||||
swapchainCI.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
swapchainCI.preTransform = (VkSurfaceTransformFlagBitsKHR)VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
swapchainCI.imageArrayLayers = 1;
|
||||
swapchainCI.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
swapchainCI.queueFamilyIndexCount = 0;
|
||||
swapchainCI.presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
swapchainCI.oldSwapchain = oldSwapchain;
|
||||
swapchainCI.clipped = VK_TRUE;
|
||||
swapchainCI.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChain);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(swapChain, VK_NULL_HANDLE);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
module_out_path = "graphic_standard/vulkan_wrapper"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":vulkan_wrapper_unit_test" ]
|
||||
}
|
||||
|
||||
ohos_unittest("vulkan_wrapper_unit_test") {
|
||||
module_out_path = module_out_path
|
||||
sources = [
|
||||
"../../src/driver.cpp",
|
||||
"../../src/driver_loader.cpp",
|
||||
"../../src/swapchain.cpp",
|
||||
"vulkan_wrapper_unit_test.cpp",
|
||||
]
|
||||
deps = [ ":vulkan_wrapper_test_common" ]
|
||||
}
|
||||
|
||||
config("vulkan_wrapper_test_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface/include",
|
||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/surface",
|
||||
"//foundation/graphic/graphic_2d/interfaces/inner_api/common",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client",
|
||||
"//foundation/window/window_manager/interfaces/innerkits",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_wrapper/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("vulkan_wrapper_test_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
public_configs = [ ":vulkan_wrapper_test_common_public_config" ]
|
||||
|
||||
public_deps = [
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/graphic/graphic_2d:libsurface",
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface:surface",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//foundation/window/window_manager/wmserver:libwms",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/vulkan-headers:vulkan_headers",
|
||||
"//third_party/zlib:libz",
|
||||
]
|
||||
subsystem_name = "graphic"
|
||||
part_name = "graphic_standard"
|
||||
}
|
@ -1,875 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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, Hardware
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <window.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "refbase.h"
|
||||
#include "surface.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "driver.h"
|
||||
#include "driver_loader.h"
|
||||
#include "swapchain.h"
|
||||
#include "render_context/render_context.h"
|
||||
#include "transaction/rs_transaction.h"
|
||||
#include "ui/rs_surface_extractor.h"
|
||||
#include "ui/rs_surface_node.h"
|
||||
#include "wm/window.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace vulkan::driver {
|
||||
typedef bool (*PFN_IsSupportedVulkan)();
|
||||
class VulkanWrapperUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase();
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
uint32_t getQueueFamilyIndex(VkQueueFlagBits queueFlags);
|
||||
OHNativeWindow* createNativeWindow(std::string name);
|
||||
VkSwapchainCreateInfoKHR getSwapchainCreateInfo(VkFormat imageFormat, VkColorSpaceKHR imageColorSpace);
|
||||
|
||||
static inline PFN_vkCreateInstance vkCreateInstance;
|
||||
static inline PFN_vkDestroyInstance vkDestroyInstance;
|
||||
static inline PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
|
||||
static inline PFN_vkCreateDevice vkCreateDevice;
|
||||
static inline PFN_vkDestroyDevice vkDestroyDevice;
|
||||
static inline PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
|
||||
static inline PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
|
||||
static inline PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
|
||||
static inline PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
||||
static inline PFN_vkCreateOHOSSurfaceOpenHarmony vkCreateOHOSSurfaceOpenHarmony;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fpGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fpGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
static inline PFN_vkCreateSwapchainKHR fpCreateSwapchainKHR;
|
||||
static inline PFN_vkDestroySwapchainKHR fpDestroySwapchainKHR;
|
||||
static inline PFN_vkAcquireNextImage2KHR fpAcquireNextImage2KHR;
|
||||
static inline PFN_vkQueuePresentKHR fpQueuePresentKHR;
|
||||
static inline PFN_IsSupportedVulkan fpIsSupportedVulkan;
|
||||
static inline PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
|
||||
static inline PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
|
||||
static inline PFN_vkGetPhysicalDeviceFeatures vkGetPhysicalDeviceFeatures;
|
||||
static inline PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
|
||||
static inline PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
|
||||
static inline PFN_vkGetSwapchainImagesKHR fpGetSwapchainImagesKHR;
|
||||
|
||||
static inline void *libVulkan = nullptr;
|
||||
static inline VkInstance instance = nullptr;
|
||||
static inline VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||
static inline VkPhysicalDevice physicalDevice = nullptr;
|
||||
static inline VkDevice device = nullptr;
|
||||
static inline VkSurfaceCapabilitiesKHR surfCaps = {};
|
||||
static inline VkSurfaceFormatKHR surfaceFormat = {};
|
||||
static inline VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||
static inline VkSwapchainKHR swapChain2 = VK_NULL_HANDLE;
|
||||
static inline VkSemaphore semaphore = VK_NULL_HANDLE;
|
||||
static inline bool isSupportedVulkan = false;
|
||||
static inline std::vector<VkQueueFamilyProperties> queueProps;
|
||||
static inline uint32_t queueCount;
|
||||
};
|
||||
|
||||
VkSwapchainCreateInfoKHR VulkanWrapperUnitTest::getSwapchainCreateInfo(
|
||||
VkFormat imageFormat, VkColorSpaceKHR imageColorSpace)
|
||||
{
|
||||
VkSwapchainCreateInfoKHR swapchainCI = {};
|
||||
swapchainCI.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
swapchainCI.surface = surface;
|
||||
uint32_t desiredNumberOfSwapchainImages = surfCaps.minImageCount + 1;
|
||||
swapchainCI.minImageCount = desiredNumberOfSwapchainImages;
|
||||
swapchainCI.imageFormat = imageFormat;
|
||||
swapchainCI.imageColorSpace = imageColorSpace;
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
swapchainCI.imageExtent = { width, height };
|
||||
swapchainCI.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
swapchainCI.preTransform = (VkSurfaceTransformFlagBitsKHR)VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
swapchainCI.imageArrayLayers = 1;
|
||||
swapchainCI.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
swapchainCI.queueFamilyIndexCount = 0;
|
||||
swapchainCI.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
swapchainCI.oldSwapchain = swapChain;
|
||||
swapchainCI.clipped = VK_TRUE;
|
||||
swapchainCI.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
return swapchainCI;
|
||||
}
|
||||
|
||||
OHNativeWindow* VulkanWrapperUnitTest::createNativeWindow(std::string name)
|
||||
{
|
||||
constexpr int windowLeft = 100;
|
||||
constexpr int windowTop = 200;
|
||||
constexpr int windowWidth = 360;
|
||||
constexpr int windowHeight = 360;
|
||||
OHOS::Rosen::Rect rect = {windowLeft, windowTop, windowWidth, windowHeight};
|
||||
OHOS::sptr<OHOS::Rosen::WindowOption> option(new OHOS::Rosen::WindowOption());
|
||||
option->SetDisplayId(0);
|
||||
option->SetWindowRect(rect);
|
||||
option->SetWindowType(OHOS::Rosen::WindowType::APP_MAIN_WINDOW_BASE);
|
||||
option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
option->SetWindowName(name.c_str());
|
||||
OHOS::sptr<OHOS::Rosen::Window> window = OHOS::Rosen::Window::Create(option->GetWindowName(), option);
|
||||
EXPECT_NE(window, nullptr);
|
||||
|
||||
OHOS::Rosen::RSTransaction::FlushImplicitTransaction();
|
||||
window->Show();
|
||||
|
||||
auto surfaceNode = window->GetSurfaceNode();
|
||||
OHOS::sptr<OHOS::Surface> surf = surfaceNode->GetSurface();
|
||||
OHNativeWindow* nativeWindow = CreateNativeWindowFromSurface(&surf);
|
||||
return nativeWindow;
|
||||
}
|
||||
|
||||
uint32_t VulkanWrapperUnitTest::getQueueFamilyIndex(VkQueueFlagBits queueFlags)
|
||||
{
|
||||
decltype(queueProps.size()) i = 0;
|
||||
if (queueFlags & VK_QUEUE_COMPUTE_BIT) {
|
||||
for (i = 0; i < queueProps.size(); i++) {
|
||||
if ((queueProps[i].queueFlags & queueFlags) &&
|
||||
((queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (queueFlags & VK_QUEUE_TRANSFER_BIT) {
|
||||
for (i = 0; i < queueProps.size(); i++) {
|
||||
if ((queueProps[i].queueFlags & queueFlags) &&
|
||||
((queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) &&
|
||||
((queueProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < queueProps.size(); i++) {
|
||||
if (queueProps[i].queueFlags & queueFlags) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
std::cout << "Could not find a matching queue family index" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void VulkanWrapperUnitTest::TearDownTestCase()
|
||||
{
|
||||
if (device != nullptr) {
|
||||
if (swapChain != VK_NULL_HANDLE) {
|
||||
fpDestroySwapchainKHR(device, swapChain, nullptr);
|
||||
}
|
||||
vkDestroyDevice(device, nullptr);
|
||||
}
|
||||
if (instance != nullptr) {
|
||||
if (surface != VK_NULL_HANDLE) {
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
}
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: dlopen
|
||||
* @tc.desc: dlopen
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, dlopen_Test, TestSize.Level1)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
const char *path = "/system/lib64/libvulkan_wrapper.so";
|
||||
#else
|
||||
const char *path = "/system/lib/libvulkan_wrapper.so";
|
||||
#endif
|
||||
libVulkan = dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||||
EXPECT_NE(libVulkan, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: load function pointer 001
|
||||
* @tc.desc: load function pointer 001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, LoadFuncPtr001, TestSize.Level1)
|
||||
{
|
||||
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(
|
||||
dlsym(libVulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
EXPECT_NE(vkEnumerateInstanceExtensionProperties, nullptr);
|
||||
vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(dlsym(libVulkan, "vkCreateInstance"));
|
||||
EXPECT_NE(vkCreateInstance, nullptr);
|
||||
vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(dlsym(libVulkan, "vkGetInstanceProcAddr"));
|
||||
EXPECT_NE(vkGetInstanceProcAddr, nullptr);
|
||||
vkGetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(dlsym(libVulkan, "vkGetDeviceProcAddr"));
|
||||
EXPECT_NE(vkGetDeviceProcAddr, nullptr);
|
||||
fpIsSupportedVulkan = reinterpret_cast<PFN_IsSupportedVulkan>(dlsym(libVulkan, "IsSupportedVulkan"));
|
||||
EXPECT_NE(fpIsSupportedVulkan, nullptr);
|
||||
isSupportedVulkan = fpIsSupportedVulkan();
|
||||
std::cout << "support vulkan :" << isSupportedVulkan << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkCreateInstance
|
||||
* @tc.desc: test vkCreateInstance
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkCreateInstance_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(vkCreateInstance, nullptr);
|
||||
VkApplicationInfo appInfo = {};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "pApplicationName";
|
||||
appInfo.pEngineName = "pEngineName";
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
std::vector<const char*> instanceExtensions = { VK_KHR_SURFACE_EXTENSION_NAME };
|
||||
instanceExtensions.push_back(VK_OPENHARMONY_OHOS_SURFACE_EXTENSION_NAME);
|
||||
uint32_t extCount = 0;
|
||||
VkResult err = vkEnumerateInstanceExtensionProperties(nullptr, &extCount, nullptr);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
if (extCount > 0) {
|
||||
std::vector<VkExtensionProperties> extensions(extCount);
|
||||
err = vkEnumerateInstanceExtensionProperties(nullptr, &extCount, &extensions.front());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
for (VkExtensionProperties extension : extensions)
|
||||
{
|
||||
instanceExtensions.push_back(extension.extensionName);
|
||||
}
|
||||
}
|
||||
|
||||
VkInstanceCreateInfo instanceCreateInfo = {};
|
||||
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
instanceCreateInfo.pNext = NULL;
|
||||
instanceCreateInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
if (instanceExtensions.size() > 0) {
|
||||
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
|
||||
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
|
||||
}
|
||||
|
||||
err = vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(instance, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: load instance based function pointer
|
||||
* @tc.desc: load instance based function pointer
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, LoadFuncPtr002, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(instance, nullptr);
|
||||
|
||||
vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(
|
||||
vkGetInstanceProcAddr(instance, "vkDestroyInstance"));
|
||||
EXPECT_NE(vkDestroyInstance, nullptr);
|
||||
vkEnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(
|
||||
vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"));
|
||||
EXPECT_NE(vkEnumeratePhysicalDevices, nullptr);
|
||||
vkCreateDevice = reinterpret_cast<PFN_vkCreateDevice>(vkGetInstanceProcAddr(instance, "vkCreateDevice"));
|
||||
EXPECT_NE(vkCreateDevice, nullptr);
|
||||
vkDestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>(vkGetInstanceProcAddr(instance, "vkDestroyDevice"));
|
||||
EXPECT_NE(vkDestroyDevice, nullptr);
|
||||
vkDestroySurfaceKHR = reinterpret_cast<PFN_vkDestroySurfaceKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkDestroySurfaceKHR"));
|
||||
EXPECT_NE(vkDestroySurfaceKHR, nullptr);
|
||||
|
||||
vkCreateOHOSSurfaceOpenHarmony = reinterpret_cast<PFN_vkCreateOHOSSurfaceOpenHarmony>(
|
||||
vkGetInstanceProcAddr(instance, "vkCreateOHOSSurfaceOpenHarmony"));
|
||||
EXPECT_NE(vkCreateOHOSSurfaceOpenHarmony, nullptr);
|
||||
|
||||
fpGetPhysicalDeviceSurfaceCapabilitiesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceCapabilitiesKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfacePresentModesKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfacePresentModesKHR, nullptr);
|
||||
fpGetPhysicalDeviceSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormatsKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR"));
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceFormatsKHR, nullptr);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceQueueFamilyProperties>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceQueueFamilyProperties"));
|
||||
EXPECT_NE(vkGetPhysicalDeviceQueueFamilyProperties, nullptr);
|
||||
vkGetPhysicalDeviceProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceProperties"));
|
||||
EXPECT_NE(vkGetPhysicalDeviceProperties, nullptr);
|
||||
vkGetPhysicalDeviceFeatures = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceFeatures"));
|
||||
EXPECT_NE(vkGetPhysicalDeviceFeatures, nullptr);
|
||||
vkGetPhysicalDeviceMemoryProperties = reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
EXPECT_NE(vkGetPhysicalDeviceMemoryProperties, nullptr);
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceSurfaceSupportKHR"));
|
||||
EXPECT_NE(vkGetPhysicalDeviceSurfaceSupportKHR, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkEnumeratePhysicalDevices
|
||||
* @tc.desc: test vkEnumeratePhysicalDevices
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkEnumeratePhysicalDevices_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(instance, nullptr);
|
||||
|
||||
uint32_t gpuCount = 0;
|
||||
VkResult err = vkEnumeratePhysicalDevices(instance, &gpuCount, nullptr);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(gpuCount, 0);
|
||||
std::vector<VkPhysicalDevice> physicalDevices(gpuCount);
|
||||
err = vkEnumeratePhysicalDevices(instance, &gpuCount, physicalDevices.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
physicalDevice = physicalDevices[0];
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
|
||||
VkPhysicalDeviceProperties deviceProperties;
|
||||
VkPhysicalDeviceFeatures deviceFeatures;
|
||||
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
||||
vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
|
||||
vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures);
|
||||
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkGetPhysicalDeviceQueueFamilyProperties
|
||||
* @tc.desc: test vkGetPhysicalDeviceQueueFamilyProperties
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkGetPhysicalDeviceQueueFamilyProperties_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueCount, NULL);
|
||||
EXPECT_GT(queueCount, 0);
|
||||
|
||||
queueProps.resize(queueCount);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueCount, queueProps.data());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkCreateDevice
|
||||
* @tc.desc: test vkCreateDevice
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkCreateDevice_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(vkCreateDevice, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo = {};
|
||||
deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
|
||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos{};
|
||||
const float defaultQueuePriority(0.0f);
|
||||
VkDeviceQueueCreateInfo queueInfo{};
|
||||
queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||
queueInfo.queueFamilyIndex = getQueueFamilyIndex(VK_QUEUE_GRAPHICS_BIT);
|
||||
queueInfo.queueCount = 1;
|
||||
queueInfo.pQueuePriorities = &defaultQueuePriority;
|
||||
queueCreateInfos.push_back(queueInfo);
|
||||
deviceCreateInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());;
|
||||
deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data();
|
||||
|
||||
std::vector<const char*> deviceExtensions;
|
||||
deviceExtensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||
deviceCreateInfo.enabledExtensionCount = (uint32_t)deviceExtensions.size();
|
||||
deviceCreateInfo.ppEnabledExtensionNames = deviceExtensions.data();
|
||||
VkDevice logicalDevice;
|
||||
VkResult err = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &logicalDevice);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(logicalDevice, nullptr);
|
||||
device = logicalDevice;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkCreateOHOSSurfaceOpenHarmony
|
||||
* @tc.desc: test vkCreateOHOSSurfaceOpenHarmony
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkCreateOHOSSurfaceOpenHarmony_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(vkCreateOHOSSurfaceOpenHarmony, nullptr);
|
||||
EXPECT_NE(instance, nullptr);
|
||||
|
||||
OHNativeWindow* nativeWindow = createNativeWindow("createSurfaceUT");
|
||||
EXPECT_NE(nativeWindow, nullptr);
|
||||
VkOHOSSurfaceCreateInfoOpenHarmony surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_OHOS_SURFACE_CREATE_INFO_OPENHARMONY;
|
||||
surfaceCreateInfo.window = nativeWindow;
|
||||
VkResult err = vkCreateOHOSSurfaceOpenHarmony(instance, &surfaceCreateInfo, NULL, &surface);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkCreateOHOSSurfaceOpenHarmony 2
|
||||
* @tc.desc: test vkCreateOHOSSurfaceOpenHarmony 2
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkCreateOHOSSurfaceOpenHarmony_Test2, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(vkCreateOHOSSurfaceOpenHarmony, nullptr);
|
||||
EXPECT_NE(instance, nullptr);
|
||||
|
||||
OHNativeWindow* nativeWindow = createNativeWindow("createSurfaceUT2");
|
||||
EXPECT_NE(nativeWindow, nullptr);
|
||||
int ret = NativeWindowHandleOpt(nativeWindow, SET_USAGE, 0);
|
||||
EXPECT_EQ(ret, OHOS::GSERROR_OK);
|
||||
VkOHOSSurfaceCreateInfoOpenHarmony surfaceCreateInfo = {};
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_OHOS_SURFACE_CREATE_INFO_OPENHARMONY;
|
||||
surfaceCreateInfo.window = nativeWindow;
|
||||
VkSurfaceKHR surface2 = VK_NULL_HANDLE;
|
||||
VkResult err = vkCreateOHOSSurfaceOpenHarmony(instance, &surfaceCreateInfo, NULL, &surface2);
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
EXPECT_EQ(surface2, VK_NULL_HANDLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkGetPhysicalDeviceSurfaceSupportKHR
|
||||
* @tc.desc: test vkGetPhysicalDeviceSurfaceSupportKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkGetPhysicalDeviceSurfaceSupportKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
std::vector<VkBool32> supportsPresent(queueCount);
|
||||
for (uint32_t i = 0; i < queueCount; i++) {
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, surface, &supportsPresent[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: load device based function pointer 003
|
||||
* @tc.desc: load device based function pointer 003
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, LoadFuncPtr003, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(device, nullptr);
|
||||
|
||||
fpCreateSwapchainKHR = reinterpret_cast<PFN_vkCreateSwapchainKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkCreateSwapchainKHR"));
|
||||
EXPECT_NE(fpCreateSwapchainKHR, nullptr);
|
||||
fpDestroySwapchainKHR = reinterpret_cast<PFN_vkDestroySwapchainKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkDestroySwapchainKHR"));
|
||||
EXPECT_NE(fpDestroySwapchainKHR, nullptr);
|
||||
fpAcquireNextImage2KHR = reinterpret_cast<PFN_vkAcquireNextImage2KHR>(
|
||||
vkGetDeviceProcAddr(device, "vkAcquireNextImage2KHR"));
|
||||
EXPECT_NE(fpAcquireNextImage2KHR, nullptr);
|
||||
fpQueuePresentKHR = reinterpret_cast<PFN_vkQueuePresentKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkQueuePresentKHR"));
|
||||
EXPECT_NE(fpQueuePresentKHR, nullptr);
|
||||
fpGetSwapchainImagesKHR = reinterpret_cast<PFN_vkGetSwapchainImagesKHR>(
|
||||
vkGetDeviceProcAddr(device, "vkGetSwapchainImagesKHR"));
|
||||
EXPECT_NE(fpGetSwapchainImagesKHR, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetPhysicalDeviceSurfaceCapabilitiesKHR
|
||||
* @tc.desc: test fpGetPhysicalDeviceSurfaceCapabilitiesKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetPhysicalDeviceSurfaceCapabilitiesKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceCapabilitiesKHR, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
VkResult err = fpGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &surfCaps);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetPhysicalDeviceSurfacePresentModesKHR
|
||||
* @tc.desc: test fpGetPhysicalDeviceSurfacePresentModesKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetPhysicalDeviceSurfacePresentModesKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfacePresentModesKHR, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
uint32_t presentModeCount;
|
||||
VkResult err = fpGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &presentModeCount, NULL);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_GT(presentModeCount, 0);
|
||||
|
||||
std::vector<VkPresentModeKHR> presentModes(presentModeCount);
|
||||
err = fpGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
physicalDevice, surface, &presentModeCount, presentModes.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetPhysicalDeviceSurfacePresentModesKHR FAIL
|
||||
* @tc.desc: test fpGetPhysicalDeviceSurfacePresentModesKHR FAIL
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetPhysicalDeviceSurfacePresentModesKHR_FAIL_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfacePresentModesKHR, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
uint32_t presentModeCount = 1;
|
||||
std::vector<VkPresentModeKHR> presentModes(presentModeCount);
|
||||
VkResult err = fpGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
physicalDevice, surface, &presentModeCount, presentModes.data());
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetPhysicalDeviceSurfaceFormatsKHR
|
||||
* @tc.desc: test fpGetPhysicalDeviceSurfaceFormatsKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetPhysicalDeviceSurfaceFormatsKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceFormatsKHR, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
uint32_t formatCount;
|
||||
VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, NULL);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_GT(formatCount, 0);
|
||||
std::vector<VkSurfaceFormatKHR> surfaceFormats(formatCount);
|
||||
err = fpGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, surfaceFormats.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
surfaceFormat = surfaceFormats[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetPhysicalDeviceSurfaceFormatsKHR FAIL
|
||||
* @tc.desc: test fpGetPhysicalDeviceSurfaceFormatsKHR FAIL
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetPhysicalDeviceSurfaceFormatsKHR_FAIL_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpGetPhysicalDeviceSurfaceFormatsKHR, nullptr);
|
||||
EXPECT_NE(physicalDevice, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
uint32_t formatCount = 1;
|
||||
std::vector<VkSurfaceFormatKHR> surfaceFormats(formatCount);
|
||||
VkResult err = fpGetPhysicalDeviceSurfaceFormatsKHR(
|
||||
physicalDevice, surface, &formatCount, surfaceFormats.data());
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpCreateSwapchainKHR Success
|
||||
* @tc.desc: test fpCreateSwapchainKHR Success
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpCreateSwapchainKHR_Success_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpCreateSwapchainKHR, nullptr);
|
||||
EXPECT_NE(device, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
std::vector<VkFormat> pixelFormatArray = {
|
||||
VK_FORMAT_R8G8B8A8_UNORM,
|
||||
VK_FORMAT_R8G8B8A8_SRGB,
|
||||
};
|
||||
std::vector<VkColorSpaceKHR> colorDataspaceArray = {
|
||||
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||
VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_DCI_P3_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
|
||||
VK_COLOR_SPACE_BT2020_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_HDR10_ST2084_EXT,
|
||||
VK_COLOR_SPACE_DOLBYVISION_EXT,
|
||||
VK_COLOR_SPACE_HDR10_HLG_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
|
||||
VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
|
||||
VK_COLORSPACE_SRGB_NONLINEAR_KHR,
|
||||
VK_COLOR_SPACE_DCI_P3_LINEAR_EXT
|
||||
};
|
||||
|
||||
for (decltype(pixelFormatArray.size()) i = 0; i < pixelFormatArray.size(); i++) {
|
||||
for (decltype(colorDataspaceArray.size()) j = 0; j < colorDataspaceArray.size(); j++) {
|
||||
VkSwapchainCreateInfoKHR swapchainCI = getSwapchainCreateInfo(
|
||||
pixelFormatArray[i], colorDataspaceArray[j]);
|
||||
|
||||
VkSwapchainKHR swapChainSuccess = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapChainSuccess2 = VK_NULL_HANDLE;
|
||||
|
||||
VkResult err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChainSuccess);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(swapChainSuccess, VK_NULL_HANDLE);
|
||||
|
||||
swapchainCI.oldSwapchain = swapChainSuccess;
|
||||
err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChainSuccess2);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(swapChainSuccess2, VK_NULL_HANDLE);
|
||||
fpDestroySwapchainKHR(device, swapChainSuccess, nullptr);
|
||||
fpDestroySwapchainKHR(device, swapChainSuccess2, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpCreateSwapchainKHR fail
|
||||
* @tc.desc: test fpCreateSwapchainKHR fail
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpCreateSwapchainKHR_Fail_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpCreateSwapchainKHR, nullptr);
|
||||
EXPECT_NE(device, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
std::vector<VkColorSpaceKHR> colorDataspaceArray = {
|
||||
VK_COLOR_SPACE_PASS_THROUGH_EXT,
|
||||
VK_COLOR_SPACE_DISPLAY_NATIVE_AMD,
|
||||
VK_COLOR_SPACE_MAX_ENUM_KHR
|
||||
};
|
||||
|
||||
for (decltype(colorDataspaceArray.size()) i = 0; i < colorDataspaceArray.size(); i++) {
|
||||
VkSwapchainCreateInfoKHR swapchainCI = getSwapchainCreateInfo(
|
||||
VK_FORMAT_R8G8B8A8_UNORM, colorDataspaceArray[i]);
|
||||
|
||||
VkSwapchainKHR swapChainFail = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapChainFail2 = VK_NULL_HANDLE;
|
||||
|
||||
VkResult err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChainFail);
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
EXPECT_EQ(swapChainFail, VK_NULL_HANDLE);
|
||||
|
||||
swapchainCI.oldSwapchain = swapChainFail;
|
||||
err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChainFail2);
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
EXPECT_EQ(swapChainFail2, VK_NULL_HANDLE);
|
||||
fpDestroySwapchainKHR(device, swapChainFail, nullptr);
|
||||
fpDestroySwapchainKHR(device, swapChainFail2, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpCreateSwapchainKHR
|
||||
* @tc.desc: test fpCreateSwapchainKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpCreateSwapchainKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(fpCreateSwapchainKHR, nullptr);
|
||||
EXPECT_NE(device, nullptr);
|
||||
EXPECT_NE(surface, VK_NULL_HANDLE);
|
||||
|
||||
VkSwapchainCreateInfoKHR swapchainCI = getSwapchainCreateInfo(
|
||||
VK_FORMAT_B8G8R8A8_UNORM, surfaceFormat.colorSpace);
|
||||
|
||||
VkResult err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChain);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(swapChain, VK_NULL_HANDLE);
|
||||
|
||||
swapchainCI.oldSwapchain = swapChain;
|
||||
err = fpCreateSwapchainKHR(device, &swapchainCI, nullptr, &swapChain2);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
EXPECT_NE(swapChain2, VK_NULL_HANDLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetSwapchainImagesKHR
|
||||
* @tc.desc: test fpGetSwapchainImagesKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetSwapchainImagesKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
uint32_t imageCount;
|
||||
std::vector<VkImage> images;
|
||||
VkResult err = fpGetSwapchainImagesKHR(device, swapChain, &imageCount, NULL);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
images.resize(imageCount);
|
||||
err = fpGetSwapchainImagesKHR(device, swapChain, &imageCount, images.data());
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpGetSwapchainImagesKHR FAIL
|
||||
* @tc.desc: test fpGetSwapchainImagesKHR FAIL
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpGetSwapchainImagesKHR_FAIL_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
uint32_t imageCount = 1;
|
||||
std::vector<VkImage> images(imageCount);
|
||||
VkResult err = fpGetSwapchainImagesKHR(device, swapChain2, &imageCount, images.data());
|
||||
EXPECT_NE(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkCreateSemaphore
|
||||
* @tc.desc: test vkCreateSemaphore
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, vkCreateSemaphore_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
VkSemaphoreCreateInfo semaphoreCreateInfo {};
|
||||
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
PFN_vkCreateSemaphore vkCreateSemaphore = reinterpret_cast<PFN_vkCreateSemaphore>(
|
||||
vkGetInstanceProcAddr(instance, "vkCreateSemaphore"));
|
||||
EXPECT_NE(vkCreateSemaphore, nullptr);
|
||||
VkResult err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphore);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpAcquireNextImage2KHR
|
||||
* @tc.desc: test fpAcquireNextImage2KHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpAcquireNextImage2KHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
VkAcquireNextImageInfoKHR pAcquireInfo;
|
||||
pAcquireInfo.swapchain = swapChain2;
|
||||
pAcquireInfo.timeout = UINT64_MAX;
|
||||
pAcquireInfo.semaphore = semaphore;
|
||||
pAcquireInfo.fence = (VkFence)nullptr;
|
||||
uint32_t imageIndex = 0;
|
||||
VkResult err = fpAcquireNextImage2KHR(device, &pAcquireInfo, &imageIndex);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test fpQueuePresentKHR
|
||||
* @tc.desc: test fpQueuePresentKHR
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, fpQueuePresentKHR_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
VkRectLayerKHR pRectangles = {};
|
||||
|
||||
std::vector<VkPresentRegionKHR> pRegions;
|
||||
VkPresentRegionKHR pRegion;
|
||||
pRegion.rectangleCount = 1;
|
||||
pRegion.pRectangles = &pRectangles;
|
||||
pRegions.push_back(pRegion);
|
||||
|
||||
VkPresentRegionsKHR presentRegions;
|
||||
presentRegions.sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR;
|
||||
presentRegions.pNext = NULL;
|
||||
presentRegions.swapchainCount = 1;
|
||||
presentRegions.pRegions = pRegions.data();
|
||||
|
||||
VkQueue queue = nullptr;
|
||||
PFN_vkGetDeviceQueue vkGetDeviceQueue = reinterpret_cast<PFN_vkGetDeviceQueue>(
|
||||
vkGetInstanceProcAddr(instance, "vkGetDeviceQueue"));
|
||||
EXPECT_NE(vkGetDeviceQueue, nullptr);
|
||||
vkGetDeviceQueue(device, 0, 0, &queue);
|
||||
EXPECT_NE(queue, nullptr);
|
||||
uint32_t imageIndex = 0;
|
||||
VkPresentInfoKHR presentInfo = {};
|
||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
presentInfo.pNext = &presentRegions;
|
||||
presentInfo.swapchainCount = 1;
|
||||
presentInfo.pSwapchains = &swapChain2;
|
||||
presentInfo.pImageIndices = &imageIndex;
|
||||
EXPECT_NE(semaphore, VK_NULL_HANDLE);
|
||||
presentInfo.pWaitSemaphores = &semaphore;
|
||||
presentInfo.waitSemaphoreCount = 1;
|
||||
VkResult err = fpQueuePresentKHR(queue, &presentInfo);
|
||||
EXPECT_EQ(err, VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: test vkDestroySurfaceKHR nullptr
|
||||
* @tc.desc: test vkDestroySurfaceKHR nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5ODXM
|
||||
*/
|
||||
HWTEST_F(VulkanWrapperUnitTest, DestroySurface_NULL_Test, TestSize.Level1)
|
||||
{
|
||||
if (isSupportedVulkan) {
|
||||
EXPECT_NE(vkDestroySurfaceKHR, nullptr);
|
||||
vkDestroySurfaceKHR(instance, VK_NULL_HANDLE, nullptr);
|
||||
}
|
||||
}
|
||||
} // vulkan::driver
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <dlfcn.h>
|
||||
#include "directory_ex.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#ifdef __aarch64__
|
||||
constexpr const char *LIB_CACULATE_PATH = "/system/lib64/libvulkan_wrapper.so";
|
||||
#else
|
||||
constexpr const char *LIB_CACULATE_PATH = "/system/lib/libvulkan_wrapper.so";
|
||||
#endif
|
||||
|
||||
int32_t main(int32_t argc, const char* argv[])
|
||||
{
|
||||
std::cout << "vulkan wrapper native test is comming :: Loading libvulkan.so..." << std::endl;
|
||||
std::string realPath;
|
||||
if (!OHOS::PathToRealPath(LIB_CACULATE_PATH, realPath)) {
|
||||
std::cout << "file is not real path, file path: " << LIB_CACULATE_PATH << std::endl;
|
||||
return -1;
|
||||
}
|
||||
void* libVulkan = dlopen(realPath.c_str(), RTLD_LOCAL | RTLD_NOW);
|
||||
|
||||
if (libVulkan == nullptr) {
|
||||
std::cout << "vulkan wrapper native test :: dlopen faild " << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "vulkan wrapper native test :: dlopen "<< LIB_CACULATE_PATH <<" success" << std::endl;
|
||||
|
||||
// Test Load base function pointers
|
||||
PFN_vkCreateInstance vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(
|
||||
dlsym(libVulkan, "vkCreateInstance"));
|
||||
if (vkCreateInstance) {
|
||||
std::cout << "find vulkan vkCreateInstance success" << std::endl;
|
||||
} else {
|
||||
std::cout << "find vulkan vkCreateInstance failed" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "vulkan wrapper native test is successful :: Loading libvulkan.so..." << std::endl;
|
||||
return 0;
|
||||
}
|
@ -53,7 +53,7 @@ if (graphic_standard_feature_ace_enable_gpu && current_os != "ios") {
|
||||
if (graphic_standard_feature_enable_vulkan) {
|
||||
libvulkan += [
|
||||
"//third_party/flutter/engine/flutter/vulkan:vulkan_flutter",
|
||||
"//foundation/graphic/graphic_2d/frameworks/vulkan_wrapper:vulkan",
|
||||
"//third_party/vulkan-loader/openharmony:vulkan_loader",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
|
@ -122,8 +122,6 @@ ohos_shared_library("librender_service") {
|
||||
}
|
||||
|
||||
if (rs_enable_gpu) {
|
||||
include_dirs += [ "$graphic_2d_root/frameworks/vulkan_wrapper/include" ]
|
||||
|
||||
if (graphic_standard_feature_enable_vulkan) {
|
||||
include_dirs += [ "//third_party/flutter/engine/flutter/vulkan" ]
|
||||
}
|
||||
|
@ -113,8 +113,10 @@ constexpr int32_t CLICK_ANIMATION_COMPLETE = 4;
|
||||
constexpr int32_t ANIMATION_START = 0;
|
||||
constexpr int32_t ANIMATION_COMPLETE = 1;
|
||||
#endif
|
||||
#ifdef RS_ENABLE_GL
|
||||
constexpr size_t DEFAULT_SKIA_CACHE_SIZE = 96 * (1 << 20);
|
||||
constexpr int DEFAULT_SKIA_CACHE_COUNT = 2 * (1 << 12);
|
||||
#endif
|
||||
const std::map<int, int32_t> BLUR_CNT_TO_BLUR_CODE {
|
||||
{ 1, 10021 },
|
||||
{ 2, 10022 },
|
||||
|
@ -120,7 +120,6 @@ ohos_source_set("rosen_ohos_sources") {
|
||||
if (rs_enable_gpu) {
|
||||
include_dirs += [
|
||||
"//third_party/openssl/include",
|
||||
"$graphic_2d_root/frameworks/vulkan_wrapper/include",
|
||||
"$graphic_2d_root/frameworks/surface/include",
|
||||
"$graphic_2d_root/interfaces/inner_api/common",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user