Explorar o código

Some refactoring

Panagiotis Christopoulos Charitos %!s(int64=8) %!d(string=hai) anos
pai
achega
af808b73f6

+ 0 - 10
src/anki/gr/common/ClassGpuAllocator.h

@@ -67,14 +67,6 @@ private:
 	}
 	}
 };
 };
 
 
-class ClassGpuAllocatorStats
-{
-public:
-	PtrSize m_totalMemoryUsage;
-	PtrSize m_realMemoryUsage;
-	F32 m_fragmentation; ///< XXX
-};
-
 /// Class based allocator.
 /// Class based allocator.
 class ClassGpuAllocator : public NonCopyable
 class ClassGpuAllocator : public NonCopyable
 {
 {
@@ -93,8 +85,6 @@ public:
 	/// Free allocated memory.
 	/// Free allocated memory.
 	void free(ClassGpuAllocatorHandle& handle);
 	void free(ClassGpuAllocatorHandle& handle);
 
 
-	void getStats(ClassGpuAllocatorStats& stats) const;
-
 private:
 private:
 	using Class = ClassGpuAllocatorClass;
 	using Class = ClassGpuAllocatorClass;
 	using Chunk = ClassGpuAllocatorChunk;
 	using Chunk = ClassGpuAllocatorChunk;

+ 0 - 134
src/anki/gr/common/GpuBlockAllocator.cpp

@@ -1,134 +0,0 @@
-// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <anki/gr/common/GpuBlockAllocator.h>
-
-namespace anki
-{
-
-class GpuBlockAllocator::Block : public IntrusiveListEnabled<GpuBlockAllocator::Block>
-{
-public:
-	PtrSize m_offset = 0;
-	U32 m_allocationCount = 0;
-};
-
-GpuBlockAllocator::~GpuBlockAllocator()
-{
-	if(m_freeBlockCount != m_blocks.getSize())
-	{
-		ANKI_LOGW("Forgot to free memory");
-	}
-
-	m_blocks.destroy(m_alloc);
-	m_freeBlocksStack.destroy(m_alloc);
-}
-
-void GpuBlockAllocator::init(GenericMemoryPoolAllocator<U8> alloc, PtrSize totalSize, PtrSize blockSize)
-{
-	ANKI_ASSERT(!isCreated());
-	ANKI_ASSERT(totalSize > 0 && blockSize > 0);
-	ANKI_ASSERT(totalSize > blockSize);
-	ANKI_ASSERT((totalSize % blockSize) == 0);
-
-	m_alloc = alloc;
-	m_size = totalSize;
-	m_blockSize = blockSize;
-	m_blocks.create(alloc, totalSize / blockSize);
-
-	m_freeBlocksStack.create(alloc, m_blocks.getSize());
-	m_freeBlockCount = m_blocks.getSize();
-	m_currentBlock = MAX_U32;
-
-	U count = m_freeBlocksStack.getSize();
-	for(U32& i : m_freeBlocksStack)
-	{
-		i = --count;
-	}
-}
-
-Bool GpuBlockAllocator::blockHasEnoughSpace(U blockIdx, PtrSize size, U alignment) const
-{
-	ANKI_ASSERT(size > 0);
-
-	const Block& block = m_blocks[blockIdx];
-
-	PtrSize allocEnd = getAlignedRoundUp(alignment, block.m_offset) + size;
-	PtrSize blockEnd = (blockIdx + 1) * m_blockSize;
-
-	return allocEnd <= blockEnd;
-}
-
-Error GpuBlockAllocator::allocate(PtrSize size, U alignment, PtrSize& outOffset)
-{
-	ANKI_ASSERT(isCreated());
-	ANKI_ASSERT(size < m_blockSize);
-
-	Block* block = nullptr;
-	Error err = ErrorCode::NONE;
-
-	LockGuard<Mutex> lock(m_mtx);
-
-	if(m_currentBlock == MAX_U32 || !blockHasEnoughSpace(m_currentBlock, size, alignment))
-	{
-		// Need new block
-		if(m_freeBlockCount > 0)
-		{
-			// Pop block from free
-			U blockIdx = --m_freeBlockCount;
-
-			block = &m_blocks[blockIdx];
-			block->m_offset = blockIdx * m_blockSize;
-			ANKI_ASSERT(block->m_allocationCount == 0);
-
-			// Make it in-use
-			m_currentBlock = blockIdx;
-		}
-	}
-
-	if(block)
-	{
-		PtrSize outOffset = getAlignedRoundUp(alignment, block->m_offset);
-		block->m_offset = outOffset + size;
-		ANKI_ASSERT(block->m_offset <= (block - &m_blocks[0] + 1) * m_blockSize);
-
-		++block->m_allocationCount;
-
-		// Update the handle
-		outOffset = outOffset;
-	}
-	else
-	{
-		err = ErrorCode::OUT_OF_MEMORY;
-		outOffset = MAX_PTR_SIZE;
-	}
-
-	return err;
-}
-
-void GpuBlockAllocator::free(PtrSize offset)
-{
-	ANKI_ASSERT(isCreated());
-	ANKI_ASSERT(offset < m_size);
-
-	U blockIdx = offset / m_blockSize;
-
-	LockGuard<Mutex> lock(m_mtx);
-
-	ANKI_ASSERT(m_blocks[blockIdx].m_allocationCount > 0);
-	if((--m_blocks[blockIdx].m_allocationCount) == 0)
-	{
-		// Block no longer in use
-
-		if(m_currentBlock == blockIdx)
-		{
-			m_currentBlock = MAX_U32;
-		}
-
-		m_freeBlocksStack[m_freeBlockCount++] = blockIdx;
-	}
-}
-
-} // end namespace anki

+ 0 - 60
src/anki/gr/common/GpuBlockAllocator.h

@@ -1,60 +0,0 @@
-// Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <anki/gr/Common.h>
-#include <anki/util/List.h>
-
-namespace anki
-{
-
-/// @addtogroup graphics
-/// @{
-
-/// Manages pre-allocated, always mapped GPU memory in blocks.
-class GpuBlockAllocator : public NonCopyable
-{
-public:
-	/// Default constructor.
-	GpuBlockAllocator()
-	{
-	}
-
-	/// Destructor.
-	~GpuBlockAllocator();
-
-	/// Initialize the allocator using pre-allocated CPU mapped memory.
-	void init(GenericMemoryPoolAllocator<U8> alloc, PtrSize totalSize, PtrSize blockSize);
-
-	/// Allocate GPU memory.
-	ANKI_USE_RESULT Error allocate(PtrSize size, U alignment, PtrSize& outOffset);
-
-	/// Free GPU memory.
-	void free(PtrSize offset);
-
-private:
-	class Block;
-
-	GenericMemoryPoolAllocator<U8> m_alloc;
-	PtrSize m_size = 0;
-	PtrSize m_blockSize = 0;
-	DynamicArray<Block> m_blocks;
-
-	DynamicArray<U32> m_freeBlocksStack;
-	U32 m_freeBlockCount = 0;
-	U32 m_currentBlock = MAX_U32;
-	Mutex m_mtx;
-
-	Bool isCreated() const
-	{
-		return m_size > 0;
-	}
-
-	Bool blockHasEnoughSpace(U blockIdx, PtrSize size, U alignment) const;
-};
-/// @}
-
-} // end namespace anki

+ 1 - 1
src/anki/renderer/Is.cpp

@@ -160,6 +160,7 @@ void Is::run(RenderingContext& ctx)
 	cmdb->bindTexture(1, 1, m_r->getMs().m_rt1);
 	cmdb->bindTexture(1, 1, m_r->getMs().m_rt1);
 	cmdb->bindTexture(1, 2, m_r->getMs().m_rt2);
 	cmdb->bindTexture(1, 2, m_r->getMs().m_rt2);
 	cmdb->bindTexture(1, 3, m_r->getMs().m_depthRt, DepthStencilAspectBit::DEPTH);
 	cmdb->bindTexture(1, 3, m_r->getMs().m_depthRt, DepthStencilAspectBit::DEPTH);
+	cmdb->informTextureCurrentUsage(m_r->getSsao().m_main.getPreviousRt(), TextureUsageBit::SAMPLED_FRAGMENT);
 	cmdb->bindTexture(1, 4, m_r->getSsao().m_main.getPreviousRt());
 	cmdb->bindTexture(1, 4, m_r->getSsao().m_main.getPreviousRt());
 
 
 	cmdb->bindTexture(0, 0, m_r->getSm().m_spotTexArray);
 	cmdb->bindTexture(0, 0, m_r->getSm().m_spotTexArray);
@@ -170,7 +171,6 @@ void Is::run(RenderingContext& ctx)
 	cmdb->bindTexture(0, 5, (ctx.m_is.m_diffDecalTex) ? ctx.m_is.m_diffDecalTex : m_r->getDummyTexture());
 	cmdb->bindTexture(0, 5, (ctx.m_is.m_diffDecalTex) ? ctx.m_is.m_diffDecalTex : m_r->getDummyTexture());
 	cmdb->bindTexture(
 	cmdb->bindTexture(
 		0, 6, (ctx.m_is.m_normRoughnessDecalTex) ? ctx.m_is.m_normRoughnessDecalTex : m_r->getDummyTexture());
 		0, 6, (ctx.m_is.m_normRoughnessDecalTex) ? ctx.m_is.m_normRoughnessDecalTex : m_r->getDummyTexture());
-	cmdb->informTextureCurrentUsage(m_r->getSsao().m_main.getPreviousRt(), TextureUsageBit::SAMPLED_FRAGMENT);
 
 
 	bindUniforms(cmdb, 0, 0, ctx.m_is.m_commonToken);
 	bindUniforms(cmdb, 0, 0, ctx.m_is.m_commonToken);
 	bindUniforms(cmdb, 0, 1, ctx.m_is.m_pointLightsToken);
 	bindUniforms(cmdb, 0, 1, ctx.m_is.m_pointLightsToken);

+ 17 - 0
tests/ui/Ui.cpp

@@ -0,0 +1,17 @@
+// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <tests/framework/Framework.h>
+#include <anki/core/App.h>
+#include <anki/core/Config.h>
+
+namespace anki
+{
+
+ANKI_TEST(Ui, Ui)
+{
+	// TODO
+}
+}