mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat] (MG_Backend/DirectVulkan): VkClearManager
This commit is contained in:
@@ -229,6 +229,7 @@ set(SOURCE_FILES
|
|||||||
MobileGL/MG_Backend/DirectVulkan/Renderer/VkRenderPassManager.cpp
|
MobileGL/MG_Backend/DirectVulkan/Renderer/VkRenderPassManager.cpp
|
||||||
MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp
|
MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp
|
||||||
MobileGL/MG_Backend/DirectVulkan/Renderer/VkSamplerManager.cpp
|
MobileGL/MG_Backend/DirectVulkan/Renderer/VkSamplerManager.cpp
|
||||||
|
MobileGL/MG_Backend/DirectVulkan/Renderer/VkClearManager.cpp
|
||||||
|
|
||||||
MobileGL/MG_State/GLState/Core.cpp
|
MobileGL/MG_State/GLState/Core.cpp
|
||||||
MobileGL/MG_State/GLState/ErrorState/Error.cpp
|
MobileGL/MG_State/GLState/ErrorState/Error.cpp
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/VkClearManager.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 "VkClearManager.h"
|
||||||
|
|
||||||
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
|
Bool VkClearManager::Initialize() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VkClearManager::Shutdown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void VkClearManager::QueueClear(GLbitfield mask, const ClearFramebufferPayload& clearPayload,
|
||||||
|
MG_State::GLState::FramebufferObject& drawFbo) {
|
||||||
|
if (mask & GL_COLOR_BUFFER_BIT) {
|
||||||
|
auto& drawbufs = drawFbo.GetDrawBuffers();
|
||||||
|
// This should automatically work on default & offscreen FBO
|
||||||
|
for (auto drawbuf: drawbufs) {
|
||||||
|
if (drawbuf == FramebufferAttachmentType::None ||
|
||||||
|
drawFbo.GetAttachment(drawbuf).IsRenderbuffer())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QueueClear({
|
||||||
|
.color = clearPayload.color,
|
||||||
|
.attachmentType = drawbuf
|
||||||
|
}, drawFbo.GetAttachment(drawbuf).GetTexture());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask & GL_DEPTH_BUFFER_BIT &&
|
||||||
|
!drawFbo.GetAttachment(FramebufferAttachmentType::Depth).IsRenderbuffer()) {
|
||||||
|
QueueClear({
|
||||||
|
.depth = clearPayload.depth,
|
||||||
|
.attachmentType = FramebufferAttachmentType::Depth,
|
||||||
|
}, drawFbo.GetAttachment(FramebufferAttachmentType::Depth).GetTexture());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask & GL_STENCIL_BUFFER_BIT &&
|
||||||
|
!drawFbo.GetAttachment(FramebufferAttachmentType::Stencil).IsRenderbuffer()) {
|
||||||
|
QueueClear({
|
||||||
|
.stencil = clearPayload.stencil,
|
||||||
|
.attachmentType = FramebufferAttachmentType::Stencil,
|
||||||
|
}, drawFbo.GetAttachment(FramebufferAttachmentType::Depth).GetTexture());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VkClearManager::QueueClear(const ClearAttachmentPayload& clearPayload,
|
||||||
|
const SharedPtr<MG_State::GLState::ITextureObject>& texture) {
|
||||||
|
WeakPtr weakTexturePtr = texture;
|
||||||
|
if (weakTexturePtr.expired())
|
||||||
|
return;
|
||||||
|
auto* pTexture = weakTexturePtr.lock().get();
|
||||||
|
m_aliveObjects[pTexture] = weakTexturePtr;
|
||||||
|
m_pendingClears[pTexture] = clearPayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool VkClearManager::DequeueClear(MG_State::GLState::ITextureObject* texture, ClearAttachmentPayload& outPayload) {
|
||||||
|
if (m_aliveObjects.find(texture) == m_aliveObjects.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
outPayload = m_pendingClears[texture];
|
||||||
|
m_aliveObjects.erase(texture);
|
||||||
|
m_pendingClears.erase(texture);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SizeT VkClearManager::CollectGarbage() {
|
||||||
|
SizeT count = 0;
|
||||||
|
for (const auto& [raw, weak]: m_aliveObjects) {
|
||||||
|
if (weak.expired()) {
|
||||||
|
count++;
|
||||||
|
m_pendingClears.erase(raw);
|
||||||
|
m_aliveObjects.erase(raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Backend/DirectVulkan/Renderer/VkClearManager.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 "../VkIncludes.h"
|
||||||
|
#include "../VulkanRendererConfig.h"
|
||||||
|
#include "MG_State/GLState/FramebufferState/FramebufferObject.h"
|
||||||
|
#include "MG_Util/Math/VectorTypes.h"
|
||||||
|
|
||||||
|
#include <Includes.h>
|
||||||
|
|
||||||
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
|
struct ClearFramebufferPayload {
|
||||||
|
FloatVec4 color;
|
||||||
|
Float depth{};
|
||||||
|
Uint32 stencil{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ClearAttachmentPayload {
|
||||||
|
union {
|
||||||
|
FloatVec4 color;
|
||||||
|
Float depth{};
|
||||||
|
Uint32 stencil;
|
||||||
|
};
|
||||||
|
FramebufferAttachmentType attachmentType = FramebufferAttachmentType::Color0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class VkClearManager {
|
||||||
|
public:
|
||||||
|
Bool Initialize();
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
void QueueClear(GLbitfield mask, const ClearFramebufferPayload& clearPayload, MG_State::GLState::FramebufferObject& drawFbo);
|
||||||
|
void QueueClear(
|
||||||
|
const ClearAttachmentPayload& clearPayload,
|
||||||
|
const SharedPtr<MG_State::GLState::ITextureObject>& texture);
|
||||||
|
Bool DequeueClear(MG_State::GLState::ITextureObject* texture, ClearAttachmentPayload& outPayload);
|
||||||
|
SizeT CollectGarbage();
|
||||||
|
private:
|
||||||
|
UnorderedMap<MG_State::GLState::ITextureObject*, ClearAttachmentPayload> m_pendingClears;
|
||||||
|
UnorderedMap<MG_State::GLState::ITextureObject*, WeakPtr<MG_State::GLState::ITextureObject>> m_aliveObjects;
|
||||||
|
};
|
||||||
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
@@ -62,6 +62,7 @@ namespace MobileGL {
|
|||||||
Color29,
|
Color29,
|
||||||
Color30,
|
Color30,
|
||||||
Color31,
|
Color31,
|
||||||
|
ColorMax = Color31,
|
||||||
|
|
||||||
FramebufferAttachmentTypeCount,
|
FramebufferAttachmentTypeCount,
|
||||||
Unknown = -1
|
Unknown = -1
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ namespace MobileGL {
|
|||||||
using SharedPtr = std::shared_ptr<T>;
|
using SharedPtr = std::shared_ptr<T>;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using UniquePtr = std::unique_ptr<T>;
|
using UniquePtr = std::unique_ptr<T>;
|
||||||
|
template <typename T>
|
||||||
|
using WeakPtr = std::weak_ptr<T>;
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
inline SharedPtr<T> MakeShared(Args&&... args) {
|
inline SharedPtr<T> MakeShared(Args&&... args) {
|
||||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||||
|
|||||||
Reference in New Issue
Block a user