Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird drawing behavior with G4onG5 with Vulkan backend #830

Open
tcdude opened this issue Dec 3, 2023 · 1 comment
Open

Weird drawing behavior with G4onG5 with Vulkan backend #830

tcdude opened this issue Dec 3, 2023 · 1 comment

Comments

@tcdude
Copy link
Contributor

tcdude commented Dec 3, 2023

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.
@KosLooney
Copy link

KosLooney commented 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:

kinc_g4_set_matrix4(mvp_loc, &mvp_mat);
kinc_g4_set_matrix4(v_loc, &v_mat);
kinc_g4_set_floats(lightPos_loc, (float*)&light_pos, 3);

The constants are written to a vertexConstantBuffer and fragmentConstantBuffer.

static kinc_g5_constant_buffer_t vertexConstantBuffer;
static kinc_g5_constant_buffer_t fragmentConstantBuffer;

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.

kinc_g5_constant_buffer_lock(&vertexConstantBuffer, 0, constantBufferSize);
kinc_g5_constant_buffer_lock(&fragmentConstantBuffer, 0, constantBufferSize);
memcpy(vertexConstantBuffer.data, current_state.vertex_constant_data, constantBufferSize);
memcpy(fragmentConstantBuffer.data, current_state.fragment_constant_data, constantBufferSize);
}
else {
kinc_g5_constant_buffer_lock(&vertexConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize);
kinc_g5_constant_buffer_lock(&fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize);

kinc_g5_command_list_set_vertex_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize);
kinc_g5_command_list_set_fragment_constant_buffer(&commandList, &fragmentConstantBuffer, constantBufferIndex * constantBufferSize, constantBufferSize);

void kinc_g5_command_list_set_fragment_constant_buffer(kinc_g5_command_list_t *list, struct kinc_g5_constant_buffer *buffer, int offset, size_t size) {
lastFragmentConstantBufferOffset = offset;
VkDescriptorSet descriptor_set = getDescriptorSet();
uint32_t offsets[2] = {lastVertexConstantBufferOffset, lastFragmentConstantBufferOffset};
vkCmdBindDescriptorSets(list->impl._buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, currentPipeline->impl.pipeline_layout, 0, 1, &descriptor_set, 2, offsets);
}

The command list is then executed every 100 draw calls, on a vertex_buffer change, kinc_g4_start() or on kinc_g4_end().

if (constantBufferIndex >= constantBufferMultiply || waitAfterNextDraw) {
kinc_g5_command_list_end(&commandList);
kinc_g5_command_list_execute(&commandList);
kinc_g5_command_list_wait_for_execution_to_finish(&commandList);
kinc_g5_command_list_begin(&commandList);
if (windows[current_window].current_render_targets[0] == NULL) {

So at the moment your 1st instance uses all constants and the rest are only using off_loc and rot_loc.
1st cube:
1st_call
2nd cube:
2nd_call

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:
1st_call_2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants