Slang bindings

Started by codex, January 22, 2026, 00:51:06

Previous topic - Next topic

codex

Are there any plans to add bindings for slang? If not, how can I get started on making these bindings for lwjgl myself?

spasi

Hey codex,

There are two options now:

1. Building "offline" bindings as a new LWJGL module. You could start by examining the shaderc bindings and doing something similar for slang. This involves using the LWJGL Kotlin-based bindings generator. A great starting point is the commit that first added the shaderc bindings, it should include everything necessary to get started.

2. Building runtime-generated bindings using LWJGL 3.4.0. If you're able to upgrade to 3.4.0 and JDK 25, then you can use the new FFM-based runtime bindings generator in the org.lwjgl.system.ffm package. With this generator you write simple Java interfaces to describe a C API (downcalls, upcalls, structs/unions) and you get instances of those interfaces generated at runtime by LWJGL. Assuming you have access to prebuilt slang binaries, you should be able to start using it immediately, without building a custom LWJGL or waiting for a fresh snapshot.

codex

Thanks for the guidance. I'm attempting option 1, but slang already seems a lot more complex than shaderc, so I have some questions.

struct ISession : public ISlangUnknown {
    virtual IGlobalSession* getGlobalSession() = 0;
    virtual IModule* loadModule(const char* moduleName, IBlob** outDiagnostics = nullptr) = 0;
}

How do I properly represent ISession? I've tried using both StructType and NativeClass for this, but neither seems to cover all the bases.

spasi

First of all, slang does not have a pure C API, so this isn't going to be straightforward. Do not try to support C++ features, LWJGL does not support C++ bindings.

With that said, types like ISession are usually treated as opaque types. E.g.

val ISession = "slang::ISession".opaque

For example, in:

SLANG_EXTERN_C SLANG_API slang::IModule* slang_loadModuleFromSource(
    slang::ISession* session,
    const char* moduleName,
    const char* path,
    const char* source,
    size_t sourceSize,
    ISlangBlob** outDiagnostics = nullptr);

the session parameter would be defined as:

ISession.p("session")

which LWJGL understands as: a paramater with name "session" that has a type "pointer to opaque type slang::ISession".

codex

Ah, ok, that makes a lot more sense. Thanks for the clarification!