mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Feat] (Diligent): Add Diligent Vulkan backend.
This commit is contained in:
+2
-1
@@ -53,7 +53,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
|
|||||||
|
|
||||||
MG/MG_GL/Implementations/EGL/GLES/EGL_WRAP.cpp
|
MG/MG_GL/Implementations/EGL/GLES/EGL_WRAP.cpp
|
||||||
|
|
||||||
MG/MG_GL/Implementations/EGL/Diligent/GLES/EGL_impl.cpp
|
MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp
|
||||||
|
|
||||||
# MG_GL/State
|
# MG_GL/State
|
||||||
MG/MG_GL/State/Core/GLState.cpp
|
MG/MG_GL/State/Core/GLState.cpp
|
||||||
@@ -119,6 +119,7 @@ target_link_libraries(MobileGL
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
Diligent-Common
|
Diligent-Common
|
||||||
Diligent-GraphicsEngineOpenGL-shared
|
Diligent-GraphicsEngineOpenGL-shared
|
||||||
|
Diligent-GraphicsEngineVk-shared
|
||||||
)
|
)
|
||||||
|
|
||||||
if (PROFILING)
|
if (PROFILING)
|
||||||
|
|||||||
@@ -178,6 +178,10 @@ namespace MG_Constants {
|
|||||||
#define BACKEND_METAL 0x0016
|
#define BACKEND_METAL 0x0016
|
||||||
#define BACKEND_GLES 0x0017
|
#define BACKEND_GLES 0x0017
|
||||||
#define BACKEND_DILIGENT 0x0018
|
#define BACKEND_DILIGENT 0x0018
|
||||||
|
|
||||||
|
inline const int BACKEND_DILIGENT_VULKAN = 0x0020;
|
||||||
|
inline const int BACKEND_DILIGENT_METAL = 0x0021; // not ready currently
|
||||||
|
inline const int BACKEND_DILIGENT_OPENGL = 0x0022;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char* RenderName = "MobileGL";
|
inline const char* RenderName = "MobileGL";
|
||||||
|
|||||||
@@ -138,6 +138,7 @@
|
|||||||
#if BACKEND_TYPE == BACKEND_DILIGENT
|
#if BACKEND_TYPE == BACKEND_DILIGENT
|
||||||
#include "EngineFactory.h"
|
#include "EngineFactory.h"
|
||||||
#include "EngineFactoryOpenGL.h"
|
#include "EngineFactoryOpenGL.h"
|
||||||
|
#include "EngineFactoryVk.h"
|
||||||
#include "RefCntAutoPtr.hpp"
|
#include "RefCntAutoPtr.hpp"
|
||||||
|
|
||||||
#include "PipelineState.h"
|
#include "PipelineState.h"
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by BZLZHH on 2025/5/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../../../../Includes.h"
|
||||||
|
|
||||||
|
namespace MG_EGL::Diligent {
|
||||||
|
inline const int DILIGENT_BACKEND_TYPE = MG_Constants::Backend::BACKEND_DILIGENT_VULKAN;
|
||||||
|
}
|
||||||
+39
-6
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "EGL_impl.h"
|
#include "EGL_impl.h"
|
||||||
|
|
||||||
|
typedef Diligent::IEngineFactoryVk* (*Diligent_GetEngineFactoryVk_t)();
|
||||||
typedef Diligent::IEngineFactoryOpenGL* (*Diligent_GetEngineFactoryOpenGL_t)();
|
typedef Diligent::IEngineFactoryOpenGL* (*Diligent_GetEngineFactoryOpenGL_t)();
|
||||||
|
|
||||||
using namespace Diligent;
|
using namespace Diligent;
|
||||||
@@ -54,8 +55,7 @@ void main(in PSInput PSIn,
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
void LoadDiligentCoreOpenGL(NativeWindowType window) {
|
||||||
const EGLint *attrib_list) {
|
|
||||||
void *handle = dlopen("libGraphicsEngineOpenGL.so", RTLD_LAZY);
|
void *handle = dlopen("libGraphicsEngineOpenGL.so", RTLD_LAZY);
|
||||||
auto Diligent_GetEngineFactoryOpenGL =
|
auto Diligent_GetEngineFactoryOpenGL =
|
||||||
(Diligent_GetEngineFactoryOpenGL_t) dlsym(handle,
|
(Diligent_GetEngineFactoryOpenGL_t) dlsym(handle,
|
||||||
@@ -68,10 +68,44 @@ void main(in PSInput PSIn,
|
|||||||
|
|
||||||
::Diligent::SwapChainDesc SCDesc;
|
::Diligent::SwapChainDesc SCDesc;
|
||||||
|
|
||||||
auto &ctx = MG_EGL::Diligent::DeviceContext::GetInstance();
|
|
||||||
|
|
||||||
pFactoryOpenGL->CreateDeviceAndSwapChainGL(
|
pFactoryOpenGL->CreateDeviceAndSwapChainGL(
|
||||||
EngineCI, &ctx.pDevice, &ctx.pContext, SCDesc, &ctx.pSwapChain);
|
EngineCI, &ctx.pDevice, &ctx.pContext, SCDesc, &ctx.pSwapChain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadDiligentCoreVulkan(NativeWindowType window) {
|
||||||
|
void *handle = dlopen("libGraphicsEngineVk.so", RTLD_LAZY);
|
||||||
|
auto Diligent_GetEngineFactoryVk =
|
||||||
|
(Diligent_GetEngineFactoryVk_t) dlsym(handle,
|
||||||
|
"Diligent_GetEngineFactoryVk");
|
||||||
|
|
||||||
|
auto *pFactoryVk = Diligent_GetEngineFactoryVk();
|
||||||
|
::Diligent::EngineVkCreateInfo EngineCI;
|
||||||
|
|
||||||
|
::Diligent::SwapChainDesc SCDesc;
|
||||||
|
|
||||||
|
pFactoryVk->CreateDeviceAndContextsVk(
|
||||||
|
EngineCI, &ctx.pDevice, &ctx.pContext);
|
||||||
|
AndroidNativeWindow nativeWindow{window};
|
||||||
|
pFactoryVk->CreateSwapChainVk(
|
||||||
|
ctx.pDevice, ctx.pContext, SCDesc, nativeWindow, &ctx.pSwapChain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadDiligentCore(NativeWindowType window) {
|
||||||
|
switch (DILIGENT_BACKEND_TYPE) {
|
||||||
|
case MG_Constants::Backend::BACKEND_DILIGENT_VULKAN:
|
||||||
|
LoadDiligentCoreVulkan(window);
|
||||||
|
break;
|
||||||
|
case MG_Constants::Backend::BACKEND_DILIGENT_OPENGL:
|
||||||
|
default:
|
||||||
|
LoadDiligentCoreOpenGL(window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||||
|
const EGLint *attrib_list) {
|
||||||
|
LoadDiligentCore(window);
|
||||||
|
|
||||||
// Pipeline state object encompasses configuration of all GPU stages
|
// Pipeline state object encompasses configuration of all GPU stages
|
||||||
|
|
||||||
@@ -205,8 +239,6 @@ void main(in PSInput PSIn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) {
|
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) {
|
||||||
auto &ctx = MG_EGL::Diligent::DeviceContext::GetInstance();
|
|
||||||
|
|
||||||
// Clear the back buffer
|
// Clear the back buffer
|
||||||
const float ClearColor[] = {0.350f, 0.350f, 0.350f, 1.0f};
|
const float ClearColor[] = {0.350f, 0.350f, 0.350f, 1.0f};
|
||||||
// Let the engine perform required state transitions
|
// Let the engine perform required state transitions
|
||||||
@@ -226,6 +258,7 @@ void main(in PSInput PSIn,
|
|||||||
DrawAttribs drawAttrs;
|
DrawAttribs drawAttrs;
|
||||||
drawAttrs.NumVertices = 3; // We will render 3 vertices
|
drawAttrs.NumVertices = 3; // We will render 3 vertices
|
||||||
ctx.pContext->Draw(drawAttrs);
|
ctx.pContext->Draw(drawAttrs);
|
||||||
|
ctx.pContext->Flush();
|
||||||
|
|
||||||
ctx.pSwapChain->Present();
|
ctx.pSwapChain->Present();
|
||||||
|
|
||||||
+7
-10
@@ -2,22 +2,17 @@
|
|||||||
// Created by Swung 0x48 on 2025-05-18.
|
// Created by Swung 0x48 on 2025-05-18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MOBILEGLUES_EGL_IMPL_H
|
#ifndef MOBILEGL_EGL_IMPL_H
|
||||||
#define MOBILEGLUES_EGL_IMPL_H
|
#define MOBILEGL_EGL_IMPL_H
|
||||||
|
|
||||||
|
#include "../../../../Includes.h"
|
||||||
#include "../../../../../Includes.h"
|
#include "DiligentConfig.h"
|
||||||
|
|
||||||
#if BACKEND_TYPE == BACKEND_DILIGENT
|
#if BACKEND_TYPE == BACKEND_DILIGENT
|
||||||
|
|
||||||
namespace MG_EGL::Diligent {
|
namespace MG_EGL::Diligent {
|
||||||
struct DeviceContext {
|
struct DeviceContext {
|
||||||
public:
|
public:
|
||||||
static inline DeviceContext& GetInstance() {
|
|
||||||
static DeviceContext devctx;
|
|
||||||
return devctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
::Diligent::RefCntAutoPtr<::Diligent::IRenderDevice> pDevice;
|
::Diligent::RefCntAutoPtr<::Diligent::IRenderDevice> pDevice;
|
||||||
::Diligent::RefCntAutoPtr<::Diligent::IDeviceContext> pContext;
|
::Diligent::RefCntAutoPtr<::Diligent::IDeviceContext> pContext;
|
||||||
::Diligent::RefCntAutoPtr<::Diligent::ISwapChain> pSwapChain;
|
::Diligent::RefCntAutoPtr<::Diligent::ISwapChain> pSwapChain;
|
||||||
@@ -28,6 +23,8 @@ namespace MG_EGL::Diligent {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct DeviceContext ctx;
|
||||||
|
|
||||||
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint* attrib_list);
|
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint* attrib_list);
|
||||||
EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size, EGLint* num_config);
|
EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size, EGLint* num_config);
|
||||||
EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list);
|
EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list);
|
||||||
@@ -59,4 +56,4 @@ MG_EXPORT __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif //MOBILEGLUES_EGL_IMPL_H
|
#endif //MOBILEGL_EGL_IMPL_H
|
||||||
Reference in New Issue
Block a user