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.7k stars 121 forks source link

No error when using `[D2DInputSimple(n)]` but reading outside of current pixel #769

Open rickbrew opened 6 months ago

rickbrew commented 6 months ago

I only noticed this recently when someone on the PDN forum posted a shader that was using D2DInputSimple even though they were doing complex sampling: https://forums.getpaint.net/topic/124551-gpu-median-filter/

To repro this, take any D2D shader that specifies [D2DInputComplex(n)] and replace it with [D2DInputSimple(n)].

Two weird things happen:

  1. No compile-time error, which I was expecting d2d1effecthelpers.hlsli to force, e.g. by mapping D2DSampleInputAtOffset(n) to some invalid syntax or the equivalent of a #pragma error
  2. The shader works fine?! What's the actual difference here then? I wonder if it would confuse/break D2D if it tries to use the shader as a linked shader

My proposal is that ComputeSharp.D2D1 should detect this and emit an error.