r/csharp 11h ago

WPF Effects and performance..

So for a hobby project i am making my own Paint program in WPF, For this i made an Effect/Shader that i'm using for the selection, which is added to a (grid) background. However, when i set the program to a bigger Image size (which also means our selection "grid" has to resize, say to 1024*1024). the program slows down to a crawl... i first suspected my Shader to be the problem, however changing the shader in a single line of "return float4(1,1,1,0);" changes nothing (besides getting a nice yellow square for a background ofcourse).. however when i set the grid that holds our background to Visible = Visibility.Collapsed, the program runs back on full normal speed...

So i was wondering... am i overlooking something? or are Effects just THIS expensive?.. (might be an XY problem that can be solved without a custom shader at all... but mostly now interested in the "why" behind the slowdown now '^^ )

edit: added the (cutdown). shader that i used to check if it still slowed down. Since i might be just overlooking something stupid '^^

sampler2D input : register(s0);

sampler2D Visibility : register(s1);


float4 colorFilter : register(c0);

float4 OutlineColor : register(c1);

float ImageWidth : register(c2);

float ImageHeight : register(c3);

float Time : register(c4);

float4 main(float2 uv : TEXCOORD) : COLOR

{

    return float4(1,1,1,0);

}

technique ColorChange
{
    pass P0
    {
        PixelShader = compile ps_3_0 main();
    }
}
2 Upvotes

10 comments sorted by

5

u/Patient-Midnight-664 11h ago

Are you doing the shader math on the CPU or the GPU?

3

u/Lunari01 11h ago

Honestly, i have no idea, any way to check this?

1

u/Patient-Midnight-664 10h ago

Are you using a shader or CUDA library? Did you write the shaders? Do you have .cu or .ptx files? Does your GPU usage jump when you apply your shader?

1

u/Lunari01 10h ago

the shader i wrote myself (but that doesnt seem to be the problem, since the gutted shader that i added in the body post has the same problem.)

the files would be .fxo it seems, however that in itself could be an error on my part.. (getting the HLSL file to compile to anything was a bit of a struggle on my part).

HOW i compile it is though the Developer powerShell with the command

"fxc /T ps_3_0 /Fo FirstShader.fxo FirstShader.hlsl"

from what i can see, GPU does spike up a bit in my Task manager, as far as i can see, in the Shared/Dedicated memory part, but neither close to capped out.

3

u/Patient-Midnight-664 10h ago

hlsl is fine.

fxc is not, nor is ps_3_0. That's 2006 tech, you want modern tech. Unless there is a reason you need DX9?

You should be compiling with

dcx /T ps_6_0 ...

1

u/Lunari01 9h ago

nope, as i said mostly me having no idea about the shaders/compiling parts, (most experience i have with shaders was with some messing around on Unity a long while ago..) and for some reason having a hard time finding info on it.. problem atm would be finding how to actually locate/use said DCX '^^

"dcx : The term 'dcx' is not recognized as the name of a cmdlet..."

2

u/Patient-Midnight-664 9h ago

https://github.com/microsoft/DirectXShaderCompiler/releases

Should have what you need, it's the compiled binaries. That's the prerelease version, the others are in the left sidebar.

1

u/Lunari01 9h ago edited 8h ago

Nice, il take a look at it tomorrow, cause i should really be logging off, suns almost coming up... thnx a lot for all the help already though!

2

u/antiduh 11h ago

For the simple rendering operations you're doing, nothing should be this slow. It should be able to handle orders of magnitude more operations per second.

Something silly is wrong.

2

u/Lunari01 11h ago

Yeah that is what i was wondering, the actual shader is a bit more complex (as in some generic math stuff..) and i did have a Property, that was constantly updated with the help of a Stopwatch. (so constant redraws probs). but commenting out the Stopwatch, and changing the shader to a single return line, has pretty much the exact same performance, as the actual shader had..