aboutsummaryrefslogtreecommitdiffstats
path: root/include/api-test
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2025-12-24 15:35:21 +0100
committerladevieq <ladevie.quentin@gmail.com>2025-12-24 15:35:21 +0100
commitb4d24e8f2cb4838acc0b827f007e7faa609039ba (patch)
treeba6504b67923789d84b2473eb4e14f7002e34ab7 /include/api-test
parentc29105b461135f3909cca0308fb05715cee45763 (diff)
Use build.bat for building
Everything is included in main.cpp Do not rely on vcpkg anymore
Diffstat (limited to 'include/api-test')
-rw-r--r--include/api-test/freelist.hpp56
-rw-r--r--include/api-test/handle.hpp2
-rw-r--r--include/api-test/vk-device-types.hpp11
-rw-r--r--include/api-test/vk-device.hpp12
4 files changed, 51 insertions, 30 deletions
diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp
index 3d0324d..cbcd56d 100644
--- a/include/api-test/freelist.hpp
+++ b/include/api-test/freelist.hpp
@@ -15,17 +15,20 @@ class freelist {
}
handle<T> add(const T& item) {
- auto id = elements[0U].next_free;
+ // auto id = elements[0U].next_free;
+ auto id = next_free_id;
- if (id == invalid_id) {
+ if (id == freelist<T>::invalid_id) {
grow(elements.size());
- id = elements[0U].next_free;
+ // id = elements[0U].next_free;
+ id = next_free_id;
}
auto& element = elements[id];
- elements[0U].next_free = element.next_free;
+ next_free_id = element.next_free;
+ // elements[0U].next_free = element.next_free;
element.item = std::move(item);
return { id, ++element.generation };
@@ -33,8 +36,10 @@ class freelist {
void remove(handle<T> handle) {
assert(handle.generation == elements[handle.id].generation);
- elements[handle.id].next_free = elements[0U].next_free;
- elements[0U].next_free = handle.id;
+ // elements[handle.id].next_free = elements[0U].next_free;
+ // elements[0U].next_free = handle.id;
+ elements[handle.id].next_free = next_free_id;
+ next_free_id = handle.id;
}
T& operator[](handle<T> handle) {
@@ -47,12 +52,13 @@ class freelist {
return elements[handle.id].item;
}
- static constexpr uint32_t invalid_id = -1;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
private:
void grow(size_t grow_size) {
auto size = elements.size();
- uint32_t next_free = size;
+ uint32_t next_free = static_cast<uint32_t>(size);
+ next_free_id = next_free;
elements.reserve(size + grow_size);
@@ -64,18 +70,19 @@ private:
);
}
- elements.back().next_free = -1U;
+ elements.back().next_free = freelist<T>::invalid_id;
}
struct element {
union {
T item;
- uint32_t next_free = -1;
+ uint32_t next_free = freelist<T>::invalid_id;
};
uint32_t generation = 0U;
};
std::vector<element> elements;
+ uint32_t next_free_id;
};
template<const size_t initial_size = default_element_count>
@@ -87,51 +94,58 @@ class idlist {
}
handle<void> add() {
- auto id = elements[0U].next_free;
+ // auto id = elements[0U].next_free;
+ auto id = next_free_id;
- if (id == invalid_id) {
+ if (id == idlist<T>::invalid_id) {
grow(elements.size());
- id = elements[0U].next_free;
+ // id = elements[0U].next_free;
+ id = next_free_id;
}
auto& element = elements[id];
+ next_free_id = element.next_free;
elements[0U].next_free = element.next_free;
- element.next_free = -1;
+ element.next_free = idlist<T>::invalid_id;
return { id, ++element.generation };
}
void remove(handle<void> handle) {
assert(handle.generation == elements[handle.id].generation);
- elements[handle.id].next_free = elements[0U].next_free;
- elements[0U].next_free = handle.id;
+ // elements[handle.id].next_free = elements[0U].next_free;
+ // elements[0U].next_free = handle.id;
+ elements[handle.id].next_free = next_free_id;
+ next_free_id = handle.id;
}
- static constexpr uint32_t invalid_id = -1;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
private:
void grow(size_t grow_size) {
auto size = elements.size();
- uint32_t next_free = size;
+ uint32_t next_free = static_cast<uint32_t>(size);
+ next_free_id = next_free;
elements.reserve(size + grow_size);
for (auto id { 0U }; id < initial_size; id++) {
elements.push_back(
{
- .next_free = static_cast<uint32_t>(++next_free % initial_size),
+ .next_free = static_cast<uint32_t>(++next_free% initial_size),
}
);
}
- elements.back().next_free = -1U;
+ elements.back().next_free = idlist<T>::invalid_id;
}
struct element {
- uint32_t next_free = -1;
+ uint32_t next_free = idlist<T>::invalid_id;
uint32_t generation = 0U;
};
std::vector<element> elements;
+ uint32_t next_free_id;
};
diff --git a/include/api-test/handle.hpp b/include/api-test/handle.hpp
index f07776b..2c52c01 100644
--- a/include/api-test/handle.hpp
+++ b/include/api-test/handle.hpp
@@ -18,7 +18,7 @@ struct handle {
[[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; }
- static constexpr uint32_t invalid_id = -1U;
+ static constexpr uint32_t invalid_id = UINT32_MAX;
// static constexpr handle<U> invalid_handle {};
};
diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp
index dd8348b..eddf40c 100644
--- a/include/api-test/vk-device-types.hpp
+++ b/include/api-test/vk-device-types.hpp
@@ -24,6 +24,7 @@ struct texture_desc {
VkFormat format;
VkImageType type;
VkImage vk_image = nullptr;
+ const char* name = nullptr;
static constexpr auto max_mips = 16U;
};
@@ -111,11 +112,14 @@ struct buffer_desc {
uint32_t memory_usage;
};
+#define ALIGN(value, alignment) \
+ (((value) + ((alignment) - 1)) & ~((alignment) - 1))
+
struct device_buffer {
template<typename T>
T* allocate() {
// size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00;
- size_t alloc_size = sizeof(T);
+ size_t alloc_size = ALIGN(sizeof(T), 16);
if (offset + alloc_size > size) {
reset();
}
@@ -127,6 +131,7 @@ struct device_buffer {
void* allocate(uint64_t alloc_size) {
// size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00;
+ alloc_size = ALIGN(alloc_size, 16);
if (offset + alloc_size > size) {
reset();
}
@@ -140,7 +145,7 @@ struct device_buffer {
offset = 0U;
}
- uint32_t offset = 0U;
+ uint64_t offset = 0U;
VkBuffer vk_buffer;
VmaAllocation alloc;
VkDeviceAddress device_address = 0U;
@@ -154,10 +159,12 @@ struct graphics_pipeline_desc {
std::span<VkFormat> color_attachments_format;
VkFormat depth_attachment_format;
VkFormat stencil_attachment_format;
+ const char* name;
};
struct compute_pipeline_desc {
std::span<uint8_t> cs_code;
+ const char* name;
};
struct device_pipeline {
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp
index dc46e1a..1b04bb3 100644
--- a/include/api-test/vk-device.hpp
+++ b/include/api-test/vk-device.hpp
@@ -42,7 +42,7 @@ class vkdevice {
handle<device_surface> create_surface(const surface_desc& desc);
- handle<device_semaphore> create_semaphore(const semaphore_desc& desc);
+ handle<device_semaphore> create_semaphore(const semaphore_desc& desc, const char* name);
void destroy_texture(handle<device_texture> handle);
@@ -57,8 +57,8 @@ class vkdevice {
void destroy_surface(handle<device_surface> handle);
template<typename buffer_type>
- void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type) {
- allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type);
+ void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type, const char* name) {
+ allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type, name);
}
[[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) {
@@ -99,8 +99,8 @@ class vkdevice {
// uint64_t submit(std::span<command_buffer> buffers, handle<device_semaphore> wait_handle, handle<device_semaphore> signal_handle, handle<device_semaphore> fence_handle);
uint32_t acquire_image_index(handle<device_surface> surface_handle);
- uint32_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count);
- uint32_t submit(command_buffer* buffers, uint32_t count);
+ uint64_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count);
+ uint64_t submit(command_buffer* buffers, uint32_t count);
void present(handle<device_surface> surface_handle);
@@ -110,7 +110,7 @@ class vkdevice {
vkdevice() = default;
~vkdevice() = default;
- void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type);
+ void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type, const char* name);
VkShaderModule create_shader_module(const std::span<uint8_t>& shader_code);