mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
gpu/internal/driver: rename gpu/backend
There are no longer any importers of package backend outside of gioui.org/gpu. Move it internally, and rename it to the slightly more specific "driver" while we're at it. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
)
|
||||
|
||||
// GLSLCC is a shader cross-compilation tool.
|
||||
@@ -25,10 +25,10 @@ func NewGLSLCC() *GLSLCC { return &GLSLCC{Bin: "glslcc"} }
|
||||
|
||||
// Metadata contains reflection data about the shader.
|
||||
type Metadata struct {
|
||||
Uniforms backend.UniformsReflection
|
||||
Inputs []backend.InputLocation
|
||||
Textures []backend.TextureBinding
|
||||
StorageBuffers []backend.StorageBufferBinding
|
||||
Uniforms driver.UniformsReflection
|
||||
Inputs []driver.InputLocation
|
||||
Textures []driver.TextureBinding
|
||||
StorageBuffers []driver.StorageBufferBinding
|
||||
}
|
||||
|
||||
// Convert converts input data to the target shader.
|
||||
@@ -163,7 +163,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
|
||||
if err != nil {
|
||||
return info, fmt.Errorf("parseReflection: %v", err)
|
||||
}
|
||||
info.Inputs = append(info.Inputs, backend.InputLocation{
|
||||
info.Inputs = append(info.Inputs, driver.InputLocation{
|
||||
Name: input.Name,
|
||||
Location: input.Location,
|
||||
Semantic: input.Semantic,
|
||||
@@ -183,7 +183,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
|
||||
|
||||
blockOffset := 0
|
||||
for _, block := range shaderBlocks {
|
||||
info.Uniforms.Blocks = append(info.Uniforms.Blocks, backend.UniformBlock{
|
||||
info.Uniforms.Blocks = append(info.Uniforms.Blocks, driver.UniformBlock{
|
||||
Name: block.Name,
|
||||
Binding: block.Binding,
|
||||
})
|
||||
@@ -192,7 +192,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
|
||||
if err != nil {
|
||||
return info, fmt.Errorf("parseReflection: %v", err)
|
||||
}
|
||||
info.Uniforms.Locations = append(info.Uniforms.Locations, backend.UniformLocation{
|
||||
info.Uniforms.Locations = append(info.Uniforms.Locations, driver.UniformLocation{
|
||||
// Synthetic name generated by glslcc.
|
||||
Name: fmt.Sprintf("_%d.%s", block.ID, member.Name),
|
||||
Type: dataType,
|
||||
@@ -209,14 +209,14 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
|
||||
textures = reflect.FS.Textures
|
||||
}
|
||||
for _, texture := range textures {
|
||||
info.Textures = append(info.Textures, backend.TextureBinding{
|
||||
info.Textures = append(info.Textures, driver.TextureBinding{
|
||||
Name: texture.Name,
|
||||
Binding: texture.Binding,
|
||||
})
|
||||
}
|
||||
|
||||
for _, sb := range reflect.CS.StorageBuffers {
|
||||
info.StorageBuffers = append(info.StorageBuffers, backend.StorageBufferBinding{
|
||||
info.StorageBuffers = append(info.StorageBuffers, driver.StorageBufferBinding{
|
||||
Binding: sb.Binding,
|
||||
BlockSize: sb.BlockSize,
|
||||
})
|
||||
@@ -225,24 +225,24 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func parseDataType(t string) (backend.DataType, int, error) {
|
||||
func parseDataType(t string) (driver.DataType, int, error) {
|
||||
switch t {
|
||||
case "float":
|
||||
return backend.DataTypeFloat, 1, nil
|
||||
return driver.DataTypeFloat, 1, nil
|
||||
case "float2":
|
||||
return backend.DataTypeFloat, 2, nil
|
||||
return driver.DataTypeFloat, 2, nil
|
||||
case "float3":
|
||||
return backend.DataTypeFloat, 3, nil
|
||||
return driver.DataTypeFloat, 3, nil
|
||||
case "float4":
|
||||
return backend.DataTypeFloat, 4, nil
|
||||
return driver.DataTypeFloat, 4, nil
|
||||
case "int":
|
||||
return backend.DataTypeInt, 1, nil
|
||||
return driver.DataTypeInt, 1, nil
|
||||
case "int2":
|
||||
return backend.DataTypeInt, 2, nil
|
||||
return driver.DataTypeInt, 2, nil
|
||||
case "int3":
|
||||
return backend.DataTypeInt, 3, nil
|
||||
return driver.DataTypeInt, 3, nil
|
||||
case "int4":
|
||||
return backend.DataTypeInt, 4, nil
|
||||
return driver.DataTypeInt, 4, nil
|
||||
default:
|
||||
return 0, 0, fmt.Errorf("unsupported input data type: %s", t)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"sync"
|
||||
"text/template"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -138,7 +138,7 @@ func (conv *Converter) Run(out io.Writer) error {
|
||||
|
||||
type ShaderResult struct {
|
||||
Path string
|
||||
Shaders []backend.ShaderSources
|
||||
Shaders []driver.ShaderSources
|
||||
Error error
|
||||
}
|
||||
shaderResults := make([]ShaderResult, len(shaders))
|
||||
@@ -187,7 +187,7 @@ func (conv *Converter) Run(out io.Writer) error {
|
||||
|
||||
fmt.Fprintf(out, "// Code generated by build.go. DO NOT EDIT.\n\n")
|
||||
fmt.Fprintf(out, "package %s\n\n", conv.packageName)
|
||||
fmt.Fprintf(out, "import %q\n\n", "gioui.org/gpu/backend")
|
||||
fmt.Fprintf(out, "import %q\n\n", "gioui.org/gpu/internal/driver")
|
||||
|
||||
fmt.Fprintf(out, "var (\n")
|
||||
|
||||
@@ -202,17 +202,17 @@ func (conv *Converter) Run(out io.Writer) error {
|
||||
|
||||
multiVariant := len(r.Shaders) > 1
|
||||
if multiVariant {
|
||||
fmt.Fprintf(out, "[...]backend.ShaderSources{\n")
|
||||
fmt.Fprintf(out, "[...]driver.ShaderSources{\n")
|
||||
}
|
||||
|
||||
for _, src := range r.Shaders {
|
||||
fmt.Fprintf(out, "backend.ShaderSources{\n")
|
||||
fmt.Fprintf(out, "driver.ShaderSources{\n")
|
||||
fmt.Fprintf(out, "Name: %#v,\n", src.Name)
|
||||
if len(src.Inputs) > 0 {
|
||||
fmt.Fprintf(out, "Inputs: %#v,\n", src.Inputs)
|
||||
}
|
||||
if u := src.Uniforms; len(u.Blocks) > 0 {
|
||||
fmt.Fprintf(out, "Uniforms: backend.UniformsReflection{\n")
|
||||
fmt.Fprintf(out, "Uniforms: driver.UniformsReflection{\n")
|
||||
fmt.Fprintf(out, "Blocks: %#v,\n", u.Blocks)
|
||||
fmt.Fprintf(out, "Locations: %#v,\n", u.Locations)
|
||||
fmt.Fprintf(out, "Size: %d,\n", u.Size)
|
||||
@@ -254,7 +254,7 @@ func (conv *Converter) Run(out io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (conv *Converter) Shader(shaderPath string) ([]backend.ShaderSources, error) {
|
||||
func (conv *Converter) Shader(shaderPath string) ([]driver.ShaderSources, error) {
|
||||
type Variant struct {
|
||||
FetchColorExpr string
|
||||
Header string
|
||||
@@ -279,7 +279,7 @@ func (conv *Converter) Shader(shaderPath string) ([]backend.ShaderSources, error
|
||||
return nil, fmt.Errorf("failed to parse template %q: %w", shaderPath, err)
|
||||
}
|
||||
|
||||
var variants []backend.ShaderSources
|
||||
var variants []driver.ShaderSources
|
||||
for i, variantArg := range variantArgs {
|
||||
variantName := strconv.Itoa(i)
|
||||
var buf bytes.Buffer
|
||||
@@ -288,7 +288,7 @@ func (conv *Converter) Shader(shaderPath string) ([]backend.ShaderSources, error
|
||||
return nil, fmt.Errorf("failed to execute template %q with %#v: %w", shaderPath, variantArg, err)
|
||||
}
|
||||
|
||||
var sources backend.ShaderSources
|
||||
var sources driver.ShaderSources
|
||||
sources.Name = filepath.Base(shaderPath)
|
||||
|
||||
// Ignore error; some shaders are not meant to run in GLSL 1.00.
|
||||
@@ -341,7 +341,7 @@ func (conv *Converter) Shader(shaderPath string) ([]backend.ShaderSources, error
|
||||
return variants, nil
|
||||
}
|
||||
|
||||
func (conv *Converter) ComputeShader(shaderPath string) ([]backend.ShaderSources, error) {
|
||||
func (conv *Converter) ComputeShader(shaderPath string) ([]driver.ShaderSources, error) {
|
||||
shader, err := ioutil.ReadFile(shaderPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load shader %q: %w", shaderPath, err)
|
||||
@@ -352,7 +352,7 @@ func (conv *Converter) ComputeShader(shaderPath string) ([]backend.ShaderSources
|
||||
return nil, fmt.Errorf("failed to convert compute shader %q: %w", shaderPath, err)
|
||||
}
|
||||
|
||||
var sources backend.ShaderSources
|
||||
var sources driver.ShaderSources
|
||||
sources.Name = filepath.Base(shaderPath)
|
||||
|
||||
sources.GLSL310ES, err = conv.spirv.Convert(spirv, "es", "310")
|
||||
@@ -373,7 +373,7 @@ func (conv *Converter) ComputeShader(shaderPath string) ([]backend.ShaderSources
|
||||
}
|
||||
}
|
||||
|
||||
return []backend.ShaderSources{sources}, nil
|
||||
return []driver.ShaderSources{sources}, nil
|
||||
}
|
||||
|
||||
// Workers implements wait group with synchronous logging.
|
||||
|
||||
Reference in New Issue
Block a user