microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.15k stars 476 forks source link

Why a lot of (maybe all) d3d/d2d/dwrite APIs are marked as unsafe? #2012

Closed seungha-yang closed 1 year ago

seungha-yang commented 1 year ago

Probably duplication of (or somewhat related to) https://github.com/microsoft/windows-rs/issues/1506 and https://github.com/microsoft/windows-rs/issues/1782

Feel free to close this issue if this is a kind of duplicated one (but I'm asking in directX scope fwiw).

The unsafe is because those APIs are not thread-safe? (ID3D11Device should be thread-safe by default, ID3D11DeviceContext requires serialization though, and similar rule is applied to d2d depending on the way of construction time flags), or is there other concern?

kennykerr commented 1 year ago

Mostly the unsafe exists on non-WinRT APIs as we don't know how to reason about the safety of the calls themselves. I would like to relax this restriction as the blanket policy on all Win32 APIs is overly restrictive.

See this comment: https://github.com/microsoft/windows-rs/issues/1506#issuecomment-1050507750