Ver Fonte

Make more types available in GLSL

Panagiotis Christopoulos Charitos há 5 anos atrás
pai
commit
c8a55f7091

+ 0 - 1
src/anki/Math.h

@@ -11,7 +11,6 @@
 #include <anki/math/Euler.h>
 #include <anki/math/Axisang.h>
 #include <anki/math/Transform.h>
-#include <anki/math/F16.h>
 
 #include <anki/math/Functions.h>
 

+ 1 - 0
src/anki/Util.h

@@ -40,6 +40,7 @@
 #include <anki/util/Tracer.h>
 #include <anki/util/Serializer.h>
 #include <anki/util/Xml.h>
+#include <anki/util/F16.h>
 
 /// @defgroup util Utilities (like STL)
 

+ 22 - 0
src/anki/gr/ShaderVariableDataTypeDefs.h

@@ -7,20 +7,42 @@
 
 // ANKI_SVDT_MACRO(capital, varType, baseType, rowCount, columnCount)
 #if defined(ANKI_SVDT_MACRO)
+ANKI_SVDT_MACRO(I8, I8, I8, 1, 1)
+ANKI_SVDT_MACRO(U8, U8, U8, 1, 1)
+ANKI_SVDT_MACRO(I16, I16, I16, 1, 1)
+ANKI_SVDT_MACRO(U16, U16, U16, 1, 1)
 ANKI_SVDT_MACRO(I32, I32, I32, 1, 1)
 ANKI_SVDT_MACRO(U32, U32, U32, 1, 1)
+ANKI_SVDT_MACRO(I64, I64, I64, 1, 1)
+ANKI_SVDT_MACRO(U64, U64, U64, 1, 1)
+ANKI_SVDT_MACRO(F16, F16, F16, 1, 1)
 ANKI_SVDT_MACRO(F32, F32, F32, 1, 1)
 
+ANKI_SVDT_MACRO(I8VEC2, I8Vec2, I8, 2, 1)
+ANKI_SVDT_MACRO(U8VEC2, U8Vec2, U8, 2, 1)
+ANKI_SVDT_MACRO(I16VEC2, I16Vec2, I16, 2, 1)
+ANKI_SVDT_MACRO(U16VEC2, U16Vec2, U16, 2, 1)
 ANKI_SVDT_MACRO(IVEC2, IVec2, I32, 2, 1)
 ANKI_SVDT_MACRO(UVEC2, UVec2, U32, 2, 1)
+ANKI_SVDT_MACRO(HVEC2, HVec2, F16, 2, 1)
 ANKI_SVDT_MACRO(VEC2, Vec2, F32, 2, 1)
 
+ANKI_SVDT_MACRO(I8VEC3, I8Vec3, I8, 3, 1)
+ANKI_SVDT_MACRO(U8VEC3, U8Vec3, U8, 3, 1)
+ANKI_SVDT_MACRO(I16VEC3, I16Vec3, I16, 3, 1)
+ANKI_SVDT_MACRO(U16VEC3, U16Vec3, U16, 3, 1)
 ANKI_SVDT_MACRO(IVEC3, IVec3, I32, 3, 1)
 ANKI_SVDT_MACRO(UVEC3, UVec3, U32, 3, 1)
+ANKI_SVDT_MACRO(HVEC3, HVec3, F16, 3, 1)
 ANKI_SVDT_MACRO(VEC3, Vec3, F32, 3, 1)
 
+ANKI_SVDT_MACRO(I8VEC4, I8Vec4, I8, 4, 1)
+ANKI_SVDT_MACRO(U8VEC4, U8Vec4, U8, 4, 1)
+ANKI_SVDT_MACRO(I16VEC4, I16Vec4, I16, 4, 1)
+ANKI_SVDT_MACRO(U16VEC4, U16Vec4, U16, 4, 1)
 ANKI_SVDT_MACRO(IVEC4, IVec4, I32, 4, 1)
 ANKI_SVDT_MACRO(UVEC4, UVec4, U32, 4, 1)
+ANKI_SVDT_MACRO(HVEC4, HVec4, F16, 4, 1)
 ANKI_SVDT_MACRO(VEC4, Vec4, F32, 4, 1)
 
 ANKI_SVDT_MACRO(MAT3, Mat3, F32, 3, 3)

+ 0 - 1
src/anki/math/CommonSrc.h

@@ -13,5 +13,4 @@
 #include <anki/math/Mat4.h>
 #include <anki/math/Mat3x4.h>
 #include <anki/math/Transform.h>
-#include <anki/math/F16.h>
 #include <anki/math/Functions.h>

+ 1 - 0
src/anki/math/Vec.h

@@ -6,6 +6,7 @@
 #pragma once
 
 #include <anki/math/Common.h>
+#include <anki/util/F16.h>
 
 namespace anki
 {

+ 4 - 3
src/anki/shader_compiler/ShaderProgramCompiler.cpp

@@ -13,7 +13,7 @@
 namespace anki
 {
 
-static const char* SHADER_BINARY_MAGIC = "ANKISDR1";
+static const char* SHADER_BINARY_MAGIC = "ANKISDR2";
 const U32 SHADER_BINARY_VERSION = 1;
 
 Error ShaderProgramBinaryWrapper::serializeToFile(CString fname) const
@@ -43,9 +43,10 @@ Error ShaderProgramBinaryWrapper::deserializeFromFile(CString fname)
 
 	m_singleAllocation = true;
 
-	if(memcmp(SHADER_BINARY_MAGIC, &m_binary->m_magic[0], 0) != 0)
+	if(memcmp(SHADER_BINARY_MAGIC, &m_binary->m_magic[0], strlen(SHADER_BINARY_MAGIC)) != 0)
 	{
-		ANKI_SHADER_COMPILER_LOGE("Corrupted or wrong version of shader binary: %s", fname.cstr());
+		ANKI_SHADER_COMPILER_LOGE("Corrupted or wrong version of shader binary: %s. Clean the shader cache",
+								  fname.cstr());
 		return Error::USER_DATA;
 	}
 

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

@@ -1,5 +1,5 @@
 set(SOURCES Assert.cpp Functions.cpp File.cpp Filesystem.cpp Memory.cpp System.cpp HighRezTimer.cpp ThreadPool.cpp
-	ThreadHive.cpp Hash.cpp Logger.cpp String.cpp StringList.cpp Tracer.cpp Serializer.cpp Xml.cpp)
+	ThreadHive.cpp Hash.cpp Logger.cpp String.cpp StringList.cpp Tracer.cpp Serializer.cpp Xml.cpp F16.cpp)
 
 if(LINUX OR ANDROID OR MACOS)
 	set(SOURCES ${SOURCES} HighRezTimerPosix.cpp FilesystemPosix.cpp ThreadPosix.cpp ProcessPosix.cpp)

+ 2 - 1
src/anki/math/F16.cpp → src/anki/util/F16.cpp

@@ -3,7 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include <anki/math/F16.h>
+#include <anki/util/F16.h>
+#include <anki/util/Assert.h>
 
 namespace anki
 {

+ 63 - 61
src/anki/math/F16.h → src/anki/util/F16.h

@@ -5,23 +5,61 @@
 
 #pragma once
 
-#include <anki/math/Common.h>
+#include <anki/util/StdTypes.h>
 
 namespace anki
 {
 
-/// @addtogroup math
+/// @addtogroup util_other
 /// @{
 
 /// Half float
 class F16
 {
-	/// @name Friends
+	/// @name Friends with F32
 	/// @{
-	friend F32 operator+(const F32 f, const F16 h);
-	friend F32 operator-(const F32 f, const F16 h);
-	friend F32 operator*(const F32 f, const F16 h);
-	friend F32 operator/(const F32 f, const F16 h);
+	friend F32 operator+(const F32 f, const F16 h)
+	{
+		return f + h.toF32();
+	}
+
+	friend F32 operator-(const F32 f, const F16 h)
+	{
+		return f - h.toF32();
+	}
+
+	friend F32 operator*(const F32 f, const F16 h)
+	{
+		return f * h.toF32();
+	}
+
+	friend F32 operator/(const F32 f, const F16 h)
+	{
+		return f / h.toF32();
+	}
+	/// @}
+
+	/// @name Friends with F64
+	/// @{
+	friend F64 operator+(const F64 f, const F16 h)
+	{
+		return f + h.toF32();
+	}
+
+	friend F64 operator-(const F64 f, const F16 h)
+	{
+		return f - h.toF32();
+	}
+
+	friend F64 operator*(const F64 f, const F16 h)
+	{
+		return f * h.toF32();
+	}
+
+	friend F64 operator/(const F64 f, const F16 h)
+	{
+		return f / h.toF32();
+	}
 	/// @}
 
 public:
@@ -37,6 +75,11 @@ public:
 		m_data = b.m_data;
 	}
 
+	explicit F16(const F64 f)
+	{
+		*this = toF16(F32(f));
+	}
+
 	explicit F16(const F32 f)
 	{
 		*this = toF16(f);
@@ -113,64 +156,47 @@ public:
 
 	/// @name Operators with F32
 	/// @{
-	F16& operator=(const F32 b)
-	{
-		*this = toF16(b);
-		return *this;
-	}
-
 	F32 operator+(const F32 b) const
 	{
 		return toF32() + b;
 	}
 
-	F16& operator+=(const F32 b)
-	{
-		*this = toF16(toF32() + b);
-		return *this;
-	}
-
 	F32 operator-(const F32 b) const
 	{
 		return toF32() - b;
 	}
 
-	F16& operator-=(const F32 b)
-	{
-		*this = toF16(toF32() - b);
-		return *this;
-	}
-
 	F32 operator*(const F32 b) const
 	{
 		return toF32() * b;
 	}
 
-	F16& operator*=(const F32 b)
+	F32 operator/(const F32 b) const
 	{
-		*this = toF16(toF32() * b);
-		return *this;
+		return toF32() / b;
 	}
+	/// @}
 
-	F32 operator/(const F32 b) const
+	/// @name Operators with F64
+	/// @{
+	F64 operator+(const F64 b) const
 	{
-		return toF32() / b;
+		return toF32() + b;
 	}
 
-	F16& operator/=(const F32 b)
+	F64 operator-(const F64 b) const
 	{
-		*this = toF16(toF32() / b);
-		return *this;
+		return toF32() - b;
 	}
 
-	Bool operator==(const F32 b) const
+	F64 operator*(const F64 b) const
 	{
-		return toF32() == b;
+		return toF32() * b;
 	}
 
-	Bool operator!=(const F32 b) const
+	F64 operator/(const F64 b) const
 	{
-		return toF32() != b;
+		return toF32() / b;
 	}
 	/// @}
 
@@ -193,30 +219,6 @@ private:
 	static F32 toF32(F16 h);
 	static F16 toF16(F32 f);
 };
-
-/// @memberof F16
-inline F32 operator+(const F32 f, const F16 h)
-{
-	return f + h.toF32();
-}
-
-/// @memberof F16
-inline F32 operator-(const F32 f, const F16 h)
-{
-	return f - h.toF32();
-}
-
-/// @memberof F16
-inline F32 operator*(const F32 f, const F16 h)
-{
-	return f * h.toF32();
-}
-
-/// @memberof F16
-inline F32 operator/(const F32 f, const F16 h)
-{
-	return f / h.toF32();
-}
 /// @}
 
 } // end namespace anki

+ 39 - 0
src/anki/util/String.cpp

@@ -4,6 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <anki/util/String.h>
+#include <anki/util/F16.h>
 #include <cmath> // For HUGE_VAL
 #include <climits> // For LLONG_MAX
 #include <cstdarg> // For var args
@@ -37,6 +38,14 @@ Error CString::toNumber(F32& out) const
 	return Error::NONE;
 }
 
+Error CString::toNumber(F16& out) const
+{
+	F64 d;
+	ANKI_CHECK(toNumber(d));
+	out = F16(d);
+	return Error::NONE;
+}
+
 Error CString::toNumber(I64& out) const
 {
 	checkInit();
@@ -133,6 +142,36 @@ Error CString::toNumber(U8& out) const
 	return Error::NONE;
 }
 
+Error CString::toNumber(I16& out) const
+{
+	I64 i64 = 0;
+	ANKI_CHECK(toNumber(i64));
+
+	if(i64 < MIN_I16 || i64 > MAX_I16)
+	{
+		ANKI_UTIL_LOGE("Conversion failed. Our of range: %s", m_ptr);
+		return Error::USER_DATA;
+	}
+
+	out = I16(i64);
+	return Error::NONE;
+}
+
+Error CString::toNumber(U16& out) const
+{
+	U64 u64;
+	ANKI_CHECK(toNumber(u64));
+
+	if(u64 > MAX_U16)
+	{
+		ANKI_UTIL_LOGE("Conversion failed. Our of range: %s", m_ptr);
+		return Error::USER_DATA;
+	}
+
+	out = U16(u64);
+	return Error::NONE;
+}
+
 Error CString::toNumber(Bool& out) const
 {
 	I32 i;

+ 51 - 21
src/anki/util/String.h

@@ -17,6 +17,9 @@
 namespace anki
 {
 
+// Forward
+class F16;
+
 /// @addtogroup util_private
 /// @{
 
@@ -213,29 +216,38 @@ public:
 		return (out == nullptr) ? NPOS : PtrSize(out - m_ptr);
 	}
 
-	/// Convert to F64.
-	ANKI_USE_RESULT Error toNumber(F64& out) const;
+	/// Convert to F16.
+	ANKI_USE_RESULT Error toNumber(F16& out) const;
 
 	/// Convert to F32.
 	ANKI_USE_RESULT Error toNumber(F32& out) const;
 
+	/// Convert to F64.
+	ANKI_USE_RESULT Error toNumber(F64& out) const;
+
 	/// Convert to I8.
 	ANKI_USE_RESULT Error toNumber(I8& out) const;
 
-	/// Convert to I64.
-	ANKI_USE_RESULT Error toNumber(I64& out) const;
+	/// Convert to U8.
+	ANKI_USE_RESULT Error toNumber(U8& out) const;
+
+	/// Convert to I16.
+	ANKI_USE_RESULT Error toNumber(I16& out) const;
+
+	/// Convert to U16.
+	ANKI_USE_RESULT Error toNumber(U16& out) const;
 
 	/// Convert to I32.
 	ANKI_USE_RESULT Error toNumber(I32& out) const;
 
-	/// Convert to U64.
-	ANKI_USE_RESULT Error toNumber(U64& out) const;
-
 	/// Convert to U32.
 	ANKI_USE_RESULT Error toNumber(U32& out) const;
 
-	/// Convert to U8.
-	ANKI_USE_RESULT Error toNumber(U8& out) const;
+	/// Convert to I64.
+	ANKI_USE_RESULT Error toNumber(I64& out) const;
+
+	/// Convert to U64.
+	ANKI_USE_RESULT Error toNumber(U64& out) const;
 
 	/// Convert to Bool.
 	ANKI_USE_RESULT Error toNumber(Bool& out) const;
@@ -529,8 +541,8 @@ public:
 	template<typename TNumber>
 	void toString(Allocator alloc, TNumber number);
 
-	/// Convert to F64.
-	ANKI_USE_RESULT Error toNumber(F64& out) const
+	/// Convert to F16.
+	ANKI_USE_RESULT Error toNumber(F16& out) const
 	{
 		return toCString().toNumber(out);
 	}
@@ -541,26 +553,38 @@ public:
 		return toCString().toNumber(out);
 	}
 
-	/// Convert to I64.
-	ANKI_USE_RESULT Error toNumber(I64& out) const
+	/// Convert to F64.
+	ANKI_USE_RESULT Error toNumber(F64& out) const
 	{
 		return toCString().toNumber(out);
 	}
 
-	/// Convert to I32.
-	ANKI_USE_RESULT Error toNumber(I32& out) const
+	/// Convert to I8.
+	ANKI_USE_RESULT Error toNumber(I8& out) const
 	{
 		return toCString().toNumber(out);
 	}
 
-	/// Convert to I8.
-	ANKI_USE_RESULT Error toNumber(I8& out) const
+	/// Convert to U8.
+	ANKI_USE_RESULT Error toNumber(U8& out) const
 	{
 		return toCString().toNumber(out);
 	}
 
-	/// Convert to U64.
-	ANKI_USE_RESULT Error toNumber(U64& out) const
+	/// Convert to I16.
+	ANKI_USE_RESULT Error toNumber(I16& out) const
+	{
+		return toCString().toNumber(out);
+	}
+
+	/// Convert to U16.
+	ANKI_USE_RESULT Error toNumber(U16& out) const
+	{
+		return toCString().toNumber(out);
+	}
+
+	/// Convert to I32.
+	ANKI_USE_RESULT Error toNumber(I32& out) const
 	{
 		return toCString().toNumber(out);
 	}
@@ -571,8 +595,14 @@ public:
 		return toCString().toNumber(out);
 	}
 
-	/// Convert to U8.
-	ANKI_USE_RESULT Error toNumber(U8& out) const
+	/// Convert to I64.
+	ANKI_USE_RESULT Error toNumber(I64& out) const
+	{
+		return toCString().toNumber(out);
+	}
+
+	/// Convert to U64.
+	ANKI_USE_RESULT Error toNumber(U64& out) const
 	{
 		return toCString().toNumber(out);
 	}