diff --git a/.gitignore b/.gitignore index f46b7d2d..cec2c293 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ Framework/Externals/slang/source/**/*.natvis !Framework/Externals/slang/source/**/*.cpp !Framework/Externals/slang/source/**/*.cpp !Framework/Externals/slang/source/**/*.h + +# Ignore intermediate files that Slang dumps when +# we ask it to preserve intermedites +slang-dump* \ No newline at end of file diff --git a/Framework/Source/FalcorConfig.h b/Framework/Source/FalcorConfig.h index 3e136510..894c8f65 100644 --- a/Framework/Source/FalcorConfig.h +++ b/Framework/Source/FalcorConfig.h @@ -39,9 +39,5 @@ #define _ENABLE_NVAPI false // Controls NVIDIA specific DX extensions. If it is set to true, make sure you have the NVAPI package in your 'Externals' directory. View the readme for more information -#define FALCOR_BUILD_SPIRE 1 /* Set this to 1 to enable Slang compiler to be built into Falcor */ -#define FALCOR_USE_SLANG_AS_PREPROCESSOR 0 /* Set this to 1 to use Slang as a source-to-source preprocessor */ - -#if (FALCOR_USE_SLANG_AS_PREPROCESSOR) && !FALCOR_BUILD_SPIRE -#error Trying to use Slang without building it -#endif +#define FALCOR_SLANG_DISABLE_LINE_DIRECTIVES 0 /* Set this to 1 to disable emission of `#line` directives in Slang-generated code */ +#define FALCOR_SLANG_DUMP_COMPILER_INTERMEDIATES 0 /* Set this to 1 to enable dumping of intermediate code generated by Slang to disk */ diff --git a/Framework/Source/Graphics/Program.cpp b/Framework/Source/Graphics/Program.cpp index dade55be..50b3d2be 100644 --- a/Framework/Source/Graphics/Program.cpp +++ b/Framework/Source/Graphics/Program.cpp @@ -328,6 +328,29 @@ namespace Falcor slangFlags |= SLANG_COMPILE_FLAG_NO_CHECKING; spSetCompileFlags(slangRequest, slangFlags); + // Enable this block to disable the emission of `#line` directives + // and hopefully make the HLSL/GLSL output by Slang a bit more + // readable. + // + // This is useful for diagnosing issues where Slang outputs bogus + // code and you need to isolate what Slang is doing wrong. + // + // This is way less useful if the user's code has a legitimate + // issue in it, because it will be reported at a location + // unrelated to the code they wrote. That is why it is off by default. +#if FALCOR_SLANG_DISABLE_LINE_DIRECTIVES + spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE); +#endif + + // Enable this block to make Slang dump intermediate HLSL/GLSL + // and DXBC/SPIR-V (both binary and assembly) for every shader + // it compiles. These will be dumped to the current working + // directory and named `slang-dump-*.{glsl,hlsl,spv,dxbc,spv.asm,dxbc.asm} +#if FALCOR_SLANG_DUMP_COMPILER_INTERMEDIATES + spSetDumpIntermediates(slangRequest, true); +#endif + + // Now lets add all our input shader code, one-by-one int translationUnitsAdded = 0; for(auto source : mDesc.mSources)