Skip to content

Commit d930c65

Browse files
authored
Update the type of a call inst during specialization. (shader-slang#1569)
1 parent 3321df7 commit d930c65

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

source/slang/slang-ir-specialize.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,12 @@ struct SpecializationContext
901901
if(!calleeFunc)
902902
return;
903903

904+
// Update result type since the callee may have been changed.
905+
if (inst->getDataType() != calleeFunc->getResultType())
906+
{
907+
inst->setFullType(calleeFunc->getResultType());
908+
}
909+
904910
// We can only specialize if we have access to a body for the callee.
905911
//
906912
if(!calleeFunc->isDefinition())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Tests using associated types through an existential-struct-typed param.
2+
3+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda
4+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
5+
6+
[anyValueSize(8)]
7+
interface IInterface
8+
{
9+
associatedtype TEval:IEval;
10+
TEval getEval();
11+
}
12+
13+
[anyValueSize(8)]
14+
interface IEval
15+
{
16+
uint eval();
17+
}
18+
19+
struct Impl : IInterface
20+
{
21+
uint val;
22+
struct TEval : IEval
23+
{
24+
uint val;
25+
uint eval()
26+
{
27+
return val;
28+
}
29+
};
30+
TEval getEval()
31+
{
32+
TEval rs;
33+
rs.val = val;
34+
return rs;
35+
}
36+
};
37+
38+
struct Params
39+
{
40+
StructuredBuffer<IInterface> obj;
41+
};
42+
43+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
44+
RWStructuredBuffer<uint> gOutputBuffer;
45+
46+
void compute(uint tid, Params p)
47+
{
48+
gOutputBuffer[tid] = p.obj[0].getEval().eval();
49+
}
50+
51+
//TEST_INPUT: entryPointExistentialType Impl
52+
53+
[numthreads(4, 1, 1)]
54+
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID,
55+
//TEST_INPUT:ubuffer(data=[0 0 0 0 1 0], stride=4):name=params.obj
56+
uniform Params params)
57+
{
58+
uint tid = dispatchThreadID.x;
59+
compute(tid, params);
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
1
3+
1
4+
1

0 commit comments

Comments
 (0)