hadronized / spectra

Rust demoscene engine (currently on hold)
122 stars 6 forks source link

Graphics abstraction: blocks #53

Open hadronized opened 5 years ago

hadronized commented 5 years ago
hadronized commented 5 years ago

On GPU blocks

Fundamentals

Blocks are composed of three main parts:

Combinators

There are some block transformations that are combinators:

What’s in the box?

The GLSL is just a simple AST. That is, a Vec<ExternalDeclaration> – see my glsl crate for further details. The idea is that it must define:

Unresolved: identifiers?

In order to authorize a correct naming of structs and functions, they should be named randomly. For instance, the call functions must carry a prefix or suffix. We can use the name of the box for that, but that’s not enough. I think that we need somekind of a context here in order to be able to get a new render block identifier each time a new one must be created. This will prevent nasty conflicts.

hadronized commented 5 years ago

Do we want to be able to reference the call functions from dependent blocks? If so, how so? Also, how do we reference other input / output types from the current block?

X: A -> B
Y: B -> C
Z: A -> C

Here, the first B (output) is not the exact same as the second B (input) if you strictly generate the GLSL code for X, Y and Z. We need to find a way to share B between X and Y for this to work.

hadronized commented 5 years ago

Maybe a lead for implementing composition:

  1. Set the inputs of the composition block to A.
  2. Set the outputs of the composition block to C.
  3. Generate the GLSL code:
    1. Change every occurrence to the Out type in the code of X to InOut_{name_of_composition_block}.
    2. Do the same for In from Y.
    3. Now, inject a single copy of the type (InOut_{name_of_composition_block}) as ExternalDeclaration, then both mangled code from X and Y. We get two functions call_x and call_y that now share the same input / output type.
    4. Implement call, which is now trivial.
  4. Profit.