From 856086cf2ac6fb1544b5b08ffa64b2f01931d35c Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 4 Aug 2023 15:55:06 -0700 Subject: Add option to use original entrypoint in spirv output. (#3047) * Add option to use original entrypoint in spirv output. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-compiler.cpp | 15 +++++++++++---- source/slang/slang-hlsl-to-vulkan-layout-options.h | 7 +++++++ source/slang/slang-options.cpp | 9 +++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 4e1ab8e98..12e96d7bb 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1222,11 +1222,18 @@ namespace Slang auto entryPoint = getEntryPoint(entryPointIndex); profile = getEffectiveProfile(entryPoint, targetReq); - options.entryPointName = allocator.allocate(getText(entryPoint->getName())); - auto entryPointNameOverride = getProgram()->getEntryPointNameOverride(entryPointIndex); - if (entryPointNameOverride.getLength() != 0) + if (getTargetReq()->getHLSLToVulkanLayoutOptions() && !getTargetReq()->getHLSLToVulkanLayoutOptions()->getUseOriginalEntryPointName()) { - options.entryPointName = allocator.allocate(entryPointNameOverride); + } + else + { + + options.entryPointName = allocator.allocate(getText(entryPoint->getName())); + auto entryPointNameOverride = getProgram()->getEntryPointNameOverride(entryPointIndex); + if (entryPointNameOverride.getLength() != 0) + { + options.entryPointName = allocator.allocate(entryPointNameOverride); + } } } else diff --git a/source/slang/slang-hlsl-to-vulkan-layout-options.h b/source/slang/slang-hlsl-to-vulkan-layout-options.h index 4ae169d90..2d24dfccb 100644 --- a/source/slang/slang-hlsl-to-vulkan-layout-options.h +++ b/source/slang/slang-hlsl-to-vulkan-layout-options.h @@ -119,6 +119,8 @@ public: /// True if the compiler should invert the Y coordinate of any SV_Position output. bool shouldInvertY() const { return m_invertY; } + bool getUseOriginalEntryPointName() const { return m_useOriginalEntryPointName; } + /// Given an kind and a binding infer the vulkan binding. /// Will return an invalid binding if one is not found Binding inferBinding(Kind kind, const Binding& inBinding) const; @@ -145,6 +147,8 @@ public: void setInvertY(bool value) { m_invertY = value; } + void setUseOriginalEntryPointName(bool value) { m_useOriginalEntryPointName = value; } + /// Ctor HLSLToVulkanLayoutOptions(); @@ -171,6 +175,9 @@ protected: /// Whether to invert the Y coordinate of SV_Position output. bool m_invertY = false; + + /// If set, will use the original entry point name in the generated SPIRV instead of "main". + bool m_useOriginalEntryPointName = false; }; } // namespace Slang diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index e59109b37..b31a502e7 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -93,6 +93,8 @@ enum class OptionKind VulkanBindShift, VulkanBindGlobals, VulkanInvertY, + VulkanUseEntryPointName, + GLSLForceScalarLayout, EnableEffectAnnotations, @@ -498,6 +500,7 @@ void initCommandOptions(CommandOptions& options) { OptionKind::VulkanBindGlobals, "-fvk-bind-globals", "-fvk-bind-globals ", "Places the $Globals cbuffer at descriptor set and binding ."}, { OptionKind::VulkanInvertY, "-fvk-invert-y", nullptr, "Negates (additively inverts) SV_Position.y before writing to stage output."}, + { OptionKind::VulkanUseEntryPointName, "-fvk-use-entrypoint-name", nullptr, "Uses the entrypoint name from the source instead of 'main' in the spirv output."}, { OptionKind::EnableEffectAnnotations, "-enable-effect-annotations", nullptr, "Enables support for legacy effect annotation syntax."}, @@ -2016,6 +2019,12 @@ SlangResult OptionsParser::_parse( m_hlslToVulkanLayoutOptions->setInvertY(true); break; } + case OptionKind::VulkanUseEntryPointName: + { + // -fvk-use-entrypoint-name + m_hlslToVulkanLayoutOptions->setUseOriginalEntryPointName(true); + break; + } case OptionKind::Profile: SLANG_RETURN_ON_FAIL(_parseProfile(arg)); break; case OptionKind::Capability: { -- cgit v1.2.3