{{ message }}
Repository navigation
Weird drawing behavior with G4onG5 with Vulkan backend #830
Copy link
Copy link
Open
Description
Describe the bug
Drawing the same indexed vertices multiple times with some uniforms set only once per pipeline/frame and other uniforms set differently for each draw call, the resulting render looks strange (out of sync, appears to be drawn over the span of multiple frames).
using G4onG5 with Vulkan backend
rec-2023-12-03--15-17-42.mp4
using OpenGL backend
rec-2023-12-03--15-22-18.mp4
To Reproduce
A repro repo can be found here: weird-vulkan-behavior
Expected behavior
See the video where the OpenGL backend is being used.
Execution Environment:
- Host system (where you compile your code): Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz - Linux 6.6.3-zen1-1-zen Update VertexBufferImpl.cpp #1 ZEN SMP PREEMPT_DYNAMIC Wed, 29 Nov 2023 00:40:39 +0000 x86_64 GNU/Linux
- Target system (where you run your code): same as host
- IDE and/or compiler used: vscode
- Kinc revision: be46b46
- Kinc build output:
Kinc/make --debug --compile -g vulkan
Using Kinc (be46b461) from /home/tc/code/weird-vulkan-behavior/Kinc
kfile found.
Creating Linux project files.
Compiling shader 1 of 4 (shader.frag).
Compiling shader 2 of 4 (shader.vert).
Compiling shader 3 of 4 (g1.frag).
Compiling shader 4 of 4 (g1.vert).
Compiling...
[1/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF posixunit.o.d -c ../../Kinc/Backends/System/POSIX/Sources/kinc/backend/posixunit.c -o posixunit.o
[2/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF shader.o.d -c ../../Sources/shader.c -o shader.o
[3/22] g++ -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF rootunit_.o.d -c ../../Kinc/Sources/kinc/rootunit.cpp -o rootunit_.o
[4/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF compute.o.d -c ../../Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.c -o compute.o
[5/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF audio.o.d -c ../../Kinc/Sources/kinc/audio2/audio.c -o audio.o
[6/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF g4ong5unit.o.d -c ../../Kinc/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/g4ong5unit.c -o g4ong5unit.o
[7/22] g++ -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF graphics_kore.o.d -c ../../Kinc/Sources/kinc/graphics2/graphics_kore.cpp -o graphics_kore.o
[8/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF graphics.o.d -c ../../Kinc/Sources/kinc/graphics1/graphics.c -o graphics.o
[9/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF a1unit.o.d -c ../../Kinc/Sources/kinc/audio1/a1unit.c -o a1unit.o
[10/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF graphics_soft.o.d -c ../../Kinc/Sources/kinc/graphics2/graphics_soft.c -o graphics_soft.o
[11/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF g4unit.o.d -c ../../Kinc/Sources/kinc/graphics4/g4unit.c -o g4unit.o
[12/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF g5unit.o.d -c ../../Kinc/Sources/kinc/graphics5/g5unit.c -o g5unit.o
[13/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF linuxunit.o.d -c ../../Kinc/Backends/System/Linux/Sources/kinc/backend/linuxunit.c -o linuxunit.o
[14/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF inputunit.o.d -c ../../Kinc/Sources/kinc/input/inputunit.c -o inputunit.o
[15/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF iounit.o.d -c ../../Kinc/Sources/kinc/io/iounit.c -o iounit.o
[16/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF mathunit.o.d -c ../../Kinc/Sources/kinc/math/mathunit.c -o mathunit.o
[17/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF rootunit.o.d -c ../../Kinc/Sources/kinc/rootunit.c -o rootunit.o
[18/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF networkunit.o.d -c ../../Kinc/Sources/kinc/network/networkunit.c -o networkunit.o
[19/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF waylandunit.o.d -c ../wayland/wayland-generated/waylandunit.c -o waylandunit.o
[20/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF vulkanunit.o.d -c ../../Kinc/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/vulkanunit.c -o vulkanunit.o
[21/22] gcc -g -I../../Kinc/Sources -I../../Kinc/Backends/System/Linux/Sources -I../../Kinc/Backends/System/POSIX/Sources -I../wayland -I../../Kinc/Backends/Graphics5/Vulkan/Sources -I../../Kinc/Backends/Graphics4/G4onG5/Sources -DKINC_NO_WAYLAND -DKORE_G1 -DKORE_G2 -DKORE_G3 -DKORE_A1 -DKORE_A2 -DKORE_LZ4X -DKORE_VULKAN -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -DKORE_G4 -DKORE_G5 -DKORE_G4ONG5 -MD -MF stb_vorbis.o.d -c ../../Kinc/Sources/kinc/libs/stb_vorbis.c -o stb_vorbis.o
[22/22] g++ -o ShaderTest -g shader.o g4ong5unit.o compute.o vulkanunit.o linuxunit.o posixunit.o rootunit.o rootunit_.o a1unit.o audio.o graphics.o graphics_kore.o graphics_soft.o g4unit.o g5unit.o inputunit.o iounit.o stb_vorbis.o mathunit.o networkunit.o waylandunit.o -static-libgcc -static-libstdc++ -pthread -lasound -ldl -ludev -lvulkan
Build time: 0m 2s
Done.
- Application output (if it runs):
Running with Vulkan validation layers enabled.
Reactions are currently unavailable
You can’t perform that action at this time.

Activity
KosLooney commentedon Jan 5, 2024
It happens here too (amd + windows).
It looks like you have to put these uniform constants in the for loop to make it work as intended:
The constants are written to a vertexConstantBuffer and fragmentConstantBuffer.
https://github.com/Kode/Kinc/blob/6c012b7878c5ff8c8bc9145df06edaff3ed23877/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h#L35-L36
Each call to kinc_g4_draw_indexed_vertices on G4onG5 uses a offset (constantBufferIndex*constantBufferSize) from these buffers and they are then linked with a g5 command.
https://github.com/Kode/Kinc/blob/6c012b7878c5ff8c8bc9145df06edaff3ed23877/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h#L229-L237
https://github.com/Kode/Kinc/blob/6c012b7878c5ff8c8bc9145df06edaff3ed23877/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h#L171-L172
https://github.com/Kode/Kinc/blob/6c012b7878c5ff8c8bc9145df06edaff3ed23877/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/commandlist.c.h#L799-L805
The command list is then executed every 100 draw calls, on a vertex_buffer change, kinc_g4_start() or on kinc_g4_end().
https://github.com/Kode/Kinc/blob/6c012b7878c5ff8c8bc9145df06edaff3ed23877/Backends/Graphics4/G4onG5/Sources/kinc/backend/graphics4/G4.c.h#L177-L182
So at the moment your 1st instance uses all constants and the rest are only using off_loc and rot_loc.


1st cube:
2nd cube:
Edit:

The cubes eventually appear because each frame the mvp and v uniform constants are set on a different offset location
1st cube now has offset 344064: