Introduce CameraRenderRequest scheduling and fix Vulkan build
This commit is contained in:
52
engine/include/XCEngine/RHI/Vulkan/VulkanFramebuffer.h
Normal file
52
engine/include/XCEngine/RHI/Vulkan/VulkanFramebuffer.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCEngine/RHI/RHIFramebuffer.h"
|
||||
#include "XCEngine/RHI/Vulkan/VulkanCommon.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class VulkanRenderPass;
|
||||
class VulkanResourceView;
|
||||
class VulkanTexture;
|
||||
|
||||
class VulkanFramebuffer : public RHIFramebuffer {
|
||||
public:
|
||||
VulkanFramebuffer() = default;
|
||||
~VulkanFramebuffer() override;
|
||||
|
||||
bool Initialize(VkDevice device, RHIRenderPass* renderPass, uint32_t width, uint32_t height,
|
||||
uint32_t colorAttachmentCount, RHIResourceView** colorAttachments,
|
||||
RHIResourceView* depthStencilAttachment);
|
||||
bool Initialize(RHIRenderPass* renderPass, uint32_t width, uint32_t height,
|
||||
uint32_t colorAttachmentCount, RHIResourceView** colorAttachments,
|
||||
RHIResourceView* depthStencilAttachment) override;
|
||||
void Shutdown() override;
|
||||
|
||||
void* GetNativeHandle() override { return m_framebuffer; }
|
||||
uint32_t GetWidth() const override { return m_width; }
|
||||
uint32_t GetHeight() const override { return m_height; }
|
||||
bool IsValid() const override { return m_framebuffer != VK_NULL_HANDLE; }
|
||||
|
||||
VkFramebuffer GetFramebuffer() const { return m_framebuffer; }
|
||||
VulkanRenderPass* GetRenderPass() const { return m_renderPass; }
|
||||
uint32_t GetColorAttachmentCount() const { return static_cast<uint32_t>(m_colorAttachmentViews.size()); }
|
||||
VulkanResourceView* GetColorAttachmentView(uint32_t index) const;
|
||||
VulkanResourceView* GetDepthStencilView() const { return m_depthStencilView; }
|
||||
VulkanTexture* GetColorAttachmentTexture(uint32_t index) const;
|
||||
VulkanTexture* GetDepthStencilTexture() const;
|
||||
|
||||
private:
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkFramebuffer m_framebuffer = VK_NULL_HANDLE;
|
||||
VulkanRenderPass* m_renderPass = nullptr;
|
||||
uint32_t m_width = 0;
|
||||
uint32_t m_height = 0;
|
||||
std::vector<VulkanResourceView*> m_colorAttachmentViews;
|
||||
VulkanResourceView* m_depthStencilView = nullptr;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
45
engine/include/XCEngine/RHI/Vulkan/VulkanRenderPass.h
Normal file
45
engine/include/XCEngine/RHI/Vulkan/VulkanRenderPass.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCEngine/RHI/RHIRenderPass.h"
|
||||
#include "XCEngine/RHI/Vulkan/VulkanCommon.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class VulkanRenderPass : public RHIRenderPass {
|
||||
public:
|
||||
VulkanRenderPass() = default;
|
||||
~VulkanRenderPass() override;
|
||||
|
||||
bool Initialize(VkDevice device, uint32_t colorAttachmentCount, const AttachmentDesc* colorAttachments,
|
||||
const AttachmentDesc* depthStencilAttachment);
|
||||
bool Initialize(uint32_t colorAttachmentCount, const AttachmentDesc* colorAttachments,
|
||||
const AttachmentDesc* depthStencilAttachment) override;
|
||||
void Shutdown() override;
|
||||
|
||||
uint32_t GetColorAttachmentCount() const override { return m_colorAttachmentCount; }
|
||||
const AttachmentDesc* GetColorAttachments() const override {
|
||||
return m_colorAttachments.empty() ? nullptr : m_colorAttachments.data();
|
||||
}
|
||||
const AttachmentDesc* GetDepthStencilAttachment() const override {
|
||||
return m_hasDepthStencil ? &m_depthStencilAttachment : nullptr;
|
||||
}
|
||||
void* GetNativeHandle() override { return nullptr; }
|
||||
|
||||
VkRenderPass GetRenderPass() const { return m_renderPass; }
|
||||
uint32_t GetAttachmentCount() const { return m_colorAttachmentCount + (m_hasDepthStencil ? 1u : 0u); }
|
||||
bool HasDepthStencil() const { return m_hasDepthStencil; }
|
||||
|
||||
private:
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkRenderPass m_renderPass = VK_NULL_HANDLE;
|
||||
uint32_t m_colorAttachmentCount = 0;
|
||||
std::vector<AttachmentDesc> m_colorAttachments;
|
||||
AttachmentDesc m_depthStencilAttachment = {};
|
||||
bool m_hasDepthStencil = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
29
engine/include/XCEngine/Rendering/CameraRenderRequest.h
Normal file
29
engine/include/XCEngine/Rendering/CameraRenderRequest.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Rendering/RenderContext.h>
|
||||
#include <XCEngine/Rendering/RenderSurface.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Components {
|
||||
class CameraComponent;
|
||||
class Scene;
|
||||
} // namespace Components
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
struct CameraRenderRequest {
|
||||
const Components::Scene* scene = nullptr;
|
||||
Components::CameraComponent* camera = nullptr;
|
||||
RenderContext context;
|
||||
RenderSurface surface;
|
||||
float cameraDepth = 0.0f;
|
||||
|
||||
bool IsValid() const {
|
||||
return scene != nullptr &&
|
||||
camera != nullptr &&
|
||||
context.IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Rendering
|
||||
} // namespace XCEngine
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Rendering/CameraRenderRequest.h>
|
||||
#include <XCEngine/Rendering/RenderPipeline.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -23,11 +24,7 @@ public:
|
||||
void SetPipeline(std::unique_ptr<RenderPipeline> pipeline);
|
||||
RenderPipeline* GetPipeline() const { return m_pipeline.get(); }
|
||||
|
||||
bool Render(
|
||||
const Components::Scene& scene,
|
||||
Components::CameraComponent* overrideCamera,
|
||||
const RenderContext& context,
|
||||
const RenderSurface& surface);
|
||||
bool Render(const CameraRenderRequest& request);
|
||||
|
||||
private:
|
||||
RenderSceneExtractor m_sceneExtractor;
|
||||
|
||||
@@ -31,11 +31,16 @@ public:
|
||||
Components::CameraComponent* overrideCamera,
|
||||
uint32_t viewportWidth,
|
||||
uint32_t viewportHeight) const;
|
||||
|
||||
private:
|
||||
RenderSceneData ExtractForCamera(
|
||||
const Components::Scene& scene,
|
||||
Components::CameraComponent& camera,
|
||||
uint32_t viewportWidth,
|
||||
uint32_t viewportHeight) const;
|
||||
Components::CameraComponent* SelectCamera(
|
||||
const Components::Scene& scene,
|
||||
Components::CameraComponent* overrideCamera) const;
|
||||
|
||||
private:
|
||||
RenderCameraData BuildCameraData(
|
||||
const Components::CameraComponent& camera,
|
||||
uint32_t viewportWidth,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Rendering/CameraRenderRequest.h>
|
||||
#include <XCEngine/Rendering/CameraRenderer.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Components {
|
||||
class CameraComponent;
|
||||
@@ -19,6 +22,14 @@ public:
|
||||
void SetPipeline(std::unique_ptr<RenderPipeline> pipeline);
|
||||
RenderPipeline* GetPipeline() const { return m_cameraRenderer.GetPipeline(); }
|
||||
|
||||
std::vector<CameraRenderRequest> BuildRenderRequests(
|
||||
const Components::Scene& scene,
|
||||
Components::CameraComponent* overrideCamera,
|
||||
const RenderContext& context,
|
||||
const RenderSurface& surface) const;
|
||||
|
||||
bool Render(const CameraRenderRequest& request);
|
||||
bool Render(const std::vector<CameraRenderRequest>& requests);
|
||||
bool Render(
|
||||
const Components::Scene& scene,
|
||||
Components::CameraComponent* overrideCamera,
|
||||
@@ -26,6 +37,7 @@ public:
|
||||
const RenderSurface& surface);
|
||||
|
||||
private:
|
||||
RenderSceneExtractor m_sceneExtractor;
|
||||
CameraRenderer m_cameraRenderer;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user