Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering Backend Rebuild (v1027) #111

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d93169c
Squashed commit of the following:
pollend Jan 1, 2024
c5c9a44
feature: add abstractions to simplify rendering code
pollend Jan 1, 2024
f218900
feat: simplify deferred renderer logic
pollend Jan 2, 2024
9b5114d
feat: fix translucency pass
pollend Jan 3, 2024
a2fcd34
feat: implement water material
pollend Jan 4, 2024
8f288b5
feat: add water translucency water
pollend Jan 4, 2024
43c0d36
feat: add water pipeline
pollend Jan 5, 2024
7f161a0
feat: fix crash
pollend Jan 5, 2024
f1a0ee3
Merge pull request #112 from OSS-Cosmic/feature/implement-water-mater…
pollend Jan 5, 2024
81d9d7d
feat: simplify guiset global
pollend Jan 5, 2024
a7d80c7
move ring buffer to graphics allocator
pollend Jan 5, 2024
17c2db6
Merge pull request #113 from OSS-Cosmic/feature/simplify-gui-set
pollend Jan 5, 2024
fd98e2b
feat: add uniform ring buffer for viewport
pollend Jan 5, 2024
a5a2f99
feat: tweak batch logic for viewport
pollend Jan 5, 2024
0cfd703
feat: start add shadow pass
pollend Jan 5, 2024
71ce9c7
feat: move shadow logic
pollend Jan 6, 2024
ef5b186
feat: fix fragment depth shader
pollend Jan 6, 2024
018b8e5
feat: add shadow pass
pollend Jan 7, 2024
88b8e9a
feat: add shadow pass back
pollend Jan 7, 2024
8eafc93
Merge pull request #114 from OSS-Cosmic/feature/uniform-ring-buffer-v…
pollend Jan 7, 2024
348fa12
bugfix: resolve broken shadows
pollend Jan 7, 2024
86361a8
feat: minor cleanup gtao wip
pollend Jan 8, 2024
75be209
feat: pcf kernel
pollend Jan 8, 2024
20c1e61
feat: tweak pcf
pollend Jan 8, 2024
6b99d3d
Merge pull request #115 from OSS-Cosmic/feature/pcf
pollend Jan 8, 2024
d7e2d64
feat: fix depth
pollend Jan 8, 2024
793e4a7
feat: replace cRendererDeferred with cRendererDeferred2
pollend Jan 8, 2024
e10811f
Merge pull request #116 from OSS-Cosmic/feature/replace-RendererDefer…
pollend Jan 8, 2024
ebdf3cd
bugfix: fix update problem with material descriptor set
pollend Jan 9, 2024
38b9147
feat: add missing reset
pollend Jan 9, 2024
e660a59
reduce the number of bound descriptors
pollend Jan 10, 2024
9ddfe8a
Merge pull request #117 from OSS-Cosmic/bugfix/resolve-descriptor-set…
pollend Jan 10, 2024
9ef1914
tweak sources
pollend Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ endif()
include("${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")

add_definitions(
-DUSE_THE_FORGE_LEGACY
# -DUSE_FORWARD_PLUS_BACKEND # prototype forward renderer
)

Expand Down
5 changes: 5 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"name": "AMNESIA_GAME_DIRECTORY",
"value": "C:/Program Files (x86)/Steam/steamapps/common/Amnesia The Dark Descent",
"type": "PATH"
},
{
"name": "THE_FORGE_DIR",
"value": "C:/projects/The-Forge",
"type": "STRING"
}
],
"cmakeCommandArgs": "VULKAN_SDK=\"C:\\VulkanSDK\\1.3.250.1\""
Expand Down
4 changes: 2 additions & 2 deletions HPL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ source_group("Platform" REGULAR_EXPRESSION "\\/impl\\/Platform.+")

# setup libs

set(OpenGL_GL_PREFERENCE LEGACY)
# set(OpenGL_GL_PREFERENCE LEGACY)
find_package(DevIL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down Expand Up @@ -319,10 +319,10 @@ function(copy_shader_to_target_dir TARGET)
-d "$<TARGET_FILE_DIR:${TARGET}>/Shaders"
--verbose
-b "$<TARGET_FILE_DIR:${TARGET}>/CompiledShaders"
--debug
--incremental
--compile ${_SHADER_RESOURCE_PATH_}/ShaderList.fsl
)

else()
add_custom_command(
TARGET ${TARGET}_HPL_SHADERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
#include "graphics/IndexPool.h"

namespace hpl {
class TextureDescriptorPool final {
class BindlessDescriptorPool final {
public:
enum Action {
UpdateSlot,
RemoveSlot
};
using DescriptorHandler = std::function<void(Action action, uint32_t slot, SharedTexture& texture)>;
TextureDescriptorPool(uint32_t ringsize, uint32_t poolSize);
BindlessDescriptorPool();
explicit BindlessDescriptorPool(uint32_t ringsize, uint32_t poolSize);
void reset(DescriptorHandler handler);
uint32_t request(SharedTexture& texture);
void dispose(uint32_t slot);
private:

struct SlotInfo {
SharedTexture m_texture;
uint8_t m_count = 0;
};

struct RingEntry {
Action m_action;
uint32_t slot;
Expand All @@ -25,7 +31,7 @@ namespace hpl {
uint32_t m_index = 0;
IndexPool m_pool;
folly::small_vector<std::vector<RingEntry>> m_ring;
std::vector<SharedTexture> m_slot;
std::vector<SlotInfo> m_slot;
DescriptorHandler m_actionHandler;
};
} // namespace hpl
71 changes: 71 additions & 0 deletions HPL2/include/graphics/CommandBufferPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

#include "graphics/ForgeHandles.h"
#include "graphics/Renderer.h"
#include <cstdint>

#include "Common_3/Graphics/Interfaces/IGraphics.h"
#include "FixPreprocessor.h"

namespace hpl {
template<uint32_t COUNT>
class CommandBufferPool {
public:
struct PoolEntry {
public:
SharedCmdPool m_pool;
SharedCmd m_cmd;
SharedFence m_fence;
};
CommandBufferPool() {}
CommandBufferPool(CommandBufferPool<COUNT>&&) = default;
CommandBufferPool(const CommandBufferPool<COUNT>&) = delete;

void operator=(const CommandBufferPool<COUNT>&) = delete;
CommandBufferPool<COUNT>& operator=(CommandBufferPool<COUNT>&&) = default;

CommandBufferPool(Renderer* renderer, Queue* queue): m_renderer(renderer){
for(auto& entry: m_pool) {
entry.m_pool.Load(renderer, [&](CmdPool** pool) {
CmdPoolDesc cmdPoolDesc = {};
cmdPoolDesc.pQueue = queue;
addCmdPool(renderer, &cmdPoolDesc, pool);
return true;
});
entry.m_cmd.Load(renderer, [&](Cmd** cmd) {
CmdDesc cmdDesc = {};
cmdDesc.pPool = entry.m_pool.m_handle;
addCmd(renderer, &cmdDesc, cmd);
return true;
});
entry.m_fence.Load(renderer, [&](Fence** fence) {
addFence(renderer, fence);
return true;
});
}
}

void waitAll() {
for(auto& entry: m_pool) {
FenceStatus status{};
getFenceStatus(m_renderer, entry.m_fence.m_handle, &status);
if(status == FENCE_STATUS_INCOMPLETE) {
waitForFences(m_renderer, 1, &entry.m_handle);
}
}
}
PoolEntry* findAvaliableEntry() {
for(auto& entry: m_pool) {
FenceStatus status{};
getFenceStatus(m_renderer, entry.m_fence.m_handle, &status);
if(status != FENCE_STATUS_INCOMPLETE) {
return &entry;
}
}
return nullptr;
}
private:
Renderer* m_renderer;
std::array<PoolEntry, COUNT> m_pool;
};
}
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
8 changes: 4 additions & 4 deletions HPL2/include/graphics/DebugDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class DebugDraw final {
Count
};

static constexpr uint32_t ImmediateVertexBufferSize = 1 << 25;
static constexpr uint32_t ImmediateIndexBufferSize = 1 << 23;
static constexpr uint32_t ImmediateVertexBufferSize = 1 << 10;
static constexpr uint32_t ImmediateIndexBufferSize = 1 << 10;
static constexpr uint32_t NumberOfPerFrameUniforms = 32;
static constexpr uint32_t NumberOfTextureUnits = 512;

Expand Down Expand Up @@ -131,8 +131,8 @@ class DebugDraw final {
mat4 m_viewProj2DMat;
};

GPURingBuffer* m_vertexBuffer = nullptr;
GPURingBuffer* m_indexBuffer = nullptr;
GPURingBuffer m_vertexBuffer = {};
GPURingBuffer m_indexBuffer = {};
std::array<SharedBuffer, NumberOfPerFrameUniforms> m_viewBufferUniform;
uint32_t m_frameIndex = 0;
uint32_t m_activeFrame = 0;
Expand Down
5 changes: 2 additions & 3 deletions HPL2/include/graphics/DrawPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace hpl {
uint32_t m_numStreams;
struct {
SharedBuffer* m_buffer;
eVertexBufferElement m_element;
uint64_t m_offset;
uint32_t m_stride;
} m_vertexStream[MaxVertexBindings];
Expand All @@ -33,8 +34,6 @@ namespace hpl {
};

struct GeometrySetBinding {
uint32_t m_numStreams;
eVertexBufferElement m_elements[MaxVertexBindings];
GraphicsAllocator::AllocationSet m_set;
GeometrySet::GeometrySetSubAllocation* m_subAllocation;
uint32_t m_numIndices;
Expand All @@ -51,7 +50,7 @@ namespace hpl {
return 0;
}

static void cmdBindBuffers(Cmd* cmd, ForgeRenderer::CommandResourcePool* resourcePool, DrawPacket* packet);
static void cmdBindBuffers(Cmd* cmd, ForgeRenderer::CommandResourcePool* resourcePool, DrawPacket* packet, std::span<eVertexBufferElement> elements);

DrawPacket()
: m_type(DrawPacketType::Unknown) {
Expand Down
79 changes: 49 additions & 30 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 @@ -103,10 +103,18 @@ namespace hpl {
/**
* tracks the resources used by a single command buffer
*/
//TODO: transiation this to Frame.h
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;

Frame() = default;
Frame(Frame& frame) = delete;
void operator=(Frame&) = delete;

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

template<typename T>
inline void pushResource(const T& ele) {
m_resourcePool->Push(ele);
}

inline uint32_t FrameCount() {
return m_currentFrame;
}

inline uint32_t index() {
return m_frameIndex;
}

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

inline RenderTarget* finalTarget() {
return m_finalRenderTarget;
}

inline GpuCmdRingElement& RingElement() {
return m_cmdRingElement;
}

friend class ForgeRenderer;
};

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;
return frame;
inline Frame& GetFrame() {
return m_frame;
}
// void BeginFrame() {}

Expand All @@ -145,10 +167,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 @@ -158,17 +176,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;

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 @@ -187,11 +203,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
Loading
Loading