Skip to content

Commit 2165c51

Browse files
committed
Add unit test for entry point lookup bug
See issue #4760.
1 parent f90a763 commit 2165c51

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "../../source/core/slang-process.h"
2+
#include "slang-com-ptr.h"
3+
#include "slang.h"
4+
#include "unit-test/slang-unit-test.h"
5+
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
9+
using namespace Slang;
10+
11+
// Make sure that we can look up entry points that are not explicitly marked out using e.g.
12+
// [shader("fragment")], but rather specified as entry points via the
13+
// CompilerOptionName::EntryPointName API option.
14+
15+
SLANG_UNIT_TEST(entryPointOptions)
16+
{
17+
18+
char const* const sourceString =
19+
R"(
20+
float4 vertexMain() : SV_Position
21+
{
22+
return float4(0,0,0,1);
23+
}
24+
25+
float4 fragmentMain() : SV_Target
26+
{
27+
return float4(1,1,1,1);
28+
})";
29+
Slang::String source(sourceString);
30+
31+
ComPtr<slang::IGlobalSession> globalSession;
32+
SlangResult res = slang::createGlobalSession(globalSession.writeRef());
33+
SLANG_CHECK(SLANG_SUCCEEDED(res));
34+
35+
slang::TargetDesc targetDesc = {};
36+
targetDesc.format = SlangCompileTarget::SLANG_HLSL;
37+
slang::SessionDesc sessionDesc = {};
38+
sessionDesc.targetCount = 1;
39+
sessionDesc.targets = &targetDesc;
40+
List<slang::CompilerOptionEntry> sessionOptionEntries;
41+
const char* entryPointNames[] = {"vertexMain", "fragmentMain"};
42+
for (const char* name : entryPointNames)
43+
{
44+
slang::CompilerOptionEntry entry;
45+
entry.name = slang::CompilerOptionName::EntryPointName;
46+
entry.value.kind = slang::CompilerOptionValueKind::String;
47+
entry.value.stringValue0 = name;
48+
sessionOptionEntries.add(entry);
49+
}
50+
sessionDesc.compilerOptionEntries = sessionOptionEntries.getBuffer();
51+
sessionDesc.compilerOptionEntryCount = sessionOptionEntries.getCount();
52+
ComPtr<slang::ISession> session;
53+
res = globalSession->createSession(sessionDesc, session.writeRef());
54+
SLANG_CHECK(SLANG_SUCCEEDED(res));
55+
ComPtr<slang::IBlob> diagnostics;
56+
ComPtr<slang::IModule> module(session->loadModuleFromSourceString(
57+
"main",
58+
"main.slang",
59+
source.getBuffer(),
60+
diagnostics.writeRef()));
61+
SLANG_CHECK(module != nullptr);
62+
63+
for (const char* name : entryPointNames)
64+
{
65+
ComPtr<slang::IEntryPoint> entryPoint;
66+
res = module->findEntryPointByName(name, entryPoint.writeRef());
67+
SLANG_CHECK(SLANG_SUCCEEDED(res));
68+
SLANG_CHECK(entryPoint != nullptr);
69+
}
70+
}

0 commit comments

Comments
 (0)