Browse Source

Some refactoring

Panagiotis Christopoulos Charitos 5 năm trước cách đây
mục cha
commit
c588faf1ce

+ 1 - 1
samples/common/Framework.cpp

@@ -215,7 +215,7 @@ Error SampleApp::userMainLoop(Bool& quit, Second elapsedTime)
 			angles.x() = clamp(angles.x(), toRad(-90.0f), toRad(90.0f)); // Avoid cycle in Y axis
 			angles.y() += -velocity.x() * toRad(360.0f) * F32(elapsedTime) * MOUSE_SENSITIVITY;
 			angles.z() = 0.0f;
-			mover->setLocalRotation(Mat3x4(angles));
+			mover->setLocalRotation(Mat3x4(Vec3(0.0f), angles));
 		}
 	}
 	else

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

@@ -21,18 +21,18 @@ class BufferInitInfo : public GrBaseInitInfo
 public:
 	PtrSize m_size = 0;
 	BufferUsageBit m_usage = BufferUsageBit::NONE;
-	BufferMapAccessBit m_access = BufferMapAccessBit::NONE;
+	BufferMapAccessBit m_mapAccess = BufferMapAccessBit::NONE;
 
 	BufferInitInfo(CString name = {})
 		: GrBaseInitInfo(name)
 	{
 	}
 
-	BufferInitInfo(PtrSize size, BufferUsageBit usage, BufferMapAccessBit access, CString name = {})
+	BufferInitInfo(PtrSize size, BufferUsageBit usage, BufferMapAccessBit mapAccess, CString name = {})
 		: GrBaseInitInfo(name)
 		, m_size(size)
 		, m_usage(usage)
-		, m_access(access)
+		, m_mapAccess(mapAccess)
 	{
 	}
 
@@ -82,9 +82,9 @@ public:
 	/// @param access The access to the buffer.
 	/// @return The array that was mapped.
 	template<typename T>
-	WeakArray<T> map(PtrSize offset, U32 elementCount, BufferMapAccessBit access)
+	WeakArray<T, PtrSize> map(PtrSize offset, PtrSize elementCount, BufferMapAccessBit access)
 	{
-		return WeakArray<T>(static_cast<T*>(map(offset, sizeof(T) * elementCount, access)), elementCount);
+		return WeakArray<T, PtrSize>(static_cast<T*>(map(offset, sizeof(T) * elementCount, access)), elementCount);
 	}
 
 	/// Unmap the buffer.

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

@@ -177,7 +177,7 @@ void AccelerationStructureImpl::initBuildInfo()
 			BufferInitInfo buffInit("RT_instances");
 			buffInit.m_size = sizeof(VkAccelerationStructureInstanceKHR) * instanceCount;
 			buffInit.m_usage = InternalBufferUsageBit::ACCELERATION_STRUCTURE_BUILD_SCRATCH;
-			buffInit.m_access = BufferMapAccessBit::WRITE;
+			buffInit.m_mapAccess = BufferMapAccessBit::WRITE;
 			m_topLevelInfo.m_instancesBuff = getManager().newBuffer(buffInit);
 		}
 

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

@@ -31,7 +31,7 @@ Error BufferImpl::init(const BufferInitInfo& inf)
 								  && !!(inf.m_usage & ~BufferUsageBit::ALL_TRANSFER);
 
 	PtrSize size = inf.m_size;
-	BufferMapAccessBit access = inf.m_access;
+	BufferMapAccessBit access = inf.m_mapAccess;
 	BufferUsageBit usage = inf.m_usage;
 
 	ANKI_ASSERT(size > 0);

+ 5 - 5
src/anki/importer/GltfImporter.cpp

@@ -130,7 +130,7 @@ static ANKI_USE_RESULT Error getNodeTransform(const cgltf_node& node, Transform&
 	}
 
 	trf.setOrigin(tsl.xyz0());
-	trf.setRotation(Mat3x4(rot));
+	trf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	trf.setScale(scale[0]);
 
 	return Error::NONE;
@@ -487,7 +487,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 				getNodeName(node).cstr(), aabbMin.x(), aabbMin.y(), aabbMin.z(), aabbMax.x(), aabbMax.y(),
 				aabbMax.z()));
 
-			Transform localTrf = Transform(tsl.xyz0(), Mat3x4(rot), 1.0f);
+			Transform localTrf = Transform(tsl.xyz0(), Mat3x4(Vec3(0.0f), rot), 1.0f);
 			ANKI_CHECK(writeTransform(parentTrf.combineTransformations(localTrf)));
 		}
 		else if((it = extras.find("gi_probe")) != extras.getEnd() && *it == "true")
@@ -531,7 +531,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 				ANKI_CHECK(m_sceneFile.writeText("comp:setCellSize(%f)\n", cellSize));
 			}
 
-			Transform localTrf = Transform(tsl.xyz0(), Mat3x4(rot), 1.0f);
+			const Transform localTrf = Transform(tsl.xyz0(), Mat3x4(Vec3(0.0f), rot), 1.0f);
 			ANKI_CHECK(writeTransform(parentTrf.combineTransformations(localTrf)));
 		}
 		else if((it = extras.find("decal")) != extras.getEnd() && *it == "true")
@@ -591,7 +591,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 			Mat3 rot;
 			Vec3 scale;
 			getNodeTransform(node, tsl, rot, scale);
-			Transform localTrf = Transform(tsl.xyz0(), Mat3x4(rot), 1.0f);
+			Transform localTrf = Transform(tsl.xyz0(), Mat3x4(Vec3(0.0f), rot), 1.0f);
 			ANKI_CHECK(writeTransform(parentTrf.combineTransformations(localTrf)));
 		}
 		else
@@ -711,7 +711,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 		Mat3 rot;
 		Vec3 scale;
 		getNodeTransform(node, tsl, rot, scale);
-		nodeTrf = Transform(tsl.xyz0(), Mat3x4(rot), scale.x());
+		nodeTrf = Transform(tsl.xyz0(), Mat3x4(Vec3(0.0f), rot), scale.x());
 	}
 	for(cgltf_node* const* c = node.children; c < node.children + node.children_count; ++c)
 	{

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

@@ -108,49 +108,49 @@ inline T modf(T x, T& intPart)
 /// The same as abs/fabs. For ints and floats.
 template<typename T,
 		 ANKI_ENABLE(std::is_floating_point<T>::value || (std::is_integral<T>::value && std::is_signed<T>::value))>
-inline T absolute(const T f)
+inline constexpr T absolute(const T f)
 {
 	return (f < T(0)) ? -f : f;
 }
 
 template<typename T>
-inline T pow(const T x, const T power)
+inline constexpr T pow(const T x, const T power)
 {
 	return T(std::pow(x, power));
 }
 
 template<typename T>
-inline T log2(const T x)
+inline constexpr T log2(const T x)
 {
 	return T(std::log2(x));
 }
 
 template<typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0>
-inline Bool isZero(const T f, const T e = EPSILON)
+inline constexpr Bool isZero(const T f, const T e = EPSILON)
 {
 	return absolute<T>(f) < e;
 }
 
 template<typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
-inline Bool isZero(const T f)
+inline constexpr Bool isZero(const T f)
 {
 	return f == 0;
 }
 
 template<typename T>
-inline T toRad(const T degrees)
+inline constexpr T toRad(const T degrees)
 {
 	return degrees * (PI / T(180));
 }
 
 template<typename T>
-inline T toDegrees(const T rad)
+inline constexpr T toDegrees(const T rad)
 {
 	return rad * (T(180) / PI);
 }
 
 template<typename T>
-inline T clamp(T v, T minv, T maxv)
+inline constexpr T clamp(T v, T minv, T maxv)
 {
 	ANKI_ASSERT(minv < maxv);
 	return min<T>(max<T>(minv, v), maxv);
@@ -158,14 +158,14 @@ inline T clamp(T v, T minv, T maxv)
 
 /// Returns 1 or -1 based on the sign
 template<typename T>
-inline T sign(T v)
+inline constexpr T sign(T v)
 {
 	return (v > T(0)) ? T(1) : T(-1);
 }
 
 /// Same as smoothstep in glsl
 template<typename T>
-inline T smoothstep(T edge0, T edge1, T value)
+inline constexpr T smoothstep(T edge0, T edge1, T value)
 {
 	value = clamp((value - edge0) / (edge1 - edge0), T(0), T(1));
 	return value * value * (T(3) - T(2) * value);
@@ -175,21 +175,21 @@ inline T smoothstep(T edge0, T edge1, T value)
 /// @param[in] from Starting value
 /// @param[in] to Ending value
 /// @param[in] u The percentage from the from "from" value. Values from [0.0, 1.0]
-template<typename Type>
-inline Type linearInterpolate(const Type& from, const Type& to, F32 u)
+template<typename T>
+inline constexpr T linearInterpolate(const T& from, const T& to, F32 u)
 {
-	return from * Type(1.0f - u) + to * Type(u);
+	return from * T(1.0f - u) + to * T(u);
 }
 
 /// Cosine interpolation
 /// @param[in] from Starting value
 /// @param[in] to Ending value
 /// @param[in] u The percentage from the from "from" value. Values from [0.0, 1.0]
-template<typename Type>
-inline Type cosInterpolate(const Type& from, const Type& to, F32 u)
+template<typename T>
+inline T cosInterpolate(const T& from, const T& to, F32 u)
 {
-	const F32 u2 = (1.0f - cos<Type>(u * PI)) / 2.0f;
-	return from * Type(1.0f - u2) + to * Type(u2);
+	const F32 u2 = (1.0f - cos<F32>(u * PI)) / 2.0f;
+	return from * T(1.0f - u2) + to * T(u2);
 }
 
 /// Cubic interpolation
@@ -198,14 +198,14 @@ inline Type cosInterpolate(const Type& from, const Type& to, F32 u)
 /// @param[in] c Point c
 /// @param[in] d Point d
 /// @param[in] u The percentage from the from b point to d point. Value from [0.0, 1.0]
-template<typename Type>
-inline Type cubicInterpolate(const Type& a, const Type& b, const Type& c, const Type& d, F32 u)
+template<typename T>
+inline constexpr T cubicInterpolate(const T& a, const T& b, const T& c, const T& d, F32 u)
 {
-	F32 u2 = u * u;
-	Type a0 = d - c - a + b;
-	Type a1 = a - b - a0;
-	Type a2 = c - a;
-	Type a3 = b;
+	const F32 u2 = u * u;
+	const T a0 = d - c - a + b;
+	const T a1 = a - b - a0;
+	const T a2 = c - a;
+	const T a3 = b;
 
 	return (a0 * u * u2 + a1 * u2 + a2 * u + a3);
 }

+ 22 - 127
src/anki/math/Mat.h

@@ -145,77 +145,18 @@ public:
 	}
 
 	ANKI_ENABLE_METHOD(J == 4 && I == 4)
-	explicit TMat(const TMat<T, 3, 3>& m3)
-	{
-		auto& m = *this;
-		m(0, 0) = m3(0, 0);
-		m(0, 1) = m3(0, 1);
-		m(0, 2) = m3(0, 2);
-		m(0, 3) = 0.0;
-		m(1, 0) = m3(1, 0);
-		m(1, 1) = m3(1, 1);
-		m(1, 2) = m3(1, 2);
-		m(1, 3) = 0.0;
-		m(2, 0) = m3(2, 0);
-		m(2, 1) = m3(2, 1);
-		m(2, 2) = m3(2, 2);
-		m(2, 3) = 0.0;
-		m(3, 0) = 0.0;
-		m(3, 1) = 0.0;
-		m(3, 2) = 0.0;
-		m(3, 3) = 1.0;
-	}
-
-	ANKI_ENABLE_METHOD(J == 4 && I == 4)
-	explicit TMat(const TVec<T, 4>& v)
-	{
-		auto& m = *this;
-		m(0, 0) = 1.0;
-		m(0, 1) = 0.0;
-		m(0, 2) = 0.0;
-		m(0, 3) = v.x();
-		m(1, 0) = 0.0;
-		m(1, 1) = 1.0;
-		m(1, 2) = 0.0;
-		m(1, 3) = v.y();
-		m(2, 0) = 0.0;
-		m(2, 1) = 0.0;
-		m(2, 2) = 1.0;
-		m(2, 3) = v.z();
-		m(3, 0) = 0.0;
-		m(3, 1) = 0.0;
-		m(3, 2) = 0.0;
-		m(3, 3) = v.w();
-	}
-
-	ANKI_ENABLE_METHOD(J == 4 && I == 4)
-	explicit TMat(const TVec<T, 3>& v)
-		: TMat(v.xyz1())
-	{
-	}
-
-	ANKI_ENABLE_METHOD(J == 4 && I == 4)
-	TMat(const TVec<T, 4>& transl, const TMat<T, 3, 3>& rot)
-	{
-		setRotationPart(rot);
-		setTranslationPart(transl);
-		auto& m = *this;
-		m(3, 0) = m(3, 1) = m(3, 2) = T(0);
-	}
-
-	ANKI_ENABLE_METHOD(J == 4 && I == 4)
-	TMat(const TVec<T, 4>& transl, const TMat<T, 3, 3>& rot, const T scale)
+	TMat(const TVec<T, 4>& translation, const TMat<T, 3, 3>& rotation, const T scale = T(1))
 	{
 		if(isZero<T>(scale - T(1)))
 		{
-			setRotationPart(rot);
+			setRotationPart(rotation);
 		}
 		else
 		{
-			setRotationPart(rot * scale);
+			setRotationPart(rotation * scale);
 		}
 
-		setTranslationPart(transl);
+		setTranslationPart(translation);
 
 		auto& m = *this;
 		m(3, 0) = m(3, 1) = m(3, 2) = T(0);
@@ -223,7 +164,7 @@ public:
 
 	ANKI_ENABLE_METHOD(J == 4 && I == 4)
 	explicit TMat(const TTransform<T>& t)
-		: TMat<T, 4, 4>(t.getOrigin().xyz1(), t.getRotation().getRotationPart(), t.getScale())
+		: TMat(t.getOrigin().xyz1(), t.getRotation().getRotationPart(), t.getScale())
 	{
 	}
 
@@ -247,24 +188,6 @@ public:
 		m(2, 3) = m23;
 	}
 
-	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	explicit TMat(const TMat<T, 3, 3>& m3)
-	{
-		auto& m = *this;
-		m(0, 0) = m3(0, 0);
-		m(0, 1) = m3(0, 1);
-		m(0, 2) = m3(0, 2);
-		m(0, 3) = 0.0;
-		m(1, 0) = m3(1, 0);
-		m(1, 1) = m3(1, 1);
-		m(1, 2) = m3(1, 2);
-		m(1, 3) = 0.0;
-		m(2, 0) = m3(2, 0);
-		m(2, 1) = m3(2, 1);
-		m(2, 2) = m3(2, 2);
-		m(2, 3) = 0.0;
-	}
-
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
 	explicit TMat(const TMat<T, 4, 4>& m4)
 	{
@@ -284,70 +207,42 @@ public:
 	}
 
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	explicit TMat(const TVec<T, 3>& v)
-	{
-		auto& m = *this;
-		m(0, 0) = 1.0;
-		m(0, 1) = 0.0;
-		m(0, 2) = 0.0;
-		m(0, 3) = v.x();
-		m(1, 0) = 0.0;
-		m(1, 1) = 1.0;
-		m(1, 2) = 0.0;
-		m(1, 3) = v.y();
-		m(2, 0) = 0.0;
-		m(2, 1) = 0.0;
-		m(2, 2) = 1.0;
-		m(2, 3) = v.z();
-	}
-
-	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	explicit TMat(const TQuat<T>& q)
+	explicit TMat(const TVec<T, 3>& translation, const TMat<T, 3, 3>& rotation, const T scale = T(1))
 	{
-		setRotationPart(TMat<T, 3, 3>(q));
-		setTranslationPart(TVec<T, 3>(0.0));
-	}
+		if(isZero<T>(scale - T(1)))
+		{
+			setRotationPart(rotation);
+		}
+		else
+		{
+			setRotationPart(rotation * scale);
+		}
 
-	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	explicit TMat(const TEuler<T>& b)
-	{
-		setRotationPart(TMat<T, 3, 3>(b));
-		setTranslationPart(TVec<T, 3>(0.0));
+		setTranslationPart(translation);
 	}
 
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	explicit TMat(const TAxisang<T>& b)
+	explicit TMat(const TVec<T, 3>& translation, const TQuat<T>& q, const T scale = T(1))
+		: TMat(translation, TMat<T, 3, 3>(q), scale)
 	{
-		setRotationPart(TAxisang<T>(b));
-		setTranslationPart(TVec<T, 3>(0.0));
 	}
 
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	TMat(const TVec<T, 3>& transl, const TMat<T, 3, 3>& rot)
+	explicit TMat(const TVec<T, 3>& translation, const TEuler<T>& b, const T scale = T(1))
+		: TMat(translation, TMat<T, 3, 3>(b), scale)
 	{
-		setRotationPart(rot);
-		setTranslationPart(transl);
 	}
 
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
-	TMat(const TVec<T, 3>& transl, const TMat<T, 3, 3>& rot, const T scale)
+	explicit TMat(const TVec<T, 3>& translation, const TAxisang<T>& b, const T scale = T(1))
+		: TMat(translation, TMat<T, 3, 3>(b), scale)
 	{
-		if(isZero<T>(scale - 1.0))
-		{
-			setRotationPart(rot);
-		}
-		else
-		{
-			setRotationPart(rot * scale);
-		}
-
-		setTranslationPart(transl);
 	}
 
 	ANKI_ENABLE_METHOD(J == 3 && I == 4)
 	explicit TMat(const TTransform<T>& t)
+		: TMat(t.getOrigin().xyz(), t.getRotation(), t.getScale())
 	{
-		(*this) = TMat(t.getOrigin(), t.getRotation(), t.getScale());
 	}
 	/// @}
 

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

@@ -455,7 +455,7 @@ void ClusterBin::binTile(U32 tileIdx, BinCtx& ctx, TileCtx& tileCtx)
 		{
 			const DecalQueueElement& decal = ctx.m_in->m_renderQueue->m_decals[i];
 			decalBox.setCenter(decal.m_obbCenter.xyz0());
-			decalBox.setRotation(Mat3x4(decal.m_obbRotation));
+			decalBox.setRotation(Mat3x4(Vec3(0.0f), decal.m_obbRotation));
 			decalBox.setExtend(decal.m_obbExtend.xyz0());
 
 			if(!insideClusterFrustum(frustumPlanes, decalBox))

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

@@ -56,7 +56,7 @@ Error DepthDownscale::initInternal(const ConfigSet&)
 
 		// Create buffer
 		BufferInitInfo buffInit("HiZ Client");
-		buffInit.m_access = BufferMapAccessBit::READ;
+		buffInit.m_mapAccess = BufferMapAccessBit::READ;
 		buffInit.m_size = lastMipHeight * lastMipWidth * sizeof(F32);
 		buffInit.m_usage = BufferUsageBit::STORAGE_COMPUTE_WRITE;
 		m_copyToBuff.m_buff = getGrManager().newBuffer(buffInit);

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

@@ -153,7 +153,7 @@ void Ssao::runMain(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx
 	const Mat4& pmat = ctx.m_renderQueue->m_projectionMatrix;
 	unis.m_unprojectionParams = ctx.m_unprojParams;
 	unis.m_projectionMat = Vec4(pmat(0, 0), pmat(1, 1), pmat(2, 2), pmat(2, 3));
-	unis.m_viewRotMat = Mat3x4(ctx.m_renderQueue->m_viewMatrix.getRotationPart());
+	unis.m_viewRotMat = Mat3x4(Vec3(0.0f), ctx.m_renderQueue->m_viewMatrix.getRotationPart());
 	cmdb->setPushConstants(&unis, sizeof(unis));
 
 	if(m_useCompute)

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

@@ -208,7 +208,7 @@ void Ssgi::run(RenderPassWorkContext& rgraphCtx)
 	unis->m_projMat = ctx.m_matrices.m_projectionJitter;
 	unis->m_prevViewProjMatMulInvViewProjMat =
 		ctx.m_prevMatrices.m_viewProjection * ctx.m_matrices.m_viewProjectionJitter.getInverse();
-	unis->m_normalMat = Mat3x4(ctx.m_matrices.m_view.getRotationPart());
+	unis->m_normalMat = Mat3x4(Vec3(0.0f), ctx.m_matrices.m_view.getRotationPart());
 	unis->m_frameCount = m_r->getFrameCount() & MAX_U32;
 	unis->m_maxSteps = m_main.m_maxSteps;
 	unis->m_firstStepPixels = m_main.m_firstStepPixels;

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

@@ -112,7 +112,7 @@ void Ssr::run(RenderPassWorkContext& rgraphCtx)
 		ctx.m_prevMatrices.m_viewProjection * ctx.m_matrices.m_viewProjectionJitter.getInverse();
 	unis->m_projMat = ctx.m_matrices.m_projectionJitter;
 	unis->m_invProjMat = ctx.m_matrices.m_projectionJitter.getInverse();
-	unis->m_normalMat = Mat3x4(ctx.m_matrices.m_view.getRotationPart());
+	unis->m_normalMat = Mat3x4(Vec3(0.0f), ctx.m_matrices.m_view.getRotationPart());
 
 	// Bind all
 	cmdb->bindSampler(0, 2, m_r->getSamplers().m_trilinearClamp);

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

@@ -33,9 +33,9 @@ class TransferGpuAllocatorHandle;
 /// @name Constants
 /// @{
 constexpr U32 MAX_LOD_COUNT = 3;
-constexpr U32 MAX_INSTANCES = 64;
-constexpr U32 MAX_SUB_DRAWCALLS = 64; ///< @warning If changed don't forget to change MAX_INSTANCE_GROUPS
-constexpr U32 MAX_INSTANCE_GROUPS = 7; ///< It's log2(MAX_INSTANCES) + 1
+constexpr U32 MAX_INSTANCES = 64; /// @warning Change MAX_INSTANCE_GROUPS as well
+constexpr U32 MAX_SUB_DRAWCALLS = 64;
+constexpr U32 MAX_INSTANCE_GROUPS = 7; /// It's log2(MAX_INSTANCES) + 1
 
 /// Standard attribute locations. Should be the same as in Common.glsl.
 enum class VertexAttributeLocation : U8

+ 6 - 6
src/anki/scene/GlobalIlluminationProbeNode.cpp

@@ -97,17 +97,17 @@ Error GlobalIlluminationProbeNode::init()
 
 	Mat3 rot;
 	rot = Mat3(Euler(0.0f, -PI / 2.0f, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeFaceTransforms[0].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[0].setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, PI / 2.0f, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeFaceTransforms[1].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[1].setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(PI / 2.0f, 0.0f, 0.0f));
-	m_cubeFaceTransforms[2].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[2].setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(-PI / 2.0f, 0.0f, 0.0f));
-	m_cubeFaceTransforms[3].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[3].setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, PI, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeFaceTransforms[4].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[4].setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeFaceTransforms[5].setRotation(Mat3x4(rot));
+	m_cubeFaceTransforms[5].setRotation(Mat3x4(Vec3(0.0f), rot));
 
 	for(U i = 0; i < 6; ++i)
 	{

+ 3 - 3
src/anki/scene/GpuParticleEmitterNode.cpp

@@ -61,7 +61,7 @@ Error GpuParticleEmitterNode::init(const CString& filename)
 
 	// Create a UBO with the props
 	BufferInitInfo buffInit;
-	buffInit.m_access = BufferMapAccessBit::WRITE;
+	buffInit.m_mapAccess = BufferMapAccessBit::WRITE;
 	buffInit.m_usage = BufferUsageBit::UNIFORM_COMPUTE;
 	buffInit.m_size = sizeof(GpuParticleEmitterProperties);
 	m_propsBuff = getSceneGraph().getGrManager().newBuffer(buffInit);
@@ -86,7 +86,7 @@ Error GpuParticleEmitterNode::init(const CString& filename)
 	m_particleCount = inProps.m_maxNumOfParticles;
 
 	// Create the particle buffer
-	buffInit.m_access = BufferMapAccessBit::WRITE;
+	buffInit.m_mapAccess = BufferMapAccessBit::WRITE;
 	buffInit.m_usage = BufferUsageBit::ALL_STORAGE;
 	buffInit.m_size = sizeof(GpuParticle) * inProps.m_maxNumOfParticles;
 	m_particlesBuff = getSceneGraph().getGrManager().newBuffer(buffInit);
@@ -200,7 +200,7 @@ void GpuParticleEmitterNode::simulate(GenericGpuComputeJobQueueElementContext& c
 	unis->m_dt = F32(m_dt);
 	unis->m_emitterPosition = m_worldPosition;
 	unis->m_emitterRotation = m_worldRotation;
-	unis->m_invViewRotation = Mat3x4(ctx.m_cameraTransform.getRotationPart());
+	unis->m_invViewRotation = Mat3x4(Vec3(0.0f), ctx.m_cameraTransform.getRotationPart());
 	cmdb->bindUniformBuffer(1, 4, token.m_buffer, token.m_offset, token.m_range);
 
 	// Dispatch

+ 6 - 6
src/anki/scene/LightNode.cpp

@@ -258,17 +258,17 @@ Error PointLightNode::frameUpdate(Second prevUpdateTime, Second crntTime)
 		Mat3 rot;
 
 		rot = Mat3(Euler(0.0, -PI / 2.0, 0.0)) * Mat3(Euler(0.0, 0.0, PI));
-		m_shadowData[0].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[0].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 		rot = Mat3(Euler(0.0, PI / 2.0, 0.0)) * Mat3(Euler(0.0, 0.0, PI));
-		m_shadowData[1].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[1].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 		rot = Mat3(Euler(PI / 2.0, 0.0, 0.0));
-		m_shadowData[2].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[2].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 		rot = Mat3(Euler(-PI / 2.0, 0.0, 0.0));
-		m_shadowData[3].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[3].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 		rot = Mat3(Euler(0.0, PI, 0.0)) * Mat3(Euler(0.0, 0.0, PI));
-		m_shadowData[4].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[4].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 		rot = Mat3(Euler(0.0, 0.0, PI));
-		m_shadowData[5].m_localTrf.setRotation(Mat3x4(rot));
+		m_shadowData[5].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 
 		const Vec4& origin = getComponent<MoveComponent>().getWorldTransform().getOrigin();
 		for(U32 i = 0; i < 6; i++)

+ 1 - 1
src/anki/scene/PlayerNode.cpp

@@ -42,7 +42,7 @@ public:
 			origin.y() += 1.9f;
 
 			// Set rotation
-			Mat3x4 rot(Euler(ang * y * 11.25f, ang * x * -20.0f, 0.0f));
+			Mat3x4 rot(Vec3(0.0f), Euler(ang * y * 11.25f, ang * x * -20.0f, 0.0f));
 
 			rot = move.getLocalRotation().combineTransformations(rot);
 

+ 6 - 6
src/anki/scene/ReflectionProbeNode.cpp

@@ -70,17 +70,17 @@ Error ReflectionProbeNode::init(const Vec4& aabbMinLSpace, const Vec4& aabbMaxLS
 	Mat3 rot;
 
 	rot = Mat3(Euler(0.0f, -PI / 2.0f, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeSides[0].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[0].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, PI / 2.0f, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeSides[1].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[1].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(PI / 2.0f, 0.0f, 0.0f));
-	m_cubeSides[2].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[2].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(-PI / 2.0f, 0.0f, 0.0f));
-	m_cubeSides[3].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[3].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, PI, 0.0f)) * Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeSides[4].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[4].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	rot = Mat3(Euler(0.0f, 0.0f, PI));
-	m_cubeSides[5].m_localTrf.setRotation(Mat3x4(rot));
+	m_cubeSides[5].m_localTrf.setRotation(Mat3x4(Vec3(0.0f), rot));
 
 	for(U i = 0; i < 6; ++i)
 	{

+ 1 - 1
src/anki/scene/events/AnimationEvent.cpp

@@ -37,7 +37,7 @@ Error AnimationEvent::update(Second prevUpdateTime, Second crntTime)
 
 	Transform trf;
 	trf.setOrigin(pos.xyz0());
-	trf.setRotation(Mat3x4(rot));
+	trf.setRotation(Mat3x4(Vec3(0.0f), rot));
 	trf.setScale(scale);
 
 	MoveComponent& move = m_associatedNodes[0]->getComponent<MoveComponent>();

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

@@ -139,28 +139,28 @@ T getRandomRange(T min, T max)
 
 /// Get min of two values.
 template<typename T>
-inline T min(T a, T b)
+inline constexpr T min(T a, T b)
 {
 	return (a < b) ? a : b;
 }
 
 /// Get max of two values.
 template<typename T>
-inline T max(T a, T b)
+inline constexpr T max(T a, T b)
 {
 	return (a > b) ? a : b;
 }
 
 /// Check if a number is a power of 2
 template<typename Int, ANKI_ENABLE(std::is_integral<Int>::value)>
-inline Bool isPowerOfTwo(Int x)
+inline constexpr Bool isPowerOfTwo(Int x)
 {
 	return !(x == 0) && !(x & (x - 1));
 }
 
 /// Get the next power of two number. For example if x is 130 this will return 256.
 template<typename Int, ANKI_ENABLE(std::is_integral<Int>::value)>
-inline Int nextPowerOfTwo(Int x)
+inline constexpr Int nextPowerOfTwo(Int x)
 {
 	const F64 d = F64(x);
 	const F64 res = pow(2.0, ceil(log(d) / log(2.0)));
@@ -171,7 +171,7 @@ inline Int nextPowerOfTwo(Int x)
 /// @param alignment The bytes of alignment
 /// @param value The value to align
 template<typename TInt, ANKI_ENABLE(std::is_integral<TInt>::value)>
-inline TInt getAlignedRoundUp(PtrSize alignment, TInt value)
+inline constexpr TInt getAlignedRoundUp(PtrSize alignment, TInt value)
 {
 	ANKI_ASSERT(alignment > 0);
 	PtrSize v = PtrSize(value);
@@ -183,7 +183,7 @@ inline TInt getAlignedRoundUp(PtrSize alignment, TInt value)
 /// @param alignment The bytes of alignment
 /// @param value The value to align
 template<typename TFloat, ANKI_ENABLE(std::is_floating_point<TFloat>::value)>
-inline TFloat getAlignedRoundUp(TFloat alignment, TFloat value)
+inline constexpr TFloat getAlignedRoundUp(TFloat alignment, TFloat value)
 {
 	ANKI_ASSERT(alignment > TFloat(0.0));
 	return ceil(value / alignment) * alignment;
@@ -202,7 +202,7 @@ inline void alignRoundUp(TAlignment alignment, TValue& value)
 /// @param alignment The bytes of alignment
 /// @param value The value to align
 template<typename TInt, ANKI_ENABLE(std::is_integral<TInt>::value)>
-inline TInt getAlignedRoundDown(PtrSize alignment, TInt value)
+inline constexpr TInt getAlignedRoundDown(PtrSize alignment, TInt value)
 {
 	ANKI_ASSERT(alignment > 0);
 	PtrSize v = PtrSize(value);
@@ -214,7 +214,7 @@ inline TInt getAlignedRoundDown(PtrSize alignment, TInt value)
 /// @param alignment The bytes of alignment
 /// @param value The value to align
 template<typename TFloat, ANKI_ENABLE(std::is_floating_point<TFloat>::value)>
-inline TFloat getAlignedRoundDown(TFloat alignment, TFloat value)
+inline constexpr TFloat getAlignedRoundDown(TFloat alignment, TFloat value)
 {
 	ANKI_ASSERT(alignment > TFloat(0.0));
 	return floor(value / alignment) * alignment;
@@ -231,7 +231,7 @@ inline void alignRoundDown(TAlignment alignment, TValue& value)
 
 /// Check if a number is aligned
 template<typename Type>
-inline Bool isAligned(PtrSize alignment, Type value)
+inline constexpr Bool isAligned(PtrSize alignment, Type value)
 {
 	return (PtrSize(value) % alignment) == 0;
 }
@@ -239,7 +239,7 @@ inline Bool isAligned(PtrSize alignment, Type value)
 template<typename T>
 inline void swapValues(T& a, T& b)
 {
-	T tmp = b;
+	const T tmp = b;
 	b = a;
 	a = tmp;
 }
@@ -248,14 +248,14 @@ inline void swapValues(T& a, T& b)
 template<typename TPtr>
 inline PtrSize ptrToNumber(TPtr ptr)
 {
-	uintptr_t i = reinterpret_cast<uintptr_t>(ptr);
-	PtrSize size = i;
+	const uintptr_t i = reinterpret_cast<uintptr_t>(ptr);
+	const PtrSize size = i;
 	return size;
 }
 
 /// Convert a number to a pointer.
 template<typename TPtr>
-inline TPtr numberToPtr(PtrSize num)
+inline constexpr TPtr numberToPtr(PtrSize num)
 {
 	uintptr_t i = static_cast<uintptr_t>(num);
 	TPtr ptr = reinterpret_cast<TPtr>(i);

+ 64 - 8
tests/gr/Gr.cpp

@@ -2316,7 +2316,7 @@ void main()
 	BufferInitInfo info;
 	info.m_size = sizeof(Vec4) * 2;
 	info.m_usage = BufferUsageBit::ALL_COMPUTE;
-	info.m_access = BufferMapAccessBit::WRITE;
+	info.m_mapAccess = BufferMapAccessBit::WRITE;
 	BufferPtr ptrBuff = gr->newBuffer(info);
 
 	Vec4* mapped = static_cast<Vec4*>(ptrBuff->map(0, MAX_PTR_SIZE, BufferMapAccessBit::WRITE));
@@ -2375,7 +2375,7 @@ ANKI_TEST(Gr, RayQuery)
 	{
 		Array<U16, 3> indices = {0, 1, 2};
 		BufferInitInfo init;
-		init.m_access = BufferMapAccessBit::WRITE;
+		init.m_mapAccess = BufferMapAccessBit::WRITE;
 		init.m_usage = BufferUsageBit::INDEX;
 		init.m_size = sizeof(indices);
 		idxBuffer = gr->newBuffer(init);
@@ -2392,7 +2392,7 @@ ANKI_TEST(Gr, RayQuery)
 		Array<Vec4, 3> verts = {{{-1.0f, 0.0f, 0.0f, 100.0f}, {1.0f, 0.0f, 0.0f, 100.0f}, {0.0f, 2.0f, 0.0f, 100.0f}}};
 
 		BufferInitInfo init;
-		init.m_access = BufferMapAccessBit::WRITE;
+		init.m_mapAccess = BufferMapAccessBit::WRITE;
 		init.m_usage = BufferUsageBit::VERTEX;
 		init.m_size = sizeof(verts);
 		vertBuffer = gr->newBuffer(init);
@@ -2634,11 +2634,11 @@ static void createCubeBuffers(GrManager& gr, Vec3 min, Vec3 max, BufferPtr& inde
 							  Bool turnInsideOut = false)
 {
 	BufferInitInfo inf;
-	inf.m_access = BufferMapAccessBit::WRITE;
+	inf.m_mapAccess = BufferMapAccessBit::WRITE;
 	inf.m_usage = BufferUsageBit::INDEX | BufferUsageBit::VERTEX | BufferUsageBit::STORAGE_TRACE_RAYS_READ;
 	inf.m_size = sizeof(Vec3) * 8;
 	vertBuffer = gr.newBuffer(inf);
-	WeakArray<Vec3> positions = vertBuffer->map<Vec3>(0, 8, BufferMapAccessBit::WRITE);
+	WeakArray<Vec3, PtrSize> positions = vertBuffer->map<Vec3>(0, 8, BufferMapAccessBit::WRITE);
 
 	//   7------6
 	//  /|     /|
@@ -2660,7 +2660,7 @@ static void createCubeBuffers(GrManager& gr, Vec3 min, Vec3 max, BufferPtr& inde
 
 	inf.m_size = sizeof(U16) * 36;
 	indexBuffer = gr.newBuffer(inf);
-	WeakArray<U16> indices = indexBuffer->map<U16>(0, 36, BufferMapAccessBit::WRITE);
+	WeakArray<U16, PtrSize> indices = indexBuffer->map<U16>(0, 36, BufferMapAccessBit::WRITE);
 	U32 t = 0;
 
 	// Top
@@ -2899,8 +2899,63 @@ void main()
 						  true);
 	}
 
+	// Create AS
+	AccelerationStructurePtr tlas;
+	if(useRayTracing)
+	{
+		// Small box
+		AccelerationStructureInitInfo inf;
+		inf.m_type = AccelerationStructureType::BOTTOM_LEVEL;
+		inf.m_bottomLevel.m_indexBuffer = smallBoxIndexBuffer;
+		inf.m_bottomLevel.m_indexType = IndexType::U16;
+		inf.m_bottomLevel.m_indexCount = 36;
+		inf.m_bottomLevel.m_positionBuffer = smallBoxVertBuffer;
+		inf.m_bottomLevel.m_positionCount = 8;
+		inf.m_bottomLevel.m_positionsFormat = Format::R32G32B32_SFLOAT;
+		inf.m_bottomLevel.m_positionStride = sizeof(Vec3);
+
+		AccelerationStructurePtr smallBlas = gr->newAccelerationStructure(inf);
+
+		// TLAS
+		Array<AccelerationStructureInstance, 1> instances;
+		instances[0].m_bottomLevel = smallBlas;
+		instances[0].m_transform = Mat3x4(Vec3((smallBox.getMin() + smallBox.getMax()).xyz() / 2.0f),
+										  Mat3(Axisang(toRad(-18.0f), Vec3(0.0f, 1.0f, 0.0f))));
+		instances[0].m_sbtRecordIndex = 0;
+
+		inf.m_type = AccelerationStructureType::TOP_LEVEL;
+		inf.m_topLevel.m_instances = instances;
+
+		tlas = gr->newAccelerationStructure(inf);
+	}
+
+	// Create the SBT
+	BufferPtr sbt;
+	if(useRayTracing)
+	{
+		BufferInitInfo inf;
+		inf.m_mapAccess = BufferMapAccessBit::WRITE;
+		inf.m_usage = BufferUsageBit::SBT;
+		inf.m_size = gr->getDeviceCapabilities().m_sbtRecordSize * 4;
+
+		sbt = gr->newBuffer(inf);
+		WeakArray<U8, PtrSize> mapped = sbt->map<U8>(0, inf.m_size, BufferMapAccessBit::WRITE);
+		memset(&mapped[0], 0, inf.m_size);
+
+		ConstWeakArray<U8> handles = rtProg->getShaderGroupHandles();
+		ANKI_TEST_EXPECT_EQ(handles.getSize(), gr->getDeviceCapabilities().m_shaderGroupHandleSize * 4);
+
+		for(U32 handle = 0; handle < 4; ++handle)
+		{
+			memcpy(&mapped[gr->getDeviceCapabilities().m_sbtRecordSize * handle],
+				   &handles[gr->getDeviceCapabilities().m_shaderGroupHandleSize * handle],
+				   gr->getDeviceCapabilities().m_shaderGroupHandleSize);
+		}
+
+		sbt->unmap();
+	}
+
 	// Draw
-#if 0
 	constexpr U32 ITERATIONS = 200;
 	for(U i = 0; i < ITERATIONS; ++i)
 	{
@@ -2917,6 +2972,7 @@ void main()
 		cinit.m_flags = CommandBufferFlag::GRAPHICS_WORK | CommandBufferFlag::SMALL_BATCH;
 		CommandBufferPtr cmdb = gr->newCommandBuffer(cinit);
 
+#if 0
 		cmdb->setViewport(0, 0, WIDTH, HEIGHT);
 
 		cmdb->bindShaderProgram(rasterProg);
@@ -2968,6 +3024,7 @@ void main()
 
 		cmdb->setTextureBarrier(presentTex, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE, TextureUsageBit::PRESENT,
 								TextureSubresourceInfo());
+#endif
 
 		cmdb->flush();
 
@@ -2980,7 +3037,6 @@ void main()
 			HighRezTimer::sleep(TICK - timer.getElapsedTime());
 		}
 	}
-#endif
 
 	COMMON_END();
 }