mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Revert "shaderprecomp: accept an ID instead of source to register"
This reverts commit ecc3f29af1
.
Reason: we are considering to remove ShaderSourceID
Updates #2861
Updates #2999
This commit is contained in:
parent
ecc3f29af1
commit
3279688dd6
@ -40,7 +40,7 @@ func run() error {
|
|||||||
if errors.Is(err, exec.ErrNotFound) {
|
if errors.Is(err, exec.ErrNotFound) {
|
||||||
fmt.Fprintln(os.Stderr, "fxc.exe not found. Please install Windows SDK.")
|
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, "See https://learn.microsoft.com/en-us/windows/win32/direct3dtools/fxc for more details.")
|
||||||
fmt.Fprintln(os.Stderr, "HINT: On PowerShell, you can add a path to the PATH environment variable temporarily like:")
|
fmt.Fprintln(os.Stderr, "On PowerShell, you can add a path to the PATH environment variable temporarily like:")
|
||||||
fmt.Fprintln(os.Stderr)
|
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, ` & (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)
|
fmt.Fprintln(os.Stderr)
|
||||||
|
@ -16,9 +16,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
||||||
)
|
)
|
||||||
@ -27,40 +28,24 @@ import (
|
|||||||
var metallibs embed.FS
|
var metallibs embed.FS
|
||||||
|
|
||||||
func registerPrecompiledShaders() error {
|
func registerPrecompiledShaders() error {
|
||||||
ents, err := metallibs.ReadDir("metallib")
|
srcs := shaderprecomp.AppendBuildinShaderSources(nil)
|
||||||
|
defaultShaderSource, err := shaderprecomp.NewShaderSource(defaultShaderSourceBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
srcs = append(srcs, defaultShaderSource)
|
||||||
|
|
||||||
var registered bool
|
for _, src := range srcs {
|
||||||
for _, ent := range ents {
|
name := src.ID().String() + ".metallib"
|
||||||
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)
|
lib, err := metallibs.ReadFile("metallib/" + name)
|
||||||
if err != nil {
|
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
|
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
|
return nil
|
||||||
|
@ -16,9 +16,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
"github.com/hajimehoshi/ebiten/v2/shaderprecomp"
|
||||||
)
|
)
|
||||||
@ -29,44 +30,35 @@ import (
|
|||||||
var fxcs embed.FS
|
var fxcs embed.FS
|
||||||
|
|
||||||
func registerPrecompiledShaders() error {
|
func registerPrecompiledShaders() error {
|
||||||
ents, err := fxcs.ReadDir("fxc")
|
srcs := shaderprecomp.AppendBuildinShaderSources(nil)
|
||||||
|
defaultShaderSource, err := shaderprecomp.NewShaderSource(defaultShaderSourceBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
srcs = append(srcs, defaultShaderSource)
|
||||||
|
|
||||||
var registered bool
|
for _, src := range srcs {
|
||||||
for _, ent := range ents {
|
vsname := src.ID().String() + "_vs.fxc"
|
||||||
if ent.IsDir() {
|
vs, err := fxcs.ReadFile("fxc/" + vsname)
|
||||||
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 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderprecomp.RegisterFXCs(srcID, vs, ps)
|
psname := src.ID().String() + "_ps.fxc"
|
||||||
registered = true
|
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
|
||||||
|
}
|
||||||
|
|
||||||
if !registered {
|
shaderprecomp.RegisterFXCs(src, vs, ps)
|
||||||
fmt.Fprintln(os.Stderr, "precompiled HLSL libraries were not found. Run 'go generate' for 'fxc' directory to generate them.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -17,7 +17,6 @@ package shaderir
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
"go/constant"
|
"go/constant"
|
||||||
"go/token"
|
"go/token"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
@ -43,19 +42,6 @@ func CalcSourceHash(source []byte) SourceHash {
|
|||||||
return hash
|
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 {
|
func (s SourceHash) String() string {
|
||||||
return hex.EncodeToString(s[:])
|
return hex.EncodeToString(s[:])
|
||||||
}
|
}
|
||||||
|
@ -64,15 +64,6 @@ func (s *ShaderSource) ID() ShaderSourceID {
|
|||||||
// ShaderSourceID is a uniuqe identifier for a shader source.
|
// ShaderSourceID is a uniuqe identifier for a shader source.
|
||||||
type ShaderSourceID [16]byte
|
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.
|
// String returns a string representation of the shader source ID.
|
||||||
func (s ShaderSourceID) String() string {
|
func (s ShaderSourceID) String() string {
|
||||||
return shaderir.SourceHash(s).String()
|
return shaderir.SourceHash(s).String()
|
||||||
|
@ -39,11 +39,11 @@ func CompileToMSL(w io.Writer, source *ShaderSource) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterMetalLibrary registers a precompiled Metal library for a shader source ID.
|
// RegisterMetalLibrary registers a precompiled Metal library for a shader source.
|
||||||
// library must be the content of a .metallib file.
|
// 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.
|
// For more details, see https://developer.apple.com/documentation/metal/shader_libraries/building_a_shader_library_by_precompiling_source_files.
|
||||||
//
|
//
|
||||||
// RegisterMetalLibrary is concurrent-safe.
|
// RegisterMetalLibrary is concurrent-safe.
|
||||||
func RegisterMetalLibrary(id ShaderSourceID, library []byte) {
|
func RegisterMetalLibrary(source *ShaderSource, library []byte) {
|
||||||
metal.RegisterPrecompiledLibrary(shaderir.SourceHash(id), library)
|
metal.RegisterPrecompiledLibrary(shaderir.SourceHash(source.ID()), library)
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,11 @@ func CompileToHLSL(vertexWriter, pixelWriter io.Writer, source *ShaderSource) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterFXCs registers a precompiled HLSL (FXC) for a shader source ID.
|
// RegisterFXCs registers a precompiled HLSL (FXC) for a shader source.
|
||||||
// vertexFXC and pixelFXC must be the content of .fxc files generated by `fxc` command.
|
// 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.
|
// For more details, see https://learn.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-using.
|
||||||
//
|
//
|
||||||
// RegisterFXCs is concurrent-safe.
|
// RegisterFXCs is concurrent-safe.
|
||||||
func RegisterFXCs(id ShaderSourceID, vertexFXC, pixelFXC []byte) {
|
func RegisterFXCs(source *ShaderSource, vertexFXC, pixelFXC []byte) {
|
||||||
directx.RegisterPrecompiledFXCs(shaderir.SourceHash(id), vertexFXC, pixelFXC)
|
directx.RegisterPrecompiledFXCs(shaderir.SourceHash(source.ID()), vertexFXC, pixelFXC)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user