Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined exceptions thrown by public API #5950

Open
Axel-Reactor opened this issue Dec 28, 2024 · 4 comments
Open

Undefined exceptions thrown by public API #5950

Axel-Reactor opened this issue Dec 28, 2024 · 4 comments

Comments

@Axel-Reactor
Copy link

Axel-Reactor commented Dec 28, 2024

As far as I can tell Slang::Exception is not defined in the public headers, but sometimes due to ICE they get thrown out of the public API anyway.
catch(...) works, but there is no way to get any diagnostic text.

I am using the precompiled binaries for Windows (slang.lib, slang.dll etc.). I would expect the exceptions to be caught internally and an appropriate error returned instead.

@csyonghe
Copy link
Collaborator

Can you share more details on which APIs are leaking internal exceptions?

@Axel-Reactor
Copy link
Author

Axel-Reactor commented Dec 31, 2024

extern "C" CompileResult *slang_compile(const char *source_code, size_t source_code_length, const char *source_file) {
    CompileResult *result = new CompileResult();

    try {
        Slang::ComPtr<slang::IGlobalSession> global_session;
        RETURN_ON_FAIL(slang::createGlobalSession(global_session.writeRef()));

        slang::SessionDesc session_desc = {};
        slang::TargetDesc target_desc = {};
        target_desc.format = SLANG_SPIRV;
        target_desc.profile = global_session->findProfile("spirv_1_6");
        target_desc.flags = 0;

        session_desc.targets = &target_desc;
        session_desc.targetCount = 1;

        std::vector<slang::CompilerOptionEntry> options;
        options.push_back({slang::CompilerOptionName::EmitSpirvDirectly,
                           {slang::CompilerOptionValueKind::Int, 1, 0, nullptr, nullptr}});
        session_desc.compilerOptionEntries = options.data();
        session_desc.compilerOptionEntryCount = options.size();

        Slang::ComPtr<slang::ISession> session;
        RETURN_ON_FAIL(global_session->createSession(session_desc, session.writeRef()));

        Slang::ComPtr<ISlangBlob> source_blob = UnownedBlob::create(source_code, source_code_length);
        slang::IModule *module =
            session->loadModuleFromSource("main", source_file, source_blob, result->diagnostics_blob.writeRef());
        if (!module) {
            result->result = SLANG_FAIL;
            return result;
        }

        Slang::ComPtr<slang::IEntryPoint> entry_point;
        RETURN_ON_FAIL(module->findEntryPointByName("main", entry_point.writeRef()));

        std::vector<slang::IComponentType *> component_types;
        component_types.push_back(module);
        component_types.push_back(entry_point);

        Slang::ComPtr<slang::IComponentType> composed_program;
        RETURN_ON_FAIL(session->createCompositeComponentType(component_types.data(), component_types.size(),
                                                             composed_program.writeRef(),
                                                             result->diagnostics_blob.writeRef()));

        Slang::ComPtr<slang::IComponentType> linked_program;
        RETURN_ON_FAIL(composed_program->link(linked_program.writeRef(), result->diagnostics_blob.writeRef()));

        RETURN_ON_FAIL(linked_program->getEntryPointCode(0, 0, result->compiled_code.writeRef(),
                                                         result->diagnostics_blob.writeRef()));
    } catch (...) {
        // Shouldn't get here
        result->m_exception = true;
    }
    return result;
}

Pretty sure it's coming from loadModuleFromSource

@csyonghe
Copy link
Collaborator

Is it possible for you to provide the shader code that triggers the ice? All ices are worth looking into anyways.

@Axel-Reactor
Copy link
Author

Sorry, I fixed a bunch of code gen by now and I lost the history of what produced the invalid output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants