https://github.com/shader-slang/slang
Tip revision: 25eeb10a9731b0980f63709d0141ba2cccc954b5 authored by Tim Foley on 21 February 2020, 19:42:27 UTC
Add some missing support for Shader Model 6.4/6.5 (#1237)
Add some missing support for Shader Model 6.4/6.5 (#1237)
Tip revision: 25eeb10
interface-local.slang
// interface-local.slang
// Test basic use of an interface as an existential type
// for a local variable, instead of just as a constraint
// on a generic type parameter.
//
// Because the existential is created and then used inside
// the same function, we can eliminate it via simple
// local optimizations.
// on a generic type parameter.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
interface IHelper
{
int getVal();
}
struct HelperImpl : IHelper
{
int storedVal;
int getVal() { return storedVal; }
}
int test(int val)
{
HelperImpl helperImpl = { val };
IHelper existentialHelper = helperImpl;
return existentialHelper.getVal();
}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<int> gOutputBuffer;
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint tid = dispatchThreadID.x;
int inputVal = tid;
int outputVal = test(inputVal);
gOutputBuffer[tid] = outputVal;
}