shader-slang / slang

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

Deprecate the old C API #3617

Open tangent-vector opened 4 months ago

tangent-vector commented 4 months ago

The Slang API has evolved over a long period of time, stretching back to well before the system was even called "Slang." The C API of sp-prefixed functions no longer reflects the intended way to use Slang, and we would like to deprecate (and eventually remove) these functions so that we no longer have to maintain them as we introduce new functionality.

Issue #3616 covers the more urgent task of discouraging new users from writing code using the to-be-deprecated API.

Further steps to effectively deprecate and remove the C API should ideally include:

The above steps can be staged out slowly, or lumped together into a smaller number of changes, depending on how quickly we think we can migrate existing users over to the new API.

laurooyen commented 4 months ago

It's unfortunate to see the C API go since it allowed me to automatically generate Rust language bindings to Slang for use in my own open-source toy engine. I fully understand the decision to deprecate though.

EDIT: Assuming the slang_createGlobalSession dll export won't be deprecated, I created new Rust bindings based on the COM API. If anyone is interested, they're open source and available here: https://github.com/FloatyMonkey/slang-rs.

The biggest missing part of the COM API and therefore my new bindings is reflection. It is available in the C++ API but not as a COM Interface so generating bindings to it is not possible.

csyonghe commented 2 months ago

Blocked by #3882.

csyonghe commented 2 months ago

@laurooyen We will keep the reflection API as is and there is no plan to deprecate them.

csyonghe commented 2 months ago

The functions to deprecate are all the sp* functions, plus the ICompileRequest interface.

milliewalky commented 3 days ago

Given these:

  1. Refactoring the slang.h API header so that the C++ API is declared first, and the C API types are expressed as typedefs of the C++ types.
  2. Moving the implementation of the C API (in terms of the C++ API) into the slang-legacy-api.h header, making it a single-file library wrapping the proper Slang API.

Could you further clarify if the intention is to provide C bindings to the C++ API, or if there's another direction planned for supporting C users?

csyonghe commented 2 days ago

For the C API, we will need to use some code generators to generate C wrappers from the COM interface, so that we don't need to maintain the two versions manually. We haven't planned this work yet but it is something we will need before removing the existing C API.

milliewalky commented 2 days ago

This is excellent, thank you!