Skip to content

Commit

Permalink
Merge pull request #109 from OSS-Cosmic/feature/visibility-buffer-ill…
Browse files Browse the repository at this point in the history
…uminiation-translucency

feature: visibility buffer illuminiation translucency
  • Loading branch information
pollend authored Jan 1, 2024
2 parents 9556405 + d6e0bfc commit 4e2cf1e
Show file tree
Hide file tree
Showing 27 changed files with 611 additions and 305 deletions.
26 changes: 26 additions & 0 deletions HPL2/include/graphics/CopyTextureSubpass4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "graphics/ForgeRenderer.h"
#include "graphics/ForgeHandles.h"

namespace hpl {

class CopyTextureSubpass4 {
public:

static constexpr uint32_t NumberOfDescriptors = 32;
CopyTextureSubpass4(CopyTextureSubpass4&&) = default;
CopyTextureSubpass4(CopyTextureSubpass4&) = delete;
CopyTextureSubpass4(hpl::ForgeRenderer& renderer);
void operator=(CopyTextureSubpass4&) = delete;
CopyTextureSubpass4& operator=(CopyTextureSubpass4&&) = default;

void Dispatch(ForgeRenderer::Frame& frame, Texture* src, Texture* dest);
private:
SharedRootSignature m_copyRootSignature;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_copyPerFrameSet;
SharedPipeline m_copyPipline;
SharedShader m_copyShader;
std::array<uint32_t, ForgeRenderer::SwapChainLength> m_index;
};
} // namespace hpl
79 changes: 44 additions & 35 deletions HPL2/include/graphics/ForgeRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <engine/RTTI.h>

#include "Common_3/Utilities/RingBuffer.h"
#include "graphics/ForgeHandles.h"
#include "windowing/NativeWindow.h"
#include "engine/QueuedEventLoopHandler.h"
Expand Down Expand Up @@ -54,13 +55,12 @@ namespace hpl {
CopyPipelineCount = 2
};


static constexpr uint32_t MaxCopyFrames = 32;
static constexpr uint32_t SwapChainLength = 2; // double buffered
static constexpr uint32_t ResourcePoolSize = 4; // double buffered

void InitializeRenderer(window::NativeWindowWrapper* window);
void InitializeResource();
//RendererApi GetApi();

struct SamplerPoolKey {
union {
Expand Down Expand Up @@ -104,9 +104,13 @@ namespace hpl {
* tracks the resources used by a single command buffer
*/
struct Frame {
public:
uint32_t m_currentFrame = 0;
uint32_t m_frameIndex = 0;
uint32_t m_swapChainIndex = 0;
GpuCmdRingElement m_cmdRingElement;
bool m_isFinished = true;
//FrameState m_state = FrameState::Unitialize;

ForgeRenderer* m_renderer = nullptr;
SwapChain* m_swapChain = nullptr;
Cmd* m_cmd = nullptr;
Expand All @@ -115,26 +119,37 @@ namespace hpl {
Semaphore* m_renderCompleteSemaphore = nullptr;
CommandResourcePool* m_resourcePool = nullptr;
RenderTarget* m_finalRenderTarget = nullptr;
std::vector<Semaphore*>* m_waitSemaphores;
};


const inline Frame GetFrame() {
Frame frame;
frame.m_currentFrame = FrameCount();
frame.m_frameIndex = CurrentFrameIndex();
frame.m_swapChainIndex = SwapChainIndex();
frame.m_renderer = this;
frame.m_swapChain = m_swapChain.m_handle;

frame.m_cmd = m_cmds[CurrentFrameIndex()];
frame.m_cmdPool = m_cmdPools[CurrentFrameIndex()];
frame.m_renderCompleteFence = m_renderCompleteFences[CurrentFrameIndex()];
frame.m_renderCompleteSemaphore = m_renderCompleteSemaphores[CurrentFrameIndex()];
frame.m_resourcePool = &m_resourcePool[CurrentFrameIndex()];
frame.m_finalRenderTarget = m_finalRenderTarget[CurrentFrameIndex()].m_handle;
frame.m_waitSemaphores = &m_waitSemaphores[CurrentFrameIndex()];
return frame;
template<typename T>
inline void pushResource(const T& ele) {
m_resourcePool->Push(ele);
}
inline uint32_t index() {
return m_frameIndex;
}

inline Cmd*& cmd() {
return m_cmdRingElement.pCmds[0];
}

inline RenderTarget* finalTarget() {
return m_finalRenderTarget;
}

// inline RenderTarget* swapChainTarget() {
// return m_swapChainTarget;
// }

inline GpuCmdRingElement& RingElement() {
return m_cmdRingElement;
}

friend class ForgeRenderer;
};

inline Frame& GetFrame() {
return m_frame;
}
// void BeginFrame() {}

Expand All @@ -147,10 +162,6 @@ namespace hpl {
}
RootSignature* PipelineSignature() { return m_pipelineSignature; }

size_t SwapChainIndex() { return m_swapChainIndex; }
size_t CurrentFrameIndex() { return m_currentFrameCount % SwapChainLength; }
size_t FrameCount() { return m_currentFrameCount; }
inline SwapChain* GetSwapChain() { return m_swapChain.m_handle; }
inline Queue* GetGraphicsQueue() { return m_graphicsQueue; }

void cmdCopyTexture(Cmd* cmd, Texture* srcTexture, RenderTarget* dstTexture);
Expand All @@ -160,20 +171,15 @@ namespace hpl {
private:
std::array<Sampler*, SamplerPoolKey::NumOfVariants> m_samplerPool;
std::array<CommandResourcePool, SwapChainLength> m_resourcePool;
std::array<Fence*, SwapChainLength> m_renderCompleteFences;
std::array<Semaphore*, SwapChainLength> m_renderCompleteSemaphores;
std::array<CmdPool*, SwapChainLength> m_cmdPools;
std::array<Cmd*, SwapChainLength> m_cmds;
std::array<SharedRenderTarget, SwapChainLength> m_finalRenderTarget;

std::array<std::vector<Semaphore*>, SwapChainLength> m_waitSemaphores;


float m_gamma = 1.0f;

window::WindowEvent::QueuedEventHandler m_windowEventHandler;
window::NativeWindowWrapper* m_window = nullptr;

GpuCmdRing m_graphicsCmdRing;

Renderer* m_renderer = nullptr;
RootSignature* m_pipelineSignature = nullptr;
SharedSwapChain m_swapChain;
Expand All @@ -192,11 +198,14 @@ namespace hpl {
SharedSampler m_pointSampler ;

RootSignature* m_copyPostProcessingRootSignature = nullptr;
DescriptorSet* m_copyPostProcessingDescriptorSet = nullptr;
std::array<DescriptorSet*, SwapChainLength> m_copyPostProcessingDescriptorSet ;
uint32_t m_copyRegionDescriptorIndex = 0;
float m_gamma = 1.0f;
uint32_t m_swapChainCount;


Frame m_frame;

uint32_t m_currentFrameCount = 0;
uint32_t m_swapChainIndex = 0;
};

} // namespace hpl
7 changes: 4 additions & 3 deletions HPL2/include/graphics/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "math/MathTypes.h"
#include "scene/SceneTypes.h"

#include "graphics/ScopedBarrier.h"
#include "graphics/RenderFunctions.h"
#include "scene/Viewport.h"
#include <cstdint>
Expand Down Expand Up @@ -149,13 +150,13 @@ namespace hpl {
// ensure the contents is copied to the RenderViewport
virtual void Draw(
Cmd* cmd,
const ForgeRenderer::Frame& context,
ForgeRenderer::Frame& context,
cViewport& viewport,
float afFrameTime,
cFrustum* apFrustum,
cWorld* apWorld,
cRenderSettings* apSettings,
bool abSendFrameBufferToPostEffects) = 0;
cRenderSettings* apSettings
) = 0;

void Update(float afTimeStep);

Expand Down
6 changes: 3 additions & 3 deletions HPL2/include/graphics/RendererDeferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "engine/RTTI.h"

#include "graphics/SceneResource.h"
#include "graphics/ScopedBarrier.h"
#include "scene/Viewport.h"
#include "scene/World.h"
#include "windowing/NativeWindow.h"
Expand Down Expand Up @@ -356,13 +357,12 @@ namespace hpl {

virtual void Draw(
Cmd* cmd,
const ForgeRenderer::Frame& frame,
ForgeRenderer::Frame& frame,
cViewport& viewport,
float afFrameTime,
cFrustum* apFrustum,
cWorld* apWorld,
cRenderSettings* apSettings,
bool abSendFrameBufferToPostEffects) override;
cRenderSettings* apSettings) override;

private:
iVertexBuffer* GetLightShape(iLight* apLight, eDeferredShapeQuality aQuality) const;
Expand Down
12 changes: 8 additions & 4 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#include "engine/RTTI.h"

#include "graphics/CommandBufferPool.h"
#include "graphics/CopyTextureSubpass4.h"
#include "graphics/GraphicsTypes.h"
#include "graphics/ImageBindlessPool.h"
#include "graphics/SceneResource.h"
#include "graphics/ScopedBarrier.h"
#include "graphics/ShadowCache.h"
#include "graphics/BindlessDescriptorPool.h"
#include "scene/Viewport.h"
Expand Down Expand Up @@ -120,13 +122,14 @@ namespace hpl {
ViewportData() = default;
ViewportData(const ViewportData&) = delete;
ViewportData(ViewportData&& buffer)= default;
ViewportData& operator=(const ViewportData&) = delete;
ViewportData& operator=(ViewportData&& buffer) = default;
ViewportData& operator=(const ViewportData&) = delete;

uint2 m_size = uint2(0, 0);
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_outputBuffer;
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_depthBuffer;
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_albedoBuffer; // this is used for the adding decals to albedo
std::array<SharedTexture, ForgeRenderer::SwapChainLength> m_refractionImage;

std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_testBuffer; //encodes the parallax
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_visiblityBuffer;
Expand All @@ -148,13 +151,12 @@ namespace hpl {
virtual SharedRenderTarget GetOutputImage(uint32_t frameIndex, cViewport& viewport) override;
virtual void Draw(
Cmd* cmd,
const ForgeRenderer::Frame& frame,
ForgeRenderer::Frame& frame,
cViewport& viewport,
float afFrameTime,
cFrustum* apFrustum,
cWorld* apWorld,
cRenderSettings* apSettings,
bool abSendFrameBufferToPostEffects) override;
cRenderSettings* apSettings) override;

private:
void setIndirectDrawArg(const ForgeRenderer::Frame& frame, uint32_t drawArgIndex, uint32_t slot, DrawPacket& packet);
Expand Down Expand Up @@ -312,6 +314,8 @@ namespace hpl {
BlendPipelines m_translucencyIlluminationPipline;
BlendPipelines m_translucencyIlluminationPiplineNoDepth;

CopyTextureSubpass4 m_copySubpass;

bool m_supportIndirectRootConstant = false;
};
}; // namespace hpl
Expand Down
5 changes: 2 additions & 3 deletions HPL2/include/graphics/RendererWireFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ namespace hpl {

virtual void Draw(
Cmd* cmd,
const ForgeRenderer::Frame& context,
ForgeRenderer::Frame& context,
cViewport& viewport,
float afFrameTime,
cFrustum* apFrustum,
cWorld* apWorld,
cRenderSettings* apSettings,
bool abSendFrameBufferToPostEffects) override;
cRenderSettings* apSettings) override;

std::array<SharedBuffer, NumberOfPerFrameUniforms> m_frameBufferUniform;
uint32_t m_perFrameIndex = 0;
Expand Down
61 changes: 61 additions & 0 deletions HPL2/include/graphics/ScopedBarrier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include "Common_3/Graphics/Interfaces/IGraphics.h"
#include <span>

namespace hpl {
class RenderTargetScopedBarrier;
struct RenderTargetTransition {
RenderTargetScopedBarrier* m_resource;
ResourceState m_newState;
};

namespace ScopedBarrier {
void End(
Cmd* cmd,
std::span<RenderTargetScopedBarrier*>
);

void Transition(
Cmd* cmd,
std::span<RenderTargetTransition>
);
};

class RenderTargetScopedBarrier {
public:
RenderTargetScopedBarrier();
RenderTargetScopedBarrier(RenderTarget* target, ResourceState start, ResourceState end);
RenderTargetScopedBarrier(RenderTargetScopedBarrier&) = delete;
RenderTargetScopedBarrier(RenderTargetScopedBarrier&&);

void Set(RenderTarget* target, ResourceState start, ResourceState end);
void operator=(RenderTargetBarrier&) = delete;
void operator=(RenderTargetScopedBarrier&&);

~RenderTargetScopedBarrier() {
// scope hasn't been closed
ASSERT(m_target == nullptr);
}

inline bool IsValid() {
return m_target != nullptr;
}

inline RenderTarget* Target() {
return m_target;
}

private:
ResourceState m_startState;
ResourceState m_currentState;
ResourceState m_endState;
RenderTarget* m_target = nullptr;

friend void ScopedBarrier::End(Cmd*, std::span<RenderTargetScopedBarrier*>);
friend void ScopedBarrier::Transition(Cmd*, std::span<RenderTargetTransition>);

};


}
2 changes: 1 addition & 1 deletion HPL2/include/scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace hpl {
* Called by cEngine
*/
void Render(float afFrameTime, tFlag alFlags) {} //TODO MP: this needs to be replaced
void Render(const ForgeRenderer::Frame&, float afFrameTime, tFlag alFlags);
void Render(ForgeRenderer::Frame&, float afFrameTime, tFlag alFlags);

void Update(float timeStep);

Expand Down
Loading

0 comments on commit 4e2cf1e

Please sign in to comment.