Browse Source

Some refactoring

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
3a6884e744

+ 5 - 0
src/anki/Gr.h

@@ -20,6 +20,11 @@
 #include <anki/gr/RenderGraph.h>
 #include <anki/gr/RenderGraph.h>
 #include <anki/gr/ShaderCompiler.h>
 #include <anki/gr/ShaderCompiler.h>
 
 
+#include <anki/gr/utils/ClassGpuAllocator.h>
+#include <anki/gr/utils/FrameGpuAllocator.h>
+#include <anki/gr/utils/Functions.h>
+#include <anki/gr/utils/StackGpuAllocator.h>
+
 /// @defgroup graphics Graphics API abstraction
 /// @defgroup graphics Graphics API abstraction
 
 
 /// @defgroup opengl OpenGL backend
 /// @defgroup opengl OpenGL backend

+ 1 - 1
src/anki/core/StagingGpuMemoryManager.h

@@ -7,7 +7,7 @@
 
 
 #include <anki/core/Common.h>
 #include <anki/core/Common.h>
 #include <anki/gr/Buffer.h>
 #include <anki/gr/Buffer.h>
-#include <anki/gr/common/FrameGpuAllocator.h>
+#include <anki/gr/utils/FrameGpuAllocator.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 1 - 1
src/anki/gr/CMakeLists.txt

@@ -1,4 +1,4 @@
-file(GLOB SOURCES *.cpp common/*.cpp)
+file(GLOB SOURCES *.cpp utils/*.cpp)
 
 
 if(GL)
 if(GL)
 	set(GR_BACKEND "gl")
 	set(GR_BACKEND "gl")

+ 0 - 51
src/anki/gr/Shader.h

@@ -15,57 +15,6 @@ namespace anki
 /// @addtogroup graphics
 /// @addtogroup graphics
 /// @{
 /// @{
 
 
-/// Using an AnKi typename get the ShaderVariableDataType. Used for debugging.
-template<typename T>
-ShaderVariableDataType getShaderVariableTypeFromTypename();
-
-#define ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(typename_, type_) \
-	template<> \
-	inline ShaderVariableDataType getShaderVariableTypeFromTypename<typename_>() \
-	{ \
-		return ShaderVariableDataType::type_; \
-	}
-
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(I32, INT)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec2, IVEC2)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec3, IVEC3)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec4, IVEC4)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(U32, UINT)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec2, UVEC2)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec3, UVEC3)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec4, UVEC4)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(F32, FLOAT)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec2, VEC2)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec3, VEC3)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec4, VEC4)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Mat3, MAT3)
-ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Mat4, MAT4)
-
-#undef ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET
-
-/// Shader block information.
-class ShaderVariableBlockInfo
-{
-public:
-	I16 m_offset = -1; ///< Offset inside the block
-
-	I16 m_arraySize = -1; ///< Number of elements.
-
-	/// Stride between the each array element if the variable is array.
-	I16 m_arrayStride = -1;
-
-	/// Identifying the stride between columns of a column-major matrix or rows of a row-major matrix.
-	I16 m_matrixStride = -1;
-};
-
-/// Populate the memory of a variable that is inside a shader block.
-void writeShaderBlockMemory(ShaderVariableDataType type,
-	const ShaderVariableBlockInfo& varBlkInfo,
-	const void* elements,
-	U32 elementsCount,
-	void* buffBegin,
-	const void* buffEnd);
-
 /// Specialization constant value.
 /// Specialization constant value.
 class ShaderSpecializationConstValue
 class ShaderSpecializationConstValue
 {
 {

+ 0 - 36
src/anki/gr/common/Misc.h

@@ -1,36 +0,0 @@
-// Copyright (C) 2009-2019, 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>
-
-namespace anki
-{
-
-inline Bool stencilTestDisabled(StencilOperation stencilFail,
-	StencilOperation stencilPassDepthFail,
-	StencilOperation stencilPassDepthPass,
-	CompareOperation compare)
-{
-	return stencilFail == StencilOperation::KEEP && stencilPassDepthFail == StencilOperation::KEEP
-		   && stencilPassDepthPass == StencilOperation::KEEP && compare == CompareOperation::ALWAYS;
-}
-
-inline Bool blendingDisabled(BlendFactor srcFactorRgb,
-	BlendFactor dstFactorRgb,
-	BlendFactor srcFactorA,
-	BlendFactor dstFactorA,
-	BlendOperation opRgb,
-	BlendOperation opA)
-{
-	Bool dontWantBlend = srcFactorRgb == BlendFactor::ONE && dstFactorRgb == BlendFactor::ZERO
-						 && srcFactorA == BlendFactor::ONE && dstFactorA == BlendFactor::ZERO
-						 && (opRgb == BlendOperation::ADD || opRgb == BlendOperation::SUBTRACT)
-						 && (opA == BlendOperation::ADD || opA == BlendOperation::SUBTRACT);
-	return dontWantBlend;
-}
-
-} // end namespace anki

+ 1 - 1
src/anki/gr/gl/StateTracker.h

@@ -19,7 +19,7 @@
 #include <anki/gr/gl/ShaderProgramImpl.h>
 #include <anki/gr/gl/ShaderProgramImpl.h>
 #include <anki/gr/Framebuffer.h>
 #include <anki/gr/Framebuffer.h>
 #include <anki/gr/gl/FramebufferImpl.h>
 #include <anki/gr/gl/FramebufferImpl.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 1 - 1
src/anki/gr/gl/TextureImpl.h

@@ -7,7 +7,7 @@
 
 
 #include <anki/gr/Texture.h>
 #include <anki/gr/Texture.h>
 #include <anki/gr/gl/GlObject.h>
 #include <anki/gr/gl/GlObject.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 #include <anki/util/HashMap.h>
 #include <anki/util/HashMap.h>
 
 
 namespace anki
 namespace anki

+ 1 - 1
src/anki/gr/common/ClassGpuAllocator.cpp → src/anki/gr/utils/ClassGpuAllocator.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/common/ClassGpuAllocator.h>
+#include <anki/gr/utils/ClassGpuAllocator.h>
 #include <anki/util/List.h>
 #include <anki/util/List.h>
 #include <anki/util/BitSet.h>
 #include <anki/util/BitSet.h>
 
 

+ 0 - 0
src/anki/gr/common/ClassGpuAllocator.h → src/anki/gr/utils/ClassGpuAllocator.h


+ 2 - 2
src/anki/gr/common/FrameGpuAllocator.cpp → src/anki/gr/utils/FrameGpuAllocator.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/common/FrameGpuAllocator.h>
+#include <anki/gr/utils/FrameGpuAllocator.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -90,4 +90,4 @@ PtrSize FrameGpuAllocator::getUnallocatedMemorySize() const
 }
 }
 #endif
 #endif
 
 
-} // end namespace anki
+} // end namespace anki

+ 0 - 0
src/anki/gr/common/FrameGpuAllocator.h → src/anki/gr/utils/FrameGpuAllocator.h


+ 1 - 1
src/anki/gr/Shader.cpp → src/anki/gr/utils/Functions.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/Shader.h>
+#include <anki/gr/utils/Functions.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 88 - 0
src/anki/gr/utils/Functions.h

@@ -0,0 +1,88 @@
+// Copyright (C) 2009-2019, 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/Math.h>
+
+namespace anki
+{
+
+inline Bool stencilTestDisabled(StencilOperation stencilFail,
+	StencilOperation stencilPassDepthFail,
+	StencilOperation stencilPassDepthPass,
+	CompareOperation compare)
+{
+	return stencilFail == StencilOperation::KEEP && stencilPassDepthFail == StencilOperation::KEEP
+		   && stencilPassDepthPass == StencilOperation::KEEP && compare == CompareOperation::ALWAYS;
+}
+
+inline Bool blendingDisabled(BlendFactor srcFactorRgb,
+	BlendFactor dstFactorRgb,
+	BlendFactor srcFactorA,
+	BlendFactor dstFactorA,
+	BlendOperation opRgb,
+	BlendOperation opA)
+{
+	Bool dontWantBlend = srcFactorRgb == BlendFactor::ONE && dstFactorRgb == BlendFactor::ZERO
+						 && srcFactorA == BlendFactor::ONE && dstFactorA == BlendFactor::ZERO
+						 && (opRgb == BlendOperation::ADD || opRgb == BlendOperation::SUBTRACT)
+						 && (opA == BlendOperation::ADD || opA == BlendOperation::SUBTRACT);
+	return dontWantBlend;
+}
+
+/// Using an AnKi typename get the ShaderVariableDataType. Used for debugging.
+template<typename T>
+ShaderVariableDataType getShaderVariableTypeFromTypename();
+
+#define ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(typename_, type_) \
+	template<> \
+	inline ShaderVariableDataType getShaderVariableTypeFromTypename<typename_>() \
+	{ \
+		return ShaderVariableDataType::type_; \
+	}
+
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(I32, INT)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec2, IVEC2)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec3, IVEC3)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(IVec4, IVEC4)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(U32, UINT)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec2, UVEC2)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec3, UVEC3)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(UVec4, UVEC4)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(F32, FLOAT)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec2, VEC2)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec3, VEC3)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Vec4, VEC4)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Mat3, MAT3)
+ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(Mat4, MAT4)
+
+#undef ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET
+
+/// Shader block information.
+class ShaderVariableBlockInfo
+{
+public:
+	I16 m_offset = -1; ///< Offset inside the block
+
+	I16 m_arraySize = -1; ///< Number of elements.
+
+	/// Stride between the each array element if the variable is array.
+	I16 m_arrayStride = -1;
+
+	/// Identifying the stride between columns of a column-major matrix or rows of a row-major matrix.
+	I16 m_matrixStride = -1;
+};
+
+/// Populate the memory of a variable that is inside a shader block.
+void writeShaderBlockMemory(ShaderVariableDataType type,
+	const ShaderVariableBlockInfo& varBlkInfo,
+	const void* elements,
+	U32 elementsCount,
+	void* buffBegin,
+	const void* buffEnd);
+
+} // end namespace anki

+ 0 - 0
src/anki/gr/common/InstantiationMacros.h → src/anki/gr/utils/InstantiationMacros.h


+ 1 - 1
src/anki/gr/common/StackGpuAllocator.cpp → src/anki/gr/utils/StackGpuAllocator.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/common/StackGpuAllocator.h>
+#include <anki/gr/utils/StackGpuAllocator.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 0 - 0
src/anki/gr/common/StackGpuAllocator.h → src/anki/gr/utils/StackGpuAllocator.h


+ 1 - 1
src/anki/gr/vulkan/GpuMemoryManager.h

@@ -5,7 +5,7 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <anki/gr/common/ClassGpuAllocator.h>
+#include <anki/gr/utils/ClassGpuAllocator.h>
 #include <anki/gr/vulkan/Common.h>
 #include <anki/gr/vulkan/Common.h>
 
 
 namespace anki
 namespace anki

+ 1 - 1
src/anki/gr/vulkan/Pipeline.cpp

@@ -5,7 +5,7 @@
 
 
 #include <anki/gr/vulkan/Pipeline.h>
 #include <anki/gr/vulkan/Pipeline.h>
 #include <anki/gr/vulkan/GrManagerImpl.h>
 #include <anki/gr/vulkan/GrManagerImpl.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 #include <anki/util/Tracer.h>
 #include <anki/util/Tracer.h>
 
 
 namespace anki
 namespace anki

+ 1 - 1
src/anki/gr/vulkan/ShaderImpl.cpp

@@ -5,7 +5,7 @@
 
 
 #include <anki/gr/vulkan/ShaderImpl.h>
 #include <anki/gr/vulkan/ShaderImpl.h>
 #include <anki/gr/vulkan/GrManagerImpl.h>
 #include <anki/gr/vulkan/GrManagerImpl.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 #include <SPIRV-Cross/spirv_cross.hpp>
 #include <SPIRV-Cross/spirv_cross.hpp>
 
 
 #define ANKI_DUMP_SHADERS ANKI_EXTRA_CHECKS
 #define ANKI_DUMP_SHADERS ANKI_EXTRA_CHECKS

+ 1 - 1
src/anki/gr/vulkan/TextureImpl.cpp

@@ -9,7 +9,7 @@
 #include <anki/gr/vulkan/GrManagerImpl.h>
 #include <anki/gr/vulkan/GrManagerImpl.h>
 #include <anki/gr/CommandBuffer.h>
 #include <anki/gr/CommandBuffer.h>
 #include <anki/gr/vulkan/CommandBufferImpl.h>
 #include <anki/gr/vulkan/CommandBufferImpl.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 
 
 namespace anki
 namespace anki
 {
 {

+ 1 - 1
src/anki/gr/vulkan/TextureImpl.h

@@ -8,7 +8,7 @@
 #include <anki/gr/Texture.h>
 #include <anki/gr/Texture.h>
 #include <anki/gr/vulkan/VulkanObject.h>
 #include <anki/gr/vulkan/VulkanObject.h>
 #include <anki/gr/vulkan/GpuMemoryManager.h>
 #include <anki/gr/vulkan/GpuMemoryManager.h>
-#include <anki/gr/common/Misc.h>
+#include <anki/gr/utils/Functions.h>
 #include <anki/gr/vulkan/SamplerFactory.h>
 #include <anki/gr/vulkan/SamplerFactory.h>
 #include <anki/util/HashMap.h>
 #include <anki/util/HashMap.h>
 
 

+ 1 - 1
src/anki/gr/vulkan/VulkanObject.cpp

@@ -39,7 +39,7 @@ namespace anki
 	}
 	}
 
 
 #define ANKI_INSTANTIATE_GR_OBJECT_DELIMITER()
 #define ANKI_INSTANTIATE_GR_OBJECT_DELIMITER()
-#include <anki/gr/common/InstantiationMacros.h>
+#include <anki/gr/utils/InstantiationMacros.h>
 #undef ANKI_INSTANTIATE_GR_OBJECT_DELIMITER
 #undef ANKI_INSTANTIATE_GR_OBJECT_DELIMITER
 #undef ANKI_INSTANTIATE_GR_OBJECT
 #undef ANKI_INSTANTIATE_GR_OBJECT
 
 

+ 1 - 1
src/anki/gr/vulkan/VulkanObject.h

@@ -34,7 +34,7 @@ public:
 	template<> \
 	template<> \
 	const GrManagerImpl& VulkanObject<type_, type_##Impl>::getGrManagerImpl() const;
 	const GrManagerImpl& VulkanObject<type_, type_##Impl>::getGrManagerImpl() const;
 #define ANKI_INSTANTIATE_GR_OBJECT_DELIMITER()
 #define ANKI_INSTANTIATE_GR_OBJECT_DELIMITER()
-#include <anki/gr/common/InstantiationMacros.h>
+#include <anki/gr/utils/InstantiationMacros.h>
 #undef ANKI_INSTANTIATE_GR_OBJECT_DELIMITER
 #undef ANKI_INSTANTIATE_GR_OBJECT_DELIMITER
 #undef ANKI_INSTANTIATE_GR_OBJECT
 #undef ANKI_INSTANTIATE_GR_OBJECT
 /// @}
 /// @}

+ 1 - 1
src/anki/resource/TransferGpuAllocator.h

@@ -6,7 +6,7 @@
 #pragma once
 #pragma once
 
 
 #include <anki/resource/Common.h>
 #include <anki/resource/Common.h>
-#include <anki/gr/common/StackGpuAllocator.h>
+#include <anki/gr/utils/StackGpuAllocator.h>
 #include <anki/util/List.h>
 #include <anki/util/List.h>
 
 
 namespace anki
 namespace anki

+ 1 - 1
tests/gr/ClassGpuAllocator.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/common/ClassGpuAllocator.h>
+#include <anki/gr/utils/ClassGpuAllocator.h>
 #include <tests/framework/Framework.h>
 #include <tests/framework/Framework.h>
 #include <random>
 #include <random>
 #include <algorithm>
 #include <algorithm>

+ 1 - 1
tests/gr/StackGpuAllocator.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#include <anki/gr/common/StackGpuAllocator.h>
+#include <anki/gr/utils/StackGpuAllocator.h>
 #include <anki/util/ThreadHive.h>
 #include <anki/util/ThreadHive.h>
 #include <tests/framework/Framework.h>
 #include <tests/framework/Framework.h>
 #include <algorithm>
 #include <algorithm>

+ 1 - 1
tests/util/HashMap.cpp

@@ -145,7 +145,7 @@ ANKI_TEST(Util, HashMap)
 		using AkMap = HashMap<int, int, Hasher>;
 		using AkMap = HashMap<int, int, Hasher>;
 		AkMap akMap(128, 32, 0.9f);
 		AkMap akMap(128, 32, 0.9f);
 		using StlMap =
 		using StlMap =
-			std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
+			std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<const int, int>>>;
 		StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), alloc);
 		StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), alloc);
 
 
 		std::unordered_map<int, int> tmpMap;
 		std::unordered_map<int, int> tmpMap;

+ 3 - 2
tests/util/SparseArray.cpp

@@ -202,7 +202,7 @@ ANKI_TEST(Util, SparseArray)
 		const U MAX = 10000;
 		const U MAX = 10000;
 		SparseArray<SAFoo, U64> arr;
 		SparseArray<SAFoo, U64> arr;
 		using StlMap =
 		using StlMap =
-			std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
+			std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<const int, int>>>;
 		StlMap map(10, std::hash<int>(), std::equal_to<int>(), alloc);
 		StlMap map(10, std::hash<int>(), std::equal_to<int>(), alloc);
 
 
 		for(U i = 0; i < MAX; ++i)
 		for(U i = 0; i < MAX; ++i)
@@ -320,7 +320,8 @@ ANKI_TEST(Util, SparseArrayBench)
 	HeapAllocator<U8> allocStl(allocAlignedStl, nullptr);
 	HeapAllocator<U8> allocStl(allocAlignedStl, nullptr);
 	HeapAllocator<U8> allocTml(allocAligned, nullptr);
 	HeapAllocator<U8> allocTml(allocAligned, nullptr);
 
 
-	using StlMap = std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
+	using StlMap =
+		std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<const int, int>>>;
 	StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), allocStl);
 	StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), allocStl);
 
 
 	using AkMap = SparseArray<int, U32>;
 	using AkMap = SparseArray<int, U32>;