-
Notifications
You must be signed in to change notification settings - Fork 289
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
Expose a "PassthroughEffect" to enable more flexibility for effect authors #917
Comments
There are some special things to note about a passthrough effect that is implemented through the use of
Fixing 1 isn't really possible, as you don't get notified about changes to your own precision property. The fix here is to have a separate effect, which I call the Fixing the second one? This one really depends on how your COM wrappers-and-interop system works. If you can have a single |
Can you clarify exactly what would that "fix" look like, in theory? I'm not sure I'm following what you mean 🤔 |
Your managed object/wrapper needs a way to provide the native object it's creating/wrapping. Often this is fixed at the time of constructing the wrapper. But, if the wrapper is able to provide a different native object each time it's needed, then it can do so. However, this still comes with the risk that the native object is being held onto and won't be "updated." For instance, in my code, I do stuff like this: internal sealed class D2D1DeviceContext6 : ...
{
public void DrawImage(IDeviceImage image, ...)
{
...
using ComPtr<ID2D1Image> spImage = default;
HRESULT hr = ComObject.GetIUnknown(image, &spImage);
hr.ThrowOnError();
...
this.pD2D1DeviceContext6->DrawImage(spImage, ...);
}
}
|
Notes from API reviewThis is no longer a blocker for the Store, as we could work around this by expanding the effect graph APIs in ComputeSharp instead to allow toggling output nodes dynamically (done in Sergio0694/ComputeSharp#517). It might still be useful to expose a passthrough effect in the future (as it can be useful as part of building a more general effects system), but implementing this would require increasing the complexity in Win2D due to the handling of DPIs and DPI compensation in |
Overview
With the new infrastructure for custom effects, it's now possible for developers to build custom effects that can then also be "packaged" into
ICanvasImage
objects that can be easily passed around and reused. For instance, ComputeSharp exposes theCanvasEffect
base type for this, which we're also using for all our custom effects in the Microsoft Store. One scenario that is relatively common though, especially in more complex effect graphs, is to be able to "switch" from different inputs. That is, consider this scenario:We have an effect graph with an input node, then a bunch of effects, and then an output node. Suppose we want to be able to "switch" so that the output will either go through
4
, or through2
and bypass the other upstream effects entirely. To do this efficiently, we'd want the output node to be a passthrough effect, so that the internal effect implementation can just set the right source node for it in a way that's transparent to code consuming that output effect. This is crucial, because it means the effect can keep using the sameICanvasImage
object (which can also be passed around), and will simply change its source.Having a passthrough effect is also particularly useful to be able to have a uniform API surface that exposes
ICanvasEffect
no matter what the underlying source is. That is, you can have eg. aCanvasBitmap
with a passthrough effect, and pass it around to code that only wants anICanvasEffect
object instead, and it'll work just fine.API proposal
The proposal is to add a new
PassthroughEffect
, defined as follows:API use
The effect can be used as follows, eg. using
CanvasEffect
from ComputeSharp:In this case, the graph is only built once, and the passthrough effect is used as the output node. Then whenever the "bypass" property changes, there's no need to rebuild the whole graph, instead the output node can just "switch" the source node internally. This means that any downstream consumers of this output node also don't need to do anything else or otherwise be modified. They'd just get the correct graph when trying to build the realized D2D effect from that node, as it's always the same.
The text was updated successfully, but these errors were encountered: