From 61cddbee405935fa8391a757a08bcbe4ea7ac98f Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:12:33 -0500 Subject: Improve on spirv generation compile option (#5479) CompilerOptionName::EmitSpirvViaGLSL and CompilerOptionName::EmitSpirvDirectly options are not mutually exclusive, but due to compatible reason, we cannot delete those options. Instead, this change makes the effort to create a new option name EmitSpirvMethod, and we will turn those two options into the new one internally. Also, we put a priority implicitly on those two options, where EmitSpirvDirectly always win if it's set. We have another location that can setup the same option, where is through SlangTargetFlags::SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY. We should definitely deprecate this flag to avoid more confusing. But for the same compatible reason, we cannot do that in this PR. Again, we will encourage people to not use this flag, but using the CompilerOptionName instead. In this PR, we will also implicitly give CompilerOptionName higher priority, it means that as long as user setup the CompilerOptionName for emit spirv method, it always take higher priority for the final decision. --- examples/hello-world/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp index e9585bde9..c6774b64f 100644 --- a/examples/hello-world/main.cpp +++ b/examples/hello-world/main.cpp @@ -117,11 +117,19 @@ int HelloWorldExample::createComputePipelineFromShader() slang::TargetDesc targetDesc = {}; targetDesc.format = SLANG_SPIRV; targetDesc.profile = slangGlobalSession->findProfile("spirv_1_5"); - targetDesc.flags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; + targetDesc.flags = 0; + sessionDesc.targets = &targetDesc; sessionDesc.targetCount = 1; + std::vector options; + options.push_back( + {slang::CompilerOptionName::EmitSpirvDirectly, + {slang::CompilerOptionValueKind::Int, 1, 0, nullptr, nullptr}}); + sessionDesc.compilerOptionEntries = options.data(); + sessionDesc.compilerOptionEntryCount = options.size(); + ComPtr session; RETURN_ON_FAIL(slangGlobalSession->createSession(sessionDesc, session.writeRef())); -- cgit v1.2.3