#Geometry Shader Bug

15 messages · Page 1 of 1 (latest)

dark holly
#

I've been working with two different PCs on a Vulkan program, recently implementing a Geometry Shader. On PC #2, the shader works fine, but on PC #1, it runs into some unexplainable glitch.
I did some testing and found the glitch is occurs whenever EndPrimitive is called.

For reference, the following (incorrect) code produces image 1, the (desired) image.

#version 430
#extension GL_EXT_scalar_block_layout: enable
layout (triangles) in;
layout (triangle_strip, max_vertices = 256) out;

layout(location = 0) in vec4 fragColor[];
layout(location = 1) in vec2 fragTexCoord[];
layout(location = 2) flat in int texIndex[];
layout(location = 3) in ivec2 texRepeat[];

layout(location = 0) out vec4 fragColorOut;
layout(location = 1) out vec2 fragTexCoordOut;
layout(location = 2) flat out int texIndexOut;


void drawVertex(int i) {

    fragColorOut = vec4(fragColor[i].x,fragColor[i].y,fragColor[i].z,fragColor[i].a);
    fragTexCoordOut = fragTexCoord[i];
    texIndexOut = texIndex[i];
    EmitVertex();
}

void main() {
    gl_Position = gl_in[0].gl_Position;
    drawVertex(0);
    gl_Position = gl_in[1].gl_Position;
    drawVertex(1);
    gl_Position = gl_in[2].gl_Position;
    drawVertex(2);
    return;
}

However, whenever I add EndPrimitive() right before the return statement I end up with the second deformed image. This only occurs on 1 out of 2 of my Computers, and I'm inclined to believe it might be a driver bug. So far the only validation errors on PC #1, are the benign invalid manifest file messages. Would appreciate some feedback on this issue.

hasty egret
#

Different GPUs?

dark holly
#

Yes, give me a sec, I'll post the GPU info

hasty egret
#

Do you really output 256 vertices per GS run?

#

If not, try and lower that limit. I've had high max_vertices counts cause hardware problems in the past.

dark holly
#

Lowered it to 64. Appears to have fixed the issue.

#

Reason I had it high was because the Geometry Shader's main purpose was for repeating generated quads without having to allocate more index data.

hasty egret
#

not sure if you're aware, but geometry shaders should usually be avoided

dark holly
#

I've heard about that

hasty egret
#

aside from running into aribtrary implementation limitations they can also trigger slow software paths

dark holly
#

Yeah, the main feature I wanted to implement was the ability to repeat sprites like so,

#

The issue with using the fragment shader I had is that, as far as I'm aware, it can only repeat the entire texture, rather than a specific region.

#

Though if there's another way to address this problem, outside of duplicate Vertex Data, I'd be interested in hearing.

hasty egret
#

if you're using a texture atlas, array textures or texture arrays may be an alternative

dark holly
#

I belive I do have, a texture array mapped to my fragment shader, layout(binding = 1) uniform sampler2D texSampler[64];, if this is what you're referring to. Would there be a way to command it to sample a specific portion only?