Skip to content

D3D12: Fix shader model check, initialization error handling #108919

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KeyboardDanni
Copy link
Contributor

@KeyboardDanni KeyboardDanni commented Jul 23, 2025

Partial fix for #98207 and #98848

The D3D12 initialization code was checking whether the calls to CheckFeatureSupport() succeeded, but not the actual returned data, so it would continue initializing even if the Shader Model of the device was too old.

Additionally, if this code were to throw an initialization error, Godot would crash trying to uninitialize partially initialized data, due either to missing checks or bad init/deinit order.

This is only a partial fix because it doesn't automatically fallback to GL, but it at least displays a friendly error dialog (with instructions on switching renderer) instead of crashing, which is better than nothing.

In order for the automatic fallback to work, the Shader Model version check would have to be moved into the ContextDriver, but that requires the ID3D12Device which lives in (and is initialized by) the DeviceDriver.

I also bumped the minimum required Shader Model version from 6.0 to 6.1 per this comment.

@KeyboardDanni KeyboardDanni requested a review from a team as a code owner July 23, 2025 22:02
@KeyboardDanni
Copy link
Contributor Author

cc @DarioSamo , looking for your input on Shader Model version.

@Calinou Calinou added this to the 4.5 milestone Jul 23, 2025
@Calinou Calinou added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Jul 23, 2025
@DarioSamo
Copy link
Contributor

DarioSamo commented Jul 24, 2025

The suggested change makes sense, but there seems to be unrelated changes polluting the commit a bit. Are they intentional? It might be best to move them to a separate PR if they are.

@KeyboardDanni
Copy link
Contributor Author

Not unrelated. They're required in order for the D3D12 driver to uninitialize without Godot crashing.

@DarioSamo
Copy link
Contributor

Not unrelated. They're required in order for the D3D12 driver to uninitialize without Godot crashing.

Wouldn't some of these imply any driver can cause the engine to crash if it fails to initialize then, not just D3D12? It seems odd for it to be able to reach some of the code that was changed in the first place if that happens.

@KeyboardDanni
Copy link
Contributor Author

Wouldn't some of these imply any driver can cause the engine to crash if it fails to initialize then, not just D3D12? It seems odd for it to be able to reach some of the code that was changed in the first place if that happens.

Some of the stuff was getting initialized in the wrong order. This just fixes that so we don't have partial frames initialization causing the cleanup code to think there's resources that aren't there.

This stuff could probably use null checks, but I'm unsure if that's by design for performance reasons.

@DarioSamo
Copy link
Contributor

The GLSL change makes sense to me, but I think we should probably investigate a bit deeper into why it can possibly reach the code that was modified for RenderingDevice. It's just a bit of a small code smell to me that that happens in the first place. I'll check in a bit.

@KeyboardDanni
Copy link
Contributor Author

I've been testing this by commenting out shader_capabilities.shader_model = shader_model.HighestShaderModel; on line 5830. That's how I arrived at the changes to RenderingDevice.

I think in general, renderer backend init/deinit could use a bit of refactoring. I'm just unsure of the best way to do that as someone who's relatively new to this aspect of the codebase.

@DarioSamo
Copy link
Contributor

This line should be wrapped with if frames not empty check based on the render graph's own state instead.

_wait_for_secondary_command_buffer_tasks();

@Repiteo
Copy link
Contributor

Repiteo commented Jul 28, 2025

@KeyboardDanni Have you gotten the chance to integrate Dario's suggestions?

@KeyboardDanni KeyboardDanni force-pushed the d3d12_init_shader_model_check branch from cada249 to 42a6adc Compare July 28, 2025 16:54
@KeyboardDanni
Copy link
Contributor Author

@Repiteo Requested change has been made.

@DarioSamo
Copy link
Contributor

DarioSamo commented Jul 28, 2025

Changes look good to me, but I'm a bit suspect about the SM 6.1 change.

As per this page, the additions to SM 6.1 seem to be:

[SV_ViewID](https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_ViewID). This feature enables instancing of the graphics pipeline by "view", in a manner that is orthogonal to draw instancing.
[SV_Barycentrics](https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_Barycentrics). This is a new system-generated value available in pixel shaders, used for example to perform interpolation over small or unaligned values like a few bits from a 32-bit value.

ViewID is only relevant for multiview (XR), so unless it is enabled, it won't get compiled. And I don't think there's a GLSL construct for barycentrics. I'm not sure the provided comment is good enough of a justification to bump the minimum SM required unless we get something that proves it necessary.

@KeyboardDanni KeyboardDanni force-pushed the d3d12_init_shader_model_check branch from 42a6adc to bf6629a Compare July 29, 2025 00:36
@KeyboardDanni
Copy link
Contributor Author

Could someone gently prod the CI? It failed on web build with a 503 trying to get emsdk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release platform:windows topic:porting topic:rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants