aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2026-05-21 23:18:16 +0200
committerladevieq <ladevie.quentin@gmail.com>2026-05-21 23:18:16 +0200
commit92e09dc06f8c8dd5b7a9323d586f4bf642078727 (patch)
treee88400323165ab55b39b05d5e0f01f6ebc2df7a7
parent8f137322da4220aeb3863ff79724644e7e5152a0 (diff)
Save work on fixing images upload
-rw-r--r--build.bat4
-rw-r--r--include/vk-device-types.hpp4
-rw-r--r--include/vk-utils.hpp2
-rw-r--r--src/gltf.cpp20
-rw-r--r--src/vk-device.cpp18
5 files changed, 28 insertions, 20 deletions
diff --git a/build.bat b/build.bat
index 674eaf3..b6d3810 100644
--- a/build.bat
+++ b/build.bat
@@ -47,7 +47,7 @@ if %MSVC% EQU 1 (
set RELEASE_C_FLAGS=/DNDEBUG /O2
set DEBUG_L_FLAGS=/DEBUG
) else (
- set C_FLAGS=--target=x86_64-pc-windows-msvc -pedantic -I include -I %VULKAN_SDK%\Include -isystem thirdparty -isystem thirdparty\imgui -std=c++20 -DNOMINMAX -c -msse4.1 -Wno-missing-designated-field-initializers
+ set C_FLAGS=--target=x86_64-pc-windows-msvc -Wall -Werror -pedantic -I include -I %VULKAN_SDK%\Include -isystem thirdparty -isystem thirdparty\imgui -std=c++20 -DNOMINMAX -c -msse4.1 -Wno-missing-designated-field-initializers
set DEBUG_C_FLAGS=-DDEBUG -g -O0
set RELEASE_C_FLAGS=-DNDEBUG -O2
@@ -91,7 +91,7 @@ if %MSVC% EQU 1 (
%C_COMPILER% -o %BUILD_DIR%\main.obj %C_FLAGS% src\main.cpp
)
-link %L_FLAGS% /OUT:%BUILD_DIR%\main.exe %BUILD_DIR%\main.obj kernel32.lib user32.lib shlwapi.lib
+link %L_FLAGS% /DEBUG /OUT:%BUILD_DIR%\main.exe %BUILD_DIR%\main.obj kernel32.lib user32.lib
set shaders=ui.vert ui.frag test.comp compute.comp api-test-ui.vert api-test-ui.frag tonemapping.comp transmittance_lut.comp
(for %%s in (%shaders%) do (
diff --git a/include/vk-device-types.hpp b/include/vk-device-types.hpp
index 94f9560..f77d2af 100644
--- a/include/vk-device-types.hpp
+++ b/include/vk-device-types.hpp
@@ -143,8 +143,8 @@ struct device_buffer {
offset = 0U;
}
- u32 offset = 0U;
- u32 allocated_size = 0U;
+ u64 offset = 0U;
+ u64 allocated_size = 0U;
VkBuffer vk_buffer;
VmaAllocation alloc;
VkDeviceAddress device_address = 0U;
diff --git a/include/vk-utils.hpp b/include/vk-utils.hpp
index f26d2a3..c67cf31 100644
--- a/include/vk-utils.hpp
+++ b/include/vk-utils.hpp
@@ -1,6 +1,6 @@
#pragma once
-#ifdef _DEBUG
+#ifdef DEBUG
#define VKCHECK(result) assert((result) == VK_SUCCESS)
#else
#define VKCHECK(result) (void)result
diff --git a/src/gltf.cpp b/src/gltf.cpp
index 3e0af7d..8b5255c 100644
--- a/src/gltf.cpp
+++ b/src/gltf.cpp
@@ -25,11 +25,6 @@ struct buffer_view {
#define GL_FLOAT 0x1406
#define GL_FIXED 0x140C
-#define SCALAR 0x5343414C4152
-#define VEC2 0x56454332
-#define VEC3 0x56454333
-#define VEC4 0x56454334
-
static u32 accessor_type_to_component_count(std::string_view& type) {
if (strncmp("SCALAR", type.data(), type.size()) == 0) {
return 1U;
@@ -166,11 +161,7 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
vkdevice& device = vkdevice::get();
constexpr auto buffers_count = 2U;
- size_t total_size = images.size() * 4096U * 4096 * sizeof(uint32_t);
- // TODO: Fix nasty stuff going on
- // Crash on buffer destruction and load wrong images
- // size_t buffer_size = total_size / 32U;
- size_t buffer_size = total_size / 4U;
+ size_t buffer_size = 256U * MB;
handle<device_buffer> staging_buffers_handle[buffers_count] = {
device.create_buffer({
@@ -178,12 +169,14 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
.usages = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
.memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
.memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ .name = "image upload staging buffer 0",
}),
device.create_buffer({
.size = buffer_size,
.usages = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
.memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
.memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ .name = "image upload staging buffer 1",
}),
};
@@ -194,6 +187,7 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
auto buffer_index = 0U;
auto command_buffer = command_buffers[buffer_index];
auto buffer_handle = staging_buffers_handle[buffer_index];
+ // FIX: when taking a reference to the buffer and we latter swap the buffers we override the referenced buffer
device_buffer& buffer = device.get_buffer(buffer_handle);
command_buffer.start();
@@ -219,7 +213,6 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
u32 size = image.width * image.height * sizeof(uint32_t);
if (buffer.allocated_size + size > buffer.size) {
command_buffer.stop();
-
device.submit(&command_buffer, 1);
buffer_index = (buffer_index + 1U) % buffers_count;
@@ -227,8 +220,8 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
buffer_handle = staging_buffers_handle[buffer_index];
buffer = device.get_buffer(buffer_handle);
buffer.reset();
- // TODO: Remove the wait
- // device.wait();
+ // TODO: Remove wait on device idle, wait on command buffer completion instead
+ device.wait();
command_buffer.start();
}
@@ -245,6 +238,7 @@ static void load_textures(char* path, std::vector<handle<device_texture>>& textu
command_buffer.stop();
device.submit(&command_buffer, 1);
}
+ // TODO: Remove wait on device idle, wait on command buffer completion instead
device.wait();
device.destroy_buffer(staging_buffers_handle[0]);
device.destroy_buffer(staging_buffers_handle[1]);
diff --git a/src/vk-device.cpp b/src/vk-device.cpp
index 6fa3533..9c1b7a4 100644
--- a/src/vk-device.cpp
+++ b/src/vk-device.cpp
@@ -76,7 +76,19 @@ void vkdevice::deinit() {
}
-void vkdevice::wait() { vkDeviceWaitIdle(device); };
+void vkdevice::wait() {
+ vkDeviceWaitIdle(device);
+};
+
+void vkdevice::wait_for_fence(u64 value) {
+ VkSemaphoreWaitInfoKHR semaphore_wait_info {
+ .type = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO_KHR,
+ };
+ semaphore_wait_info.pSemaphores = &semaphore;
+ semaphore_wait_info.semaphoreCount = 1;
+ semaphore_wait_info.pValues = &value;
+ VK_CHECK(vkWaitSemaphoresKHR(device->get_handle(), &semaphore_wait_info, UINT64_MAX));
+}
handle<device_texture> vkdevice::create_texture(const texture_desc& desc) {
device_texture device_texture;
@@ -125,7 +137,9 @@ handle<device_buffer> vkdevice::create_buffer(const buffer_desc& desc) {
.pUserData = nullptr,
};
- VmaAllocationInfo alloc_info{};
+ VmaAllocationInfo alloc_info{
+ .pName = desc.name,
+ };
VKCHECK(vmaCreateBuffer(gpu_allocator, &create_info, &alloc_create_info, &device_buffer.vk_buffer, &device_buffer.alloc, &alloc_info));
vmaSetAllocationName(render_device.get_allocator(), device_buffer.alloc, desc.name);