directxhlsldirectx-9

Upgrading an existing D3D9 SH3 project to SH4?


I have an old DirectX 3D 9 Visual Stuido project that I have recently been working on.

I have been diving into the world of rendering & HLSL shaders, however it is becoming quite apparent to me that Shader Model 3 is rather limiting. Looking over the MS Docs for Shader Model 3 and 4, it appears that 4 was quite an upgrade. Attempting to compile my project with any HLSL shader higher than 3_0 yields error X3506: Only 3_x and earlier targets are supported on this compiler., hence I figured that my project needs it's compiler upgraded.

It appears that my project automatically loads D3DCompiler_43.dll from SysWOW64, however after looking into that system folder, it appears I already do have D3DCompiler_47.dll. I also read online that there is a supposed "legacy" mode for SH4, however I'm a bit confused on how to implement it properly. After looking at the MS Docs for the compile syntax (https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-syntax), when compiling my pixel shader, using keywords such as ps_4_0_level_9_0 would allow it to be ran on D3D9, however that yields error X3523: DX9-style intrinsics are disabled when not in dx9 compatibility mode.. I'm kinda lost at this point as to what needs to be done to upgrade my project.

Is upgrading an existing SH3 project to SH4 even possible to do in D3D9? Is it even possible to get my project to run D3DCompiler_47.dll instead of D3DCompiler_43.dll?

Any help is appreciated, thank you for reading my post!


Solution

  • Shader Model 4.0 is only supported by Direct3D 10 or later. To make use of it, you must move past legacy Direct3D 9. The recommendation would be to move to Direct3D 11.

    Shader Model 4.0+ shaders are not supported by Direct3D 9 era hardware. The "10level9" HLSL profiles for modern Direct3D that are required to build shaders compatible with Direct3D Hardware Feature Level 9.x actually produces TWO shader blobs: Shader Model 4.0 for D3D10+ hardware and Shader Model 2.x for D3D9 hardware.

    The error X3506 is output whenever you attempt to use Shader Model 4 or later via the D3DX9 interfaces to the compiler. It works if you use the D3DCompile APIs, although #43 is quite old. You can use the D3DCompiler_47.DLL to build Shader Model 2.0 and Shader Model 3.0 for Direct3D 9. The DLL itself works on Windows 7 SP1 or later, but won't load on Windows XP. See this blog post for more on the #47 compiler and it's uses.

    There is a 'compatibility mode' for the HLSL compiler to accept the older DX9-style shader syntax. This is the /Gec switch or the D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY flag. These 'breaking changes' were introduced in the March 2008 legacy DirectX SDK:

    If you are using D3DCompiler_43.DLL, then you still have the legacy DirectX SDK. Note that there's a better option for using D3DX9/D3DX10/D3DX11 these days via NuGet that avoids numerous conflicts with modern Windows SDK headers. See this blog post.