summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-18 06:12:30 -0700
committerGitHub <noreply@github.com>2023-09-18 21:12:30 +0800
commit8bcffcc085b996babedfeaee674c6ad09c9b08cf (patch)
tree8e1537aca0a637c6d2a3b626f43a03fb4b085805
parent95b470f810a5cecffee165635996fa908a38707f (diff)
Use direct spirv in hello-world example. (#3207)
* Use direct spirv in hello-world example. * Use vulkan 1.1 * Use vulkan 1.2. * fix. * Fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--examples/hello-world/main.cpp3
-rw-r--r--examples/hello-world/vulkan-api.cpp2
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp19
-rw-r--r--source/slang/slang-ir-insts.h1
-rw-r--r--tests/spirv/direct-spirv-emit.slang.expected2
-rw-r--r--tools/gfx/vulkan/vk-shader-program.cpp10
6 files changed, 25 insertions, 12 deletions
diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp
index db243749b..95c3daa72 100644
--- a/examples/hello-world/main.cpp
+++ b/examples/hello-world/main.cpp
@@ -115,7 +115,8 @@ int HelloWorldExample::createComputePipelineFromShader()
slang::TargetDesc targetDesc = {};
targetDesc.format = SLANG_SPIRV;
targetDesc.profile = slangGlobalSession->findProfile("glsl440");
-
+ targetDesc.flags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY;
+
sessionDesc.targets = &targetDesc;
sessionDesc.targetCount = 1;
diff --git a/examples/hello-world/vulkan-api.cpp b/examples/hello-world/vulkan-api.cpp
index d2d8aefa6..cc52956ce 100644
--- a/examples/hello-world/vulkan-api.cpp
+++ b/examples/hello-world/vulkan-api.cpp
@@ -74,7 +74,7 @@ int initializeVulkanDevice(VulkanAPI& api)
VkApplicationInfo applicationInfo = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
applicationInfo.pApplicationName = "slang-hello-world";
applicationInfo.pEngineName = "slang-hello-world";
- applicationInfo.apiVersion = VK_API_VERSION_1_0;
+ applicationInfo.apiVersion = VK_API_VERSION_1_2;
applicationInfo.engineVersion = 1;
applicationInfo.applicationVersion = 1;
const char* instanceExtensions[] = {
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index 866fd3a4d..b94afe611 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -2634,6 +2634,18 @@ void legalizeEntryPointParameterForGLSL(
}
}
+bool shouldUseOriginalEntryPointName(CodeGenContext* codeGenContext)
+{
+ if (auto hlslOptions = codeGenContext->getTargetReq()->getHLSLToVulkanLayoutOptions())
+ {
+ if (hlslOptions->getUseOriginalEntryPointName())
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
void legalizeEntryPointForGLSL(
Session* session,
IRModule* module,
@@ -2679,6 +2691,13 @@ void legalizeEntryPointForGLSL(
context.builder = &builder;
+ // Rename the entrypoint to "main" to conform to GLSL standard,
+ // if the compile options require us to do it.
+ if (!shouldUseOriginalEntryPointName(codeGenContext))
+ {
+ entryPointDecor->setName(builder.getStringValue(UnownedStringSlice("main")));
+ }
+
// We will start by looking at the return type of the
// function, because that will enable us to do an
// early-out check to avoid more work.
diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h
index d8788aa06..b88df524a 100644
--- a/source/slang/slang-ir-insts.h
+++ b/source/slang/slang-ir-insts.h
@@ -454,6 +454,7 @@ struct IREntryPointDecoration : IRDecoration
IRStringLit* getName() { return cast<IRStringLit>(getOperand(1)); }
IRStringLit* getModuleName() { return cast<IRStringLit>(getOperand(2)); }
+ void setName(IRStringLit* name) { setOperand(1, name); }
};
IR_SIMPLE_DECORATION(CudaHostDecoration)
diff --git a/tests/spirv/direct-spirv-emit.slang.expected b/tests/spirv/direct-spirv-emit.slang.expected
index 55cc718a8..ab2e816ae 100644
--- a/tests/spirv/direct-spirv-emit.slang.expected
+++ b/tests/spirv/direct-spirv-emit.slang.expected
@@ -9,7 +9,7 @@ standard output = {
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %computeMain "computeMain"
+ OpEntryPoint GLCompute %computeMain "main"
OpExecutionMode %computeMain LocalSize 4 1 1
; Debug Information
diff --git a/tools/gfx/vulkan/vk-shader-program.cpp b/tools/gfx/vulkan/vk-shader-program.cpp
index caa219c99..4159561d1 100644
--- a/tools/gfx/vulkan/vk-shader-program.cpp
+++ b/tools/gfx/vulkan/vk-shader-program.cpp
@@ -68,16 +68,8 @@ Result ShaderProgramImpl::createShaderModule(
{
m_codeBlobs.add(kernelCode);
VkShaderModule shaderModule;
- // HACK: our direct-spirv-emit path generates SPIRV that respects
- // the original entry point name, while the glslang path always
- // uses "main" as the name. We should introduce a compiler parameter
- // to control the entry point naming behavior in SPIRV-direct path
- // so we can remove the ad-hoc logic here.
auto realEntryPointName = entryPointInfo->getNameOverride();
- const char* spirvBinaryEntryPointName =
- m_device->m_desc.slang.targetFlags & SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY
- ? realEntryPointName
- : "main";
+ const char* spirvBinaryEntryPointName = "main";
m_stageCreateInfos.add(compileEntryPoint(
spirvBinaryEntryPointName,
kernelCode,