Sergio0694 / ComputeSharp

A .NET library to run C# code in parallel on the GPU through DX12, D2D1, and dynamically generated HLSL compute and pixel shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
MIT License
2.65k stars 122 forks source link

D2D1 pixel shaders w/ complex inputs should still be compiled for linking #804

Closed rickbrew closed 1 month ago

rickbrew commented 1 month ago

In D2DPixelShaderDescriptorGenerator.Initialize(), it looks like a D2D1 shader is not compiled w/ linking if it has non-simple inputs.

However, if we look at the documentation for shader linking :

Only shader functions with simple inputs can have their input provided by another shader function. Shader functions with complex inputs must be provided with an input texture to sample. This means that Direct2D will not link a shader with complex inputs to its predecessor.

This would seem to indicate that, for shaders with complex inputs, they cannot have their inputs linked to them. However, these docs do not say that a shader with complex inputs cannot be linked into a shader using it as an input.

So imagine this simple effect graph:

[Premultiply] -> [Gaussian Blur] -> [UnPremultiply]

Because Gaussian Blur has complex inputs, Premultiply cannot be linked into it. This seems quite clear from the docs. However, it would seem that Gaussian Blur can be linked into UnPremultiply, since the docs do not say something like "shaders with complex inputs cannot be linked into shaders with simple inputs (i.o.w. into its successor)."

[Premultiply] -> ([Gaussian Blur] -> [UnPremultiply])

I propose that ComputeSharp should not make any decisions about whether to enable or disable shader linking based on the properties of the shader. In other words, if linking is enabled via the options then the shader should always be enabled with linking, which enables Direct2D to make its own decisions about this. There is no harm in providing the linkable export function when Direct2D decides not to use it, but there is definitely harm if Direct2D could link a shader that does not have its linkable export function.