shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
2.99k stars 210 forks source link

Interface with 2 implementations from separate compiled slang-modules -> crash #5407

Open fknfilewalker opened 1 month ago

fknfilewalker commented 1 month ago

So I have this simple interface and the following simple shader:

// emitter.slang
public interface IEmitter<Real : __BuiltinFloatingPointType> {
    [Differentiable] vector<Real, 3> illuminate(vector<Real, 3>, vector<Real, 3>);
    [Differentiable] vector<Real, 3> sample();
} 
import emitter;
StructuredBuffer<IEmitter<float>> emitters;
RWStructuredBuffer<float> outputBuffer;

[shader("compute")]
[numthreads(1, 1, 1)]
void main(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    vector<float, 3> P = { 0.0, 0.0, 0.0 };
    vector<float, 3> N = { 0.0, 1.0, 0.0 };
    outputBuffer[0] = emitters[0].illuminate(P, N).x;
}

I compile two different implementations (PointLight and SpotLight) of this interface to two slang-modules, which then get added when compiling the main shader above. If I only use one implementation it compiles but when using two, it results in a crash.

Directly compiling to spirv gives me "Unhandled global inst in spirv-emit: witness_table %1 : %2(%PointLight);" Compiling to glsl gives me an internal error 99999

So the problem comes from the last line where the compiler has an kIROp_swizzle with kIROp_WitnessTable as operand0, which then in the func defaultEmitInstExpr can not be handled and results in the error.

https://github.com/fknfilewalker/dyslang contains the code tests/load_plugins_one works but tests/load_plugins_two crashes (only tried it on windows) DYSLANG_SLANG_FROM_SUBMODULE TRUE uses the latest github code.

fknfilewalker commented 1 week ago

Seems to be a problem with generics in interfaces. Removing them fixes the problem.