Skip to content
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

Use of D2D1PixelOptions.TrivialSampling on shader w/ complex inputs causes problems #770

Open
rickbrew opened this issue Mar 2, 2024 · 2 comments
Labels
proposal 💡 A proposal for a new feature untriaged 🧰 A new issue that needs initial triage

Comments

@rickbrew
Copy link
Collaborator

rickbrew commented Mar 2, 2024

This isn't a ComputeSharp.D2D1 bug, but I think it's an easy mistake that should be flagged by the source generator. It's something that has caused me to waste a bunch of time in the debugger for a mistake that was rather difficult to figure out.

To repro, take a shader that has any complex input and add a [D2D1PixelOptions(D2D1PixelOptions.TrivialSampling)] attribute on it. Once you run the shader, you'll either see all sorts of missing gaps with transparent pixels, or if you have the debug layer on you'll see random colors in those gaps instead. Presumably D2D fills the texture with those solid colors to aid debugging.

Direct2D defines trivial sampling as being applicable only to shaders that 1) only use simple inputs, and 2) produce all-zero output for all-zero input. This allows it to do optimizations like skipping the shader entirely if it knows the input is all-zeros. An example would be an shader with an output region of e.g. [x=0, y=0, w=100, h=100] being plugged into a shader with an output region of e.g. [x=0, y=0, w=200, h=200]. The right and bottom edges of the input are known by D2D to be zero, so it only needs to run the second shader on the top left quadrant.

Here's an example using my custom Gaussian Blur shaders, with the D2D debug layer enabled:

image

image

@rickbrew rickbrew added proposal 💡 A proposal for a new feature untriaged 🧰 A new issue that needs initial triage labels Mar 2, 2024
@Sergio0694
Copy link
Owner

"Direct2D defines trivial sampling as being applicable only to shaders that 1) only use simple inputs"

Can you share the source for this? I'm only finding this:

"Indicates that the shader samples its inputs only at exactly the same scene coordinate as the output pixel"

Doesn't this mean that complex inputs are also technically allowed, as long as you only sample at the same position?

@rickbrew
Copy link
Collaborator Author

Doesn't this mean that complex inputs are also technically allowed, as long as you only sample at the same position?

At which point why not just declare them as simple inputs? But, technically, maybe you're right

However, you can't really determine that statically (halting problem). Better to key off of usage of D2D.GetInput(n) versus the other input sampling methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal 💡 A proposal for a new feature untriaged 🧰 A new issue that needs initial triage
Projects
None yet
Development

No branches or pull requests

2 participants