hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.08k stars 664 forks source link

a tool and a helper to statically analyze shader sources #3157

Open hajimehoshi opened 1 week ago

hajimehoshi commented 1 week ago

Operating System

What feature would you like to be added?

In order to introduce shader precompilation, we need to know what shader sources are used. We have to list them before the compilation. Listing them by users would not be a good solution since unknown dependencies might use shaders internally, and users couldn't know them.

In order to resolve this issue, what about this?

  1. Introduce a new function ebiten.RegisterShader(src []byte) (or string?). This function is just a marker and does nothing.
  2. Introduce a new tool to analyaze all the source of a specified package and its dependencies, list all the invocations of RegisterShader, and output them as JSON or something.

Libralies using shaders would have to call RegisterShader to precompile the shader source, but it should be much better than having to export shader sources as a public API.

Why is this needed?

No response

hajimehoshi commented 1 week ago

Probably commenting is better since any library can prepare this without waiting for Ebitengine 2.9.

//ebitengine:shader
const superUltraShader = "package main

func Fragment(..."
hajimehoshi commented 1 week ago

Add a new field to provide compilation results like GLSL, HLSL, and MSL.

See also: https://github.com/hajimehoshi/ebiten/commit/48f79af884f947c83ccfa5baceafeb53e27dcdb7