Open petsuter opened 4 months ago
It looks like this:
The red visual should be fully covered by the magenta visual.
The full project: WpfShaderTest.zip
It should look like this:
Hi,@petsuter.Could you share the steps to reproduce the problem? I tested your WpfShaderTest application and got the result as expected behavior.
Hi @LiuHuiii, thanks for testing. I just run the attached project and it looks broken (red is visible). There are no additional steps. I just did the following steps again now to confirm:
WpfShaderTest.sln
in Visual Studio 2022If you did that and saw no red bars, then I guess there might be some unknown other condition (GPU driver, versions, ...) maybe.
My notebook has two GPUs: Intel UHD Graphics 630 and NVIDIA GeForce GTX 1650 I can use the NVIDIA Control Panel to select / force which one is used. I just noticed now, in the test project the problem only occurs when the Intel GPU is selected.
With the NVIDIA GPU the problem still occurs, but only at even higher zoom levels, e.g. if I change the line
from var rect = new Rect() { X = 300, Y = -3000, Width = 3400, Height = 3400 };
to var rect = new Rect() { X = 300, Y = -6400, Width = 7000, Height = 7000 };
Are custom shader effects applied to some intermediate target with limited size? Could it be related for example to caps.MaxTextureWidth
? Can the intermediate target be avoided / disabled somehow?
I did not reproduce your problem when I changed the line in the CustomElement class constructor method from var rect = new Rect() { X = 300, Y = -3000, Width = 3400, Height = 3400 };
to var rect = new Rect() { X = 300, Y = -6400, Width = 7000, Height = 7000 };
and it worked fine. Maybe it has something to do with the setup and the specific machine?
Thanks again for testing.
Could you try even larger values?
var rect = new Rect() { X = 300, Y = -16400, Width = 17000, Height = 17000 };
var rect = new Rect() { X = 300, Y = -26400, Width = 27000, Height = 27000 };
Maybe it has something to do with the setup and the specific machine?
Right. Could you use dxcapsviewer ( C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\dxcapsviewer.exe
)
and confirm the GPU name under "Direct3D9 Devices"
and the MaxTextureWidth under its "D3D Device Types > HAL > Caps"?
I can't test this due to GPU issues. Maybe other communities can help you.
On a different computer, selecting via Windows Graphics Settings between:
Both GPUs show the issue with the following (or higher, but not lower) values:
var rect = new Rect() { X = 300, Y = -16400, Width = 17000, Height = 17000 };
On a similar notebook also with:
var rect = new Rect() { X = 300, Y = -7900, Width = 8500, Height = 8500 };
is the cutoff.var rect = new Rect() { X = 300, Y = -15900, Width = 16500, Height = 16500 };
is the cutoff.due to GPU issues. Maybe other communities can help you
Are you saying this is not offtopic for WPF? I think other communities would need more information from WPF team. For example:
Are WPF custom shader effects applied to some intermediate target with limited size? Could it be related for example to
caps.MaxTextureWidth
? Can the intermediate target be avoided / disabled somehow?
What is the difference in low-level (D3D9?) API calls when a custom shader effect is used or not?
Description
Use a ShaderEffect similar to the example from the API docs. Use it on a large visual (e.g. a large rectangle or image.) Problem: Not the entire visual is drawn, if any effect is applied. (It does not matter what the effect does.)
Reproduction Steps
(Or use the attached full project below.)
With this C# code:
And this trivial pixel shader file
TestEffect.ps
:And this trivial XAML file
MainWindow.xaml
:Compile and run it.
Expected behavior
The two visuals are drawn with the same rectangle coordinates, so they should cover the same area.
The second (magenta) visual with the effect should be positioned correctly and fully / exactly cover the first (red) visual.
Actual behavior
The first (red) rectangle (without effect) is positioned correctly. The second (magenta) rectangle (with effect) is positioned slightly incorrectly, so the red rectangle is not fully covered.
Regression?
Not sure.
Known Workarounds
None.
Impact
The real use case is an image viewer for very large images with deep zoom levels. This bug also happens when drawing images, not only when drawing rectangles. The image is then not completely displayed! Some parts are just missing! And with larger sizes / deeper zoom levels more and more of the image is missing.
So the impact is that it's impossible to rely on WPF for drawing large images with an effect applied. The effects are required to perform interactive image manipulations (thresholding, color space conversion, ...)
Configuration
.NET 8 Windows 11 x64 I assume this is not specific to that configuration.
Other information
None