Skip to content

Commit

Permalink
feat: tweak batch logic for viewport
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Jan 5, 2024
1 parent fd98e2b commit a5a2f99
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
8 changes: 4 additions & 4 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace hpl {
static constexpr uint32_t TransientImagePoolCount = 256;

static constexpr uint32_t ViewportRingBufferSize = 2048;
static constexpr uint32_t ScenePerDescriptorBatchSize = 32;

static constexpr uint32_t IndirectArgumentSize = 8 * sizeof(uint32_t);

Expand Down Expand Up @@ -205,6 +206,7 @@ namespace hpl {
SharedRootSignature m_sceneRootSignature;
SharedDescriptorSet m_sceneDescriptorConstSet;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_sceneDescriptorPerFrameSet;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_sceneDescriptorPerBatchSet;

SharedShader m_visibilityBufferPassShader;
SharedShader m_visibilityBufferAlphaPassShader;
Expand All @@ -219,16 +221,14 @@ namespace hpl {
std::array<SharedBuffer, ForgeRenderer::SwapChainLength> m_perSceneInfoBuffer;
std::array<SharedBuffer, ForgeRenderer::SwapChainLength> m_indirectDrawArgsBuffer;

std::array<SharedSampler, resource::MaterialSceneSamplersCount> m_materialSampler;

SharedTexture m_emptyTexture2D;
SharedTexture m_emptyTextureCube;
Image* m_dissolveImage;

cRenderList m_rendererList;

GPURingBuffer m_viewPortUniformBuffer{};
GPURingBuffer m_viewPortUniformBuffer{};

SharedRootSignature m_lightClusterRootSignature;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_lightDescriptorPerFrameSet;
SharedShader m_lightClusterShader;
Expand Down
2 changes: 1 addition & 1 deletion HPL2/resource/visibility_emit_shade_pass.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ float4 PS_MAIN(PsIn In)
UniformObject obj = Get(sceneObjects)[objectId];
uint startIndex = obj.indexOffset;
uint vertexOffset = obj.vertexOffset;
ViewportInfo viewInfo = Get(viewports)[PRIMARY_VIEWPORT_INDEX];
ViewportInfo viewInfo = Get(viewport);

float4x4 vp = mul(viewInfo.projMat, viewInfo.viewMat);
float4x4 mvp = mul(vp, obj.modelMat);
Expand Down
9 changes: 0 additions & 9 deletions HPL2/sources/graphics/GraphicsAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,4 @@ namespace hpl {
GPURingBufferOffset GraphicsAllocator::allocTransientIndexBuffer(uint32_t size) {
return getGPURingBufferOffset(&m_transientIndeciesBuffer, size);
}

// GraphicsAllocator::OffsetAllocHandle GraphicsAllocator::allocVertexFromSharedBuffer(uint32_t size) {
// OffsetAllocator::Allocation alloc = m_vertexBufferAllocator.allocate(size);
// return OffsetAllocHandle(&m_vertexBufferAllocator, alloc, m_sharedVertexBuffer);
// }
// GraphicsAllocator::OffsetAllocHandle GraphicsAllocator::allocIndeciesFromSharedBuffer(uint32_t size) {
// OffsetAllocator::Allocation alloc = m_indexBufferAllocator.allocate(size);
// return OffsetAllocHandle(&m_indexBufferAllocator, alloc, m_sharedIndexBuffer);
// }
} // namespace hpl
35 changes: 30 additions & 5 deletions HPL2/sources/graphics/RendererDeferred2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "graphics/RendererDeferred2.h"
#include "Common_3/Utilities/RingBuffer.h"
#include "graphics/DrawPacket.h"
#include "graphics/ForgeHandles.h"
#include "graphics/ForgeRenderer.h"
Expand Down Expand Up @@ -1274,7 +1275,7 @@ namespace hpl {
m_diffuseIndexPool = IndexPool(resource::MaxSolidDiffuseMaterials);
m_translucencyIndexPool = IndexPool(resource::MaxTranslucenctMaterials);
m_waterIndexPool = IndexPool(resource::MaxWaterMaterials);

addUniformGPURingBuffer(forgeRenderer->Rend(), ViewportRingBufferSize, &m_viewPortUniformBuffer);


Expand All @@ -1291,7 +1292,11 @@ namespace hpl {
addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet);
return true;
});

m_sceneDescriptorPerBatchSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) {
DescriptorSetDesc descriptorSetDesc{ m_sceneRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_BATCH, ScenePerDescriptorBatchSize };
addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet);
return true;
});
m_lightDescriptorPerFrameSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) {
DescriptorSetDesc descriptorSetDesc{ m_lightClusterRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_FRAME, 1 };
addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet);
Expand Down Expand Up @@ -1488,6 +1493,7 @@ namespace hpl {
vars.m_objectSlotIndex.clear();
});


auto viewportDatum = m_boundViewportData.resolve(viewport);
if (!viewportDatum || viewportDatum->m_size != viewport.GetSizeU2()) {
auto updateDatum = std::make_unique<ViewportData>();
Expand Down Expand Up @@ -1607,6 +1613,26 @@ namespace hpl {
frame.m_resourcePool->Push(viewportDatum->m_outputBuffer[frame.m_frameIndex]);
frame.m_resourcePool->Push(viewportDatum->m_albedoBuffer[frame.m_frameIndex]);
frame.m_resourcePool->Push(viewportDatum->m_refractionImage[frame.m_frameIndex]);

uint32_t mainBatchIndex = frameVars.m_viewportIndex++;
{
GPURingBufferOffset offset = getGPURingBufferOffset(&m_viewPortUniformBuffer, sizeof(resource::ViewportInfo));
BufferUpdateDesc updateDesc = { offset.pBuffer, offset.mOffset };
beginUpdateResource(&updateDesc);
resource::ViewportInfo* viewportInfo = reinterpret_cast<resource::ViewportInfo*>(updateDesc.pMappedData);
(*viewportInfo) = resource::ViewportInfo::create(apFrustum, float4(0.0f, 0.0f, static_cast<float>(viewportDatum->m_size.x), static_cast<float>(viewportDatum->m_size.y)));
endUpdateResource(&updateDesc);

{
DescriptorDataRange viewportRange = { (uint32_t)offset.mOffset, sizeof(resource::ViewportInfo) };
std::array params = {
DescriptorData { .pName = "viewportBlock", .pRanges = &viewportRange, .ppBuffers = &offset.pBuffer }
};
updateDescriptorSet(
forgeRenderer->Rend(), mainBatchIndex, m_sceneDescriptorPerBatchSet[frame.m_frameIndex].m_handle, params.size(), params.data());
}
}

// ----------------
// Setup Data
// -----------------
Expand All @@ -1623,7 +1649,7 @@ namespace hpl {
forgeRenderer->Rend(), 0, m_sceneDescriptorPerFrameSet[frame.m_frameIndex].m_handle, params.size(), params.data());
}



{
BufferUpdateDesc updateDesc = { m_perSceneInfoBuffer[frame.m_frameIndex].m_handle, 0, sizeof(resource::SceneInfoResource) };
Expand Down Expand Up @@ -2255,7 +2281,6 @@ namespace hpl {
cmdResourceBarrier(cmd, 0, nullptr, 0, nullptr, rtBarriers.size(), rtBarriers.data());
}
{
//cmdBeginDebugMarker(cmd, 0, 1, 0, "Visibility Emit Buffer Pass");
LoadActionsDesc loadActions = {};
loadActions.mLoadActionsColor[0] = LOAD_ACTION_CLEAR;
loadActions.mClearColorValues[0] = { .r = 0.0f, .g = 0.0f, .b = 0.0f, .a = 0.0f };
Expand All @@ -2268,8 +2293,8 @@ namespace hpl {
cmdBindPipeline(cmd, m_visbilityEmitBufferPass.m_handle);
cmdBindDescriptorSet(cmd, 0, m_sceneDescriptorConstSet.m_handle);
cmdBindDescriptorSet(cmd, 0, m_sceneDescriptorPerFrameSet[frame.m_frameIndex].m_handle);
cmdBindDescriptorSet(cmd, mainBatchIndex, m_sceneDescriptorPerBatchSet[frame.m_frameIndex].m_handle);
cmdDraw(cmd, 3, 0);
//cmdEndDebugMarker(cmd);
}
{
//cmdBeginDebugMarker(cmd, 0, 1, 0, "Decal Output Buffer Pass");
Expand Down

0 comments on commit a5a2f99

Please sign in to comment.