shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Crash with TypeConformance #4455

Open fknfilewalker opened 5 days ago

fknfilewalker commented 5 days ago

Using the following code and setting typeconformance for TestInterface to TestImplementation results in a crash in composedProgram->getEntryPointCode access violation It seems like this problem comes from interface implementation structs that do not have a member variable.

interface TestInterface {
    float sample();
}
struct TestImplementation : TestInterface {
    float sample() {
        return 1.0f;
    }
};
StructuredBuffer<TestInterface> inBuffer;
RWStructuredBuffer<float> outputBuffer;
[shader("compute")]
[numthreads(1, 1, 1)]
void main(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    outputBuffer[0] = inBuffer[0].sample();
}

when returning a member var instead, for some reason, it compiles successfully

interface TestInterface {
    float sample();
}
struct TestImplementation : TestInterface {
    float x;
    float sample() {
        return x;
    }
};
StructuredBuffer<TestInterface> inBuffer;
RWStructuredBuffer<float> outputBuffer;
[shader("compute")]
[numthreads(1, 1, 1)]
void main(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    outputBuffer[0] = inBuffer[0].sample();
}

Slang 2024.1.22

Additionally in the second working case, when the TestImplementation is moved to another file which gets then compiled to a slang-module for later insertion into the main code, this also results in a crash. When including the impl using an import from a TestImplementation.slang file, it works.