forked from joejulian/gio
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 {
|
||||
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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user