Skip to content

Add ID2D1PixelShaderDescriptor<T>.EffectFactory and remove runtime delegate marshalling #907

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

Merged
merged 4 commits into from
Apr 13, 2025

Conversation

Sergio0694
Copy link
Owner

Description

The ComputeSharp.D2D1 infrastructure is currently relying on Marshal.GetFunctionPointerForDelegate to marshal a wrapper object for a given T in a non-generic way, such that the internal ID2D1EffectImpl object can call the methods on it. This works, but it's not efficient, and also means you cannot use ComputeSharp in heavily constrained/sandboxed environments, where Marshal.GetFunctionPointerForDelegate is not allowed (as it requires the runtime to allocate a thunk of executable memory at runtime). This PR addresses both problems having the generator emit a non-generic native factory instead.

@Sergio0694 Sergio0694 added enhancement ✨ An improvement to existing APIs optimization 🚀 Performance improvement to existing APIs breaking change 💣 A change that is either binary or source breaking labels Apr 11, 2025
@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch 2 times, most recently from 699d64e to 06983ab Compare April 11, 2025 07:20
@Sergio0694
Copy link
Owner Author

Saves ~17 KB in a minimal native library, and drops all the delegate marshalling logic:

image

@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch from 06983ab to f909936 Compare April 12, 2025 20:47
@Sergio0694 Sergio0694 force-pushed the dev/remove-delegate-marshalling branch from f909936 to bf354d5 Compare April 12, 2025 20:48
@Sergio0694 Sergio0694 merged commit 1141f48 into main Apr 13, 2025
24 checks passed
@Sergio0694 Sergio0694 deleted the dev/remove-delegate-marshalling branch April 13, 2025 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change 💣 A change that is either binary or source breaking enhancement ✨ An improvement to existing APIs optimization 🚀 Performance improvement to existing APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant