Skip to content

Switch to DirectX based render backend#2212

Draft
secsome wants to merge 11 commits into
Phobos-developers:developfrom
secsome:feature/render_dx12
Draft

Switch to DirectX based render backend#2212
secsome wants to merge 11 commits into
Phobos-developers:developfrom
secsome:feature/render_dx12

Conversation

@secsome
Copy link
Copy Markdown
Member

@secsome secsome commented May 16, 2026

YR originally used DDRAW as its rendering backend. However, DDRAW was introduced more than two decades ago, primarily for the graphics hardware environment of that time, where 2D accelerator cards were still common. Modern computers now almost universally use display hardware based on 3D graphics pipelines, and Windows itself has long since migrated to a modern graphics architecture built around DXGI-based swap chains. Therefore, we would like YR to migrate to a modern rendering backend based on DirectX as well.

At present, the community usually achieves similar functionality through DDRAW wrappers, with CNC-DDRAW being one of the common examples. These solutions intercept and forward DDRAW calls, translating them into corresponding modern rendering backend implementations. While this approach can improve compatibility and display quality, it also introduces a limitation: directly using such modern 3D rendering backends to add rendering effects to the YR game engine becomes extremely difficult. The core rendering process still remains within the traditional 2D software rendering model.

Our current approach is based on the SDL implementation in Vinifera. In essence, it is similar to the earlier CNC-DDRAW approach: 2D software rendering is still performed on the CPU. Currently, D3D is mainly used to present the fully rendered frame as a texture to the screen through a fullscreen triangle. Therefore, in theory, its performance should be close to CNC-DDRAW.

At present, the program reads the following configuration from RA2MD.ini:

[DXRender]
PreserveAspectRatio = yes
WindowedBorder = yes
StartFullscreen = yes
PauseGameWhenLoseFocus = yes

In addition, fullscreen and windowed mode can be toggled in-game with Alt+Enter. Please feel free to report any issues you encounter.

Regarding ReShade, this rendering backend may theoretically conflict with the current community ReShade plugin. However, once this backend is functional, the logic currently implemented in ReShade can later be developed directly in Phobos instead of relying on an external DLL, providing more stable and more efficient rendering.

CURRENTLY, BINK MOVIE IS DISABLED, YOU CAN JUST FOCUS ON OTHER PARTS AND SEE IF THEY WORK CORRECTLY

Support for vanilla YR is still WIP, and it seems cannot be easily done in 1 month, I will update as soon as I made any progress.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 16, 2026

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

@TaranDahl TaranDahl added the ⚙️T2 T2 maintainer review is sufficient label May 16, 2026
@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

I think you can start a topic on the forum so that more people can test and communicate. Currently, some Chinese users find it difficult to understand this English title and want to ask questions about windowing and Reshade usage.

@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 16, 2026

I think you can start a topic on the forum so that more people can test and communicate. Currently, some Chinese users find it difficult to understand this English title and want to ask questions about windowing and Reshade usage.

I haven't registered on that forum currently, I'd appreciate it if somebody post this message on that. I will sign up for an account later maybe.

@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 16, 2026

About the reshade stuffs, I think we can integrate the reshade features after switching to the new render backend, because we can use the GPU directly instead of adding an extra library.

@phoboscn-bot

This comment was marked as outdated.

@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

I'd appreciate it if somebody post this message on that. I will sign up for an account later maybe.

The current test template requires filling in some content with subjective information; it would be best for you to create a topic yourself. The topic mentioned in the link above is temporary, and testing for this PR still requires a new topic.

@phoboscn-bot
Copy link
Copy Markdown

To Chinese users:
This pull request has been mentioned on Phobos CN. There might be relevant details there:

致中文用户:
此拉取请求已在 Phobos CN 上被提及。那里可能有相关详细信息:

https://www.phoboscn.top/t/topic/470/1

@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 16, 2026

I'd appreciate it if somebody post this message on that. I will sign up for an account later maybe.

The current test template requires filling in some content with subjective information; it would be best for you to create a topic yourself. The topic mentioned in the link above is temporary, and testing for this PR still requires a new topic.

Done

@IronHammer-Std
Copy link
Copy Markdown

IronHammer-Std commented May 16, 2026

ERROR REPORT

Game Environment

  • Pure YR
  • Ares3.0p1
  • Phobos(Nightly Build 8fe94f2)
  • SyringeIH 0.3b9 (irrelevant, same error using Syringe 0.7.2)

Device Status

7030376aa0f08ef5bbb6f71d62640cd5

Log File :

syringe (without ddraw).log
syringe (with ddraw).log
debug (14).log

Maybe related parts : these functions are in the specific commit.

[20:59:48:163] 0x001ACB48: 0x7BF8AD3A (Phobos.dll!WinDialog_GetRectangle{Hooks.cpp,行101}+3A)[访问权限:读/执行]
[20:59:48:163] 0x001ACB4C: 0x00050C76 (UNKNOWN+50C76)[访问权限:只读]
[20:59:48:163] 0x001ACB50: 0x001ACB5C (UNKNOWN+1ACB5C)[访问权限:读/写]
[20:59:48:163] 0x001ACB54: 0x00DE09A2 (gamemd.exe+9E09A2)[访问权限:只读]
[20:59:48:163] 0x001ACB58: 0x0C17C7C4 (gamemd.exe+BD7C7C4)[访问权限:读/写]
[20:59:48:163] 0x001ACB5C: 0x00000000
[20:59:48:163] 0x001ACB60: 0x00000000
[20:59:48:163] 0x001ACB64: 0x00000780

[20:59:48:164] 0x001ACDA0: 0x7BF8AA60 (Phobos.dll!OwnerDraw_Window_Procedure_{Hooks.cpp,行191}+0)[访问权限:读/执行]
[20:59:48:164] 0x001ACDA4: 0x000004E4
[20:59:48:164] 0x001ACDA8: 0x001AD15C (UNKNOWN+1AD15C)[访问权限:读/写]
[20:59:48:164] 0x001ACDAC: 0x001AD264 (UNKNOWN+1AD264)[访问权限:读/写]

Direct Error Cause

In SUB_432750:

    else
    {
      v26 = Rect.top;
      v27 = v17;
    }
    *(this + 16) = v26;
    *(this + 20) = v22;
    *(this + 24) = v27;
    *(this + 28) = v25;
    *(this + 8) = BinkDDSurfaceType(Primary->VideoSurfacePtr);
    result = 1;
  }

Here Calls BinkDDSurfaceType(Primary->VideoSurfacePtr); , in which Primary->VideoSurfacePtr is NULL.

@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

DeathFishAtEase commented May 16, 2026

ERROR REPORT

image

Please provide the specific Error message.

@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 16, 2026

The vanilla YR support requires us to understand the OwnerDraw procedure, which I haven't figured out already. So currently tests based on cncnet spawner is appreciated

@SadPencil
Copy link
Copy Markdown

SadPencil commented May 16, 2026

CnCNet YR 9.2.0 + c80db5e

The game may freeze for a period of time, during which the BGM plays normally and the cursor moves normally.

AMD Ryzen 7 PRO 6850H, iGPU Radeon 680M, 64 GB RAM (fixed VRAM for the iGPU is set to 4GB), in-game resolution 1920x1080, monitor resolution 3840x2160. Windows 11 25H2.

Video:
https://github.com/user-attachments/assets/395ba3c4-ab25-4334-a1ca-4a28f8cdec38

secsome added 3 commits May 17, 2026 12:37
Prioritize hardware adapter selection using `IDXGIFactory6::EnumAdapterByGpuPreference` for optimal performance. Fall back to `IDXGIFactory4::EnumAdapters1` if `IDXGIFactory6` is unavailable. If no hardware device can be created, attempt to create a WARP device as a last resort. This improves robustness and compatibility across various systems.
@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 17, 2026

Switched to DX11 implementation. Retesting is welcomed

@SadPencil
Copy link
Copy Markdown

To Chinese users: This pull request has been mentioned on Phobos CN. There might be relevant details there:

致中文用户:
此拉取请求已在 Phobos CN 上被提及。那里可能有相关详细信息:

https://www.phoboscn.top/t/topic/468/1

This URL redirects to an HTTP 404 page. @DeathFishAtEase

@DeathFishAtEase
Copy link
Copy Markdown
Collaborator

Yeah, that link is outdated. The correct address is provided in another comment below. I've hidden the old one to avoid confusion.

@SadPencil
Copy link
Copy Markdown

CnCNet YR 9.2.0 + 40df9a3

AMD Ryzen 7 PRO 6850H, iGPU Radeon 680M, 64 GB RAM (fixed VRAM for the iGPU is set to 4GB), in-game resolution 1920x1080, monitor resolution 3840x2160. Windows 11 25H2.

Compared to the previous c80db5e commit, the same phenomenon of "the game may freeze for a period of time, during which the BGM plays normally and the cursor moves normally" has not been observed so far with this 40df9a3 commit.

On this basis, I immediately switched back to the c80db5e commit and observed the phenomenon of "the game may freeze for a period of time, during which the BGM plays normally and the cursor moves normally" again. Therefore, it can be confirmed that this 40df9a3 commit has a significant improvement regarding this issue, at least on my machine.

@FridgeRr
Copy link
Copy Markdown
Contributor

FridgeRr commented May 19, 2026

haven't tested it rigorously but I noticed an immediate improvement in responsiveness/delay/smoothness compared to cncddraw, simply put, it plays like a dream.
AMD R7 5600x, 16gb RAM, 1920x1080 on 1440p 240hz monitor, W10 1903

@secsome
Copy link
Copy Markdown
Member Author

secsome commented May 20, 2026

I'm currently working on the whole OwnerDraw control part as it's essential to make things looks completely correctly. But OwnerDraw is so huge and it might take much more time than already done part(I'm quite busy so im not sure whether this part could be done in 1 month or not). If you want to help testing, currently verifying the spawner based game works is enough. Thanks for everyone testing this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs testing ⚙️T2 T2 maintainer review is sufficient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants