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:
Elias Naur
2021-03-06 10:21:08 +01:00
parent 2c7aba9e7c
commit c799452c57
15 changed files with 379 additions and 379 deletions
+4 -4
View File
@@ -2,14 +2,14 @@
package gpu 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. // 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. // 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. // OpenGL denotes the OpenGL or OpenGL ES API.
type OpenGL = backend.OpenGL type OpenGL = driver.OpenGL
// Direct3D11 denotes the Direct3D API. // Direct3D11 denotes the Direct3D API.
type Direct3D11 = backend.Direct3D11 type Direct3D11 = driver.Direct3D11
+44 -44
View File
@@ -14,7 +14,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
gunsafe "gioui.org/internal/unsafe" gunsafe "gioui.org/internal/unsafe"
"gioui.org/layout" "gioui.org/layout"
@@ -22,7 +22,7 @@ import (
) )
type compute struct { type compute struct {
ctx backend.Device ctx driver.Device
enc encoder enc encoder
drawOps drawOps drawOps drawOps
@@ -30,16 +30,16 @@ type compute struct {
maxTextureDim int maxTextureDim int
programs struct { programs struct {
elements backend.Program elements driver.Program
tileAlloc backend.Program tileAlloc driver.Program
pathCoarse backend.Program pathCoarse driver.Program
backdrop backend.Program backdrop driver.Program
binning backend.Program binning driver.Program
coarse backend.Program coarse driver.Program
kernel4 backend.Program kernel4 driver.Program
} }
buffers struct { buffers struct {
config backend.Buffer config driver.Buffer
scene sizedBuffer scene sizedBuffer
state sizedBuffer state sizedBuffer
memory sizedBuffer memory sizedBuffer
@@ -48,32 +48,32 @@ type compute struct {
size image.Point size image.Point
// image is the output texture. Note that it is in RGBA format, // image is the output texture. Note that it is in RGBA format,
// but contains data in sRGB. See blitOutput for more detail. // but contains data in sRGB. See blitOutput for more detail.
image backend.Texture image driver.Texture
blitProg backend.Program blitProg driver.Program
} }
// images contains ImageOp images packed into a texture atlas. // images contains ImageOp images packed into a texture atlas.
images struct { images struct {
packer packer packer packer
// positions maps imageOpData.handles to positions inside tex. // positions maps imageOpData.handles to positions inside tex.
positions map[interface{}]image.Point positions map[interface{}]image.Point
tex backend.Texture tex driver.Texture
} }
// materials contains the pre-processed materials (transformed images for // materials contains the pre-processed materials (transformed images for
// now, gradients etc. later) packed in a texture atlas. The atlas is used // now, gradients etc. later) packed in a texture atlas. The atlas is used
// as source in kernel4. // as source in kernel4.
materials struct { materials struct {
prog backend.Program prog driver.Program
layout backend.InputLayout layout driver.InputLayout
packer packer packer packer
texSize image.Point texSize image.Point
tex backend.Texture tex driver.Texture
fbo backend.Framebuffer fbo driver.Framebuffer
quads []materialVertex quads []materialVertex
bufSize int bufSize int
buffer backend.Buffer buffer driver.Buffer
} }
timers struct { timers struct {
profile string profile string
@@ -112,7 +112,7 @@ type encodeState struct {
type sizedBuffer struct { type sizedBuffer struct {
size int size int
buffer backend.Buffer buffer driver.Buffer
} }
// config matches Config in setup.h // config matches Config in setup.h
@@ -187,7 +187,7 @@ const (
memMallocFailed = 1 // ERR_MALLOC_FAILED memMallocFailed = 1 // ERR_MALLOC_FAILED
) )
func newCompute(ctx backend.Device) (*compute, error) { func newCompute(ctx driver.Device) (*compute, error) {
maxDim := ctx.Caps().MaxTextureSize maxDim := ctx.Caps().MaxTextureSize
// Large atlas textures cause artifacts due to precision loss in // Large atlas textures cause artifacts due to precision loss in
// shaders. // shaders.
@@ -215,9 +215,9 @@ func newCompute(ctx backend.Device) (*compute, error) {
return nil, err return nil, err
} }
g.materials.prog = materialProg g.materials.prog = materialProg
progLayout, err := ctx.NewInputLayout(shader_material_vert, []backend.InputDesc{ progLayout, err := ctx.NewInputLayout(shader_material_vert, []driver.InputDesc{
{Type: backend.DataTypeFloat, Size: 2, Offset: 0}, {Type: driver.DataTypeFloat, Size: 2, Offset: 0},
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2}, {Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
}) })
if err != nil { if err != nil {
g.Release() g.Release()
@@ -228,7 +228,7 @@ func newCompute(ctx backend.Device) (*compute, error) {
g.drawOps.pathCache = newOpCache() g.drawOps.pathCache = newOpCache()
g.drawOps.retainPathData = true 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 { if err != nil {
g.Release() g.Release()
return nil, err return nil, err
@@ -236,8 +236,8 @@ func newCompute(ctx backend.Device) (*compute, error) {
g.buffers.config = buf g.buffers.config = buf
shaders := []struct { shaders := []struct {
prog *backend.Program prog *driver.Program
src backend.ShaderSources src driver.ShaderSources
}{ }{
{&g.programs.elements, shader_elements_comp}, {&g.programs.elements, shader_elements_comp},
{&g.programs.tileAlloc, shader_tile_alloc_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 { for _, img := range g.drawOps.allImageOps {
expandPathOp(img.path, img.clip) 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 := &g.timers
t.t = newTimers(g.ctx) t.t = newTimers(g.ctx)
t.elements = g.timers.t.newTimer() 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.Viewport(0, 0, viewport.X, viewport.Y)
g.ctx.BindTexture(0, g.output.image) g.ctx.BindTexture(0, g.output.image)
g.ctx.BindProgram(g.output.blitProg) 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 { func (g *compute) encode(viewport image.Point) error {
@@ -414,7 +414,7 @@ restart:
a.tex = nil a.tex = nil
} }
sz := a.packer.maxDim 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 { if err != nil {
return fmt.Errorf("compute: failed to create image atlas: %v", err) return fmt.Errorf("compute: failed to create image atlas: %v", err)
} }
@@ -426,7 +426,7 @@ restart:
panic("compute: internal error: image not placed") panic("compute: internal error: image not placed")
} }
size := img.Bounds().Size() size := img.Bounds().Size()
backend.UploadImage(a.tex, pos, img) driver.UploadImage(a.tex, pos, img)
rightPadding := image.Pt(padding, size.Y) 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)) 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) 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. // Round to nearest power of 2 while we're doing an expensive recreation anyway.
sz := image.Pt(pow2Ceil(outSize.X), pow2Ceil(outSize.Y)) sz := image.Pt(pow2Ceil(outSize.X), pow2Ceil(outSize.Y))
m.texSize = sz 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 { if err != nil {
return fmt.Errorf("compute: failed to create material atlas: %v", err) return fmt.Errorf("compute: failed to create material atlas: %v", err)
} }
@@ -480,7 +480,7 @@ func (g *compute) renderMaterials() error {
} }
// Ditto. // Ditto.
n := pow2Ceil(len(vertexData)) n := pow2Ceil(len(vertexData))
buf, err := g.ctx.NewBuffer(backend.BufferBindingVertices, n) buf, err := g.ctx.NewBuffer(driver.BufferBindingVertices, n)
if err != nil { if err != nil {
return err return err
} }
@@ -495,7 +495,7 @@ func (g *compute) renderMaterials() error {
g.ctx.BindProgram(m.prog) g.ctx.BindProgram(m.prog)
g.ctx.BindVertexBuffer(m.buffer, int(unsafe.Sizeof(m.quads[0])), 0) g.ctx.BindVertexBuffer(m.buffer, int(unsafe.Sizeof(m.quads[0])), 0)
g.ctx.BindInputLayout(m.layout) 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 return nil
} }
@@ -719,9 +719,9 @@ func (g *compute) render(tileDims image.Point) error {
return err 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 { 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. // 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() t.kernel4.end()
if err := g.buffers.memory.buffer.Download(gunsafe.StructView(g.memHeader)); err != nil { if err := g.buffers.memory.buffer.Download(gunsafe.StructView(g.memHeader)); err != nil {
if err == backend.ErrContentLost { if err == driver.ErrContentLost {
continue continue
} }
return err return err
@@ -854,10 +854,10 @@ func (g *compute) resizeOutput(size image.Point) error {
g.output.image.Release() g.output.image.Release()
g.output.image = nil g.output.image = nil
} }
img, err := g.ctx.NewTexture(backend.TextureFormatRGBA8, size.X, size.Y, img, err := g.ctx.NewTexture(driver.TextureFormatRGBA8, size.X, size.Y,
backend.FilterNearest, driver.FilterNearest,
backend.FilterNearest, driver.FilterNearest,
backend.BufferBindingShaderStorage|backend.BufferBindingTexture) driver.BufferBindingShaderStorage|driver.BufferBindingTexture)
if err != nil { if err != nil {
return err return err
} }
@@ -873,7 +873,7 @@ func (g *compute) Release() {
if g.cache != nil { if g.cache != nil {
g.cache.release() g.cache.release()
} }
progs := []backend.Program{ progs := []driver.Program{
g.programs.elements, g.programs.elements,
g.programs.tileAlloc, g.programs.tileAlloc,
g.programs.pathCoarse, g.programs.pathCoarse,
@@ -942,14 +942,14 @@ func (b *sizedBuffer) release() {
*b = sizedBuffer{} *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 { if b.size >= size {
return nil return nil
} }
if b.buffer != nil { if b.buffer != nil {
b.release() b.release()
} }
buf, err := ctx.NewBuffer(backend.BufferBindingShaderStorage, size) buf, err := ctx.NewBuffer(driver.BufferBindingShaderStorage, size)
if err != nil { if err != nil {
return err return err
} }
@@ -958,7 +958,7 @@ func (b *sizedBuffer) ensureCapacity(ctx backend.Device, size int) error {
return nil return nil
} }
func bindStorageBuffers(prog backend.Program, buffers ...backend.Buffer) { func bindStorageBuffers(prog driver.Program, buffers ...driver.Buffer) {
for i, buf := range buffers { for i, buf := range buffers {
prog.SetStorageBuffer(i, buf) prog.SetStorageBuffer(i, buf)
} }
+78 -78
View File
@@ -10,11 +10,11 @@ import (
"time" "time"
"unsafe" "unsafe"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/glimpl" "gioui.org/internal/glimpl"
) )
// Backend implements backend.Device. // Backend implements driver.Device.
type Backend struct { type Backend struct {
funcs *glimpl.Functions funcs *glimpl.Functions
@@ -23,7 +23,7 @@ type Backend struct {
glver [2]int glver [2]int
gles bool gles bool
ubo bool ubo bool
feats backend.Caps feats driver.Caps
// floatTriple holds the settings for floating point // floatTriple holds the settings for floating point
// textures. // textures.
floatTriple textureTriple floatTriple textureTriple
@@ -73,7 +73,7 @@ type gpuBuffer struct {
backend *Backend backend *Backend
hasBuffer bool hasBuffer bool
obj glimpl.Buffer obj glimpl.Buffer
typ backend.BufferBinding typ driver.BufferBinding
size int size int
immutable bool immutable bool
version int version int
@@ -100,13 +100,13 @@ type uniformsTracker struct {
type uniformLocation struct { type uniformLocation struct {
uniform glimpl.Uniform uniform glimpl.Uniform
offset int offset int
typ backend.DataType typ driver.DataType
size int size int
} }
type gpuInputLayout struct { type gpuInputLayout struct {
inputs []backend.InputLocation inputs []driver.InputLocation
layout []backend.InputDesc layout []driver.InputDesc
} }
// textureTriple holds the type settings for // textureTriple holds the type settings for
@@ -124,10 +124,10 @@ const (
) )
func init() { 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) f, err := glimpl.NewFunctions(api.Context)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -155,19 +155,19 @@ func newOpenGLDevice(api backend.OpenGL) (backend.Device, error) {
srgbaTriple: srgbaTriple, srgbaTriple: srgbaTriple,
} }
if ffboErr == nil { if ffboErr == nil {
b.feats.Features |= backend.FeatureFloatRenderTargets b.feats.Features |= driver.FeatureFloatRenderTargets
} }
if gles31 { 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") { 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) b.feats.MaxTextureSize = f.GetInteger(glimpl.MAX_TEXTURE_SIZE)
return b, nil return b, nil
} }
func (b *Backend) BeginFrame() backend.Framebuffer { func (b *Backend) BeginFrame() driver.Framebuffer {
// Assume GL state is reset between frames. // Assume GL state is reset between frames.
b.state = glstate{} b.state = glstate{}
fboID := glimpl.Framebuffer(b.funcs.GetBinding(glimpl.FRAMEBUFFER_BINDING)) fboID := glimpl.Framebuffer(b.funcs.GetBinding(glimpl.FRAMEBUFFER_BINDING))
@@ -178,11 +178,11 @@ func (b *Backend) EndFrame() {
b.funcs.ActiveTexture(glimpl.TEXTURE0) b.funcs.ActiveTexture(glimpl.TEXTURE0)
} }
func (b *Backend) Caps() backend.Caps { func (b *Backend) Caps() driver.Caps {
return b.feats return b.feats
} }
func (b *Backend) NewTimer() backend.Timer { func (b *Backend) NewTimer() driver.Timer {
return &gpuTimer{ return &gpuTimer{
funcs: b.funcs, funcs: b.funcs,
obj: b.funcs.CreateQuery(), obj: b.funcs.CreateQuery(),
@@ -193,7 +193,7 @@ func (b *Backend) IsTimeContinuous() bool {
return b.funcs.GetInteger(glimpl.GPU_DISJOINT_EXT) == glimpl.FALSE 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) glErr(b.funcs)
gltex := tex.(*gpuTexture) gltex := tex.(*gpuTexture)
fb := b.funcs.CreateFramebuffer() fb := b.funcs.CreateFramebuffer()
@@ -230,15 +230,15 @@ func (b *Backend) NewFramebuffer(tex backend.Texture, depthBits int) (backend.Fr
return fbo, nil 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) glErr(b.funcs)
tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture(), width: width, height: height} tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture(), width: width, height: height}
switch format { switch format {
case backend.TextureFormatFloat: case driver.TextureFormatFloat:
tex.triple = b.floatTriple tex.triple = b.floatTriple
case backend.TextureFormatSRGB: case driver.TextureFormatSRGB:
tex.triple = b.srgbaTriple tex.triple = b.srgbaTriple
case backend.TextureFormatRGBA8: case driver.TextureFormatRGBA8:
tex.triple = textureTriple{glimpl.RGBA8, glimpl.RGBA, glimpl.UNSIGNED_BYTE} tex.triple = textureTriple{glimpl.RGBA8, glimpl.RGBA, glimpl.UNSIGNED_BYTE}
default: default:
return nil, errors.New("unsupported texture format") 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 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) glErr(b.funcs)
buf := &gpuBuffer{backend: b, typ: typ, size: size} buf := &gpuBuffer{backend: b, typ: typ, size: size}
if typ&backend.BufferBindingUniforms != 0 { if typ&driver.BufferBindingUniforms != 0 {
if typ != backend.BufferBindingUniforms { if typ != driver.BufferBindingUniforms {
return nil, errors.New("uniforms buffers cannot be bound as anything else") return nil, errors.New("uniforms buffers cannot be bound as anything else")
} }
if !b.ubo { if !b.ubo {
@@ -273,7 +273,7 @@ func (b *Backend) NewBuffer(typ backend.BufferBinding, size int) (backend.Buffer
buf.data = make([]byte, size) buf.data = make([]byte, size)
} }
} }
if typ&^backend.BufferBindingUniforms != 0 || b.ubo { if typ&^driver.BufferBindingUniforms != 0 || b.ubo {
buf.hasBuffer = true buf.hasBuffer = true
buf.obj = b.funcs.CreateBuffer() buf.obj = b.funcs.CreateBuffer()
if err := glErr(b.funcs); err != nil { 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 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) glErr(b.funcs)
obj := b.funcs.CreateBuffer() obj := b.funcs.CreateBuffer()
buf := &gpuBuffer{backend: b, obj: obj, typ: typ, size: len(data), hasBuffer: true} 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) 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) t := tex.(*gpuTexture)
var acc glimpl.Enum var acc glimpl.Enum
switch access { switch access {
case backend.AccessWrite: case driver.AccessWrite:
acc = glimpl.WRITE_ONLY acc = glimpl.WRITE_ONLY
case backend.AccessRead: case driver.AccessRead:
acc = glimpl.READ_ONLY acc = glimpl.READ_ONLY
default: default:
panic("unsupported access bits") panic("unsupported access bits")
} }
var format glimpl.Enum var format glimpl.Enum
switch f { switch f {
case backend.TextureFormatRGBA8: case driver.TextureFormatRGBA8:
format = glimpl.RGBA8 format = glimpl.RGBA8
default: default:
panic("unsupported format") 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)) b.funcs.BlendFunc(toGLBlendFactor(sfactor), toGLBlendFactor(dfactor))
} }
func toGLBlendFactor(f backend.BlendFactor) glimpl.Enum { func toGLBlendFactor(f driver.BlendFactor) glimpl.Enum {
switch f { switch f {
case backend.BlendFactorOne: case driver.BlendFactorOne:
return glimpl.ONE return glimpl.ONE
case backend.BlendFactorOneMinusSrcAlpha: case driver.BlendFactorOneMinusSrcAlpha:
return glimpl.ONE_MINUS_SRC_ALPHA return glimpl.ONE_MINUS_SRC_ALPHA
case backend.BlendFactorZero: case driver.BlendFactorZero:
return glimpl.ZERO return glimpl.ZERO
case backend.BlendFactorDstColor: case driver.BlendFactorDstColor:
return glimpl.DST_COLOR return glimpl.DST_COLOR
default: default:
panic("unsupported blend factor") 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() b.prepareDraw()
// off is in 16-bit indices, but DrawElements take a byte offset. // off is in 16-bit indices, but DrawElements take a byte offset.
byteOff := off * 2 byteOff := off * 2
b.funcs.DrawElements(toGLDrawMode(mode), count, glimpl.UNSIGNED_SHORT, byteOff) 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.prepareDraw()
b.funcs.DrawArrays(toGLDrawMode(mode), off, count) 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 { switch mode {
case backend.DrawModeTriangleStrip: case driver.DrawModeTriangleStrip:
return glimpl.TRIANGLE_STRIP return glimpl.TRIANGLE_STRIP
case backend.DrawModeTriangles: case driver.DrawModeTriangles:
return glimpl.TRIANGLES return glimpl.TRIANGLES
default: default:
panic("unsupported draw mode") panic("unsupported draw mode")
@@ -463,12 +463,12 @@ func (b *Backend) ClearDepth(d float32) {
b.funcs.Clear(glimpl.DEPTH_BUFFER_BIT) 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 var glfunc glimpl.Enum
switch f { switch f {
case backend.DepthFuncGreater: case driver.DepthFuncGreater:
glfunc = glimpl.GREATER glfunc = glimpl.GREATER
case backend.DepthFuncGreaterEqual: case driver.DepthFuncGreaterEqual:
glfunc = glimpl.GEQUAL glfunc = glimpl.GEQUAL
default: default:
panic("unsupported depth func") panic("unsupported depth func")
@@ -476,7 +476,7 @@ func (b *Backend) DepthFunc(f backend.DepthFunc) {
b.funcs.DepthFunc(glfunc) 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) { if len(vs.Inputs) != len(layout) {
return nil, fmt.Errorf("NewInputLayout: got %d inputs, expected %d", len(layout), len(vs.Inputs)) 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 }, 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) p, err := glimpl.CreateComputeProgram(b.funcs, src.GLSL310ES)
if err != nil { if err != nil {
return nil, fmt.Errorf("%s: %v", src.Name, err) 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 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)) attr := make([]string, len(vertShader.Inputs))
for _, inp := range vertShader.Inputs { for _, inp := range vertShader.Inputs {
attr[inp.Location] = inp.Name attr[inp.Location] = inp.Name
@@ -568,24 +568,24 @@ func (b *Backend) NewProgram(vertShader, fragShader backend.ShaderSources) (back
return gpuProg, nil 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) u := funcs.GetUniformLocation(p, loc.Name)
return uniformLocation{uniform: u, offset: loc.Offset, typ: loc.Type, size: loc.Size} 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) buf := buffer.(*gpuBuffer)
if buf.typ&backend.BufferBindingShaderStorage == 0 { if buf.typ&driver.BufferBindingShaderStorage == 0 {
panic("not a shader storage buffer") panic("not a shader storage buffer")
} }
p.storage[binding] = buf p.storage[binding] = buf
} }
func (p *gpuProgram) SetVertexUniforms(buffer backend.Buffer) { func (p *gpuProgram) SetVertexUniforms(buffer driver.Buffer) {
p.vertUniforms.setBuffer(buffer) p.vertUniforms.setBuffer(buffer)
} }
func (p *gpuProgram) SetFragmentUniforms(buffer backend.Buffer) { func (p *gpuProgram) SetFragmentUniforms(buffer driver.Buffer) {
p.fragUniforms.setBuffer(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) p := prog.(*gpuProgram)
b.useProgram(p) b.useProgram(p)
} }
@@ -613,7 +613,7 @@ func (p *gpuProgram) Release() {
p.backend.funcs.DeleteProgram(p.obj) 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)) u.locs = make([]uniformLocation, len(uniforms))
for i, uniform := range uniforms { for i, uniform := range uniforms {
u.locs[i] = lookupUniform(funcs, p, uniform) 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 u.size = uniformSize
} }
func (u *uniformsTracker) setBuffer(buffer backend.Buffer) { func (u *uniformsTracker) setBuffer(buffer driver.Buffer) {
buf := buffer.(*gpuBuffer) buf := buffer.(*gpuBuffer)
if buf.typ&backend.BufferBindingUniforms == 0 { if buf.typ&driver.BufferBindingUniforms == 0 {
panic("not a uniform buffer") panic("not a uniform buffer")
} }
if buf.size < u.size { if buf.size < u.size {
@@ -644,19 +644,19 @@ func (p *uniformsTracker) update(funcs *glimpl.Functions) {
for _, u := range p.locs { for _, u := range p.locs {
data := data[u.offset:] data := data[u.offset:]
switch { switch {
case u.typ == backend.DataTypeFloat && u.size == 1: case u.typ == driver.DataTypeFloat && u.size == 1:
data := data[:4] data := data[:4]
v := *(*[1]float32)(unsafe.Pointer(&data[0])) v := *(*[1]float32)(unsafe.Pointer(&data[0]))
funcs.Uniform1f(u.uniform, v[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] data := data[:8]
v := *(*[2]float32)(unsafe.Pointer(&data[0])) v := *(*[2]float32)(unsafe.Pointer(&data[0]))
funcs.Uniform2f(u.uniform, v[0], v[1]) 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] data := data[:12]
v := *(*[3]float32)(unsafe.Pointer(&data[0])) v := *(*[3]float32)(unsafe.Pointer(&data[0]))
funcs.Uniform3f(u.uniform, v[0], v[1], v[2]) 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] data := data[:16]
v := *(*[4]float32)(unsafe.Pointer(&data[0])) v := *(*[4]float32)(unsafe.Pointer(&data[0]))
funcs.Uniform4f(u.uniform, v[0], v[1], v[2], v[3]) 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) copy(data, bufferMap)
if !b.backend.funcs.UnmapBuffer(firstBinding) { if !b.backend.funcs.UnmapBuffer(firstBinding) {
return backend.ErrContentLost return driver.ErrContentLost
} }
return nil 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) gbuf := buf.(*gpuBuffer)
if gbuf.typ&backend.BufferBindingVertices == 0 { if gbuf.typ&driver.BufferBindingVertices == 0 {
panic("not a vertex buffer") panic("not a vertex buffer")
} }
b.state.buffer = bufferBinding{buf: gbuf, stride: stride, offset: offset} b.state.buffer = bufferBinding{buf: gbuf, stride: stride, offset: offset}
@@ -735,9 +735,9 @@ func (b *Backend) setupVertexArrays() {
l := layout.layout[i] l := layout.layout[i]
var gltyp glimpl.Enum var gltyp glimpl.Enum
switch l.Type { switch l.Type {
case backend.DataTypeFloat: case driver.DataTypeFloat:
gltyp = glimpl.FLOAT gltyp = glimpl.FLOAT
case backend.DataTypeShort: case driver.DataTypeShort:
gltyp = glimpl.SHORT gltyp = glimpl.SHORT
default: default:
panic("unsupported data type") 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) gbuf := buf.(*gpuBuffer)
if gbuf.typ&backend.BufferBindingIndices == 0 { if gbuf.typ&driver.BufferBindingIndices == 0 {
panic("not an index buffer") panic("not an index buffer")
} }
b.funcs.BindBuffer(glimpl.ELEMENT_ARRAY_BUFFER, gbuf.obj) 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.DRAW_FRAMEBUFFER, dst.(*gpuFramebuffer).obj)
b.funcs.BindFramebuffer(glimpl.READ_FRAMEBUFFER, src.(*gpuFramebuffer).obj) b.funcs.BindFramebuffer(glimpl.READ_FRAMEBUFFER, src.(*gpuFramebuffer).obj)
b.funcs.BlitFramebuffer( 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) 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 { switch f {
case backend.FilterNearest: case driver.FilterNearest:
return glimpl.NEAREST return glimpl.NEAREST
case backend.FilterLinear: case driver.FilterLinear:
return glimpl.LINEAR return glimpl.LINEAR
default: default:
panic("unsupported texture filter") 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)) b.bindTexture(unit, t.(*gpuTexture))
} }
@@ -861,7 +861,7 @@ func (t *gpuTimer) Duration() (time.Duration, bool) {
return time.Duration(nanos), true return time.Duration(nanos), true
} }
func (b *Backend) BindInputLayout(l backend.InputLayout) { func (b *Backend) BindInputLayout(l driver.InputLayout) {
b.state.layout = l.(*gpuInputLayout) b.state.layout = l.(*gpuInputLayout)
} }
@@ -941,15 +941,15 @@ func hasExtension(exts []string, ext string) bool {
return false return false
} }
func firstBufferType(typ backend.BufferBinding) glimpl.Enum { func firstBufferType(typ driver.BufferBinding) glimpl.Enum {
switch { switch {
case typ&backend.BufferBindingIndices != 0: case typ&driver.BufferBindingIndices != 0:
return glimpl.ELEMENT_ARRAY_BUFFER return glimpl.ELEMENT_ARRAY_BUFFER
case typ&backend.BufferBindingVertices != 0: case typ&driver.BufferBindingVertices != 0:
return glimpl.ARRAY_BUFFER return glimpl.ARRAY_BUFFER
case typ&backend.BufferBindingUniforms != 0: case typ&driver.BufferBindingUniforms != 0:
return glimpl.UNIFORM_BUFFER return glimpl.UNIFORM_BUFFER
case typ&backend.BufferBindingShaderStorage != 0: case typ&driver.BufferBindingShaderStorage != 0:
return glimpl.SHADER_STORAGE_BUFFER return glimpl.SHADER_STORAGE_BUFFER
default: default:
panic("unsupported buffer type") panic("unsupported buffer type")
+34 -34
View File
@@ -20,7 +20,7 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
"gioui.org/internal/opconst" "gioui.org/internal/opconst"
"gioui.org/internal/ops" "gioui.org/internal/ops"
@@ -57,12 +57,12 @@ type gpu struct {
frameStart time.Time frameStart time.Time
zopsTimer, stencilTimer, coverTimer, cleanupTimer *timer zopsTimer, stencilTimer, coverTimer, cleanupTimer *timer
drawOps drawOps drawOps drawOps
ctx backend.Device ctx driver.Device
renderer *renderer renderer *renderer
} }
type renderer struct { type renderer struct {
ctx backend.Device ctx driver.Device
blitter *blitter blitter *blitter
pather *pather pather *pather
packer packer packer packer
@@ -302,18 +302,18 @@ type resource interface {
type texture struct { type texture struct {
src *image.RGBA src *image.RGBA
tex backend.Texture tex driver.Texture
} }
type blitter struct { type blitter struct {
ctx backend.Device ctx driver.Device
viewport image.Point viewport image.Point
prog [3]*program prog [3]*program
layout backend.InputLayout layout driver.InputLayout
colUniforms *blitColUniforms colUniforms *blitColUniforms
texUniforms *blitTexUniforms texUniforms *blitTexUniforms
linearGradientUniforms *blitLinearGradientUniforms linearGradientUniforms *blitLinearGradientUniforms
quadVerts backend.Buffer quadVerts driver.Buffer
} }
type blitColUniforms struct { type blitColUniforms struct {
@@ -344,12 +344,12 @@ type blitLinearGradientUniforms struct {
} }
type uniformBuffer struct { type uniformBuffer struct {
buf backend.Buffer buf driver.Buffer
ptr []byte ptr []byte
} }
type program struct { type program struct {
prog backend.Program prog driver.Program
vertUniforms *uniformBuffer vertUniforms *uniformBuffer
fragUniforms *uniformBuffer fragUniforms *uniformBuffer
} }
@@ -385,23 +385,23 @@ const (
) )
func New(api API) (GPU, error) { func New(api API) (GPU, error) {
d, err := backend.NewDevice(api) d, err := driver.NewDevice(api)
if err != nil { if err != nil {
return nil, err return nil, err
} }
forceCompute := os.Getenv("GIORENDERER") == "forcecompute" forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
feats := d.Caps().Features feats := d.Caps().Features
switch { switch {
case !forceCompute && feats.Has(backend.FeatureFloatRenderTargets): case !forceCompute && feats.Has(driver.FeatureFloatRenderTargets):
return newGPU(d) return newGPU(d)
case feats.Has(backend.FeatureCompute): case feats.Has(driver.FeatureCompute):
return newCompute(d) return newCompute(d)
default: default:
return nil, errors.New("gpu: no support for float render targets nor compute") 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{ g := &gpu{
cache: newResourceCache(), cache: newResourceCache(),
} }
@@ -412,7 +412,7 @@ func newGPU(ctx backend.Device) (*gpu, error) {
return g, nil return g, nil
} }
func (g *gpu) init(ctx backend.Device) error { func (g *gpu) init(ctx driver.Device) error {
g.ctx = ctx g.ctx = ctx
g.renderer = newRenderer(ctx) g.renderer = newRenderer(ctx)
return nil return nil
@@ -439,7 +439,7 @@ func (g *gpu) Collect(viewport image.Point, frameOps *op.Ops) {
g.drawOps.reset(g.cache, viewport) g.drawOps.reset(g.cache, viewport)
g.drawOps.collect(g.ctx, g.cache, frameOps, viewport) g.drawOps.collect(g.ctx, g.cache, frameOps, viewport)
g.frameStart = time.Now() 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.timers = newTimers(g.ctx)
g.zopsTimer = g.timers.newTimer() g.zopsTimer = g.timers.newTimer()
g.stencilTimer = g.timers.newTimer() g.stencilTimer = g.timers.newTimer()
@@ -459,7 +459,7 @@ func (g *gpu) Frame() error {
g.zopsTimer.begin() g.zopsTimer.begin()
} }
g.ctx.BindFramebuffer(defFBO) 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 // 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. // (len(zimageOps) == 0). If not, the Fairphone 2 will corrupt the depth buffer.
if g.drawOps.clear { if g.drawOps.clear {
@@ -505,7 +505,7 @@ func (g *gpu) Profile() string {
return g.profile 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 var tex *texture
t, exists := cache.get(data.handle) t, exists := cache.get(data.handle)
if !exists { if !exists {
@@ -518,11 +518,11 @@ func (r *renderer) texHandle(cache *resourceCache, data imageOpData) backend.Tex
if tex.tex != nil { if tex.tex != nil {
return tex.tex 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 { if err != nil {
panic(err) panic(err)
} }
backend.UploadImage(handle, image.Pt(0, 0), data.src) driver.UploadImage(handle, image.Pt(0, 0), data.src)
tex.tex = handle tex.tex = handle
return tex.tex 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{ r := &renderer{
ctx: ctx, ctx: ctx,
blitter: newBlitter(ctx), blitter: newBlitter(ctx),
@@ -557,8 +557,8 @@ func (r *renderer) release() {
r.blitter.release() r.blitter.release()
} }
func newBlitter(ctx backend.Device) *blitter { func newBlitter(ctx driver.Device) *blitter {
quadVerts, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices, quadVerts, err := ctx.NewImmutableBuffer(driver.BufferBindingVertices,
gunsafe.BytesView([]float32{ gunsafe.BytesView([]float32{
-1, +1, 0, 0, -1, +1, 0, 0,
+1, +1, 1, 0, +1, +1, 1, 0,
@@ -596,7 +596,7 @@ func (b *blitter) release() {
b.layout.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 var progs [3]*program
{ {
prog, err := b.NewProgram(vsSrc, fsSrc[materialTexture]) 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) progs[materialLinearGradient] = newProgram(prog, vertBuffer, fragBuffer)
} }
layout, err := b.NewInputLayout(vsSrc, []backend.InputDesc{ layout, err := b.NewInputLayout(vsSrc, []driver.InputDesc{
{Type: backend.DataTypeFloat, Size: 2, Offset: 0}, {Type: driver.DataTypeFloat, Size: 2, Offset: 0},
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2}, {Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
}) })
if err != nil { if err != nil {
progs[materialTexture].Release() 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.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.uniforms.vert.subUVTransform = [4]float32{subScale.X, subScale.Y, subOff.X, subOff.Y}
r.pather.stenciler.iprog.prog.UploadUniforms() 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) { func (r *renderer) packIntersections(ops []imageOp) {
@@ -819,7 +819,7 @@ func (d *drawOps) reset(cache *resourceCache, viewport image.Point) {
d.vertCache = d.vertCache[:0] 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{ clip := f32.Rectangle{
Max: f32.Point{X: float32(viewport.X), Y: float32(viewport.Y)}, 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) { func (r *renderer) drawOps(cache *resourceCache, ops []imageOp) {
r.ctx.SetDepthTest(true) r.ctx.SetDepthTest(true)
r.ctx.DepthMask(false) 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.BindVertexBuffer(r.blitter.quadVerts, 4*4, 0)
r.ctx.BindInputLayout(r.pather.coverer.layout) r.ctx.BindInputLayout(r.pather.coverer.layout)
var coverTex backend.Texture var coverTex driver.Texture
for _, img := range ops { for _, img := range ops {
m := img.material m := img.material
switch m.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.z = z
uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y} uniforms.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
p.UploadUniforms() 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 // newUniformBuffer creates a new GPU uniform buffer backed by the
// structure uniformBlock points to. // structure uniformBlock points to.
func newUniformBuffer(b backend.Device, uniformBlock interface{}) *uniformBuffer { func newUniformBuffer(b driver.Device, uniformBlock interface{}) *uniformBuffer {
ref := reflect.ValueOf(uniformBlock) ref := reflect.ValueOf(uniformBlock)
// Determine the size of the uniforms structure, *uniforms. // Determine the size of the uniforms structure, *uniforms.
size := ref.Elem().Type().Size() size := ref.Elem().Type().Size()
// Map the uniforms structure as a byte slice. // Map the uniforms structure as a byte slice.
ptr := (*[1 << 30]byte)(unsafe.Pointer(ref.Pointer()))[:size:size] 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 { if err != nil {
panic(err) panic(err)
} }
@@ -1225,7 +1225,7 @@ func (u *uniformBuffer) Release() {
u.buf = nil u.buf = nil
} }
func newProgram(prog backend.Program, vertUniforms, fragUniforms *uniformBuffer) *program { func newProgram(prog driver.Program, vertUniforms, fragUniforms *uniformBuffer) *program {
if vertUniforms != nil { if vertUniforms != nil {
prog.SetVertexUniforms(vertUniforms.buf) prog.SetVertexUniforms(vertUniforms.buf)
} }
+14 -14
View File
@@ -12,7 +12,7 @@ import (
"runtime" "runtime"
"testing" "testing"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
"gioui.org/internal/unsafe" "gioui.org/internal/unsafe"
) )
@@ -42,7 +42,7 @@ func TestSimpleShader(t *testing.T) {
} }
defer p.Release() defer p.Release()
b.BindProgram(p) b.BindProgram(p)
b.DrawArrays(backend.DrawModeTriangles, 0, 3) b.DrawArrays(driver.DrawModeTriangles, 0, 3)
img := screenshot(t, fbo, sz) img := screenshot(t, fbo, sz)
if got := img.RGBAAt(0, 0); got != clearColExpect { if got := img.RGBAAt(0, 0); got != clearColExpect {
t.Errorf("got color %v, expected %v", got, clearColExpect) t.Errorf("got color %v, expected %v", got, clearColExpect)
@@ -65,7 +65,7 @@ func TestInputShader(t *testing.T) {
} }
defer p.Release() defer p.Release()
b.BindProgram(p) b.BindProgram(p)
buf, err := b.NewImmutableBuffer(backend.BufferBindingVertices, buf, err := b.NewImmutableBuffer(driver.BufferBindingVertices,
unsafe.BytesView([]float32{ unsafe.BytesView([]float32{
0, .5, .5, 1, 0, .5, .5, 1,
-.5, -.5, .5, 1, -.5, -.5, .5, 1,
@@ -77,9 +77,9 @@ func TestInputShader(t *testing.T) {
} }
defer buf.Release() defer buf.Release()
b.BindVertexBuffer(buf, 4*4, 0) 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, Size: 4,
Offset: 0, Offset: 0,
}, },
@@ -89,7 +89,7 @@ func TestInputShader(t *testing.T) {
} }
defer layout.Release() defer layout.Release()
b.BindInputLayout(layout) b.BindInputLayout(layout)
b.DrawArrays(backend.DrawModeTriangles, 0, 3) b.DrawArrays(driver.DrawModeTriangles, 0, 3)
img := screenshot(t, fbo, sz) img := screenshot(t, fbo, sz)
if got := img.RGBAAt(0, 0); got != clearColExpect { if got := img.RGBAAt(0, 0); got != clearColExpect {
t.Errorf("got color %v, expected %v", 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) fbo := newFBO(t, b, size)
b.BindFramebuffer(fbo) b.BindFramebuffer(fbo)
// ClearColor accepts linear RGBA colors, while 8-bit colors // 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 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( fboTex, err := b.NewTexture(
backend.TextureFormatSRGB, driver.TextureFormatSRGB,
size.X, size.Y, size.X, size.Y,
backend.FilterNearest, backend.FilterNearest, driver.FilterNearest, driver.FilterNearest,
backend.BufferBindingFramebuffer, driver.BufferBindingFramebuffer,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -161,7 +161,7 @@ func newFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuffe
return fbo return fbo
} }
func newBackend(t *testing.T) backend.Device { func newBackend(t *testing.T) driver.Device {
ctx, err := newContext() ctx, err := newContext()
if err != nil { if err != nil {
t.Skipf("no context available: %v", err) t.Skipf("no context available: %v", err)
@@ -170,7 +170,7 @@ func newBackend(t *testing.T) backend.Device {
if err := ctx.MakeCurrent(); err != nil { if err := ctx.MakeCurrent(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
b, err := backend.NewDevice(ctx.API()) b, err := driver.NewDevice(ctx.API())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -184,7 +184,7 @@ func newBackend(t *testing.T) backend.Device {
return b 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}) img := image.NewRGBA(image.Rectangle{Max: size})
err := fbo.ReadPixels( err := fbo.ReadPixels(
image.Rectangle{ image.Rectangle{
+8 -8
View File
@@ -10,7 +10,7 @@ import (
"runtime" "runtime"
"gioui.org/gpu" "gioui.org/gpu"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/op" "gioui.org/op"
) )
@@ -18,10 +18,10 @@ import (
type Window struct { type Window struct {
size image.Point size image.Point
ctx context ctx context
backend backend.Device backend driver.Device
gpu gpu.GPU gpu gpu.GPU
fboTex backend.Texture fboTex driver.Texture
fbo backend.Framebuffer fbo driver.Framebuffer
} }
type context interface { type context interface {
@@ -43,16 +43,16 @@ func NewWindow(width, height int) (*Window, error) {
} }
err = contextDo(ctx, func() error { err = contextDo(ctx, func() error {
api := ctx.API() api := ctx.API()
dev, err := backend.NewDevice(api) dev, err := driver.NewDevice(api)
if err != nil { if err != nil {
return err return err
} }
dev.Viewport(0, 0, width, height) dev.Viewport(0, 0, width, height)
fboTex, err := dev.NewTexture( fboTex, err := dev.NewTexture(
backend.TextureFormatSRGB, driver.TextureFormatSRGB,
width, height, width, height,
backend.FilterNearest, backend.FilterNearest, driver.FilterNearest, driver.FilterNearest,
backend.BufferBindingFramebuffer, driver.BufferBindingFramebuffer,
) )
if err != nil { if err != nil {
return nil return nil
+5 -5
View File
@@ -2,19 +2,19 @@
package headless package headless
import "gioui.org/gpu/backend" import "gioui.org/gpu/internal/driver"
var ( var (
shader_input_vert = backend.ShaderSources{ shader_input_vert = driver.ShaderSources{
Name: "input.vert", 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", 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", 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", 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", 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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shader_simple_frag = backend.ShaderSources{ shader_simple_frag = driver.ShaderSources{
Name: "simple.frag", 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", 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", 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", 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, 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, 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", 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", 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", 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",
+19 -19
View File
@@ -11,7 +11,7 @@ import (
"sort" "sort"
"strings" "strings"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
) )
// GLSLCC is a shader cross-compilation tool. // 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. // Metadata contains reflection data about the shader.
type Metadata struct { type Metadata struct {
Uniforms backend.UniformsReflection Uniforms driver.UniformsReflection
Inputs []backend.InputLocation Inputs []driver.InputLocation
Textures []backend.TextureBinding Textures []driver.TextureBinding
StorageBuffers []backend.StorageBufferBinding StorageBuffers []driver.StorageBufferBinding
} }
// Convert converts input data to the target shader. // Convert converts input data to the target shader.
@@ -163,7 +163,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
if err != nil { if err != nil {
return info, fmt.Errorf("parseReflection: %v", err) return info, fmt.Errorf("parseReflection: %v", err)
} }
info.Inputs = append(info.Inputs, backend.InputLocation{ info.Inputs = append(info.Inputs, driver.InputLocation{
Name: input.Name, Name: input.Name,
Location: input.Location, Location: input.Location,
Semantic: input.Semantic, Semantic: input.Semantic,
@@ -183,7 +183,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
blockOffset := 0 blockOffset := 0
for _, block := range shaderBlocks { 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, Name: block.Name,
Binding: block.Binding, Binding: block.Binding,
}) })
@@ -192,7 +192,7 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
if err != nil { if err != nil {
return info, fmt.Errorf("parseReflection: %v", err) 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. // Synthetic name generated by glslcc.
Name: fmt.Sprintf("_%d.%s", block.ID, member.Name), Name: fmt.Sprintf("_%d.%s", block.ID, member.Name),
Type: dataType, Type: dataType,
@@ -209,14 +209,14 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
textures = reflect.FS.Textures textures = reflect.FS.Textures
} }
for _, texture := range textures { for _, texture := range textures {
info.Textures = append(info.Textures, backend.TextureBinding{ info.Textures = append(info.Textures, driver.TextureBinding{
Name: texture.Name, Name: texture.Name,
Binding: texture.Binding, Binding: texture.Binding,
}) })
} }
for _, sb := range reflect.CS.StorageBuffers { for _, sb := range reflect.CS.StorageBuffers {
info.StorageBuffers = append(info.StorageBuffers, backend.StorageBufferBinding{ info.StorageBuffers = append(info.StorageBuffers, driver.StorageBufferBinding{
Binding: sb.Binding, Binding: sb.Binding,
BlockSize: sb.BlockSize, BlockSize: sb.BlockSize,
}) })
@@ -225,24 +225,24 @@ func (glslcc *GLSLCC) parseReflection(jsonData []byte) (Metadata, error) {
return info, nil return info, nil
} }
func parseDataType(t string) (backend.DataType, int, error) { func parseDataType(t string) (driver.DataType, int, error) {
switch t { switch t {
case "float": case "float":
return backend.DataTypeFloat, 1, nil return driver.DataTypeFloat, 1, nil
case "float2": case "float2":
return backend.DataTypeFloat, 2, nil return driver.DataTypeFloat, 2, nil
case "float3": case "float3":
return backend.DataTypeFloat, 3, nil return driver.DataTypeFloat, 3, nil
case "float4": case "float4":
return backend.DataTypeFloat, 4, nil return driver.DataTypeFloat, 4, nil
case "int": case "int":
return backend.DataTypeInt, 1, nil return driver.DataTypeInt, 1, nil
case "int2": case "int2":
return backend.DataTypeInt, 2, nil return driver.DataTypeInt, 2, nil
case "int3": case "int3":
return backend.DataTypeInt, 3, nil return driver.DataTypeInt, 3, nil
case "int4": case "int4":
return backend.DataTypeInt, 4, nil return driver.DataTypeInt, 4, nil
default: default:
return 0, 0, fmt.Errorf("unsupported input data type: %s", t) return 0, 0, fmt.Errorf("unsupported input data type: %s", t)
} }
+12 -12
View File
@@ -18,7 +18,7 @@ import (
"sync" "sync"
"text/template" "text/template"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
) )
func main() { func main() {
@@ -138,7 +138,7 @@ func (conv *Converter) Run(out io.Writer) error {
type ShaderResult struct { type ShaderResult struct {
Path string Path string
Shaders []backend.ShaderSources Shaders []driver.ShaderSources
Error error Error error
} }
shaderResults := make([]ShaderResult, len(shaders)) 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, "// Code generated by build.go. DO NOT EDIT.\n\n")
fmt.Fprintf(out, "package %s\n\n", conv.packageName) 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") fmt.Fprintf(out, "var (\n")
@@ -202,17 +202,17 @@ func (conv *Converter) Run(out io.Writer) error {
multiVariant := len(r.Shaders) > 1 multiVariant := len(r.Shaders) > 1
if multiVariant { if multiVariant {
fmt.Fprintf(out, "[...]backend.ShaderSources{\n") fmt.Fprintf(out, "[...]driver.ShaderSources{\n")
} }
for _, src := range r.Shaders { 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) fmt.Fprintf(out, "Name: %#v,\n", src.Name)
if len(src.Inputs) > 0 { if len(src.Inputs) > 0 {
fmt.Fprintf(out, "Inputs: %#v,\n", src.Inputs) fmt.Fprintf(out, "Inputs: %#v,\n", src.Inputs)
} }
if u := src.Uniforms; len(u.Blocks) > 0 { 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, "Blocks: %#v,\n", u.Blocks)
fmt.Fprintf(out, "Locations: %#v,\n", u.Locations) fmt.Fprintf(out, "Locations: %#v,\n", u.Locations)
fmt.Fprintf(out, "Size: %d,\n", u.Size) fmt.Fprintf(out, "Size: %d,\n", u.Size)
@@ -254,7 +254,7 @@ func (conv *Converter) Run(out io.Writer) error {
return nil return nil
} }
func (conv *Converter) Shader(shaderPath string) ([]backend.ShaderSources, error) { func (conv *Converter) Shader(shaderPath string) ([]driver.ShaderSources, error) {
type Variant struct { type Variant struct {
FetchColorExpr string FetchColorExpr string
Header 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) 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 { for i, variantArg := range variantArgs {
variantName := strconv.Itoa(i) variantName := strconv.Itoa(i)
var buf bytes.Buffer 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) 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) sources.Name = filepath.Base(shaderPath)
// Ignore error; some shaders are not meant to run in GLSL 1.00. // 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 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) shader, err := ioutil.ReadFile(shaderPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load shader %q: %w", shaderPath, err) 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) 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.Name = filepath.Base(shaderPath)
sources.GLSL310ES, err = conv.spirv.Convert(spirv, "es", "310") 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. // Workers implements wait group with synchronous logging.
+62 -62
View File
@@ -11,7 +11,7 @@ import (
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/d3d11" "gioui.org/internal/d3d11"
gunsafe "gioui.org/internal/unsafe" gunsafe "gioui.org/internal/unsafe"
) )
@@ -29,7 +29,7 @@ type Backend struct {
// Current program. // Current program.
prog *Program prog *Program
caps backend.Caps caps driver.Caps
// fbo is the currently bound fbo. // fbo is the currently bound fbo.
fbo *Framebuffer fbo *Framebuffer
@@ -43,20 +43,20 @@ type Backend struct {
type blendState struct { type blendState struct {
enable bool enable bool
sfactor backend.BlendFactor sfactor driver.BlendFactor
dfactor backend.BlendFactor dfactor driver.BlendFactor
} }
type depthState struct { type depthState struct {
enable bool enable bool
mask bool mask bool
fn backend.DepthFunc fn driver.DepthFunc
} }
type Texture struct { type Texture struct {
backend *Backend backend *Backend
format uint32 format uint32
bindings backend.BufferBinding bindings driver.BufferBinding
tex *d3d11.Texture2D tex *d3d11.Texture2D
sampler *d3d11.SamplerState sampler *d3d11.SamplerState
resView *d3d11.ShaderResourceView resView *d3d11.ShaderResourceView
@@ -99,7 +99,7 @@ type InputLayout struct {
} }
func init() { func init() {
backend.NewDirect3D11Device = newDirect3D11Device driver.NewDirect3D11Device = newDirect3D11Device
} }
func detectFloatFormat(dev *d3d11.Device) (uint32, bool) { func detectFloatFormat(dev *d3d11.Device) (uint32, bool) {
@@ -121,12 +121,12 @@ func detectFloatFormat(dev *d3d11.Device) (uint32, bool) {
return 0, false return 0, false
} }
func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) { func newDirect3D11Device(api driver.Direct3D11) (driver.Device, error) {
dev := (*d3d11.Device)(api.Device) dev := (*d3d11.Device)(api.Device)
b := &Backend{ b := &Backend{
dev: dev, dev: dev,
ctx: dev.GetImmediateContext(), ctx: dev.GetImmediateContext(),
caps: backend.Caps{ caps: driver.Caps{
MaxTextureSize: 2048, // 9.1 maximum MaxTextureSize: 2048, // 9.1 maximum
}, },
depthStates: make(map[depthState]*d3d11.DepthStencilState), depthStates: make(map[depthState]*d3d11.DepthStencilState),
@@ -146,7 +146,7 @@ func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) {
} }
if fmt, ok := detectFloatFormat(dev); ok { if fmt, ok := detectFloatFormat(dev); ok {
b.floatFormat = fmt b.floatFormat = fmt
b.caps.Features |= backend.FeatureFloatRenderTargets b.caps.Features |= driver.FeatureFloatRenderTargets
} }
// Enable depth mask to match OpenGL. // Enable depth mask to match OpenGL.
b.depthState.mask = true b.depthState.mask = true
@@ -164,7 +164,7 @@ func newDirect3D11Device(api backend.Direct3D11) (backend.Device, error) {
return b, nil return b, nil
} }
func (b *Backend) BeginFrame() backend.Framebuffer { func (b *Backend) BeginFrame() driver.Framebuffer {
renderTarget, depthView := b.ctx.OMGetRenderTargets() renderTarget, depthView := b.ctx.OMGetRenderTargets()
// Assume someone else is holding on to the render targets. // Assume someone else is holding on to the render targets.
if renderTarget != nil { if renderTarget != nil {
@@ -179,11 +179,11 @@ func (b *Backend) BeginFrame() backend.Framebuffer {
func (b *Backend) EndFrame() { func (b *Backend) EndFrame() {
} }
func (b *Backend) Caps() backend.Caps { func (b *Backend) Caps() driver.Caps {
return b.caps return b.caps
} }
func (b *Backend) NewTimer() backend.Timer { func (b *Backend) NewTimer() driver.Timer {
panic("timers not supported") panic("timers not supported")
} }
@@ -202,12 +202,12 @@ func (b *Backend) Release() {
*b = Backend{} *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 var d3dfmt uint32
switch format { switch format {
case backend.TextureFormatFloat: case driver.TextureFormatFloat:
d3dfmt = b.floatFormat d3dfmt = b.floatFormat
case backend.TextureFormatSRGB: case driver.TextureFormatSRGB:
d3dfmt = d3d11.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB d3dfmt = d3d11.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
default: default:
return nil, fmt.Errorf("unsupported texture format %d", format) 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 sampler *d3d11.SamplerState
resView *d3d11.ShaderResourceView resView *d3d11.ShaderResourceView
) )
if bindings&backend.BufferBindingTexture != 0 { if bindings&driver.BufferBindingTexture != 0 {
var filter uint32 var filter uint32
switch { switch {
case minFilter == backend.FilterNearest && magFilter == backend.FilterNearest: case minFilter == driver.FilterNearest && magFilter == driver.FilterNearest:
filter = d3d11.FILTER_MIN_MAG_MIP_POINT 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 filter = d3d11.FILTER_MIN_MAG_LINEAR_MIP_POINT
default: default:
d3d11.IUnknownRelease(unsafe.Pointer(tex), tex.Vtbl.Release) 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 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) 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") return nil, errors.New("the texture was created without BufferBindingFramebuffer binding")
} }
resource := (*d3d11.Resource)(unsafe.Pointer(d3dtex.tex)) 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 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) { if len(vertexShader.Inputs) != len(layout) {
return nil, fmt.Errorf("NewInputLayout: got %d inputs, expected %d", len(layout), len(vertexShader.Inputs)) 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 var format uint32
switch l.Type { switch l.Type {
case backend.DataTypeFloat: case driver.DataTypeFloat:
switch l.Size { switch l.Size {
case 1: case 1:
format = d3d11.DXGI_FORMAT_R32_FLOAT format = d3d11.DXGI_FORMAT_R32_FLOAT
@@ -326,7 +326,7 @@ func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []ba
default: default:
panic("unsupported float data size") panic("unsupported float data size")
} }
case backend.DataTypeShort: case driver.DataTypeShort:
switch l.Size { switch l.Size {
case 1: case 1:
format = d3d11.DXGI_FORMAT_R16_SINT format = d3d11.DXGI_FORMAT_R16_SINT
@@ -352,9 +352,9 @@ func (b *Backend) NewInputLayout(vertexShader backend.ShaderSources, layout []ba
return &InputLayout{layout: l}, nil return &InputLayout{layout: l}, 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) {
if typ&backend.BufferBindingUniforms != 0 { if typ&driver.BufferBindingUniforms != 0 {
if typ != backend.BufferBindingUniforms { if typ != driver.BufferBindingUniforms {
return nil, errors.New("uniform buffers cannot have other bindings") return nil, errors.New("uniform buffers cannot have other bindings")
} }
if size%16 != 0 { 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 return &Buffer{backend: b, buf: buf, bind: bind}, 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) {
if typ&backend.BufferBindingUniforms != 0 { if typ&driver.BufferBindingUniforms != 0 {
if typ != backend.BufferBindingUniforms { if typ != driver.BufferBindingUniforms {
return nil, errors.New("uniform buffers cannot have other bindings") return nil, errors.New("uniform buffers cannot have other bindings")
} }
if len(data)%16 != 0 { 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 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") 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) vs, err := b.dev.CreateVertexShader(vertexShader.HLSL)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -435,17 +435,17 @@ func (b *Backend) Viewport(x, y, width, height int) {
b.ctx.RSSetViewports(&b.viewport) 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.prepareDraw(mode)
b.ctx.Draw(uint32(count), uint32(off)) 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.prepareDraw(mode)
b.ctx.DrawIndexed(uint32(count), uint32(off), 0) 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 { if p := b.prog; p != nil {
b.ctx.VSSetShader(p.vert.shader) b.ctx.VSSetShader(p.vert.shader)
b.ctx.PSSetShader(p.frag.shader) b.ctx.PSSetShader(p.frag.shader)
@@ -458,9 +458,9 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
} }
var topology uint32 var topology uint32
switch mode { switch mode {
case backend.DrawModeTriangles: case driver.DrawModeTriangles:
topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLELIST topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLELIST
case backend.DrawModeTriangleStrip: case driver.DrawModeTriangleStrip:
topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLESTRIP topology = d3d11.PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
default: default:
panic("unsupported draw mode") panic("unsupported draw mode")
@@ -477,9 +477,9 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
desc.DepthWriteMask = d3d11.DEPTH_WRITE_MASK_ALL desc.DepthWriteMask = d3d11.DEPTH_WRITE_MASK_ALL
} }
switch b.depthState.fn { switch b.depthState.fn {
case backend.DepthFuncGreater: case driver.DepthFuncGreater:
desc.DepthFunc = d3d11.COMPARISON_GREATER desc.DepthFunc = d3d11.COMPARISON_GREATER
case backend.DepthFuncGreaterEqual: case driver.DepthFuncGreaterEqual:
desc.DepthFunc = d3d11.COMPARISON_GREATER_EQUAL desc.DepthFunc = d3d11.COMPARISON_GREATER_EQUAL
default: default:
panic("unsupported depth func") panic("unsupported depth func")
@@ -519,7 +519,7 @@ func (b *Backend) prepareDraw(mode backend.DrawMode) {
b.ctx.OMSetBlendState(blendState, nil, 0xffffffff) b.ctx.OMSetBlendState(blendState, nil, 0xffffffff)
} }
func (b *Backend) DepthFunc(f backend.DepthFunc) { func (b *Backend) DepthFunc(f driver.DepthFunc) {
b.depthState.fn = f b.depthState.fn = f
} }
@@ -535,12 +535,12 @@ func (b *Backend) DepthMask(mask bool) {
b.depthState.mask = mask 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.sfactor = sfactor
b.blendState.dfactor = dfactor 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") 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) t := tex.(*Texture)
b.ctx.PSSetSamplers(uint32(unit), t.sampler) b.ctx.PSSetSamplers(uint32(unit), t.sampler)
b.ctx.PSSetShaderResources(uint32(unit), t.resView) 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) b.prog = prog.(*Program)
} }
@@ -596,23 +596,23 @@ func (p *Program) Release() {
p.frag.shader = nil 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") panic("not implemented")
} }
func (p *Program) SetVertexUniforms(buf backend.Buffer) { func (p *Program) SetVertexUniforms(buf driver.Buffer) {
p.vert.uniforms = buf.(*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) 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)) 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) 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 return nil
} }
func (b *Backend) BindFramebuffer(fbo backend.Framebuffer) { func (b *Backend) BindFramebuffer(fbo driver.Framebuffer) {
b.fbo = fbo.(*Framebuffer) b.fbo = fbo.(*Framebuffer)
b.ctx.OMSetRenderTargets(b.fbo.renderTarget, b.fbo.depthView) 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) b.ctx.IASetInputLayout(layout.(*InputLayout).layout)
} }
@@ -715,35 +715,35 @@ func (l *InputLayout) Release() {
l.layout = nil l.layout = nil
} }
func convBufferBinding(typ backend.BufferBinding) uint32 { func convBufferBinding(typ driver.BufferBinding) uint32 {
var bindings uint32 var bindings uint32
if typ&backend.BufferBindingVertices != 0 { if typ&driver.BufferBindingVertices != 0 {
bindings |= d3d11.BIND_VERTEX_BUFFER bindings |= d3d11.BIND_VERTEX_BUFFER
} }
if typ&backend.BufferBindingIndices != 0 { if typ&driver.BufferBindingIndices != 0 {
bindings |= d3d11.BIND_INDEX_BUFFER bindings |= d3d11.BIND_INDEX_BUFFER
} }
if typ&backend.BufferBindingUniforms != 0 { if typ&driver.BufferBindingUniforms != 0 {
bindings |= d3d11.BIND_CONSTANT_BUFFER bindings |= d3d11.BIND_CONSTANT_BUFFER
} }
if typ&backend.BufferBindingTexture != 0 { if typ&driver.BufferBindingTexture != 0 {
bindings |= d3d11.BIND_SHADER_RESOURCE bindings |= d3d11.BIND_SHADER_RESOURCE
} }
if typ&backend.BufferBindingFramebuffer != 0 { if typ&driver.BufferBindingFramebuffer != 0 {
bindings |= d3d11.BIND_RENDER_TARGET bindings |= d3d11.BIND_RENDER_TARGET
} }
return bindings return bindings
} }
func toBlendFactor(f backend.BlendFactor) (uint32, uint32) { func toBlendFactor(f driver.BlendFactor) (uint32, uint32) {
switch f { switch f {
case backend.BlendFactorOne: case driver.BlendFactorOne:
return d3d11.BLEND_ONE, d3d11.BLEND_ONE return d3d11.BLEND_ONE, d3d11.BLEND_ONE
case backend.BlendFactorOneMinusSrcAlpha: case driver.BlendFactorOneMinusSrcAlpha:
return d3d11.BLEND_INV_SRC_ALPHA, d3d11.BLEND_INV_SRC_ALPHA return d3d11.BLEND_INV_SRC_ALPHA, d3d11.BLEND_INV_SRC_ALPHA
case backend.BlendFactorZero: case driver.BlendFactorZero:
return d3d11.BLEND_ZERO, d3d11.BLEND_ZERO return d3d11.BLEND_ZERO, d3d11.BLEND_ZERO
case backend.BlendFactorDstColor: case driver.BlendFactorDstColor:
return d3d11.BLEND_DEST_COLOR, d3d11.BLEND_DEST_ALPHA return d3d11.BLEND_DEST_COLOR, d3d11.BLEND_DEST_ALPHA
default: default:
panic("unsupported blend source factor") panic("unsupported blend source factor")
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Unlicense OR MIT // SPDX-License-Identifier: Unlicense OR MIT
package backend package driver
import ( import (
"fmt" "fmt"
@@ -49,7 +49,7 @@ func NewDevice(api API) (Device, error) {
return NewDirect3D11Device(api) 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() {} func (OpenGL) implementsAPI() {}
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Unlicense OR MIT // SPDX-License-Identifier: Unlicense OR MIT
package backend package driver
import ( import (
"errors" "errors"
+35 -35
View File
@@ -12,13 +12,13 @@ import (
"unsafe" "unsafe"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
"gioui.org/internal/f32color" "gioui.org/internal/f32color"
gunsafe "gioui.org/internal/unsafe" gunsafe "gioui.org/internal/unsafe"
) )
type pather struct { type pather struct {
ctx backend.Device ctx driver.Device
viewport image.Point viewport image.Point
@@ -27,12 +27,12 @@ type pather struct {
} }
type coverer struct { type coverer struct {
ctx backend.Device ctx driver.Device
prog [3]*program prog [3]*program
texUniforms *coverTexUniforms texUniforms *coverTexUniforms
colUniforms *coverColUniforms colUniforms *coverColUniforms
linearGradientUniforms *coverLinearGradientUniforms linearGradientUniforms *coverLinearGradientUniforms
layout backend.InputLayout layout driver.InputLayout
} }
type coverTexUniforms struct { type coverTexUniforms struct {
@@ -71,20 +71,20 @@ type coverUniforms struct {
} }
type stenciler struct { type stenciler struct {
ctx backend.Device ctx driver.Device
prog struct { prog struct {
prog *program prog *program
uniforms *stencilUniforms uniforms *stencilUniforms
layout backend.InputLayout layout driver.InputLayout
} }
iprog struct { iprog struct {
prog *program prog *program
uniforms *intersectUniforms uniforms *intersectUniforms
layout backend.InputLayout layout driver.InputLayout
} }
fbos fboSet fbos fboSet
intersections fboSet intersections fboSet
indexBuf backend.Buffer indexBuf driver.Buffer
} }
type stencilUniforms struct { type stencilUniforms struct {
@@ -108,13 +108,13 @@ type fboSet struct {
type stencilFBO struct { type stencilFBO struct {
size image.Point size image.Point
fbo backend.Framebuffer fbo driver.Framebuffer
tex backend.Texture tex driver.Texture
} }
type pathData struct { type pathData struct {
ncurves int ncurves int
data backend.Buffer data driver.Buffer
} }
// vertex data suitable for passing to vertex programs. // vertex data suitable for passing to vertex programs.
@@ -146,7 +146,7 @@ const (
vertStride = 8 * 4 vertStride = 8 * 4
) )
func newPather(ctx backend.Device) *pather { func newPather(ctx driver.Device) *pather {
return &pather{ return &pather{
ctx: ctx, ctx: ctx,
stenciler: newStenciler(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{ c := &coverer{
ctx: ctx, ctx: ctx,
} }
@@ -173,7 +173,7 @@ func newCoverer(ctx backend.Device) *coverer {
return c return c
} }
func newStenciler(ctx backend.Device) *stenciler { func newStenciler(ctx driver.Device) *stenciler {
// Allocate a suitably large index buffer for drawing paths. // Allocate a suitably large index buffer for drawing paths.
indices := make([]uint16, pathBatchSize*6) indices := make([]uint16, pathBatchSize*6)
for i := 0; i < pathBatchSize; i++ { 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+4] = i*4 + 1
indices[i*6+5] = i*4 + 3 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 { if err != nil {
panic(err) panic(err)
} }
progLayout, err := ctx.NewInputLayout(shader_stencil_vert, []backend.InputDesc{ progLayout, err := ctx.NewInputLayout(shader_stencil_vert, []driver.InputDesc{
{Type: backend.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).Corner))}, {Type: driver.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).Corner))},
{Type: backend.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).MaxY))}, {Type: driver.DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).MaxY))},
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).FromX))}, {Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).FromX))},
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).CtrlX))}, {Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).CtrlX))},
{Type: backend.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).ToX))}, {Type: driver.DataTypeFloat, Size: 2, Offset: int(unsafe.Offsetof((*(*vertex)(nil)).ToX))},
}) })
if err != nil { if err != nil {
panic(err) panic(err)
} }
iprogLayout, err := ctx.NewInputLayout(shader_intersect_vert, []backend.InputDesc{ iprogLayout, err := ctx.NewInputLayout(shader_intersect_vert, []driver.InputDesc{
{Type: backend.DataTypeFloat, Size: 2, Offset: 0}, {Type: driver.DataTypeFloat, Size: 2, Offset: 0},
{Type: backend.DataTypeFloat, Size: 2, Offset: 4 * 2}, {Type: driver.DataTypeFloat, Size: 2, Offset: 4 * 2},
}) })
if err != nil { if err != nil {
panic(err) panic(err)
@@ -229,7 +229,7 @@ func newStenciler(ctx backend.Device) *stenciler {
return st return st
} }
func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) { func (s *fboSet) resize(ctx driver.Device, sizes []image.Point) {
// Add fbos. // Add fbos.
for i := len(s.fbos); i < len(sizes); i++ { for i := len(s.fbos); i < len(sizes); i++ {
s.fbos = append(s.fbos, stencilFBO{}) s.fbos = append(s.fbos, stencilFBO{})
@@ -247,8 +247,8 @@ func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) {
f.fbo.Release() f.fbo.Release()
f.tex.Release() f.tex.Release()
} }
tex, err := ctx.NewTexture(backend.TextureFormatFloat, sz.X, sz.Y, backend.FilterNearest, backend.FilterNearest, tex, err := ctx.NewTexture(driver.TextureFormatFloat, sz.X, sz.Y, driver.FilterNearest, driver.FilterNearest,
backend.BufferBindingTexture|backend.BufferBindingFramebuffer) driver.BufferBindingTexture|driver.BufferBindingFramebuffer)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -265,13 +265,13 @@ func (s *fboSet) resize(ctx backend.Device, sizes []image.Point) {
s.delete(ctx, len(sizes)) s.delete(ctx, len(sizes))
} }
func (s *fboSet) invalidate(ctx backend.Device) { func (s *fboSet) invalidate(ctx driver.Device) {
for _, f := range s.fbos { for _, f := range s.fbos {
f.fbo.Invalidate() 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++ { for i := idx; i < len(s.fbos); i++ {
f := s.fbos[i] f := s.fbos[i]
f.fbo.Release() f.fbo.Release()
@@ -301,8 +301,8 @@ func (c *coverer) release() {
c.layout.Release() c.layout.Release()
} }
func buildPath(ctx backend.Device, p []byte) pathData { func buildPath(ctx driver.Device, p []byte) pathData {
buf, err := ctx.NewImmutableBuffer(backend.BufferBindingVertices, p) buf, err := ctx.NewImmutableBuffer(driver.BufferBindingVertices, p)
if err != nil { if err != nil {
panic(err) 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) { 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 // 8 bit coverage is enough, but OpenGL ES only supports single channel
// floating point formats. Replace with GL_RGB+GL_UNSIGNED_BYTE if // floating point formats. Replace with GL_RGB+GL_UNSIGNED_BYTE if
// no floating point support is available. // no floating point support is available.
@@ -343,7 +343,7 @@ func (s *stenciler) cover(idx int) stencilFBO {
} }
func (s *stenciler) begin(sizes []image.Point) { 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.fbos.resize(s.ctx, sizes)
s.ctx.BindProgram(s.prog.prog.prog) s.ctx.BindProgram(s.prog.prog.prog)
s.ctx.BindInputLayout(s.prog.layout) 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 off := vertStride * start * 4
s.ctx.BindVertexBuffer(data.data, vertStride, off) 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 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.transform = [4]float32{scale.X, scale.Y, off.X, off.Y}
uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y} uniforms.uvCoverTransform = [4]float32{coverScale.X, coverScale.Y, coverOff.X, coverOff.Y}
p.UploadUniforms() p.UploadUniforms()
c.ctx.DrawArrays(backend.DrawModeTriangleStrip, 0, 4) c.ctx.DrawArrays(driver.DrawModeTriangleStrip, 0, 4)
} }
func init() { func init() {
+56 -56
View File
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -5,18 +5,18 @@ package gpu
import ( import (
"time" "time"
"gioui.org/gpu/backend" "gioui.org/gpu/internal/driver"
) )
type timers struct { type timers struct {
backend backend.Device backend driver.Device
timers []*timer timers []*timer
} }
type timer struct { type timer struct {
Elapsed time.Duration Elapsed time.Duration
backend backend.Device backend driver.Device
timer backend.Timer timer driver.Timer
state timerState state timerState
} }
@@ -28,7 +28,7 @@ const (
timerWaiting timerWaiting
) )
func newTimers(b backend.Device) *timers { func newTimers(b driver.Device) *timers {
return &timers{ return &timers{
backend: b, backend: b,
} }