mirror of
https://gitee.com/openharmony/third_party_vulkan-loader
synced 2024-11-23 07:10:23 +00:00
!2 Vulkan-Loader适配OpenHarmony
Merge pull request !2 from shegangbin/pr_1
This commit is contained in:
commit
cc5d41bc02
@ -114,6 +114,11 @@ typedef struct VkLayerInstanceDispatchTable_ {
|
||||
PFN_vkCreateAndroidSurfaceKHR CreateAndroidSurfaceKHR;
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
PFN_vkCreateOHOSSurfaceOpenHarmony CreateOHOSSurfaceOpenHarmony;
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_KHR_win32_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
PFN_vkCreateWin32SurfaceKHR CreateWin32SurfaceKHR;
|
||||
|
@ -266,6 +266,10 @@ VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_icd_term *icd_t
|
||||
#ifdef VK_USE_PLATFORM_FUCHSIA
|
||||
LOOKUP_GIPA(CreateImagePipeSurfaceFUCHSIA, false);
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
LOOKUP_GIPA(CreateOHOSSurfaceOpenHarmony, false);
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_EXT_metal_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
@ -1310,6 +1314,11 @@ VKAPI_ATTR void VKAPI_CALL loader_init_instance_extension_dispatch_table(VkLayer
|
||||
table->CreateImagePipeSurfaceFUCHSIA = (PFN_vkCreateImagePipeSurfaceFUCHSIA)gpa(inst, "vkCreateImagePipeSurfaceFUCHSIA");
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
table->CreateOHOSSurfaceOpenHarmony = (PFN_vkCreateOHOSSurfaceOpenHarmony)gpa(inst, "vkCreateOHOSSurfaceOpenHarmony");
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_EXT_metal_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
table->CreateMetalSurfaceEXT = (PFN_vkCreateMetalSurfaceEXT)gpa(inst, "vkCreateMetalSurfaceEXT");
|
||||
@ -2339,6 +2348,11 @@ VKAPI_ATTR void* VKAPI_CALL loader_lookup_instance_dispatch_table(const VkLayerI
|
||||
if (!strcmp(name, "CreateImagePipeSurfaceFUCHSIA")) return (void *)table->CreateImagePipeSurfaceFUCHSIA;
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
if (!strcmp(name, "CreateOHOSSurfaceOpenHarmony")) return (void *)table->CreateOHOSSurfaceOpenHarmony;
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_EXT_metal_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
if (!strcmp(name, "CreateMetalSurfaceEXT")) return (void *)table->CreateMetalSurfaceEXT;
|
||||
@ -9790,6 +9804,11 @@ const VkLayerInstanceDispatchTable instance_disp = {
|
||||
.CreateImagePipeSurfaceFUCHSIA = terminator_CreateImagePipeSurfaceFUCHSIA,
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
.CreateOHOSSurfaceOpenHarmony = terminator_CreateOHOSSurfaceOpenHarmony,
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_EXT_metal_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
.CreateMetalSurfaceEXT = terminator_CreateMetalSurfaceEXT,
|
||||
@ -9897,6 +9916,9 @@ const char *const LOADER_INSTANCE_EXTENSIONS[] = {
|
||||
#ifdef VK_USE_PLATFORM_FUCHSIA
|
||||
VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME,
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
VK_OPENHARMONY_OHOS_SURFACE_EXTENSION_NAME,
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
VK_EXT_METAL_SURFACE_EXTENSION_NAME,
|
||||
#endif // VK_USE_PLATFORM_METAL_EXT
|
||||
|
@ -419,6 +419,11 @@ struct loader_icd_term_dispatch {
|
||||
PFN_vkCreateImagePipeSurfaceFUCHSIA CreateImagePipeSurfaceFUCHSIA;
|
||||
#endif // VK_USE_PLATFORM_FUCHSIA
|
||||
|
||||
// ---- VK_OpenHarmony_OHOS_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
PFN_vkCreateOHOSSurfaceOpenHarmony CreateOHOSSurfaceOpenHarmony;
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// ---- VK_EXT_metal_surface extension commands
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
PFN_vkCreateMetalSurfaceEXT CreateMetalSurfaceEXT;
|
||||
|
@ -322,6 +322,9 @@ struct loader_instance {
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
bool wsi_android_surface_enabled;
|
||||
#endif
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
bool wsi_openharmony_surface_enabled;
|
||||
#endif
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
bool wsi_macos_surface_enabled;
|
||||
#endif
|
||||
|
@ -33,8 +33,11 @@
|
||||
|
||||
#include "debug_utils.h"
|
||||
#include "get_environment.h"
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
#include "loader_hilog.h"
|
||||
#endif
|
||||
|
||||
uint32_t g_loader_debug = 0;
|
||||
uint32_t g_loader_debug = ~0u;
|
||||
|
||||
void loader_debug_init(void) {
|
||||
char *env, *orig;
|
||||
@ -221,6 +224,10 @@ void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t ms
|
||||
OutputDebugString("\n");
|
||||
#endif
|
||||
|
||||
#if defined(VK_USE_PLATFORM_OHOS_OPENHARMONY)
|
||||
OpenHarmonyLog(msg_type, cmd_line_msg);
|
||||
#endif
|
||||
|
||||
fputs(cmd_line_msg, stderr);
|
||||
fputc('\n', stderr);
|
||||
} else {
|
||||
|
65
loader/wsi.c
65
loader/wsi.c
@ -80,6 +80,12 @@ void wsi_create_instance(struct loader_instance *loader_inst, const VkInstanceCr
|
||||
continue;
|
||||
}
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_OPENHARMONY_OHOS_SURFACE_EXTENSION_NAME) == 0) {
|
||||
loader_inst->wsi_openharmony_surface_enabled = true;
|
||||
continue;
|
||||
}
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_MVK_MACOS_SURFACE_EXTENSION_NAME) == 0) {
|
||||
loader_inst->wsi_macos_surface_enabled = true;
|
||||
@ -1211,6 +1217,57 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance ins
|
||||
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// Functions for the VK_OpenHarmony_OHOS_surface extension:
|
||||
|
||||
// This is the trampoline entrypoint for CreateOHOSSurfaceOpenHarmony
|
||||
|
||||
LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkSurfaceKHR *pSurface) {
|
||||
const VkLayerInstanceDispatchTable *disp;
|
||||
if (NULL == loader_get_instance(instance)) {
|
||||
loader_log(NULL, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
|
||||
"VkOHOSSurfaceCreateInfoOpenHarmony: Invalid instance [VUID-VkOHOSSurfaceCreateInfoOpenHarmony-instance-parameter]");
|
||||
abort(); /* Intentionally fail so user can correct issue. */
|
||||
}
|
||||
disp = loader_get_instance_layer_dispatch(instance);
|
||||
|
||||
return disp->CreateOHOSSurfaceOpenHarmony(instance, pCreateInfo, pAllocator, pSurface);
|
||||
}
|
||||
|
||||
// This is the instance chain terminator function for CreateOHOSSurfaceOpenHarmony
|
||||
VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
|
||||
// First, check to ensure the appropriate extension was enabled:
|
||||
struct loader_instance *loader_inst = loader_get_instance(instance);
|
||||
if (!loader_inst->wsi_display_enabled) {
|
||||
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
|
||||
"VK_KHR_display extension not enabled. vkCreateOHOSSurfaceOpenHarmony not executed!\n");
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
|
||||
// Next, if so, proceed with the implementation of this function:
|
||||
VkIcdSurfaceOpenHarmony *pIcdSurface =
|
||||
loader_instance_heap_alloc(loader_inst, sizeof(VkIcdSurfaceOpenHarmony), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (pIcdSurface == NULL) {
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
pIcdSurface->base.platform = VK_ICD_WSI_PLATFORM_OPENHARMONY;
|
||||
pIcdSurface->window = pCreateInfo->window;
|
||||
|
||||
*pSurface = (VkSurfaceKHR)pIcdSurface;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
|
||||
// Functions for the VK_EXT_headless_surface extension:
|
||||
|
||||
LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateHeadlessSurfaceEXT(VkInstance instance,
|
||||
@ -2856,6 +2913,14 @@ bool wsi_swapchain_instance_gpa(struct loader_instance *loader_inst, const char
|
||||
return true;
|
||||
}
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
// Functions for the VK_OpenHarmony_OHOS_surface extension:
|
||||
if (!strcmp("vkCreateOHOSSurfaceOpenHarmony", name)) {
|
||||
*addr = loader_inst->wsi_openharmony_surface_enabled ? (void *)vkCreateOHOSSurfaceOpenHarmony : NULL;
|
||||
return true;
|
||||
}
|
||||
#endif // VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
|
||||
|
@ -229,6 +229,12 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance ins
|
||||
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_OHOS_OPENHARMONY
|
||||
VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateOHOSSurfaceOpenHarmony(VkInstance instance,
|
||||
const VkOHOSSurfaceCreateInfoOpenHarmony* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilities2KHR(
|
||||
VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
|
||||
VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
|
||||
|
108
openharmony/BUILD.gn
Normal file
108
openharmony/BUILD.gn
Normal file
@ -0,0 +1,108 @@
|
||||
# Copyright (c) 2023 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
|
||||
#
|
||||
# https://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")
|
||||
|
||||
vulkan_headers_dir = "//third_party/vulkan-headers"
|
||||
# Vulkan loader build options
|
||||
|
||||
## Build libvulkan.so {{{
|
||||
|
||||
config("vulkan_internal_config") {
|
||||
defines = [
|
||||
"VULKAN_NON_CMAKE_BUILD",
|
||||
"VK_ENABLE_BETA_EXTENSIONS",
|
||||
]
|
||||
cflags = [
|
||||
"-Wno-conversion",
|
||||
"-Wno-extra-semi",
|
||||
"-Wno-implicit-fallthrough",
|
||||
"-Wno-sign-compare",
|
||||
"-Wno-unreachable-code",
|
||||
"-Wno-unused-function",
|
||||
"-Wno-unused-variable",
|
||||
]
|
||||
|
||||
defines += [
|
||||
"SYSCONFDIR=\"/system/etc\"",
|
||||
"FALLBACK_CONFIG_DIRS=\"/vendor/etc\"",
|
||||
"FALLBACK_DATA_DIRS=\"/data\"",
|
||||
"VK_USE_PLATFORM_OHOS_OPENHARMONY",
|
||||
]
|
||||
}
|
||||
|
||||
config("vulkan_loader_config") {
|
||||
include_dirs = [
|
||||
"../loader/generated",
|
||||
"../loader",
|
||||
"../openharmony",
|
||||
]
|
||||
defines = [
|
||||
"API_NAME=\"Vulkan\"",
|
||||
"USE_UNSAFE_FILE_SEARCH=1",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("vulkan_loader") {
|
||||
sources = [
|
||||
"../loader/adapters.h",
|
||||
"../loader/allocation.c",
|
||||
"../loader/allocation.h",
|
||||
"../loader/asm_offset.c",
|
||||
"../loader/cJSON.c",
|
||||
"../loader/cJSON.h",
|
||||
"../loader/debug_utils.c",
|
||||
"../loader/debug_utils.h",
|
||||
"../loader/dev_ext_trampoline.c",
|
||||
"../loader/extension_manual.c",
|
||||
"../loader/extension_manual.h",
|
||||
"../loader/get_environment.c",
|
||||
"../loader/get_environment.h",
|
||||
"../loader/generated/vk_layer_dispatch_table.h",
|
||||
"../loader/generated/vk_loader_extensions.h",
|
||||
"../loader/generated/vk_object_types.h",
|
||||
"../loader/gpa_helper.h",
|
||||
"../loader/gpa_helper.c",
|
||||
"../loader/loader_common.h",
|
||||
"../loader/loader.c",
|
||||
"../loader/loader.h",
|
||||
"../loader/log.c",
|
||||
"../loader/log.h",
|
||||
"../loader/phys_dev_ext.c",
|
||||
"../loader/stack_allocation.h",
|
||||
"../loader/terminator.c",
|
||||
"../loader/trampoline.c",
|
||||
"../loader/unknown_function_handling.h",
|
||||
"../loader/unknown_function_handling.c",
|
||||
"../loader/vk_loader_layer.h",
|
||||
|
||||
# TODO(jmadill): Use assembler where available.
|
||||
"../loader/unknown_ext_chain.c",
|
||||
"../loader/vk_loader_platform.h",
|
||||
"../loader/wsi.c",
|
||||
"../loader/wsi.h",
|
||||
]
|
||||
|
||||
public_deps = [ "$vulkan_headers_dir:vulkan_headers" ]
|
||||
configs = [ ":vulkan_internal_config" ]
|
||||
public_configs = [ ":vulkan_loader_config" ]
|
||||
external_deps = [ "hilog_native:libhilog" ]
|
||||
|
||||
output_name = "vulkan"
|
||||
output_extension = "so.1"
|
||||
|
||||
part_name = "graphic_standard"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
|
||||
## Build libvulkan.so }}}
|
44
openharmony/loader_hilog.h
Normal file
44
openharmony/loader_hilog.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 LOADER_HILOG_H
|
||||
#define LOADER_HILOG_H
|
||||
|
||||
#include <hilog/log.h>
|
||||
#include "loader_common.h"
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#undef LOG_TAG
|
||||
#define LOG_DOMAIN 0xD001402
|
||||
#define LOG_TAG "VulkanLoader"
|
||||
|
||||
#define VKHILOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
|
||||
#define VKHILOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
|
||||
#define VKHILOGW(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
|
||||
#define VKHILOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
|
||||
|
||||
void OpenHarmonyLog(VkFlags log_type, char *log_msg)
|
||||
{
|
||||
if (log_type & VULKAN_LOADER_ERROR_BIT) {
|
||||
VKHILOGE("%{public}s", log_msg);
|
||||
} else if (log_type & VULKAN_LOADER_WARN_BIT) {
|
||||
VKHILOGW("%{public}s", log_msg);
|
||||
} else if (log_type & VULKAN_LOADER_INFO_BIT) {
|
||||
VKHILOGI("%{public}s", log_msg);
|
||||
} else {
|
||||
VKHILOGD("%{public}s", log_msg);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LOADER_HILOG_H
|
@ -60,6 +60,7 @@ platform_dict = {
|
||||
'xlib_xrandr' : 'VK_USE_PLATFORM_XLIB_XRANDR_EXT',
|
||||
'provisional' : 'VK_ENABLE_BETA_EXTENSIONS',
|
||||
'screen' : 'VK_USE_PLATFORM_SCREEN_QNX',
|
||||
'openharmony' : 'VK_USE_PLATFORM_OHOS_OPENHARMONY',
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -46,7 +46,8 @@ WSI_EXT_NAMES = ['VK_KHR_surface',
|
||||
'VK_KHR_get_display_properties2',
|
||||
'VK_KHR_get_surface_capabilities2',
|
||||
'VK_QNX_screen_surface',
|
||||
'VK_NN_vi_surface']
|
||||
'VK_NN_vi_surface',
|
||||
'VK_OpenHarmony_OHOS_surface']
|
||||
|
||||
ADD_INST_CMDS = ['vkCreateInstance',
|
||||
'vkEnumerateInstanceExtensionProperties',
|
||||
|
Loading…
Reference in New Issue
Block a user