Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE][refactoring]gfx egl. #15830

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/assets/primitives.fbx.meta
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"displayName": "",
"id": "aae0f",
"name": "primitives.prefab",
"ver": "1.0.13",
"ver": "1.0.14",
"imported": true,
"files": [
".json"
Expand Down
102 changes: 93 additions & 9 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ elseif(ANDROID OR WINDOWS OR OHOS)
cc_set_if_undefined(CC_USE_GLES3 ON)
cc_set_if_undefined(CC_USE_VULKAN OFF)
cc_set_if_undefined(CC_USE_GLES2 OFF)
cc_set_if_undefined(CC_USE_GLES_NEW OFF)
elseif(MACOSX OR IOS)
cc_set_if_undefined(CC_USE_METAL ON)
cc_set_if_undefined(CC_USE_VULKAN OFF)
Expand Down Expand Up @@ -461,6 +462,8 @@ cocos_source_files(
cocos/base/TypeDef.h
cocos/base/BinaryArchive.cpp
cocos/base/BinaryArchive.h
cocos/base/DynamicLibrary.cpp
cocos/base/DynamicLibrary.h
cocos/base/std/any.h
cocos/base/std/optional.h
cocos/base/std/variant.h
Expand Down Expand Up @@ -1169,6 +1172,7 @@ cocos_source_files(
cocos/renderer/core/TextureBufferPool.h
cocos/renderer/core/TextureBufferPool.cpp

cocos/renderer/GFXDeviceManager.cpp
cocos/renderer/GFXDeviceManager.h

cocos/renderer/gfx-base/SPIRVUtils.h
Expand Down Expand Up @@ -1612,20 +1616,77 @@ cocos_source_files(
# )

if(CC_USE_GLES2 OR CC_USE_GLES3)
if(CC_USE_GLES_NEW)
cocos_source_files(
cocos/renderer/gfx-gles-common/egl/Context.cpp
cocos/renderer/gfx-gles-common/egl/Context.h
cocos/renderer/gfx-gles-common/egl/Surface.cpp
cocos/renderer/gfx-gles-common/egl/Surface.h
cocos/renderer/gfx-gles-common/egl/Instance.cpp
cocos/renderer/gfx-gles-common/egl/Instance.h
)

cocos_source_files(
cocos/renderer/gfx-gles-common/common/GLESQueue.cpp
cocos/renderer/gfx-gles-common/common/GLESQueue.h
cocos/renderer/gfx-gles-common/common/GLESCommandStorage.cpp
cocos/renderer/gfx-gles-common/common/GLESCommandStorage.h

cocos/renderer/gfx-gles-common/common/GLESCommands.cpp
cocos/renderer/gfx-gles-common/common/GLESCommands.h
cocos/renderer/gfx-gles-common/common/GLESCommandBuffer.cpp
cocos/renderer/gfx-gles-common/common/GLESCommandBuffer.h
cocos/renderer/gfx-gles-common/common/GLESBuffer.cpp
cocos/renderer/gfx-gles-common/common/GLESBuffer.h
cocos/renderer/gfx-gles-common/common/GLESDescriptorSet.cpp
cocos/renderer/gfx-gles-common/common/GLESDescriptorSet.h
cocos/renderer/gfx-gles-common/common/GLESDescriptorSetLayout.cpp
cocos/renderer/gfx-gles-common/common/GLESDescriptorSetLayout.h
cocos/renderer/gfx-gles-common/common/GLESDevice.cpp
cocos/renderer/gfx-gles-common/common/GLESDevice.h
cocos/renderer/gfx-gles-common/common/GLESFramebuffer.cpp
cocos/renderer/gfx-gles-common/common/GLESFramebuffer.h
cocos/renderer/gfx-gles-common/common/GLESInputAssembler.cpp
cocos/renderer/gfx-gles-common/common/GLESInputAssembler.h
cocos/renderer/gfx-gles-common/common/GLESPipelineLayout.cpp
cocos/renderer/gfx-gles-common/common/GLESPipelineLayout.h
cocos/renderer/gfx-gles-common/common/GLESPipelineState.cpp
cocos/renderer/gfx-gles-common/common/GLESPipelineState.h
cocos/renderer/gfx-gles-common/common/GLESRenderPass.cpp
cocos/renderer/gfx-gles-common/common/GLESRenderPass.h
cocos/renderer/gfx-gles-common/common/GLESSampler.cpp
cocos/renderer/gfx-gles-common/common/GLESSampler.h
cocos/renderer/gfx-gles-common/common/GLESShader.cpp
cocos/renderer/gfx-gles-common/common/GLESShader.h
cocos/renderer/gfx-gles-common/common/GLESSwapchain.cpp
cocos/renderer/gfx-gles-common/common/GLESSwapchain.h
cocos/renderer/gfx-gles-common/common/GLESTexture.cpp
cocos/renderer/gfx-gles-common/common/GLESTexture.h
cocos/renderer/gfx-gles-common/common/GLESGPUObjects.h
cocos/renderer/gfx-gles-common/common/GLESGeneralBarrier.cpp
cocos/renderer/gfx-gles-common/common/GLESGeneralBarrier.h
cocos/renderer/gfx-gles-common/common/GLESPipelineCache.cpp
cocos/renderer/gfx-gles-common/common/GLESPipelineCache.h
cocos/renderer/gfx-gles-common/common/GLESRecycleBin.cpp
cocos/renderer/gfx-gles-common/common/GLESRecycleBin.h
)
endif()

cocos_source_files(
cocos/renderer/gfx-gles-common/GLESCommandPool.h
cocos/renderer/gfx-gles-common/eglw.cpp
cocos/renderer/gfx-gles-common/gles2w.cpp
cocos/renderer/gfx-gles-common/loader/eglw.cpp
cocos/renderer/gfx-gles-common/loader/gles2w.cpp
)
if(CC_USE_GLES3)
cocos_source_files(
cocos/renderer/gfx-gles-common/gles3w.cpp
cocos/renderer/gfx-gles-common/loader/gles3w.cpp
)
endif()
endif()

if(CC_USE_GLES2)
cocos_source_files(
# if(!CC_USE_GLES_NEW)
cocos_source_files(
cocos/renderer/gfx-gles2/GLES2Buffer.cpp
cocos/renderer/gfx-gles2/GLES2Buffer.h
cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp
Expand Down Expand Up @@ -1667,11 +1728,21 @@ if(CC_USE_GLES2)
cocos/renderer/gfx-gles2/GLES2Wrangler.h
cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp
cocos/renderer/gfx-gles2/states/GLES2Sampler.h
)
)
# else()
cocos_source_files(
cocos/renderer/gfx-gles-common/gles2/GLES2Commands.cpp
cocos/renderer/gfx-gles-common/gles2/GLES2Commands.h
cocos/renderer/gfx-gles-common/gles2/GLES2Features.cpp
cocos/renderer/gfx-gles-common/gles2/GLES2CommandEncoder.cpp
cocos/renderer/gfx-gles-common/gles2/GLES2CommandEncoder.h
)
# endif()
endif()

if(CC_USE_GLES3)
cocos_source_files(
# if(!CC_USE_GLES_NEW)
cocos_source_files(
cocos/renderer/gfx-gles3/GLES3Buffer.cpp
cocos/renderer/gfx-gles3/GLES3Buffer.h
cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp
Expand Down Expand Up @@ -1717,7 +1788,16 @@ if(CC_USE_GLES3)
cocos/renderer/gfx-gles3/states/GLES3GeneralBarrier.h
cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp
cocos/renderer/gfx-gles3/states/GLES3Sampler.h
)
)
# else()
cocos_source_files(
cocos/renderer/gfx-gles-common/gles3/GLES3Commands.cpp
cocos/renderer/gfx-gles-common/gles3/GLES3Commands.h
cocos/renderer/gfx-gles-common/gles3/GLES3Features.cpp
cocos/renderer/gfx-gles-common/gles3/GLES3CommandEncoder.cpp
cocos/renderer/gfx-gles-common/gles3/GLES3CommandEncoder.h
)
# endif()
endif()

if(CC_USE_METAL)
Expand Down Expand Up @@ -2374,7 +2454,7 @@ if(USE_MIDDLEWARE)
NO_WERROR cocos/editor-support/spine-creator-support/spine-cocos2dx.cpp
cocos/editor-support/spine-creator-support/spine-cocos2dx.h
NO_WERROR cocos/editor-support/spine-creator-support/VertexEffectDelegate.cpp
cocos/editor-support/spine-creator-support/VertexEffectDelegate.h
cocos/editor-support/spine-creator-support/VertexEffectDelegate.h

)
cocos_source_files(
Expand Down Expand Up @@ -3136,6 +3216,10 @@ if(CC_USE_GLES2)
target_compile_definitions(${ENGINE_NAME} PUBLIC CC_USE_GLES2)
endif()

if(CC_USE_GLES_NEW)
target_compile_definitions(${ENGINE_NAME} PUBLIC CC_USE_GLES_NEW)
endif()

target_include_directories(${ENGINE_NAME}
PUBLIC
${CC_EXTERNAL_INCLUDES}
Expand Down Expand Up @@ -3327,7 +3411,7 @@ set(COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${COCOS_SOURCE_LIST})
set(COCOS_GENERATED_LIST)
foreach(src IN LISTS COCOS_SOURCE_LIST_EXCLUDE_GENRATED)
get_source_file_property(IS_GENERATED ${src} GENERATED)
if(IS_GENERATED)
if(IS_GENERATED)
list(REMOVE_ITEM COCOS_SOURCE_LIST_EXCLUDE_GENRATED ${src})
list(APPEND COCOS_GENERATED_LIST ${src})
endif()
Expand Down
50 changes: 50 additions & 0 deletions native/cocos/base/DynamicLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "DynamicLibrary.h"

namespace cc {

DynamicLibrary::~DynamicLibrary() {
unload();
}

bool DynamicLibrary::load() {
#ifdef _WIN32
_handle = ::LoadLibraryExA(_libName.c_str(), nullptr, 0);
#elif defined(__EMSCRIPTEN__)
_handle = nullptr;
#else
_handle = dlopen(_libName.c_str(), RTLD_LOCAL | RTLD_LAZY);
#endif
return _handle != nullptr;
}

void DynamicLibrary::unload() {
if (_handle != nullptr) {
#ifdef _WIN32
::FreeLibrary(static_cast<HMODULE>(_handle));
#elif defined(__EMSCRIPTEN__)
// do nothing
#else
dlclose(_handle);
#endif
_handle = nullptr;
}
}

bool DynamicLibrary::isLoaded() const {
return _handle != nullptr;
}

void* DynamicLibrary::getProcAddress(const std::string &key) const {
if (_handle == nullptr) {
return nullptr;
}
#ifdef _WIN32
return reinterpret_cast<void*>(::GetProcAddress(static_cast<HMODULE>(_handle), key.c_str()));
#elif defined(__EMSCRIPTEN__)
return nullptr;
#else
return dlsym(_handle, key.c_str());
#endif
}

} // namespace cc
30 changes: 30 additions & 0 deletions native/cocos/base/DynamicLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "base/std/container/string.h"

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif


namespace cc {

class DynamicLibrary {
public:
explicit DynamicLibrary(ccstd::string name) : _libName(std::move(name)) {}
~DynamicLibrary();

bool load();
void unload();
bool isLoaded() const;

void* getProcAddress(const std::string &key) const;

private:
std::string _libName;
void *_handle = nullptr;
};

} // namespace cc
2 changes: 1 addition & 1 deletion native/cocos/platform/java/modules/XRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include "gfx-vulkan/VKDevice.h"
#endif
#ifdef CC_USE_GLES3
#include "gfx-gles-common/gles3w.h"
#include "gfx-gles-common/loader/gles3w.h"
#include "gfx-gles3/GLES3Device.h"
#include "renderer/gfx-gles3/GLES3GPUObjects.h"
#endif
Expand Down
103 changes: 103 additions & 0 deletions native/cocos/renderer/GFXDeviceManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "GFXDeviceManager.h"


#ifdef CC_USE_NVN
#include "gfx-nvn/NVNDevice.h"
#endif

#ifdef CC_USE_VULKAN
#include "gfx-vulkan/VKDevice.h"
#endif

#ifdef CC_USE_METAL
#include "gfx-metal/MTLDevice.h"
#endif

#ifdef CC_USE_GLES3
#include "gfx-gles3/GLES3Device.h"
#endif

#ifdef CC_USE_GLES2
#include "gfx-gles2/GLES2Device.h"
#endif

#ifdef CC_USE_GLES_NEW
#include "gfx-gles-common/common/GLESDevice.h"
#endif

#include "gfx-empty/EmptyDevice.h"

namespace cc::gfx {
namespace {
#ifdef CC_USE_GLES_NEW
constexpr bool DETACH_DEVICE_THREAD{false};
constexpr bool FORCE_DISABLE_VALIDATION{true};
constexpr bool FORCE_ENABLE_VALIDATION{false};
#else
constexpr bool DETACH_DEVICE_THREAD{true};
constexpr bool FORCE_DISABLE_VALIDATION{false};
constexpr bool FORCE_ENABLE_VALIDATION{false};
#endif
} // namespace

bool DeviceManager::isDetachDeviceThread() {
return DETACH_DEVICE_THREAD && Device::isSupportDetachDeviceThread;
}

bool DeviceManager::isValidationSupported() {
return !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION;
}

Device *DeviceManager::create(const DeviceInfo &info) {
if (Device::instance) return Device::instance;

Device *device = nullptr;

#ifdef CC_USE_NVN
if (tryCreate<CCNVNDevice>(info, &device)) return device;
#endif

#ifdef CC_USE_VULKAN
#if XR_OEM_PICO
Device::isSupportDetachDeviceThread = false;
#endif

bool skipVulkan = false;
#if CC_PLATFORM == CC_PLATFORM_ANDROID
auto sdkVersion = BasePlatform::getPlatform()->getSdkVersion();
skipVulkan = sdkVersion <= 27; // Android 8
#endif
// if (!skipVulkan && tryCreate<CCVKDevice>(info, &device)) return device;
#endif

#ifdef CC_USE_METAL
if (tryCreate<CCMTLDevice>(info, &device)) return device;
#endif

#ifdef CC_USE_GLES_NEW
if (tryCreate<GLESDevice>(info, &device)) return device;
#endif

#ifdef CC_USE_GLES3
#if CC_USE_XR || CC_USE_AR_MODULE
Device::isSupportDetachDeviceThread = false;
#endif
if (tryCreate<GLES3Device>(info, &device)) return device;
#endif

#ifdef CC_USE_GLES2
// arcore & arengine currently only supports gles, session update requires gl context
#if CC_USE_AR_MODULE
Device::isSupportDetachDeviceThread = false;
#endif
if (tryCreate<GLES2Device>(info, &device)) return device;
#endif

#ifdef CC_EDITOR
Device::isSupportDetachDeviceThread = false;
#endif
if (tryCreate<EmptyDevice>(info, &device)) return device;

return nullptr;
}
} // namespace cc::gfx
Loading
Loading