Browse Source

Enable the code that does light/probe visibility and feedback

Panagiotis Christopoulos Charitos 2 years ago
parent
commit
519ccf2245

+ 4 - 2
AnKi/Renderer/NonRenderableVisibility.cpp → AnKi/Renderer/PrimaryNonRenderableVisibility.cpp

@@ -3,14 +3,14 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include <AnKi/Renderer/NonRenderableVisibility.h>
+#include <AnKi/Renderer/PrimaryNonRenderableVisibility.h>
 #include <AnKi/Renderer/Renderer.h>
 #include <AnKi/Scene/ContiguousArrayAllocator.h>
 #include <AnKi/Shaders/Include/GpuSceneFunctions.h>
 
 namespace anki {
 
-void NonRenderableVisibility::populateRenderGraph(RenderingContext& ctx)
+void PrimaryNonRenderableVisibility::populateRenderGraph(RenderingContext& ctx)
 {
 	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
 
@@ -63,6 +63,8 @@ void NonRenderableVisibility::populateRenderGraph(RenderingContext& ctx)
 
 		GpuVisibilityNonRenderablesOutput out;
 		getRenderer().getGpuVisibilityNonRenderables().populateRenderGraph(in, out);
+
+		m_runCtx.m_visOutBufferHandle[type] = out.m_bufferHandle;
 	}
 }
 

+ 8 - 1
AnKi/Renderer/NonRenderableVisibility.h → AnKi/Renderer/PrimaryNonRenderableVisibility.h

@@ -16,9 +16,14 @@ namespace anki {
 /// @{
 
 /// Multiple passes for GPU visibility of non-renderable entities.
-class NonRenderableVisibility : public RendererObject
+class PrimaryNonRenderableVisibility : public RendererObject
 {
 public:
+	Error init()
+	{
+		return Error::kNone;
+	}
+
 	void populateRenderGraph(RenderingContext& ctx);
 
 private:
@@ -31,6 +36,8 @@ private:
 		Array<PtrSize, U32(GpuSceneNonRenderableObjectType::kCount)> m_visOutBufferOffsets = {};
 		Array<PtrSize, U32(GpuSceneNonRenderableObjectType::kCount)> m_visOutBufferRanges = {};
 
+		Array<BufferHandle, U32(GpuSceneNonRenderableObjectType::kCount)> m_visOutBufferHandle;
+
 		Array<WeakArray<U32>, U32(GpuSceneNonRenderableObjectTypeWithFeedback::kCount)> m_uuids;
 	} m_runCtx;
 };

+ 5 - 0
AnKi/Renderer/Renderer.cpp

@@ -44,6 +44,7 @@
 #include <AnKi/Renderer/IndirectDiffuse.h>
 #include <AnKi/Renderer/VrsSriGeneration.h>
 #include <AnKi/Renderer/PackVisibleClusteredObjects.h>
+#include <AnKi/Renderer/PrimaryNonRenderableVisibility.h>
 
 namespace anki {
 
@@ -245,6 +246,9 @@ Error Renderer::initInternal(UVec2 swapchainResolution)
 	m_packVisibleClustererObjects.reset(newInstance<PackVisibleClusteredObjects>(RendererMemoryPool::getSingleton()));
 	ANKI_CHECK(m_packVisibleClustererObjects->init());
 
+	m_primaryNonRenderableVisibility.reset(newInstance<PrimaryNonRenderableVisibility>(RendererMemoryPool::getSingleton()));
+	ANKI_CHECK(m_primaryNonRenderableVisibility->init());
+
 	// Init samplers
 	{
 		SamplerInitInfo sinit("NearestNearestClamp");
@@ -344,6 +348,7 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx)
 
 	// Populate render graph. WARNING Watch the order
 	gpuSceneCopy(ctx);
+	m_primaryNonRenderableVisibility->populateRenderGraph(ctx);
 	m_packVisibleClustererObjects->populateRenderGraph(ctx);
 	m_genericCompute->populateRenderGraph(ctx);
 	m_clusterBinning->populateRenderGraph(ctx);

+ 1 - 0
AnKi/Renderer/RendererObject.defs.h

@@ -32,3 +32,4 @@ ANKI_RENDERER_OBJECT_DEF(Scale, scale)
 ANKI_RENDERER_OBJECT_DEF(IndirectDiffuse, indirectDiffuse)
 ANKI_RENDERER_OBJECT_DEF(VrsSriGeneration, vrsSriGeneration)
 ANKI_RENDERER_OBJECT_DEF(PackVisibleClusteredObjects, packVisibleClustererObjects)
+ANKI_RENDERER_OBJECT_DEF(PrimaryNonRenderableVisibility, primaryNonRenderableVisibility)

+ 8 - 8
AnKi/Renderer/Utils/GpuVisibility.cpp

@@ -150,13 +150,14 @@ void GpuVisibility::populateRenderGraph(CString passesName, RenderingTechnique t
 
 		const GpuSceneContiguousArrayType type = techniqueToArrayType(technique);
 
-		cmdb.bindStorageBuffer(0, 0, &GpuSceneBuffer::getSingleton().getBuffer(), GpuSceneContiguousArrays::getSingleton().getArrayBase(type),
-							   GpuSceneContiguousArrays::getSingleton().getElementCount(type) * sizeof(GpuSceneRenderableAabb));
+		cmdb.bindStorageBuffer(0, 0, &GpuSceneBuffer::getSingleton().getBuffer(), GpuSceneContiguousArrays::getSingleton().getArrayBaseOffset(type),
+							   GpuSceneContiguousArrays::getSingleton().getElementCount(type)
+								   * GpuSceneContiguousArrays::getSingleton().getElementSize(type));
 
 		cmdb.bindStorageBuffer(0, 1, &GpuSceneBuffer::getSingleton().getBuffer(),
-							   GpuSceneContiguousArrays::getSingleton().getArrayBase(GpuSceneContiguousArrayType::kRenderables),
+							   GpuSceneContiguousArrays::getSingleton().getArrayBaseOffset(GpuSceneContiguousArrayType::kRenderables),
 							   GpuSceneContiguousArrays::getSingleton().getElementCount(GpuSceneContiguousArrayType::kRenderables)
-								   * sizeof(GpuSceneRenderable));
+								   * GpuSceneContiguousArrays::getSingleton().getElementSize(GpuSceneContiguousArrayType::kRenderables));
 
 		cmdb.bindStorageBuffer(0, 2, &GpuSceneBuffer::getSingleton().getBuffer(), 0, kMaxPtrSize);
 
@@ -295,7 +296,7 @@ void GpuVisibilityNonRenderables::populateRenderGraph(GpuVisibilityNonRenderable
 
 	// Allocate memory for the result
 	RebarAllocation visibleIndicesAlloc;
-	U32* indices = RebarTransientMemoryPool::getSingleton().allocateFrame<U32>(objCount, visibleIndicesAlloc);
+	U32* indices = RebarTransientMemoryPool::getSingleton().allocateFrame<U32>(objCount + 1, visibleIndicesAlloc);
 	indices[0] = 0;
 
 	out.m_visibleIndicesBuffer = &RebarTransientMemoryPool::getSingleton().getBuffer();
@@ -330,9 +331,8 @@ void GpuVisibilityNonRenderables::populateRenderGraph(GpuVisibilityNonRenderable
 
 		cmdb.bindShaderProgram(m_grProgs[0][objType][needsFeedback].get());
 
-		cmdb.bindStorageBuffer(0, 0, &GpuSceneBuffer::getSingleton().getBuffer(), cArrays.getArrayBase(arrayType),
-							   cArrays.getElementCount(GpuSceneContiguousArrayType::kRenderables),
-							   cArrays.getElementSize(arrayType) * cArrays.getElementCount(arrayType));
+		cmdb.bindStorageBuffer(0, 0, &GpuSceneBuffer::getSingleton().getBuffer(), cArrays.getArrayBaseOffset(arrayType),
+							   cArrays.getElementSize(arrayType) * cArrays.getElementCount(arrayType), 0);
 
 		GpuVisibilityNonRenderableUniforms* unis =
 			allocateAndBindUniforms<GpuVisibilityNonRenderableUniforms*>(sizeof(GpuVisibilityNonRenderableUniforms), cmdb, 0, 1);

+ 5 - 1
AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp

@@ -13,7 +13,7 @@
 namespace anki {
 
 GlobalIlluminationProbeComponent::GlobalIlluminationProbeComponent(SceneNode* node)
-	: SceneComponent(node, getStaticClassId())
+	: QueryableSceneComponent<GlobalIlluminationProbeComponent>(node, getStaticClassId())
 	, m_spatial(this)
 {
 	for(U32 i = 0; i < 6; ++i)
@@ -107,6 +107,9 @@ Error GlobalIlluminationProbeComponent::update(SceneComponentUpdateInfo& info, B
 		const Aabb aabb(-m_halfSize + m_worldPos, m_halfSize + m_worldPos);
 		m_spatial.setBoundingShape(aabb);
 
+		// New UUID
+		refreshUuid();
+
 		// Upload to the GPU scene
 		GpuSceneGlobalIlluminationProbe gpuProbe;
 		gpuProbe.m_aabbMin = aabb.getMin().xyz();
@@ -114,6 +117,7 @@ Error GlobalIlluminationProbeComponent::update(SceneComponentUpdateInfo& info, B
 		gpuProbe.m_volumeTexture = m_volTexBindlessIdx;
 		gpuProbe.m_halfTexelSizeU = 1.0f / (F32(m_cellCounts.y()) * 6.0f) / 2.0f;
 		gpuProbe.m_fadeDistance = m_fadeDistance;
+		gpuProbe.m_uuid = getUuid();
 
 		GpuSceneMicroPatcher::getSingleton().newCopy(*info.m_framePool, m_gpuSceneIndex.getOffsetInGpuScene(), gpuProbe);
 	}

+ 1 - 1
AnKi/Scene/Components/GlobalIlluminationProbeComponent.h

@@ -17,7 +17,7 @@ namespace anki {
 /// @{
 
 /// Global illumination probe component. It's an axis aligned box divided into cells.
-class GlobalIlluminationProbeComponent : public SceneComponent
+class GlobalIlluminationProbeComponent : public QueryableSceneComponent<GlobalIlluminationProbeComponent>
 {
 	ANKI_SCENE_COMPONENT(GlobalIlluminationProbeComponent)
 

+ 1 - 1
AnKi/Scene/Components/ModelComponent.cpp

@@ -444,7 +444,7 @@ void ModelComponent::setupRayTracingInstanceQueueElements(U32 lod, RenderingTech
 		queueElem.m_uniformsOffset = m_patchInfos[i].m_gpuSceneUniformsOffset;
 		queueElem.m_geometryOffset =
 			U32(m_patchInfos[i].m_gpuSceneIndexMeshLods.get() * sizeof(GpuSceneMeshLod) * kMaxLodCount + lod * sizeof(GpuSceneMeshLod));
-		queueElem.m_geometryOffset += U32(gpuArrays.getArrayBase(GpuSceneContiguousArrayType::kMeshLods));
+		queueElem.m_geometryOffset += U32(gpuArrays.getArrayBaseOffset(GpuSceneContiguousArrayType::kMeshLods));
 		queueElem.m_indexBufferOffset = U32(modelInf.m_indexBufferOffset);
 
 		const Transform positionTransform(patch.getMesh()->getPositionsTranslation().xyz0(), Mat3x4::getIdentity(),

+ 5 - 1
AnKi/Scene/Components/ReflectionProbeComponent.cpp

@@ -12,7 +12,7 @@
 namespace anki {
 
 ReflectionProbeComponent::ReflectionProbeComponent(SceneNode* node)
-	: SceneComponent(node, getStaticClassId())
+	: QueryableSceneComponent<ReflectionProbeComponent>(node, getStaticClassId())
 	, m_spatial(this)
 {
 	m_worldPos = node->getWorldTransform().getOrigin().xyz();
@@ -89,12 +89,16 @@ Error ReflectionProbeComponent::update(SceneComponentUpdateInfo& info, Bool& upd
 		const Aabb aabbWorld(-m_halfSize + m_worldPos, m_halfSize + m_worldPos);
 		m_spatial.setBoundingShape(aabbWorld);
 
+		// New UUID
+		refreshUuid();
+
 		// Upload to the GPU scene
 		GpuSceneReflectionProbe gpuProbe;
 		gpuProbe.m_position = m_worldPos;
 		gpuProbe.m_cubeTexture = m_reflectionTexBindlessIndex;
 		gpuProbe.m_aabbMin = aabbWorld.getMin().xyz();
 		gpuProbe.m_aabbMax = aabbWorld.getMax().xyz();
+		gpuProbe.m_uuid = getUuid();
 		GpuSceneMicroPatcher::getSingleton().newCopy(*info.m_framePool, m_gpuSceneIndex.getOffsetInGpuScene(), gpuProbe);
 	}
 

+ 1 - 1
AnKi/Scene/Components/ReflectionProbeComponent.h

@@ -17,7 +17,7 @@ namespace anki {
 /// @{
 
 /// Reflection probe component.
-class ReflectionProbeComponent : public SceneComponent
+class ReflectionProbeComponent : public QueryableSceneComponent<ReflectionProbeComponent>
 {
 	ANKI_SCENE_COMPONENT(ReflectionProbeComponent)
 

+ 2 - 2
AnKi/Scene/ContiguousArrayAllocator.h

@@ -98,7 +98,7 @@ public:
 	GpuSceneContiguousArrayIndex allocate(GpuSceneContiguousArrayType type);
 
 	/// @note It's not thread-safe
-	PtrSize getArrayBase(GpuSceneContiguousArrayType type) const
+	PtrSize getArrayBaseOffset(GpuSceneContiguousArrayType type) const
 	{
 		return m_allocs[type].getArrayBase();
 	}
@@ -113,7 +113,7 @@ public:
 	U32 getElementOffsetInGpuScene(const GpuSceneContiguousArrayIndex& idx) const
 	{
 		ANKI_ASSERT(idx.isValid());
-		return U32(getArrayBase(idx.m_type) + m_componentCount[idx.m_type] * m_componentSize[idx.m_type] * idx.m_index);
+		return U32(getArrayBaseOffset(idx.m_type) + m_componentCount[idx.m_type] * m_componentSize[idx.m_type] * idx.m_index);
 	}
 
 	constexpr static U32 getElementSize(GpuSceneContiguousArrayType type)

+ 1 - 1
AnKi/Scene/Visibility.cpp

@@ -797,7 +797,7 @@ void CombineResultsTask::combine()
 	const GpuSceneContiguousArrays& arrays = GpuSceneContiguousArrays::getSingleton();
 
 	auto setOffset = [&](ClusteredObjectType type, GpuSceneContiguousArrayType type2) {
-		results.m_clustererObjectsArrayOffsets[type] = arrays.getElementCount(type2) ? arrays.getArrayBase(type2) : 0;
+		results.m_clustererObjectsArrayOffsets[type] = arrays.getElementCount(type2) ? arrays.getArrayBaseOffset(type2) : 0;
 		results.m_clustererObjectsArrayRanges[type] = arrays.getElementCount(type2) * arrays.getElementSize(type2);
 	};
 

+ 4 - 4
AnKi/Shaders/GpuVisibilityNonRenderables.ankiprog

@@ -124,12 +124,12 @@ Vec4 getSphere(GpuSceneGlobalIlluminationProbe l)
 #if CPU_FEEDBACK
 	if(obj.m_uuid != 0)
 	{
-		U32 count;
-		InterlockedAdd(g_counterBuffer[g_unis.m_feedbackCounterIdx], 1, count);
+		U32 idx;
+		InterlockedAdd(g_counterBuffer[g_unis.m_feedbackCounterIdx], 1, idx);
 
 		U32 dummy;
-		InterlockedExchange(g_cpuFeedbackBuffer[0], count, dummy);
-		g_cpuFeedbackBuffer[count + 1] = obj.m_uuid;
+		InterlockedExchange(g_cpuFeedbackBuffer[0], idx + 1, dummy);
+		g_cpuFeedbackBuffer[idx + 1] = obj.m_uuid;
 	}
 #endif
 }

+ 2 - 2
AnKi/Shaders/Include/GpuSceneTypes.h

@@ -98,7 +98,7 @@ struct GpuSceneReflectionProbe
 	U32 m_cubeTexture; ///< Bindless index of the reflection texture.
 
 	Vec3 m_aabbMin;
-	F32 m_uuid;
+	U32 m_uuid;
 
 	Vec3 m_aabbMax;
 	F32 m_padding1;
@@ -110,7 +110,7 @@ static_assert(sizeof(GpuSceneReflectionProbe) == kSizeof_GpuSceneReflectionProbe
 struct GpuSceneGlobalIlluminationProbe
 {
 	Vec3 m_aabbMin;
-	F32 m_uuid;
+	U32 m_uuid;
 
 	Vec3 m_aabbMax;
 	F32 m_padding1;