mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
gpu: remove compute renderer
The compute renderer is a failed experiment: a better port of the Vello vector renderer exists[0] and the upcoming Go 1.24 release no longer builds the gioui.org/cpu module because of #60725. Remove it. [0] https://github.com/dominikh/jello Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
-2193
File diff suppressed because it is too large
Load Diff
-129
@@ -1,129 +0,0 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package gpu
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/cpu"
|
||||
)
|
||||
|
||||
// This file contains code specific to running compute shaders on the CPU.
|
||||
|
||||
// dispatcher dispatches CPU compute programs across multiple goroutines.
|
||||
type dispatcher struct {
|
||||
// done is notified when a worker completes its work slice.
|
||||
done chan struct{}
|
||||
// work receives work slice indices. It is closed when the dispatcher is released.
|
||||
work chan work
|
||||
// dispatch receives compute jobs, which is then split among workers.
|
||||
dispatch chan dispatch
|
||||
// sync receives notification when a Sync completes.
|
||||
sync chan struct{}
|
||||
}
|
||||
|
||||
type work struct {
|
||||
ctx *cpu.DispatchContext
|
||||
index int
|
||||
}
|
||||
|
||||
type dispatch struct {
|
||||
_type jobType
|
||||
program *cpu.ProgramInfo
|
||||
descSet unsafe.Pointer
|
||||
x, y, z int
|
||||
}
|
||||
|
||||
type jobType uint8
|
||||
|
||||
const (
|
||||
jobDispatch jobType = iota
|
||||
jobBarrier
|
||||
jobSync
|
||||
)
|
||||
|
||||
func newDispatcher(workers int) *dispatcher {
|
||||
d := &dispatcher{
|
||||
work: make(chan work, workers),
|
||||
done: make(chan struct{}, workers),
|
||||
// Leave some room to avoid blocking calls to Dispatch.
|
||||
dispatch: make(chan dispatch, 20),
|
||||
sync: make(chan struct{}),
|
||||
}
|
||||
for i := 0; i < workers; i++ {
|
||||
go d.worker()
|
||||
}
|
||||
go d.dispatcher()
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *dispatcher) dispatcher() {
|
||||
defer close(d.work)
|
||||
var free []*cpu.DispatchContext
|
||||
defer func() {
|
||||
for _, ctx := range free {
|
||||
ctx.Free()
|
||||
}
|
||||
}()
|
||||
var used []*cpu.DispatchContext
|
||||
for job := range d.dispatch {
|
||||
switch job._type {
|
||||
case jobDispatch:
|
||||
if len(free) == 0 {
|
||||
free = append(free, cpu.NewDispatchContext())
|
||||
}
|
||||
ctx := free[len(free)-1]
|
||||
free = free[:len(free)-1]
|
||||
used = append(used, ctx)
|
||||
ctx.Prepare(cap(d.work), job.program, job.descSet, job.x, job.y, job.z)
|
||||
for i := 0; i < cap(d.work); i++ {
|
||||
d.work <- work{
|
||||
ctx: ctx,
|
||||
index: i,
|
||||
}
|
||||
}
|
||||
case jobBarrier:
|
||||
// Wait for all outstanding dispatches to complete.
|
||||
for i := 0; i < len(used)*cap(d.work); i++ {
|
||||
<-d.done
|
||||
}
|
||||
free = append(free, used...)
|
||||
used = used[:0]
|
||||
case jobSync:
|
||||
d.sync <- struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dispatcher) worker() {
|
||||
thread := cpu.NewThreadContext()
|
||||
defer thread.Free()
|
||||
for w := range d.work {
|
||||
w.ctx.Dispatch(w.index, thread)
|
||||
d.done <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dispatcher) Barrier() {
|
||||
d.dispatch <- dispatch{_type: jobBarrier}
|
||||
}
|
||||
|
||||
func (d *dispatcher) Sync() {
|
||||
d.dispatch <- dispatch{_type: jobSync}
|
||||
<-d.sync
|
||||
}
|
||||
|
||||
func (d *dispatcher) Dispatch(program *cpu.ProgramInfo, descSet unsafe.Pointer, x, y, z int) {
|
||||
d.dispatch <- dispatch{
|
||||
_type: jobDispatch,
|
||||
program: program,
|
||||
descSet: descSet,
|
||||
x: x,
|
||||
y: y,
|
||||
z: z,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dispatcher) Stop() {
|
||||
close(d.dispatch)
|
||||
}
|
||||
+16
-5
@@ -9,11 +9,11 @@ package gpu
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
"unsafe"
|
||||
@@ -343,13 +343,12 @@ func New(api API) (GPU, error) {
|
||||
func NewWithDevice(d driver.Device) (GPU, error) {
|
||||
d.BeginFrame(nil, false, image.Point{})
|
||||
defer d.EndFrame()
|
||||
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
|
||||
feats := d.Caps().Features
|
||||
switch {
|
||||
case !forceCompute && feats.Has(driver.FeatureFloatRenderTargets) && feats.Has(driver.FeatureSRGB):
|
||||
case feats.Has(driver.FeatureFloatRenderTargets) && feats.Has(driver.FeatureSRGB):
|
||||
return newGPU(d)
|
||||
}
|
||||
return newCompute(d)
|
||||
return nil, errors.New("no available GPU driver")
|
||||
}
|
||||
|
||||
func newGPU(ctx driver.Device) (*gpu, error) {
|
||||
@@ -1484,7 +1483,7 @@ func (d *drawOps) buildVerts(pathData []byte, tr f32.Affine2D, outline bool, str
|
||||
// as needed and feeds them to the supplied splitter.
|
||||
func decodeToOutlineQuads(qs *quadSplitter, tr f32.Affine2D, pathData []byte) {
|
||||
for len(pathData) >= scene.CommandSize+4 {
|
||||
qs.contour = bo.Uint32(pathData)
|
||||
qs.contour = binary.LittleEndian.Uint32(pathData)
|
||||
cmd := ops.DecodeCommand(pathData[4:])
|
||||
switch cmd.Op() {
|
||||
case scene.OpLine:
|
||||
@@ -1579,3 +1578,15 @@ func isPureOffset(t f32.Affine2D) bool {
|
||||
a, b, _, d, e, _ := t.Elems()
|
||||
return a == 1 && b == 0 && d == 0 && e == 1
|
||||
}
|
||||
|
||||
func newShaders(ctx driver.Device, vsrc, fsrc shader.Sources) (vert driver.VertexShader, frag driver.FragmentShader, err error) {
|
||||
vert, err = ctx.NewVertexShader(vsrc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
frag, err = ctx.NewFragmentShader(fsrc)
|
||||
if err != nil {
|
||||
vert.Release()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user