mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
gpu: drop access flags and format from driver.Device.BindImageTexture
They can be deferred in the drivers that need them. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -1278,12 +1278,12 @@ func (g *compute) render(images *textureAtlas, dst driver.Texture, cpuDst cpu.Im
|
|||||||
|
|
||||||
if !g.useCPU {
|
if !g.useCPU {
|
||||||
g.ctx.BeginCompute()
|
g.ctx.BeginCompute()
|
||||||
g.ctx.BindImageTexture(kernel4OutputUnit, dst, driver.AccessWrite, driver.TextureFormatRGBA8)
|
g.ctx.BindImageTexture(kernel4OutputUnit, dst)
|
||||||
img := g.output.nullMaterials
|
img := g.output.nullMaterials
|
||||||
if images != nil {
|
if images != nil {
|
||||||
img = images.image
|
img = images.image
|
||||||
}
|
}
|
||||||
g.ctx.BindImageTexture(kernel4AtlasUnit, img, driver.AccessRead, driver.TextureFormatRGBA8)
|
g.ctx.BindImageTexture(kernel4AtlasUnit, img)
|
||||||
} else {
|
} else {
|
||||||
*g.output.descriptors.Binding2() = cpuDst
|
*g.output.descriptors.Binding2() = cpuDst
|
||||||
if images != nil {
|
if images != nil {
|
||||||
|
|||||||
@@ -582,12 +582,12 @@ func (b *Backend) prepareDraw() {
|
|||||||
b.ctx.IASetPrimitiveTopology(topology)
|
b.ctx.IASetPrimitiveTopology(topology)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) BindImageTexture(unit int, tex driver.Texture, access driver.AccessBits, f driver.TextureFormat) {
|
func (b *Backend) BindImageTexture(unit int, tex driver.Texture) {
|
||||||
t := tex.(*Texture)
|
t := tex.(*Texture)
|
||||||
if access&driver.AccessWrite == 0 {
|
if t.uaView != nil {
|
||||||
b.ctx.CSSetShaderResources(uint32(unit), t.resView)
|
|
||||||
} else {
|
|
||||||
b.ctx.CSSetUnorderedAccessViews(uint32(unit), t.uaView)
|
b.ctx.CSSetUnorderedAccessViews(uint32(unit), t.uaView)
|
||||||
|
} else {
|
||||||
|
b.ctx.CSSetShaderResources(uint32(unit), t.resView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type Device interface {
|
|||||||
BindTexture(unit int, t Texture)
|
BindTexture(unit int, t Texture)
|
||||||
BindVertexBuffer(b Buffer, offset int)
|
BindVertexBuffer(b Buffer, offset int)
|
||||||
BindIndexBuffer(b Buffer)
|
BindIndexBuffer(b Buffer)
|
||||||
BindImageTexture(unit int, texture Texture, access AccessBits, format TextureFormat)
|
BindImageTexture(unit int, texture Texture)
|
||||||
BindUniforms(buf Buffer)
|
BindUniforms(buf Buffer)
|
||||||
BindStorageBuffer(binding int, buf Buffer)
|
BindStorageBuffer(binding int, buf Buffer)
|
||||||
|
|
||||||
@@ -91,8 +91,6 @@ type BlendDesc struct {
|
|||||||
SrcFactor, DstFactor BlendFactor
|
SrcFactor, DstFactor BlendFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessBits uint8
|
|
||||||
|
|
||||||
type BlendFactor uint8
|
type BlendFactor uint8
|
||||||
|
|
||||||
type Topology uint8
|
type Topology uint8
|
||||||
@@ -164,11 +162,6 @@ const (
|
|||||||
TextureFormatOutput
|
TextureFormatOutput
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
AccessRead AccessBits = 1 << iota
|
|
||||||
AccessWrite
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FilterNearest TextureFilter = iota
|
FilterNearest TextureFilter = iota
|
||||||
FilterLinear
|
FilterLinear
|
||||||
|
|||||||
@@ -814,7 +814,7 @@ func primitiveFor(mode driver.Topology) C.MTLPrimitiveType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) BindImageTexture(unit int, tex driver.Texture, access driver.AccessBits, f driver.TextureFormat) {
|
func (b *Backend) BindImageTexture(unit int, tex driver.Texture) {
|
||||||
b.BindTexture(unit, tex)
|
b.BindTexture(unit, tex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,14 +96,15 @@ type timer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type texture struct {
|
type texture struct {
|
||||||
backend *Backend
|
backend *Backend
|
||||||
obj gl.Texture
|
obj gl.Texture
|
||||||
fbo gl.Framebuffer
|
fbo gl.Framebuffer
|
||||||
hasFBO bool
|
hasFBO bool
|
||||||
triple textureTriple
|
triple textureTriple
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
foreign bool
|
bindings driver.BufferBinding
|
||||||
|
foreign bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type pipeline struct {
|
type pipeline struct {
|
||||||
@@ -675,7 +676,7 @@ func (t *texture) ensureFBO() gl.Framebuffer {
|
|||||||
|
|
||||||
func (b *Backend) NewTexture(format driver.TextureFormat, width, height int, minFilter, magFilter driver.TextureFilter, binding driver.BufferBinding) (driver.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 := &texture{backend: b, obj: b.funcs.CreateTexture(), width: width, height: height}
|
tex := &texture{backend: b, obj: b.funcs.CreateTexture(), width: width, height: height, bindings: binding}
|
||||||
switch format {
|
switch format {
|
||||||
case driver.TextureFormatFloat:
|
case driver.TextureFormatFloat:
|
||||||
tex.triple = b.floatTriple
|
tex.triple = b.floatTriple
|
||||||
@@ -772,27 +773,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 driver.Texture, access driver.AccessBits, f driver.TextureFormat) {
|
func (b *Backend) BindImageTexture(unit int, tex driver.Texture) {
|
||||||
t := tex.(*texture)
|
t := tex.(*texture)
|
||||||
var acc gl.Enum
|
var acc gl.Enum
|
||||||
switch access {
|
switch t.bindings & (driver.BufferBindingShaderStorageRead | driver.BufferBindingShaderStorageWrite) {
|
||||||
case driver.AccessWrite:
|
case driver.BufferBindingShaderStorageRead:
|
||||||
acc = gl.WRITE_ONLY
|
|
||||||
case driver.AccessRead:
|
|
||||||
acc = gl.READ_ONLY
|
acc = gl.READ_ONLY
|
||||||
case driver.AccessRead | driver.AccessWrite:
|
case driver.BufferBindingShaderStorageWrite:
|
||||||
|
acc = gl.WRITE_ONLY
|
||||||
|
case driver.BufferBindingShaderStorageRead | driver.BufferBindingShaderStorageWrite:
|
||||||
acc = gl.READ_WRITE
|
acc = gl.READ_WRITE
|
||||||
default:
|
default:
|
||||||
panic("unsupported access bits")
|
panic("unsupported access bits")
|
||||||
}
|
}
|
||||||
var format gl.Enum
|
b.funcs.BindImageTexture(unit, t.obj, 0, false, 0, acc, t.triple.internalFormat)
|
||||||
switch f {
|
|
||||||
case driver.TextureFormatRGBA8:
|
|
||||||
format = gl.RGBA8
|
|
||||||
default:
|
|
||||||
panic("unsupported format")
|
|
||||||
}
|
|
||||||
b.funcs.BindImageTexture(unit, t.obj, 0, false, 0, acc, format)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {
|
func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user