Rust-GPU / Rust-GPU/rust-gpu

RFC: link-time capabilities

Offen
#388 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

RFC
Vorherrschende Sprache
Rust
Sterne
3.4k
Forks
126
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Link-time capabilities are capabilities that are not exposed to codegen, but only set at link time. Importantly, changing link-time capabilities does not require a clean recompile, unlike the current spirv capabilities.

I good first experiment ground would likely be Large Integer polyfills, which I think they are better suited at link time. A really common use-case would likely be to emit one shader module with Int64 Capabilitiy enabled, and another with u32 polyfill for all u64 integers. So implementing this at link time would allow you to compile the shader crate only once and link it twice.

There's a few variants I could imagine to specify these link-time capabilities:

  • per entry point in the #[spirv(capability(polyfill_u64))], mapping well with multimodule
  • per shader crate using #![spirv(capability(polyfill_u64))] at root level, mapping well to single module
  • some new system that allows specifying how entry points are grouped, potentially allowing entry points to be emitted in a variety of modules with different link-time capabilities. Maybe not with the first implementation.

Importantly, this should work well with rust features, so you can #[cfg_attr(feature = "u64_emulation", spirv(capability(polyfill_u64)))] and compile only the final shader crate twice, while reusing the remaining compiled crate tree.

I could also see a similar system being employed for usual spirv capabilities in the future, replacing the current pre-declaration of used features in spirv-builder. Similarly to the zombie system, you could attach an OpCapability to a certain instruction. If that instruction is linked into a shader module, add the OpCapability to it. But if it's unused, DCE will kill the instruction thus the capability.

This reverses how you'd enable code that depends on some capability: Currently, you'd declare the capability in spirv-builder and have a #[cfg(target_feature = "")] in your code. With link-time capabilities, you use a normal rust feature like #[cfg(feature = "")]to gate your code requiring some capability, and if the end user enables that feature, it implicitly enables the required capability. The final shader crate binary can itself have features enabled though spirv-builder, that enable features of any such library gating required capabilities like you'd normally do in Cargo.toml.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Lesen des Issues zu den Large Integer polyfills (#307), und verfolge dann, wie spirv-builder derzeit Capabilities deklariert und wie die finale Shader-Crate erstellt wird. Vergleiche die vorgeschlagenen Ansätze pro Entry Point, pro Crate und mit Feature-Gating. Abgeschlossen wäre die Aufgabe, wenn ein festgelegtes Design und ein Implementierungsplan für die Wiederverwendung kompilierter Crates bei gleichzeitigem Linken von Varianten mit unterschiedlichen Capabilities vorliegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.