Browse Source

D3D: Minor workgraph stuff

Panagiotis Christopoulos Charitos 1 year ago
parent
commit
0e27348c9d

+ 3 - 1
AnKi/Gr/Common.h

@@ -556,6 +556,7 @@ enum class ShaderType : U16
 	kMiss,
 	kIntersection,
 	kCallable,
+	kWorkgraph,
 
 	kCount,
 	kFirst = 0,
@@ -583,6 +584,7 @@ enum class ShaderTypeBit : U16
 	kMiss = 1 << 11,
 	kIntersection = 1 << 12,
 	kCallable = 1 << 13,
+	kWorkgraph = 1 << 14,
 
 	kNone = 0,
 	kAllGraphics = kVertex | kTessellationControl | kTessellationEvaluation | kGeometry | kTask | kMesh | kFragment,
@@ -590,7 +592,7 @@ enum class ShaderTypeBit : U16
 	kAllModernGeometry = kTask | kMesh,
 	kAllRayTracing = kRayGen | kAnyHit | kClosestHit | kMiss | kIntersection | kCallable,
 	kAllHit = kAnyHit | kClosestHit,
-	kAll = kAllGraphics | kCompute | kAllRayTracing,
+	kAll = kAllGraphics | kCompute | kAllRayTracing | kWorkgraph,
 };
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderTypeBit)
 

+ 38 - 22
AnKi/ShaderCompiler/Dxc.cpp

@@ -8,6 +8,7 @@
 #include <AnKi/Util/Filesystem.h>
 #include <AnKi/Util/File.h>
 #include <AnKi/Util/HighRezTimer.h>
+#include <AnKi/Util/StringList.h>
 
 namespace anki {
 
@@ -18,28 +19,28 @@ static CString profile(ShaderType shaderType)
 	switch(shaderType)
 	{
 	case ShaderType::kVertex:
-		return "vs_6_7";
+		return "vs_6_8";
 		break;
 	case ShaderType::kFragment:
-		return "ps_6_7";
+		return "ps_6_8";
 		break;
 	case ShaderType::kTessellationEvaluation:
-		return "ds_6_7";
+		return "ds_6_8";
 		break;
 	case ShaderType::kTessellationControl:
-		return "ds_6_7";
+		return "ds_6_8";
 		break;
 	case ShaderType::kGeometry:
-		return "gs_6_7";
+		return "gs_6_8";
 		break;
 	case ShaderType::kTask:
-		return "as_6_7";
+		return "as_6_8";
 		break;
 	case ShaderType::kMesh:
-		return "ms_6_7";
+		return "ms_6_8";
 		break;
 	case ShaderType::kCompute:
-		return "cs_6_7";
+		return "cs_6_8";
 		break;
 	case ShaderType::kRayGen:
 	case ShaderType::kAnyHit:
@@ -47,7 +48,8 @@ static CString profile(ShaderType shaderType)
 	case ShaderType::kMiss:
 	case ShaderType::kIntersection:
 	case ShaderType::kCallable:
-		return "lib_6_7";
+	case ShaderType::kWorkgraph:
+		return "lib_6_8";
 		break;
 	default:
 		ANKI_ASSERT(0);
@@ -56,8 +58,8 @@ static CString profile(ShaderType shaderType)
 	return "";
 }
 
-static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool spirv, ShaderCompilerDynamicArray<U8>& bin,
-						 ShaderCompilerString& errorMessage)
+static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, Bool spirv,
+						 ShaderCompilerDynamicArray<U8>& bin, ShaderCompilerString& errorMessage)
 {
 	Array<U64, 3> toHash = {g_nextFileId.fetchAdd(1), getCurrentProcessId(), getRandom() & kMaxU32};
 	const U64 rand = computeHash(&toHash[0], sizeof(toHash));
@@ -79,7 +81,7 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 	ShaderCompilerString binFilename;
 	binFilename.sprintf("%s/%" PRIu64 ".spvdxil", tmpDir.cstr(), rand);
 
-	ShaderCompilerDynamicArray<ShaderCompilerString> dxcArgs;
+	ShaderCompilerStringList dxcArgs;
 	dxcArgs.emplaceBack("-Fo");
 	dxcArgs.emplaceBack(binFilename);
 	dxcArgs.emplaceBack("-Wall");
@@ -97,10 +99,12 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 	dxcArgs.emplaceBack("main");
 	dxcArgs.emplaceBack("-T");
 	dxcArgs.emplaceBack(profile(shaderType));
+
 	if(ANKI_COMPILER_MSVC)
 	{
 		dxcArgs.emplaceBack("-fdiagnostics-format=msvc"); // Make errors clickable in visual studio
 	}
+
 	if(spirv)
 	{
 		dxcArgs.emplaceBack("-spirv");
@@ -129,10 +133,15 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 	}
 	else
 	{
-		dxcArgs.emplaceBack("-Wno-ignored-attributes"); // TODO rm that eventually
-		dxcArgs.emplaceBack("-Wno-inline-asm"); // TODO rm that eventually
+		dxcArgs.emplaceBack("-Wno-ignored-attributes"); // TODO remove that at some point
+		dxcArgs.emplaceBack("-Wno-inline-asm"); // Workaround a DXC bug
+	}
+
+	if(debugInfo)
+	{
+		dxcArgs.emplaceBack("-Zi");
 	}
-	// dxcArgs.emplaceBack("-Zi"); // Debug info
+
 	dxcArgs.emplaceBack(hlslFilename);
 
 	if(compileWith16bitTypes)
@@ -141,10 +150,11 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 	}
 
 	ShaderCompilerDynamicArray<CString> dxcArgs2;
-	dxcArgs2.resize(dxcArgs.getSize());
-	for(U32 i = 0; i < dxcArgs.getSize(); ++i)
+	dxcArgs2.resize(U32(dxcArgs.getSize()));
+	U32 count = 0;
+	for(auto& it : dxcArgs)
 	{
-		dxcArgs2[i] = dxcArgs[i];
+		dxcArgs2[count++] = it.cstr();
 	}
 
 	while(true)
@@ -171,6 +181,12 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 			(void)err; // Shoudn't throw an error
 			errorMessage = errorMessageTmp;
 
+			ShaderCompilerString args;
+			dxcArgs.join(" ", args);
+			errorMessage += " (";
+			errorMessage += args;
+			errorMessage += ")";
+
 			if(!errorMessage.isEmpty() && errorMessage.find("The process cannot access the file because") != CString::kNpos)
 			{
 				// DXC might fail to read the HLSL because the antivirus might be having a lock on it. Try again
@@ -206,16 +222,16 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b
 	return Error::kNone;
 }
 
-Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray<U8>& spirv,
+Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray<U8>& spirv,
 						 ShaderCompilerString& errorMessage)
 {
-	return compileHlsl(src, shaderType, compileWith16bitTypes, true, spirv, errorMessage);
+	return compileHlsl(src, shaderType, compileWith16bitTypes, debugInfo, true, spirv, errorMessage);
 }
 
-Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray<U8>& dxil,
+Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray<U8>& dxil,
 						ShaderCompilerString& errorMessage)
 {
-	return compileHlsl(src, shaderType, compileWith16bitTypes, false, dxil, errorMessage);
+	return compileHlsl(src, shaderType, compileWith16bitTypes, debugInfo, false, dxil, errorMessage);
 }
 
 } // end namespace anki

+ 2 - 2
AnKi/ShaderCompiler/Dxc.h

@@ -20,11 +20,11 @@ inline constexpr Array2d<U32, kMaxDescriptorSets, U32(HlslResourceType::kCount)>
 inline constexpr U32 kDxcVkBindlessRegisterSpace = 1000000;
 
 /// Compile HLSL to SPIR-V.
-Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray<U8>& spirv,
+Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray<U8>& spirv,
 						 ShaderCompilerString& errorMessage);
 
 /// Compile HLSL to DXIL.
-Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray<U8>& dxil,
+Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray<U8>& dxil,
 						ShaderCompilerString& errorMessage);
 /// @}
 

+ 12 - 9
AnKi/ShaderCompiler/ShaderCompiler.cpp

@@ -639,7 +639,7 @@ Error doReflectionDxil(ConstWeakArray<U8> dxil, ShaderType type, ShaderReflectio
 }
 #endif // #if ANKI_DIXL_REFLECTION
 
-static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBinaryMutation& mutation,
+static void compileVariantAsync(const ShaderParser& parser, Bool spirv, Bool debugInfo, ShaderBinaryMutation& mutation,
 								ShaderCompilerDynamicArray<ShaderBinaryVariant>& variants,
 								ShaderCompilerDynamicArray<ShaderBinaryCodeBlock>& codeBlocks, ShaderCompilerDynamicArray<U64>& sourceCodeHashes,
 								ShaderCompilerAsyncTaskInterface& taskManager, Mutex& mtx, Atomic<I32>& error)
@@ -655,6 +655,7 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi
 		Mutex* m_mtx;
 		Atomic<I32>* m_err;
 		Bool m_spirv;
+		Bool m_debugInfo;
 	};
 
 	Ctx* ctx = newInstance<Ctx>(ShaderCompilerMemoryPool::getSingleton());
@@ -666,6 +667,7 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi
 	ctx->m_mtx = &mtx;
 	ctx->m_err = &error;
 	ctx->m_spirv = spirv;
+	ctx->m_debugInfo = debugInfo;
 
 	auto callback = [](void* userData) {
 		Ctx& ctx = *static_cast<Ctx*>(userData);
@@ -736,11 +738,11 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi
 				ShaderCompilerDynamicArray<U8> il;
 				if(ctx.m_spirv)
 				{
-					err = compileHlslToSpirv(source, shaderType, ctx.m_parser->compileWith16bitTypes(), il, compilerErrorLog);
+					err = compileHlslToSpirv(source, shaderType, ctx.m_parser->compileWith16bitTypes(), ctx.m_debugInfo, il, compilerErrorLog);
 				}
 				else
 				{
-					err = compileHlslToDxil(source, shaderType, ctx.m_parser->compileWith16bitTypes(), il, compilerErrorLog);
+					err = compileHlslToDxil(source, shaderType, ctx.m_parser->compileWith16bitTypes(), ctx.m_debugInfo, il, compilerErrorLog);
 				}
 
 				if(err)
@@ -864,7 +866,7 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi
 	taskManager.enqueueTask(callback, ctx);
 }
 
-static Error compileShaderProgramInternal(CString fname, Bool spirv, ShaderCompilerFilesystemInterface& fsystem,
+static Error compileShaderProgramInternal(CString fname, Bool spirv, Bool debugInfo, ShaderCompilerFilesystemInterface& fsystem,
 										  ShaderCompilerPostParseInterface* postParseCallback, ShaderCompilerAsyncTaskInterface* taskManager_,
 										  ConstWeakArray<ShaderCompilerDefine> defines_, ShaderBinary*& binary)
 {
@@ -980,7 +982,7 @@ static Error compileShaderProgramInternal(CString fname, Bool spirv, ShaderCompi
 			{
 				// New and unique mutation and thus variant, add it
 
-				compileVariantAsync(parser, spirv, mutation, variants, codeBlocks, sourceCodeHashes, taskManager, mtx, errorAtomic);
+				compileVariantAsync(parser, spirv, debugInfo, mutation, variants, codeBlocks, sourceCodeHashes, taskManager, mtx, errorAtomic);
 
 				ANKI_ASSERT(mutationHashToIdx.find(mutation.m_hash) == mutationHashToIdx.getEnd());
 				mutationHashToIdx.emplace(mutation.m_hash, mutationCount - 1);
@@ -1007,7 +1009,7 @@ static Error compileShaderProgramInternal(CString fname, Bool spirv, ShaderCompi
 		ShaderCompilerDynamicArray<ShaderBinaryCodeBlock> codeBlocks;
 		ShaderCompilerDynamicArray<U64> sourceCodeHashes;
 
-		compileVariantAsync(parser, spirv, binary->m_mutations[0], variants, codeBlocks, sourceCodeHashes, taskManager, mtx, errorAtomic);
+		compileVariantAsync(parser, spirv, debugInfo, binary->m_mutations[0], variants, codeBlocks, sourceCodeHashes, taskManager, mtx, errorAtomic);
 
 		ANKI_CHECK(taskManager.joinTasks());
 		ANKI_CHECK(Error(errorAtomic.getNonAtomically()));
@@ -1072,10 +1074,11 @@ static Error compileShaderProgramInternal(CString fname, Bool spirv, ShaderCompi
 	return Error::kNone;
 }
 
-Error compileShaderProgram(CString fname, Bool spirv, ShaderCompilerFilesystemInterface& fsystem, ShaderCompilerPostParseInterface* postParseCallback,
-						   ShaderCompilerAsyncTaskInterface* taskManager, ConstWeakArray<ShaderCompilerDefine> defines, ShaderBinary*& binary)
+Error compileShaderProgram(CString fname, Bool spirv, Bool debugInfo, ShaderCompilerFilesystemInterface& fsystem,
+						   ShaderCompilerPostParseInterface* postParseCallback, ShaderCompilerAsyncTaskInterface* taskManager,
+						   ConstWeakArray<ShaderCompilerDefine> defines, ShaderBinary*& binary)
 {
-	const Error err = compileShaderProgramInternal(fname, spirv, fsystem, postParseCallback, taskManager, defines, binary);
+	const Error err = compileShaderProgramInternal(fname, spirv, debugInfo, fsystem, postParseCallback, taskManager, defines, binary);
 	if(err)
 	{
 		ANKI_SHADER_COMPILER_LOGE("Failed to compile: %s", fname.cstr());

+ 3 - 2
AnKi/ShaderCompiler/ShaderCompiler.h

@@ -40,8 +40,9 @@ inline Error deserializeShaderBinaryFromFile(CString fname, ShaderBinary*& binar
 }
 
 /// Takes an AnKi special shader program and spits a binary.
-Error compileShaderProgram(CString fname, Bool spirv, ShaderCompilerFilesystemInterface& fsystem, ShaderCompilerPostParseInterface* postParseCallback,
-						   ShaderCompilerAsyncTaskInterface* taskManager, ConstWeakArray<ShaderCompilerDefine> defines, ShaderBinary*& binary);
+Error compileShaderProgram(CString fname, Bool spirv, Bool debugInfo, ShaderCompilerFilesystemInterface& fsystem,
+						   ShaderCompilerPostParseInterface* postParseCallback, ShaderCompilerAsyncTaskInterface* taskManager,
+						   ConstWeakArray<ShaderCompilerDefine> defines, ShaderBinary*& binary);
 
 /// Free the binary created ONLY by compileShaderProgram.
 void freeShaderBinary(ShaderBinary*& binary);

+ 1 - 1
AnKi/Util/String.h

@@ -267,7 +267,7 @@ public:
 		if(len > 0)
 		{
 			PtrSize outSize;
-			[[maybe_unused]] const errno_t err = mbstowcs_s(&outSize, arr, arrSize, m_ptr, len);
+			[[maybe_unused]] const auto err = mbstowcs_s(&outSize, arr, arrSize, m_ptr, len);
 			ANKI_ASSERT(err == 0 && outSize == len + 1);
 		}
 		else

+ 12 - 0
Tests/Gr/GrWorkGraphs.cpp

@@ -0,0 +1,12 @@
+// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <Tests/Framework/Framework.h>
+#include <Tests/Gr/GrCommon.h>
+#include <AnKi/Gr.h>
+
+ANKI_TEST(Gr, WorkGraphsHelloWorld)
+{
+}

+ 8 - 2
Tools/Shader/ShaderProgramCompilerMain.cpp

@@ -16,6 +16,7 @@ Options:
 -D<define_name:val>  : Extra defines to pass to the compiler
 -spirv               : Compile SPIR-V
 -dxil                : Compile DXIL
+-g                   : Include debug info
 )";
 
 class CmdLineArgs
@@ -29,6 +30,7 @@ public:
 	DynamicArray<ShaderCompilerDefine> m_defines;
 	Bool m_spirv = false;
 	Bool m_dxil = false;
+	Bool m_debugInfo = false;
 };
 
 static Error parseCommandLineArgs(int argc, char** argv, CmdLineArgs& info)
@@ -130,6 +132,10 @@ static Error parseCommandLineArgs(int argc, char** argv, CmdLineArgs& info)
 		{
 			info.m_dxil = true;
 		}
+		else if(strcmp(argv[i], "-g") == 0)
+		{
+			info.m_debugInfo = true;
+		}
 		else
 		{
 			return Error::kUserData;
@@ -210,8 +216,8 @@ static Error work(const CmdLineArgs& info)
 
 	// Compile
 	ShaderBinary* binary = nullptr;
-	ANKI_CHECK(compileShaderProgram(info.m_inputFname, info.m_spirv, fsystem, nullptr, (info.m_threadCount) ? &taskManager : nullptr, info.m_defines,
-									binary));
+	ANKI_CHECK(compileShaderProgram(info.m_inputFname, info.m_spirv, info.m_debugInfo, fsystem, nullptr,
+									(info.m_threadCount) ? &taskManager : nullptr, info.m_defines, binary));
 
 	class Dummy
 	{