Jump to content

GPU Motion Blur effect using DirectCompute


Bruce Bowyer-Smyth

Recommended Posts

Slow would be a generous term I would say. It is promoted as being optimized for correctness rather than speed but I don’t know how you could use it as a reference with that performance. I guess that’s why WARP was developed for the rendering side of things.

This is fine for a specialised plugin like this one but like you said if you wanted to use it for core functionality you would probably need a C# fallback version. The viability of that would depend on how often those things needed to be modified I suppose and how much performance benefit you could get.

That can be an impressive amount in some ideal situations. Playing around with the thread count and the MaximumRegionWidth now has the large image processing at 22,098% faster.

Starting to look at packaging and was wondering about the V4 plugin manager. Will it handle prerequisites/dependencies? If not will it be possible to run an msi?

Link to comment
Share on other sites

Starting to look at packaging and was wondering about the V4 plugin manager. Will it handle prerequisites/dependencies? If not will it be possible to run an msi?

Don't know yet. As for the MSI, doubtful. I would encourage you to figure out how to use SlimDX without having to install it, however. Otherwise plugins could end up installing all sorts of things.

Paint.NET v4 will provide access to Direct2D, DirectWrite, and WIC. However I haven't added support for Direct3D simply because it's enormous and I'm not using it in the main app. If I were to add it, then you could use that instead of SlimDX.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

As for the MSI, doubtful. I would encourage you to figure out how to use SlimDX without having to install it, however.

It's licensed under MIT, in fact.

KaHuc.png
Link to comment
Share on other sites

I would encourage you to figure out how to use SlimDX without having to install it, however.

I believe that is possible by just having it in the effect folder and a separate redist for x86 and x64. If that is the case I will probably create a custom build with just the dx11 parts and a new namespace to avoid conflicts.

I haven't added support for Direct3D simply because it's enormous

No doubt. However only a small part of it would be relevant to image post processing. Unlike D2D where you would want most of it, an additive approach to D3D might work better where support is added on demand. At least it can set a baseline and avoid version conflicts between plugins. Maybe compute and pixel shaders and the supporting functions around that. Drawing of primitives probably would want to stay in the realm of 2D.

Maybe that could be handled by the plugin manager? Only downloads D3D support when a plugin needs it.

Link to comment
Share on other sites

Well, and the other reason I haven't added D3D support is that Paint.NET won't be using it. Otherwise there's no "living" test case for the interop layer and there could be bugs. I've already found several bugs in my interop layer implementation but they've been easy to find (and fix) since I'm actually using it.

So for now, and for v4, you'll be on your own for D3D.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Yes I would have thought so too but it seems to be capped between about 2500% and 3500%. I've got some kind of bottle neck going on there but thats a good start.

Didn't bother with the quality setting and just used the equivalent of the high-quality "5" option in Paint.net's radial blur. The algorithms are not the same but the final image is pretty close.

New version posted, includes the zoom blur as well.

Link to comment
Share on other sites

Yes that was my thinking as well due to the huge amount of sampling and the scattered reads. Also when the radius increased the performance went down even though the same amount of work was being done. Probably thrashing the limited cache.

But every roadblock has a detour and this one's name is... Texture2D and the texture cache. If what I have read is correct then StructuredBuffer doesn't use the texture cache. Treating the source image as a texture has meant that caching is better and I could remove the calculations to convert a point to a position in a 1D array and also the manual bit shifting on the pixel read. The performance is now a more respectable constant 4400% when the radius is increased so this definitely looks like the way to go.

The same technique on the large image motion blur takes it up to 27K%. After implementing the code for proper alpha averaging that comes back down to 25K% but still a win there.

Link to comment
Share on other sites

  • 3 weeks later...

Well I'm back from my dependency squashing expedition with some pretty favourable results. Apart from the Vista platform update there is now nothing to install.

I’ve created a custom build of SlimDX that just contains D3D11 and is repointed to the DirectX11 RTM version so that neither it nor the DirectX February update needs to be installed. The custom build can just be copied to the effects folder.

The package now includes the effect dll, and 2 SlimDX dll’s (x86 and x64). Extract all of them into your Paint.NET Effects folder.

I have also fixed up the channel blur alpha handling and removed the reference driver fall back as that was basically not an option.

Let me know if you have any issues with this build and I will release it to the general population if all is well.

Link to comment
Share on other sites

I knew you’d be back Rick. :D Let me know if you decide to go ahead with it and want to trial anything.

With point-and-click cameras now averaging about 12 megapixels and climbing it may be soon become a requirement for some types of effects seeing that CPU’s haven’t been keeping up with that race.

I did actually check out how installation would go but pretty quickly ran into all the troubles that Promit from SlimDX goes on about in this rant. It would have been nice to pre-check a few things like driver versions and display a "<Product Name> could perform faster on your computer" type message but that is one of the trade-offs.

Here's hoping that the installer team have resolved this already and we can expect a "Web Deployment Package" style installer in the future?

Link to comment
Share on other sites

Well if I integrate it into Paint.NET proper, I would simply write my own D3D interop layer. Then installation would be no issue. I would also probably make it so that an effect can use HLSL without needing any of the D3D goop: just give me an HLSL fragment in place of OnRender().

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

All of the effects are giving me an E_INVALIDARG error in a message box when I try to apply them to this image (15204 x 4620 px): http://en.wikipedia....rn_Sky_edit.jpg

post-44714-127861584438_thumb.png

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Just give me an HLSL fragment in place of OnRender().

If you can figure out an generic way to pass parameters then that would be a great setup.

All of the effects are giving me an E_INVALIDARG error in a message box when I try to apply them to this image (15204 x 4620 px)

Hmm DX11 has a texture dimension limit of 16k but it turns out that when running on DX10 hardware the limit is still 8k. I may have to bring back the StructuredBuffer for large images...

Link to comment
Share on other sites

Ok new build is up. Not wanting to give up the texture performance for the most common scenarios I have made it switch to the StructuredBuffer only when the width or height is greater than 8k. This can certainly be done a lot better but for a V1 release it's workable.

Let me know how it goes as I don't have enough video memory to process the full 70 megapixel image.

Link to comment
Share on other sites

Paint.NET "supports" up to 65535 x 65535 pixels, so any effect should also work that high. Normally this isn't a problem because even at such a small value there isn't much probability of oveflowing an Int32.

However, I should point out that if you are doing your own pointer arithmetic, e.g. get the Scan0 pointer then multiply Y and Stride, that you should not. Use GetRowAddress() instead, as it does need to do some bouncing with 64-bit ints in order to ensure an overflow doesn't happen. I found this only late in the v3.5 release cycle and fixed this. v3.36 won't actually work with images over a certain size because of silent overflows when calculating pointer offsets.

I put supports in quotes because the memory requirements would be 12GB to start, plus 4GB per layer. Not very feasible with the current architecture.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

The StructuredBuffer has a 32bit index so it will handle that dimension but similarly the problem is memory which of course there is a lot less of on the video card.

There would be ways around that (virtual texturing?, streaming?) but it might be one for the pro's rather than my level of creating a "Hello Massively Parallel World" effect :)

Link to comment
Share on other sites

I have released a new version over on the published thread. For the motion and gaussian blur I have implemented a completely custom region slicing if the effect is being run against a whole image. With just this change the 960x1280 image goes from 426ms to 189ms. So very important to keep the GPU pipeline full and avoid stalls by copying the results back too often.

Large image is up to 31,725% faster.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...