mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
4 Commits
5942192b66
...
ecc3f29af1
Author | SHA1 | Date | |
---|---|---|---|
|
ecc3f29af1 | ||
|
1c438cb5c8 | ||
|
13c7518400 | ||
|
38d2892906 |
@ -40,7 +40,7 @@ func run() error {
|
||||
if errors.Is(err, exec.ErrNotFound) {
|
||||
fmt.Fprintln(os.Stderr, "fxc.exe not found. Please install Windows SDK.")
|
||||
fmt.Fprintln(os.Stderr, "See https://learn.microsoft.com/en-us/windows/win32/direct3dtools/fxc for more details.")
|
||||
fmt.Fprintln(os.Stderr, "On PowerShell, you can add a path to the PATH environment variable temporarily like:")
|
||||
fmt.Fprintln(os.Stderr, "HINT: On PowerShell, you can add a path to the PATH environment variable temporarily like:")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, ` & (Get-Process -Id $PID).Path { $env:PATH="C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64;"+$env:PATH; go generate .\examples\shaderprecomp\fxc\ }`)
|
||||
fmt.Fprintln(os.Stderr)
|
||||
|
@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
package fxc
|
||||
|
@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build darwin
|
||||
|
||||
//go:generate go run gen.go
|
||||
|
||||
package metallib
|
||||
|
@ -16,10 +16,9 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
||||
)
|
||||
@ -28,24 +27,40 @@ import (
|
||||
var metallibs embed.FS
|
||||
|
||||
func registerPrecompiledShaders() error {
|
||||
srcs := shaderprecomp.AppendBuildinShaderSources(nil)
|
||||
defaultShaderSource, err := shaderprecomp.NewShaderSource(defaultShaderSourceBytes)
|
||||
ents, err := metallibs.ReadDir("metallib")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
srcs = append(srcs, defaultShaderSource)
|
||||
|
||||
for _, src := range srcs {
|
||||
name := src.ID().String() + ".metallib"
|
||||
var registered bool
|
||||
for _, ent := range ents {
|
||||
if ent.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
const suffix = ".metallib"
|
||||
name := ent.Name()
|
||||
if !strings.HasSuffix(name, suffix) {
|
||||
continue
|
||||
}
|
||||
|
||||
id := name[:len(name)-len(suffix)]
|
||||
srcID, err := shaderprecomp.ParseSourceID(id)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
lib, err := metallibs.ReadFile("metallib/" + name)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Fprintf(os.Stderr, "precompiled Metal library %s was not found. Run 'go generate' for 'metallib' directory to generate them.\n", name)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
shaderprecomp.RegisterMetalLibrary(src, lib)
|
||||
|
||||
shaderprecomp.RegisterMetalLibrary(srcID, lib)
|
||||
registered = true
|
||||
}
|
||||
|
||||
if !registered {
|
||||
fmt.Fprintln(os.Stderr, "precompiled Metal libraries were not found. Run 'go generate' for 'metallib' directory to generate them.")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -16,10 +16,9 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
||||
)
|
||||
@ -30,35 +29,44 @@ import (
|
||||
var fxcs embed.FS
|
||||
|
||||
func registerPrecompiledShaders() error {
|
||||
srcs := shaderprecomp.AppendBuildinShaderSources(nil)
|
||||
defaultShaderSource, err := shaderprecomp.NewShaderSource(defaultShaderSourceBytes)
|
||||
ents, err := fxcs.ReadDir("fxc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
srcs = append(srcs, defaultShaderSource)
|
||||
|
||||
for _, src := range srcs {
|
||||
vsname := src.ID().String() + "_vs.fxc"
|
||||
vs, err := fxcs.ReadFile("fxc/" + vsname)
|
||||
var registered bool
|
||||
for _, ent := range ents {
|
||||
if ent.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
const suffix = "_vs.fxc"
|
||||
name := ent.Name()
|
||||
if !strings.HasSuffix(name, suffix) {
|
||||
continue
|
||||
}
|
||||
|
||||
id := name[:len(name)-len(suffix)]
|
||||
srcID, err := shaderprecomp.ParseSourceID(id)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
vs, err := fxcs.ReadFile("fxc/" + id + "_vs.fxc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ps, err := fxcs.ReadFile("fxc/" + id + "_ps.fxc")
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Fprintf(os.Stderr, "precompiled HLSL library %s was not found. Run 'go generate' for 'fxc' directory to generate them.\n", vsname)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
psname := src.ID().String() + "_ps.fxc"
|
||||
ps, err := fxcs.ReadFile("fxc/" + psname)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
fmt.Fprintf(os.Stderr, "precompiled HLSL library %s was not found. Run 'go generate' for 'fxc' directory to generate them.\n", psname)
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
shaderprecomp.RegisterFXCs(srcID, vs, ps)
|
||||
registered = true
|
||||
}
|
||||
|
||||
shaderprecomp.RegisterFXCs(src, vs, ps)
|
||||
if !registered {
|
||||
fmt.Fprintln(os.Stderr, "precompiled HLSL libraries were not found. Run 'go generate' for 'fxc' directory to generate them.")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
||||
github.com/ebitengine/purego v0.8.0-alpha.2
|
||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
|
||||
github.com/go-text/typesetting v0.1.1
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.1.0
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4
|
||||
github.com/jakecoffman/cp v1.2.1
|
||||
github.com/jezek/xgb v1.1.1
|
||||
|
4
go.sum
4
go.sum
@ -11,8 +11,8 @@ github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRR
|
||||
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
|
||||
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.1.0 h1:JLy/na2e83GewqebpFbS2LHpDVnGdzmyJOpqXtBgLm0=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.1.0/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1 h1:GLoMNCbvXOd39tFkqk9w/MI0xSLJaDzEOOl8mT1ILtI=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
|
||||
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
|
||||
|
@ -2309,7 +2309,7 @@ func (w *Window) platformSetCursorMode(mode int) error {
|
||||
|
||||
if mode == CursorDisabled {
|
||||
_glfw.platformWindow.disabledCursorWindow = w
|
||||
} else {
|
||||
} else if _glfw.platformWindow.disabledCursorWindow == w {
|
||||
_glfw.platformWindow.disabledCursorWindow = nil
|
||||
if err := w.platformSetCursorPos(_glfw.platformWindow.restoreCursorPosX, _glfw.platformWindow.restoreCursorPosY); err != nil {
|
||||
return err
|
||||
|
@ -17,6 +17,7 @@ package shaderir
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"hash/fnv"
|
||||
@ -42,6 +43,19 @@ func CalcSourceHash(source []byte) SourceHash {
|
||||
return hash
|
||||
}
|
||||
|
||||
func ParseSourceHash(s string) (SourceHash, error) {
|
||||
bs, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return SourceHash{}, err
|
||||
}
|
||||
var hash SourceHash
|
||||
if len(bs) != len(hash) {
|
||||
return SourceHash{}, fmt.Errorf("shaderir: invalid size hash: %s", s)
|
||||
}
|
||||
copy(hash[:], bs)
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
func (s SourceHash) String() string {
|
||||
return hex.EncodeToString(s[:])
|
||||
}
|
||||
|
@ -64,6 +64,15 @@ func (s *ShaderSource) ID() ShaderSourceID {
|
||||
// ShaderSourceID is a uniuqe identifier for a shader source.
|
||||
type ShaderSourceID [16]byte
|
||||
|
||||
// ParseSourceID parses a string representation of the shader source ID.
|
||||
func ParseSourceID(s string) (ShaderSourceID, error) {
|
||||
h, err := shaderir.ParseSourceHash(s)
|
||||
if err != nil {
|
||||
return ShaderSourceID{}, err
|
||||
}
|
||||
return ShaderSourceID(h), nil
|
||||
}
|
||||
|
||||
// String returns a string representation of the shader source ID.
|
||||
func (s ShaderSourceID) String() string {
|
||||
return shaderir.SourceHash(s).String()
|
||||
|
@ -39,11 +39,11 @@ func CompileToMSL(w io.Writer, source *ShaderSource) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterMetalLibrary registers a precompiled Metal library for a shader source.
|
||||
// RegisterMetalLibrary registers a precompiled Metal library for a shader source ID.
|
||||
// library must be the content of a .metallib file.
|
||||
// For more details, see https://developer.apple.com/documentation/metal/shader_libraries/building_a_shader_library_by_precompiling_source_files.
|
||||
//
|
||||
// RegisterMetalLibrary is concurrent-safe.
|
||||
func RegisterMetalLibrary(source *ShaderSource, library []byte) {
|
||||
metal.RegisterPrecompiledLibrary(shaderir.SourceHash(source.ID()), library)
|
||||
func RegisterMetalLibrary(id ShaderSourceID, library []byte) {
|
||||
metal.RegisterPrecompiledLibrary(shaderir.SourceHash(id), library)
|
||||
}
|
||||
|
@ -57,11 +57,11 @@ func CompileToHLSL(vertexWriter, pixelWriter io.Writer, source *ShaderSource) er
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterFXCs registers a precompiled HLSL (FXC) for a shader source.
|
||||
// RegisterFXCs registers a precompiled HLSL (FXC) for a shader source ID.
|
||||
// vertexFXC and pixelFXC must be the content of .fxc files generated by `fxc` command.
|
||||
// For more details, see https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-using.
|
||||
//
|
||||
// RegisterFXCs is concurrent-safe.
|
||||
func RegisterFXCs(source *ShaderSource, vertexFXC, pixelFXC []byte) {
|
||||
directx.RegisterPrecompiledFXCs(shaderir.SourceHash(source.ID()), vertexFXC, pixelFXC)
|
||||
func RegisterFXCs(id ShaderSourceID, vertexFXC, pixelFXC []byte) {
|
||||
directx.RegisterPrecompiledFXCs(shaderir.SourceHash(id), vertexFXC, pixelFXC)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user