forked from joejulian/gio
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:
+4
-4
@@ -2,14 +2,14 @@
|
||||
|
||||
package gpu
|
||||
|
||||
import "gioui.org/gpu/backend"
|
||||
import "gioui.org/gpu/internal/driver"
|
||||
|
||||
// An API carries the necessary GPU API specific resources to create a Device.
|
||||
// There is an API type for each supported GPU API such as OpenGL and Direct3D.
|
||||
type API = backend.API
|
||||
type API = driver.API
|
||||
|
||||
// OpenGL denotes the OpenGL or OpenGL ES API.
|
||||
type OpenGL = backend.OpenGL
|
||||
type OpenGL = driver.OpenGL
|
||||
|
||||
// Direct3D11 denotes the Direct3D API.
|
||||
type Direct3D11 = backend.Direct3D11
|
||||
type Direct3D11 = driver.Direct3D11
|
||||
|
||||
+44
-44
@@ -14,7 +14,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/f32color"
|
||||
gunsafe "gioui.org/internal/unsafe"
|
||||
"gioui.org/layout"
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
type compute struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
enc encoder
|
||||
|
||||
drawOps drawOps
|
||||
@@ -30,16 +30,16 @@ type compute struct {
|
||||
maxTextureDim int
|
||||
|
||||
programs struct {
|
||||
elements backend.Program
|
||||
tileAlloc backend.Program
|
||||
pathCoarse backend.Program
|
||||
backdrop backend.Program
|
||||
binning backend.Program
|
||||
coarse backend.Program
|
||||
kernel4 backend.Program
|
||||
elements driver.Program
|
||||
tileAlloc driver.Program
|
||||
pathCoarse driver.Program
|
||||
backdrop driver.Program
|
||||
binning driver.Program
|
||||
coarse driver.Program
|
||||
kernel4 driver.Program
|
||||
}
|
||||
buffers struct {
|
||||
config backend.Buffer
|
||||
config driver.Buffer
|
||||
scene sizedBuffer
|
||||
state sizedBuffer
|
||||
memory sizedBuffer
|
||||
@@ -48,32 +48,32 @@ type compute struct {
|
||||
size image.Point
|
||||
// image is the output texture. Note that it is in RGBA format,
|
||||
// but contains data in sRGB. See blitOutput for more detail.
|
||||
image backend.Texture
|
||||
blitProg backend.Program
|
||||
image driver.Texture
|
||||
blitProg driver.Program
|
||||
}
|
||||
// images contains ImageOp images packed into a texture atlas.
|
||||
images struct {
|
||||
packer packer
|
||||
// positions maps imageOpData.handles to positions inside tex.
|
||||
positions map[interface{}]image.Point
|
||||
tex backend.Texture
|
||||
tex driver.Texture
|
||||
}
|
||||
// materials contains the pre-processed materials (transformed images for
|
||||
// now, gradients etc. later) packed in a texture atlas. The atlas is used
|
||||
// as source in kernel4.
|
||||
materials struct {
|
||||
prog backend.Program
|
||||
layout backend.InputLayout
|
||||
prog driver.Program
|
||||
layout driver.InputLayout
|
||||
|
||||
packer packer
|
||||
|
||||
texSize image.Point
|
||||
tex backend.Texture
|
||||
fbo backend.Framebuffer
|
||||
tex driver.Texture
|
||||
fbo driver.Framebuffer
|
||||
quads []materialVertex
|
||||
|
||||
bufSize int
|
||||
buffer backend.Buffer
|
||||
buffer driver.Buffer
|
||||
}
|
||||
timers struct {
|
||||
profile string
|
||||
@@ -112,7 +112,7 @@ type encodeState struct {
|
||||
|
||||
type sizedBuffer struct {
|
||||
size int
|
||||
buffer backend.Buffer
|
||||
buffer driver.Buffer
|
||||
}
|
||||
|
||||
// config matches Config in setup.h
|
||||
@@ -187,7 +187,7 @@ const (
|
||||
memMallocFailed = 1 // ERR_MALLOC_FAILED
|
||||
)
|
||||
|
||||
func newCompute(ctx backend.Device) (*compute, error) {
|
||||
func newCompute(ctx driver.Device) (*compute, error) {
|
||||
maxDim := ctx.Caps().MaxTextureSize
|
||||
// Large atlas textures cause artifacts due to precision loss in
|
||||
// shaders.
|
||||
@@ -215,9 +215,9 @@ func newCompute(ctx backend.Device) (*compute, error) {
|
||||
return nil, err
|
||||
}
|
||||
g.materials.prog = materialProg
|
||||
progLayout, err := ctx.NewInputLayout(shader_material_vert, []backend.InputDesc{
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
progLayout, err := ctx.NewInputLayout(shader_material_vert, []driver.InputDesc{
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
})
|
||||
if err != nil {
|
||||
g.Release()
|
||||
@@ -228,7 +228,7 @@ func newCompute(ctx backend.Device) (*compute, error) {
|
||||
g.drawOps.pathCache = newOpCache()
|
||||
g.drawOps.retainPathData = true
|
||||
|
||||
buf, err := ctx.NewBuffer(backend.BufferBindingShaderStorage, int(unsafe.Sizeof(config{})))
|
||||
buf, err := ctx.NewBuffer(driver.BufferBindingShaderStorage, int(unsafe.Sizeof(config{})))
|
||||
if err != nil {
|
||||
g.Release()
|
||||
return nil, err
|
||||
@@ -236,8 +236,8 @@ func newCompute(ctx backend.Device) (*compute, error) {
|
||||
g.buffers.config = buf
|
||||
|
||||
shaders := []struct {
|
||||
prog *backend.Program
|
||||
src backend.ShaderSources
|
||||
prog *driver.Program
|
||||
src driver.ShaderSources
|
||||
}{
|
||||
{&g.programs.elements, shader_elements_comp},
|
||||
{&g.programs.tileAlloc, shader_tile_alloc_comp},
|
||||
@@ -264,7 +264,7 @@ func (g *compute) Collect(viewport image.Point, ops *op.Ops) {
|
||||
for _, img := range g.drawOps.allImageOps {
|
||||
expandPathOp(img.path, img.clip)
|
||||
}
|
||||
if g.drawOps.profile && g.timers.t == nil && g.ctx.Caps().Features.Has(backend.FeatureTimers) {
|
||||
if g.drawOps.profile && g.timers.t == nil && g.ctx.Caps().Features.Has(driver.FeatureTimers) {
|
||||
t := &g.timers
|
||||
t.t = newTimers(g.ctx)
|
||||
t.elements = g.timers.t.newTimer()
|
||||
@@ -333,7 +333,7 @@ func (g *compute) blitOutput(viewport image.Point) {
|
||||
g.ctx.Viewport(0, 0, viewport.X, viewport.Y)
|
||||
g.ctx.BindTexture(0, g.output.image)
|
||||
g.ctx.BindProgram(g.output.blitProg)
|
||||
g.ctx.DrawArrays(backend.DrawModeTriangleStrip, 0, 4)
|
||||
g.ctx.DrawArrays(driver.DrawModeTriangleStrip, 0, 4)
|
||||
}
|
||||
|
||||
func (g *compute) encode(viewport image.Point) error {
|
||||
@@ -414,7 +414,7 @@ restart:
|
||||
a.tex = nil
|
||||
}
|
||||
sz := a.packer.maxDim
|
||||
handle, err := g.ctx.NewTexture(backend.TextureFormatSRGB, sz, sz, backend.FilterLinear, backend.FilterLinear, backend.BufferBindingTexture)
|
||||
handle, err := g.ctx.NewTexture(driver.TextureFormatSRGB, sz, sz, driver.FilterLinear, driver.FilterLinear, driver.BufferBindingTexture)
|
||||
if err != nil {
|
||||
return fmt.Errorf("compute: failed to create image atlas: %v", err)
|
||||
}
|
||||
@@ -426,7 +426,7 @@ restart:
|
||||
panic("compute: internal error: image not placed")
|
||||
}
|
||||
size := img.Bounds().Size()
|
||||
backend.UploadImage(a.tex, pos, img)
|
||||
driver.UploadImage(a.tex, pos, img)
|
||||
rightPadding := image.Pt(padding, size.Y)
|
||||
a.tex.Upload(image.Pt(pos.X+size.X, pos.Y), rightPadding, g.zeros(rightPadding.X*rightPadding.Y*4))
|
||||
bottomPadding := image.Pt(size.X, padding)
|
||||
@@ -453,7 +453,7 @@ func (g *compute) renderMaterials() error {
|
||||
// Round to nearest power of 2 while we're doing an expensive recreation anyway.
|
||||
sz := image.Pt(pow2Ceil(outSize.X), pow2Ceil(outSize.Y))
|
||||
m.texSize = sz
|
||||
handle, err := g.ctx.NewTexture(backend.TextureFormatRGBA8, sz.X, sz.Y, backend.FilterNearest, backend.FilterNearest, backend.BufferBindingShaderStorage|backend.BufferBindingFramebuffer)
|
||||
handle, err := g.ctx.NewTexture(driver.TextureFormatRGBA8, sz.X, sz.Y, driver.FilterNearest, driver.FilterNearest, driver.BufferBindingShaderStorage|driver.BufferBindingFramebuffer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("compute: failed to create material atlas: %v", err)
|
||||
}
|
||||
@@ -480,7 +480,7 @@ func (g *compute) renderMaterials() error {
|
||||
}
|
||||
// Ditto.
|
||||
n := pow2Ceil(len(vertexData))
|
||||
buf, err := g.ctx.NewBuffer(backend.BufferBindingVertices, n)
|
||||
buf, err := g.ctx.NewBuffer(driver.BufferBindingVertices, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -495,7 +495,7 @@ func (g *compute) renderMaterials() error {
|
||||
g.ctx.BindProgram(m.prog)
|
||||
g.ctx.BindVertexBuffer(m.buffer, int(unsafe.Sizeof(m.quads[0])), 0)
|
||||
g.ctx.BindInputLayout(m.layout)
|
||||
g.ctx.DrawArrays(backend.DrawModeTriangles, 0, len(m.quads))
|
||||
g.ctx.DrawArrays(driver.DrawModeTriangles, 0, len(m.quads))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -719,9 +719,9 @@ func (g *compute) render(tileDims image.Point) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
g.ctx.BindImageTexture(kernel4OutputUnit, g.output.image, backend.AccessWrite, backend.TextureFormatRGBA8)
|
||||
g.ctx.BindImageTexture(kernel4OutputUnit, g.output.image, driver.AccessWrite, driver.TextureFormatRGBA8)
|
||||
if t := g.materials.tex; t != nil {
|
||||
g.ctx.BindImageTexture(kernel4AtlasUnit, t, backend.AccessRead, backend.TextureFormatRGBA8)
|
||||
g.ctx.BindImageTexture(kernel4AtlasUnit, t, driver.AccessRead, driver.TextureFormatRGBA8)
|
||||
}
|
||||
|
||||
// alloc is the number of allocated bytes for static buffers.
|
||||
@@ -819,7 +819,7 @@ func (g *compute) render(tileDims image.Point) error {
|
||||
t.kernel4.end()
|
||||
|
||||
if err := g.buffers.memory.buffer.Download(gunsafe.StructView(g.memHeader)); err != nil {
|
||||
if err == backend.ErrContentLost {
|
||||
if err == driver.ErrContentLost {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
@@ -854,10 +854,10 @@ func (g *compute) resizeOutput(size image.Point) error {
|
||||
g.output.image.Release()
|
||||
g.output.image = nil
|
||||
}
|
||||
img, err := g.ctx.NewTexture(backend.TextureFormatRGBA8, size.X, size.Y,
|
||||
backend.FilterNearest,
|
||||
backend.FilterNearest,
|
||||
backend.BufferBindingShaderStorage|backend.BufferBindingTexture)
|
||||
img, err := g.ctx.NewTexture(driver.TextureFormatRGBA8, size.X, size.Y,
|
||||
driver.FilterNearest,
|
||||
driver.FilterNearest,
|
||||
driver.BufferBindingShaderStorage|driver.BufferBindingTexture)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -873,7 +873,7 @@ func (g *compute) Release() {
|
||||
if g.cache != nil {
|
||||
g.cache.release()
|
||||
}
|
||||
progs := []backend.Program{
|
||||
progs := []driver.Program{
|
||||
g.programs.elements,
|
||||
g.programs.tileAlloc,
|
||||
g.programs.pathCoarse,
|
||||
@@ -942,14 +942,14 @@ func (b *sizedBuffer) release() {
|
||||
*b = sizedBuffer{}
|
||||
}
|
||||
|
||||
func (b *sizedBuffer) ensureCapacity(ctx backend.Device, size int) error {
|
||||
func (b *sizedBuffer) ensureCapacity(ctx driver.Device, size int) error {
|
||||
if b.size >= size {
|
||||
return nil
|
||||
}
|
||||
if b.buffer != nil {
|
||||
b.release()
|
||||
}
|
||||
buf, err := ctx.NewBuffer(backend.BufferBindingShaderStorage, size)
|
||||
buf, err := ctx.NewBuffer(driver.BufferBindingShaderStorage, size)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -958,7 +958,7 @@ func (b *sizedBuffer) ensureCapacity(ctx backend.Device, size int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func bindStorageBuffers(prog backend.Program, buffers ...backend.Buffer) {
|
||||
func bindStorageBuffers(prog driver.Program, buffers ...driver.Buffer) {
|
||||
for i, buf := range buffers {
|
||||
prog.SetStorageBuffer(i, buf)
|
||||
}
|
||||
|
||||
+78
-78
@@ -10,11 +10,11 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/glimpl"
|
||||
)
|
||||
|
||||
// Backend implements backend.Device.
|
||||
// Backend implements driver.Device.
|
||||
type Backend struct {
|
||||
funcs *glimpl.Functions
|
||||
|
||||
@@ -23,7 +23,7 @@ type Backend struct {
|
||||
glver [2]int
|
||||
gles bool
|
||||
ubo bool
|
||||
feats backend.Caps
|
||||
feats driver.Caps
|
||||
// floatTriple holds the settings for floating point
|
||||
// textures.
|
||||
floatTriple textureTriple
|
||||
@@ -73,7 +73,7 @@ type gpuBuffer struct {
|
||||
backend *Backend
|
||||
hasBuffer bool
|
||||
obj glimpl.Buffer
|
||||
typ backend.BufferBinding
|
||||
typ driver.BufferBinding
|
||||
size int
|
||||
immutable bool
|
||||
version int
|
||||
@@ -100,13 +100,13 @@ type uniformsTracker struct {
|
||||
type uniformLocation struct {
|
||||
uniform glimpl.Uniform
|
||||
offset int
|
||||
typ backend.DataType
|
||||
typ driver.DataType
|
||||
size int
|
||||
}
|
||||
|
||||
type gpuInputLayout struct {
|
||||
inputs []backend.InputLocation
|
||||
layout []backend.InputDesc
|
||||
inputs []driver.InputLocation
|
||||
layout []driver.InputDesc
|
||||
}
|
||||
|
||||
// textureTriple holds the type settings for
|
||||
@@ -124,10 +124,10 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
backend.NewOpenGLDevice = newOpenGLDevice
|
||||
driver.NewOpenGLDevice = newOpenGLDevice
|
||||
}
|
||||
|
||||
func newOpenGLDevice(api backend.OpenGL) (backend.Device, error) {
|
||||
func newOpenGLDevice(api driver.OpenGL) (driver.Device, error) {
|
||||
f, err := glimpl.NewFunctions(api.Context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -155,19 +155,19 @@ func newOpenGLDevice(api backend.OpenGL) (backend.Device, error) {
|
||||
srgbaTriple: srgbaTriple,
|
||||
}
|
||||
if ffboErr == nil {
|
||||
b.feats.Features |= backend.FeatureFloatRenderTargets
|
||||
b.feats.Features |= driver.FeatureFloatRenderTargets
|
||||
}
|
||||
if gles31 {
|
||||
b.feats.Features |= backend.FeatureCompute
|
||||
b.feats.Features |= driver.FeatureCompute
|
||||
}
|
||||
if hasExtension(exts, "GL_EXT_disjoint_timer_query_webgl2") || hasExtension(exts, "GL_EXT_disjoint_timer_query") {
|
||||
b.feats.Features |= backend.FeatureTimers
|
||||
b.feats.Features |= driver.FeatureTimers
|
||||
}
|
||||
b.feats.MaxTextureSize = f.GetInteger(glimpl.MAX_TEXTURE_SIZE)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (b *Backend) BeginFrame() backend.Framebuffer {
|
||||
func (b *Backend) BeginFrame() driver.Framebuffer {
|
||||
// Assume GL state is reset between frames.
|
||||
b.state = glstate{}
|
||||
fboID := glimpl.Framebuffer(b.funcs.GetBinding(glimpl.FRAMEBUFFER_BINDING))
|
||||
@@ -178,11 +178,11 @@ func (b *Backend) EndFrame() {
|
||||
b.funcs.ActiveTexture(glimpl.TEXTURE0)
|
||||
}
|
||||
|
||||
func (b *Backend) Caps() backend.Caps {
|
||||
func (b *Backend) Caps() driver.Caps {
|
||||
return b.feats
|
||||
}
|
||||
|
||||
func (b *Backend) NewTimer() backend.Timer {
|
||||
func (b *Backend) NewTimer() driver.Timer {
|
||||
return &gpuTimer{
|
||||
funcs: b.funcs,
|
||||
obj: b.funcs.CreateQuery(),
|
||||
@@ -193,7 +193,7 @@ func (b *Backend) IsTimeContinuous() bool {
|
||||
return b.funcs.GetInteger(glimpl.GPU_DISJOINT_EXT) == glimpl.FALSE
|
||||
}
|
||||
|
||||
func (b *Backend) NewFramebuffer(tex backend.Texture, depthBits int) (backend.Framebuffer, error) {
|
||||
func (b *Backend) NewFramebuffer(tex driver.Texture, depthBits int) (driver.Framebuffer, error) {
|
||||
glErr(b.funcs)
|
||||
gltex := tex.(*gpuTexture)
|
||||
fb := b.funcs.CreateFramebuffer()
|
||||
@@ -230,15 +230,15 @@ func (b *Backend) NewFramebuffer(tex backend.Texture, depthBits int) (backend.Fr
|
||||
return fbo, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, minFilter, magFilter backend.TextureFilter, binding backend.BufferBinding) (backend.Texture, error) {
|
||||
func (b *Backend) NewTexture(format driver.TextureFormat, width, height int, minFilter, magFilter driver.TextureFilter, binding driver.BufferBinding) (driver.Texture, error) {
|
||||
glErr(b.funcs)
|
||||
tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture(), width: width, height: height}
|
||||
switch format {
|
||||
case backend.TextureFormatFloat:
|
||||
case driver.TextureFormatFloat:
|
||||
tex.triple = b.floatTriple
|
||||
case backend.TextureFormatSRGB:
|
||||
case driver.TextureFormatSRGB:
|
||||
tex.triple = b.srgbaTriple
|
||||
case backend.TextureFormatRGBA8:
|
||||
case driver.TextureFormatRGBA8:
|
||||
tex.triple = textureTriple{glimpl.RGBA8, glimpl.RGBA, glimpl.UNSIGNED_BYTE}
|
||||
default:
|
||||
return nil, errors.New("unsupported texture format")
|
||||
@@ -261,11 +261,11 @@ func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, mi
|
||||
return tex, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer, error) {
|
||||
func (b *Backend) NewBuffer(typ driver.BufferBinding, size int) (driver.Buffer, error) {
|
||||
glErr(b.funcs)
|
||||
buf := &gpuBuffer{backend: b, typ: typ, size: size}
|
||||
if typ&backend.BufferBindingUniforms != 0 {
|
||||
if typ != backend.BufferBindingUniforms {
|
||||
if typ&driver.BufferBindingUniforms != 0 {
|
||||
if typ != driver.BufferBindingUniforms {
|
||||
return nil, errors.New("uniforms buffers cannot be bound as anything else")
|
||||
}
|
||||
if !b.ubo {
|
||||
@@ -273,7 +273,7 @@ func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer
|
||||
buf.data = make([]byte, size)
|
||||
}
|
||||
}
|
||||
if typ&^backend.BufferBindingUniforms != 0 || b.ubo {
|
||||
if typ&^driver.BufferBindingUniforms != 0 || b.ubo {
|
||||
buf.hasBuffer = true
|
||||
buf.obj = b.funcs.CreateBuffer()
|
||||
if err := glErr(b.funcs); err != nil {
|
||||
@@ -287,7 +287,7 @@ func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewImmutableBuffer(typ backend.BufferBinding, data []byte) (backend.Buffer, error) {
|
||||
func (b *Backend) NewImmutableBuffer(typ driver.BufferBinding, data []byte) (driver.Buffer, error) {
|
||||
glErr(b.funcs)
|
||||
obj := b.funcs.CreateBuffer()
|
||||
buf := &gpuBuffer{backend: b, obj: obj, typ: typ, size: len(data), hasBuffer: true}
|
||||
@@ -328,20 +328,20 @@ func (b *Backend) DispatchCompute(x, y, z int) {
|
||||
b.funcs.DispatchCompute(x, y, z)
|
||||
}
|
||||
|
||||
func (b *Backend) BindImageTexture(unit int, tex backend.Texture, access backend.AccessBits, f backend.TextureFormat) {
|
||||
func (b *Backend) BindImageTexture(unit int, tex driver.Texture, access driver.AccessBits, f driver.TextureFormat) {
|
||||
t := tex.(*gpuTexture)
|
||||
var acc glimpl.Enum
|
||||
switch access {
|
||||
case backend.AccessWrite:
|
||||
case driver.AccessWrite:
|
||||
acc = glimpl.WRITE_ONLY
|
||||
case backend.AccessRead:
|
||||
case driver.AccessRead:
|
||||
acc = glimpl.READ_ONLY
|
||||
default:
|
||||
panic("unsupported access bits")
|
||||
}
|
||||
var format glimpl.Enum
|
||||
switch f {
|
||||
case backend.TextureFormatRGBA8:
|
||||
case driver.TextureFormatRGBA8:
|
||||
format = glimpl.RGBA8
|
||||
default:
|
||||
panic("unsupported format")
|
||||
@@ -384,19 +384,19 @@ func (b *Backend) SetDepthTest(enable bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BlendFunc(sfactor, dfactor backend.BlendFactor) {
|
||||
func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {
|
||||
b.funcs.BlendFunc(toGLBlendFactor(sfactor), toGLBlendFactor(dfactor))
|
||||
}
|
||||
|
||||
func toGLBlendFactor(f backend.BlendFactor) glimpl.Enum {
|
||||
func toGLBlendFactor(f driver.BlendFactor) glimpl.Enum {
|
||||
switch f {
|
||||
case backend.BlendFactorOne:
|
||||
case driver.BlendFactorOne:
|
||||
return glimpl.ONE
|
||||
case backend.BlendFactorOneMinusSrcAlpha:
|
||||
case driver.BlendFactorOneMinusSrcAlpha:
|
||||
return glimpl.ONE_MINUS_SRC_ALPHA
|
||||
case backend.BlendFactorZero:
|
||||
case driver.BlendFactorZero:
|
||||
return glimpl.ZERO
|
||||
case backend.BlendFactorDstColor:
|
||||
case driver.BlendFactorDstColor:
|
||||
return glimpl.DST_COLOR
|
||||
default:
|
||||
panic("unsupported blend factor")
|
||||
@@ -415,14 +415,14 @@ func (b *Backend) SetBlend(enable bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) DrawElements(mode backend.DrawMode, off, count int) {
|
||||
func (b *Backend) DrawElements(mode driver.DrawMode, off, count int) {
|
||||
b.prepareDraw()
|
||||
// off is in 16-bit indices, but DrawElements take a byte offset.
|
||||
byteOff := off * 2
|
||||
b.funcs.DrawElements(toGLDrawMode(mode), count, glimpl.UNSIGNED_SHORT, byteOff)
|
||||
}
|
||||
|
||||
func (b *Backend) DrawArrays(mode backend.DrawMode, off, count int) {
|
||||
func (b *Backend) DrawArrays(mode driver.DrawMode, off, count int) {
|
||||
b.prepareDraw()
|
||||
b.funcs.DrawArrays(toGLDrawMode(mode), off, count)
|
||||
}
|
||||
@@ -438,11 +438,11 @@ func (b *Backend) prepareDraw() {
|
||||
}
|
||||
}
|
||||
|
||||
func toGLDrawMode(mode backend.DrawMode) glimpl.Enum {
|
||||
func toGLDrawMode(mode driver.DrawMode) glimpl.Enum {
|
||||
switch mode {
|
||||
case backend.DrawModeTriangleStrip:
|
||||
case driver.DrawModeTriangleStrip:
|
||||
return glimpl.TRIANGLE_STRIP
|
||||
case backend.DrawModeTriangles:
|
||||
case driver.DrawModeTriangles:
|
||||
return glimpl.TRIANGLES
|
||||
default:
|
||||
panic("unsupported draw mode")
|
||||
@@ -463,12 +463,12 @@ func (b *Backend) ClearDepth(d float32) {
|
||||
b.funcs.Clear(glimpl.DEPTH_BUFFER_BIT)
|
||||
}
|
||||
|
||||
func (b *Backend) DepthFunc(f backend.DepthFunc) {
|
||||
func (b *Backend) DepthFunc(f driver.DepthFunc) {
|
||||
var glfunc glimpl.Enum
|
||||
switch f {
|
||||
case backend.DepthFuncGreater:
|
||||
case driver.DepthFuncGreater:
|
||||
glfunc = glimpl.GREATER
|
||||
case backend.DepthFuncGreaterEqual:
|
||||
case driver.DepthFuncGreaterEqual:
|
||||
glfunc = glimpl.GEQUAL
|
||||
default:
|
||||
panic("unsupported depth func")
|
||||
@@ -476,7 +476,7 @@ func (b *Backend) DepthFunc(f backend.DepthFunc) {
|
||||
b.funcs.DepthFunc(glfunc)
|
||||
}
|
||||
|
||||
func (b *Backend) NewInputLayout(vs backend.ShaderSources, layout []backend.InputDesc) (backend.InputLayout, error) {
|
||||
func (b *Backend) NewInputLayout(vs driver.ShaderSources, layout []driver.InputDesc) (driver.InputLayout, error) {
|
||||
if len(vs.Inputs) != len(layout) {
|
||||
return nil, fmt.Errorf("NewInputLayout: got %d inputs, expected %d", len(layout), len(vs.Inputs))
|
||||
}
|
||||
@@ -491,7 +491,7 @@ func (b *Backend) NewInputLayout(vs backend.ShaderSources, layout []backend.Inpu
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewComputeProgram(src backend.ShaderSources) (backend.Program, error) {
|
||||
func (b *Backend) NewComputeProgram(src driver.ShaderSources) (driver.Program, error) {
|
||||
p, err := glimpl.CreateComputeProgram(b.funcs, src.GLSL310ES)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %v", src.Name, err)
|
||||
@@ -503,7 +503,7 @@ func (b *Backend) NewComputeProgram(src backend.ShaderSources) (backend.Program,
|
||||
return gpuProg, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (backend.Program, error) {
|
||||
func (b *Backend) NewProgram(vertShader, fragShader driver.ShaderSources) (driver.Program, error) {
|
||||
attr := make([]string, len(vertShader.Inputs))
|
||||
for _, inp := range vertShader.Inputs {
|
||||
attr[inp.Location] = inp.Name
|
||||
@@ -568,24 +568,24 @@ func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (back
|
||||
return gpuProg, nil
|
||||
}
|
||||
|
||||
func lookupUniform(funcs *glimpl.Functions, p glimpl.Program, loc backend.UniformLocation) uniformLocation {
|
||||
func lookupUniform(funcs *glimpl.Functions, p glimpl.Program, loc driver.UniformLocation) uniformLocation {
|
||||
u := funcs.GetUniformLocation(p, loc.Name)
|
||||
return uniformLocation{uniform: u, offset: loc.Offset, typ: loc.Type, size: loc.Size}
|
||||
}
|
||||
|
||||
func (p *gpuProgram) SetStorageBuffer(binding int, buffer backend.Buffer) {
|
||||
func (p *gpuProgram) SetStorageBuffer(binding int, buffer driver.Buffer) {
|
||||
buf := buffer.(*gpuBuffer)
|
||||
if buf.typ&backend.BufferBindingShaderStorage == 0 {
|
||||
if buf.typ&driver.BufferBindingShaderStorage == 0 {
|
||||
panic("not a shader storage buffer")
|
||||
}
|
||||
p.storage[binding] = buf
|
||||
}
|
||||
|
||||
func (p *gpuProgram) SetVertexUniforms(buffer backend.Buffer) {
|
||||
func (p *gpuProgram) SetVertexUniforms(buffer driver.Buffer) {
|
||||
p.vertUniforms.setBuffer(buffer)
|
||||
}
|
||||
|
||||
func (p *gpuProgram) SetFragmentUniforms(buffer backend.Buffer) {
|
||||
func (p *gpuProgram) SetFragmentUniforms(buffer driver.Buffer) {
|
||||
p.fragUniforms.setBuffer(buffer)
|
||||
}
|
||||
|
||||
@@ -604,7 +604,7 @@ func (p *gpuProgram) updateUniforms() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindProgram(prog backend.Program) {
|
||||
func (b *Backend) BindProgram(prog driver.Program) {
|
||||
p := prog.(*gpuProgram)
|
||||
b.useProgram(p)
|
||||
}
|
||||
@@ -613,7 +613,7 @@ func (p *gpuProgram) Release() {
|
||||
p.backend.funcs.DeleteProgram(p.obj)
|
||||
}
|
||||
|
||||
func (u *uniformsTracker) setup(funcs *glimpl.Functions, p glimpl.Program, uniformSize int, uniforms []backend.UniformLocation) {
|
||||
func (u *uniformsTracker) setup(funcs *glimpl.Functions, p glimpl.Program, uniformSize int, uniforms []driver.UniformLocation) {
|
||||
u.locs = make([]uniformLocation, len(uniforms))
|
||||
for i, uniform := range uniforms {
|
||||
u.locs[i] = lookupUniform(funcs, p, uniform)
|
||||
@@ -621,9 +621,9 @@ func (u *uniformsTracker) setup(funcs *glimpl.Functions, p glimpl.Program, unifo
|
||||
u.size = uniformSize
|
||||
}
|
||||
|
||||
func (u *uniformsTracker) setBuffer(buffer backend.Buffer) {
|
||||
func (u *uniformsTracker) setBuffer(buffer driver.Buffer) {
|
||||
buf := buffer.(*gpuBuffer)
|
||||
if buf.typ&backend.BufferBindingUniforms == 0 {
|
||||
if buf.typ&driver.BufferBindingUniforms == 0 {
|
||||
panic("not a uniform buffer")
|
||||
}
|
||||
if buf.size < u.size {
|
||||
@@ -644,19 +644,19 @@ func (p *uniformsTracker) update(funcs *glimpl.Functions) {
|
||||
for _, u := range p.locs {
|
||||
data := data[u.offset:]
|
||||
switch {
|
||||
case u.typ == backend.DataTypeFloat && u.size == 1:
|
||||
case u.typ == driver.DataTypeFloat && u.size == 1:
|
||||
data := data[:4]
|
||||
v := *(*[1]float32)(unsafe.Pointer(&data[0]))
|
||||
funcs.Uniform1f(u.uniform, v[0])
|
||||
case u.typ == backend.DataTypeFloat && u.size == 2:
|
||||
case u.typ == driver.DataTypeFloat && u.size == 2:
|
||||
data := data[:8]
|
||||
v := *(*[2]float32)(unsafe.Pointer(&data[0]))
|
||||
funcs.Uniform2f(u.uniform, v[0], v[1])
|
||||
case u.typ == backend.DataTypeFloat && u.size == 3:
|
||||
case u.typ == driver.DataTypeFloat && u.size == 3:
|
||||
data := data[:12]
|
||||
v := *(*[3]float32)(unsafe.Pointer(&data[0]))
|
||||
funcs.Uniform3f(u.uniform, v[0], v[1], v[2])
|
||||
case u.typ == backend.DataTypeFloat && u.size == 4:
|
||||
case u.typ == driver.DataTypeFloat && u.size == 4:
|
||||
data := data[:16]
|
||||
v := *(*[4]float32)(unsafe.Pointer(&data[0]))
|
||||
funcs.Uniform4f(u.uniform, v[0], v[1], v[2], v[3])
|
||||
@@ -704,7 +704,7 @@ func (b *gpuBuffer) Download(data []byte) error {
|
||||
}
|
||||
copy(data, bufferMap)
|
||||
if !b.backend.funcs.UnmapBuffer(firstBinding) {
|
||||
return backend.ErrContentLost
|
||||
return driver.ErrContentLost
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -716,9 +716,9 @@ func (b *gpuBuffer) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindVertexBuffer(buf backend.Buffer, stride, offset int) {
|
||||
func (b *Backend) BindVertexBuffer(buf driver.Buffer, stride, offset int) {
|
||||
gbuf := buf.(*gpuBuffer)
|
||||
if gbuf.typ&backend.BufferBindingVertices == 0 {
|
||||
if gbuf.typ&driver.BufferBindingVertices == 0 {
|
||||
panic("not a vertex buffer")
|
||||
}
|
||||
b.state.buffer = bufferBinding{buf: gbuf, stride: stride, offset: offset}
|
||||
@@ -735,9 +735,9 @@ func (b *Backend) setupVertexArrays() {
|
||||
l := layout.layout[i]
|
||||
var gltyp glimpl.Enum
|
||||
switch l.Type {
|
||||
case backend.DataTypeFloat:
|
||||
case driver.DataTypeFloat:
|
||||
gltyp = glimpl.FLOAT
|
||||
case backend.DataTypeShort:
|
||||
case driver.DataTypeShort:
|
||||
gltyp = glimpl.SHORT
|
||||
default:
|
||||
panic("unsupported data type")
|
||||
@@ -746,15 +746,15 @@ func (b *Backend) setupVertexArrays() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindIndexBuffer(buf backend.Buffer) {
|
||||
func (b *Backend) BindIndexBuffer(buf driver.Buffer) {
|
||||
gbuf := buf.(*gpuBuffer)
|
||||
if gbuf.typ&backend.BufferBindingIndices == 0 {
|
||||
if gbuf.typ&driver.BufferBindingIndices == 0 {
|
||||
panic("not an index buffer")
|
||||
}
|
||||
b.funcs.BindBuffer(glimpl.ELEMENT_ARRAY_BUFFER, gbuf.obj)
|
||||
}
|
||||
|
||||
func (b *Backend) BlitFramebuffer(dst, src backend.Framebuffer, srect, drect image.Rectangle) {
|
||||
func (b *Backend) BlitFramebuffer(dst, src driver.Framebuffer, srect, drect image.Rectangle) {
|
||||
b.funcs.BindFramebuffer(glimpl.DRAW_FRAMEBUFFER, dst.(*gpuFramebuffer).obj)
|
||||
b.funcs.BindFramebuffer(glimpl.READ_FRAMEBUFFER, src.(*gpuFramebuffer).obj)
|
||||
b.funcs.BlitFramebuffer(
|
||||
@@ -791,7 +791,7 @@ func flipImageY(stride int, height int, pixels []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindFramebuffer(fbo backend.Framebuffer) {
|
||||
func (b *Backend) BindFramebuffer(fbo driver.Framebuffer) {
|
||||
b.funcs.BindFramebuffer(glimpl.FRAMEBUFFER, fbo.(*gpuFramebuffer).obj)
|
||||
}
|
||||
|
||||
@@ -810,18 +810,18 @@ func (f *gpuFramebuffer) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func toTexFilter(f backend.TextureFilter) int {
|
||||
func toTexFilter(f driver.TextureFilter) int {
|
||||
switch f {
|
||||
case backend.FilterNearest:
|
||||
case driver.FilterNearest:
|
||||
return glimpl.NEAREST
|
||||
case backend.FilterLinear:
|
||||
case driver.FilterLinear:
|
||||
return glimpl.LINEAR
|
||||
default:
|
||||
panic("unsupported texture filter")
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindTexture(unit int, t backend.Texture) {
|
||||
func (b *Backend) BindTexture(unit int, t driver.Texture) {
|
||||
b.bindTexture(unit, t.(*gpuTexture))
|
||||
}
|
||||
|
||||
@@ -861,7 +861,7 @@ func (t *gpuTimer) Duration() (time.Duration, bool) {
|
||||
return time.Duration(nanos), true
|
||||
}
|
||||
|
||||
func (b *Backend) BindInputLayout(l backend.InputLayout) {
|
||||
func (b *Backend) BindInputLayout(l driver.InputLayout) {
|
||||
b.state.layout = l.(*gpuInputLayout)
|
||||
}
|
||||
|
||||
@@ -941,15 +941,15 @@ func hasExtension(exts []string, ext string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func firstBufferType(typ backend.BufferBinding) glimpl.Enum {
|
||||
func firstBufferType(typ driver.BufferBinding) glimpl.Enum {
|
||||
switch {
|
||||
case typ&backend.BufferBindingIndices != 0:
|
||||
case typ&driver.BufferBindingIndices != 0:
|
||||
return glimpl.ELEMENT_ARRAY_BUFFER
|
||||
case typ&backend.BufferBindingVertices != 0:
|
||||
case typ&driver.BufferBindingVertices != 0:
|
||||
return glimpl.ARRAY_BUFFER
|
||||
case typ&backend.BufferBindingUniforms != 0:
|
||||
case typ&driver.BufferBindingUniforms != 0:
|
||||
return glimpl.UNIFORM_BUFFER
|
||||
case typ&backend.BufferBindingShaderStorage != 0:
|
||||
case typ&driver.BufferBindingShaderStorage != 0:
|
||||
return glimpl.SHADER_STORAGE_BUFFER
|
||||
default:
|
||||
panic("unsupported buffer type")
|
||||
|
||||
+34
-34
@@ -20,7 +20,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/f32color"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/internal/ops"
|
||||
@@ -57,12 +57,12 @@ type gpu struct {
|
||||
frameStart time.Time
|
||||
zopsTimer, stencilTimer, coverTimer, cleanupTimer *timer
|
||||
drawOps drawOps
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
renderer *renderer
|
||||
}
|
||||
|
||||
type renderer struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
blitter *blitter
|
||||
pather *pather
|
||||
packer packer
|
||||
@@ -302,18 +302,18 @@ type resource interface {
|
||||
|
||||
type texture struct {
|
||||
src *image.RGBA
|
||||
tex backend.Texture
|
||||
tex driver.Texture
|
||||
}
|
||||
|
||||
type blitter struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
viewport image.Point
|
||||
prog [3]*program
|
||||
layout backend.InputLayout
|
||||
layout driver.InputLayout
|
||||
colUniforms *blitColUniforms
|
||||
texUniforms *blitTexUniforms
|
||||
linearGradientUniforms *blitLinearGradientUniforms
|
||||
quadVerts backend.Buffer
|
||||
quadVerts driver.Buffer
|
||||
}
|
||||
|
||||
type blitColUniforms struct {
|
||||
@@ -344,12 +344,12 @@ type blitLinearGradientUniforms struct {
|
||||
}
|
||||
|
||||
type uniformBuffer struct {
|
||||
buf backend.Buffer
|
||||
buf driver.Buffer
|
||||
ptr []byte
|
||||
}
|
||||
|
||||
type program struct {
|
||||
prog backend.Program
|
||||
prog driver.Program
|
||||
vertUniforms *uniformBuffer
|
||||
fragUniforms *uniformBuffer
|
||||
}
|
||||
@@ -385,23 +385,23 @@ const (
|
||||
)
|
||||
|
||||
func New(api API) (GPU, error) {
|
||||
d, err := backend.NewDevice(api)
|
||||
d, err := driver.NewDevice(api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
|
||||
feats := d.Caps().Features
|
||||
switch {
|
||||
case !forceCompute && feats.Has(backend.FeatureFloatRenderTargets):
|
||||
case !forceCompute && feats.Has(driver.FeatureFloatRenderTargets):
|
||||
return newGPU(d)
|
||||
case feats.Has(backend.FeatureCompute):
|
||||
case feats.Has(driver.FeatureCompute):
|
||||
return newCompute(d)
|
||||
default:
|
||||
return nil, errors.New("gpu: no support for float render targets nor compute")
|
||||
}
|
||||
}
|
||||
|
||||
func newGPU(ctx backend.Device) (*gpu, error) {
|
||||
func newGPU(ctx driver.Device) (*gpu, error) {
|
||||
g := &gpu{
|
||||
cache: newResourceCache(),
|
||||
}
|
||||
@@ -412,7 +412,7 @@ func newGPU(ctx backend.Device) (*gpu, error) {
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (g *gpu) init(ctx backend.Device) error {
|
||||
func (g *gpu) init(ctx driver.Device) error {
|
||||
g.ctx = ctx
|
||||
g.renderer = newRenderer(ctx)
|
||||
return nil
|
||||
@@ -439,7 +439,7 @@ func (g *gpu) Collect(viewport image.Point, frameOps *op.Ops) {
|
||||
g.drawOps.reset(g.cache, viewport)
|
||||
g.drawOps.collect(g.ctx, g.cache, frameOps, viewport)
|
||||
g.frameStart = time.Now()
|
||||
if g.drawOps.profile && g.timers == nil && g.ctx.Caps().Features.Has(backend.FeatureTimers) {
|
||||
if g.drawOps.profile && g.timers == nil && g.ctx.Caps().Features.Has(driver.FeatureTimers) {
|
||||
g.timers = newTimers(g.ctx)
|
||||
g.zopsTimer = g.timers.newTimer()
|
||||
g.stencilTimer = g.timers.newTimer()
|
||||
@@ -459,7 +459,7 @@ func (g *gpu) Frame() error {
|
||||
g.zopsTimer.begin()
|
||||
}
|
||||
g.ctx.BindFramebuffer(defFBO)
|
||||
g.ctx.DepthFunc(backend.DepthFuncGreater)
|
||||
g.ctx.DepthFunc(driver.DepthFuncGreater)
|
||||
// Note that Clear must be before ClearDepth if nothing else is rendered
|
||||
// (len(zimageOps) == 0). If not, the Fairphone 2 will corrupt the depth buffer.
|
||||
if g.drawOps.clear {
|
||||
@@ -505,7 +505,7 @@ func (g *gpu) Profile() string {
|
||||
return g.profile
|
||||
}
|
||||
|
||||
func (r *renderer) texHandle(cache *resourceCache, data imageOpData) backend.Texture {
|
||||
func (r *renderer) texHandle(cache *resourceCache, data imageOpData) driver.Texture {
|
||||
var tex *texture
|
||||
t, exists := cache.get(data.handle)
|
||||
if !exists {
|
||||
@@ -518,11 +518,11 @@ func (r *renderer) texHandle(cache *resourceCache, data imageOpData) backend.Tex
|
||||
if tex.tex != nil {
|
||||
return tex.tex
|
||||
}
|
||||
handle, err := r.ctx.NewTexture(backend.TextureFormatSRGB, data.src.Bounds().Dx(), data.src.Bounds().Dy(), backend.FilterLinear, backend.FilterLinear, backend.BufferBindingTexture)
|
||||
handle, err := r.ctx.NewTexture(driver.TextureFormatSRGB, data.src.Bounds().Dx(), data.src.Bounds().Dy(), driver.FilterLinear, driver.FilterLinear, driver.BufferBindingTexture)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
backend.UploadImage(handle, image.Pt(0, 0), data.src)
|
||||
driver.UploadImage(handle, image.Pt(0, 0), data.src)
|
||||
tex.tex = handle
|
||||
return tex.tex
|
||||
}
|
||||
@@ -533,7 +533,7 @@ func (t *texture) release() {
|
||||
}
|
||||
}
|
||||
|
||||
func newRenderer(ctx backend.Device) *renderer {
|
||||
func newRenderer(ctx driver.Device) *renderer {
|
||||
r := &renderer{
|
||||
ctx: ctx,
|
||||
blitter: newBlitter(ctx),
|
||||
@@ -557,8 +557,8 @@ func (r *renderer) release() {
|
||||
r.blitter.release()
|
||||
}
|
||||
|
||||
func newBlitter(ctx backend.Device) *blitter {
|
||||
quadVerts, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices,
|
||||
func newBlitter(ctx driver.Device) *blitter {
|
||||
quadVerts, err := ctx.NewImmutableBuffer(driver.BufferBindingVertices,
|
||||
gunsafe.BytesView([]float32{
|
||||
-1, +1, 0, 0,
|
||||
+1, +1, 1, 0,
|
||||
@@ -596,7 +596,7 @@ func (b *blitter) release() {
|
||||
b.layout.Release()
|
||||
}
|
||||
|
||||
func createColorPrograms(b backend.Device, vsSrc backend.ShaderSources, fsSrc [3]backend.ShaderSources, vertUniforms, fragUniforms [3]interface{}) ([3]*program, backend.InputLayout, error) {
|
||||
func createColorPrograms(b driver.Device, vsSrc driver.ShaderSources, fsSrc [3]driver.ShaderSources, vertUniforms, fragUniforms [3]interface{}) ([3]*program, driver.InputLayout, error) {
|
||||
var progs [3]*program
|
||||
{
|
||||
prog, err := b.NewProgram(vsSrc, fsSrc[materialTexture])
|
||||
@@ -649,9 +649,9 @@ func createColorPrograms(b backend.Device, vsSrc backend.ShaderSources, fsSrc [3
|
||||
}
|
||||
progs[materialLinearGradient] = newProgram(prog, vertBuffer, fragBuffer)
|
||||
}
|
||||
layout, err := b.NewInputLayout(vsSrc, []backend.InputDesc{
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
layout, err := b.NewInputLayout(vsSrc, []driver.InputDesc{
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
})
|
||||
if err != nil {
|
||||
progs[materialTexture].Release()
|
||||
@@ -726,7 +726,7 @@ func (r *renderer) intersectPath(p *pathOp, clip image.Rectangle) {
|
||||
r.pather.stenciler.iprog.uniforms.vert.uvTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y}
|
||||
r.pather.stenciler.iprog.uniforms.vert.subUVTransform = [4]float32{subScale.X, subScale.Y, subOff.X, subOff.Y}
|
||||
r.pather.stenciler.iprog.prog.UploadUniforms()
|
||||
r.ctx.DrawArrays(backend.DrawModeTriangleStrip, 0, 4)
|
||||
r.ctx.DrawArrays(driver.DrawModeTriangleStrip, 0, 4)
|
||||
}
|
||||
|
||||
func (r *renderer) packIntersections(ops []imageOp) {
|
||||
@@ -819,7 +819,7 @@ func (d *drawOps) reset(cache *resourceCache, viewport image.Point) {
|
||||
d.vertCache = d.vertCache[:0]
|
||||
}
|
||||
|
||||
func (d *drawOps) collect(ctx backend.Device, cache *resourceCache, root *op.Ops, viewport image.Point) {
|
||||
func (d *drawOps) collect(ctx driver.Device, cache *resourceCache, root *op.Ops, viewport image.Point) {
|
||||
clip := f32.Rectangle{
|
||||
Max: f32.Point{X: float32(viewport.X), Y: float32(viewport.Y)},
|
||||
}
|
||||
@@ -1135,10 +1135,10 @@ func (r *renderer) drawZOps(cache *resourceCache, ops []imageOp) {
|
||||
func (r *renderer) drawOps(cache *resourceCache, ops []imageOp) {
|
||||
r.ctx.SetDepthTest(true)
|
||||
r.ctx.DepthMask(false)
|
||||
r.ctx.BlendFunc(backend.BlendFactorOne, backend.BlendFactorOneMinusSrcAlpha)
|
||||
r.ctx.BlendFunc(driver.BlendFactorOne, driver.BlendFactorOneMinusSrcAlpha)
|
||||
r.ctx.BindVertexBuffer(r.blitter.quadVerts, 4*4, 0)
|
||||
r.ctx.BindInputLayout(r.pather.coverer.layout)
|
||||
var coverTex backend.Texture
|
||||
var coverTex driver.Texture
|
||||
for _, img := range ops {
|
||||
m := img.material
|
||||
switch m.material {
|
||||
@@ -1198,18 +1198,18 @@ func (b *blitter) blit(z float32, mat materialType, col f32color.RGBA, col1, col
|
||||
uniforms.z = z
|
||||
uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
|
||||
p.UploadUniforms()
|
||||
b.ctx.DrawArrays(backend.DrawModeTriangleStrip, 0, 4)
|
||||
b.ctx.DrawArrays(driver.DrawModeTriangleStrip, 0, 4)
|
||||
}
|
||||
|
||||
// newUniformBuffer creates a new GPU uniform buffer backed by the
|
||||
// structure uniformBlock points to.
|
||||
func newUniformBuffer(b backend.Device, uniformBlock interface{}) *uniformBuffer {
|
||||
func newUniformBuffer(b driver.Device, uniformBlock interface{}) *uniformBuffer {
|
||||
ref := reflect.ValueOf(uniformBlock)
|
||||
// Determine the size of the uniforms structure, *uniforms.
|
||||
size := ref.Elem().Type().Size()
|
||||
// Map the uniforms structure as a byte slice.
|
||||
ptr := (*[1 << 30]byte)(unsafe.Pointer(ref.Pointer()))[:size:size]
|
||||
ubuf, err := b.NewBuffer(backend.BufferBindingUniforms, len(ptr))
|
||||
ubuf, err := b.NewBuffer(driver.BufferBindingUniforms, len(ptr))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -1225,7 +1225,7 @@ func (u *uniformBuffer) Release() {
|
||||
u.buf = nil
|
||||
}
|
||||
|
||||
func newProgram(prog backend.Program, vertUniforms, fragUniforms *uniformBuffer) *program {
|
||||
func newProgram(prog driver.Program, vertUniforms, fragUniforms *uniformBuffer) *program {
|
||||
if vertUniforms != nil {
|
||||
prog.SetVertexUniforms(vertUniforms.buf)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/f32color"
|
||||
"gioui.org/internal/unsafe"
|
||||
)
|
||||
@@ -42,7 +42,7 @@ func TestSimpleShader(t *testing.T) {
|
||||
}
|
||||
defer p.Release()
|
||||
b.BindProgram(p)
|
||||
b.DrawArrays(backend.DrawModeTriangles, 0, 3)
|
||||
b.DrawArrays(driver.DrawModeTriangles, 0, 3)
|
||||
img := screenshot(t, fbo, sz)
|
||||
if got := img.RGBAAt(0, 0); got != clearColExpect {
|
||||
t.Errorf("got color %v, expected %v", got, clearColExpect)
|
||||
@@ -65,7 +65,7 @@ func TestInputShader(t *testing.T) {
|
||||
}
|
||||
defer p.Release()
|
||||
b.BindProgram(p)
|
||||
buf, err := b.NewImmutableBuffer(backend.BufferBindingVertices,
|
||||
buf, err := b.NewImmutableBuffer(driver.BufferBindingVertices,
|
||||
unsafe.BytesView([]float32{
|
||||
0, .5, .5, 1,
|
||||
-.5, -.5, .5, 1,
|
||||
@@ -77,9 +77,9 @@ func TestInputShader(t *testing.T) {
|
||||
}
|
||||
defer buf.Release()
|
||||
b.BindVertexBuffer(buf, 4*4, 0)
|
||||
layout, err := b.NewInputLayout(shader_input_vert, []backend.InputDesc{
|
||||
layout, err := b.NewInputLayout(shader_input_vert, []driver.InputDesc{
|
||||
{
|
||||
Type: backend.DataTypeFloat,
|
||||
Type: driver.DataTypeFloat,
|
||||
Size: 4,
|
||||
Offset: 0,
|
||||
},
|
||||
@@ -89,7 +89,7 @@ func TestInputShader(t *testing.T) {
|
||||
}
|
||||
defer layout.Release()
|
||||
b.BindInputLayout(layout)
|
||||
b.DrawArrays(backend.DrawModeTriangles, 0, 3)
|
||||
b.DrawArrays(driver.DrawModeTriangles, 0, 3)
|
||||
img := screenshot(t, fbo, sz)
|
||||
if got := img.RGBAAt(0, 0); got != clearColExpect {
|
||||
t.Errorf("got color %v, expected %v", got, clearColExpect)
|
||||
@@ -125,7 +125,7 @@ func TestFramebuffers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setupFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuffer {
|
||||
func setupFBO(t *testing.T, b driver.Device, size image.Point) driver.Framebuffer {
|
||||
fbo := newFBO(t, b, size)
|
||||
b.BindFramebuffer(fbo)
|
||||
// ClearColor accepts linear RGBA colors, while 8-bit colors
|
||||
@@ -137,12 +137,12 @@ func setupFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuf
|
||||
return fbo
|
||||
}
|
||||
|
||||
func newFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuffer {
|
||||
func newFBO(t *testing.T, b driver.Device, size image.Point) driver.Framebuffer {
|
||||
fboTex, err := b.NewTexture(
|
||||
backend.TextureFormatSRGB,
|
||||
driver.TextureFormatSRGB,
|
||||
size.X, size.Y,
|
||||
backend.FilterNearest, backend.FilterNearest,
|
||||
backend.BufferBindingFramebuffer,
|
||||
driver.FilterNearest, driver.FilterNearest,
|
||||
driver.BufferBindingFramebuffer,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -161,7 +161,7 @@ func newFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuffe
|
||||
return fbo
|
||||
}
|
||||
|
||||
func newBackend(t *testing.T) backend.Device {
|
||||
func newBackend(t *testing.T) driver.Device {
|
||||
ctx, err := newContext()
|
||||
if err != nil {
|
||||
t.Skipf("no context available: %v", err)
|
||||
@@ -170,7 +170,7 @@ func newBackend(t *testing.T) backend.Device {
|
||||
if err := ctx.MakeCurrent(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := backend.NewDevice(ctx.API())
|
||||
b, err := driver.NewDevice(ctx.API())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func newBackend(t *testing.T) backend.Device {
|
||||
return b
|
||||
}
|
||||
|
||||
func screenshot(t *testing.T, fbo backend.Framebuffer, size image.Point) *image.RGBA {
|
||||
func screenshot(t *testing.T, fbo driver.Framebuffer, size image.Point) *image.RGBA {
|
||||
img := image.NewRGBA(image.Rectangle{Max: size})
|
||||
err := fbo.ReadPixels(
|
||||
image.Rectangle{
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"gioui.org/gpu"
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
@@ -18,10 +18,10 @@ import (
|
||||
type Window struct {
|
||||
size image.Point
|
||||
ctx context
|
||||
backend backend.Device
|
||||
backend driver.Device
|
||||
gpu gpu.GPU
|
||||
fboTex backend.Texture
|
||||
fbo backend.Framebuffer
|
||||
fboTex driver.Texture
|
||||
fbo driver.Framebuffer
|
||||
}
|
||||
|
||||
type context interface {
|
||||
@@ -43,16 +43,16 @@ func NewWindow(width, height int) (*Window, error) {
|
||||
}
|
||||
err = contextDo(ctx, func() error {
|
||||
api := ctx.API()
|
||||
dev, err := backend.NewDevice(api)
|
||||
dev, err := driver.NewDevice(api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dev.Viewport(0, 0, width, height)
|
||||
fboTex, err := dev.NewTexture(
|
||||
backend.TextureFormatSRGB,
|
||||
driver.TextureFormatSRGB,
|
||||
width, height,
|
||||
backend.FilterNearest, backend.FilterNearest,
|
||||
backend.BufferBindingFramebuffer,
|
||||
driver.FilterNearest, driver.FilterNearest,
|
||||
driver.BufferBindingFramebuffer,
|
||||
)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
package headless
|
||||
|
||||
import "gioui.org/gpu/backend"
|
||||
import "gioui.org/gpu/internal/driver"
|
||||
|
||||
var (
|
||||
shader_input_vert = backend.ShaderSources{
|
||||
shader_input_vert = driver.ShaderSources{
|
||||
Name: "input.vert",
|
||||
Inputs: []backend.InputLocation{{Name: "position", Location: 0, Semantic: "POSITION", SemanticIndex: 0, Type: 0x0, Size: 4}},
|
||||
Inputs: []driver.InputLocation{{Name: "position", Location: 0, Semantic: "POSITION", SemanticIndex: 0, Type: 0x0, Size: 4}},
|
||||
GLSL100ES: "\nattribute vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n",
|
||||
GLSL300ES: "#version 300 es\n\nlayout(location = 0) in vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n",
|
||||
GLSL130: "#version 130\n\nin vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n",
|
||||
GLSL150: "#version 150\n\nin vec4 position;\n\nvoid main()\n{\n gl_Position = position;\n}\n\n",
|
||||
HLSL: []byte{0x44, 0x58, 0x42, 0x43, 0x35, 0xe9, 0xae, 0x29, 0x96, 0x7e, 0x7c, 0xe6, 0x40, 0xb0, 0x4e, 0x29, 0xd9, 0x98, 0x51, 0x7c, 0x1, 0x0, 0x0, 0x0, 0x10, 0x2, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x38, 0x0, 0x0, 0x0, 0x9c, 0x0, 0x0, 0x0, 0xe0, 0x0, 0x0, 0x0, 0x5c, 0x1, 0x0, 0x0, 0xa8, 0x1, 0x0, 0x0, 0xdc, 0x1, 0x0, 0x0, 0x41, 0x6f, 0x6e, 0x39, 0x5c, 0x0, 0x0, 0x0, 0x5c, 0x0, 0x0, 0x0, 0x0, 0x2, 0xfe, 0xff, 0x34, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x1, 0x0, 0x24, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0xfe, 0xff, 0x1f, 0x0, 0x0, 0x2, 0x5, 0x0, 0x0, 0x80, 0x0, 0x0, 0xf, 0x90, 0x4, 0x0, 0x0, 0x4, 0x0, 0x0, 0x3, 0xc0, 0x0, 0x0, 0xff, 0x90, 0x0, 0x0, 0xe4, 0xa0, 0x0, 0x0, 0xe4, 0x90, 0x1, 0x0, 0x0, 0x2, 0x0, 0x0, 0xc, 0xc0, 0x0, 0x0, 0xe4, 0x90, 0xff, 0xff, 0x0, 0x0, 0x53, 0x48, 0x44, 0x52, 0x3c, 0x0, 0x0, 0x0, 0x40, 0x0, 0x1, 0x0, 0xf, 0x0, 0x0, 0x0, 0x5f, 0x0, 0x0, 0x3, 0xf2, 0x10, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x67, 0x0, 0x0, 0x4, 0xf2, 0x20, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x36, 0x0, 0x0, 0x5, 0xf2, 0x20, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x1e, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x0, 0x0, 0x1, 0x53, 0x54, 0x41, 0x54, 0x74, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x44, 0x45, 0x46, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x0, 0x4, 0xfe, 0xff, 0x0, 0x1, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x0, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 0x0, 0x0, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x0, 0xab, 0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x0},
|
||||
}
|
||||
shader_simple_frag = backend.ShaderSources{
|
||||
shader_simple_frag = driver.ShaderSources{
|
||||
Name: "simple.frag",
|
||||
GLSL100ES: "precision mediump float;\nprecision highp int;\n\nvoid main()\n{\n gl_FragData[0] = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n",
|
||||
GLSL300ES: "#version 300 es\nprecision mediump float;\nprecision highp int;\n\nlayout(location = 0) out vec4 fragColor;\n\nvoid main()\n{\n fragColor = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n",
|
||||
@@ -22,7 +22,7 @@ var (
|
||||
GLSL150: "#version 150\n\nout vec4 fragColor;\n\nvoid main()\n{\n fragColor = vec4(0.25, 0.550000011920928955078125, 0.75, 1.0);\n}\n\n",
|
||||
HLSL: []byte{0x44, 0x58, 0x42, 0x43, 0xf5, 0x46, 0xde, 0x66, 0x24, 0x29, 0xa8, 0xbb, 0x56, 0xea, 0x73, 0xb5, 0x6b, 0x73, 0x12, 0x72, 0x1, 0x0, 0x0, 0x0, 0xdc, 0x1, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x38, 0x0, 0x0, 0x0, 0x90, 0x0, 0x0, 0x0, 0xd0, 0x0, 0x0, 0x0, 0x4c, 0x1, 0x0, 0x0, 0x98, 0x1, 0x0, 0x0, 0xa8, 0x1, 0x0, 0x0, 0x41, 0x6f, 0x6e, 0x39, 0x50, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x0, 0x2, 0xff, 0xff, 0x2c, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x0, 0x24, 0x0, 0x0, 0x2, 0xff, 0xff, 0x51, 0x0, 0x0, 0x5, 0x0, 0x0, 0xf, 0xa0, 0x0, 0x0, 0x80, 0x3e, 0xcd, 0xcc, 0xc, 0x3f, 0x0, 0x0, 0x40, 0x3f, 0x0, 0x0, 0x80, 0x3f, 0x1, 0x0, 0x0, 0x2, 0x0, 0x8, 0xf, 0x80, 0x0, 0x0, 0xe4, 0xa0, 0xff, 0xff, 0x0, 0x0, 0x53, 0x48, 0x44, 0x52, 0x38, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x3, 0xf2, 0x20, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x0, 0x0, 0x8, 0xf2, 0x20, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x40, 0x0, 0x0, 0x0, 0x0, 0x80, 0x3e, 0xcd, 0xcc, 0xc, 0x3f, 0x0, 0x0, 0x40, 0x3f, 0x0, 0x0, 0x80, 0x3f, 0x3e, 0x0, 0x0, 0x1, 0x53, 0x54, 0x41, 0x54, 0x74, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x44, 0x45, 0x46, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x0, 0x4, 0xff, 0xff, 0x0, 0x1, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x0, 0x49, 0x53, 0x47, 0x4e, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x53, 0x56, 0x5f, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x0, 0xab, 0xab},
|
||||
}
|
||||
shader_simple_vert = backend.ShaderSources{
|
||||
shader_simple_vert = driver.ShaderSources{
|
||||
Name: "simple.vert",
|
||||
GLSL100ES: "\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n",
|
||||
GLSL300ES: "#version 300 es\n\nvoid main()\n{\n float x;\n float y;\n if (gl_VertexID == 0)\n {\n x = 0.0;\n y = 0.5;\n }\n else\n {\n if (gl_VertexID == 1)\n {\n x = 0.5;\n y = -0.5;\n }\n else\n {\n x = -0.5;\n y = -0.5;\n }\n }\n gl_Position = vec4(x, y, 0.5, 1.0);\n}\n\n",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/d3d11"
|
||||
gunsafe "gioui.org/internal/unsafe"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ type Backend struct {
|
||||
// Current program.
|
||||
prog *Program
|
||||
|
||||
caps backend.Caps
|
||||
caps driver.Caps
|
||||
|
||||
// fbo is the currently bound fbo.
|
||||
fbo *Framebuffer
|
||||
@@ -43,20 +43,20 @@ type Backend struct {
|
||||
|
||||
type blendState struct {
|
||||
enable bool
|
||||
sfactor backend.BlendFactor
|
||||
dfactor backend.BlendFactor
|
||||
sfactor driver.BlendFactor
|
||||
dfactor driver.BlendFactor
|
||||
}
|
||||
|
||||
type depthState struct {
|
||||
enable bool
|
||||
mask bool
|
||||
fn backend.DepthFunc
|
||||
fn driver.DepthFunc
|
||||
}
|
||||
|
||||
type Texture struct {
|
||||
backend *Backend
|
||||
format uint32
|
||||
bindings backend.BufferBinding
|
||||
bindings driver.BufferBinding
|
||||
tex *d3d11.Texture2D
|
||||
sampler *d3d11.SamplerState
|
||||
resView *d3d11.ShaderResourceView
|
||||
@@ -99,7 +99,7 @@ type InputLayout struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
backend.NewDirect3D11Device = newDirect3D11Device
|
||||
driver.NewDirect3D11Device = newDirect3D11Device
|
||||
}
|
||||
|
||||
func detectFloatFormat(dev *d3d11.Device) (uint32, bool) {
|
||||
@@ -121,12 +121,12 @@ func detectFloatFormat(dev *d3d11.Device) (uint32, bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) {
|
||||
func newDirect3D11Device(api driver.Direct3D11) (driver.Device, error) {
|
||||
dev := (*d3d11.Device)(api.Device)
|
||||
b := &Backend{
|
||||
dev: dev,
|
||||
ctx: dev.GetImmediateContext(),
|
||||
caps: backend.Caps{
|
||||
caps: driver.Caps{
|
||||
MaxTextureSize: 2048, // 9.1 maximum
|
||||
},
|
||||
depthStates: make(map[depthState]*d3d11.DepthStencilState),
|
||||
@@ -146,7 +146,7 @@ func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) {
|
||||
}
|
||||
if fmt, ok := detectFloatFormat(dev); ok {
|
||||
b.floatFormat = fmt
|
||||
b.caps.Features |= backend.FeatureFloatRenderTargets
|
||||
b.caps.Features |= driver.FeatureFloatRenderTargets
|
||||
}
|
||||
// Enable depth mask to match OpenGL.
|
||||
b.depthState.mask = true
|
||||
@@ -164,7 +164,7 @@ func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (b *Backend) BeginFrame() backend.Framebuffer {
|
||||
func (b *Backend) BeginFrame() driver.Framebuffer {
|
||||
renderTarget, depthView := b.ctx.OMGetRenderTargets()
|
||||
// Assume someone else is holding on to the render targets.
|
||||
if renderTarget != nil {
|
||||
@@ -179,11 +179,11 @@ func (b *Backend) BeginFrame() backend.Framebuffer {
|
||||
func (b *Backend) EndFrame() {
|
||||
}
|
||||
|
||||
func (b *Backend) Caps() backend.Caps {
|
||||
func (b *Backend) Caps() driver.Caps {
|
||||
return b.caps
|
||||
}
|
||||
|
||||
func (b *Backend) NewTimer() backend.Timer {
|
||||
func (b *Backend) NewTimer() driver.Timer {
|
||||
panic("timers not supported")
|
||||
}
|
||||
|
||||
@@ -202,12 +202,12 @@ func (b *Backend) Release() {
|
||||
*b = Backend{}
|
||||
}
|
||||
|
||||
func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, minFilter, magFilter backend.TextureFilter, bindings backend.BufferBinding) (backend.Texture, error) {
|
||||
func (b *Backend) NewTexture(format driver.TextureFormat, width, height int, minFilter, magFilter driver.TextureFilter, bindings driver.BufferBinding) (driver.Texture, error) {
|
||||
var d3dfmt uint32
|
||||
switch format {
|
||||
case backend.TextureFormatFloat:
|
||||
case driver.TextureFormatFloat:
|
||||
d3dfmt = b.floatFormat
|
||||
case backend.TextureFormatSRGB:
|
||||
case driver.TextureFormatSRGB:
|
||||
d3dfmt = d3d11.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported texture format %d", format)
|
||||
@@ -231,12 +231,12 @@ func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, mi
|
||||
sampler *d3d11.SamplerState
|
||||
resView *d3d11.ShaderResourceView
|
||||
)
|
||||
if bindings&backend.BufferBindingTexture != 0 {
|
||||
if bindings&driver.BufferBindingTexture != 0 {
|
||||
var filter uint32
|
||||
switch {
|
||||
case minFilter == backend.FilterNearest && magFilter == backend.FilterNearest:
|
||||
case minFilter == driver.FilterNearest && magFilter == driver.FilterNearest:
|
||||
filter = d3d11.FILTER_MIN_MAG_MIP_POINT
|
||||
case minFilter == backend.FilterLinear && magFilter == backend.FilterLinear:
|
||||
case minFilter == driver.FilterLinear && magFilter == driver.FilterLinear:
|
||||
filter = d3d11.FILTER_MIN_MAG_LINEAR_MIP_POINT
|
||||
default:
|
||||
d3d11.IUnknownRelease(unsafe.Pointer(tex), tex.Vtbl.Release)
|
||||
@@ -278,9 +278,9 @@ func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, mi
|
||||
return &Texture{backend: b, format: d3dfmt, tex: tex, sampler: sampler, resView: resView, bindings: bindings, width: width, height: height}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewFramebuffer(tex backend.Texture, depthBits int) (backend.Framebuffer, error) {
|
||||
func (b *Backend) NewFramebuffer(tex driver.Texture, depthBits int) (driver.Framebuffer, error) {
|
||||
d3dtex := tex.(*Texture)
|
||||
if d3dtex.bindings&backend.BufferBindingFramebuffer == 0 {
|
||||
if d3dtex.bindings&driver.BufferBindingFramebuffer == 0 {
|
||||
return nil, errors.New("the texture was created without BufferBindingFramebuffer binding")
|
||||
}
|
||||
resource := (*d3d11.Resource)(unsafe.Pointer(d3dtex.tex))
|
||||
@@ -300,7 +300,7 @@ func (b *Backend) NewFramebuffer(tex backend.Texture, depthBits int) (backend.Fr
|
||||
return fbo, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []backend.InputDesc) (backend.InputLayout, error) {
|
||||
func (b *Backend) NewInputLayout(vertexShader driver.ShaderSources, layout []driver.InputDesc) (driver.InputLayout, error) {
|
||||
if len(vertexShader.Inputs) != len(layout) {
|
||||
return nil, fmt.Errorf("NewInputLayout: got %d inputs, expected %d", len(layout), len(vertexShader.Inputs))
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []ba
|
||||
}
|
||||
var format uint32
|
||||
switch l.Type {
|
||||
case backend.DataTypeFloat:
|
||||
case driver.DataTypeFloat:
|
||||
switch l.Size {
|
||||
case 1:
|
||||
format = d3d11.DXGI_FORMAT_R32_FLOAT
|
||||
@@ -326,7 +326,7 @@ func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []ba
|
||||
default:
|
||||
panic("unsupported float data size")
|
||||
}
|
||||
case backend.DataTypeShort:
|
||||
case driver.DataTypeShort:
|
||||
switch l.Size {
|
||||
case 1:
|
||||
format = d3d11.DXGI_FORMAT_R16_SINT
|
||||
@@ -352,9 +352,9 @@ func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []ba
|
||||
return &InputLayout{layout: l}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer, error) {
|
||||
if typ&backend.BufferBindingUniforms != 0 {
|
||||
if typ != backend.BufferBindingUniforms {
|
||||
func (b *Backend) NewBuffer(typ driver.BufferBinding, size int) (driver.Buffer, error) {
|
||||
if typ&driver.BufferBindingUniforms != 0 {
|
||||
if typ != driver.BufferBindingUniforms {
|
||||
return nil, errors.New("uniform buffers cannot have other bindings")
|
||||
}
|
||||
if size%16 != 0 {
|
||||
@@ -372,9 +372,9 @@ func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer
|
||||
return &Buffer{backend: b, buf: buf, bind: bind}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewImmutableBuffer(typ backend.BufferBinding, data []byte) (backend.Buffer, error) {
|
||||
if typ&backend.BufferBindingUniforms != 0 {
|
||||
if typ != backend.BufferBindingUniforms {
|
||||
func (b *Backend) NewImmutableBuffer(typ driver.BufferBinding, data []byte) (driver.Buffer, error) {
|
||||
if typ&driver.BufferBindingUniforms != 0 {
|
||||
if typ != driver.BufferBindingUniforms {
|
||||
return nil, errors.New("uniform buffers cannot have other bindings")
|
||||
}
|
||||
if len(data)%16 != 0 {
|
||||
@@ -393,11 +393,11 @@ func (b *Backend) NewImmutableBuffer(typ backend.BufferBinding, data []byte) (ba
|
||||
return &Buffer{backend: b, buf: buf, bind: bind, immutable: true}, nil
|
||||
}
|
||||
|
||||
func (b *Backend) NewComputeProgram(shader backend.ShaderSources) (backend.Program, error) {
|
||||
func (b *Backend) NewComputeProgram(shader driver.ShaderSources) (driver.Program, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (b *Backend) NewProgram(vertexShader, fragmentShader backend.ShaderSources) (backend.Program, error) {
|
||||
func (b *Backend) NewProgram(vertexShader, fragmentShader driver.ShaderSources) (driver.Program, error) {
|
||||
vs, err := b.dev.CreateVertexShader(vertexShader.HLSL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -435,17 +435,17 @@ func (b *Backend) Viewport(x, y, width, height int) {
|
||||
b.ctx.RSSetViewports(&b.viewport)
|
||||
}
|
||||
|
||||
func (b *Backend) DrawArrays(mode backend.DrawMode, off, count int) {
|
||||
func (b *Backend) DrawArrays(mode driver.DrawMode, off, count int) {
|
||||
b.prepareDraw(mode)
|
||||
b.ctx.Draw(uint32(count), uint32(off))
|
||||
}
|
||||
|
||||
func (b *Backend) DrawElements(mode backend.DrawMode, off, count int) {
|
||||
func (b *Backend) DrawElements(mode driver.DrawMode, off, count int) {
|
||||
b.prepareDraw(mode)
|
||||
b.ctx.DrawIndexed(uint32(count), uint32(off), 0)
|
||||
}
|
||||
|
||||
func (b *Backend) prepareDraw(mode backend.DrawMode) {
|
||||
func (b *Backend) prepareDraw(mode driver.DrawMode) {
|
||||
if p := b.prog; p != nil {
|
||||
b.ctx.VSSetShader(p.vert.shader)
|
||||
b.ctx.PSSetShader(p.frag.shader)
|
||||
@@ -458,9 +458,9 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
|
||||
}
|
||||
var topology uint32
|
||||
switch mode {
|
||||
case backend.DrawModeTriangles:
|
||||
case driver.DrawModeTriangles:
|
||||
topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLELIST
|
||||
case backend.DrawModeTriangleStrip:
|
||||
case driver.DrawModeTriangleStrip:
|
||||
topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
|
||||
default:
|
||||
panic("unsupported draw mode")
|
||||
@@ -477,9 +477,9 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
|
||||
desc.DepthWriteMask = d3d11.DEPTH_WRITE_MASK_ALL
|
||||
}
|
||||
switch b.depthState.fn {
|
||||
case backend.DepthFuncGreater:
|
||||
case driver.DepthFuncGreater:
|
||||
desc.DepthFunc = d3d11.COMPARISON_GREATER
|
||||
case backend.DepthFuncGreaterEqual:
|
||||
case driver.DepthFuncGreaterEqual:
|
||||
desc.DepthFunc = d3d11.COMPARISON_GREATER_EQUAL
|
||||
default:
|
||||
panic("unsupported depth func")
|
||||
@@ -519,7 +519,7 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
|
||||
b.ctx.OMSetBlendState(blendState, nil, 0xffffffff)
|
||||
}
|
||||
|
||||
func (b *Backend) DepthFunc(f backend.DepthFunc) {
|
||||
func (b *Backend) DepthFunc(f driver.DepthFunc) {
|
||||
b.depthState.fn = f
|
||||
}
|
||||
|
||||
@@ -535,12 +535,12 @@ func (b *Backend) DepthMask(mask bool) {
|
||||
b.depthState.mask = mask
|
||||
}
|
||||
|
||||
func (b *Backend) BlendFunc(sfactor, dfactor backend.BlendFactor) {
|
||||
func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {
|
||||
b.blendState.sfactor = sfactor
|
||||
b.blendState.dfactor = dfactor
|
||||
}
|
||||
|
||||
func (b *Backend) BindImageTexture(unit int, tex backend.Texture, access backend.AccessBits, f backend.TextureFormat) {
|
||||
func (b *Backend) BindImageTexture(unit int, tex driver.Texture, access driver.AccessBits, f driver.TextureFormat) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@@ -579,13 +579,13 @@ func (t *Texture) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindTexture(unit int, tex backend.Texture) {
|
||||
func (b *Backend) BindTexture(unit int, tex driver.Texture) {
|
||||
t := tex.(*Texture)
|
||||
b.ctx.PSSetSamplers(uint32(unit), t.sampler)
|
||||
b.ctx.PSSetShaderResources(uint32(unit), t.resView)
|
||||
}
|
||||
|
||||
func (b *Backend) BindProgram(prog backend.Program) {
|
||||
func (b *Backend) BindProgram(prog driver.Program) {
|
||||
b.prog = prog.(*Program)
|
||||
}
|
||||
|
||||
@@ -596,23 +596,23 @@ func (p *Program) Release() {
|
||||
p.frag.shader = nil
|
||||
}
|
||||
|
||||
func (p *Program) SetStorageBuffer(binding int, buffer backend.Buffer) {
|
||||
func (p *Program) SetStorageBuffer(binding int, buffer driver.Buffer) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (p *Program) SetVertexUniforms(buf backend.Buffer) {
|
||||
func (p *Program) SetVertexUniforms(buf driver.Buffer) {
|
||||
p.vert.uniforms = buf.(*Buffer)
|
||||
}
|
||||
|
||||
func (p *Program) SetFragmentUniforms(buf backend.Buffer) {
|
||||
func (p *Program) SetFragmentUniforms(buf driver.Buffer) {
|
||||
p.frag.uniforms = buf.(*Buffer)
|
||||
}
|
||||
|
||||
func (b *Backend) BindVertexBuffer(buf backend.Buffer, stride, offset int) {
|
||||
func (b *Backend) BindVertexBuffer(buf driver.Buffer, stride, offset int) {
|
||||
b.ctx.IASetVertexBuffers(buf.(*Buffer).buf, uint32(stride), uint32(offset))
|
||||
}
|
||||
|
||||
func (b *Backend) BindIndexBuffer(buf backend.Buffer) {
|
||||
func (b *Backend) BindIndexBuffer(buf driver.Buffer) {
|
||||
b.ctx.IASetIndexBuffer(buf.(*Buffer).buf, d3d11.DXGI_FORMAT_R16_UINT, 0)
|
||||
}
|
||||
|
||||
@@ -684,7 +684,7 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Backend) BindFramebuffer(fbo backend.Framebuffer) {
|
||||
func (b *Backend) BindFramebuffer(fbo driver.Framebuffer) {
|
||||
b.fbo = fbo.(*Framebuffer)
|
||||
b.ctx.OMSetRenderTargets(b.fbo.renderTarget, b.fbo.depthView)
|
||||
}
|
||||
@@ -706,7 +706,7 @@ func (f *Framebuffer) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) BindInputLayout(layout backend.InputLayout) {
|
||||
func (b *Backend) BindInputLayout(layout driver.InputLayout) {
|
||||
b.ctx.IASetInputLayout(layout.(*InputLayout).layout)
|
||||
}
|
||||
|
||||
@@ -715,35 +715,35 @@ func (l *InputLayout) Release() {
|
||||
l.layout = nil
|
||||
}
|
||||
|
||||
func convBufferBinding(typ backend.BufferBinding) uint32 {
|
||||
func convBufferBinding(typ driver.BufferBinding) uint32 {
|
||||
var bindings uint32
|
||||
if typ&backend.BufferBindingVertices != 0 {
|
||||
if typ&driver.BufferBindingVertices != 0 {
|
||||
bindings |= d3d11.BIND_VERTEX_BUFFER
|
||||
}
|
||||
if typ&backend.BufferBindingIndices != 0 {
|
||||
if typ&driver.BufferBindingIndices != 0 {
|
||||
bindings |= d3d11.BIND_INDEX_BUFFER
|
||||
}
|
||||
if typ&backend.BufferBindingUniforms != 0 {
|
||||
if typ&driver.BufferBindingUniforms != 0 {
|
||||
bindings |= d3d11.BIND_CONSTANT_BUFFER
|
||||
}
|
||||
if typ&backend.BufferBindingTexture != 0 {
|
||||
if typ&driver.BufferBindingTexture != 0 {
|
||||
bindings |= d3d11.BIND_SHADER_RESOURCE
|
||||
}
|
||||
if typ&backend.BufferBindingFramebuffer != 0 {
|
||||
if typ&driver.BufferBindingFramebuffer != 0 {
|
||||
bindings |= d3d11.BIND_RENDER_TARGET
|
||||
}
|
||||
return bindings
|
||||
}
|
||||
|
||||
func toBlendFactor(f backend.BlendFactor) (uint32, uint32) {
|
||||
func toBlendFactor(f driver.BlendFactor) (uint32, uint32) {
|
||||
switch f {
|
||||
case backend.BlendFactorOne:
|
||||
case driver.BlendFactorOne:
|
||||
return d3d11.BLEND_ONE, d3d11.BLEND_ONE
|
||||
case backend.BlendFactorOneMinusSrcAlpha:
|
||||
case driver.BlendFactorOneMinusSrcAlpha:
|
||||
return d3d11.BLEND_INV_SRC_ALPHA, d3d11.BLEND_INV_SRC_ALPHA
|
||||
case backend.BlendFactorZero:
|
||||
case driver.BlendFactorZero:
|
||||
return d3d11.BLEND_ZERO, d3d11.BLEND_ZERO
|
||||
case backend.BlendFactorDstColor:
|
||||
case driver.BlendFactorDstColor:
|
||||
return d3d11.BLEND_DEST_COLOR, d3d11.BLEND_DEST_ALPHA
|
||||
default:
|
||||
panic("unsupported blend source factor")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package backend
|
||||
package driver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -49,7 +49,7 @@ func NewDevice(api API) (Device, error) {
|
||||
return NewDirect3D11Device(api)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("backend: no backend available for the API %T", api)
|
||||
return nil, fmt.Errorf("driver: no driver available for the API %T", api)
|
||||
}
|
||||
|
||||
func (OpenGL) implementsAPI() {}
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package backend
|
||||
package driver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
+35
-35
@@ -12,13 +12,13 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
"gioui.org/internal/f32color"
|
||||
gunsafe "gioui.org/internal/unsafe"
|
||||
)
|
||||
|
||||
type pather struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
|
||||
viewport image.Point
|
||||
|
||||
@@ -27,12 +27,12 @@ type pather struct {
|
||||
}
|
||||
|
||||
type coverer struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
prog [3]*program
|
||||
texUniforms *coverTexUniforms
|
||||
colUniforms *coverColUniforms
|
||||
linearGradientUniforms *coverLinearGradientUniforms
|
||||
layout backend.InputLayout
|
||||
layout driver.InputLayout
|
||||
}
|
||||
|
||||
type coverTexUniforms struct {
|
||||
@@ -71,20 +71,20 @@ type coverUniforms struct {
|
||||
}
|
||||
|
||||
type stenciler struct {
|
||||
ctx backend.Device
|
||||
ctx driver.Device
|
||||
prog struct {
|
||||
prog *program
|
||||
uniforms *stencilUniforms
|
||||
layout backend.InputLayout
|
||||
layout driver.InputLayout
|
||||
}
|
||||
iprog struct {
|
||||
prog *program
|
||||
uniforms *intersectUniforms
|
||||
layout backend.InputLayout
|
||||
layout driver.InputLayout
|
||||
}
|
||||
fbos fboSet
|
||||
intersections fboSet
|
||||
indexBuf backend.Buffer
|
||||
indexBuf driver.Buffer
|
||||
}
|
||||
|
||||
type stencilUniforms struct {
|
||||
@@ -108,13 +108,13 @@ type fboSet struct {
|
||||
|
||||
type stencilFBO struct {
|
||||
size image.Point
|
||||
fbo backend.Framebuffer
|
||||
tex backend.Texture
|
||||
fbo driver.Framebuffer
|
||||
tex driver.Texture
|
||||
}
|
||||
|
||||
type pathData struct {
|
||||
ncurves int
|
||||
data backend.Buffer
|
||||
data driver.Buffer
|
||||
}
|
||||
|
||||
// vertex data suitable for passing to vertex programs.
|
||||
@@ -146,7 +146,7 @@ const (
|
||||
vertStride = 8 * 4
|
||||
)
|
||||
|
||||
func newPather(ctx backend.Device) *pather {
|
||||
func newPather(ctx driver.Device) *pather {
|
||||
return &pather{
|
||||
ctx: ctx,
|
||||
stenciler: newStenciler(ctx),
|
||||
@@ -154,7 +154,7 @@ func newPather(ctx backend.Device) *pather {
|
||||
}
|
||||
}
|
||||
|
||||
func newCoverer(ctx backend.Device) *coverer {
|
||||
func newCoverer(ctx driver.Device) *coverer {
|
||||
c := &coverer{
|
||||
ctx: ctx,
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func newCoverer(ctx backend.Device) *coverer {
|
||||
return c
|
||||
}
|
||||
|
||||
func newStenciler(ctx backend.Device) *stenciler {
|
||||
func newStenciler(ctx driver.Device) *stenciler {
|
||||
// Allocate a suitably large index buffer for drawing paths.
|
||||
indices := make([]uint16, pathBatchSize*6)
|
||||
for i := 0; i < pathBatchSize; i++ {
|
||||
@@ -185,23 +185,23 @@ func newStenciler(ctx backend.Device) *stenciler {
|
||||
indices[i*6+4] = i*4 + 1
|
||||
indices[i*6+5] = i*4 + 3
|
||||
}
|
||||
indexBuf, err := ctx.NewImmutableBuffer(backend.BufferBindingIndices, gunsafe.BytesView(indices))
|
||||
indexBuf, err := ctx.NewImmutableBuffer(driver.BufferBindingIndices, gunsafe.BytesView(indices))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
progLayout, err := ctx.NewInputLayout(shader_stencil_vert, []backend.InputDesc{
|
||||
{Type: backend.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).Corner))},
|
||||
{Type: backend.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).MaxY))},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).FromX))},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).CtrlX))},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).ToX))},
|
||||
progLayout, err := ctx.NewInputLayout(shader_stencil_vert, []driver.InputDesc{
|
||||
{Type: driver.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).Corner))},
|
||||
{Type: driver.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).MaxY))},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).FromX))},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).CtrlX))},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).ToX))},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
iprogLayout, err := ctx.NewInputLayout(shader_intersect_vert, []backend.InputDesc{
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
iprogLayout, err := ctx.NewInputLayout(shader_intersect_vert, []driver.InputDesc{
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 0},
|
||||
{Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -229,7 +229,7 @@ func newStenciler(ctx backend.Device) *stenciler {
|
||||
return st
|
||||
}
|
||||
|
||||
func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) {
|
||||
func (s *fboSet) resize(ctx driver.Device, sizes []image.Point) {
|
||||
// Add fbos.
|
||||
for i := len(s.fbos); i < len(sizes); i++ {
|
||||
s.fbos = append(s.fbos, stencilFBO{})
|
||||
@@ -247,8 +247,8 @@ func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) {
|
||||
f.fbo.Release()
|
||||
f.tex.Release()
|
||||
}
|
||||
tex, err := ctx.NewTexture(backend.TextureFormatFloat, sz.X, sz.Y, backend.FilterNearest, backend.FilterNearest,
|
||||
backend.BufferBindingTexture|backend.BufferBindingFramebuffer)
|
||||
tex, err := ctx.NewTexture(driver.TextureFormatFloat, sz.X, sz.Y, driver.FilterNearest, driver.FilterNearest,
|
||||
driver.BufferBindingTexture|driver.BufferBindingFramebuffer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -265,13 +265,13 @@ func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) {
|
||||
s.delete(ctx, len(sizes))
|
||||
}
|
||||
|
||||
func (s *fboSet) invalidate(ctx backend.Device) {
|
||||
func (s *fboSet) invalidate(ctx driver.Device) {
|
||||
for _, f := range s.fbos {
|
||||
f.fbo.Invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *fboSet) delete(ctx backend.Device, idx int) {
|
||||
func (s *fboSet) delete(ctx driver.Device, idx int) {
|
||||
for i := idx; i < len(s.fbos); i++ {
|
||||
f := s.fbos[i]
|
||||
f.fbo.Release()
|
||||
@@ -301,8 +301,8 @@ func (c *coverer) release() {
|
||||
c.layout.Release()
|
||||
}
|
||||
|
||||
func buildPath(ctx backend.Device, p []byte) pathData {
|
||||
buf, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices, p)
|
||||
func buildPath(ctx driver.Device, p []byte) pathData {
|
||||
buf, err := ctx.NewImmutableBuffer(driver.BufferBindingVertices, p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (p *pather) stencilPath(bounds image.Rectangle, offset f32.Point, uv image.
|
||||
}
|
||||
|
||||
func (s *stenciler) beginIntersect(sizes []image.Point) {
|
||||
s.ctx.BlendFunc(backend.BlendFactorDstColor, backend.BlendFactorZero)
|
||||
s.ctx.BlendFunc(driver.BlendFactorDstColor, driver.BlendFactorZero)
|
||||
// 8 bit coverage is enough, but OpenGL ES only supports single channel
|
||||
// floating point formats. Replace with GL_RGB+GL_UNSIGNED_BYTE if
|
||||
// no floating point support is available.
|
||||
@@ -343,7 +343,7 @@ func (s *stenciler) cover(idx int) stencilFBO {
|
||||
}
|
||||
|
||||
func (s *stenciler) begin(sizes []image.Point) {
|
||||
s.ctx.BlendFunc(backend.BlendFactorOne, backend.BlendFactorOne)
|
||||
s.ctx.BlendFunc(driver.BlendFactorOne, driver.BlendFactorOne)
|
||||
s.fbos.resize(s.ctx, sizes)
|
||||
s.ctx.BindProgram(s.prog.prog.prog)
|
||||
s.ctx.BindInputLayout(s.prog.layout)
|
||||
@@ -369,7 +369,7 @@ func (s *stenciler) stencilPath(bounds image.Rectangle, offset f32.Point, uv ima
|
||||
}
|
||||
off := vertStride * start * 4
|
||||
s.ctx.BindVertexBuffer(data.data, vertStride, off)
|
||||
s.ctx.DrawElements(backend.DrawModeTriangles, 0, batch*6)
|
||||
s.ctx.DrawElements(driver.DrawModeTriangles, 0, batch*6)
|
||||
start += batch
|
||||
}
|
||||
}
|
||||
@@ -404,7 +404,7 @@ func (c *coverer) cover(z float32, mat materialType, col f32color.RGBA, col1, co
|
||||
uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
|
||||
uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y}
|
||||
p.UploadUniforms()
|
||||
c.ctx.DrawArrays(backend.DrawModeTriangleStrip, 0, 4)
|
||||
c.ctx.DrawArrays(driver.DrawModeTriangleStrip, 0, 4)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
+56
-56
File diff suppressed because one or more lines are too long
+5
-5
@@ -5,18 +5,18 @@ package gpu
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/gpu/internal/driver"
|
||||
)
|
||||
|
||||
type timers struct {
|
||||
backend backend.Device
|
||||
backend driver.Device
|
||||
timers []*timer
|
||||
}
|
||||
|
||||
type timer struct {
|
||||
Elapsed time.Duration
|
||||
backend backend.Device
|
||||
timer backend.Timer
|
||||
backend driver.Device
|
||||
timer driver.Timer
|
||||
state timerState
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ const (
|
||||
timerWaiting
|
||||
)
|
||||
|
||||
func newTimers(b backend.Device) *timers {
|
||||
func newTimers(b driver.Device) *timers {
|
||||
return &timers{
|
||||
backend: b,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user