diff --git a/AnKi/Gr/Common.h b/AnKi/Gr/Common.h index 26a09d27c..6d9afbb7f 100644 --- a/AnKi/Gr/Common.h +++ b/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) diff --git a/AnKi/ShaderCompiler/Dxc.cpp b/AnKi/ShaderCompiler/Dxc.cpp index 7f170dd2b..151372dd5 100644 --- a/AnKi/ShaderCompiler/Dxc.cpp +++ b/AnKi/ShaderCompiler/Dxc.cpp @@ -8,6 +8,7 @@ #include #include #include +#include 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& bin, - ShaderCompilerString& errorMessage) +static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, Bool spirv, + ShaderCompilerDynamicArray& bin, ShaderCompilerString& errorMessage) { Array 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 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 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& spirv, +Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray& 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& dxil, +Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray& dxil, ShaderCompilerString& errorMessage) { - return compileHlsl(src, shaderType, compileWith16bitTypes, false, dxil, errorMessage); + return compileHlsl(src, shaderType, compileWith16bitTypes, debugInfo, false, dxil, errorMessage); } } // end namespace anki diff --git a/AnKi/ShaderCompiler/Dxc.h b/AnKi/ShaderCompiler/Dxc.h index 6d442eb95..657597514 100644 --- a/AnKi/ShaderCompiler/Dxc.h +++ b/AnKi/ShaderCompiler/Dxc.h @@ -20,11 +20,11 @@ inline constexpr Array2d inline constexpr U32 kDxcVkBindlessRegisterSpace = 1000000; /// Compile HLSL to SPIR-V. -Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray& spirv, +Error compileHlslToSpirv(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray& spirv, ShaderCompilerString& errorMessage); /// Compile HLSL to DXIL. -Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, ShaderCompilerDynamicArray& dxil, +Error compileHlslToDxil(CString src, ShaderType shaderType, Bool compileWith16bitTypes, Bool debugInfo, ShaderCompilerDynamicArray& dxil, ShaderCompilerString& errorMessage); /// @} diff --git a/AnKi/ShaderCompiler/ShaderCompiler.cpp b/AnKi/ShaderCompiler/ShaderCompiler.cpp index 20171aea0..432a986b4 100644 --- a/AnKi/ShaderCompiler/ShaderCompiler.cpp +++ b/AnKi/ShaderCompiler/ShaderCompiler.cpp @@ -639,7 +639,7 @@ Error doReflectionDxil(ConstWeakArray 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& variants, ShaderCompilerDynamicArray& codeBlocks, ShaderCompilerDynamicArray& sourceCodeHashes, ShaderCompilerAsyncTaskInterface& taskManager, Mutex& mtx, Atomic& error) @@ -655,6 +655,7 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi Mutex* m_mtx; Atomic* m_err; Bool m_spirv; + Bool m_debugInfo; }; Ctx* ctx = newInstance(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(userData); @@ -736,11 +738,11 @@ static void compileVariantAsync(const ShaderParser& parser, Bool spirv, ShaderBi ShaderCompilerDynamicArray 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 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 codeBlocks; ShaderCompilerDynamicArray 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 defines, ShaderBinary*& binary) +Error compileShaderProgram(CString fname, Bool spirv, Bool debugInfo, ShaderCompilerFilesystemInterface& fsystem, + ShaderCompilerPostParseInterface* postParseCallback, ShaderCompilerAsyncTaskInterface* taskManager, + ConstWeakArray 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()); diff --git a/AnKi/ShaderCompiler/ShaderCompiler.h b/AnKi/ShaderCompiler/ShaderCompiler.h index 597c06893..c250b233b 100644 --- a/AnKi/ShaderCompiler/ShaderCompiler.h +++ b/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 defines, ShaderBinary*& binary); +Error compileShaderProgram(CString fname, Bool spirv, Bool debugInfo, ShaderCompilerFilesystemInterface& fsystem, + ShaderCompilerPostParseInterface* postParseCallback, ShaderCompilerAsyncTaskInterface* taskManager, + ConstWeakArray defines, ShaderBinary*& binary); /// Free the binary created ONLY by compileShaderProgram. void freeShaderBinary(ShaderBinary*& binary); diff --git a/AnKi/Util/String.h b/AnKi/Util/String.h index 59814368d..7b3c1407a 100644 --- a/AnKi/Util/String.h +++ b/AnKi/Util/String.h @@ -267,7 +267,7 @@ class CString 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 diff --git a/Tests/Gr/GrWorkGraphs.cpp b/Tests/Gr/GrWorkGraphs.cpp new file mode 100644 index 000000000..730c40f91 --- /dev/null +++ b/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 +#include +#include + +ANKI_TEST(Gr, WorkGraphsHelloWorld) +{ +} diff --git a/Tools/Shader/ShaderProgramCompilerMain.cpp b/Tools/Shader/ShaderProgramCompilerMain.cpp index 19dacca87..2c274131e 100644 --- a/Tools/Shader/ShaderProgramCompilerMain.cpp +++ b/Tools/Shader/ShaderProgramCompilerMain.cpp @@ -16,6 +16,7 @@ Usage: %s [options] input_shader_program_file -D : Extra defines to pass to the compiler -spirv : Compile SPIR-V -dxil : Compile DXIL +-g : Include debug info )"; class CmdLineArgs @@ -29,6 +30,7 @@ class CmdLineArgs DynamicArray 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 {