I'm considering the idea of taking shaders written in HLSL and running them in an AviSynth plugin to process videos. This would allow accessing various shaders, and also to have GPU acceleration. I'm a .NET programmer and have no experience with HLSL, Direct, C++ or AviSynth plugin development. It's a lot to learn at once. So before spending too much time into it, I have a few questions.

  1. Can it easily be done to run a HLSL script in c++, copy the input frame data, and copy the output frame data back, doing a bridge between 2 interfaces?

  2. On computers not supporting OpenCL, will the HLSL script still run on the CPU or refuse to run at all?

  3. I haven't yet found any sample using HLSL that compiles. I can't use Windows Store Templaes on Windows 7 and ActiveX SDK samples run on outdated components that aren't compiling. Where can I find a good tutorial or sample to get started?

This right here seems to describe the basics of what needs to be done. Loading and using an HLSL shader?

  • \$\begingroup\$ Two things that might just help you Google better info: OpenCL has nothing to do with HLSL (OpenCL is a completely separate language and library) and the DirectX API you're looking for is DirectCompute (which is Microsoft's rough equivalent to OpenCL) or possibly you're even just looking for something like Microsoft's AMP (write C++ code that can be offloaded to the GPU). \$\endgroup\$ – Sean Middleditch Jul 6 '15 at 16:33
  • \$\begingroup\$ It sounds like this is getting closer. But then that requires DX11 and won't work on systems with a DX9 graphic card? code.msdn.microsoft.com/windowsdesktop/… \$\endgroup\$ – Etienne Charland Jul 6 '15 at 16:43
  • \$\begingroup\$ It would be OK to limit to DX11 if it could run on the CPU as a fallback plan. Any pointers about how to instead execute the same HLSL script on the CPU? \$\endgroup\$ – Etienne Charland Jul 6 '15 at 17:40
  • \$\begingroup\$ The DirectX 11 API runs on DX9 era hardware through a mechanism called Feature Levels. Feature Level 9.1 covers basically all Direct3D graphics hardware that has a WDDM driver (as opposed to the Windows XP era XPDM). The DirectCompute sample won't work, however, since that requires Feature Level 10.0 with optional support. \$\endgroup\$ – Chuck Walbourn Jul 6 '15 at 18:01
  • \$\begingroup\$ For a Windows desktop DirectX 11 template (i.e. that works on Windows 7), see Direct3D Win32 Game Visual Studio template. For a simple tutorial, see MSDN Code Gallery or GitHub. \$\endgroup\$ – Chuck Walbourn Jul 6 '15 at 18:02

HLSL is the High Level Shader Language used by Direct X. HLSL Shaders are run on the GPU at runtime and can only be run by the CPU in a special debug mode inside of Visual Studio. HLSL requires a Direct X pipeline to be setup in your application. Visual Studio can compile your shaders for you but you have to load them and feed them to your pipeline. You must then instruct Direct X to run your shader logic with given geometry. If you're doing video processing / playback this geometry is probably just a simple rectangular buffer.

Open CL is not Direct X and has no correlation to HLSL other than that they both run on the GPU. If a computer does not support Direct X you will have to detect that when you setup your Direct X pipeline and fall back to a different way to handle your graphics logic or just fail spectacularly (which is what I would recommend, screw CPU side graphics manipulation).

You should use C++ with Direct X as the .NET implementation (XNA Game framework) has been deprecated and while Monogame (the open source implementation of XNA) is excellent I don't think it would work very well with AviSynth. Also I believe XNA and Monogame use FX shaders which are pretty deprecated.

Learning C++ and Direct X is your best bet to get this done but it's no small task. Of course stack exchange is a good place to ask smaller questions if you run into more specific problems along the way :)

| improve this answer | |
  • \$\begingroup\$ For using Direct3D from .NET, your best bet is either SharpDX or SlimDX. See DirectX and .NET \$\endgroup\$ – Chuck Walbourn Jul 6 '15 at 18:04
  • \$\begingroup\$ Ah I guess I'm more of an OpenGL guy so I've never really seen these projects. They seem robust so yes OP may be interested in one of these. That said I'd still recommend C++ but that's up to OP. \$\endgroup\$ – Honeybunch Jul 6 '15 at 18:07
  • \$\begingroup\$ For C++ DirectX 11 development, take a look at DirectX Tool Kit. \$\endgroup\$ – Chuck Walbourn Jul 6 '15 at 18:08
  • \$\begingroup\$ I'll second that. DXTK makes Direct X bearable if you're not into writing everything from scratch. \$\endgroup\$ – Honeybunch Jul 6 '15 at 18:09
  • 2
    \$\begingroup\$ Just wait until you see DirectX 12, Honeybunch. It makes DirectX 11 seem like a paragon of usability :) Great if you are into controlling every aspect of the hardware, but getting started with it is a huge leap... \$\endgroup\$ – Chuck Walbourn Jul 6 '15 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.