Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
11 tasks
hajimehoshi opened this issue Nov 7, 2024 · 6 comments
Open
11 tasks

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

hajimehoshi opened this issue Nov 7, 2024 · 6 comments
Labels
Milestone

Comments

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 7, 2024

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

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 hajimehoshi added this to the v2.9.0 milestone Nov 7, 2024
@hajimehoshi
Copy link
Owner Author

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 added a commit that referenced this issue Nov 10, 2024
This adds a new compiler directive `//ebitengine:shader` indicating
a shader source. A new tool internal/shaderlister can iterates all
the shader strings with the directive. The tool might be exposed
in the future.

Updates #3157
@hajimehoshi
Copy link
Owner Author

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

See also: 48f79af

@hajimehoshi
Copy link
Owner Author

Hmm, this tool doesn't work well with embedded Kage files. What should we do?

var (
	//go:embed default.go
	default_go []byte

	//go:embed texel.go
	texel_go []byte

	//go:embed lighting.go
	lighting_go []byte

	//go:embed radialblur.go
	radialblur_go []byte

	//go:embed chromaticaberration.go
	chromaticaberration_go []byte

	//go:embed dissolve.go
	dissolve_go []byte

	//go:embed water.go
	water_go []byte
)

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Feb 8, 2025

Let's add another directive like ebitengine:embeddedshader for embedded files and iterate all the embedded files.

@hajimehoshi
Copy link
Owner Author

I changed the directives like these:

  • //ebitengine:shadersource for consntant values
  • //ebitengine:shaderfile [pattern] for files

hajimehoshi added a commit that referenced this issue Feb 8, 2025
The directory check must be skipped when the pattern includes a meta
character.

Updates #3157
@hajimehoshi
Copy link
Owner Author

Hmm, a directive inside a function should be ignored, but it is pretty tricky to get only top-level comments from *ast.File.

func foo() {
	// Non top-level files are ignored.

	//ebitengine:shaderfile *_notkage.go
}

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant