From 9ea7f5251a1486891eb1aa7a00d98ab81c0f2cd9 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Thu, 28 Dec 2023 14:32:33 -0800 Subject: [PATCH] feat: attempt to fix broken rendering ubuntu mesa Signed-off-by: Michael Pollind --- HPL2/include/graphics/ForgeRenderer.h | 2 - HPL2/include/graphics/RendererDeferred2.h | 1 + HPL2/include/graphics/SceneResource.h | 4 +- HPL2/resource/scene_defs.h.fsl | 4 +- HPL2/resource/scene_resource.h.fsl | 2 +- .../graphics/BindlessDescriptorPool.cpp | 5 +- HPL2/sources/graphics/ForgeRenderer.cpp | 11 ++-- HPL2/sources/graphics/ImageBindlessPool.cpp | 2 +- HPL2/sources/graphics/RendererDeferred2.cpp | 50 ++++++++++--------- HPL2/sources/scene/BillBoard.cpp | 4 +- 10 files changed, 44 insertions(+), 41 deletions(-) diff --git a/HPL2/include/graphics/ForgeRenderer.h b/HPL2/include/graphics/ForgeRenderer.h index fee58b804..4a4644cbf 100644 --- a/HPL2/include/graphics/ForgeRenderer.h +++ b/HPL2/include/graphics/ForgeRenderer.h @@ -106,7 +106,6 @@ namespace hpl { struct Frame { uint32_t m_currentFrame = 0; uint32_t m_frameIndex = 0; - uint32_t m_swapChainIndex = 0; ForgeRenderer* m_renderer = nullptr; SwapChain* m_swapChain = nullptr; Cmd* m_cmd = nullptr; @@ -123,7 +122,6 @@ namespace hpl { 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; diff --git a/HPL2/include/graphics/RendererDeferred2.h b/HPL2/include/graphics/RendererDeferred2.h index d7412ef1b..4ef15cf59 100644 --- a/HPL2/include/graphics/RendererDeferred2.h +++ b/HPL2/include/graphics/RendererDeferred2.h @@ -185,6 +185,7 @@ namespace hpl { SharedSampler m_samplerNearEdgeClamp; SharedSampler m_samplerPointWrap; SharedSampler m_samplerPointClampToBorder; + SharedSampler m_samplerLinearClampToBorder; SharedSampler m_samplerMaterial; std::array m_sharedMaterial; BindlessDescriptorPool m_sceneTexture2DPool; diff --git a/HPL2/include/graphics/SceneResource.h b/HPL2/include/graphics/SceneResource.h index b0ae3bae5..33c889ba1 100644 --- a/HPL2/include/graphics/SceneResource.h +++ b/HPL2/include/graphics/SceneResource.h @@ -117,7 +117,7 @@ namespace hpl::resource { struct SceneParticle { uint32_t diffuseTextureIndex; - uint32_t sampleIndex; + uint32_t m_pad0; float sceneAlpha; float lightLevel; mat4 modelMat; @@ -127,9 +127,9 @@ namespace hpl::resource { struct SceneDecal { uint32_t diffuseTextureIndex; - uint32_t sampleIndex; uint m_pad0; uint m_pad1; + uint m_pad2; mat4 modelMat; mat4 uvMat; }; diff --git a/HPL2/resource/scene_defs.h.fsl b/HPL2/resource/scene_defs.h.fsl index 437b722dc..87d10f49a 100644 --- a/HPL2/resource/scene_defs.h.fsl +++ b/HPL2/resource/scene_defs.h.fsl @@ -80,16 +80,16 @@ STRUCT(DiffuseMaterial) { STRUCT(Decal) { DATA(uint, diffuseTextureIndex, None); - DATA(uint, samplerIndex, None); DATA(uint, __pad0, NONE); DATA(uint, __pad1, NONE); + DATA(uint, __pad2, NONE); DATA(float4x4, modelMat, None); DATA(float4x4, uvMat, None); }; STRUCT(Particle) { DATA(uint, diffuseTextureIndex, None); - DATA(uint, samplerIndex, None); + DATA(uint, __pad0, None); DATA(float, sceneAlpha, NONE); DATA(float, lightLevel, NONE); DATA(float4x4, modelMat, None); diff --git a/HPL2/resource/scene_resource.h.fsl b/HPL2/resource/scene_resource.h.fsl index 83df271d8..1bfc482fa 100644 --- a/HPL2/resource/scene_resource.h.fsl +++ b/HPL2/resource/scene_resource.h.fsl @@ -49,7 +49,7 @@ RES(ByteBuffer, lightClusters, UPDATE_FREQ_PER_FRAME, t16, binding = 22); RES(SamplerState, sceneSampler, UPDATE_FREQ_NONE, s2, binding = 23); RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAME, t17, binding = 24); -RES(TexCube(float4), sceneCubeTextures[SCENE_MAX_TEXTURE_CUBE_COUNT], UPDATE_FREQ_PER_FRAME, t18, binding = 25 + SCENE_MAX_TEXTURE_CUBE_COUNT); +RES(TexCube(float4), sceneCubeTextures[SCENE_MAX_TEXTURE_CUBE_COUNT], UPDATE_FREQ_PER_FRAME, t18, binding = 25 + SCENE_MAX_TEXTURE_COUNT); #define SCENE_OBJECT_ID_BIT 19 // 13 bits for ObjectID #define SCENE_PRIM_ID_BIT 0 // 19 bits for PrimitiveID diff --git a/HPL2/sources/graphics/BindlessDescriptorPool.cpp b/HPL2/sources/graphics/BindlessDescriptorPool.cpp index 617d0f6c7..1e1c28a80 100644 --- a/HPL2/sources/graphics/BindlessDescriptorPool.cpp +++ b/HPL2/sources/graphics/BindlessDescriptorPool.cpp @@ -18,17 +18,18 @@ namespace hpl { m_index = (m_index + 1) % m_ring.size(); for(auto& ringEntry: m_ring[m_index]) { handler(ringEntry.m_action, ringEntry.slot, m_slot[ringEntry.slot]); + ringEntry.m_count++; switch (ringEntry.m_action) { case Action::UpdateSlot: { - if ((++ringEntry.m_count) < m_ring.size()) { + if (ringEntry.m_count < m_ring.size()) { m_ring[(m_index + 1) % m_ring.size()].push_back(ringEntry); } break; } case Action::RemoveSlot: { - if ((++ringEntry.m_count) <= m_ring.size()) { + if (ringEntry.m_count <= m_ring.size()) { m_ring[(m_index + 1) % m_ring.size()].push_back(ringEntry); } else { m_pool.returnId(ringEntry.slot); diff --git a/HPL2/sources/graphics/ForgeRenderer.cpp b/HPL2/sources/graphics/ForgeRenderer.cpp index 0bbb61913..344b8622d 100644 --- a/HPL2/sources/graphics/ForgeRenderer.cpp +++ b/HPL2/sources/graphics/ForgeRenderer.cpp @@ -16,7 +16,7 @@ #endif namespace hpl { - + void ForgeRenderer::IncrementFrame() { // Stall if CPU is running "Swap Chain Buffer Count" frames ahead of GPU @@ -24,8 +24,9 @@ namespace hpl { m_currentFrameCount++; auto frame = GetFrame(); - FenceStatus fenceStatus; auto& completeFence = frame.m_renderCompleteFence; + + FenceStatus fenceStatus; getFenceStatus(m_renderer, completeFence, &fenceStatus); if (fenceStatus == FENCE_STATUS_INCOMPLETE) { waitForFences(m_renderer, 1, &completeFence); @@ -46,8 +47,9 @@ namespace hpl { void ForgeRenderer::SubmitFrame() { auto frame = GetFrame(); + auto& waitSemaphores = m_waitSemaphores[frame.m_frameIndex]; - auto& swapChainTarget = frame.m_swapChain->ppRenderTargets[frame.m_swapChainIndex]; + auto& swapChainTarget = frame.m_swapChain->ppRenderTargets[m_swapChainIndex]; { cmdBindRenderTargets(frame.m_cmd, 0, NULL, NULL, NULL, NULL, NULL, -1, -1); std::array rtBarriers = { @@ -80,7 +82,7 @@ namespace hpl { }; cmdResourceBarrier(frame.m_cmd, 0, NULL, 0, NULL, rtBarriers.size(), rtBarriers.data()); } - endCmd(m_cmds[frame.m_frameIndex]); + endCmd(frame.m_cmd); FlushResourceUpdateDesc flushUpdateDesc = {}; flushUpdateDesc.mNodeIndex = 0; @@ -88,7 +90,6 @@ namespace hpl { waitSemaphores.push_back(flushUpdateDesc.pOutSubmittedSemaphore); waitSemaphores.push_back(m_imageAcquiredSemaphore); - QueueSubmitDesc submitDesc = {}; submitDesc.mCmdCount = 1; submitDesc.mSignalSemaphoreCount = 1; diff --git a/HPL2/sources/graphics/ImageBindlessPool.cpp b/HPL2/sources/graphics/ImageBindlessPool.cpp index 9f519cf8e..e13b5f531 100644 --- a/HPL2/sources/graphics/ImageBindlessPool.cpp +++ b/HPL2/sources/graphics/ImageBindlessPool.cpp @@ -21,7 +21,7 @@ namespace hpl { void ImageBindlessPool::reset(const ForgeRenderer::Frame& frame) { m_currentFrame = frame.m_currentFrame; while(m_headIndex != UINT16_MAX && - (m_currentFrame - m_pool[m_headIndex].m_frameCount) <= MinimumFrameCount) { + (m_currentFrame - m_pool[m_headIndex].m_frameCount) >= MinimumFrameCount) { auto& head = m_pool[m_headIndex]; // free data m_texturePool->dispose(head.m_handle); diff --git a/HPL2/sources/graphics/RendererDeferred2.cpp b/HPL2/sources/graphics/RendererDeferred2.cpp index 89aa624ee..2738bc27e 100644 --- a/HPL2/sources/graphics/RendererDeferred2.cpp +++ b/HPL2/sources/graphics/RendererDeferred2.cpp @@ -240,6 +240,16 @@ namespace hpl { addSampler(forgeRenderer->Rend(), &pointSamplerDesc, sampler); return true; }); + m_samplerLinearClampToBorder.Load(forgeRenderer->Rend(), [&](Sampler** sampler) { + SamplerDesc pointSamplerDesc = { FILTER_LINEAR, + FILTER_LINEAR, + MIPMAP_MODE_LINEAR, + ADDRESS_MODE_CLAMP_TO_BORDER, + ADDRESS_MODE_CLAMP_TO_BORDER, + ADDRESS_MODE_CLAMP_TO_BORDER }; + addSampler(forgeRenderer->Rend(), &pointSamplerDesc, sampler); + return true; + }); m_samplerPointWrap.Load(forgeRenderer->Rend(), [&](Sampler** sampler) { SamplerDesc pointSamplerDesc = { FILTER_NEAREST, FILTER_NEAREST, @@ -445,8 +455,8 @@ namespace hpl { m_translucencyRefractionShaderAlpha.m_handle, m_translucencyRefractionShaderPremulAlpha.m_handle, m_translucencyIlluminationShaderPremulAlpha.m_handle }; - Sampler* vbShadeSceneSamplers[] = { m_samplerMaterial.m_handle, m_samplerNearEdgeClamp.m_handle, m_samplerPointWrap.m_handle }; - const char* vbShadeSceneSamplersNames[] = {"sceneSampler" , "nearEdgeClampSampler", "nearPointWrapSampler" }; + Sampler* vbShadeSceneSamplers[] = { m_samplerMaterial.m_handle, m_samplerNearEdgeClamp.m_handle, m_samplerPointWrap.m_handle, m_samplerLinearClampToBorder.m_handle}; + const char* vbShadeSceneSamplersNames[] = {"sceneSampler" , "nearEdgeClampSampler", "nearPointWrapSampler", "linearBorderSampler" }; RootSignatureDesc rootSignatureDesc = {}; rootSignatureDesc.ppShaders = shaders.data(); rootSignatureDesc.mShaderCount = shaders.size(); @@ -1756,8 +1766,6 @@ namespace hpl { if (material->IsAffectedByLightLevel()) { sceneParticle->lightLevel = detail::calcLightLevel(m_rendererList.GetLights(), renderable); } - sceneParticle->sampleIndex = - resource::textureFilterNonAnistropyIdx(material->GetTextureWrap(), material->GetTextureFilter()); sceneParticle->modelMat = modelMat; sceneParticle->uvMat = cMath::ToForgeMatrix4(material->GetUvMatrix().GetTranspose()); endUpdateResource(&updateDesc); @@ -1937,7 +1945,6 @@ namespace hpl { beginUpdateResource(&updateDesc); auto* sceneDecal = static_cast(updateDesc.pMappedData); sceneDecal->diffuseTextureIndex = sharedMaterial.m_textureHandles[eMaterialTexture_Diffuse]; - sceneDecal->sampleIndex = resource::textureFilterNonAnistropyIdx(material->GetTextureWrap(), material->GetTextureFilter()); sceneDecal->modelMat = (*it)->GetModelMatrixPtr() ? cMath::ToForgeMatrix4(*(*it)->GetModelMatrixPtr()) : Matrix4::identity(); sceneDecal->uvMat = cMath::ToForgeMatrix4(material->GetUvMatrix().GetTranspose()); endUpdateResource(&updateDesc); @@ -2020,25 +2027,20 @@ namespace hpl { // ----------------- { cmdBindRenderTargets(cmd, 0, NULL, NULL, NULL, NULL, NULL, -1, -1); - cmdBindPipeline(cmd, m_clearClusterPipeline.m_handle); cmdBindDescriptorSet(cmd, 0, m_lightDescriptorPerFrameSet[frame.m_frameIndex].m_handle); cmdDispatch(cmd, 1, 1, LightClusterSlices); { - std::array barriers = { BufferBarrier{ m_lightClusterCountBuffer[frame.m_frameIndex].m_handle, + std::array barriers = { + BufferBarrier{ m_lightClusterCountBuffer[frame.m_frameIndex].m_handle, RESOURCE_STATE_UNORDERED_ACCESS, - RESOURCE_STATE_UNORDERED_ACCESS } }; + RESOURCE_STATE_UNORDERED_ACCESS } + }; cmdResourceBarrier(cmd, barriers.size(), barriers.data(), 0, nullptr, 0, nullptr); } cmdBindPipeline(cmd, m_lightClusterPipeline.m_handle); cmdBindDescriptorSet(cmd, 0, m_lightDescriptorPerFrameSet[frame.m_frameIndex].m_handle); cmdDispatch(cmd, lightCount, 1, LightClusterSlices); - { - std::array barriers = { BufferBarrier{ m_lightClustersBuffer[frame.m_frameIndex].m_handle, - RESOURCE_STATE_UNORDERED_ACCESS, - RESOURCE_STATE_UNORDERED_ACCESS } }; - cmdResourceBarrier(cmd, barriers.size(), barriers.data(), 0, nullptr, 0, nullptr); - } } // ---------------- @@ -2138,14 +2140,6 @@ namespace hpl { } { cmdBindRenderTargets(cmd, 0, NULL, NULL, NULL, NULL, NULL, -1, -1); - std::array barriers = { - BufferBarrier{ m_lightClusterCountBuffer[frame.m_frameIndex].m_handle, - RESOURCE_STATE_UNORDERED_ACCESS, - RESOURCE_STATE_SHADER_RESOURCE }, - BufferBarrier{ m_lightClustersBuffer[frame.m_frameIndex].m_handle, - RESOURCE_STATE_UNORDERED_ACCESS, - RESOURCE_STATE_SHADER_RESOURCE } - }; std::array rtBarriers = { RenderTargetBarrier{ viewportDatum->m_visiblityBuffer[frame.m_frameIndex].m_handle, RESOURCE_STATE_RENDER_TARGET, @@ -2157,7 +2151,7 @@ namespace hpl { RESOURCE_STATE_SHADER_RESOURCE, RESOURCE_STATE_RENDER_TARGET }, }; - cmdResourceBarrier(cmd, barriers.size(), barriers.data(), 0, nullptr, rtBarriers.size(), rtBarriers.data()); + cmdResourceBarrier(cmd, 0, nullptr, 0, nullptr, rtBarriers.size(), rtBarriers.data()); } { cmdBeginDebugMarker(cmd, 0, 1, 0, "Visibility Emit Buffer Pass"); @@ -2236,7 +2230,15 @@ namespace hpl { RESOURCE_STATE_RENDER_TARGET, RESOURCE_STATE_SHADER_RESOURCE }, }; - cmdResourceBarrier(cmd, 0, nullptr, 0, nullptr, rtBarriers.size(), rtBarriers.data()); + std::array barriers = { + BufferBarrier{ m_lightClusterCountBuffer[frame.m_frameIndex].m_handle, + RESOURCE_STATE_UNORDERED_ACCESS, + RESOURCE_STATE_SHADER_RESOURCE }, + BufferBarrier{ m_lightClustersBuffer[frame.m_frameIndex].m_handle, + RESOURCE_STATE_UNORDERED_ACCESS, + RESOURCE_STATE_SHADER_RESOURCE } + }; + cmdResourceBarrier(cmd, barriers.size(), barriers.data(), 0, nullptr, rtBarriers.size(), rtBarriers.data()); } { cmdBeginDebugMarker(cmd, 0, 1, 0, "Visibility Output Buffer Pass"); diff --git a/HPL2/sources/scene/BillBoard.cpp b/HPL2/sources/scene/BillBoard.cpp index 66cf9b6c3..418df6854 100644 --- a/HPL2/sources/scene/BillBoard.cpp +++ b/HPL2/sources/scene/BillBoard.cpp @@ -208,8 +208,8 @@ namespace hpl { DrawPacket cBillboard::ResolveDrawPacket(const ForgeRenderer::Frame& frame) { - if((frame.m_frameIndex - m_frameIndex) >= ForgeRenderer::SwapChainLength - 1 && m_dirtyBuffer) { - m_frameIndex = frame.m_frameIndex; + if((frame.m_currentFrame - m_frameIndex) >= ForgeRenderer::SwapChainLength - 1 && m_dirtyBuffer) { + m_frameIndex = frame.m_currentFrame; m_activeCopy = (m_activeCopy + 1) % 2; m_dirtyBuffer = false;