Skip to content

Commit

Permalink
[refactoring]gfx gles common objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesky013 committed Aug 4, 2023
1 parent b523c5c commit 342312d
Show file tree
Hide file tree
Showing 67 changed files with 6,859 additions and 170 deletions.
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
101 changes: 85 additions & 16 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 @@ -1171,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 @@ -1614,18 +1616,61 @@ cocos_source_files(
# )

if(CC_USE_GLES2 OR CC_USE_GLES3)
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/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
)
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
Expand All @@ -1640,7 +1685,8 @@ if(CC_USE_GLES2 OR CC_USE_GLES3)
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 @@ -1682,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 @@ -1732,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 @@ -3151,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
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
84 changes: 4 additions & 80 deletions native/cocos/renderer/GFXDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,95 +35,19 @@
// #undef CC_USE_METAL
// #undef CC_USE_GLES3
// #undef CC_USE_GLES2

#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

#include "gfx-empty/EmptyDevice.h"
#include "renderer/pipeline/Define.h"

namespace cc {
namespace gfx {
class CC_DLL DeviceManager final {
static constexpr bool DETACH_DEVICE_THREAD{true};
static constexpr bool FORCE_DISABLE_VALIDATION{false};
static constexpr bool FORCE_ENABLE_VALIDATION{false};

public:
static Device *create() {
DeviceInfo deviceInfo{pipeline::bindingMappingInfo};
return DeviceManager::create(deviceInfo);
}

static Device *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_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;
}

static bool isDetachDeviceThread() {
return DETACH_DEVICE_THREAD && Device::isSupportDetachDeviceThread;
}
static bool isDetachDeviceThread();
static bool isValidationSupported();
static Device *create(const DeviceInfo &info);

static ccstd::string getGFXName() {
ccstd::string gfx = "unknown";
Expand Down Expand Up @@ -154,7 +78,7 @@ class CC_DLL DeviceManager final {
}

#if !defined(CC_SERVER_MODE)
if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) {
if (CC_DEBUG > 0 && isValidationSupported()) {
device = ccnew gfx::DeviceValidator(device);
}
#endif
Expand Down
1 change: 0 additions & 1 deletion native/cocos/renderer/gfx-base/GFXDef-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class CommandBuffer;
class Queue;
class QueryPool;
class Window;
class Context;

using BufferBarrierList = ccstd::vector<BufferBarrier *>;
using TextureBarrierList = ccstd::vector<TextureBarrier *>;
Expand Down
Loading

0 comments on commit 342312d

Please sign in to comment.