Coder Social home page Coder Social logo

thindx's Introduction

🦀 thindx - Thin DirectX 🦀

Safer DirectX: Types, fns, lifetimes, tests, real docs, intellisense, examples, debug visualizers, ...

🦀 When DirectX APIs
📦 examplesrust ⮀ c++test coveragelib.rsdocs.rs
✔️ Now thindx::{d3d9, d3d::Compiler, xaudio2, xinput}
⚠️ Soon™ d3d11, d3d12, dxgi, dxcompiler, dinput
⚠️ Eventually d2d, dcompute, dsound, dstorage, dwrite, dxr, xact3, uwp::input?
Never? d3d10, d3dx*, ddraw, dplay

GitHub Build Status crates.io docs.rs License

❌ This crate is probably unsound! ❌

I'm exposing a huge legacy C++ API to Rust. Mistakes will happen.

That said, soundness is a very high priority goal. thindx will add things like extra bounds checks, parameter validation, extra init, etc. if need be in order to ensure soundness in safe fns whenever possible. When it's not possible to validate unsoundness away, the fns in question should be marked unsafe. This crate strives to be sounder than whatever manual FFI you'd write yourself would be, and that's a high bar.

But there are some practical limits to this. If a background driver thread invokes UB if it fails to allocate memory, without any direct correlation to specific API misuse like a large integer overflowing, that's a bug I can't sanely mitigate via safe fns. I mean, theoretically I could write a pure-software clone of the entire DirectX runtime... but no.

Additionally, while I'm seeking to validate my APIs via testing, older implementations of the APIs in question may have more bugs / unchecked parameters / ??? that I'll fail to mitigate due to being unable to trigger them myself. While I'm happy to investigate, accept pull requests, expand test coverage, etc. it's worth assuming this crate is unsound on older versions unless you've tested yourself.

⚠️ API major version churn ⚠️

0.0.0-yyyy-mm-dd doesn't follow semver. Individual fns are likely to gain/lose unsafe, traits, etc. in a neverending attempt to make DirectX access sound. As such, thindx itself will likely always suffer from major version churn. This isn't too much of a problem until two crates wish to share / pass thindx types between themselves. It might be possible to somewhat stabilize some types by exiling them into subcrates, but this has not yet been done. Additionally, individual extension traits / functions / methods will likely never get the same treatment (no need?)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

thindx's People

Contributors

maulingmonkey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

thindx's Issues

Lacking undocumented API support

Tracking issue for unimplemented, undocumented APIs. If you want any of these, you'll have to ask for them explicitly!

  • D3DAssemble
  • D3DReturnFailure1
  • DebugSetMute

autooutput examples

Would be nice to auto-verify test output via proc macro. Two annoyances:

  • Parsing doc attrs
  • Redirecting stdout for capture (maybe override print[ln]! instead?)

Better idea: Separate examples out, and then generate docs embedding output from them, via xtasks doc ?

Lacking D3DDecompressShaders variations

  • decompress_shaders
    • should accept any RangeBounds ?
    • should also accept an array of indicies for gathers?
    • should maybe have an Option-less variant?
  • decompress_shaders_inplace
    • ...ditto?

D3D9 Device + Window soundness safety overhaul

I believe I can make d3d9 hwnd handling 100% sound.

Validate HWND on creation

Validation failures can be coerced to Result s, which should be 100% defined behavior.

Detect Device outliving HWND

Now, to detect when an HWND is yanked out from under a device:

Option 1: Hooks

SetWindowsHookExW(WH_CALLWNDPROCRET, ...)
High overhead - hooks every wndproc, including for window handles we don't really care much about.

Option 2: Patch WNDPROCs

SetWindowLongPtrW(hwnd, GWLP_WNDPROC, ...)
Saner, probably? Note that CallWindowProcW is required to call the original WNDPROC sanely.

Error Handling

  • Emergency destruction of the device is likely impossible.
  • Canceling the destruction of the HWND might be possible (hide it instead?), but would be a bit sketchy?
  • Reparenting the device to a new (hidden) HWND might be possible, but would be a bit sketchy?
  • bugsalot::bug!(...) + std::process::abort() ?

Lacking legacy API support

The following legacy APIs have not been implemented. Ask for 'em if you want me to prioritize them!

  • D3DCompileFromMemory
  • D3DDisassembleCode
  • D3DDisassembleEffect
  • D3DGetCodeDebugInfo
  • D3DPreprocessFromMemory

All According to Keikaku

Soundness Auditing

  • Test out-of-bounds indicies
  • Test invalid params
  • Fuzz test everything
  • OOM test coverage?
  • Test refcount overflow behavior?
  • Test against all variations of the DLL I can get my grubby hands on

Documentation

  • Verify examples for all APIs
  • 911492c Verify new style error docs for all APIs
  • 55ececf Verify all documentation refers to crate types where possible/sane
  • Verify all types listed in crate level preamble mod _headers;
  • 475619b Consistent doc comments order
  • Finalize note CSS styling (quote or div, not both, also padding?) mooted: docs.rs doesn't like stylin'~
  • a138976 d53374a Ensure argument docs match actual arguments
  • Ensure Ok return docs match actual returns (911492c eliminated said docs)
  • Document tested d3dcompiler version in soundness preamble
  • Make version annotations consistent and useful Removed instead
  • Document all flags

Refactoring

  • 9550ffa Deal with D3D11::* and E::* constants conflicting due to being the same type
  • 7d9e60c Make trusting random shader blobs unsafe
  • 3f6e9da Maybe rename crate? But maybe not.
  • Spin out common crate for other thin* crates? To be done on an as needed basis, not up-front.
  • 41841ef Reorganize files by category
  • bac0874 Fix symbol loading table alignment
  • f772785 Write and leverage winstr IntoAs* traits
  • Add non-raw versions of *_raw() desc getters
  • e4fff50 Consistent naming of r#type / type_

Track Missing APIs

Now tracked via https://docs.rs/thindx/*/thindx/_headers/ + // TODO: ...s

  • #2 Lacking D3D10 effects support
  • #3 Lacking undocumented API support
  • #4 Lacking legacy API support
  • #5 Lacking D3DDecompressShaders variations
  • #6 Lacking d3d11shadertracing.h support

Merge THINERR::*

Very similar territory:

  • THINERR::SLICE_TOO_LARGE
  • THINERR::SLICE_OVERFLOW
  • THINERR::ALLOC_OVERFLOW

Lacking D3D10 effects support

Tracking issue for D3DDisassemble10Effect etc.

  • Winapi lacks ID3D10Effect among other interfaces
  • D3DDisassemble10Effect not imported or exposed by this crate

I'm likely to not bother implementing this unless someone specifically asks for it (why not just use d3d11 if you can use d3d10?)
That said, feel free to comment, send a pull request, file new issues, etc. if this is at all important to you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.