mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Feat] (MG_Backend/DirectVulkan|MG_Util): Get Vulkan device info.
This commit is contained in:
@@ -168,6 +168,7 @@ set(SOURCE_FILES
|
|||||||
MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/EliminateFloatEqualsZeroPass.cpp
|
MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/EliminateFloatEqualsZeroPass.cpp
|
||||||
|
|
||||||
MobileGL/MG_Util/BackendLoaders/OpenGL/Loader.cpp
|
MobileGL/MG_Util/BackendLoaders/OpenGL/Loader.cpp
|
||||||
|
MobileGL/MG_Util/BackendLoaders/Vulkan/Loader.cpp
|
||||||
|
|
||||||
MobileGL/MG_Util/Texture/PixelStoreProcessor.cpp
|
MobileGL/MG_Util/Texture/PixelStoreProcessor.cpp
|
||||||
MobileGL/MG_Util/Texture/TextureFormatProcessor.cpp
|
MobileGL/MG_Util/Texture/TextureFormatProcessor.cpp
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#include "BackendObject_DirectVulkan.h"
|
#include "BackendObject_DirectVulkan.h"
|
||||||
#include "MG_Backend/BackendObject.h"
|
#include "MG_Backend/BackendObject.h"
|
||||||
#include <MG_Backend/DirectVulkan/DirectVulkan.h>
|
#include <MG_Backend/DirectVulkan/DirectVulkan.h>
|
||||||
|
#include <MG_Backend/DirectVulkan/TmpImpl.h>
|
||||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||||
#include <format>
|
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
BackendObject_DirectVulkan::~BackendObject_DirectVulkan() = default;
|
BackendObject_DirectVulkan::~BackendObject_DirectVulkan() = default;
|
||||||
@@ -24,7 +24,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
|
|
||||||
void BackendObject_DirectVulkan::Initialize() {
|
void BackendObject_DirectVulkan::Initialize() {
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
// TODO
|
}
|
||||||
|
|
||||||
|
void BackendObject_DirectVulkan::InitCapabilities() {
|
||||||
|
if (!m_initialized) {
|
||||||
|
MGLOG_E("Cannot initialize capabilities before backend is initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MG_Util::BackendLoader::QueryVulkanCapabilities(m_vulkanCaps,
|
||||||
|
DirectVulkan::GetVulkanState().ctx->GetPhysicalDevice());
|
||||||
UpdateDynamicBackendParameters();
|
UpdateDynamicBackendParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +62,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
// Format:
|
// Format:
|
||||||
// <GPU Name>, Vulkan <Vulkan Version>, Driver <Driver Version>
|
// <GPU Name>, Vulkan <Vulkan Version>, Driver <Driver Version>
|
||||||
// TODO
|
// TODO
|
||||||
return "Vulkan";
|
String str = m_vulkanCaps.DeviceName + ", Vulkan " + m_vulkanCaps.VulkanAPIVersion.toString() + ", Driver " +
|
||||||
|
m_vulkanCaps.DriverVersionString;
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendType BackendObject_DirectVulkan::GetBackendType() const {
|
BackendType BackendObject_DirectVulkan::GetBackendType() const {
|
||||||
@@ -103,6 +114,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BackendObject_DirectVulkan::UpdateDynamicBackendParameters() {
|
void BackendObject_DirectVulkan::UpdateDynamicBackendParameters() {
|
||||||
m_dynamicParameters.UniformBufferOffsetAlignment = 256; // TODO
|
m_dynamicParameters.UniformBufferOffsetAlignment = m_vulkanCaps.UniformBufferOffsetAlignment;
|
||||||
}
|
}
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
@@ -9,13 +9,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Includes.h>
|
#include <Includes.h>
|
||||||
#include "../BackendObject.h"
|
#include "../BackendObject.h"
|
||||||
|
#include <MG_Util/BackendLoaders/Vulkan/Loader.h>
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
class BackendObject_DirectVulkan : public BackendObject {
|
class BackendObject_DirectVulkan : public BackendObject {
|
||||||
public:
|
public:
|
||||||
~BackendObject_DirectVulkan() override;
|
~BackendObject_DirectVulkan() override;
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
void InitWindowSurface() override;
|
void InitWindowSurface() override;
|
||||||
|
void InitCapabilities() override;
|
||||||
|
|
||||||
const RendererInfo& GetRendererInfo() const override;
|
const RendererInfo& GetRendererInfo() const override;
|
||||||
String GetBackendAPIVersionString() const override;
|
String GetBackendAPIVersionString() const override;
|
||||||
@@ -28,5 +31,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
|
|
||||||
Bool m_initialized = false;
|
Bool m_initialized = false;
|
||||||
DynamicBackendParameters m_dynamicParameters;
|
DynamicBackendParameters m_dynamicParameters;
|
||||||
|
MG_External::VulkanCapabilities m_vulkanCaps;
|
||||||
};
|
};
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
@@ -67,4 +67,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
void Present() {
|
void Present() {
|
||||||
TmpImpl::Present();
|
TmpImpl::Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TmpImpl::VulkanState& GetVulkanState() {
|
||||||
|
return TmpImpl::GetVulkanState();
|
||||||
|
}
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
#include "Renderer/VulkanRenderer.h"
|
#include "Renderer/VulkanRenderer.h"
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
|
namespace TmpImpl {
|
||||||
|
class VulkanState;
|
||||||
|
} // namespace TmpImpl
|
||||||
|
|
||||||
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||||
void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value);
|
void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value);
|
||||||
void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value);
|
void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value);
|
||||||
@@ -51,4 +55,5 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
void GetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid* pixels);
|
void GetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid* pixels);
|
||||||
Bool InitWindowSurface(NativeWindowType window);
|
Bool InitWindowSurface(NativeWindowType window);
|
||||||
void Present();
|
void Present();
|
||||||
|
const TmpImpl::VulkanState& GetVulkanState();
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -8,11 +8,229 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Includes.h>
|
#include <Includes.h>
|
||||||
|
#include "Renderer/VkCommon.h"
|
||||||
|
#include "Renderer/VulkanContext.h"
|
||||||
|
#include "Renderer/SwapchainManager.h"
|
||||||
|
#include "Renderer/FrameContext.h"
|
||||||
|
#include "Managers/ProgramManager.h"
|
||||||
|
#include <MG_State/GLState/Core.h>
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan::TmpImpl {
|
namespace MobileGL::MG_Backend::DirectVulkan::TmpImpl {
|
||||||
|
namespace DV = MobileGL::MG_Backend::DirectVulkan::VkManager;
|
||||||
|
using BufferObject = MobileGL::MG_State::GLState::BufferObject;
|
||||||
|
using ProgramObject = MobileGL::MG_State::GLState::ProgramObject;
|
||||||
|
using VertexArrayObject = MobileGL::MG_State::GLState::VertexArrayObject;
|
||||||
|
using FramebufferObject = MobileGL::MG_State::GLState::FramebufferObject;
|
||||||
|
using FramebufferAttachmentObject = MobileGL::MG_State::GLState::FramebufferAttachmentObject;
|
||||||
|
using ITextureObject = MobileGL::MG_State::GLState::ITextureObject;
|
||||||
|
using RenderbufferObject = MobileGL::MG_State::GLState::RenderbufferObject;
|
||||||
|
using SamplerObject = MobileGL::MG_State::GLState::SamplerObject;
|
||||||
|
using TextureObjectMipmap = MobileGL::MG_State::GLState::TextureObjectMipmap;
|
||||||
|
using TrashImage = MobileGL::MG_Backend::DirectVulkan::TrashImage;
|
||||||
|
|
||||||
|
struct BufferResource {
|
||||||
|
VkBuffer buffer = VK_NULL_HANDLE;
|
||||||
|
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||||
|
VkDeviceSize size = 0;
|
||||||
|
VkBufferUsageFlags usage = 0;
|
||||||
|
VkMemoryPropertyFlags props = 0;
|
||||||
|
void* mapped = nullptr;
|
||||||
|
Uint32 lastUsedFrame = ~0u;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TextureResource {
|
||||||
|
VkImage image = VK_NULL_HANDLE;
|
||||||
|
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||||
|
VkImageView view = VK_NULL_HANDLE;
|
||||||
|
UnorderedMap<Uint32, VkImageView> mipViews;
|
||||||
|
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||||
|
VkExtent3D extent{0, 0, 1};
|
||||||
|
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
Uint32 mipLevels = 1;
|
||||||
|
Uint16 paramsVersion = 0;
|
||||||
|
bool valid = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RenderbufferResource {
|
||||||
|
VkImage image = VK_NULL_HANDLE;
|
||||||
|
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||||
|
VkImageView view = VK_NULL_HANDLE;
|
||||||
|
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||||
|
VkExtent2D extent{0, 0};
|
||||||
|
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
bool valid = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SamplerResource {
|
||||||
|
VkSampler sampler = VK_NULL_HANDLE;
|
||||||
|
Uint16 version = 0;
|
||||||
|
SamplerParameters params{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PendingClearInfo {
|
||||||
|
GLbitfield mask = 0;
|
||||||
|
FloatVec4 clearColor = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
Float clearDepth = 1.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UniformBindingInfo {
|
||||||
|
String name;
|
||||||
|
Uint32 binding = 0;
|
||||||
|
Uint32 set = 0;
|
||||||
|
Uint32 blockIndex = 0xFFFFFFFFu;
|
||||||
|
VkShaderStageFlags stages = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SamplerBindingInfo {
|
||||||
|
String name;
|
||||||
|
Uint32 binding = 0;
|
||||||
|
Uint32 set = 0;
|
||||||
|
VkShaderStageFlags stages = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ProgramResource {
|
||||||
|
ProgramObject* program = nullptr;
|
||||||
|
Uint64 spvHash = 0;
|
||||||
|
DV::ProgramManager::HashType programHash = 0;
|
||||||
|
Vector<VkPipelineShaderStageCreateInfo>* shaderStages = nullptr;
|
||||||
|
|
||||||
|
VkDescriptorSetLayout setLayout = VK_NULL_HANDLE;
|
||||||
|
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
struct UboPool {
|
||||||
|
Vector<BufferResource> buffers;
|
||||||
|
Uint32 cursor = 0;
|
||||||
|
};
|
||||||
|
Vector<UboPool> uboPools;
|
||||||
|
SizeT uboSize = 0;
|
||||||
|
Int32 uboBinding = -1;
|
||||||
|
Uint32 uniformDescriptorCount = 0;
|
||||||
|
Uint32 samplerDescriptorCount = 0;
|
||||||
|
|
||||||
|
Vector<UniformBindingInfo> uniformBindings;
|
||||||
|
Vector<SamplerBindingInfo> samplerBindings;
|
||||||
|
UnorderedMap<String, Uint32> samplerBindingByName;
|
||||||
|
|
||||||
|
UnorderedMap<Uint64, VkPipeline> pipelines;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DescriptorPoolConfig {
|
||||||
|
Uint32 maxSets = 0;
|
||||||
|
Uint32 uniformCount = 0;
|
||||||
|
Uint32 samplerCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FrameDescriptorPools {
|
||||||
|
Vector<VkDescriptorPool> pools;
|
||||||
|
DescriptorPoolConfig config;
|
||||||
|
Uint32 activePool = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexAttribKey {
|
||||||
|
Uint8 enabled = 0;
|
||||||
|
Uint8 size = 0;
|
||||||
|
Uint8 type = 0;
|
||||||
|
Uint8 normalized = 0;
|
||||||
|
Uint8 isInteger = 0;
|
||||||
|
Uint8 divisor = 0;
|
||||||
|
Uint16 pad = 0;
|
||||||
|
Uint32 stride = 0;
|
||||||
|
Uint64 offset = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AttachmentInfo {
|
||||||
|
FramebufferAttachmentType type = FramebufferAttachmentType::None;
|
||||||
|
VkImageView view = VK_NULL_HANDLE;
|
||||||
|
VkFormat format = VK_FORMAT_UNDEFINED;
|
||||||
|
VkImageAspectFlags aspect = 0;
|
||||||
|
VkImageLayout finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
ITextureObject* texture = nullptr;
|
||||||
|
RenderbufferObject* renderbuffer = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BackendFramebufferObject {
|
||||||
|
Array<VkRenderPass, 8> renderPasses = {};
|
||||||
|
VkFramebuffer framebuffer = VK_NULL_HANDLE;
|
||||||
|
VkExtent2D extent{0, 0};
|
||||||
|
Uint32 colorAttachmentCount = 0;
|
||||||
|
Bool hasDepth = false;
|
||||||
|
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
Uint64 renderPassCompatHash = 0;
|
||||||
|
|
||||||
|
Vector<AttachmentInfo> attachments;
|
||||||
|
Array<Int32, static_cast<SizeT>(FramebufferAttachmentType::FramebufferAttachmentTypeCount)> attachmentIndex =
|
||||||
|
{};
|
||||||
|
|
||||||
|
FramebufferObject::FramebufferAttachmentVersionArray syncedAttachmentVersions = {0};
|
||||||
|
FramebufferObject::FramebufferAttachmentArray frontendDrawBuffers = {FramebufferAttachmentType::None};
|
||||||
|
Array<Int32, FramebufferObject::MAX_DRAW_BUFFERS> drawBufferAttachmentIndices = {};
|
||||||
|
FramebufferAttachmentType frontendReadBuffer = FramebufferAttachmentType::Color0;
|
||||||
|
Uint64 configHash = 0;
|
||||||
|
Uint16 objectVersion = 0;
|
||||||
|
|
||||||
|
Bool IsValid() const { return renderPasses[0] != VK_NULL_HANDLE && framebuffer != VK_NULL_HANDLE; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VulkanState {
|
||||||
|
UniquePtr<DV::VulkanContext> ctx;
|
||||||
|
UniquePtr<DV::SwapchainManager> swapchain;
|
||||||
|
UniquePtr<DV::ProgramManager> programMgr;
|
||||||
|
Array<VkRenderPass, 8> renderPasses = {};
|
||||||
|
VkCommandPool commandPool = VK_NULL_HANDLE;
|
||||||
|
Vector<UniquePtr<DV::FrameContext>> frames;
|
||||||
|
Vector<FrameDescriptorPools> frameDescriptorPools;
|
||||||
|
Uint32 currentFrame = 0;
|
||||||
|
Uint32 maxFramesInFlight = 2;
|
||||||
|
Bool initialized = false;
|
||||||
|
UintVec2 viewportSize{0, 0};
|
||||||
|
|
||||||
|
VkImage depthImage = VK_NULL_HANDLE;
|
||||||
|
VkDeviceMemory depthMemory = VK_NULL_HANDLE;
|
||||||
|
VkImageView depthView = VK_NULL_HANDLE;
|
||||||
|
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
Uint64 defaultRenderPassCompatHash = 0;
|
||||||
|
|
||||||
|
BufferResource nullUbo;
|
||||||
|
|
||||||
|
TextureResource defaultTexture;
|
||||||
|
SamplerResource defaultSampler;
|
||||||
|
|
||||||
|
UnorderedMap<const BufferObject*, BufferResource> buffers;
|
||||||
|
UnorderedMap<const ITextureObject*, TextureResource> textures;
|
||||||
|
UnorderedMap<const RenderbufferObject*, RenderbufferResource> renderbuffers;
|
||||||
|
UnorderedMap<const SamplerObject*, SamplerResource> samplers;
|
||||||
|
UnorderedMap<const ProgramObject*, ProgramResource> programs;
|
||||||
|
UnorderedMap<SharedPtr<MG_State::GLState::FramebufferObject>, SharedPtr<BackendFramebufferObject>> framebuffers;
|
||||||
|
|
||||||
|
VkRenderPass activeRenderPass = VK_NULL_HANDLE;
|
||||||
|
VkFramebuffer activeFramebuffer = VK_NULL_HANDLE;
|
||||||
|
VkExtent2D activeExtent{0, 0};
|
||||||
|
Uint32 activeColorAttachmentCount = 1;
|
||||||
|
Bool activeHasDepth = false;
|
||||||
|
VkFormat activeDepthFormat = VK_FORMAT_UNDEFINED;
|
||||||
|
SharedPtr<MG_State::GLState::FramebufferObject> activeStateFBO = nullptr;
|
||||||
|
SharedPtr<BackendFramebufferObject> activeBackendFBO = nullptr;
|
||||||
|
Bool activeIsDefault = true;
|
||||||
|
Bool activeDefaultColorWrites = true;
|
||||||
|
|
||||||
|
VkRenderPass recordingRenderPass = VK_NULL_HANDLE;
|
||||||
|
VkFramebuffer recordingFramebuffer = VK_NULL_HANDLE;
|
||||||
|
Bool cmdBufferBegun = false;
|
||||||
|
|
||||||
|
Bool recording = false;
|
||||||
|
Bool frameSubmitted = false;
|
||||||
|
FloatVec4 clearColor = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
Float clearDepth = 1.0f;
|
||||||
|
|
||||||
|
UnorderedMap<SharedPtr<FramebufferObject>, PendingClearInfo> pendingClears;
|
||||||
|
|
||||||
|
Vector<VkImageLayout> swapchainImageLayouts;
|
||||||
|
};
|
||||||
|
|
||||||
void Present();
|
void Present();
|
||||||
void FrameBegin();
|
void FrameBegin();
|
||||||
void InitVulkan(ANativeWindow* window);
|
void InitVulkan(ANativeWindow* window);
|
||||||
|
const VulkanState& GetVulkanState();
|
||||||
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||||
void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value);
|
void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value);
|
||||||
void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value);
|
void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value);
|
||||||
@@ -49,5 +267,4 @@ namespace MobileGL::MG_Backend::DirectVulkan::TmpImpl {
|
|||||||
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width,
|
void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width,
|
||||||
GLsizei height);
|
GLsizei height);
|
||||||
void GenerateMipmap(GLenum target);
|
void GenerateMipmap(GLenum target);
|
||||||
void Present();
|
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan::TmpImpl
|
} // namespace MobileGL::MG_Backend::DirectVulkan::TmpImpl
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
// End of Source File Header
|
// End of Source File Header
|
||||||
|
|
||||||
#include "GL_Getter.h"
|
#include "GL_Getter.h"
|
||||||
#include "GL/gl.h"
|
|
||||||
#include "MG_Util/Debug/Log.h"
|
|
||||||
#include <Config.h>
|
#include <Config.h>
|
||||||
#include <MGGitHash.h>
|
#include <MGGitHash.h>
|
||||||
#include <MG_State/GLState/Core.h>
|
#include <MG_State/GLState/Core.h>
|
||||||
|
|||||||
@@ -111,9 +111,9 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::sort(m_shaders.begin(), m_shaders.end(),
|
std::sort(m_shaders.begin(), m_shaders.end(),
|
||||||
[](SharedPtr<ShaderObject>& a, SharedPtr<ShaderObject>& b) {
|
[](SharedPtr<ShaderObject>& a, SharedPtr<ShaderObject>& b) {
|
||||||
return a->GetShaderStage() < b->GetShaderStage();
|
return a->GetShaderStage() < b->GetShaderStage();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (SizeT i = 0; i < m_shaders.size(); i++) {
|
for (SizeT i = 0; i < m_shaders.size(); i++) {
|
||||||
shaderTypes[i] = MG_Util::ConvertShaderStageToGLEnum(m_shaders[i]->GetShaderStage());
|
shaderTypes[i] = MG_Util::ConvertShaderStageToGLEnum(m_shaders[i]->GetShaderStage());
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ namespace MobileGL {
|
|||||||
// Compile for OpenGL here, so that we can do validation and link
|
// Compile for OpenGL here, so that we can do validation and link
|
||||||
// like a real OpenGL driver at linking stage
|
// like a real OpenGL driver at linking stage
|
||||||
// Will compile for other backends later.
|
// Will compile for other backends later.
|
||||||
ShaderAttrib attrib{
|
ShaderAttrib attrib{.shaderType = MG_Util::ConvertShaderStageToGLEnum(m_stage),
|
||||||
.shaderType = MG_Util::ConvertShaderStageToGLEnum(m_stage), .sourceStr = m_source, .flags = ShaderCompileBits::CompileForOpenGL};
|
.sourceStr = m_source,
|
||||||
|
.flags = ShaderCompileBits::CompileForOpenGL};
|
||||||
|
|
||||||
auto result = ShaderCompiler::CompileShader(attrib);
|
auto result = ShaderCompiler::CompileShader(attrib);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Util/BackendLoaders/Vulkan/Loader.cpp
|
||||||
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||||
|
// Licensed under the GNU Lesser General Public License v3.0:
|
||||||
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||||||
|
// End of Source File Header
|
||||||
|
|
||||||
|
#include "Loader.h"
|
||||||
|
|
||||||
|
namespace MobileGL::MG_Util::BackendLoader {
|
||||||
|
inline Version DecodeApiVersion(uint32_t version) {
|
||||||
|
return {(Int)VK_VERSION_MAJOR(version), (Int)VK_VERSION_MINOR(version), (Int)VK_VERSION_PATCH(version)};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string DecodeDriverVersion(uint32_t driverVersion) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << VK_VERSION_MAJOR(driverVersion) << "." << VK_VERSION_MINOR(driverVersion) << "."
|
||||||
|
<< VK_VERSION_PATCH(driverVersion);
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool QueryVulkanCapabilities(MobileGL::MG_External::VulkanCapabilities& caps, VkPhysicalDevice physicalDevice) {
|
||||||
|
if (!physicalDevice) {
|
||||||
|
MGLOG_E("Invalid physical device handle");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPhysicalDeviceProperties props{};
|
||||||
|
vkGetPhysicalDeviceProperties(physicalDevice, &props);
|
||||||
|
|
||||||
|
if (props.apiVersion < VK_API_VERSION_1_1) {
|
||||||
|
MGLOG_E("Vulkan API version %u.%u.%u is not supported, requires at least 1.1",
|
||||||
|
VK_VERSION_MAJOR(props.apiVersion), VK_VERSION_MINOR(props.apiVersion),
|
||||||
|
VK_VERSION_PATCH(props.apiVersion));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPhysicalDeviceProperties2 props2{};
|
||||||
|
props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
|
||||||
|
vkGetPhysicalDeviceProperties2(physicalDevice, &props2);
|
||||||
|
|
||||||
|
const VkPhysicalDeviceProperties& p = props2.properties;
|
||||||
|
caps.VulkanAPIVersion = DecodeApiVersion(p.apiVersion);
|
||||||
|
caps.DeviceName = p.deviceName;
|
||||||
|
caps.DriverVersionString = DecodeDriverVersion(p.driverVersion);
|
||||||
|
caps.UniformBufferOffsetAlignment = static_cast<int>(p.limits.minUniformBufferOffsetAlignment);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace MobileGL::MG_Util::BackendLoader
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Util/BackendLoaders/Vulkan/Loader.h
|
||||||
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||||
|
// Licensed under the GNU Lesser General Public License v3.0:
|
||||||
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||||||
|
// End of Source File Header
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <Includes.h>
|
||||||
|
|
||||||
|
namespace MobileGL {
|
||||||
|
namespace MG_External {
|
||||||
|
struct VulkanCapabilities {
|
||||||
|
Version VulkanAPIVersion{1, 0, 0};
|
||||||
|
String DeviceName;
|
||||||
|
String DriverVersionString;
|
||||||
|
Int UniformBufferOffsetAlignment = 256;
|
||||||
|
};
|
||||||
|
} // namespace MG_External
|
||||||
|
namespace MG_Util::BackendLoader {
|
||||||
|
Bool QueryVulkanCapabilities(MobileGL::MG_External::VulkanCapabilities& caps, VkPhysicalDevice physicalDevice);
|
||||||
|
} // namespace MG_Util::BackendLoader
|
||||||
|
} // namespace MobileGL
|
||||||
Reference in New Issue
Block a user