From aec7b58c39d369ccce23e28742989c1ef16575f5 Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Thu, 10 Feb 2022 02:27:49 -0700 Subject: [PATCH] Introduce Atom/GraphicsDevMode settings registry key When `"Atom": {"GraphicsDevMode": true}` is found in a `.setreg` file, PDBs for all shaders will be emitted to their corresponding output locations. This allows global PDB generation without needing to explicitly modify each `.shader` file to include the `GenerateDebugInfo` compilation option. Signed-off-by: Jeremy Ong --- .../Editor/AzslShaderBuilderSystemComponent.cpp | 2 +- Gems/Atom/RHI/Code/Include/Atom/RHI/RHIUtils.h | 3 +++ Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp | 14 ++++++++++++++ .../RHI.Builders/ShaderPlatformInterface.cpp | 10 ++++++---- .../RHI.Builders/ShaderPlatformInterface.cpp | 7 +++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp index 7e510e2e3a..43d67cc95c 100644 --- a/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp +++ b/Gems/Atom/Asset/Shader/Code/Source/Editor/AzslShaderBuilderSystemComponent.cpp @@ -82,7 +82,7 @@ namespace AZ // Register Shader Asset Builder AssetBuilderSDK::AssetBuilderDesc shaderAssetBuilderDescriptor; shaderAssetBuilderDescriptor.m_name = "Shader Asset Builder"; - shaderAssetBuilderDescriptor.m_version = 110; // Add "Definitions" field to shader asset to support convenient addition of preprocessor definitions + shaderAssetBuilderDescriptor.m_version = 111; // Enable shader PDB generation globally if Atom/GraphicsDevMode settings registry key is set shaderAssetBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern( AZStd::string::format("*.%s", RPI::ShaderSourceData::Extension), AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard)); shaderAssetBuilderDescriptor.m_busId = azrtti_typeid(); shaderAssetBuilderDescriptor.m_createJobFunction = AZStd::bind(&ShaderAssetBuilder::CreateJobs, &m_shaderAssetBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2); diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/RHIUtils.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/RHIUtils.h index 73e8e1ad56..48a041ad7d 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/RHIUtils.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/RHIUtils.h @@ -42,6 +42,9 @@ namespace AZ //! Returns if the current bakcend is a null renderer bool IsNullRenderer(); + + //! Returns true if the Atom/GraphicsDevMode settings registry key is set + bool IsGraphicsDevModeEnabled(); } } diff --git a/Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp b/Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp index bc4cde9406..de27f4ce18 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp @@ -9,9 +9,12 @@ #include #include #include +#include #include #include +static constexpr char GraphicsDevModeSetting[] = "/Atom/GraphicsDevMode"; + namespace AZ { namespace RHI @@ -134,5 +137,16 @@ namespace AZ } return false; } + + bool IsGraphicsDevModeEnabled() + { + AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get(); + bool graphicsDevMode = false; + if (settingsRegistry) + { + settingsRegistry->Get(graphicsDevMode, GraphicsDevModeSetting); + } + return graphicsDevMode; + } } } diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp index ee293292e1..287c8e4fd5 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp @@ -12,10 +12,10 @@ #include #include #include +#include #include #include - #include namespace AZ @@ -253,9 +253,11 @@ namespace AZ return false; } + const bool graphicsDevMode = RHI::IsGraphicsDevModeEnabled(); + // Compilation parameters AZStd::string params = shaderCompilerArguments.MakeAdditionalDxcCommandLineString(); - if (BuildHasDebugInfo(shaderCompilerArguments)) + if (graphicsDevMode || BuildHasDebugInfo(shaderCompilerArguments)) { params += " -Zi"; // Generate debug information params += " -Zss"; // Compute Shader Hash considering source information @@ -284,7 +286,7 @@ namespace AZ // If we use the auto-name (hash), there is no way we can retrieve that name apart from listing the directory. // Instead, let's just generate that hash ourselves. AZStd::string symbolDatabaseFileCliArgument{" "}; // when not debug: still insert a space between 5.dxil and 7.hlsl-in - if (BuildHasDebugInfo(shaderCompilerArguments)) + if (graphicsDevMode || BuildHasDebugInfo(shaderCompilerArguments)) { // prepare .pdb filename: AZStd::string md5hex = RHI::ByteToHexString(md5); @@ -353,7 +355,7 @@ namespace AZ byProducts.m_dynamicBranchCount = ByProducts::UnknownDynamicBranchCount; } - if (BuildHasDebugInfo(shaderCompilerArguments)) + if (graphicsDevMode || BuildHasDebugInfo(shaderCompilerArguments)) { byProducts.m_intermediatePaths.emplace(AZStd::move(objectCodeOutputFile)); } diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp index c5f1060ca3..f5716f384f 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Builders/ShaderPlatformInterface.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -281,7 +282,9 @@ namespace AZ args.m_destinationFolder = tempFolder.c_str(); const auto dxcInputFile = RHI::PrependFile(args); // Prepend header - if (BuildHasDebugInfo(shaderCompilerArguments)) + const bool graphicsDevMode = RHI::IsGraphicsDevModeEnabled(); + + if (graphicsDevMode || BuildHasDebugInfo(shaderCompilerArguments)) { // dump intermediate "true final HLSL" file (shadername.vulkan.shadersource.prepend) byProducts.m_intermediatePaths.insert(dxcInputFile); @@ -334,7 +337,7 @@ namespace AZ byProducts.m_dynamicBranchCount = ByProducts::UnknownDynamicBranchCount; } - if (BuildHasDebugInfo(shaderCompilerArguments)) + if (graphicsDevMode || BuildHasDebugInfo(shaderCompilerArguments)) { byProducts.m_intermediatePaths.emplace(AZStd::move(objectCodeOutputFile)); }