Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
godlikepanos committed Oct 12, 2024
1 parent b0468d4 commit 56b24c2
Show file tree
Hide file tree
Showing 45 changed files with 61 additions and 269 deletions.
3 changes: 0 additions & 3 deletions AnKi/Gr/BackendCommon/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

namespace anki {

/// There is no need to ask for a fence or a semaphore to be waited for more than 10 seconds. The GPU will timeout anyway.
constexpr Second kMaxFenceOrSemaphoreWaitTime = 120.0;

constexpr U32 kMaxQueriesPerQueryChunk = 64;

} // end namespace anki
2 changes: 2 additions & 0 deletions AnKi/Gr/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ inline BoolCVar g_rayTracingCVar("Gr", "RayTracing", false, "Try enabling ray tr
inline BoolCVar g_vrsCVar("Gr", "Vrs", false, "Enable or not VRS");
inline BoolCVar g_workGraphcsCVar("Gr", "WorkGraphs", false, "Enable or not WorkGraphs");
inline NumericCVar<U32> g_maxBindlessSampledTextureCountCVar("Gr", "MaxBindlessSampledTextureCountCVar", 512, 16, kMaxU16);
inline NumericCVar<Second> g_gpuTimeoutCVar("Gr", "GpuTimeout", 120.0, 0.0, 24.0 * 60.0,
"Max time to wait for GPU fences or semaphores. More than that it must be a GPU timeout");

#if ANKI_GR_BACKEND_DIRECT3D
inline NumericCVar<U16> g_maxRtvDescriptorsCVar("Gr", "MaxRvtDescriptors", 1024, 8, kMaxU16, "Max number of RTVs");
Expand Down
4 changes: 2 additions & 2 deletions AnKi/Gr/D3D/D3DFence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Bool MicroFence::clientWait(Second seconds)
}
else
{
seconds = min(seconds, kMaxFenceOrSemaphoreWaitTime);
seconds = min<Second>(seconds, g_gpuTimeoutCVar);

ANKI_D3D_CHECKF(m_fence->SetEventOnCompletion(m_value.load(), m_event));

Expand Down Expand Up @@ -134,7 +134,7 @@ void FenceFactory::trimSignaledFences(Bool wait)
GrDynamicArray<MicroFence*> unsignaledFences;
for(MicroFence* fence : m_fences)
{
const Bool signaled = fence->clientWait((wait) ? kMaxFenceOrSemaphoreWaitTime : 0.0f);
const Bool signaled = fence->clientWait((wait) ? g_gpuTimeoutCVar : 0.0);
if(signaled)
{
deleteInstance(GrMemoryPool::getSingleton(), fence);
Expand Down
2 changes: 1 addition & 1 deletion AnKi/Gr/Vulkan/VkFenceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void FenceFactory::trimSignaledFences(Bool wait)
GrDynamicArray<MicroFence*> unsignaledFences;
for(MicroFence* fence : m_fences)
{
const Bool signaled = fence->clientWait((wait) ? kMaxFenceOrSemaphoreWaitTime : 0.0f);
const Bool signaled = fence->clientWait((wait) ? g_gpuTimeoutCVar : 0.0);
if(signaled)
{
deleteInstance(GrMemoryPool::getSingleton(), fence);
Expand Down
2 changes: 1 addition & 1 deletion AnKi/Gr/Vulkan/VkFenceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MicroFence
}
else
{
seconds = min(seconds, kMaxFenceOrSemaphoreWaitTime);
seconds = min<Second>(seconds, g_gpuTimeoutCVar);
const F64 nsf = 1e+9 * seconds;
const U64 ns = U64(nsf);
VkResult res;
Expand Down
2 changes: 1 addition & 1 deletion AnKi/Gr/Vulkan/VkSemaphoreFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Bool MicroSemaphore::clientWait(Second seconds)
{
ANKI_ASSERT(m_isTimeline);

seconds = min(seconds, kMaxFenceOrSemaphoreWaitTime);
seconds = min<Second>(seconds, g_gpuTimeoutCVar);

VkSemaphoreWaitInfo waitInfo = {};
waitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO;
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/Bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Error Bloom::init()
const UVec2 pyramidSize = getRenderer().getInternalResolution() / 2;
const U32 pyramidMipCount = computeMaxMipmapCount2d(pyramidSize.x(), pyramidSize.y(), g_bloomPyramidLowLimit);

ANKI_R_LOGV("Initializing bloom downscale pyramid. Resolution %ux%u, mip count %u", pyramidSize.x(), pyramidSize.y(), pyramidMipCount);

const Bool preferCompute = g_preferComputeCVar;

// Create the miped texture
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/Dbg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Dbg::~Dbg()

Error Dbg::init()
{
ANKI_R_LOGV("Initializing DBG");

// RT descr
m_rtDescr = getRenderer().create2DRenderTargetDescription(getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(),
Format::kR8G8B8A8_Unorm, "Dbg");
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/DepthDownscale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ Error DepthDownscale::initInternal()

const UVec2 lastMipSize = UVec2(width, height) >> (m_mipCount - 1);

ANKI_R_LOGV("Initializing HiZ. Mip count %u, last mip size %ux%u", m_mipCount, lastMipSize.x(), lastMipSize.y());

const Bool preferCompute = g_preferComputeCVar;

// Create RT descr
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/FinalComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ namespace anki {

Error FinalComposite::initInternal()
{
ANKI_R_LOGV("Initializing final composite");

// Progs
for(MutatorValue dbg = 0; dbg < 2; ++dbg)
{
Expand Down
14 changes: 0 additions & 14 deletions AnKi/Renderer/GBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ GBuffer::~GBuffer()

Error GBuffer::init()
{
Error err = initInternal();

if(err)
{
ANKI_R_LOGE("Failed to initialize g-buffer pass");
}

return err;
}

Error GBuffer::initInternal()
{
ANKI_R_LOGV("Initializing GBuffer. Resolution %ux%u", getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y());

// RTs
static constexpr Array<const char*, 2> depthRtNames = {{"GBuffer depth #0", "GBuffer depth #1"}};
for(U32 i = 0; i < 2; ++i)
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/GBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ class GBuffer : public RendererObject
BufferView m_visibleAaabbIndicesBuffer; ///< Optional
BufferHandle m_visibleAaabbIndicesBufferDepedency;
} m_runCtx;

Error initInternal();
};
/// @}

Expand Down
14 changes: 0 additions & 14 deletions AnKi/Renderer/GBufferPost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@ namespace anki {

Error GBufferPost::init()
{
const Error err = initInternal();
if(err)
{
ANKI_R_LOGE("Failed to initialize GBufferPost pass");
}
return err;
}

Error GBufferPost::initInternal()
{
ANKI_R_LOGV("Initializing GBufferPost pass");

// Load shaders
ANKI_CHECK(loadShaderProgram("ShaderBinaries/GBufferPost.ankiprogbin", m_prog, m_grProg));

return Error::kNone;
}

Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/GBufferPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class GBufferPost : public RendererObject
private:
ShaderProgramResourcePtr m_prog;
ShaderProgramPtr m_grProg;

Error initInternal();
};
/// @}

Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/LensFlare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Error LensFlare::init()

Error LensFlare::initInternal()
{
ANKI_R_LOGV("Initializing lens flare");

m_maxSpritesPerFlare = g_lensFlareMaxSpritesPerFlareCVar;
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LensFlareSprite.ankiprogbin", m_realProg, m_realGrProg));

Expand Down
63 changes: 17 additions & 46 deletions AnKi/Renderer/LightShading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,37 @@ namespace anki {

Error LightShading::init()
{
ANKI_R_LOGV("Initializing light shading");
{
// Load shaders and programs
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShading.ankiprogbin", m_lightShading.m_prog, m_lightShading.m_grProg));

Error err = initLightShading();
// Create RT descr
const UVec2 internalResolution = getRenderer().getInternalResolution();
m_lightShading.m_rtDescr = getRenderer().create2DRenderTargetDescription(internalResolution.x(), internalResolution.y(),
getRenderer().getHdrFormat(), "Light Shading");
m_lightShading.m_rtDescr.bake();

if(!err)
{
err = initSkybox();
// Debug visualization
ANKI_CHECK(loadShaderProgram("ShaderBinaries/VisualizeHdrRenderTarget.ankiprogbin", m_visualizeRtProg, m_visualizeRtGrProg));
}

if(!err)
{
err = initApplyFog();
}
ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/LightShadingSkybox.ankiprogbin", m_skybox.m_prog));

if(err)
{
ANKI_R_LOGE("Failed to init light stage");
for(MutatorValue method = 0; method < 3; ++method)
{
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShadingSkybox.ankiprogbin", {{"METHOD", method}}, m_skybox.m_prog,
m_skybox.m_grProgs[method]));
}
}

return err;
}

Error LightShading::initLightShading()
{
// Load shaders and programs
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShading.ankiprogbin", m_lightShading.m_prog, m_lightShading.m_grProg));

// Create RT descr
const UVec2 internalResolution = getRenderer().getInternalResolution();
m_lightShading.m_rtDescr =
getRenderer().create2DRenderTargetDescription(internalResolution.x(), internalResolution.y(), getRenderer().getHdrFormat(), "Light Shading");
m_lightShading.m_rtDescr.bake();

// Debug visualization
ANKI_CHECK(loadShaderProgram("ShaderBinaries/VisualizeHdrRenderTarget.ankiprogbin", m_visualizeRtProg, m_visualizeRtGrProg));

return Error::kNone;
}

Error LightShading::initSkybox()
{
ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/LightShadingSkybox.ankiprogbin", m_skybox.m_prog));

for(MutatorValue method = 0; method < 3; ++method)
{
ANKI_CHECK(
loadShaderProgram("ShaderBinaries/LightShadingSkybox.ankiprogbin", {{"METHOD", method}}, m_skybox.m_prog, m_skybox.m_grProgs[method]));
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShadingApplyFog.ankiprogbin", m_applyFog.m_prog, m_applyFog.m_grProg));
}

return Error::kNone;
}

Error LightShading::initApplyFog()
{
// Load shaders and programs
ANKI_CHECK(loadShaderProgram("ShaderBinaries/LightShadingApplyFog.ankiprogbin", m_applyFog.m_prog, m_applyFog.m_grProg));

return Error::kNone;
}

void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx)
{
ANKI_TRACE_SCOPED_EVENT(LightShading);
Expand Down
4 changes: 0 additions & 4 deletions AnKi/Renderer/LightShading.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class LightShading : public RendererObject
ShaderProgramResourcePtr m_visualizeRtProg;
ShaderProgramPtr m_visualizeRtGrProg;

Error initLightShading();
Error initSkybox();
Error initApplyFog();

void run(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx);

void getDebugRenderTarget(CString rtName, Array<RenderTargetHandle, kMaxDebugRenderTargets>& handles,
Expand Down
14 changes: 0 additions & 14 deletions AnKi/Renderer/MotionVectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,8 @@ namespace anki {

Error MotionVectors::init()
{
const Error err = initInternal();
if(err)
{
ANKI_R_LOGE("Failed to initialize motion vectors");
}
return err;
}

Error MotionVectors::initInternal()
{
ANKI_R_LOGV("Initializing motion vectors");

// Prog
ANKI_CHECK(loadShaderProgram("ShaderBinaries/MotionVectors.ankiprogbin", m_prog, m_grProg));

// RTs
m_motionVectorsRtDescr = getRenderer().create2DRenderTargetDescription(
getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(), Format::kR16G16_Sfloat, "MotionVectors");
m_motionVectorsRtDescr.bake();
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/MotionVectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class MotionVectors : public RendererObject
public:
RenderTargetHandle m_motionVectorsRtHandle;
} m_runCtx;

Error initInternal();
};
/// @}

Expand Down
8 changes: 7 additions & 1 deletion AnKi/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ Error Renderer::initInternal(const RendererInitInfo& inf)
if(initCondition) \
{ \
m_##name2 = newInstance<name>(RendererMemoryPool::getSingleton()); \
ANKI_CHECK(m_##name2->init()); \
ANKI_R_LOGV("Initializing " ANKI_STRINGIZE(name)); \
const Error err = m_##name2->init(); \
if(err) \
{ \
ANKI_R_LOGE("Initialization failed: " ANKI_STRINGIZE(name)); \
return err; \
} \
}
#include <AnKi/Renderer/RendererObject.def.h>

Expand Down
13 changes: 0 additions & 13 deletions AnKi/Renderer/RtShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ namespace anki {

Error RtShadows::init()
{
const Error err = initInternal();
if(err)
{
ANKI_R_LOGE("Failed to initialize ray traced shadows");
}

return err;
}

Error RtShadows::initInternal()
{
ANKI_R_LOGV("Initializing RT shadows");

m_useSvgf = g_rtShadowsSvgfCVar;
m_atrousPassCount = g_rtShadowsSvgfAtrousPassCountCVar;

Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/RtShadows.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class RtShadows : public RendererObject
Array<RenderTargetHandle, 2> m_varianceRts;
} m_runCtx;

Error initInternal();

void runDenoise(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx, Bool horizontal);

U32 getPassCountWithoutUpscaling() const
Expand Down
15 changes: 0 additions & 15 deletions AnKi/Renderer/ShadowMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,12 @@ static LightHash decodeTileHash(U64 hash)
}

Error ShadowMapping::init()
{
const Error err = initInternal();
if(err)
{
ANKI_R_LOGE("Failed to initialize shadowmapping");
}

return err;
}

Error ShadowMapping::initInternal()
{
// Init RT
{
m_tileResolution = g_shadowMappingTileResolutionCVar;
m_tileCountBothAxis = g_shadowMappingTileCountPerRowOrColumnCVar;

ANKI_R_LOGV("Initializing shadowmapping. Atlas resolution %ux%u", m_tileResolution * m_tileCountBothAxis,
m_tileResolution * m_tileCountBothAxis);

// RT
const TextureUsageBit usage = TextureUsageBit::kSrvPixel | TextureUsageBit::kSrvCompute | TextureUsageBit::kAllRtvDsv;
TextureInitInfo texinit = getRenderer().create2DRenderTargetInitInfo(
m_tileResolution * m_tileCountBothAxis, m_tileResolution * m_tileCountBothAxis, Format::kD32_Sfloat, usage, "ShadowAtlas");
Expand Down
2 changes: 0 additions & 2 deletions AnKi/Renderer/ShadowMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class ShadowMapping : public RendererObject
RenderTargetHandle m_rt;
} m_runCtx;

Error initInternal();

void processLights(RenderingContext& ctx);

TileAllocatorResult2 allocateAtlasTiles(U32 lightUuid, U32 componentIndex, U32 faceCount, const U32* hierarchies, UVec4* atlasTileViewports);
Expand Down
Loading

0 comments on commit 56b24c2

Please sign in to comment.