Skip to content

Commit 4b9a342

Browse files
authored
Fix geometry shader related modifier lowering. (shader-slang#6197)
* Fix geometry shader related modifier lowering. * Cleanup. * Delete obselete test. * Enable geometryShader test on windows only. * Fix test.
1 parent cd27fbd commit 4b9a342

File tree

2 files changed

+117
-44
lines changed

2 files changed

+117
-44
lines changed

source/slang/slang-lower-to-ir.cpp

+24-44
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,30 @@ void addVarDecorations(IRGenContext* context, IRInst* inst, Decl* decl)
23332333
inst,
23342334
IRIntegerValue(collection->getMemoryQualifierBit()));
23352335
}
2336+
else if (auto geometryModifier = as<HLSLGeometryShaderInputPrimitiveTypeModifier>(mod))
2337+
{
2338+
IROp op = kIROp_Invalid;
2339+
switch (geometryModifier->astNodeType)
2340+
{
2341+
case ASTNodeType::HLSLTriangleModifier:
2342+
op = kIROp_TriangleInputPrimitiveTypeDecoration;
2343+
break;
2344+
case ASTNodeType::HLSLPointModifier:
2345+
op = kIROp_PointInputPrimitiveTypeDecoration;
2346+
break;
2347+
case ASTNodeType::HLSLLineModifier:
2348+
op = kIROp_LineInputPrimitiveTypeDecoration;
2349+
break;
2350+
case ASTNodeType::HLSLLineAdjModifier:
2351+
op = kIROp_LineAdjInputPrimitiveTypeDecoration;
2352+
break;
2353+
case ASTNodeType::HLSLTriangleAdjModifier:
2354+
op = kIROp_TriangleAdjInputPrimitiveTypeDecoration;
2355+
break;
2356+
}
2357+
if (op != kIROp_Invalid)
2358+
builder->addDecoration(inst, op);
2359+
}
23362360
// TODO: what are other modifiers we need to propagate through?
23372361
}
23382362
if (auto t =
@@ -11180,50 +11204,6 @@ static void lowerFrontEndEntryPointToIR(
1118011204
entryPointName->text.getUnownedSlice(),
1118111205
moduleName.getUnownedSlice());
1118211206
}
11183-
11184-
// Go through the entry point parameters creating decorations from layout as appropriate
11185-
// But only if this is a definition not a declaration
11186-
if (isDefinition(instToDecorate))
11187-
{
11188-
FilteredMemberList<ParamDecl> params = entryPointFuncDecl->getParameters();
11189-
11190-
IRGlobalValueWithParams* valueWithParams = as<IRGlobalValueWithParams>(instToDecorate);
11191-
if (valueWithParams)
11192-
{
11193-
IRParam* irParam = valueWithParams->getFirstParam();
11194-
11195-
for (auto param : params)
11196-
{
11197-
if (auto modifier =
11198-
param->findModifier<HLSLGeometryShaderInputPrimitiveTypeModifier>())
11199-
{
11200-
IROp op = kIROp_Invalid;
11201-
11202-
if (as<HLSLTriangleModifier>(modifier))
11203-
op = kIROp_TriangleInputPrimitiveTypeDecoration;
11204-
else if (as<HLSLPointModifier>(modifier))
11205-
op = kIROp_PointInputPrimitiveTypeDecoration;
11206-
else if (as<HLSLLineModifier>(modifier))
11207-
op = kIROp_LineInputPrimitiveTypeDecoration;
11208-
else if (as<HLSLLineAdjModifier>(modifier))
11209-
op = kIROp_LineAdjInputPrimitiveTypeDecoration;
11210-
else if (as<HLSLTriangleAdjModifier>(modifier))
11211-
op = kIROp_TriangleAdjInputPrimitiveTypeDecoration;
11212-
11213-
if (op != kIROp_Invalid)
11214-
{
11215-
builder->addDecoration(irParam, op);
11216-
}
11217-
else
11218-
{
11219-
SLANG_UNEXPECTED("unhandled primitive type");
11220-
}
11221-
}
11222-
11223-
irParam = irParam->getNextParam();
11224-
}
11225-
}
11226-
}
1122711207
}
1122811208

1122911209
static void lowerProgramEntryPointToIR(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// unit-test-geometry-shader.cpp
2+
3+
#include "../../source/core/slang-io.h"
4+
#include "../../source/core/slang-process.h"
5+
#include "slang-com-ptr.h"
6+
#include "slang.h"
7+
#include "unit-test/slang-unit-test.h"
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
12+
using namespace Slang;
13+
14+
// Test the compilation API for compiling geometry shaders to DXIL.
15+
16+
#if SLANG_WINDOWS_FAMILY
17+
18+
SLANG_UNIT_TEST(geometryShader)
19+
{
20+
const char* userSourceBody = R"(
21+
struct GS_INPUT
22+
{
23+
float4 PosSS : TEXTURE0; // [Screen Space] Position
24+
};
25+
26+
struct PS_INPUT
27+
{
28+
float4 PosSS : SV_POSITION; // [Screen Space] Position
29+
};
30+
31+
[maxvertexcount(3)]
32+
void main(triangle GS_INPUT input[3], inout TriangleStream<PS_INPUT> outStream)
33+
{
34+
PS_INPUT output;
35+
36+
output.PosSS = input[0].PosSS;
37+
outStream.Append(output);
38+
39+
output.PosSS = input[1].PosSS;
40+
outStream.Append(output);
41+
42+
output.PosSS = input[2].PosSS;
43+
outStream.Append(output);
44+
45+
outStream.RestartStrip();
46+
}
47+
)";
48+
ComPtr<slang::IGlobalSession> globalSession;
49+
SlangGlobalSessionDesc globalDesc = {};
50+
globalDesc.enableGLSL = true;
51+
SLANG_CHECK(slang_createGlobalSession2(&globalDesc, globalSession.writeRef()) == SLANG_OK);
52+
slang::TargetDesc targetDesc = {};
53+
targetDesc.format = SLANG_DXIL;
54+
targetDesc.profile = globalSession->findProfile("sm_6_0");
55+
slang::SessionDesc sessionDesc = {};
56+
sessionDesc.targetCount = 1;
57+
sessionDesc.targets = &targetDesc;
58+
ComPtr<slang::ISession> session;
59+
SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK);
60+
61+
ComPtr<slang::IBlob> diagnosticBlob;
62+
auto module = session->loadModuleFromSourceString(
63+
"m",
64+
"m.slang",
65+
userSourceBody,
66+
diagnosticBlob.writeRef());
67+
SLANG_CHECK(module != nullptr);
68+
69+
ComPtr<slang::IEntryPoint> entryPoint;
70+
module->findAndCheckEntryPoint(
71+
"main",
72+
SLANG_STAGE_GEOMETRY,
73+
entryPoint.writeRef(),
74+
diagnosticBlob.writeRef());
75+
76+
slang::IComponentType* componentTypes[2] = {module, entryPoint.get()};
77+
ComPtr<slang::IComponentType> composedProgram;
78+
session->createCompositeComponentType(
79+
componentTypes,
80+
2,
81+
composedProgram.writeRef(),
82+
diagnosticBlob.writeRef());
83+
84+
ComPtr<slang::IComponentType> linkedProgram;
85+
composedProgram->link(linkedProgram.writeRef(), diagnosticBlob.writeRef());
86+
87+
ComPtr<slang::IBlob> code;
88+
linkedProgram->getEntryPointCode(0, 0, code.writeRef(), diagnosticBlob.writeRef());
89+
90+
SLANG_CHECK(code != nullptr);
91+
}
92+
93+
#endif

0 commit comments

Comments
 (0)