I found a sample about how to run a HLSL code with DirectCompute.


This is the HLSL script I want to run


It doesn't seem the same as the BasicCompute sample. First, the main function's name is called "main" instead of "CSMain". Second, it uses data types like float2, float3 and float4 while BasicCompute uses standard data types. So, is it the same or something else?

Will DirectCompute run this script or it has to be done through other means?

  • \$\begingroup\$ Why a downvote and no answer? Anyone knows the answer? \$\endgroup\$ Jul 7, 2015 at 0:58
  • \$\begingroup\$ Have you tried it? Tell us what you've done already and what's not working about it. \$\endgroup\$
    – House
    Jul 7, 2015 at 3:45
  • \$\begingroup\$ Before implementing anything, I'd want to be sure to be implementing the right solution to execute that file. Are you saying these differences are normal and that it should run fine? \$\endgroup\$ Jul 7, 2015 at 4:27
  • \$\begingroup\$ I tried copying a very simple HLSL file into the BasicCompute sample. The project doesn't even compile. It says "error X4545: vs_2_0 target does not support texture lookups". It uses 2D Texture (tex2D) to store video frame data into a buffer. \$\endgroup\$ Jul 7, 2015 at 14:41

2 Answers 2


It appears there are syntax differences between HLSL for DX9 and DX11. I'm pretty such the above script was written for DX9, so it won't work as-is on DX11.


EDIT: After doing research, HLSL is supported both in DX9 and DX11. You generally pre-compile HLSL with fxc.exe and you have to specify the language format being used (ps_3_0 in my case). Thus, there are various versions of the language but it's not related to the DirectX version. As for the main function's name, fxc.exe also takes the main function's name as a parameter so that's not restricted to a standard name, the function can be called whatever you want.

  • \$\begingroup\$ You can often compile DX9 shaders using the /Gec or D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY (Enable backwards compatibility mode.) flags. That said, DX9 shaders were always Vertex Shaders or Pixel Shaders. They were never other kinds of shaders like DirectCompute, Hull/Domain Tessellation, or Geometry Shaders. \$\endgroup\$ Jul 8, 2015 at 6:03

If you are targeting ps_3_0 then u are using a pixel shader not a compute shader, compute shaders can only be use from dx10 and up.

The code u linked is a pixel shader not a compute shader.

Like chuck said u can use the /gec switch but unless u need to port shaders from dx9-dx11 I would just write dx11 hlsl and forget the dx9 stuff.

The main difference is the way u sample textures in dx11 hlsl vs dx9 hlsl, just having a look at that shader u linked u will only need to change 10-15 lines of code for it work.

look at the msdn docs for directX they are a massive help.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .