diff --git a/gpu/compute.go b/gpu/compute.go index d01cbeed..6de65c21 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -1278,12 +1278,12 @@ func (g *compute) render(images *textureAtlas, dst driver.Texture, cpuDst cpu.Im if !g.useCPU { g.ctx.BeginCompute() - g.ctx.BindImageTexture(kernel4OutputUnit, dst, driver.AccessWrite, driver.TextureFormatRGBA8) + g.ctx.BindImageTexture(kernel4OutputUnit, dst) img := g.output.nullMaterials if images != nil { img = images.image } - g.ctx.BindImageTexture(kernel4AtlasUnit, img, driver.AccessRead, driver.TextureFormatRGBA8) + g.ctx.BindImageTexture(kernel4AtlasUnit, img) } else { *g.output.descriptors.Binding2() = cpuDst if images != nil { diff --git a/gpu/internal/d3d11/d3d11_windows.go b/gpu/internal/d3d11/d3d11_windows.go index c5bcfc9c..a30f6a23 100644 --- a/gpu/internal/d3d11/d3d11_windows.go +++ b/gpu/internal/d3d11/d3d11_windows.go @@ -582,12 +582,12 @@ func (b *Backend) prepareDraw() { 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) - if access&driver.AccessWrite == 0 { - b.ctx.CSSetShaderResources(uint32(unit), t.resView) - } else { + if t.uaView != nil { b.ctx.CSSetUnorderedAccessViews(uint32(unit), t.uaView) + } else { + b.ctx.CSSetShaderResources(uint32(unit), t.resView) } } diff --git a/gpu/internal/driver/driver.go b/gpu/internal/driver/driver.go index a67883c7..b07cbb50 100644 --- a/gpu/internal/driver/driver.go +++ b/gpu/internal/driver/driver.go @@ -42,7 +42,7 @@ type Device interface { BindTexture(unit int, t Texture) BindVertexBuffer(b Buffer, offset int) BindIndexBuffer(b Buffer) - BindImageTexture(unit int, texture Texture, access AccessBits, format TextureFormat) + BindImageTexture(unit int, texture Texture) BindUniforms(buf Buffer) BindStorageBuffer(binding int, buf Buffer) @@ -91,8 +91,6 @@ type BlendDesc struct { SrcFactor, DstFactor BlendFactor } -type AccessBits uint8 - type BlendFactor uint8 type Topology uint8 @@ -164,11 +162,6 @@ const ( TextureFormatOutput ) -const ( - AccessRead AccessBits = 1 << iota - AccessWrite -) - const ( FilterNearest TextureFilter = iota FilterLinear diff --git a/gpu/internal/metal/metal_darwin.go b/gpu/internal/metal/metal_darwin.go index 96e17258..1c29fafb 100644 --- a/gpu/internal/metal/metal_darwin.go +++ b/gpu/internal/metal/metal_darwin.go @@ -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) } diff --git a/gpu/internal/opengl/opengl.go b/gpu/internal/opengl/opengl.go index 08879fc5..7436b225 100644 --- a/gpu/internal/opengl/opengl.go +++ b/gpu/internal/opengl/opengl.go @@ -96,14 +96,15 @@ type timer struct { } type texture struct { - backend *Backend - obj gl.Texture - fbo gl.Framebuffer - hasFBO bool - triple textureTriple - width int - height int - foreign bool + backend *Backend + obj gl.Texture + fbo gl.Framebuffer + hasFBO bool + triple textureTriple + width int + height int + bindings driver.BufferBinding + foreign bool } 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) { 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 { case driver.TextureFormatFloat: tex.triple = b.floatTriple @@ -772,27 +773,20 @@ func (b *Backend) DispatchCompute(x, y, z int) { 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) var acc gl.Enum - switch access { - case driver.AccessWrite: - acc = gl.WRITE_ONLY - case driver.AccessRead: + switch t.bindings & (driver.BufferBindingShaderStorageRead | driver.BufferBindingShaderStorageWrite) { + case driver.BufferBindingShaderStorageRead: 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 default: panic("unsupported access bits") } - var format gl.Enum - switch f { - case driver.TextureFormatRGBA8: - format = gl.RGBA8 - default: - panic("unsupported format") - } - b.funcs.BindImageTexture(unit, t.obj, 0, false, 0, acc, format) + b.funcs.BindImageTexture(unit, t.obj, 0, false, 0, acc, t.triple.internalFormat) } func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {