[Feat] (Diligent): Add Diligent Vulkan backend.

This commit is contained in:
BZLZHH
2025-05-25 11:46:38 +08:00
parent 604482d55c
commit 2466897531
6 changed files with 64 additions and 18 deletions
+2 -1
View File
@@ -53,7 +53,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
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/MG_GL/State/Core/GLState.cpp
@@ -119,6 +119,7 @@ target_link_libraries(MobileGL
PRIVATE
Diligent-Common
Diligent-GraphicsEngineOpenGL-shared
Diligent-GraphicsEngineVk-shared
)
if (PROFILING)
+4
View File
@@ -178,6 +178,10 @@ namespace MG_Constants {
#define BACKEND_METAL 0x0016
#define BACKEND_GLES 0x0017
#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";
+1
View File
@@ -138,6 +138,7 @@
#if BACKEND_TYPE == BACKEND_DILIGENT
#include "EngineFactory.h"
#include "EngineFactoryOpenGL.h"
#include "EngineFactoryVk.h"
#include "RefCntAutoPtr.hpp"
#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;
}
@@ -4,6 +4,7 @@
#include "EGL_impl.h"
typedef Diligent::IEngineFactoryVk* (*Diligent_GetEngineFactoryVk_t)();
typedef Diligent::IEngineFactoryOpenGL* (*Diligent_GetEngineFactoryOpenGL_t)();
using namespace Diligent;
@@ -53,9 +54,8 @@ void main(in PSInput PSIn,
PSOut.Color = float4(PSIn.Color.rgb, 1.0);
}
)";
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
const EGLint *attrib_list) {
void LoadDiligentCoreOpenGL(NativeWindowType window) {
void *handle = dlopen("libGraphicsEngineOpenGL.so", RTLD_LAZY);
auto Diligent_GetEngineFactoryOpenGL =
(Diligent_GetEngineFactoryOpenGL_t) dlsym(handle,
@@ -68,10 +68,44 @@ void main(in PSInput PSIn,
::Diligent::SwapChainDesc SCDesc;
auto &ctx = MG_EGL::Diligent::DeviceContext::GetInstance();
pFactoryOpenGL->CreateDeviceAndSwapChainGL(
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
@@ -205,8 +239,6 @@ void main(in PSInput PSIn,
}
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) {
auto &ctx = MG_EGL::Diligent::DeviceContext::GetInstance();
// Clear the back buffer
const float ClearColor[] = {0.350f, 0.350f, 0.350f, 1.0f};
// Let the engine perform required state transitions
@@ -226,6 +258,7 @@ void main(in PSInput PSIn,
DrawAttribs drawAttrs;
drawAttrs.NumVertices = 3; // We will render 3 vertices
ctx.pContext->Draw(drawAttrs);
ctx.pContext->Flush();
ctx.pSwapChain->Present();
@@ -2,22 +2,17 @@
// Created by Swung 0x48 on 2025-05-18.
//
#ifndef MOBILEGLUES_EGL_IMPL_H
#define MOBILEGLUES_EGL_IMPL_H
#ifndef MOBILEGL_EGL_IMPL_H
#define MOBILEGL_EGL_IMPL_H
#include "../../../../../Includes.h"
#include "../../../../Includes.h"
#include "DiligentConfig.h"
#if BACKEND_TYPE == BACKEND_DILIGENT
namespace MG_EGL::Diligent {
struct DeviceContext {
public:
static inline DeviceContext& GetInstance() {
static DeviceContext devctx;
return devctx;
}
::Diligent::RefCntAutoPtr<::Diligent::IRenderDevice> pDevice;
::Diligent::RefCntAutoPtr<::Diligent::IDeviceContext> pContext;
::Diligent::RefCntAutoPtr<::Diligent::ISwapChain> pSwapChain;
@@ -27,6 +22,8 @@ namespace MG_EGL::Diligent {
int minorVer = 5;
};
static struct DeviceContext ctx;
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);
@@ -59,4 +56,4 @@ MG_EXPORT __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char
#endif
#endif //MOBILEGLUES_EGL_IMPL_H
#endif //MOBILEGL_EGL_IMPL_H