iridia_interface/lib.rs
1//! What a compiled shader program exposes, as plain data: its inputs and outputs, its resources (constant buffers with
2//! explicit layouts, textures, samplers, buffers, storage) and the stage's own facts, the fixed-function state it is drawn
3//! with, and what the analyses of `iridia` observe of its code, independent of any graphics API.
4//!
5//! A reader maps its API's reflection into this once and keeps the API's own names and addresses in provenance, so a
6//! consumer that only needs meaning (a binding step, a validator, a writer) never sees an API's enum numbers. The
7//! rule for differences between APIs: conventions are normalized (D3D register packing is unpacked into one varying
8//! per label, D3D, std140 and DX9 constant packings all become explicit byte offsets and strides) and the original is
9//! kept in provenance; behaviour that differs is not hidden here at all (that is the program body's business). A value
10//! a reader cannot map is refused by name, never mapped to a guess.
11//!
12//! Everything is plain data: owned strings, integers and enums, no handles and no GPU types, and every type
13//! implements `serde::Serialize`, so the vocabulary can be shown, stored and compared. What a program's inputs,
14//! constants and outputs stand for (a view-projection matrix, an albedo) is not here: that is decided by whoever binds
15//! the program to a renderer or a baker, in its own terms.
16//!
17//! # Contents
18//!
19//! - [`Interface`]: the [`Stage`], the [`Varying`]s a program takes and gives (by [`Label`], with a [`SystemValue`]
20//! where the pipeline supplies it, an [`Interpolation`] and the D3D register and lanes in [`VaryingProvenance`]), its
21//! [`Resource`]s and the per-stage [`StageFacts`] (tessellation, geometry, mesh and ray tracing facts).
22//! - [`Resource`] and [`ResourceKind`]: constant buffers with a [`BufferLayout`] of [`Constant`]s whose [`ConstantType`]
23//! states every stride, textures, samplers, buffers and storage.
24//! - [`ShaderFormat`]: how a program's bytes are encoded; [`InstructionCount`]: how large a program is.
25//! - [`RenderState`] (blend, depth, stencil, cull, fill, alpha test) and [`SamplerState`] (filters, addressing,
26//! comparison): Direct3D's fixed-function state, as a source states it.
27//! - What a program's code shows, as `iridia`'s analyses read it: [`MatrixLines`] (whether a constant's lines are a
28//! matrix's rows or its columns), [`AlphaComparison`] (what a discard compares a constant with) and [`OutputUse`]
29//! (what tests or blends an output's lanes); and [`ConstantBufferBinding`], the size a source binds a constant buffer
30//! with.
31//!
32//! # Example
33//!
34//! An interface is built by a reader (`iridia-dxbc`, `iridia-dxil`), but it is only data; this one is written by hand and
35//! serialized:
36//!
37//! ```
38//! use iridia_interface::{
39//! Interface, Label, ScalarType, Stage, StageFacts, SystemValue, Value, Varying, VaryingProvenance,
40//! };
41//!
42//! let colour = Varying {
43//! label: Label { name: "SV_Target".into(), index: 0 },
44//! system: Some(SystemValue::Target(0)),
45//! value: Value { scalar: ScalarType::Float, width: 4 },
46//! interp: None,
47//! used: true,
48//! provenance: VaryingProvenance::default(),
49//! };
50//! let interface = Interface {
51//! stage: Stage::Pixel,
52//! inputs: Vec::new(),
53//! outputs: vec![colour],
54//! resources: Vec::new(),
55//! facts: StageFacts::None,
56//! };
57//! let json = serde_json::to_string(&interface)?;
58//! assert!(json.contains(r#""stage":"pixel""#));
59//! # Ok::<(), serde_json::Error>(())
60//! ```
61#![deny(missing_docs)]
62#![deny(clippy::disallowed_methods, clippy::disallowed_types)]
63#![cfg_attr(
64 not(test),
65 deny(
66 clippy::indexing_slicing,
67 clippy::arithmetic_side_effects,
68 clippy::cast_possible_truncation
69 )
70)]
71
72// Run the examples in the README as doc tests.
73#[cfg(doctest)]
74#[doc = include_str!("../README.md")]
75struct ReadmeExamples;
76
77mod binding;
78mod facts;
79mod interface;
80mod resource;
81mod stage;
82mod state;
83
84pub use binding::{AlphaComparison, ConstantBufferBinding, MatrixLines, OutputUse, Unshown};
85pub use facts::{InstructionCount, InstructionUnit};
86pub use interface::{
87 D3dSignature, DomainFacts, GeometryFacts, GsInput, GsOutput, HitGroup, HitGroupKind, HullFacts,
88 Interface, InterpMode, InterpSampling, Interpolation, Label, MeshFacts, MeshTopology, Partitioning,
89 RayTracingFacts, ScalarType, StageFacts, Subobject, SystemValue, TessDomain, TessTopology, Value,
90 Varying, VaryingProvenance,
91};
92pub use resource::{
93 Access, BufferKind, BufferLayout, Constant, ConstantType, D3dBinding, D3dClass, Majorness, Member,
94 Resource, ResourceId, ResourceKind, ResourceProvenance, SampleType, StorageTarget, TextureDim,
95};
96pub use stage::{ShaderFormat, Stage};
97pub use state::{
98 AddressMode, AlphaTest, Blend, BlendEquation, BlendFactor, BlendOp, Compare, Cull, DepthBias, DepthState,
99 Fill, Filter, Filters, MipFilter, RenderState, SamplerState, Stencil, StencilFace, StencilOp,
100 TargetState,
101};