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:
Elias Naur
2021-09-19 20:27:23 +02:00
parent 0bdd24c51e
commit 1f0f88dbd3
5 changed files with 25 additions and 38 deletions
+2 -2
View File
@@ -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 {
+4 -4
View File
@@ -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)
} }
} }
+1 -8
View File
@@ -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
+1 -1
View File
@@ -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)
} }
+17 -23
View File
@@ -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) {