shader-slang / slang

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

Reflection API reports 0 entry points in v2024.1.22 #4388

Closed dubiousconst282 closed 2 weeks ago

dubiousconst282 commented 2 weeks ago

IModule::getDefinedEntryPointCount() and related APIs are returning 0 in the latest release / master branch. I have a minimal repro:

#include <slang.h>
#include <slang-com-ptr.h>

int main() {
    Slang::ComPtr<slang::IGlobalSession> globalSession;
    slang::createGlobalSession(globalSession.writeRef());

    slang::TargetDesc targetDesc = {
        .format = SLANG_SPIRV,
        .profile = globalSession->findProfile("glsl_460"),
        .flags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY,
        .forceGLSLScalarBufferLayout = true,
    };
    slang::SessionDesc sessionDesc = {
        .targets = &targetDesc,
        .targetCount = 1,
        .defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR,
    };

    // Parsing
    Slang::ComPtr<slang::ISession> session;
    globalSession->createSession(sessionDesc, session.writeRef());

    Slang::ComPtr<slang::IBlob> diagnostics;

    const char* source = R"(

RWByteAddressBuffer output;

[numthreads(1)]
void ComputeMain(int tid : SV_DispatchThreadID) {
    output.Store(tid, 123);
}
)";
    slang::IModule* module = session->loadModuleFromSourceString("Repro", "Repro.slang", source, diagnostics.writeRef());

    Slang::ComPtr<slang::IEntryPoint> ep;
    auto res = module->findEntryPointByName("ComputeMain", ep.writeRef());
    printf("#EP: %p %08x %d\n", ep.get(), res, module->getDefinedEntryPointCount());

    return 0;
}

Output in v2024.1.22:

EP: 00000256B939EF40 80070057 0

Output in v2024.1.21:

EP: 000001F4D9DF0160 00000000 1

natevm commented 2 weeks ago

I don't suppose this relates at all to the flag -fvk-use-entrypoint-name, does it?

I usually have to add that flag into slangc in order to have entrypoint names "stick".

dubiousconst282 commented 2 weeks ago

I don't think so, this happens before even linking and codegen. It's weird that looking up the entrypoint by name returns a non-null pointer, but an error result.

csyonghe commented 2 weeks ago

You can always use findAndCheckEntryPoint to make any function treated as an entrypoint, even when they don't have [shader] attribute.

jkwak-work commented 2 weeks ago

I can take a look at this more if it is not expected change. It could be a regression.

I found a related code to this, https://github.com/shader-slang/slang/blob/2cc96907e4152291e0b6bca78a0bfbc69ddb8839/source/slang/slang-compiler.cpp#L2497

Basically, Slang looks for [shader(XXX)] as an EntryPointAttribute. If it fails to find it, it looks for [numthreads]. Based on my understanding the entry count should have been 1 in the given example/repro.

csyonghe commented 2 weeks ago

It looks like a regression,. I recently touched this logic in https://github.com/shader-slang/slang/pull/4336/files#diff-81b3d1428af174af2fd0c7a42eef8d9b7e0fd4b239851472649fd51df063add6, not sure if that is the cause for the regression.

dubiousconst282 commented 2 weeks ago

This was actually caused by a linking error, as I was just replacing the DLLs in my app folder 🤦. My apologies.