Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill Usage of DirectX SDK (June 2010) #733

Merged
merged 14 commits into from
Dec 16, 2020
Merged

Kill Usage of DirectX SDK (June 2010) #733

merged 14 commits into from
Dec 16, 2020

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented Dec 4, 2020

This kills off usage of the DirectX SDK from June 2010 in favor of the DirectX support built into the Windows 8 SDK, which has come with Visual Studio since VS 2013. This change will allow us to avoid requiring yet another dependency and allow building on GitHub Actions, where the DXSDK is not preinstalled (unlike AppVeyor). This change means that the following components are no longer available:

  • DxErr
  • DirectDraw (obsolete)
  • DirectSound (obsolete)
  • DirectInput (obsolete)
  • Direct3D9X

The DxErr deprecation was handled by converting to the standard Win32 HRESULT handling mechanisms. The DirectX HRESULTs are now in the Windows SDK itself, so no special handler is needed.

The Direct3D9X deprecation is a bit more problematic and why this pull request is still a WIP draft. The nice matrix class was fairly easy to replace with the base matrix and with XMMATRIX(in one particular place). The problem is with plDXVertexShader, plDXPixelShader, and with plShaderAssembler. The Plasma shaders are all written in assembly and built with D3DXAssembleShaderFromFile, which is now gone. The closest analogue is D3DCompileFromFile, which, per the documentation expects HLSL. I have yet to test compiling Plasma's shaders with this replacement method, but I suspect we will have to either rewrite the shaders in HLSL or find some other method forward. For now, this problem is blocking the PR.


After a bit of reverse engineering, I've arrived at a solution to finish killing off the dependency on D3DX9. When assembling shaders, D3DX9 effectively forwards the entire shader to a function in D3Dcompiler_[0-9][0-9].dll named D3DAssemble. This function is not publicly documented, but it is exported from the June 2010 DX SDK compiler through modern Windows SDKs. I refactored plShaderAssembler.exe to load the pointer to this method and assemble the shaders with this function. The resulting assembled shader bytecode appears identical to what is currently checked in.

I also removed support for assembling shaders at runtime from plDXVertexShader and plDXPixelShader. I'm sure this was great when Cyan was developing the engine, but we've never changed the shaders. I think if we do, we'll want to operate at a level higher than assembly (eg HLSL) and therefore would need to rewrite the code anyway.

Now that the final dependency on D3DX9 has been removed, I turned the DirectX SDK finder into a dumb list of libraries: d3d9 and D3Dcompiler. I'm not sure how clean that is--commentary welcome. The code now compiles without referencing the standalone DirectX SDK at all and appears to work correctly. As a bonus, I fixed an ST::bad_format error in plShaderAssembler.

D3DX is gone, so we have to use the standard D3DCompiler library. Sadly,
the D3DCompiler only publicly offers an HLSL Compiler and not an
assembler. However, after disassembling d3dx, I found that D3DX just
dispatches assembler calls into an undocumented export in D3DCompile. We
now use this to assemble the shaders from the assembly source.

If someone wants to add support for HLSL shaders, it should probably be
done in a separate program.
@Hoikas Hoikas changed the title WIP: Kill Usage of DirectX SDK (June 2010) Kill Usage of DirectX SDK (June 2010) Dec 8, 2020
@Hoikas Hoikas marked this pull request as ready for review December 8, 2020 21:24
@Hoikas
Copy link
Member Author

Hoikas commented Dec 15, 2020

Manually merged master to fix conflicts.

@Hoikas
Copy link
Member Author

Hoikas commented Dec 16, 2020

Manually merged master to fix conflicts. (again)

@Hoikas
Copy link
Member Author

Hoikas commented Dec 16, 2020

Note for posterity: we'll clean-up the stubbed FindDirectX cmake module in an upcoming cmake pass.

@Hoikas Hoikas merged commit 11f34bc into H-uru:master Dec 16, 2020
@Hoikas Hoikas deleted the dxsdk branch December 16, 2020 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants