瀏覽代碼

Improve and optimize SSAO. Fix dist calculation in visibility tests. Change the code format a bit

Panagiotis Christopoulos Charitos 8 年之前
父節點
當前提交
99bf099800

+ 1 - 1
.clang-format

@@ -5,7 +5,7 @@ AccessModifierOffset: -4
 AlignAfterOpenBracket: DontAlign
 AlignAfterOpenBracket: DontAlign
 AlignConsecutiveAssignments: false
 AlignConsecutiveAssignments: false
 AlignConsecutiveDeclarations: false
 AlignConsecutiveDeclarations: false
-AlignEscapedNewlinesLeft: false
+AlignEscapedNewlinesLeft: true
 AlignOperands:   false
 AlignOperands:   false
 AlignTrailingComments: false
 AlignTrailingComments: false
 AllowAllParametersOfDeclarationOnNextLine: true
 AllowAllParametersOfDeclarationOnNextLine: true

+ 100 - 0
programs/DepthAwareBlur.ankiprog

@@ -0,0 +1,100 @@
+<!-- 
+Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
+All rights reserved.
+Code licensed under the BSD License.
+http://www.anki3d.org/LICENSE
+-->
+<shaderProgram>
+	<mutators>
+		<mutator name="HORIZONTAL" values="0 1"/>
+		<mutator name="KERNEL_SIZE" values="3 5 7 9 11 13 15"/>
+		<mutator name="COLOR_COMPONENTS" values="4 3 1"/>
+	</mutators>
+
+	<shaders>
+		<shader type="vert">
+			<source><![CDATA[
+#include "shaders/Quad.vert.glsl"
+			]]></source>
+		</shader>
+
+		<shader type="frag">
+			<inputs>
+				<input name="TEXTURE_SIZE" type="uvec2" const="1"/>
+			</inputs>
+
+			<source><![CDATA[
+#include "shaders/GaussianBlurCommon.glsl"
+#include "shaders/Tonemapping.glsl"
+#include "shaders/Functions.glsl"
+
+// Determine color type
+#if COLOR_COMPONENTS == 4
+#	define COL_TYPE vec4
+#	define TEX_FETCH rgba
+#elif COLOR_COMPONENTS == 3
+#	define COL_TYPE vec3
+#	define TEX_FETCH rgb
+#elif COLOR_COMPONENTS == 1
+#	define COL_TYPE float
+#	define TEX_FETCH r
+#else
+#	error See file
+#endif
+
+layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_tex; 
+layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_depthRt;
+
+layout(location = 0) in vec2 in_uv;
+
+layout(location = 0) out COL_TYPE out_color;
+
+float computeDepthWeight(float refDepth, float depth)
+{
+	float diff = abs(refDepth - depth);
+	float weight = 1.0 / (EPSILON + diff);
+	return sqrt(weight);
+}
+
+float readDepth(vec2 uv)
+{
+	return textureLod(u_depthRt, uv, 0.0).r;
+}
+
+void main()
+{
+#if HORIZONTAL
+	const vec2 TEXEL_SIZE = vec2(1.0 / float(TEXTURE_SIZE.x), 0.0);
+#else
+	const vec2 TEXEL_SIZE = vec2(0.0, 1.0 / float(TEXTURE_SIZE.y));
+#endif
+
+	out_color = texture(u_tex, in_uv).TEX_FETCH;
+	float refDepth = readDepth(in_uv);
+	float weight = 1.0;
+	vec2 texCoordOffset = 1.5 * TEXEL_SIZE;
+
+	for(uint i = 0u; i < STEP_COUNT; ++i)
+	{
+		vec2 uv = in_uv + texCoordOffset;
+		COL_TYPE col = texture(u_tex, uv).TEX_FETCH;
+		float w = computeDepthWeight(refDepth, readDepth(uv));
+		out_color += col * w;
+		weight += w;
+
+		uv = in_uv - texCoordOffset;
+		col = texture(u_tex, uv).TEX_FETCH;
+		w = computeDepthWeight(refDepth, readDepth(uv));
+		out_color += col * w;
+		weight += w;
+
+		texCoordOffset += 2.0 * TEXEL_SIZE;
+	}
+
+	out_color = out_color / weight;
+
+}
+			]]></source>
+		</shader>
+	</shaders>
+</shaderProgram>

+ 1 - 8
programs/Is.ankiprog

@@ -155,17 +155,10 @@ void main()
 
 
 	// Get world position
 	// Get world position
 	vec3 worldPos;
 	vec3 worldPos;
-	vec2 oldUv;
 	{
 	{
 		vec4 worldPos4 = u_invViewProjMat * vec4(ndc, UV_TO_NDC(depth), 1.0);
 		vec4 worldPos4 = u_invViewProjMat * vec4(ndc, UV_TO_NDC(depth), 1.0);
 		worldPos4 = worldPos4 / worldPos4.w;
 		worldPos4 = worldPos4 / worldPos4.w;
 		worldPos = worldPos4.xyz;
 		worldPos = worldPos4.xyz;
-
-		// Project to get old ndc
-		vec4 oldNdc4 = u_prevViewProjMat * vec4(worldPos, 1.0);
-		vec2 oldNdc = oldNdc4.xy / oldNdc4.w;
-
-		oldUv = NDC_TO_UV(oldNdc);
 	}
 	}
 
 
 	// Decode GBuffer
 	// Decode GBuffer
@@ -188,7 +181,7 @@ void main()
 	emission = gbuffer.emission;
 	emission = gbuffer.emission;
 
 
 	// Get SSAO
 	// Get SSAO
-	float ssao = texture(u_ssaoTex, oldUv).r;
+	float ssao = texture(u_ssaoTex, in_uv).r;
 	diffCol *= ssao;
 	diffCol *= ssao;
 
 
 	// Get counts and offsets
 	// Get counts and offsets

+ 0 - 3
programs/LumaAwareBlur.ankiprog

@@ -91,6 +91,3 @@ void main()
 		</shader>
 		</shader>
 	</shaders>
 	</shaders>
 </shaderProgram>
 </shaderProgram>
-
-
-

+ 12 - 11
programs/Ssao.ankiprog

@@ -108,10 +108,14 @@ void main(void)
 
 
 	// Compute the history blend. If clip falls outside NDC then it's 1.0 (use only current SSAO term) and if it's
 	// Compute the history blend. If clip falls outside NDC then it's 1.0 (use only current SSAO term) and if it's
 	// inside NDC then use the HISTORY_FEEDBACK value
 	// inside NDC then use the HISTORY_FEEDBACK value
+#if 0
 	vec2 posNdc = abs(clip.xy);
 	vec2 posNdc = abs(clip.xy);
 	float historyFeedback = max(posNdc.x, posNdc.y);
 	float historyFeedback = max(posNdc.x, posNdc.y);
 	historyFeedback = min(floor(historyFeedback), 1.0 - HISTORY_FEEDBACK);
 	historyFeedback = min(floor(historyFeedback), 1.0 - HISTORY_FEEDBACK);
 	historyFeedback += HISTORY_FEEDBACK;
 	historyFeedback += HISTORY_FEEDBACK;
+#else
+	const float historyFeedback = HISTORY_FEEDBACK;
+#endif
 
 
 	// Find the projected radius
 	// Find the projected radius
 	vec3 sphereLimit = origin + vec3(RADIUS, 0.0, 0.0);
 	vec3 sphereLimit = origin + vec3(RADIUS, 0.0, 0.0);
@@ -119,17 +123,14 @@ void main(void)
 	vec2 projSphereLimit2 = projSphereLimit.xy / projSphereLimit.w;
 	vec2 projSphereLimit2 = projSphereLimit.xy / projSphereLimit.w;
 	float projRadius = length(projSphereLimit2 - ndc);
 	float projRadius = length(projSphereLimit2 - ndc);
 
 
-	// Compute rand cos and sin
-	float randAng = randFactors[0] * PI * 2.0;
-	float cosAng = cos(randAng);
-	float sinAng = sin(randAng);
-
-	// Rotate the disk point
-	vec2 diskPoint = (randFactors.yz * 0.8 + 0.2) * projRadius;
-	vec2 rotDiskPoint;
-	rotDiskPoint.x = diskPoint.x * cosAng - diskPoint.y * sinAng;
-	rotDiskPoint.y = diskPoint.y * cosAng + diskPoint.x * sinAng;
-	vec2 finalDiskPoint = ndc + rotDiskPoint;
+	// Find a random point around the current NDC. Make sure that the sides fall inside the screen.
+#if 1
+	vec2 startXY = -in_uv; // range [0,-1]
+	startXY += randFactors.xy; // for the left side it's [0,1] for the center [0,0], right [-1,0]
+	vec2 finalDiskPoint = ndc + startXY * projRadius;
+#else
+	vec2 finalDiskPoint = ndc + (randFactors.xy - 0.5) * projRadius;
+#endif
 
 
 	// Compute factor
 	// Compute factor
 	vec3 s = readPosition(NDC_TO_UV(finalDiskPoint));
 	vec3 s = readPosition(NDC_TO_UV(finalDiskPoint));

+ 15 - 15
shaders/ClusterLightCommon.glsl

@@ -79,27 +79,27 @@ layout(ANKI_UBO_BINDING(LIGHT_SET, LIGHT_UBO_BINDING), std140, row_major) unifor
 #define u_time readFirstInvocationARB(u_lightingUniforms.rendererSizeTimePad1.z)
 #define u_time readFirstInvocationARB(u_lightingUniforms.rendererSizeTimePad1.z)
 #define u_unprojectionParams readFirstInvocationARB(u_lightingUniforms.projectionParams)
 #define u_unprojectionParams readFirstInvocationARB(u_lightingUniforms.projectionParams)
 
 
-#define u_invViewRotation                                                                                              \
-	mat3(readFirstInvocationARB(u_lightingUniforms.invViewRotation[0]),                                                \
-		readFirstInvocationARB(u_lightingUniforms.invViewRotation[1]),                                                 \
+#define u_invViewRotation                                               \
+	mat3(readFirstInvocationARB(u_lightingUniforms.invViewRotation[0]), \
+		readFirstInvocationARB(u_lightingUniforms.invViewRotation[1]),  \
 		readFirstInvocationARB(u_lightingUniforms.invViewRotation[2]))
 		readFirstInvocationARB(u_lightingUniforms.invViewRotation[2]))
 
 
-#define u_invProjMat                                                                                                   \
-	mat4(readFirstInvocationARB(u_lightingUniforms.invProjMat[0]),                                                     \
-		readFirstInvocationARB(u_lightingUniforms.invProjMat[1]),                                                      \
-		readFirstInvocationARB(u_lightingUniforms.invProjMat[2]),                                                      \
+#define u_invProjMat                                               \
+	mat4(readFirstInvocationARB(u_lightingUniforms.invProjMat[0]), \
+		readFirstInvocationARB(u_lightingUniforms.invProjMat[1]),  \
+		readFirstInvocationARB(u_lightingUniforms.invProjMat[2]),  \
 		readFirstInvocationARB(u_lightingUniforms.invProjMat[3]))
 		readFirstInvocationARB(u_lightingUniforms.invProjMat[3]))
 
 
-#define u_invViewProjMat                                                                                               \
-	mat4(readFirstInvocationARB(u_lightingUniforms.invViewProjMat[0]),                                                 \
-		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[1]),                                                  \
-		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[2]),                                                  \
+#define u_invViewProjMat                                               \
+	mat4(readFirstInvocationARB(u_lightingUniforms.invViewProjMat[0]), \
+		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[1]),  \
+		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[2]),  \
 		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[3]))
 		readFirstInvocationARB(u_lightingUniforms.invViewProjMat[3]))
 
 
-#define u_prevViewProjMat                                                                                              \
-	mat4(readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[0]),                                                \
-		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[1]),                                                 \
-		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[2]),                                                 \
+#define u_prevViewProjMat                                               \
+	mat4(readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[0]), \
+		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[1]),  \
+		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[2]),  \
 		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[3]))
 		readFirstInvocationARB(u_lightingUniforms.prevViewProjMat[3]))
 
 
 #else
 #else

+ 0 - 3
shaders/Final.frag.glsl

@@ -16,9 +16,6 @@ layout(location = 0) out vec3 out_color;
 void main()
 void main()
 {
 {
 	vec2 uv = in_texCoord;
 	vec2 uv = in_texCoord;
-#if ANKI_VK
-	uv.y = 1.0 - uv.y;
-#endif
 
 
 	vec3 col = textureLod(u_tex, uv, 0.0).rgb;
 	vec3 col = textureLod(u_tex, uv, 0.0).rgb;
 	out_color = col;
 	out_color = col;

+ 2 - 2
shaders/Functions.glsl

@@ -230,8 +230,8 @@ vec3 readErosion(sampler2D tex, vec2 uv)
 {
 {
 	vec3 minValue = textureLod(tex, uv, 0.0).rgb;
 	vec3 minValue = textureLod(tex, uv, 0.0).rgb;
 
 
-#define ANKI_EROSION(x, y)                                                                                             \
-	col2 = textureLodOffset(tex, uv, 0.0, ivec2(x, y)).rgb;                                                            \
+#define ANKI_EROSION(x, y)                                  \
+	col2 = textureLodOffset(tex, uv, 0.0, ivec2(x, y)).rgb; \
 	minValue = min(col2, minValue);
 	minValue = min(col2, minValue);
 
 
 	vec3 col2;
 	vec3 col2;

+ 21 - 0
src/anki/Config.h.cmake

@@ -8,6 +8,9 @@
 /// @addtogroup config
 /// @addtogroup config
 /// @{
 /// @{
 
 
+#define _ANKI_STR_HELPER(x) #x
+#define _ANKI_STR(x) _ANKI_STR_HELPER(x)
+
 #define ANKI_VERSION_MINOR ${ANKI_VERSION_MINOR}
 #define ANKI_VERSION_MINOR ${ANKI_VERSION_MINOR}
 #define ANKI_VERSION_MAJOR ${ANKI_VERSION_MAJOR}
 #define ANKI_VERSION_MAJOR ${ANKI_VERSION_MAJOR}
 #define ANKI_REVISION ${ANKI_REVISION}
 #define ANKI_REVISION ${ANKI_REVISION}
@@ -17,6 +20,24 @@
 #define ANKI_OPTIMIZE ${ANKI_OPTIMIZE}
 #define ANKI_OPTIMIZE ${ANKI_OPTIMIZE}
 #define ANKI_TESTS ${ANKI_TESTS}
 #define ANKI_TESTS ${ANKI_TESTS}
 
 
+// Compiler
+#define ANKI_COMPILER_CLANG 0
+#define ANKI_COMPILER_GCC 1
+#define ANKI_COMPILER_MSVC 2
+
+#if defined(__clang__)
+#	define ANKI_COMPILER ANKI_COMPILER_CLANG
+#	define ANKI_COMPILER_STR "clang " __VERSION__
+#elif defined(__GNUC__) || defined(__GNUG__)
+#	define ANKI_COMPILER ANKI_COMPILER_GCC
+#	define ANKI_COMPILER_STR "gcc " __VERSION__
+#elif defined(_MSC_VER)
+#	define ANKI_COMPILER ANKI_COMPILER_MSVC
+#	define ANKI_COMPILER_STR "MSVC " _ANKI_STR(_MSC_FULL_VER)
+#else
+#	error Unknown compiler
+#endif
+
 // Operating system
 // Operating system
 #define ANKI_OS_LINUX 1
 #define ANKI_OS_LINUX 1
 #define ANKI_OS_ANDROID 2
 #define ANKI_OS_ANDROID 2

+ 4 - 2
src/anki/core/App.cpp

@@ -169,11 +169,13 @@ Error App::initInternal(const ConfigSet& config_, AllocAlignedCallback allocCb,
 	ANKI_CORE_LOGI("Initializing application ("
 	ANKI_CORE_LOGI("Initializing application ("
 				   "version %u.%u, "
 				   "version %u.%u, "
 				   "%s, "
 				   "%s, "
-				   "date %s, "
-				   "commit %s)...",
+				   "compiler %s, "
+				   "build date %s, "
+				   "commit %s)",
 		ANKI_VERSION_MAJOR,
 		ANKI_VERSION_MAJOR,
 		ANKI_VERSION_MINOR,
 		ANKI_VERSION_MINOR,
 		buildType,
 		buildType,
+		ANKI_COMPILER_STR,
 		__DATE__,
 		__DATE__,
 		ANKI_REVISION);
 		ANKI_REVISION);
 
 

+ 4 - 4
src/anki/core/Trace.cpp

@@ -63,10 +63,10 @@ static Array<const char*, U(TraceCounterType::COUNT)> counterNames = {{"GR_DRAWC
 	"STAGING_UNIFORMS_SIZE",
 	"STAGING_UNIFORMS_SIZE",
 	"STAGING_STORAGE_SIZE"}};
 	"STAGING_STORAGE_SIZE"}};
 
 
-#define ANKI_TRACE_FILE_ERROR()                                                                                        \
-	if(err)                                                                                                            \
-	{                                                                                                                  \
-		ANKI_CORE_LOGE("Error writing the trace file");                                                                \
+#define ANKI_TRACE_FILE_ERROR()                         \
+	if(err)                                             \
+	{                                                   \
+		ANKI_CORE_LOGE("Error writing the trace file"); \
 	}
 	}
 
 
 const U MAX_EVENTS_DEPTH = 20;
 const U MAX_EVENTS_DEPTH = 20;

+ 7 - 7
src/anki/core/Trace.h

@@ -171,7 +171,7 @@ using TraceManagerSingleton = Singleton<TraceManager>;
 
 
 #define ANKI_TRACE_STOP_EVENT(name_) TraceManagerSingleton::get().stopEvent(TraceEventType::name_)
 #define ANKI_TRACE_STOP_EVENT(name_) TraceManagerSingleton::get().stopEvent(TraceEventType::name_)
 
 
-#define ANKI_TRACE_SCOPED_EVENT(name_)                                                                                 \
+#define ANKI_TRACE_SCOPED_EVENT(name_) \
 	ScopedTraceManagerEvent _tse##name_(&TraceManagerSingleton::get(), TraceEventType::name_)
 	ScopedTraceManagerEvent _tse##name_(&TraceManagerSingleton::get(), TraceEventType::name_)
 
 
 #define ANKI_TRACE_INC_COUNTER(name_, val_) TraceManagerSingleton::get().incCounter(TraceCounterType::name_, val_)
 #define ANKI_TRACE_INC_COUNTER(name_, val_) TraceManagerSingleton::get().incCounter(TraceCounterType::name_, val_)
@@ -191,12 +191,12 @@ using TraceManagerSingleton = Singleton<TraceManager>;
 
 
 #endif
 #endif
 
 
-#define ANKI_TRACE_START_STOP_EVENT(execute, event)                                                                    \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		ANKI_TRACE_START_EVENT(event);                                                                                 \
-		execute;                                                                                                       \
-		ANKI_TRACE_STOP_EVENT(event);                                                                                  \
+#define ANKI_TRACE_START_STOP_EVENT(execute, event) \
+	do                                              \
+	{                                               \
+		ANKI_TRACE_START_EVENT(event);              \
+		execute;                                    \
+		ANKI_TRACE_STOP_EVENT(event);               \
 	} while(0)
 	} while(0)
 /// @}
 /// @}
 
 

+ 9 - 9
src/anki/gr/Common.h

@@ -54,9 +54,9 @@ const U COMMAND_BUFFER_SMALL_BATCH_MAX_COMMANDS = 100;
 template<typename T>
 template<typename T>
 using GrObjectPtr = IntrusivePtr<T, DefaultPtrDeleter<T>>;
 using GrObjectPtr = IntrusivePtr<T, DefaultPtrDeleter<T>>;
 
 
-#define ANKI_GR_CLASS(x_)                                                                                              \
-	class x_##Impl;                                                                                                    \
-	class x_;                                                                                                          \
+#define ANKI_GR_CLASS(x_) \
+	class x_##Impl;       \
+	class x_;             \
 	using x_##Ptr = GrObjectPtr<x_>;
 	using x_##Ptr = GrObjectPtr<x_>;
 
 
 ANKI_GR_CLASS(Buffer)
 ANKI_GR_CLASS(Buffer)
@@ -71,12 +71,12 @@ ANKI_GR_CLASS(Fence)
 
 
 #undef ANKI_GR_CLASS
 #undef ANKI_GR_CLASS
 
 
-#define ANKI_GR_OBJECT                                                                                                 \
-	friend class GrManager;                                                                                            \
-	template<typename, typename>                                                                                       \
-	friend class IntrusivePtr;                                                                                         \
-	template<typename, typename>                                                                                       \
-	friend class GenericPoolAllocator;                                                                                 \
+#define ANKI_GR_OBJECT                 \
+	friend class GrManager;            \
+	template<typename, typename>       \
+	friend class IntrusivePtr;         \
+	template<typename, typename>       \
+	friend class GenericPoolAllocator; \
 	friend class GrObjectCache;
 	friend class GrObjectCache;
 
 
 /// Knowing the ventor allows some optimizations
 /// Knowing the ventor allows some optimizations

+ 5 - 5
src/anki/gr/Shader.h

@@ -18,11 +18,11 @@ namespace anki
 template<typename T>
 template<typename T>
 ShaderVariableDataType getShaderVariableTypeFromTypename();
 ShaderVariableDataType getShaderVariableTypeFromTypename();
 
 
-#define ANKI_SPECIALIZE_SHADER_VAR_TYPE_GET(typename_, type_)                                                          \
-	template<>                                                                                                         \
-	inline ShaderVariableDataType getShaderVariableTypeFromTypename<typename_>()                                       \
-	{                                                                                                                  \
-		return ShaderVariableDataType::type_;                                                                          \
+#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(I32, INT)

+ 7 - 7
src/anki/gr/common/Misc.cpp

@@ -49,13 +49,13 @@ void logShaderErrorCode(const CString& error, const CString& source, GenericMemo
 
 
 Bool textureInitInfoValid(const TextureInitInfo& inf)
 Bool textureInitInfoValid(const TextureInitInfo& inf)
 {
 {
-#define ANKI_CHECK_VAL_VALIDITY(x)                                                                                     \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if(!(x))                                                                                                       \
-		{                                                                                                              \
-			return false;                                                                                              \
-		}                                                                                                              \
+#define ANKI_CHECK_VAL_VALIDITY(x) \
+	do                             \
+	{                              \
+		if(!(x))                   \
+		{                          \
+			return false;          \
+		}                          \
 	} while(0)
 	} while(0)
 
 
 	ANKI_CHECK_VAL_VALIDITY(inf.m_usage != TextureUsageBit::NONE);
 	ANKI_CHECK_VAL_VALIDITY(inf.m_usage != TextureUsageBit::NONE);

+ 2 - 2
src/anki/gr/vulkan/CommandBufferImpl.h

@@ -27,8 +27,8 @@ class CommandBufferInitInfo;
 /// @addtogroup vulkan
 /// @addtogroup vulkan
 /// @{
 /// @{
 
 
-#define ANKI_CMD(x_, t_)                                                                                               \
-	flushBatches(CommandBufferCommandType::t_);                                                                        \
+#define ANKI_CMD(x_, t_)                        \
+	flushBatches(CommandBufferCommandType::t_); \
 	x_;
 	x_;
 
 
 /// List the commands that can be batched.
 /// List the commands that can be batched.

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

@@ -68,7 +68,7 @@ public:
 	}
 	}
 };
 };
 
 
-#define ANKI_FMT(fmt, trf, vk, as)                                                                                     \
+#define ANKI_FMT(fmt, trf, vk, as) \
 	ConvertFormat(PixelFormat(ComponentFormat::fmt, TransformFormat::trf), vk, Aspect::as)
 	ConvertFormat(PixelFormat(ComponentFormat::fmt, TransformFormat::trf), vk, Aspect::as)
 
 
 static const ConvertFormat CONVERT_FORMAT_TABLE[] = {ANKI_FMT(NONE, NONE, VK_FORMAT_R4G4_UNORM_PACK8, C),
 static const ConvertFormat CONVERT_FORMAT_TABLE[] = {ANKI_FMT(NONE, NONE, VK_FORMAT_R4G4_UNORM_PACK8, C),

+ 17 - 17
src/anki/gr/vulkan/Common.h

@@ -60,26 +60,26 @@ const U DESCRIPTOR_FRAME_BUFFERING = 60 * 5; ///< How many frames worth of descr
 /// @}
 /// @}
 
 
 /// Check if a vulkan function failed. It will abort on failure.
 /// Check if a vulkan function failed. It will abort on failure.
-#define ANKI_VK_CHECKF(x)                                                                                              \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		VkResult rez;                                                                                                  \
-		if((rez = (x)) < 0)                                                                                            \
-		{                                                                                                              \
-			ANKI_VK_LOGF("Vulkan function failed (VkResult: %d): %s", rez, #x);                                        \
-		}                                                                                                              \
+#define ANKI_VK_CHECKF(x)                                                       \
+	do                                                                          \
+	{                                                                           \
+		VkResult rez;                                                           \
+		if((rez = (x)) < 0)                                                     \
+		{                                                                       \
+			ANKI_VK_LOGF("Vulkan function failed (VkResult: %d): %s", rez, #x); \
+		}                                                                       \
 	} while(0)
 	} while(0)
 
 
 /// Check if a vulkan function failed.
 /// Check if a vulkan function failed.
-#define ANKI_VK_CHECK(x)                                                                                               \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		VkResult rez;                                                                                                  \
-		if((rez = (x)) < 0)                                                                                            \
-		{                                                                                                              \
-			ANKI_VK_LOGE("Vulkan function failed (VkResult: %d): %s", rez, #x);                                        \
-			return ErrorCode::FUNCTION_FAILED;                                                                         \
-		}                                                                                                              \
+#define ANKI_VK_CHECK(x)                                                        \
+	do                                                                          \
+	{                                                                           \
+		VkResult rez;                                                           \
+		if((rez = (x)) < 0)                                                     \
+		{                                                                       \
+			ANKI_VK_LOGE("Vulkan function failed (VkResult: %d): %s", rez, #x); \
+			return ErrorCode::FUNCTION_FAILED;                                  \
+		}                                                                       \
 	} while(0)
 	} while(0)
 
 
 /// Convert compare op.
 /// Convert compare op.

+ 10 - 10
src/anki/math/Functions.h

@@ -89,11 +89,11 @@ inline T mod(const T x, const T y)
 template<typename T>
 template<typename T>
 T absolute(const T f);
 T absolute(const T f);
 
 
-#define ANKI_SPECIALIZE_ABS(type_)                                                                                     \
-	template<>                                                                                                         \
-	inline type_ absolute(const type_ f)                                                                               \
-	{                                                                                                                  \
-		return (f < type_(0)) ? -f : f;                                                                                \
+#define ANKI_SPECIALIZE_ABS(type_)       \
+	template<>                           \
+	inline type_ absolute(const type_ f) \
+	{                                    \
+		return (f < type_(0)) ? -f : f;  \
 	}
 	}
 
 
 ANKI_SPECIALIZE_ABS(I8)
 ANKI_SPECIALIZE_ABS(I8)
@@ -111,11 +111,11 @@ inline Bool isZero(const T f)
 	return absolute<T>(f) < EPSILON;
 	return absolute<T>(f) < EPSILON;
 }
 }
 
 
-#define ANKI_SPECIALIZE_IS_ZERO_INT(type_)                                                                             \
-	template<>                                                                                                         \
-	inline Bool isZero(const type_ x)                                                                                  \
-	{                                                                                                                  \
-		return x == type_(0);                                                                                          \
+#define ANKI_SPECIALIZE_IS_ZERO_INT(type_) \
+	template<>                             \
+	inline Bool isZero(const type_ x)      \
+	{                                      \
+		return x == type_(0);              \
 	}
 	}
 
 
 ANKI_SPECIALIZE_IS_ZERO_INT(I8)
 ANKI_SPECIALIZE_IS_ZERO_INT(I8)

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

@@ -437,7 +437,7 @@ Error RenderableDrawer::drawSingle(DrawContext& ctx)
 	ctx.m_crntBuildInfo = !ctx.m_crntBuildInfo;
 	ctx.m_crntBuildInfo = !ctx.m_crntBuildInfo;
 
 
 	// Fill the crntBuild
 	// Fill the crntBuild
-	F32 flod = m_r->calculateLod(sqrt(ctx.m_visibleNode->m_frustumDistanceSquared));
+	F32 flod = m_r->calculateLod(ctx.m_visibleNode->m_frustumDistance);
 	flod = min<F32>(flod, MAX_LOD_COUNT - 1);
 	flod = min<F32>(flod, MAX_LOD_COUNT - 1);
 
 
 	crntBuild.m_rc = &renderable;
 	crntBuild.m_rc = &renderable;

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

@@ -160,8 +160,8 @@ 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->informTextureCurrentUsage(m_r->getSsao().getRt(), TextureUsageBit::SAMPLED_FRAGMENT);
+	cmdb->bindTexture(1, 4, m_r->getSsao().getRt());
 
 
 	cmdb->bindTexture(0, 0, m_r->getSm().m_spotTexArray);
 	cmdb->bindTexture(0, 0, m_r->getSm().m_spotTexArray);
 	cmdb->bindTexture(0, 1, m_r->getSm().m_omniTexArray);
 	cmdb->bindTexture(0, 1, m_r->getSm().m_omniTexArray);

+ 3 - 5
src/anki/renderer/Renderer.cpp

@@ -276,11 +276,10 @@ Error Renderer::render(RenderingContext& ctx)
 	m_ms->setPostRunBarriers(ctx);
 	m_ms->setPostRunBarriers(ctx);
 	m_sm->setPostRunBarriers(ctx);
 	m_sm->setPostRunBarriers(ctx);
 	m_depth->m_hd.setPreRunBarriers(ctx);
 	m_depth->m_hd.setPreRunBarriers(ctx);
-	m_is->setPreRunBarriers(ctx);
 
 
 	// Passes
 	// Passes
-	m_is->run(ctx);
 	m_depth->m_hd.run(ctx);
 	m_depth->m_hd.run(ctx);
+	m_lf->updateIndirectInfo(ctx, cmdb);
 
 
 	// Barriers
 	// Barriers
 	m_depth->m_hd.setPostRunBarriers(ctx);
 	m_depth->m_hd.setPostRunBarriers(ctx);
@@ -304,9 +303,6 @@ Error Renderer::render(RenderingContext& ctx)
 	m_ssao->m_main.setPostRunBarriers(ctx);
 	m_ssao->m_main.setPostRunBarriers(ctx);
 	m_ssao->m_hblur.setPreRunBarriers(ctx);
 	m_ssao->m_hblur.setPreRunBarriers(ctx);
 
 
-	// Misc
-	m_lf->updateIndirectInfo(ctx, cmdb);
-
 	// Passes
 	// Passes
 	m_vol->m_hblur.run(ctx);
 	m_vol->m_hblur.run(ctx);
 	m_ssao->m_hblur.run(ctx);
 	m_ssao->m_hblur.run(ctx);
@@ -324,9 +320,11 @@ Error Renderer::render(RenderingContext& ctx)
 	// Barriers
 	// Barriers
 	m_vol->m_vblur.setPostRunBarriers(ctx);
 	m_vol->m_vblur.setPostRunBarriers(ctx);
 	m_ssao->m_vblur.setPostRunBarriers(ctx);
 	m_ssao->m_vblur.setPostRunBarriers(ctx);
+	m_is->setPreRunBarriers(ctx);
 	m_fs->setPreRunBarriers(ctx);
 	m_fs->setPreRunBarriers(ctx);
 
 
 	// Passes
 	// Passes
+	m_is->run(ctx);
 	m_fs->run(ctx);
 	m_fs->run(ctx);
 
 
 	// Barriers
 	// Barriers

+ 49 - 66
src/anki/renderer/Ssao.cpp

@@ -17,37 +17,8 @@ namespace anki
 
 
 const PixelFormat Ssao::RT_PIXEL_FORMAT(ComponentFormat::R8, TransformFormat::UNORM);
 const PixelFormat Ssao::RT_PIXEL_FORMAT(ComponentFormat::R8, TransformFormat::UNORM);
 
 
-TexturePtr SsaoMain::getRt() const
-{
-	return m_rt[m_r->getFrameCount() & 1];
-}
-
-TexturePtr SsaoMain::getPreviousRt() const
-{
-	return m_rt[(m_r->getFrameCount() + 1) & 1];
-}
-
 Error SsaoMain::init(const ConfigSet& config)
 Error SsaoMain::init(const ConfigSet& config)
 {
 {
-	for(U i = 0; i < 2; ++i)
-	{
-		// RT
-		m_rt[i] = m_r->createAndClearRenderTarget(m_r->create2DRenderTargetInitInfo(m_ssao->m_width,
-			m_ssao->m_height,
-			Ssao::RT_PIXEL_FORMAT,
-			TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::CLEAR,
-			SamplingFilter::LINEAR,
-			1,
-			"ssaomain"));
-
-		// FB
-		FramebufferInitInfo fbInit("ssaomain");
-		fbInit.m_colorAttachmentCount = 1;
-		fbInit.m_colorAttachments[0].m_texture = m_rt[i];
-		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
-		m_fb[i] = getGrManager().newInstance<Framebuffer>(fbInit);
-	}
-
 	// Noise
 	// Noise
 	ANKI_CHECK(getResourceManager().loadResource("engine_data/BlueNoiseLdrRgb64x64.ankitex", m_noiseTex));
 	ANKI_CHECK(getResourceManager().loadResource("engine_data/BlueNoiseLdrRgb64x64.ankitex", m_noiseTex));
 
 
@@ -57,10 +28,10 @@ Error SsaoMain::init(const ConfigSet& config)
 	ShaderProgramResourceConstantValueInitList<6> consts(m_prog);
 	ShaderProgramResourceConstantValueInitList<6> consts(m_prog);
 	consts.add("NOISE_MAP_SIZE", U32(m_noiseTex->getWidth()))
 	consts.add("NOISE_MAP_SIZE", U32(m_noiseTex->getWidth()))
 		.add("FB_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height))
 		.add("FB_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height))
-		.add("RADIUS", F32(HEMISPHERE_RADIUS))
-		.add("BIAS", F32(0.3))
-		.add("STRENGTH", F32(3.0))
-		.add("HISTORY_FEEDBACK", F32(1.0f / 8.0f));
+		.add("RADIUS", 2.0f)
+		.add("BIAS", 0.0f)
+		.add("STRENGTH", 2.0f)
+		.add("HISTORY_FEEDBACK", 1.0f / 4.0f);
 	const ShaderProgramResourceVariant* variant;
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(consts.get(), variant);
 	m_prog->getOrCreateVariant(consts.get(), variant);
 	m_grProg = variant->getProgram();
 	m_grProg = variant->getProgram();
@@ -70,7 +41,7 @@ Error SsaoMain::init(const ConfigSet& config)
 
 
 void SsaoMain::setPreRunBarriers(RenderingContext& ctx)
 void SsaoMain::setPreRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_rt[m_r->getFrameCount() & 1],
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[m_r->getFrameCount() & 1],
 		TextureUsageBit::NONE,
 		TextureUsageBit::NONE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureSurfaceInfo(0, 0, 0, 0));
 		TextureSurfaceInfo(0, 0, 0, 0));
@@ -80,14 +51,14 @@ void SsaoMain::run(RenderingContext& ctx)
 {
 {
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 
 
-	cmdb->beginRenderPass(m_fb[m_r->getFrameCount() & 1]);
+	cmdb->beginRenderPass(m_ssao->m_fb[m_r->getFrameCount() & 1]);
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
 
 
 	cmdb->bindTexture(0, 0, m_r->getDepthDownscale().m_qd.m_depthRt);
 	cmdb->bindTexture(0, 0, m_r->getDepthDownscale().m_qd.m_depthRt);
 	cmdb->bindTextureAndSampler(0, 1, m_r->getMs().m_rt2, m_r->getLinearSampler());
 	cmdb->bindTextureAndSampler(0, 1, m_r->getMs().m_rt2, m_r->getLinearSampler());
 	cmdb->bindTexture(0, 2, m_noiseTex->getGrTexture());
 	cmdb->bindTexture(0, 2, m_noiseTex->getGrTexture());
-	cmdb->bindTexture(0, 3, m_rt[(m_r->getFrameCount() + 1) & 1]);
+	cmdb->bindTexture(0, 3, m_ssao->m_rt[(m_r->getFrameCount() + 1) & 1]);
 
 
 	struct Unis
 	struct Unis
 	{
 	{
@@ -110,7 +81,7 @@ void SsaoMain::run(RenderingContext& ctx)
 
 
 void SsaoMain::setPostRunBarriers(RenderingContext& ctx)
 void SsaoMain::setPostRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_rt[m_r->getFrameCount() & 1],
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[m_r->getFrameCount() & 1],
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureSurfaceInfo(0, 0, 0, 0));
 		TextureSurfaceInfo(0, 0, 0, 0));
@@ -118,27 +89,11 @@ void SsaoMain::setPostRunBarriers(RenderingContext& ctx)
 
 
 Error SsaoHBlur::init(const ConfigSet& config)
 Error SsaoHBlur::init(const ConfigSet& config)
 {
 {
-	// RT
-	m_rt = m_r->createAndClearRenderTarget(m_r->create2DRenderTargetInitInfo(m_ssao->m_width,
-		m_ssao->m_height,
-		Ssao::RT_PIXEL_FORMAT,
-		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
-		SamplingFilter::LINEAR,
-		1,
-		"ssaoblur"));
-
-	// FB
-	FramebufferInitInfo fbInit("ssaoblur");
-	fbInit.m_colorAttachmentCount = 1;
-	fbInit.m_colorAttachments[0].m_texture = m_rt;
-	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
-	m_fb = getGrManager().newInstance<Framebuffer>(fbInit);
-
 	// shader
 	// shader
-	ANKI_CHECK(m_r->getResourceManager().loadResource("programs/GaussianBlur.ankiprog", m_prog));
+	ANKI_CHECK(m_r->getResourceManager().loadResource("programs/DepthAwareBlur.ankiprog", m_prog));
 
 
 	ShaderProgramResourceMutationInitList<3> mutators(m_prog);
 	ShaderProgramResourceMutationInitList<3> mutators(m_prog);
-	mutators.add("HORIZONTAL", 1).add("KERNEL_SIZE", 9).add("COLOR_COMPONENTS", 1);
+	mutators.add("HORIZONTAL", 1).add("KERNEL_SIZE", 7).add("COLOR_COMPONENTS", 1);
 	ShaderProgramResourceConstantValueInitList<1> consts(m_prog);
 	ShaderProgramResourceConstantValueInitList<1> consts(m_prog);
 	consts.add("TEXTURE_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height));
 	consts.add("TEXTURE_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height));
 
 
@@ -152,8 +107,10 @@ Error SsaoHBlur::init(const ConfigSet& config)
 
 
 void SsaoHBlur::setPreRunBarriers(RenderingContext& ctx)
 void SsaoHBlur::setPreRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(
-		m_rt, TextureUsageBit::NONE, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE, TextureSurfaceInfo(0, 0, 0, 0));
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[(m_r->getFrameCount() + 1) & 1],
+		TextureUsageBit::NONE,
+		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
+		TextureSurfaceInfo(0, 0, 0, 0));
 }
 }
 
 
 void SsaoHBlur::run(RenderingContext& ctx)
 void SsaoHBlur::run(RenderingContext& ctx)
@@ -161,16 +118,17 @@ void SsaoHBlur::run(RenderingContext& ctx)
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 
 
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
-	cmdb->beginRenderPass(m_fb);
+	cmdb->beginRenderPass(m_ssao->m_fb[(m_r->getFrameCount() + 1) & 1]);
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
-	cmdb->bindTexture(0, 0, m_ssao->m_main.m_rt[m_r->getFrameCount() & 1]);
+	cmdb->bindTexture(0, 0, m_ssao->m_rt[m_r->getFrameCount() & 1]);
+	cmdb->bindTexture(0, 1, m_r->getDepthDownscale().m_qd.m_depthRt);
 	m_r->drawQuad(cmdb);
 	m_r->drawQuad(cmdb);
 	cmdb->endRenderPass();
 	cmdb->endRenderPass();
 }
 }
 
 
 void SsaoHBlur::setPostRunBarriers(RenderingContext& ctx)
 void SsaoHBlur::setPostRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_rt,
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[(m_r->getFrameCount() + 1) & 1],
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureSurfaceInfo(0, 0, 0, 0));
 		TextureSurfaceInfo(0, 0, 0, 0));
@@ -179,10 +137,10 @@ void SsaoHBlur::setPostRunBarriers(RenderingContext& ctx)
 Error SsaoVBlur::init(const ConfigSet& config)
 Error SsaoVBlur::init(const ConfigSet& config)
 {
 {
 	// shader
 	// shader
-	ANKI_CHECK(m_r->getResourceManager().loadResource("programs/GaussianBlur.ankiprog", m_prog));
+	ANKI_CHECK(m_r->getResourceManager().loadResource("programs/DepthAwareBlur.ankiprog", m_prog));
 
 
 	ShaderProgramResourceMutationInitList<3> mutators(m_prog);
 	ShaderProgramResourceMutationInitList<3> mutators(m_prog);
-	mutators.add("HORIZONTAL", 0).add("KERNEL_SIZE", 9).add("COLOR_COMPONENTS", 1);
+	mutators.add("HORIZONTAL", 0).add("KERNEL_SIZE", 7).add("COLOR_COMPONENTS", 1);
 	ShaderProgramResourceConstantValueInitList<1> consts(m_prog);
 	ShaderProgramResourceConstantValueInitList<1> consts(m_prog);
 	consts.add("TEXTURE_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height));
 	consts.add("TEXTURE_SIZE", UVec2(m_ssao->m_width, m_ssao->m_height));
 
 
@@ -196,7 +154,7 @@ Error SsaoVBlur::init(const ConfigSet& config)
 
 
 void SsaoVBlur::setPreRunBarriers(RenderingContext& ctx)
 void SsaoVBlur::setPreRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_main.m_rt[m_r->getFrameCount() & 1],
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[m_r->getFrameCount() & 1],
 		TextureUsageBit::NONE,
 		TextureUsageBit::NONE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureSurfaceInfo(0, 0, 0, 0));
 		TextureSurfaceInfo(0, 0, 0, 0));
@@ -207,16 +165,17 @@ void SsaoVBlur::run(RenderingContext& ctx)
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 	CommandBufferPtr& cmdb = ctx.m_commandBuffer;
 
 
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
 	cmdb->setViewport(0, 0, m_ssao->m_width, m_ssao->m_height);
-	cmdb->beginRenderPass(m_ssao->m_main.m_fb[m_r->getFrameCount() & 1]);
+	cmdb->beginRenderPass(m_ssao->m_fb[m_r->getFrameCount() & 1]);
 	cmdb->bindShaderProgram(m_grProg);
 	cmdb->bindShaderProgram(m_grProg);
-	cmdb->bindTexture(0, 0, m_ssao->m_hblur.m_rt);
+	cmdb->bindTexture(0, 0, m_ssao->m_rt[(m_r->getFrameCount() + 1) & 1]);
+	cmdb->bindTexture(0, 1, m_r->getDepthDownscale().m_qd.m_depthRt);
 	m_r->drawQuad(cmdb);
 	m_r->drawQuad(cmdb);
 	cmdb->endRenderPass();
 	cmdb->endRenderPass();
 }
 }
 
 
 void SsaoVBlur::setPostRunBarriers(RenderingContext& ctx)
 void SsaoVBlur::setPostRunBarriers(RenderingContext& ctx)
 {
 {
-	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_main.m_rt[m_r->getFrameCount() & 1],
+	ctx.m_commandBuffer->setTextureSurfaceBarrier(m_ssao->m_rt[m_r->getFrameCount() & 1],
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureSurfaceInfo(0, 0, 0, 0));
 		TextureSurfaceInfo(0, 0, 0, 0));
@@ -229,6 +188,25 @@ Error Ssao::init(const ConfigSet& config)
 
 
 	ANKI_R_LOGI("Initializing SSAO. Size %ux%u", m_width, m_height);
 	ANKI_R_LOGI("Initializing SSAO. Size %ux%u", m_width, m_height);
 
 
+	for(U i = 0; i < 2; ++i)
+	{
+		// RT
+		m_rt[i] = m_r->createAndClearRenderTarget(m_r->create2DRenderTargetInitInfo(m_width,
+			m_height,
+			Ssao::RT_PIXEL_FORMAT,
+			TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::CLEAR,
+			SamplingFilter::LINEAR,
+			1,
+			"ssaomain"));
+
+		// FB
+		FramebufferInitInfo fbInit("ssaomain");
+		fbInit.m_colorAttachmentCount = 1;
+		fbInit.m_colorAttachments[0].m_texture = m_rt[i];
+		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
+		m_fb[i] = getGrManager().newInstance<Framebuffer>(fbInit);
+	}
+
 	Error err = m_main.init(config);
 	Error err = m_main.init(config);
 
 
 	if(!err)
 	if(!err)
@@ -249,4 +227,9 @@ Error Ssao::init(const ConfigSet& config)
 	return err;
 	return err;
 }
 }
 
 
+TexturePtr Ssao::getRt() const
+{
+	return m_rt[m_r->getFrameCount() & 1];
+}
+
 } // end namespace anki
 } // end namespace anki

+ 4 - 14
src/anki/renderer/Ssao.h

@@ -27,18 +27,12 @@ class SsaoMain : public RenderingPass
 	friend class SsaoHBlur;
 	friend class SsaoHBlur;
 
 
 anki_internal:
 anki_internal:
-	static constexpr F32 HEMISPHERE_RADIUS = 3.0; // In game units
-
 	SsaoMain(Renderer* r, Ssao* ssao)
 	SsaoMain(Renderer* r, Ssao* ssao)
 		: RenderingPass(r)
 		: RenderingPass(r)
 		, m_ssao(ssao)
 		, m_ssao(ssao)
 	{
 	{
 	}
 	}
 
 
-	TexturePtr getRt() const;
-
-	TexturePtr getPreviousRt() const;
-
 	ANKI_USE_RESULT Error init(const ConfigSet& config);
 	ANKI_USE_RESULT Error init(const ConfigSet& config);
 
 
 	void setPreRunBarriers(RenderingContext& ctx);
 	void setPreRunBarriers(RenderingContext& ctx);
@@ -50,8 +44,6 @@ anki_internal:
 private:
 private:
 	Ssao* m_ssao;
 	Ssao* m_ssao;
 
 
-	Array<TexturePtr, 2> m_rt;
-	Array<FramebufferPtr, 2> m_fb;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramPtr m_grProg;
 	ShaderProgramPtr m_grProg;
 	TextureResourcePtr m_noiseTex;
 	TextureResourcePtr m_noiseTex;
@@ -80,8 +72,6 @@ anki_internal:
 private:
 private:
 	Ssao* m_ssao;
 	Ssao* m_ssao;
 
 
-	TexturePtr m_rt;
-	FramebufferPtr m_fb;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramPtr m_grProg;
 	ShaderProgramPtr m_grProg;
 };
 };
@@ -135,13 +125,13 @@ anki_internal:
 
 
 	ANKI_USE_RESULT Error init(const ConfigSet& config);
 	ANKI_USE_RESULT Error init(const ConfigSet& config);
 
 
-	TexturePtr getRt() const
-	{
-		return m_main.getRt();
-	}
+	TexturePtr getRt() const;
 
 
 private:
 private:
 	U32 m_width, m_height;
 	U32 m_width, m_height;
+
+	Array<TexturePtr, 2> m_rt;
+	Array<FramebufferPtr, 2> m_fb;
 };
 };
 /// @}
 /// @}
 
 

+ 2 - 2
src/anki/resource/Common.h

@@ -59,8 +59,8 @@ template<typename T>
 using ResourcePtr = IntrusivePtr<T, ResourcePtrDeleter<T>>;
 using ResourcePtr = IntrusivePtr<T, ResourcePtrDeleter<T>>;
 
 
 // NOTE: Add resources in 3 places
 // NOTE: Add resources in 3 places
-#define ANKI_FORWARD(rsrc_, name_)                                                                                     \
-	class rsrc_;                                                                                                       \
+#define ANKI_FORWARD(rsrc_, name_) \
+	class rsrc_;                   \
 	using name_ = ResourcePtr<rsrc_>;
 	using name_ = ResourcePtr<rsrc_>;
 
 
 ANKI_FORWARD(Animation, AnimationResourcePtr)
 ANKI_FORWARD(Animation, AnimationResourcePtr)

+ 8 - 8
src/anki/resource/Material.h

@@ -93,14 +93,14 @@ protected:
 };
 };
 
 
 // Specialize the MaterialVariable::getValue
 // Specialize the MaterialVariable::getValue
-#define ANKI_SPECIALIZE_GET_VALUE(t_, var_, shaderType_)                                                               \
-	template<>                                                                                                         \
-	inline const t_& MaterialVariable::getValue<t_>() const                                                            \
-	{                                                                                                                  \
-		ANKI_ASSERT(m_input);                                                                                          \
-		ANKI_ASSERT(m_input->getShaderVariableDataType() == ShaderVariableDataType::shaderType_);                      \
-		ANKI_ASSERT(m_builtin == BuiltinMaterialVariableId::NONE);                                                     \
-		return var_;                                                                                                   \
+#define ANKI_SPECIALIZE_GET_VALUE(t_, var_, shaderType_)                                          \
+	template<>                                                                                    \
+	inline const t_& MaterialVariable::getValue<t_>() const                                       \
+	{                                                                                             \
+		ANKI_ASSERT(m_input);                                                                     \
+		ANKI_ASSERT(m_input->getShaderVariableDataType() == ShaderVariableDataType::shaderType_); \
+		ANKI_ASSERT(m_builtin == BuiltinMaterialVariableId::NONE);                                \
+		return var_;                                                                              \
 	}
 	}
 
 
 ANKI_SPECIALIZE_GET_VALUE(I32, m_int, INT)
 ANKI_SPECIALIZE_GET_VALUE(I32, m_int, INT)

+ 2 - 1
src/anki/scene/Visibility.cpp

@@ -353,7 +353,8 @@ void VisibilityTestTask::test(ThreadHive& hive)
 		visibleNode.m_node = &node;
 		visibleNode.m_node = &node;
 
 
 		// Compute distance from the frustum
 		// Compute distance from the frustum
-		visibleNode.m_frustumDistanceSquared = (sps[0].m_origin - testedFrc.getFrustumOrigin()).getLengthSquared();
+		const Plane& nearPlane = testedFrc.getFrustum().getPlanesWorldSpace()[FrustumPlaneType::NEAR];
+		visibleNode.m_frustumDistance = max(0.0f, sps[0].m_sp->getAabb().testPlane(nearPlane));
 
 
 		ANKI_ASSERT(count < MAX_U8);
 		ANKI_ASSERT(count < MAX_U8);
 		visibleNode.m_spatialsCount = count;
 		visibleNode.m_spatialsCount = count;

+ 2 - 2
src/anki/scene/Visibility.h

@@ -46,7 +46,7 @@ public:
 	/// An array of the visible spatials
 	/// An array of the visible spatials
 	U8* m_spatialIndices = nullptr;
 	U8* m_spatialIndices = nullptr;
 	/// Distance from the frustum component.
 	/// Distance from the frustum component.
-	F32 m_frustumDistanceSquared = 0.0;
+	F32 m_frustumDistance = 0.0;
 	U8 m_spatialsCount = 0;
 	U8 m_spatialsCount = 0;
 
 
 	VisibleNode()
 	VisibleNode()
@@ -62,7 +62,7 @@ public:
 	{
 	{
 		m_node = other.m_node;
 		m_node = other.m_node;
 		m_spatialIndices = other.m_spatialIndices;
 		m_spatialIndices = other.m_spatialIndices;
-		m_frustumDistanceSquared = other.m_frustumDistanceSquared;
+		m_frustumDistance = other.m_frustumDistance;
 		m_spatialsCount = other.m_spatialsCount;
 		m_spatialsCount = other.m_spatialsCount;
 		return *this;
 		return *this;
 	}
 	}

+ 2 - 2
src/anki/scene/VisibilityInternal.h

@@ -29,7 +29,7 @@ public:
 	Bool operator()(const VisibleNode& a, const VisibleNode& b)
 	Bool operator()(const VisibleNode& a, const VisibleNode& b)
 	{
 	{
 		ANKI_ASSERT(a.m_node && b.m_node);
 		ANKI_ASSERT(a.m_node && b.m_node);
-		return a.m_frustumDistanceSquared < b.m_frustumDistanceSquared;
+		return a.m_frustumDistance < b.m_frustumDistance;
 	}
 	}
 };
 };
 
 
@@ -39,7 +39,7 @@ public:
 	Bool operator()(const VisibleNode& a, const VisibleNode& b)
 	Bool operator()(const VisibleNode& a, const VisibleNode& b)
 	{
 	{
 		ANKI_ASSERT(a.m_node && b.m_node);
 		ANKI_ASSERT(a.m_node && b.m_node);
-		return a.m_frustumDistanceSquared > b.m_frustumDistanceSquared;
+		return a.m_frustumDistance > b.m_frustumDistance;
 	}
 	}
 };
 };
 
 

+ 2 - 2
src/anki/script/ScriptManager.cpp

@@ -31,8 +31,8 @@ Error ScriptManager::init(AllocAlignedCallback allocCb, void* allocCbData, Scene
 	// Wrap stuff
 	// Wrap stuff
 	lua_State* l = m_lua.getLuaState();
 	lua_State* l = m_lua.getLuaState();
 
 
-#define ANKI_SCRIPT_CALL_WRAP(x_)                                                                                      \
-	extern void wrapModule##x_(lua_State*);                                                                            \
+#define ANKI_SCRIPT_CALL_WRAP(x_)           \
+	extern void wrapModule##x_(lua_State*); \
 	wrapModule##x_(l);
 	wrapModule##x_(l);
 
 
 	ANKI_SCRIPT_CALL_WRAP(Math);
 	ANKI_SCRIPT_CALL_WRAP(Math);

+ 2 - 2
src/anki/ui/Common.h

@@ -24,8 +24,8 @@ class UiManager;
 
 
 using UiAllocator = HeapAllocator<U8>;
 using UiAllocator = HeapAllocator<U8>;
 
 
-#define ANKI_UI_OBJECT_FW(name_)                                                                                       \
-	class name_;                                                                                                       \
+#define ANKI_UI_OBJECT_FW(name_) \
+	class name_;                 \
 	using name_##Ptr = IntrusivePtr<name_>;
 	using name_##Ptr = IntrusivePtr<name_>;
 
 
 ANKI_UI_OBJECT_FW(Font)
 ANKI_UI_OBJECT_FW(Font)

+ 7 - 7
src/anki/util/Assert.h

@@ -20,13 +20,13 @@ void akassert(const char* exprTxt, const char* file, int line, const char* func)
 
 
 } // end namespace
 } // end namespace
 
 
-#define ANKI_ASSERT(x)                                                                                                 \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if(!(x))                                                                                                       \
-		{                                                                                                              \
-			anki::akassert(#x, ANKI_FILE, __LINE__, ANKI_FUNC);                                                        \
-		}                                                                                                              \
+#define ANKI_ASSERT(x)                                          \
+	do                                                          \
+	{                                                           \
+		if(!(x))                                                \
+		{                                                       \
+			anki::akassert(#x, ANKI_FILE, __LINE__, ANKI_FUNC); \
+		}                                                       \
 	} while(0)
 	} while(0)
 #define ANKI_ASSERTS_ENABLED 1
 #define ANKI_ASSERTS_ENABLED 1
 
 

+ 55 - 55
src/anki/util/Enum.h

@@ -24,73 +24,73 @@ constexpr inline typename EnumUnderlyingType<TEnum>::Type enumToType(TEnum e)
 	return static_cast<typename EnumUnderlyingType<TEnum>::Type>(e);
 	return static_cast<typename EnumUnderlyingType<TEnum>::Type>(e);
 }
 }
 
 
-#define _ANKI_ENUM_OPERATOR(enum_, qualifier_, operator_, selfOperator_)                                               \
-	constexpr qualifier_ enum_ operator operator_(const enum_ a, const enum_ b)                                        \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		return static_cast<enum_>(static_cast<Int>(a) operator_ static_cast<Int>(b));                                  \
-	}                                                                                                                  \
-	constexpr qualifier_ enum_ operator operator_(const enum_ a, const EnumUnderlyingType<enum_>::Type b)              \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		return static_cast<enum_>(static_cast<Int>(a) operator_ b);                                                    \
-	}                                                                                                                  \
-	constexpr qualifier_ enum_ operator operator_(const EnumUnderlyingType<enum_>::Type a, const enum_ b)              \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		return static_cast<enum_>(a operator_ static_cast<Int>(b));                                                    \
-	}                                                                                                                  \
-	qualifier_ enum_& operator selfOperator_(enum_& a, const enum_ b)                                                  \
-	{                                                                                                                  \
-		a = a operator_ b;                                                                                             \
-		return a;                                                                                                      \
+#define _ANKI_ENUM_OPERATOR(enum_, qualifier_, operator_, selfOperator_)                                  \
+	constexpr qualifier_ enum_ operator operator_(const enum_ a, const enum_ b)                           \
+	{                                                                                                     \
+		using Int = EnumUnderlyingType<enum_>::Type;                                                      \
+		return static_cast<enum_>(static_cast<Int>(a) operator_ static_cast<Int>(b));                     \
+	}                                                                                                     \
+	constexpr qualifier_ enum_ operator operator_(const enum_ a, const EnumUnderlyingType<enum_>::Type b) \
+	{                                                                                                     \
+		using Int = EnumUnderlyingType<enum_>::Type;                                                      \
+		return static_cast<enum_>(static_cast<Int>(a) operator_ b);                                       \
+	}                                                                                                     \
+	constexpr qualifier_ enum_ operator operator_(const EnumUnderlyingType<enum_>::Type a, const enum_ b) \
+	{                                                                                                     \
+		using Int = EnumUnderlyingType<enum_>::Type;                                                      \
+		return static_cast<enum_>(a operator_ static_cast<Int>(b));                                       \
+	}                                                                                                     \
+	qualifier_ enum_& operator selfOperator_(enum_& a, const enum_ b)                                     \
+	{                                                                                                     \
+		a = a operator_ b;                                                                                \
+		return a;                                                                                         \
 	}
 	}
 
 
-#define _ANKI_ENUM_UNARAY_OPERATOR(enum_, qualifier_, operator_)                                                       \
-	constexpr qualifier_ enum_ operator operator_(const enum_ a)                                                       \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		return static_cast<enum_>(operator_ static_cast<Int>(a));                                                      \
+#define _ANKI_ENUM_UNARAY_OPERATOR(enum_, qualifier_, operator_)  \
+	constexpr qualifier_ enum_ operator operator_(const enum_ a)  \
+	{                                                             \
+		using Int = EnumUnderlyingType<enum_>::Type;              \
+		return static_cast<enum_>(operator_ static_cast<Int>(a)); \
 	}
 	}
 
 
-#define _ANKI_ENUM_INCREMENT_DECREMENT(enum_, qualifier_)                                                              \
-	qualifier_ enum_& operator++(enum_& a)                                                                             \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		a = static_cast<enum_>(static_cast<Int>(a) + 1);                                                               \
-		return a;                                                                                                      \
-	}                                                                                                                  \
-	qualifier_ enum_& operator--(enum_& a)                                                                             \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		a = static_cast<enum_>(static_cast<Int>(a) - 1);                                                               \
-		return a;                                                                                                      \
+#define _ANKI_ENUM_INCREMENT_DECREMENT(enum_, qualifier_) \
+	qualifier_ enum_& operator++(enum_& a)                \
+	{                                                     \
+		using Int = EnumUnderlyingType<enum_>::Type;      \
+		a = static_cast<enum_>(static_cast<Int>(a) + 1);  \
+		return a;                                         \
+	}                                                     \
+	qualifier_ enum_& operator--(enum_& a)                \
+	{                                                     \
+		using Int = EnumUnderlyingType<enum_>::Type;      \
+		a = static_cast<enum_>(static_cast<Int>(a) - 1);  \
+		return a;                                         \
 	}
 	}
 
 
-#define _ANKI_ENUM_NEGATIVE_OPERATOR(enum_, qualifier_)                                                                \
-	qualifier_ bool operator!(const enum_& a)                                                                          \
-	{                                                                                                                  \
-		using Int = EnumUnderlyingType<enum_>::Type;                                                                   \
-		return static_cast<Int>(a) == 0;                                                                               \
-	}                                                                                                                  \
+#define _ANKI_ENUM_NEGATIVE_OPERATOR(enum_, qualifier_) \
+	qualifier_ bool operator!(const enum_& a)           \
+	{                                                   \
+		using Int = EnumUnderlyingType<enum_>::Type;    \
+		return static_cast<Int>(a) == 0;                \
+	}                                                   \
 /// @}
 /// @}
 
 
 /// @addtogroup util_other
 /// @addtogroup util_other
 /// @{
 /// @{
 
 
 /// Implement all those functions that will make a stronly typed enum behave like the old type of enums.
 /// Implement all those functions that will make a stronly typed enum behave like the old type of enums.
-#define ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(enum_, qualifier_)                                                          \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, |, |=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, &, &=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, ^, ^=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, +, +=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, -, -=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, *, *=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, /, /=)                                                                      \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, <<, <<=)                                                                    \
-	_ANKI_ENUM_OPERATOR(enum_, qualifier_, >>, >>=)                                                                    \
-	_ANKI_ENUM_UNARAY_OPERATOR(enum_, qualifier_, ~)                                                                   \
-	_ANKI_ENUM_INCREMENT_DECREMENT(enum_, qualifier_)                                                                  \
+#define ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(enum_, qualifier_) \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, |, |=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, &, &=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, ^, ^=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, +, +=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, -, -=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, *, *=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, /, /=)             \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, <<, <<=)           \
+	_ANKI_ENUM_OPERATOR(enum_, qualifier_, >>, >>=)           \
+	_ANKI_ENUM_UNARAY_OPERATOR(enum_, qualifier_, ~)          \
+	_ANKI_ENUM_INCREMENT_DECREMENT(enum_, qualifier_)         \
 	_ANKI_ENUM_NEGATIVE_OPERATOR(enum_, qualifier_)
 	_ANKI_ENUM_NEGATIVE_OPERATOR(enum_, qualifier_)
 
 
 /// Convert enum to the underlying type.
 /// Convert enum to the underlying type.

+ 11 - 11
src/anki/util/Functions.h

@@ -187,17 +187,17 @@ struct TypesAreTheSame<T, T>
 template<typename T>
 template<typename T>
 void memorySet(T* dest, T value, const PtrSize count);
 void memorySet(T* dest, T value, const PtrSize count);
 
 
-#define ANKI_SPECIALISE_MEMORY_SET(T)                                                                                  \
-	template<>                                                                                                         \
-	inline void memorySet(T* dest, T value, const PtrSize count)                                                       \
-	{                                                                                                                  \
-		ANKI_ASSERT(dest);                                                                                             \
-		const T* end = dest + count;                                                                                   \
-		while(dest != end)                                                                                             \
-		{                                                                                                              \
-			memcpy(reinterpret_cast<char*>(dest), &value, sizeof(T));                                                  \
-			++dest;                                                                                                    \
-		}                                                                                                              \
+#define ANKI_SPECIALISE_MEMORY_SET(T)                                 \
+	template<>                                                        \
+	inline void memorySet(T* dest, T value, const PtrSize count)      \
+	{                                                                 \
+		ANKI_ASSERT(dest);                                            \
+		const T* end = dest + count;                                  \
+		while(dest != end)                                            \
+		{                                                             \
+			memcpy(reinterpret_cast<char*>(dest), &value, sizeof(T)); \
+			++dest;                                                   \
+		}                                                             \
 	}
 	}
 
 
 ANKI_SPECIALISE_MEMORY_SET(U8)
 ANKI_SPECIALISE_MEMORY_SET(U8)

+ 5 - 5
src/anki/util/Logger.h

@@ -96,11 +96,11 @@ private:
 
 
 typedef Singleton<Logger> LoggerSingleton;
 typedef Singleton<Logger> LoggerSingleton;
 
 
-#define ANKI_LOG(subsystem_, t, ...)                                                                                   \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		LoggerSingleton::get().writeFormated(                                                                          \
-			ANKI_FILE, __LINE__, ANKI_FUNC, subsystem_, Logger::MessageType::t, __VA_ARGS__);                          \
+#define ANKI_LOG(subsystem_, t, ...)                                                          \
+	do                                                                                        \
+	{                                                                                         \
+		LoggerSingleton::get().writeFormated(                                                 \
+			ANKI_FILE, __LINE__, ANKI_FUNC, subsystem_, Logger::MessageType::t, __VA_ARGS__); \
 	} while(false);
 	} while(false);
 /// @}
 /// @}
 
 

+ 15 - 15
src/anki/util/StdTypes.h

@@ -158,24 +158,24 @@ private:
 };
 };
 
 
 /// Macro to check if a method/function returned an error.
 /// Macro to check if a method/function returned an error.
-#define ANKI_CHECK(x_)                                                                                                 \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		Error error = x_;                                                                                              \
-		if(ANKI_UNLIKELY(error))                                                                                       \
-		{                                                                                                              \
-			return error;                                                                                              \
-		}                                                                                                              \
+#define ANKI_CHECK(x_)           \
+	do                           \
+	{                            \
+		Error error = x_;        \
+		if(ANKI_UNLIKELY(error)) \
+		{                        \
+			return error;        \
+		}                        \
 	} while(0)
 	} while(0)
 
 
 /// Macro the check if a memory allocation is OOM.
 /// Macro the check if a memory allocation is OOM.
-#define ANKI_CHECK_OOM(x_)                                                                                             \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if(ANKI_UNLIKELY(x_ == nullptr))                                                                               \
-		{                                                                                                              \
-			return ErrorCode::OUT_OF_MEMORY;                                                                           \
-		}                                                                                                              \
+#define ANKI_CHECK_OOM(x_)                   \
+	do                                       \
+	{                                        \
+		if(ANKI_UNLIKELY(x_ == nullptr))     \
+		{                                    \
+			return ErrorCode::OUT_OF_MEMORY; \
+		}                                    \
 	} while(0)
 	} while(0)
 
 
 /// Macro to nuliffy a pointer on debug builds.
 /// Macro to nuliffy a pointer on debug builds.

+ 5 - 5
src/anki/util/String.h

@@ -32,11 +32,11 @@ constexpr const char* toStringFormat()
 	return nullptr;
 	return nullptr;
 }
 }
 
 
-#define ANKI_DEPLOY_TO_STRING(type_, string_)                                                                          \
-	template<>                                                                                                         \
-	constexpr const char* toStringFormat<type_>()                                                                      \
-	{                                                                                                                  \
-		return string_;                                                                                                \
+#define ANKI_DEPLOY_TO_STRING(type_, string_)     \
+	template<>                                    \
+	constexpr const char* toStringFormat<type_>() \
+	{                                             \
+		return string_;                           \
 	}
 	}
 
 
 ANKI_DEPLOY_TO_STRING(I8, "%" PRId8)
 ANKI_DEPLOY_TO_STRING(I8, "%" PRId8)

+ 82 - 82
tests/framework/Framework.h

@@ -85,109 +85,109 @@ extern void deleteTesterSingleton();
 // Macros
 // Macros
 
 
 /// Create a new test and add it. It does a trick to add the test by using a static function
 /// Create a new test and add it. It does a trick to add the test by using a static function
-#define ANKI_TEST(suiteName_, name_)                                                                                   \
-	using namespace anki;                                                                                              \
-	void test_##suiteName_##name_(Test&);                                                                              \
-                                                                                                                       \
-	struct Foo##suiteName_##name_                                                                                      \
-	{                                                                                                                  \
-		Foo##suiteName_##name_()                                                                                       \
-		{                                                                                                              \
-			getTesterSingleton().addTest(#name_, #suiteName_, test_##suiteName_##name_);                               \
-		}                                                                                                              \
-	};                                                                                                                 \
-	static Foo##suiteName_##name_ yada##suiteName_##name_;                                                             \
+#define ANKI_TEST(suiteName_, name_)                                                     \
+	using namespace anki;                                                                \
+	void test_##suiteName_##name_(Test&);                                                \
+                                                                                         \
+	struct Foo##suiteName_##name_                                                        \
+	{                                                                                    \
+		Foo##suiteName_##name_()                                                         \
+		{                                                                                \
+			getTesterSingleton().addTest(#name_, #suiteName_, test_##suiteName_##name_); \
+		}                                                                                \
+	};                                                                                   \
+	static Foo##suiteName_##name_ yada##suiteName_##name_;                               \
 	void test_##suiteName_##name_(Test&)
 	void test_##suiteName_##name_(Test&)
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_EQ_IMPL(file_, line_, func_, x, y)                                                            \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) != (y))                                                                                                 \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " != " << #y << " (" << file_ << ":" << line_ << ")";                           \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_EQ_IMPL(file_, line_, func_, x, y)                                  \
+	do                                                                                       \
+	{                                                                                        \
+		if((x) != (y))                                                                       \
+		{                                                                                    \
+			std::stringstream ss;                                                            \
+			ss << "FAILURE: " << #x << " != " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                       \
+			abort();                                                                         \
+		}                                                                                    \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_NEQ_IMPL(file_, line_, func_, x, y)                                                           \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) == (y))                                                                                                 \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " == " << #y << " (" << file_ << ":" << line_ << ")";                           \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_NEQ_IMPL(file_, line_, func_, x, y)                                 \
+	do                                                                                       \
+	{                                                                                        \
+		if((x) == (y))                                                                       \
+		{                                                                                    \
+			std::stringstream ss;                                                            \
+			ss << "FAILURE: " << #x << " == " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                       \
+			abort();                                                                         \
+		}                                                                                    \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_GT_IMPL(file_, line_, func_, x, y)                                                            \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) <= (y))                                                                                                 \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " > " << #y << " (" << file_ << ":" << line_ << ")";                            \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_GT_IMPL(file_, line_, func_, x, y)                                 \
+	do                                                                                      \
+	{                                                                                       \
+		if((x) <= (y))                                                                      \
+		{                                                                                   \
+			std::stringstream ss;                                                           \
+			ss << "FAILURE: " << #x << " > " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                      \
+			abort();                                                                        \
+		}                                                                                   \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_GEQ_IMPL(file_, line_, func_, x, y)                                                           \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) < (y))                                                                                                  \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " >= " << #y << " (" << file_ << ":" << line_ << ")";                           \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_GEQ_IMPL(file_, line_, func_, x, y)                                 \
+	do                                                                                       \
+	{                                                                                        \
+		if((x) < (y))                                                                        \
+		{                                                                                    \
+			std::stringstream ss;                                                            \
+			ss << "FAILURE: " << #x << " >= " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                       \
+			abort();                                                                         \
+		}                                                                                    \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_LT_IMPL(file_, line_, func_, x, y)                                                            \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) >= (y))                                                                                                 \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " < " << #y << " (" << file_ << ":" << line_ << ")";                            \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_LT_IMPL(file_, line_, func_, x, y)                                 \
+	do                                                                                      \
+	{                                                                                       \
+		if((x) >= (y))                                                                      \
+		{                                                                                   \
+			std::stringstream ss;                                                           \
+			ss << "FAILURE: " << #x << " < " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                      \
+			abort();                                                                        \
+		}                                                                                   \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_LEQ_IMPL(file_, line_, func_, x, y)                                                           \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if((x) > (y))                                                                                                  \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " <= " << #y << " (" << file_ << ":" << line_ << ")";                           \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_LEQ_IMPL(file_, line_, func_, x, y)                                 \
+	do                                                                                       \
+	{                                                                                        \
+		if((x) > (y))                                                                        \
+		{                                                                                    \
+			std::stringstream ss;                                                            \
+			ss << "FAILURE: " << #x << " <= " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                       \
+			abort();                                                                         \
+		}                                                                                    \
 	} while(0);
 	} while(0);
 
 
 /// Intermediate macro
 /// Intermediate macro
-#define ANKI_TEST_EXPECT_NEAR_IMPL(file_, line_, func_, x, y, epsilon_)                                                \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		if(absolute((x) - (y)) > (epsilon_))                                                                           \
-		{                                                                                                              \
-			std::stringstream ss;                                                                                      \
-			ss << "FAILURE: " << #x << " != " << #y << " (" << file_ << ":" << line_ << ")";                           \
-			fprintf(stderr, "%s\n", ss.str().c_str());                                                                 \
-			abort();                                                                                                   \
-		}                                                                                                              \
+#define ANKI_TEST_EXPECT_NEAR_IMPL(file_, line_, func_, x, y, epsilon_)                      \
+	do                                                                                       \
+	{                                                                                        \
+		if(absolute((x) - (y)) > (epsilon_))                                                 \
+		{                                                                                    \
+			std::stringstream ss;                                                            \
+			ss << "FAILURE: " << #x << " != " << #y << " (" << file_ << ":" << line_ << ")"; \
+			fprintf(stderr, "%s\n", ss.str().c_str());                                       \
+			abort();                                                                         \
+		}                                                                                    \
 	} while(0);
 	} while(0);
 
 
 /// Macro to compare equal
 /// Macro to compare equal

+ 33 - 33
tests/gr/Gr.cpp

@@ -286,27 +286,27 @@ static NativeWindow* win = nullptr;
 static GrManager* gr = nullptr;
 static GrManager* gr = nullptr;
 static StagingGpuMemoryManager* stagingMem = nullptr;
 static StagingGpuMemoryManager* stagingMem = nullptr;
 
 
-#define COMMON_BEGIN()                                                                                                 \
-	stagingMem = new StagingGpuMemoryManager();                                                                        \
-	Config cfg;                                                                                                        \
-	cfg.set("width", WIDTH);                                                                                           \
-	cfg.set("height", HEIGHT);                                                                                         \
-	cfg.set("debugContext", true);                                                                                     \
-	cfg.set("vsync", false);                                                                                           \
-	win = createWindow(cfg);                                                                                           \
-	gr = createGrManager(cfg, win);                                                                                    \
-	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, Config()));                                                           \
-	TransferGpuAllocator transfAlloc;                                                                                  \
-	ANKI_TEST_EXPECT_NO_ERR(transfAlloc.init(128_MB, gr, gr->getAllocator()));                                         \
+#define COMMON_BEGIN()                                                         \
+	stagingMem = new StagingGpuMemoryManager();                                \
+	Config cfg;                                                                \
+	cfg.set("width", WIDTH);                                                   \
+	cfg.set("height", HEIGHT);                                                 \
+	cfg.set("debugContext", true);                                             \
+	cfg.set("vsync", false);                                                   \
+	win = createWindow(cfg);                                                   \
+	gr = createGrManager(cfg, win);                                            \
+	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, Config()));                   \
+	TransferGpuAllocator transfAlloc;                                          \
+	ANKI_TEST_EXPECT_NO_ERR(transfAlloc.init(128_MB, gr, gr->getAllocator())); \
 	{
 	{
 
 
-#define COMMON_END()                                                                                                   \
-	}                                                                                                                  \
-	delete stagingMem;                                                                                                 \
-	delete gr;                                                                                                         \
-	delete win;                                                                                                        \
-	win = nullptr;                                                                                                     \
-	gr = nullptr;                                                                                                      \
+#define COMMON_END()   \
+	}                  \
+	delete stagingMem; \
+	delete gr;         \
+	delete win;        \
+	win = nullptr;     \
+	gr = nullptr;      \
 	stagingMem = nullptr;
 	stagingMem = nullptr;
 
 
 static void* setUniforms(PtrSize size, CommandBufferPtr& cmdb, U set, U binding)
 static void* setUniforms(PtrSize size, CommandBufferPtr& cmdb, U set, U binding)
@@ -328,22 +328,22 @@ static void* setStorage(PtrSize size, CommandBufferPtr& cmdb, U set, U binding)
 #define SET_UNIFORMS(type_, size_, cmdb_, set_, binding_) static_cast<type_>(setUniforms(size_, cmdb_, set_, binding_))
 #define SET_UNIFORMS(type_, size_, cmdb_, set_, binding_) static_cast<type_>(setUniforms(size_, cmdb_, set_, binding_))
 #define SET_STORAGE(type_, size_, cmdb_, set_, binding_) static_cast<type_>(setStorage(size_, cmdb_, set_, binding_))
 #define SET_STORAGE(type_, size_, cmdb_, set_, binding_) static_cast<type_>(setStorage(size_, cmdb_, set_, binding_))
 
 
-#define UPLOAD_TEX_SURFACE(cmdb_, tex_, surf_, ptr_, size_, handle_)                                                   \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		ANKI_TEST_EXPECT_NO_ERR(transfAlloc.allocate(size_, handle_));                                                 \
-		void* f = handle_.getMappedMemory();                                                                           \
-		memcpy(f, ptr_, size_);                                                                                        \
-		cmdb_->copyBufferToTextureSurface(handle_.getBuffer(), handle_.getOffset(), handle_.getRange(), tex_, surf_);  \
+#define UPLOAD_TEX_SURFACE(cmdb_, tex_, surf_, ptr_, size_, handle_)                                                  \
+	do                                                                                                                \
+	{                                                                                                                 \
+		ANKI_TEST_EXPECT_NO_ERR(transfAlloc.allocate(size_, handle_));                                                \
+		void* f = handle_.getMappedMemory();                                                                          \
+		memcpy(f, ptr_, size_);                                                                                       \
+		cmdb_->copyBufferToTextureSurface(handle_.getBuffer(), handle_.getOffset(), handle_.getRange(), tex_, surf_); \
 	} while(0)
 	} while(0)
 
 
-#define UPLOAD_TEX_VOL(cmdb_, tex_, vol_, ptr_, size_, handle_)                                                        \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		ANKI_TEST_EXPECT_NO_ERR(transfAlloc.allocate(size_, handle_));                                                 \
-		void* f = handle_.getMappedMemory();                                                                           \
-		memcpy(f, ptr_, size_);                                                                                        \
-		cmdb_->copyBufferToTextureVolume(handle_.getBuffer(), handle_.getOffset(), handle_.getRange(), tex_, vol_);    \
+#define UPLOAD_TEX_VOL(cmdb_, tex_, vol_, ptr_, size_, handle_)                                                     \
+	do                                                                                                              \
+	{                                                                                                               \
+		ANKI_TEST_EXPECT_NO_ERR(transfAlloc.allocate(size_, handle_));                                              \
+		void* f = handle_.getMappedMemory();                                                                        \
+		memcpy(f, ptr_, size_);                                                                                     \
+		cmdb_->copyBufferToTextureVolume(handle_.getBuffer(), handle_.getOffset(), handle_.getRange(), tex_, vol_); \
 	} while(0)
 	} while(0)
 
 
 const PixelFormat DS_FORMAT = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);
 const PixelFormat DS_FORMAT = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);

+ 5 - 5
tests/util/String.cpp

@@ -94,11 +94,11 @@ ANKI_TEST(Util, String)
 
 
 	// Compare
 	// Compare
 	{
 	{
-#define COMPARE(x_, y_, op_)                                                                                           \
-	a.append(alloc, x_);                                                                                               \
-	b.append(alloc, y_);                                                                                               \
-	ANKI_TEST_EXPECT_EQ(a op_ b, std::string(x_) op_ std::string(y_))                                                  \
-	a.destroy(alloc);                                                                                                  \
+#define COMPARE(x_, y_, op_)                                          \
+	a.append(alloc, x_);                                              \
+	b.append(alloc, y_);                                              \
+	ANKI_TEST_EXPECT_EQ(a op_ b, std::string(x_) op_ std::string(y_)) \
+	a.destroy(alloc);                                                 \
 	b.destroy(alloc);
 	b.destroy(alloc);
 
 
 		String a, b;
 		String a, b;

+ 5 - 5
tools/scene/Common.h

@@ -13,11 +13,11 @@ void log(const char* file, int line, unsigned type, const char* fmt, ...);
 // Log and errors
 // Log and errors
 #define LOGI(...) log(__FILE__, __LINE__, 1, __VA_ARGS__)
 #define LOGI(...) log(__FILE__, __LINE__, 1, __VA_ARGS__)
 
 
-#define ERROR(...)                                                                                                     \
-	do                                                                                                                 \
-	{                                                                                                                  \
-		log(__FILE__, __LINE__, 2, __VA_ARGS__);                                                                       \
-		exit(0);                                                                                                       \
+#define ERROR(...)                               \
+	do                                           \
+	{                                            \
+		log(__FILE__, __LINE__, 2, __VA_ARGS__); \
+		exit(0);                                 \
 	} while(0)
 	} while(0)
 
 
 #define LOGW(...) log(__FILE__, __LINE__, 3, __VA_ARGS__)
 #define LOGW(...) log(__FILE__, __LINE__, 3, __VA_ARGS__)