-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
API to accept and use precompiled shader #2861
Comments
Hello. Consider adding an API to use your shaders. |
I'm afraid this suggestion is not for enabling other languages than Kage |
To minimize an impact of the existing APIs, I suggest this API: // AddPrecompiledShader adds a pair of a shader source and a shader binary.
// When a new shader is created by NewShader,
// Ebitengine tries to seek the pair that has the same shader source.
// If there is such a pair, Ebitengine uses a registered shader binary for the same shader source instead of compiling it.
//
// AddPrecompiledShader is useful to shoten the shader compile time, or even necessary in an environment
// where you cannot compile a shader on the fly.
func AddPrecompiledShader(kageShaderSource []byte, nativeShaderBinary []byte, graphicsLibrary GraphicsLibrary) error EDIT: |
OpenGL: It is impossible to precompile shaders. DirectX: A native shader binary is the result of Metal: A native shader binary is a .metallib format. This can be used at |
Instead of exposing the the vertex shader, would this work? func CompileShaderToNativeSource(kageShaderSource []byte, graphicsLibrary GraphicsLibrary) ([]byte, error)
// Compiling a native source to a native binary is a developer's responsibility.
func AddPrecompiledShader(kageShaderSource []byte, nativeShaderBinary []byte, graphicsLibrary GraphicsLibrary) error |
Compiling and using a shaderin a pseudo Go-like code. OpenGLvertex_shader_source, fragment_shader_source = glsl.Compile(ir)
vertex_shader = glNewShader(vertex_shader_source)
fragment_shader = glNewShader(fragment_shader_source)
program = glNewProgram(vertex_shader, fragmen_shader, array_buffer_layout_names) Metalsrc = metal.Compile(ir)
lib = MakeLibrary(src)
vertex_function = MakeFunction(lib, vertex_name)
fragment_function = MakeFunction(lib, fragment_name) See also: DirectXvertex_shader_source, pixel_shader_source, offsets = hlsl.Compile(ir)
vertex_blob = D3DCompile(vertex_shader, name, ...)
pixel_blob = D3DCompile(pixel_shader, name, ...) See also:
Proposal (TBD)As there are various ways to compile and use shaders in different environments, the precompilation APIs should be separate for each environment unfortunately. package shaderprecomp
func BuiltinShaderSources() [][]byte
func CompileToHLSL(kageSource []byte) (vertex []byte, pixel []byte, err error)
func RegisterDirectXShaderBlobs(kageSource []byte, vertexBlob []byte, pixelBlob []byte)
func CompileToMSL(kageSource []byte) ([]byte, error)
func RegisterMetalShaderLibrary(kageSource []byte, library []byte) |
The current implementation is only for macOS so far. Updates #2861
The current implementation is only for macOS so far. Updates #2861
The final API is like this package shaderprecomp
type ShaderSource struct {
// ...
}
func NewShaderSource([]byte) (*ShaderSource, error)
func (s *ShaderSource) ID() ShaderSourceID
type ShaderSourceID [16]byte
func (s *ShaderSourceID) String() string
func AppendBuiltinShaderSources(sources []*ShaderSource) []*ShaderSource
func CompileToHLSL(vertexWriter, pixelWriter io.Writer, kageSource *ShaderSource) error
func RegisterFXCs(id ShaderSourceID, vertexFXC []byte, pixelFXC []byte)
func CompileToMSL(w io.Writer, kageSource *ShaderSource) error
func RegisterMetalLibrary(id ShaderSourceID, library []byte) |
With #2984, I realized some considerations:
Thus, until I decide a better API design, I'd like to retract the package once. I might postpone the milestone for release. |
With #2984, we realized some considerations: * Builtin shaders don't have to or should not be exposed. * The shader complation processes like what the examples/shaderprecomp does can be provided by this package Thus, until we decide a better API design, we'd like to retract the package once. Updates #2861
Operating System
What feature would you like to be added?
On consoles, compiling shaders is possible but takes long (Xbox), or, is probably impossible (PS5) 😢. We might need a tool to precompile shader and APIs to use them...
Why is this needed?
For some special environments where dynamic compiling shaders is difficult.
The text was updated successfully, but these errors were encountered: