Skip to content

Commit

Permalink
feat: attempt to fix broken rendering ubuntu mesa
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Dec 28, 2023
1 parent e1d9539 commit 9ea7f52
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 41 deletions.
2 changes: 0 additions & 2 deletions HPL2/include/graphics/ForgeRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ namespace hpl {
SharedSampler m_samplerNearEdgeClamp;
SharedSampler m_samplerPointWrap;
SharedSampler m_samplerPointClampToBorder;
SharedSampler m_samplerLinearClampToBorder;
SharedSampler m_samplerMaterial;
std::array<ResourceMaterial, cMaterial::MaxMaterialID> m_sharedMaterial;
BindlessDescriptorPool m_sceneTexture2DPool;
Expand Down
4 changes: 2 additions & 2 deletions HPL2/include/graphics/SceneResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions HPL2/resource/scene_defs.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion HPL2/resource/scene_resource.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions HPL2/sources/graphics/BindlessDescriptorPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions HPL2/sources/graphics/ForgeRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
#endif

namespace hpl {


void ForgeRenderer::IncrementFrame() {
// Stall if CPU is running "Swap Chain Buffer Count" frames ahead of GPU
// m_resourcePoolIndex = (m_resourcePoolIndex + 1) % ResourcePoolSize;
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);
Expand All @@ -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 = {
Expand Down Expand Up @@ -80,15 +82,14 @@ 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;
flushResourceUpdates(&flushUpdateDesc);
waitSemaphores.push_back(flushUpdateDesc.pOutSubmittedSemaphore);
waitSemaphores.push_back(m_imageAcquiredSemaphore);


QueueSubmitDesc submitDesc = {};
submitDesc.mCmdCount = 1;
submitDesc.mSignalSemaphoreCount = 1;
Expand Down
2 changes: 1 addition & 1 deletion HPL2/sources/graphics/ImageBindlessPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 26 additions & 24 deletions HPL2/sources/graphics/RendererDeferred2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1937,7 +1945,6 @@ namespace hpl {
beginUpdateResource(&updateDesc);
auto* sceneDecal = static_cast<resource::SceneDecal*>(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);
Expand Down Expand Up @@ -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);
}
}

// ----------------
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions HPL2/sources/scene/BillBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9ea7f52

Please sign in to comment.