From 41e812d5e82bfd6aaa2e1be9bb4cd3b8753b39e1 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 16 Sep 2021 17:57:09 +0200 Subject: [PATCH] gpu: [compute] always bind valid materials texture Currently, we run kernel4.comp with whatever texture was bound (or none) when there are no materials in the set of layers. However, Vulkan require every image binding to a compute shader to be non-null and valid. This change works around that limitation by binding a small dummy texture when no materials are needed. Signed-off-by: Elias Naur --- gpu/compute.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gpu/compute.go b/gpu/compute.go index 01cd373c..bd177fd1 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -73,6 +73,8 @@ type compute struct { layerVertices []layerVertex descriptors *piet.Kernel4DescriptorSetLayout + + nullMaterials driver.Texture } // imgAllocs maps imageOpData.handles to allocs. imgAllocs map[interface{}]*atlasAlloc @@ -409,6 +411,12 @@ func newCompute(ctx driver.Device) (*compute, error) { conf: new(config), memHeader: new(memoryHeader), } + null, err := ctx.NewTexture(driver.TextureFormatRGBA8, 1, 1, driver.FilterNearest, driver.FilterNearest, driver.BufferBindingShaderStorageRead) + if err != nil { + g.Release() + return nil, err + } + g.output.nullMaterials = null shaders := []struct { prog *computeProgram src shader.Sources @@ -1275,9 +1283,11 @@ 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) + img := g.output.nullMaterials if images != nil { - g.ctx.BindImageTexture(kernel4AtlasUnit, images.image, driver.AccessRead, driver.TextureFormatRGBA8) + img = images.image } + g.ctx.BindImageTexture(kernel4AtlasUnit, img, driver.AccessRead, driver.TextureFormatRGBA8) } else { *g.output.descriptors.Binding2() = cpuDst if images != nil { @@ -1478,6 +1488,7 @@ func (g *compute) Release() { Release() } res := []resource{ + g.output.nullMaterials, &g.programs.elements, &g.programs.tileAlloc, &g.programs.pathCoarse,