Browse Source

Minor improvements

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
f3e266562f

+ 1 - 1
AnKi/Core/ConfigDefs.h

@@ -5,7 +5,7 @@
 
 ANKI_CONFIG_OPTION(core_uniformPerFrameMemorySize, 16_MB, 1_MB, 1_GB)
 ANKI_CONFIG_OPTION(core_storagePerFrameMemorySize, 16_MB, 1_MB, 1_GB)
-ANKI_CONFIG_OPTION(core_vertexPerFrameMemorySize, 10_MB, 1_MB, 1_GB)
+ANKI_CONFIG_OPTION(core_vertexPerFrameMemorySize, 8_MB, 1_MB, 1_GB)
 ANKI_CONFIG_OPTION(core_textureBufferPerFrameMemorySize, 1_MB, 1_MB, 1_GB)
 
 ANKI_CONFIG_OPTION(width, 1920, 16, 16 * 1024, "Width")

+ 2 - 2
AnKi/Core/StagingGpuMemoryManager.cpp

@@ -51,7 +51,7 @@ Error StagingGpuMemoryManager::init(GrManager* gr, const ConfigSet& cfg)
 void StagingGpuMemoryManager::initBuffer(StagingGpuMemoryType type, U32 alignment, PtrSize maxAllocSize,
 										 BufferUsageBit usage, GrManager& gr)
 {
-	auto& perframe = m_perFrameBuffers[type];
+	PerFrameBuffer& perframe = m_perFrameBuffers[type];
 
 	perframe.m_buff = gr.newBuffer(BufferInitInfo(perframe.m_size, usage, BufferMapAccessBit::WRITE, "Staging"));
 	perframe.m_alloc.init(perframe.m_size, alignment, maxAllocSize);
@@ -61,7 +61,7 @@ void StagingGpuMemoryManager::initBuffer(StagingGpuMemoryType type, U32 alignmen
 void* StagingGpuMemoryManager::allocateFrame(PtrSize size, StagingGpuMemoryType usage, StagingGpuMemoryToken& token)
 {
 	PerFrameBuffer& buff = m_perFrameBuffers[usage];
-	Error err = buff.m_alloc.allocate(size, token.m_offset);
+	const Error err = buff.m_alloc.allocate(size, token.m_offset);
 	if(err)
 	{
 		ANKI_CORE_LOGF("Out of staging GPU memory. Usage: %u", U32(usage));

+ 2 - 2
AnKi/Gr/Vulkan/Common.h

@@ -94,7 +94,7 @@ static_assert(!(BufferUsageBit::ALL & PrivateBufferUsageBit::ALL_PRIVATE), "Upda
 	do \
 	{ \
 		VkResult rez; \
-		if((rez = (x)) < 0) \
+		if(ANKI_UNLIKELY((rez = (x)) < 0)) \
 		{ \
 			ANKI_VK_LOGF("Vulkan function failed (VkResult: %s): %s", vkResultToString(rez), #x); \
 		} \
@@ -105,7 +105,7 @@ static_assert(!(BufferUsageBit::ALL & PrivateBufferUsageBit::ALL_PRIVATE), "Upda
 	do \
 	{ \
 		VkResult rez; \
-		if((rez = (x)) < 0) \
+		if(ANKI_UNLIKELY((rez = (x)) < 0)) \
 		{ \
 			ANKI_VK_LOGE("Vulkan function failed (VkResult: %s): %s", vkResultToString(rez), #x); \
 			return Error::FUNCTION_FAILED; \

+ 8 - 2
AnKi/Gr/Vulkan/GpuMemoryManager.cpp

@@ -64,7 +64,6 @@ public:
 		else
 		{
 			// Create new
-			mem = m_alloc.newInstance<Memory>();
 
 			VkMemoryAllocateInfo ci = {};
 			ci.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
@@ -79,8 +78,15 @@ public:
 				ci.pNext = &flags;
 			}
 
-			ANKI_VK_CHECKF(vkAllocateMemory(m_dev, &ci, nullptr, &mem->m_handle));
+			VkDeviceMemory memHandle;
+			if(ANKI_UNLIKELY(vkAllocateMemory(m_dev, &ci, nullptr, &memHandle) < 0))
+			{
+				ANKI_VK_LOGF("Out of GPU memory. Mem type index %u, size %zu", m_memTypeIdx,
+							 CLASSES[classIdx].m_chunkSize);
+			}
 
+			mem = m_alloc.newInstance<Memory>();
+			mem->m_handle = memHandle;
 			mem->m_classIdx = U8(classIdx);
 		}
 

+ 3 - 2
AnKi/Renderer/ClusterBinning.cpp

@@ -45,14 +45,15 @@ Error ClusterBinning::init(const ConfigSet& config)
 void ClusterBinning::populateRenderGraph(RenderingContext& ctx)
 {
 	m_runCtx.m_ctx = &ctx;
-	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
-	ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("Cluster Binning");
 
 	const RenderQueue& rqueue = *m_runCtx.m_ctx->m_renderQueue;
 	if(ANKI_LIKELY(rqueue.m_pointLights.getSize() || rqueue.m_spotLights.getSize() || rqueue.m_decals.getSize()
 				   || rqueue.m_reflectionProbes.getSize() || rqueue.m_fogDensityVolumes.getSize()
 				   || rqueue.m_giProbes.getSize()))
 	{
+		RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
+		ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("Cluster Binning");
+
 		pass.setWork(
 			[](RenderPassWorkContext& rgraphCtx) {
 				static_cast<ClusterBinning*>(rgraphCtx.m_userData)->run(rgraphCtx);

+ 1 - 0
AnKi/Renderer/Renderer.cpp

@@ -320,6 +320,7 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx)
 
 	// Populate render graph. WARNING Watch the order
 	m_genericCompute->populateRenderGraph(ctx);
+	m_clusterBinning->populateRenderGraph(ctx);
 	if(m_accelerationStructureBuilder)
 	{
 		m_accelerationStructureBuilder->populateRenderGraph(ctx);

+ 12 - 0
AnKi/Shaders/Functions.glsl

@@ -532,3 +532,15 @@ Vec3 animateBlueNoise(Vec3 inputBlueNoise, U32 frameIdx)
 	const F32 goldenRatioConjugate = 0.61803398875;
 	return fract(inputBlueNoise + F32(frameIdx % 64u) * goldenRatioConjugate);
 }
+
+#if defined(ANKI_FRAGMENT_SHADER)
+/// https://bgolus.medium.com/distinctive-derivative-differences-cce38d36797b
+/// normalizedUvs is uv*textureResolution
+F32 computeMipLevel(Vec2 normalizedUvs)
+{
+	const Vec2 dx = dFdxCoarse(normalizedUvs);
+	const Vec2 dy = dFdyCoarse(normalizedUvs);
+	const F32 deltaMax2 = max(dot(dx, dx), dot(dy, dy));
+	return max(0.0, 0.5 * log2(deltaMax2));
+}
+#endif

+ 7 - 7
AnKi/Shaders/Include/ClustererTypes.h

@@ -25,8 +25,8 @@ const U32 MAX_SHADOW_CASCADES2 = 4u;
 const U32 MAX_VISIBLE_POINT_LIGHTS = 64u;
 const U32 MAX_VISIBLE_SPOT_LIGHTS = 64u;
 const U32 MAX_VISIBLE_DECALS = 64u;
-const U32 MAX_VISIBLE_FOG_DENSITY_VOLUMES = 32u;
-const U32 MAX_VISIBLE_REFLECTION_PROBES = 32u;
+const U32 MAX_VISIBLE_FOG_DENSITY_VOLUMES = 16u;
+const U32 MAX_VISIBLE_REFLECTION_PROBES = 16u;
 const U32 MAX_VISIBLE_GLOBAL_ILLUMINATION_PROBES2 = 8u;
 
 /// Point light.
@@ -187,12 +187,12 @@ struct Cluster
 	U64 m_pointLightsMask;
 	U64 m_spotLightsMask;
 	U64 m_decalsMask;
-	U32 m_fogDensityVolumesMask;
-	U32 m_reflectionProbesMask;
-	U32 m_giProbesMask;
-	U32 m_padding; ///< Add some padding to be 100% sure nothing will break.
+	U16 m_fogDensityVolumesMask;
+	U16 m_reflectionProbesMask;
+	U16 m_giProbesMask;
+	U16 m_padding; ///< Add some padding to be 100% sure nothing will break.
 };
-const U32 _ANKI_SIZEOF_Cluster = 5u * ANKI_SIZEOF(U64);
+const U32 _ANKI_SIZEOF_Cluster = 4u * ANKI_SIZEOF(U64);
 ANKI_SHADER_STATIC_ASSERT(sizeof(Cluster) == _ANKI_SIZEOF_Cluster);
 
 ANKI_END_NAMESPACE