-
Notifications
You must be signed in to change notification settings - Fork 542
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
Direct3D12 sample doesn't render properly in release builds #3406
Comments
Good catch - that sample can definitely be simplified. |
The sample follows the same strategy as the C++ version (https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12HelloWorld/src/HelloTriangle/Win32Application.cpp#L104). I've not heard of any issues with that one. It'd be good to try and understand why there's a difference in behavior here before making any changes. |
I tested and sure enough |
The Note making the pointer read volatile or using the return value of |
I'll look into it when I have a moment but from the description it sounds suspiciously like there's UB lurking somewhere in the unsafe code. |
I looked at the code 🎉. Thanks to @riverar for narrowing it down, I think I identified the cause as being the transmute, which creates a pointer without provenance. Hopefully #3419 should fix this, if you'd like to test it. |
I saw that too but it doesn't quite explain why the compiler suddenly optimizes the entire arm out. Something still seems amiss. |
Dereferencing a pointer without provenance is UB. Any branch that reaches UB "can't happen" and so LLVM is within its right to optimize out unreachable branches. |
It certainly fixes the problem. 😉 |
Printing the return value of the I'm OK with the change, since transmuting integers to pointers for non-zero sized reads is explicitly documented as undefined behavior, but it feels like there's something else lurking here. |
I think the UB fully explains it. It's just that |
Summary
Overview
This issue is regarding the DirectX12 triangle sample located at:
crates/samples/windows/direct3d12/src/main.rs
Issue Description
The triangle sample shows different behavior between debug and release builds:
Reproduction Steps
Root Cause
The current implementation relies on WM_PAINT messages for rendering:
This approach may not trigger frequently enough in release builds due to optimization, leading to inconsistent rendering behavior.
Suggested Fix
Implement continuous rendering in the main message loop instead of relying on WM_PAINT:
Environment
Rust Version: rustc 1.85.0-nightly (dd84b7d5e 2024-12-27)
Windows Version: Windows 11 Version 24H2 (OS Build 26100.2605)
Graphics Card: NVIDIA GeForce RTX 2060
Driver Version: GeForce Game Ready Driver 555.97
Crate manifest
https://github.com/microsoft/windows-rs/blob/master/crates/samples/windows/direct3d12/Cargo.toml
Crate code
The text was updated successfully, but these errors were encountered: