aboutsummaryrefslogtreecommitdiffstats
path: root/api-test
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2023-02-03 09:55:06 +0100
committerladevieq <ladevie.quentin@gmail.com>2023-02-03 09:55:06 +0100
commit9286a3db4f529f435ea4270ffc2ca7a7a1da922d (patch)
treedf1d1f1f03e5688185234aa538b4d99cca34bea5 /api-test
parent75acd0104448d7c5f43f99700decff39b8a034b2 (diff)
Start presentation abstraction design
Diffstat (limited to 'api-test')
-rw-r--r--api-test/main.cpp63
-rw-r--r--api-test/vk-device.cpp3
2 files changed, 33 insertions, 33 deletions
diff --git a/api-test/main.cpp b/api-test/main.cpp
index 2f973ff..7f30fda 100644
--- a/api-test/main.cpp
+++ b/api-test/main.cpp
@@ -34,6 +34,36 @@ void ui() {
ImGui::Render();
}
+void update_buffers(ImDrawData* draw_data, const device_buffer& vertex_buffer, const device_buffer& index_buffer) {
+ struct vertex {
+ ImVec2 pos;
+ ImVec2 uv;
+ uint32_t color;
+ uint32_t padding;
+ };
+
+ off_t vertex_offset = 0;
+ off_t index_offset = 0;
+ for (auto index {0U} ; index < draw_data->CmdListsCount; index++) {
+ auto* cmd_list = draw_data->CmdLists[index];
+
+ size_t vertex_bytes_size = sizeof(ImDrawVert) * cmd_list->VtxBuffer.size();
+ auto* vtx_ptr = static_cast<vertex*>(vertex_buffer.mapped_ptr) + vertex_offset;
+ for (auto vtx_index{0}; vtx_index < cmd_list->VtxBuffer.size(); vtx_index++, vtx_ptr++) {
+ auto& vtx = cmd_list->VtxBuffer[vtx_index];
+ vtx_ptr->pos = vtx.pos;
+ vtx_ptr->uv = vtx.uv;
+ vtx_ptr->color = vtx.col;
+ }
+ // memcpy(static_cast<uint8_t*>(vertex_buffer.mapped_ptr) + vertex_offset, cmd_list->VtxBuffer.Data, vertex_bytes_size);
+ vertex_offset += static_cast<off_t>(vertex_bytes_size);
+
+ size_t index_bytes_size = sizeof(ImDrawIdx) * cmd_list->IdxBuffer.size();
+ memcpy(static_cast<uint8_t*>(index_buffer.mapped_ptr) + index_offset, cmd_list->IdxBuffer.Data, index_bytes_size);
+ index_offset += static_cast<off_t>(index_bytes_size);
+ }
+}
+
int main() {
#ifdef ENABLE_RENDERDOC
@@ -193,6 +223,7 @@ int main() {
command_buffers[0].barrier(gpu_texture_handle, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
command_buffers[0].stop();
+
std::array<struct command_buffer, 1U> compute_command_buffers = {command_buffers[0]};
device->submit(compute_command_buffers, nullptr, &semaphore);
@@ -206,33 +237,7 @@ int main() {
ui();
auto* draw_data = ImGui::GetDrawData();
- struct vertex {
- ImVec2 pos;
- ImVec2 uv;
- uint32_t color;
- uint32_t padding;
- };
-
- off_t vertex_offset = 0;
- off_t index_offset = 0;
- for (auto index {0U} ; index < draw_data->CmdListsCount; index++) {
- auto* cmd_list = draw_data->CmdLists[index];
-
- size_t vertex_bytes_size = sizeof(ImDrawVert) * cmd_list->VtxBuffer.size();
- auto* vtx_ptr = static_cast<vertex*>(vertex_buffer.mapped_ptr) + vertex_offset;
- for (auto vtx_index{0}; vtx_index < cmd_list->VtxBuffer.size(); vtx_index++, vtx_ptr++) {
- auto& vtx = cmd_list->VtxBuffer[vtx_index];
- vtx_ptr->pos = vtx.pos;
- vtx_ptr->uv = vtx.uv;
- vtx_ptr->color = vtx.col;
- }
- // memcpy(static_cast<uint8_t*>(vertex_buffer.mapped_ptr) + vertex_offset, cmd_list->VtxBuffer.Data, vertex_bytes_size);
- vertex_offset += static_cast<off_t>(vertex_bytes_size);
-
- size_t index_bytes_size = sizeof(ImDrawIdx) * cmd_list->IdxBuffer.size();
- memcpy(static_cast<uint8_t*>(index_buffer.mapped_ptr) + index_offset, cmd_list->IdxBuffer.Data, index_bytes_size);
- index_offset += static_cast<off_t>(index_bytes_size);
- }
+ update_buffers(draw_data, vertex_buffer, index_buffer);
device->wait(semaphore);
@@ -259,8 +264,6 @@ int main() {
printf("%llu\n", sizeof(ImDrawVert));
uint32_t draw_index = 0U;
- uint32_t vtx_offset = 0U;
- uint32_t idx_offset = 0U;
std::array<draw_params, 100U> draws;
for (auto index {0U} ; index < draw_data->CmdListsCount; index++) {
auto* cmd_list = draw_data->CmdLists[index];
@@ -290,7 +293,6 @@ int main() {
});
draw_index++;
- // vtx_offset += draw_command.
}
}
@@ -303,7 +305,6 @@ int main() {
device->submit(ui_command_buffers, nullptr, &semaphore);
RD_END_CAPTURE;
- // std::system("PAUSE");
break;
}
diff --git a/api-test/vk-device.cpp b/api-test/vk-device.cpp
index 296d76c..502143a 100644
--- a/api-test/vk-device.cpp
+++ b/api-test/vk-device.cpp
@@ -235,7 +235,6 @@ handle<device_buffer> vkdevice::create_buffer(const buffer_desc& desc) {
handle<device_pipeline> vkdevice::create_pipeline(const pipeline_desc& desc) {
device_pipeline device_pipeline{
.desc = desc,
- .bindless = &bindless,
};
if (!desc.cs_code.empty()) {
VkShaderModule shader_module;
@@ -587,7 +586,7 @@ void vkdevice::submit(std::span<command_buffer> buffers, vksemaphore* wait, vkse
#endif
}
-void vkdevice::present(vksurface& surface, const vksemaphore& semaphore) {
+void vkdevice::present(device_surface& surface, const vksemaphore& semaphore) {
VkResult result;
VkPresentInfoKHR present_info{
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,