~eliasnaur/gio

9e8fe5305be3420b166573e73a26d0b447c2d7f3 — Elias Naur 2 years ago 41f3a7e
gpu/internal/opengl: don't panic when uniforms are optimized out

glGetUniformLocation can return -1 (not found) for uniforms that have
been optimized out during linking of a GPU program. This happens because
the default renderer compile multiple program from the same generic
template.

Updates gio#280

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 5 insertions(+), 9 deletions(-)

M gpu/internal/opengl/opengl.go
M gpu/internal/opengl/opengl.go => gpu/internal/opengl/opengl.go +5 -9
@@ 954,14 954,6 @@ func (b *Backend) newProgram(desc driver.PipelineDesc) (*program, error) {
	return prog, nil
}

func lookupUniform(funcs *gl.Functions, p gl.Program, loc shader.UniformLocation) uniformLocation {
	u := funcs.GetUniformLocation(p, loc.Name)
	if !u.Valid() {
		panic(fmt.Errorf("uniform %q not found", loc.Name))
	}
	return uniformLocation{uniform: u, offset: loc.Offset, typ: loc.Type, size: loc.Size}
}

func (b *Backend) BindStorageBuffer(binding int, buf driver.Buffer) {
	bf := buf.(*buffer)
	if bf.typ&(driver.BufferBindingShaderStorageRead|driver.BufferBindingShaderStorageWrite) == 0 {


@@ 995,7 987,8 @@ func (p *program) Release() {
func (u *uniforms) setup(funcs *gl.Functions, p gl.Program, uniformSize int, uniforms []shader.UniformLocation) {
	u.locs = make([]uniformLocation, len(uniforms))
	for i, uniform := range uniforms {
		u.locs[i] = lookupUniform(funcs, p, uniform)
		loc := funcs.GetUniformLocation(p, uniform.Name)
		u.locs[i] = uniformLocation{uniform: loc, offset: uniform.Offset, typ: uniform.Type, size: uniform.Size}
	}
	u.size = uniformSize
}


@@ 1006,6 999,9 @@ func (p *uniforms) update(funcs *gl.Functions, buf *buffer) {
	}
	data := buf.data
	for _, u := range p.locs {
		if !u.uniform.Valid() {
			continue
		}
		data := data[u.offset:]
		switch {
		case u.typ == shader.DataTypeFloat && u.size == 1: