@@ -71,3 +71,68 @@ SLANG_UNIT_TEST(findAndCheckEntryPoint)
71
71
SLANG_CHECK (code != nullptr );
72
72
SLANG_CHECK (code->getBufferSize () != 0 );
73
73
}
74
+
75
+ // This test reproduces issue #6507, where it was noticed that compilation of
76
+ // tests/compute/simple.slang for PTX target generates invalid code.
77
+ // TODO: Remove this when issue #4759 is resolved, because at that point
78
+ // tests/compute/simple.slang should cover the same issue.
79
+ SLANG_UNIT_TEST (cudaCodeGenBug)
80
+ {
81
+ // Source for a module that contains an undecorated entrypoint.
82
+ const char * userSourceBody = R"(
83
+ RWStructuredBuffer<float> outputBuffer;
84
+
85
+ [numthreads(4, 1, 1)]
86
+ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
87
+ {
88
+ outputBuffer[dispatchThreadID.x] = float(dispatchThreadID.x);
89
+ }
90
+ )" ;
91
+
92
+ auto moduleName = " moduleG" + String (Process::getId ());
93
+ String userSource = " import " + moduleName + " ;\n " + userSourceBody;
94
+ ComPtr<slang::IGlobalSession> globalSession;
95
+ SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION, globalSession.writeRef ()) == SLANG_OK);
96
+ slang::TargetDesc targetDesc = {};
97
+ targetDesc.format = SLANG_PTX;
98
+ slang::SessionDesc sessionDesc = {};
99
+ sessionDesc.targetCount = 1 ;
100
+ sessionDesc.targets = &targetDesc;
101
+ ComPtr<slang::ISession> session;
102
+ SLANG_CHECK (globalSession->createSession (sessionDesc, session.writeRef ()) == SLANG_OK);
103
+
104
+ ComPtr<slang::IBlob> diagnosticBlob;
105
+ auto module = session->loadModuleFromSourceString (
106
+ " m" ,
107
+ " m.slang" ,
108
+ userSourceBody,
109
+ diagnosticBlob.writeRef ());
110
+ SLANG_CHECK (module != nullptr );
111
+
112
+ ComPtr<slang::IEntryPoint> entryPoint;
113
+ module->findAndCheckEntryPoint (
114
+ " computeMain" ,
115
+ SLANG_STAGE_COMPUTE,
116
+ entryPoint.writeRef (),
117
+ diagnosticBlob.writeRef ());
118
+ SLANG_CHECK (entryPoint != nullptr );
119
+
120
+ ComPtr<slang::IComponentType> compositeProgram;
121
+ slang::IComponentType* components[] = {module, entryPoint.get ()};
122
+ session->createCompositeComponentType (
123
+ components,
124
+ 2 ,
125
+ compositeProgram.writeRef (),
126
+ diagnosticBlob.writeRef ());
127
+ SLANG_CHECK (compositeProgram != nullptr );
128
+
129
+ ComPtr<slang::IComponentType> linkedProgram;
130
+ compositeProgram->link (linkedProgram.writeRef (), diagnosticBlob.writeRef ());
131
+ SLANG_CHECK (linkedProgram != nullptr );
132
+
133
+ ComPtr<slang::IBlob> code;
134
+ auto res = linkedProgram->getEntryPointCode (0 , 0 , code.writeRef (), diagnosticBlob.writeRef ());
135
+ SLANG_CHECK (res == SLANG_OK);
136
+ SLANG_CHECK (code != nullptr );
137
+ SLANG_CHECK (code->getBufferSize () != 0 );
138
+ }
0 commit comments