Browse Source

Minor changes

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
2e03b2cc10

+ 0 - 1
AnKi/Renderer/VolumetricFog.cpp

@@ -32,7 +32,6 @@ Error VolumetricFog::init(const ConfigSet& config)
 
 
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	variantInitInfo.addConstant("VOLUME_SIZE", UVec3(m_volumeSize[0], m_volumeSize[1], m_volumeSize[2]));
 	variantInitInfo.addConstant("VOLUME_SIZE", UVec3(m_volumeSize[0], m_volumeSize[1], m_volumeSize[2]));
-	variantInitInfo.addConstant("TILE_COUNT", m_r->getTileCounts());
 	variantInitInfo.addConstant("Z_SPLIT_COUNT", m_r->getZSplitCount());
 	variantInitInfo.addConstant("Z_SPLIT_COUNT", m_r->getZSplitCount());
 	variantInitInfo.addConstant("FINAL_Z_SPLIT", m_finalZSplit);
 	variantInitInfo.addConstant("FINAL_Z_SPLIT", m_finalZSplit);
 
 

+ 11 - 2
AnKi/ShaderCompiler/Glslang.cpp

@@ -6,6 +6,7 @@
 #include <AnKi/ShaderCompiler/Glslang.h>
 #include <AnKi/ShaderCompiler/Glslang.h>
 #include <AnKi/Util/StringList.h>
 #include <AnKi/Util/StringList.h>
 #include <AnKi/Util/File.h>
 #include <AnKi/Util/File.h>
+#include <AnKi/Util/Filesystem.h>
 
 
 #if ANKI_COMPILER_GCC_COMPATIBLE
 #if ANKI_COMPILER_GCC_COMPATIBLE
 #	pragma GCC diagnostic push
 #	pragma GCC diagnostic push
@@ -300,8 +301,12 @@ Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolA
 		}
 		}
 
 
 		File file;
 		File file;
+
+		StringAuto tmpDir(tmpAlloc);
+		ANKI_CHECK(getTempDirectory(tmpDir));
+
 		StringAuto fname(tmpAlloc);
 		StringAuto fname(tmpAlloc);
-		fname.sprintf("/tmp/%u.glsl", count);
+		fname.sprintf("%s/%u.glsl", tmpDir.cstr(), count);
 		ANKI_CHECK(file.open(fname, FileOpenFlag::WRITE));
 		ANKI_CHECK(file.open(fname, FileOpenFlag::WRITE));
 		ANKI_CHECK(file.writeText("%s", src.cstr()));
 		ANKI_CHECK(file.writeText("%s", src.cstr()));
 	}
 	}
@@ -352,8 +357,12 @@ Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolA
 		}
 		}
 
 
 		File file;
 		File file;
+
+		StringAuto tmpDir(tmpAlloc);
+		ANKI_CHECK(getTempDirectory(tmpDir));
+
 		StringAuto fname(tmpAlloc);
 		StringAuto fname(tmpAlloc);
-		fname.sprintf("/tmp/%u.spv", count);
+		fname.sprintf("%s/%u.spv", tmpDir.cstr(), count);
 		ANKI_CHECK(file.open(fname, FileOpenFlag::WRITE | FileOpenFlag::BINARY));
 		ANKI_CHECK(file.open(fname, FileOpenFlag::WRITE | FileOpenFlag::BINARY));
 		ANKI_CHECK(file.write(spirv.getBegin(), spirv.getSizeInBytes()));
 		ANKI_CHECK(file.write(spirv.getBegin(), spirv.getSizeInBytes()));
 	}
 	}

+ 19 - 11
AnKi/Shaders/ImportanceSampling.glsl

@@ -9,22 +9,22 @@
 
 
 #include <AnKi/Shaders/Common.glsl>
 #include <AnKi/Shaders/Common.glsl>
 
 
-// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
-// Using bitfieldReverse instead of bitwise ops
+/// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+/// Using bitfieldReverse instead of bitwise ops
 F32 radicalInverseVdC(U32 bits)
 F32 radicalInverseVdC(U32 bits)
 {
 {
 	bits = bitfieldReverse(bits);
 	bits = bitfieldReverse(bits);
 	return F32(bits) * 2.3283064365386963e-10; // / 0x100000000
 	return F32(bits) * 2.3283064365386963e-10; // / 0x100000000
 }
 }
 
 
-// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+/// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
 Vec2 hammersley2d(U32 i, U32 N)
 Vec2 hammersley2d(U32 i, U32 N)
 {
 {
 	return Vec2(F32(i) / F32(N), radicalInverseVdC(i));
 	return Vec2(F32(i) / F32(N), radicalInverseVdC(i));
 }
 }
 
 
-// Stolen from Unreal
-// Returns three elements with 16 random bits each (0-0xffff)
+/// Stolen from Unreal
+/// Returns three elements with 16 random bits each (0-0xffff)
 UVec3 rand3DPCG16(UVec3 v)
 UVec3 rand3DPCG16(UVec3 v)
 {
 {
 	v = v * 1664525u + 1013904223u;
 	v = v * 1664525u + 1013904223u;
@@ -39,8 +39,8 @@ UVec3 rand3DPCG16(UVec3 v)
 	return v >> 16u;
 	return v >> 16u;
 }
 }
 
 
-// Stolen from Unreal
-// It will return a uniform 2D point inside [0.0, 1.0]. For random use rand3DPCG16()
+/// Stolen from Unreal
+/// It will return a uniform 2D point inside [0.0, 1.0]. For random use rand3DPCG16()
 Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
 Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
 {
 {
 	const F32 e1 = fract(F32(sampleIdx) / F32(sampleCount) + F32(random.x) * (1.0 / 65536.0));
 	const F32 e1 = fract(F32(sampleIdx) / F32(sampleCount) + F32(random.x) * (1.0 / 65536.0));
@@ -48,8 +48,8 @@ Vec2 hammersleyRandom16(U32 sampleIdx, U32 sampleCount, UVec2 random)
 	return Vec2(e1, e2);
 	return Vec2(e1, e2);
 }
 }
 
 
-// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
-// From a uniform 2D point inside a circle get a 3D point in the surface of a hemisphere. It's oriented in the z axis
+/// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+/// From a uniform 2D point inside a circle get a 3D point in the surface of a hemisphere. It's oriented in the z axis
 Vec3 hemisphereSampleUniform(Vec2 uv)
 Vec3 hemisphereSampleUniform(Vec2 uv)
 {
 {
 	const F32 phi = uv.y * 2.0 * PI;
 	const F32 phi = uv.y * 2.0 * PI;
@@ -58,8 +58,8 @@ Vec3 hemisphereSampleUniform(Vec2 uv)
 	return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
 	return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
 }
 }
 
 
-// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
-// Same as hemisphereSampleUniform but it distributes points closer to the z axis
+/// http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+/// Same as hemisphereSampleUniform but it distributes points closer to the z axis
 Vec3 hemisphereSampleCos(Vec2 uv)
 Vec3 hemisphereSampleCos(Vec2 uv)
 {
 {
 	const F32 phi = uv.y * 2.0 * PI;
 	const F32 phi = uv.y * 2.0 * PI;
@@ -67,3 +67,11 @@ Vec3 hemisphereSampleCos(Vec2 uv)
 	const F32 sinTheta = sqrt(1.0 - cosTheta * cosTheta);
 	const F32 sinTheta = sqrt(1.0 - cosTheta * cosTheta);
 	return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
 	return Vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta);
 }
 }
+
+/// PCG hash function.
+U32 hashPcg(U32 u)
+{
+	const U32 state = u * 747796405u + 2891336453u;
+	const U32 word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
+	return (word >> 22u) ^ word;
+}

+ 3 - 2
AnKi/Util/Filesystem.h

@@ -44,10 +44,11 @@ ANKI_USE_RESULT Error removeDirectory(const CString& dir, GenericMemoryPoolAlloc
 ANKI_USE_RESULT Error createDirectory(const CString& dir);
 ANKI_USE_RESULT Error createDirectory(const CString& dir);
 
 
 /// Get the home directory.
 /// Get the home directory.
-/// Write the home directory to @a buff. The @a buffSize is the size of the @a buff. If the @buffSize is not enough the
-/// function will throw an exception.
 ANKI_USE_RESULT Error getHomeDirectory(StringAuto& out);
 ANKI_USE_RESULT Error getHomeDirectory(StringAuto& out);
 
 
+/// Get the temp directory.
+ANKI_USE_RESULT Error getTempDirectory(StringAuto& out);
+
 /// Get the time the file was last modified.
 /// Get the time the file was last modified.
 ANKI_USE_RESULT Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day, U32& hour, U32& min,
 ANKI_USE_RESULT Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day, U32& hour, U32& min,
 											  U32& second);
 											  U32& second);

+ 6 - 0
AnKi/Util/FilesystemPosix.cpp

@@ -209,6 +209,12 @@ Error getHomeDirectory(StringAuto& out)
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 
+Error getTempDirectory(StringAuto& out)
+{
+	out.create("/tmp/");
+	return Error::NONE;
+}
+
 Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day, U32& hour, U32& min, U32& second)
 Error getFileModificationTime(CString filename, U32& year, U32& month, U32& day, U32& hour, U32& min, U32& second)
 {
 {
 	struct stat buff;
 	struct stat buff;

+ 15 - 0
AnKi/Util/FilesystemWindows.cpp

@@ -79,6 +79,21 @@ Error getHomeDirectory(StringAuto& out)
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 
+Error getTempDirectory(StringAuto& out)
+{
+	char path[MAX_PATH + 1];
+
+	const DWORD len = GetTempPathA(sizeof(path), path);
+	if(len == 0)
+	{
+		ANKI_UTIL_LOGE("GetTempPathA() failed");
+		return Error::FUNCTION_FAILED;
+	}
+
+	out.create(path);
+	return Error::NONE;
+}
+
 static Error walkDirectoryTreeInternal(const CString& dir, void* userData, WalkDirectoryTreeCallback callback,
 static Error walkDirectoryTreeInternal(const CString& dir, void* userData, WalkDirectoryTreeCallback callback,
 									   U baseDirLen)
 									   U baseDirLen)
 {
 {

+ 6 - 0
AnKi/Util/Win32Minimal.h

@@ -100,6 +100,7 @@ ANKI_WINBASEAPI HRESULT ANKI_WINAPI SHGetFolderPathA(HWND hwnd, int csidl, HANDL
 ANKI_WINBASEAPI HANDLE ANKI_WINAPI FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
 ANKI_WINBASEAPI HANDLE ANKI_WINAPI FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
 ANKI_WINBASEAPI BOOL ANKI_WINAPI FindClose(HANDLE hFindFile);
 ANKI_WINBASEAPI BOOL ANKI_WINAPI FindClose(HANDLE hFindFile);
 ANKI_WINBASEAPI BOOL ANKI_WINAPI FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
 ANKI_WINBASEAPI BOOL ANKI_WINAPI FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
+ANKI_WINBASEAPI DWORD ANKI_WINAPI GetTempPathA(DWORD nBufferLength, LPSTR lpBuffer);
 
 
 // Other
 // Other
 ANKI_WINBASEAPI DWORD ANKI_WINAPI GetLastError(VOID);
 ANKI_WINBASEAPI DWORD ANKI_WINAPI GetLastError(VOID);
@@ -409,6 +410,11 @@ inline BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)
 	return ::FindNextFileA(hFindFile, reinterpret_cast<::LPWIN32_FIND_DATAA>(lpFindFileData));
 	return ::FindNextFileA(hFindFile, reinterpret_cast<::LPWIN32_FIND_DATAA>(lpFindFileData));
 }
 }
 
 
+inline DWORD GetTempPathA(DWORD nBufferLength, LPSTR lpBuffer)
+{
+	return ::GetTempPathA(nBufferLength, lpBuffer);
+}
+
 // Other
 // Other
 inline BOOL QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency)
 inline BOOL QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency)
 {
 {