Panagiotis Christopoulos Charitos преди 2 години
родител
ревизия
75b815f6d3

+ 1 - 1
AnKi/Config.h.cmake

@@ -162,7 +162,7 @@
 #endif
 
 // Mobile or not
-#define ANKI_PLATFORM_MOBILE (ANKI_CPU_ARCH_ARM)
+#define ANKI_PLATFORM_MOBILE ${_ANKI_PLATFORM_MOBILE}
 
 // Some compiler attributes
 #if ANKI_COMPILER_GCC_COMPATIBLE

+ 5 - 2
AnKi/Renderer/ShadowmapsResolve.cpp

@@ -139,8 +139,11 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx)
 		rgraphCtx.bindColorTexture(0, 9, getRenderer().getRtShadows().getRt());
 	}
 
-	const Vec4 consts(F32(m_rtDescr.m_width), F32(m_rtDescr.m_height), 0.0f, 0.0f);
-	cmdb.setPushConstants(&consts, sizeof(consts));
+	if(g_preferComputeCVar.get() || g_shadowMappingPcfCVar.get())
+	{
+		const Vec4 consts(F32(m_rtDescr.m_width), F32(m_rtDescr.m_height), 0.0f, 0.0f);
+		cmdb.setPushConstants(&consts, sizeof(consts));
+	}
 
 	if(g_preferComputeCVar.get())
 	{

+ 1 - 1
AnKi/Resource/ResourceFilesystem.cpp

@@ -281,7 +281,7 @@ Error ResourceFilesystem::init()
 
 #if ANKI_OS_ANDROID
 	// Add the external storage
-	ANKI_CHECK(addNewPath(g_androidApp->activity->externalDataPath, excludedStrings));
+	ANKI_CHECK(addNewPath(g_androidApp->activity->externalDataPath, {}, {}));
 #endif
 
 	return Error::kNone;

+ 3 - 6
AnKi/ShaderCompiler/Common.h

@@ -64,15 +64,12 @@ public:
 	virtual Error joinTasks() = 0;
 };
 
-/// Options to be passed to the compiler.
-ANKI_BEGIN_PACKED_STRUCT
-class ShaderCompilerOptions
+class ShaderCompilerDefine
 {
 public:
-	Bool m_forceFullFloatingPointPrecision = false;
-	Bool m_mobilePlatform = false;
+	CString m_name;
+	I32 m_value;
 };
-ANKI_END_PACKED_STRUCT
 /// @}
 
 } // end namespace anki

+ 4 - 4
AnKi/ShaderCompiler/ShaderProgramCompiler.cpp

@@ -289,7 +289,7 @@ static void compileVariantAsync(const ShaderProgramParser& parser, ShaderProgram
 }
 
 Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem, ShaderProgramPostParseInterface* postParseCallback,
-								   ShaderProgramAsyncTaskInterface* taskManager_, const ShaderCompilerOptions& compilerOptions,
+								   ShaderProgramAsyncTaskInterface* taskManager_, ConstWeakArray<ShaderCompilerDefine> defines,
 								   ShaderProgramBinary*& binary)
 {
 	ShaderCompilerMemoryPool& memPool = ShaderCompilerMemoryPool::getSingleton();
@@ -299,7 +299,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 	memcpy(&binary->m_magic[0], kShaderBinaryMagic, 8);
 
 	// Parse source
-	ShaderProgramParser parser(fname, &fsystem, compilerOptions);
+	ShaderProgramParser parser(fname, &fsystem, defines);
 	ANKI_CHECK(parser.parse());
 
 	if(postParseCallback && postParseCallback->skipCompilation(parser.getHash()))
@@ -492,9 +492,9 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 }
 
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem, ShaderProgramPostParseInterface* postParseCallback,
-						   ShaderProgramAsyncTaskInterface* taskManager, const ShaderCompilerOptions& compilerOptions, ShaderProgramBinary*& binary)
+						   ShaderProgramAsyncTaskInterface* taskManager, ConstWeakArray<ShaderCompilerDefine> defines, ShaderProgramBinary*& binary)
 {
-	const Error err = compileShaderProgramInternal(fname, fsystem, postParseCallback, taskManager, compilerOptions, binary);
+	const Error err = compileShaderProgramInternal(fname, fsystem, postParseCallback, taskManager, defines, binary);
 	if(err)
 	{
 		ANKI_SHADER_COMPILER_LOGE("Failed to compile: %s", fname.cstr());

+ 1 - 1
AnKi/ShaderCompiler/ShaderProgramCompiler.h

@@ -41,7 +41,7 @@ inline Error deserializeShaderProgramBinaryFromFile(CString fname, ShaderProgram
 
 /// Takes an AnKi special shader program and spits a binary.
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem, ShaderProgramPostParseInterface* postParseCallback,
-						   ShaderProgramAsyncTaskInterface* taskManager, const ShaderCompilerOptions& compilerOptions, ShaderProgramBinary*& binary);
+						   ShaderProgramAsyncTaskInterface* taskManager, ConstWeakArray<ShaderCompilerDefine> defines, ShaderProgramBinary*& binary);
 
 /// Free the binary created ONLY by compileShaderProgram.
 void freeShaderProgramBinary(ShaderProgramBinary*& binary);

+ 14 - 11
AnKi/ShaderCompiler/ShaderProgramParser.cpp

@@ -20,15 +20,10 @@ inline constexpr Array<CString, U32(ShaderType::kCount)> kShaderStageNames = {{"
 																			   "ANY_HIT", "CLOSEST_HIT", "MISS", "INTERSECTION", "CALLABLE"}};
 
 inline constexpr char kShaderHeader[] = R"(#define ANKI_%s_SHADER 1
-#define ANKI_PLATFORM_MOBILE %d
-#define ANKI_FORCE_FULL_FP_PRECISION %d
-
 #define kMaxBindlessTextures %uu
 #define kMaxBindlessReadonlyTextureBuffers %uu
 )";
 
-static const U64 kShaderHeaderHash = computeHash(kShaderHeader, sizeof(kShaderHeader));
-
 static ShaderType strToShaderType(CString str)
 {
 	ShaderType shaderType = ShaderType::kCount;
@@ -95,11 +90,15 @@ static ShaderType strToShaderType(CString str)
 	return shaderType;
 }
 
-ShaderProgramParser::ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, const ShaderCompilerOptions& compilerOptions)
+ShaderProgramParser::ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, ConstWeakArray<ShaderCompilerDefine> defines)
 	: m_fname(fname)
 	, m_fsystem(fsystem)
-	, m_compilerOptions(compilerOptions)
 {
+	for(const ShaderCompilerDefine& def : defines)
+	{
+		m_defineNames.emplaceBack(def.m_name);
+		m_defineValues.emplaceBack(def.m_value);
+	}
 }
 
 ShaderProgramParser::~ShaderProgramParser()
@@ -838,10 +837,9 @@ Error ShaderProgramParser::parse()
 	return Error::kNone;
 }
 
-void ShaderProgramParser::generateAnkiShaderHeader(ShaderType shaderType, const ShaderCompilerOptions& compilerOptions, ShaderCompilerString& header)
+void ShaderProgramParser::generateAnkiShaderHeader(ShaderType shaderType, ShaderCompilerString& header)
 {
-	header.sprintf(kShaderHeader, kShaderStageNames[shaderType].cstr(), compilerOptions.m_mobilePlatform,
-				   compilerOptions.m_forceFullFloatingPointPrecision, kMaxBindlessTextures, kMaxBindlessReadonlyTextureBuffers);
+	header.sprintf(kShaderHeader, kShaderStageNames[shaderType].cstr(), kMaxBindlessTextures, kMaxBindlessReadonlyTextureBuffers);
 }
 
 void ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParserTechnique& technique, ShaderType shaderType,
@@ -860,6 +858,11 @@ void ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation,
 	ANKI_ASSERT(&technique >= m_techniques.getBegin() && &technique < m_techniques.getEnd());
 	const U32 tIdx = U32(&technique - m_techniques.getBegin());
 
+	for(U32 i = 0; i < m_defineNames.getSize(); ++i)
+	{
+		source += ShaderCompilerString().sprintf("#define %s %d\n", m_defineNames[i].cstr(), m_defineValues[i]);
+	}
+
 	for(U32 i = 0; i < mutation.getSize(); ++i)
 	{
 		if(!!(technique.m_activeMutators[shaderType] & (1_U64 << U64(i))))
@@ -871,7 +874,7 @@ void ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation,
 	source += ShaderCompilerString().sprintf("#define ANKI_TECHNIQUE_%s 1\n", technique.m_name.cstr());
 
 	ShaderCompilerString header;
-	generateAnkiShaderHeader(shaderType, m_compilerOptions, header);
+	generateAnkiShaderHeader(shaderType, header);
 	source += header;
 
 	if(m_16bitTypes)

+ 5 - 3
AnKi/ShaderCompiler/ShaderProgramParser.h

@@ -74,7 +74,7 @@ public:
 class ShaderProgramParser
 {
 public:
-	ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, const ShaderCompilerOptions& compilerOptions);
+	ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, ConstWeakArray<ShaderCompilerDefine> defines);
 
 	ShaderProgramParser(const ShaderProgramParser&) = delete; // Non-copyable
 
@@ -119,7 +119,7 @@ public:
 	}
 
 	/// Generates the common header that will be used by all AnKi shaders.
-	static void generateAnkiShaderHeader(ShaderType shaderType, const ShaderCompilerOptions& compilerOptions, ShaderCompilerString& header);
+	static void generateAnkiShaderHeader(ShaderType shaderType, ShaderCompilerString& header);
 
 private:
 	using Mutator = ShaderProgramParserMutator;
@@ -144,7 +144,9 @@ private:
 
 	ShaderCompilerString m_fname;
 	ShaderProgramFilesystemInterface* m_fsystem = nullptr;
-	ShaderCompilerOptions m_compilerOptions;
+
+	ShaderCompilerDynamicArray<ShaderCompilerString> m_defineNames;
+	ShaderCompilerDynamicArray<I32> m_defineValues;
 
 	U64 m_hash = 0;
 

+ 4 - 2
AnKi/Shaders/CMakeLists.txt

@@ -20,16 +20,18 @@ endif()
 
 if(ANDROID OR ARM)
 	message("++ Compiling shaders for mobile")
-	set(extra_compiler_args "-mobile-platform")
+	set(extra_compiler_args "-DANKI_PLATFORM_MOBILE=1")
 else()
 	message("++ Compiling shaders for desktop")
+	set(extra_compiler_args "-DANKI_PLATFORM_MOBILE=0")
 endif()
 
 if(ANKI_SHADER_FULL_PRECISION)
 	message("++ Forcing full shader precision")
-	set(extra_compiler_args ${extra_compiler_args} "-force-full-fp")
+	set(extra_compiler_args ${extra_compiler_args} "-DANKI_FORCE_FULL_FP_PRECISION=1")
 else()
 	message("++ Leaving default shader precision")
+	set(extra_compiler_args ${extra_compiler_args} "-DANKI_FORCE_FULL_FP_PRECISION=0")
 endif()
 
 include(FindPythonInterp)

+ 7 - 0
AnKi/Util/BlockArray.h

@@ -323,6 +323,13 @@ private:
 	{
 	public:
 		Mask m_elementsInUseMask{false};
+
+		BlockMetadata() = default;
+
+		BlockMetadata(Bool set)
+			: m_elementsInUseMask(set)
+		{
+		}
 	};
 
 	DynamicArray<BlockStorage*, TMemoryPool> m_blockStorages;

+ 3 - 1
AnKi/Window/NativeWindowHeadless.cpp

@@ -34,7 +34,9 @@ void MakeSingletonPtr<NativeWindow>::freeSingleton()
 
 Error NativeWindow::init([[maybe_unused]] const NativeWindowInitInfo& inf)
 {
-	// Nothing
+	// Nothing important
+	m_width = inf.m_width;
+	m_height = inf.m_height;
 	return Error::kNone;
 }
 

+ 13 - 0
CMakeLists.txt

@@ -150,6 +150,11 @@ option(ANKI_HEADLESS "Build a headless application" OFF)
 option(ANKI_SHADER_FULL_PRECISION "Build shaders with full precision" OFF)
 set(ANKI_OVERRIDE_SHADER_COMPILER "" CACHE FILEPATH "Set the ShaderCompiler to be used to compile all shaders")
 option(ANKI_DLSS "Integrate DLSS if supported" OFF)
+if(ANDROID)
+	option(ANKI_PLATFORM_MOBILE "Build for a mobile platform" ON)
+else()
+	option(ANKI_PLATFORM_MOBILE "Build for a mobile platform" OFF)
+endif()
 
 # Take a wild guess on the windowing system
 if(ANKI_HEADLESS)
@@ -410,6 +415,14 @@ else()
 	set(_ANKI_WINDOWING_SYSTEM 2)
 endif()
 
+if(ANKI_PLATFORM_MOBILE)
+	message("++ Compiling for a mobile platform")
+	set(_ANKI_PLATFORM_MOBILE 1)
+else()
+	message("++ NOT compiling for a mobile platform")
+	set(_ANKI_PLATFORM_MOBILE 0)
+endif()
+
 configure_file("AnKi/Config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/AnKi/Config.h")
 
 # Include & lib directories

+ 1 - 1
Tools/Android/app/build.gradle

@@ -4,7 +4,7 @@ plugins {
 
 android {
     compileSdk 32
-	ndkVersion "25.1.8937393"
+	ndkVersion "26.1.10909125"
 
     externalNativeBuild {
         cmake {

+ 30 - 16
Tools/Shader/ShaderProgramCompilerMain.cpp

@@ -13,8 +13,7 @@ Options:
 -o <name of output>  : The name of the output binary
 -j <thread count>    : Number of threads. Defaults to system's max
 -I <include path>    : The path of the #include files
--force-full-fp       : Force full floating point precision
--mobile-platform     : Build for mobile
+-D<define_name:val>  : Extra defines to pass to the compiler
 )";
 
 class CmdLineArgs
@@ -24,8 +23,8 @@ public:
 	String m_outFname;
 	String m_includePath;
 	U32 m_threadCount = getCpuCoresCount();
-	Bool m_fullFpPrecision = false;
-	Bool m_mobilePlatform = false;
+	DynamicArray<String> m_defineNames;
+	DynamicArray<ShaderCompilerDefine> m_defines;
 };
 
 static Error parseCommandLineArgs(int argc, char** argv, CmdLineArgs& info)
@@ -91,13 +90,33 @@ static Error parseCommandLineArgs(int argc, char** argv, CmdLineArgs& info)
 				return Error::kUserData;
 			}
 		}
-		else if(strcmp(argv[i], "-force-full-fp") == 0)
+		else if(CString(argv[i]).find("-D") == 0)
 		{
-			info.m_fullFpPrecision = true;
-		}
-		else if(strcmp(argv[i], "-mobile-platform") == 0)
-		{
-			info.m_mobilePlatform = true;
+			CString a = argv[i];
+			if(a.getLength() < 5)
+			{
+				return Error::kUserData;
+			}
+
+			const String arg(a.getBegin() + 2, a.getEnd());
+			StringList tokens;
+			tokens.splitString(arg, '=');
+
+			if(tokens.getSize() != 2)
+			{
+				return Error::kUserData;
+			}
+
+			info.m_defineNames.emplaceBack(tokens.getFront());
+
+			I32 val;
+			const Error err = (tokens.getBegin() + 1)->toNumber(val);
+			if(err)
+			{
+				return Error::kUserData;
+			}
+
+			info.m_defines.emplaceBack(ShaderCompilerDefine{info.m_defineNames.getBack().toCString(), val});
 		}
 		else
 		{
@@ -177,14 +196,9 @@ static Error work(const CmdLineArgs& info)
 	taskManager.m_jobManager.reset((info.m_threadCount) ? newInstance<ThreadJobManager>(DefaultMemoryPool::getSingleton(), info.m_threadCount, true)
 														: nullptr);
 
-	// Compiler options
-	ShaderCompilerOptions compilerOptions;
-	compilerOptions.m_forceFullFloatingPointPrecision = info.m_fullFpPrecision;
-	compilerOptions.m_mobilePlatform = info.m_mobilePlatform;
-
 	// Compile
 	ShaderProgramBinary* binary = nullptr;
-	ANKI_CHECK(compileShaderProgram(info.m_inputFname, fsystem, nullptr, (info.m_threadCount) ? &taskManager : nullptr, compilerOptions, binary));
+	ANKI_CHECK(compileShaderProgram(info.m_inputFname, fsystem, nullptr, (info.m_threadCount) ? &taskManager : nullptr, info.m_defines, binary));
 
 	class Dummy
 	{