Skip to main content
edited body
Source Link

I found it! The issue stems from a problem in the swap. When we swap buffers, the output buffer becomes the input and the input buffer becomes the output. However, the buffer that is now the output was not updated to match!

To illustrate: Init: In Out 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 First Iteration (remove north corners): In Out 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Swap In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Second iteration (remove east corners): In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 01 1 1 0 ... (and so on) 

By modifying skeleton() in the compute shader to copy image_0 to image_1, prior to anything else, the algorithm works correctly.

void skeleton() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); uint neighborhood[9]; neighborhood[0] = getVal(getPos(x, y)); image_1[getPos(x, y)] = image_0[getPos(x, y)]; // Only consider cases where the center is 1 if (neighborhood[0] != 1) { image_1[0] = 0; return; } ... 

Additionally, I cleaned up the code quite a bit. For example, you can set the in and out buffers via glBindBufferBase() prior to the dispatch call.

I found it! The issue stems from a problem in the swap. When we swap buffers, the output buffer becomes the input and the input buffer becomes the output. However, the buffer that is now the output was not updated to match!

To illustrate: Init: In Out 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 First Iteration (remove north corners): In Out 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Swap In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Second iteration (remove east corners): In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 ... (and so on) 

By modifying skeleton() in the compute shader to copy image_0 to image_1, prior to anything else, the algorithm works correctly.

void skeleton() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); uint neighborhood[9]; neighborhood[0] = getVal(getPos(x, y)); image_1[getPos(x, y)] = image_0[getPos(x, y)]; // Only consider cases where the center is 1 if (neighborhood[0] != 1) { image_1[0] = 0; return; } ... 

Additionally, I cleaned up the code quite a bit. For example, you can set the in and out buffers via glBindBufferBase() prior to the dispatch call.

I found it! The issue stems from a problem in the swap. When we swap buffers, the output buffer becomes the input and the input buffer becomes the output. However, the buffer that is now the output was not updated to match!

To illustrate: Init: In Out 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 First Iteration (remove north corners): In Out 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Swap In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Second iteration (remove east corners): In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 ... (and so on) 

By modifying skeleton() in the compute shader to copy image_0 to image_1, prior to anything else, the algorithm works correctly.

void skeleton() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); uint neighborhood[9]; neighborhood[0] = getVal(getPos(x, y)); image_1[getPos(x, y)] = image_0[getPos(x, y)]; // Only consider cases where the center is 1 if (neighborhood[0] != 1) { image_1[0] = 0; return; } ... 

Additionally, I cleaned up the code quite a bit. For example, you can set the in and out buffers via glBindBufferBase() prior to the dispatch call.

Source Link

I found it! The issue stems from a problem in the swap. When we swap buffers, the output buffer becomes the input and the input buffer becomes the output. However, the buffer that is now the output was not updated to match!

To illustrate: Init: In Out 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 First Iteration (remove north corners): In Out 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 Swap In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Second iteration (remove east corners): In Out 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 ... (and so on) 

By modifying skeleton() in the compute shader to copy image_0 to image_1, prior to anything else, the algorithm works correctly.

void skeleton() { int x = int(gl_GlobalInvocationID.x); int y = int(gl_GlobalInvocationID.y); uint neighborhood[9]; neighborhood[0] = getVal(getPos(x, y)); image_1[getPos(x, y)] = image_0[getPos(x, y)]; // Only consider cases where the center is 1 if (neighborhood[0] != 1) { image_1[0] = 0; return; } ... 

Additionally, I cleaned up the code quite a bit. For example, you can set the in and out buffers via glBindBufferBase() prior to the dispatch call.