Coder Social home page Coder Social logo

Comments (7)

floooh avatar floooh commented on August 24, 2024

That's indeed weird. The info you posted looks good as far as I can see.

Also, what GPU and driver version do you have?

If i use it for some other random calculation (for example uv *= amodel3.xz) then it stays.

This is also crazy... I had some problems in the past with glslangValidator and or SPIRVCross to strip unused attributes, but I haven't seen this sort of behaviour from GL drivers so far.

If it turns out that GL drivers are allowed to remove "unused" attributes then I guess the sokol_gfx.h GL backend needs to be a bit more flexible (I'm not sure if it is already enough to just turn the error into a warning, theoretically the vertex attribute should then be disabled, and skipped in _sg_gl_apply_bindings(), might be worth a try though)

sokol/sokol_gfx.h

Lines 8876 to 8923 in 5b6b743

// vertex attributes
for (GLuint attr_index = 0; attr_index < (GLuint)_sg.limits.max_vertex_attrs; attr_index++) {
_sg_gl_attr_t* attr = &bnd->pip->gl.attrs[attr_index];
_sg_gl_cache_attr_t* cache_attr = &_sg.gl.cache.attrs[attr_index];
bool cache_attr_dirty = false;
int vb_offset = 0;
GLuint gl_vb = 0;
if (attr->vb_index >= 0) {
// attribute is enabled
SOKOL_ASSERT(attr->vb_index < bnd->num_vbs);
_sg_buffer_t* vb = bnd->vbs[attr->vb_index];
SOKOL_ASSERT(vb);
gl_vb = vb->gl.buf[vb->cmn.active_slot];
vb_offset = bnd->vb_offsets[attr->vb_index] + attr->offset;
if ((gl_vb != cache_attr->gl_vbuf) ||
(attr->size != cache_attr->gl_attr.size) ||
(attr->type != cache_attr->gl_attr.type) ||
(attr->normalized != cache_attr->gl_attr.normalized) ||
(attr->stride != cache_attr->gl_attr.stride) ||
(vb_offset != cache_attr->gl_attr.offset) ||
(cache_attr->gl_attr.divisor != attr->divisor))
{
_sg_gl_cache_bind_buffer(GL_ARRAY_BUFFER, gl_vb);
glVertexAttribPointer(attr_index, attr->size, attr->type, attr->normalized, attr->stride, (const GLvoid*)(GLintptr)vb_offset);
_sg_stats_add(gl.num_vertex_attrib_pointer, 1);
glVertexAttribDivisor(attr_index, (GLuint)attr->divisor);
_sg_stats_add(gl.num_vertex_attrib_divisor, 1);
cache_attr_dirty = true;
}
if (cache_attr->gl_attr.vb_index == -1) {
glEnableVertexAttribArray(attr_index);
_sg_stats_add(gl.num_enable_vertex_attrib_array, 1);
cache_attr_dirty = true;
}
} else {
// attribute is disabled
if (cache_attr->gl_attr.vb_index != -1) {
glDisableVertexAttribArray(attr_index);
_sg_stats_add(gl.num_disable_vertex_attrib_array, 1);
cache_attr_dirty = true;
}
}
if (cache_attr_dirty) {
cache_attr->gl_attr = *attr;
cache_attr->gl_attr.offset = vb_offset;
cache_attr->gl_vbuf = gl_vb;
}
}

from sokol.

pseregiet avatar pseregiet commented on August 24, 2024

That's indeed weird. The info you posted looks good as far as I can see.

Also, what GPU and driver version do you have?

If i use it for some other random calculation (for example uv *= amodel3.xz) then it stays.

This is also crazy... I had some problems in the past with glslangValidator and or SPIRVCross to strip unused attributes, but I haven't seen this sort of behaviour from GL drivers so far.

If it turns out that GL drivers are allowed to remove "unused" attributes then I guess the sokol_gfx.h GL backend needs to be a bit more flexible (I'm not sure if it is already enough to just turn the error into a warning, theoretically the vertex attribute should then be disabled, and skipped in _sg_gl_apply_bindings(), might be worth a try though)

sokol/sokol_gfx.h

Lines 8876 to 8923 in 5b6b743

// vertex attributes
for (GLuint attr_index = 0; attr_index < (GLuint)_sg.limits.max_vertex_attrs; attr_index++) {
_sg_gl_attr_t* attr = &bnd->pip->gl.attrs[attr_index];
_sg_gl_cache_attr_t* cache_attr = &_sg.gl.cache.attrs[attr_index];
bool cache_attr_dirty = false;
int vb_offset = 0;
GLuint gl_vb = 0;
if (attr->vb_index >= 0) {
// attribute is enabled
SOKOL_ASSERT(attr->vb_index < bnd->num_vbs);
_sg_buffer_t* vb = bnd->vbs[attr->vb_index];
SOKOL_ASSERT(vb);
gl_vb = vb->gl.buf[vb->cmn.active_slot];
vb_offset = bnd->vb_offsets[attr->vb_index] + attr->offset;
if ((gl_vb != cache_attr->gl_vbuf) ||
(attr->size != cache_attr->gl_attr.size) ||
(attr->type != cache_attr->gl_attr.type) ||
(attr->normalized != cache_attr->gl_attr.normalized) ||
(attr->stride != cache_attr->gl_attr.stride) ||
(vb_offset != cache_attr->gl_attr.offset) ||
(cache_attr->gl_attr.divisor != attr->divisor))
{
_sg_gl_cache_bind_buffer(GL_ARRAY_BUFFER, gl_vb);
glVertexAttribPointer(attr_index, attr->size, attr->type, attr->normalized, attr->stride, (const GLvoid*)(GLintptr)vb_offset);
_sg_stats_add(gl.num_vertex_attrib_pointer, 1);
glVertexAttribDivisor(attr_index, (GLuint)attr->divisor);
_sg_stats_add(gl.num_vertex_attrib_divisor, 1);
cache_attr_dirty = true;
}
if (cache_attr->gl_attr.vb_index == -1) {
glEnableVertexAttribArray(attr_index);
_sg_stats_add(gl.num_enable_vertex_attrib_array, 1);
cache_attr_dirty = true;
}
} else {
// attribute is disabled
if (cache_attr->gl_attr.vb_index != -1) {
glDisableVertexAttribArray(attr_index);
_sg_stats_add(gl.num_disable_vertex_attrib_array, 1);
cache_attr_dirty = true;
}
}
if (cache_attr_dirty) {
cache_attr->gl_attr = *attr;
cache_attr->gl_attr.offset = vb_offset;
cache_attr->gl_vbuf = gl_vb;
}
}

I'll just add that despite this attribute being apparently optimised out my code still runs fine. If a whole line of a matrix was gone it would surely produce a bogus transformation matrix. RenderDoc's Mesh View shows the attribute is gone:
image

from sokol.

pseregiet avatar pseregiet commented on August 24, 2024

Oh and my driver is

OpenGL vendor string: AMD
OpenGL renderer string: AMD Radeon RX 590 Series (polaris10, LLVM 16.0.6, DRM 3.54, 6.5.9-zen2-1-zen)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 23.2.1-arch1.2
OpenGL core profile shading language version string: 4.60

from sokol.

Interrupt avatar Interrupt commented on August 24, 2024

I just ran into this when compiling a Zig app that loads a mesh but only has a basic shader that does not use the normals or tangents passed in. When I remove those vertex attributes from the layout, the mesh loads and renders fine.

from sokol.

alichraghi avatar alichraghi commented on August 24, 2024

it seems like the problem is shdc ignores unused variables (uniform/in/out) so the information never get added into shader descriptor

from sokol.

floooh avatar floooh commented on August 24, 2024

Unfortunately this stripping of unused uniforms is something that's out of my control. It may happen in the first compile pass from GLSL to SPIRV, and I also had it happen as secondary effect of the SPIRV-Tools dead code elimination (although I disabled all optimizer passes I could find which involve DCE).

Even at runtime, the GLSL compilers in GL drivers are free to remove unused uniforms so that they don't show up in glGetUniformLocation.

from sokol.

pseregiet avatar pseregiet commented on August 24, 2024

it seems like the problem is shdc ignores unused variables (uniform/in/out) so the information never get added into shader descriptor

The fact openGL strips unused uniforms or attributes is not strange. What is weird is that if you look at my original code the attributes that was "removed" is clearly used. And at the same time all rendering looks correct as if it was present. The attribute that was removed was part of a matrix, so if it was gone, undefined, filed with random data I would surely have corrupted transformations.

from sokol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.