shader-slang / slang

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

Setting Type Conformance for shared interfaces across modules does not work #4281

Open fknfilewalker opened 4 weeks ago

fknfilewalker commented 4 weeks ago

I have an Interfaces defined in header A and implement it in Module B. When I include header A and Module B in my main shader I can no longer find the Interface type with layout->findTypeByName, the implementation type I can find. When I exclude Module B from the main shader, I can find the interface but of course no longer the implementation.

// header A
interface A {}

// Module B
#include "A"
struct B : A {};

// Main Shader that includes Module B
#include "A"
StructuredBuffer<A> buffer;
bmillsNV commented 4 weeks ago

@fknfilewalker can you help to attach a better reproduction case and include any output from the slang compiler?

fknfilewalker commented 4 weeks ago

I forgot to say that I compile the module with the interface implementation to a .slang-module and then later include that in my main shader. But then I can no longer find the Interface type.

Yes can do that, is it possible to set type conformance via command line so I can make this example quicker?

csyonghe commented 3 weeks ago

We don't have a convenient way to set it via the command line, unfortunately.

fknfilewalker commented 2 weeks ago

I found out that this only happens when using #include instead of using import to integrate the Interface definition

jkwak-work commented 1 week ago

I think @fknfilewalker found a solution for it. Can we close this issue?

My understanding is that when you share an interface they must be import-ed. If you use #include, the including file will be preprocessed and the definition of the interface will exist in the each and every translation units. I don't think they will be combined and resulted in a single definition at the linking time only because their names are same.

If you still think this is a bug, please give us more concrete repro steps so that we can discuss at more detail.

fknfilewalker commented 1 week ago

@jkwak-work you are absolutely right. I am fine with the module solution but of course it would be nice to also make this work with #include. There should be at least some kind of warning or info about that so people don't need to figure this out themselves.