Skip to content

Commit df89159

Browse files
dsabadie-datadogColonelThirtyTwo
authored andcommitted
Pipelines and gates design doc.
1 parent d81f9f2 commit df89159

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/design.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ This document describes the overall design of [luminance].
4444
* [Samplers and sampler types](#samplers-and-sampler-types)
4545
* [Texture binding](#texture-binding)
4646
* [Pipelines and gates](#pipelines-and-gates)
47+
* [Obtaining a pipeline gate](#obtaining-a-pipeline-gate)
48+
* [Shading gates](#shading-gates)
49+
* [Render gates](#render-gates)
4750
* [Queries](#queries)
4851

4952
<!-- vim-markdown-toc -->
@@ -794,6 +797,44 @@ only way to pass a texture to a shader for reading.
794797

795798
## Pipelines and gates
796799

800+
Pipelines and gates play an important role in how computations are effectively performed. The design befind pipelines
801+
and gates is based on the Rust type system and its lifetime / borrow semantics, and how graphics scarce resources should
802+
be shared.
803+
804+
The idea is that there is a tree-like hierarchy of how resources are used and shared. At the top of the tree is found a
805+
framebuffer. Everything under it, in the tree, will then be affecting the tree (i.e. they will partake into rendering
806+
into it). Under a framebuffer can be found shaders. Each shader is a node directly connected to the framebuffer node.
807+
Under each shader node are render nodes, which encode various render options (those are encoded as `RenderState`),
808+
allowing to customize how tessellations will be rendered. And under each render node is found… tessellations to render
809+
(strictly speaking, `TessView`, because it’s possible to ask the backend to partially render tessellations).
810+
811+
Two main ideas were imagined to represent such a sharing and running of resources:
812+
813+
1. Implement a datastructure encoding that graph / tree.
814+
2. Recognize that code itself is a tree (i.e. AST), and leverage this and Rust’s borrow and lifetime system to enforce
815+
it.
816+
817+
The second point was chosen, as it feels more natural and can benefit from using the type system to track all objects.
818+
_“Gates”_ are the names given to those nodes mentioned earlier.
819+
820+
### Obtaining a pipeline gate
821+
822+
A pipeline gate is the top-most object in the graphics tree and is obtained via `GraphicsContext::new_pipeline_gate`.
823+
That object can then be used to create the first framebuffer node via `PipelineGate::pipeline`. That function expects a
824+
`FnOnce(Pipeline, ShadingGate)` (simplified for short). The `Pipeline` argument represents the running pipeline and
825+
allows to perform various operations, such as binding a texture or a shader data. The second argument represents the
826+
next gate down the tree, `ShadingGate`.
827+
828+
### Shading gates
829+
830+
Shading gates allow to shade with a given shader `Program`. Doing so will provide the user back with the uniform
831+
interface attached with the shader programs and allow them to change the uniform values. Shading gates, once entered via
832+
the `FnOnce`, will also provide a `RenderGate`, allowing to go down the tree once again.
833+
834+
### Render gates
835+
836+
Render gates create a sharing node around `RenderState`, allowing to render using the same `RenderState`.
837+
797838
## Queries
798839

799840
[luminance]: https://crates.io/crates/luminance

0 commit comments

Comments
 (0)