From a105b9ea76e10ca2d1d482314409c93901817e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Thu, 27 Nov 2025 18:17:25 +0100 Subject: [PATCH 01/28] feat: clear screen option for imgui --- src/core/graphite/imgui.hh | 4 ++++ src/platform/vulkan/render_graph_vk.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/graphite/imgui.hh b/src/core/graphite/imgui.hh index ed26d31..0cc0493 100644 --- a/src/core/graphite/imgui.hh +++ b/src/core/graphite/imgui.hh @@ -35,6 +35,7 @@ struct ImGUIFunctions { class AgnImGUI { protected: GPUAdapter* gpu = nullptr; + bool clear_screen = false; /* Collection of imgui functions. */ ImGUIFunctions functions {}; @@ -45,6 +46,9 @@ protected: public: /* Initialize the immediate mode GUI. */ PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt, ImGUIFunctions functions) = 0; + + /* Set whether the immediate mode GUI should clear the screen before rendering. (default: false) */ + void set_clear_screen(bool value = false) { clear_screen = value; }; /* Start a new immediate frame. */ PLATFORM_SPECIFIC void new_frame() = 0; diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index c788fb5..f8760a7 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -466,7 +466,7 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { VkRenderingAttachmentInfoKHR attachment_info { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR }; attachment_info.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + attachment_info.loadOp = imgui->clear_screen ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; attachment_info.imageView = rt.view(); /* Rendering info */ From b7bdc3e947c49f5fdb5acf64d7235b76366ec87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Thu, 27 Nov 2025 18:50:09 +0100 Subject: [PATCH 02/28] feat: raster node load operation --- src/core/graphite/imgui.hh | 4 ---- src/core/graphite/nodes/raster_node.cc | 5 +++++ src/core/graphite/nodes/raster_node.hh | 10 ++++++++++ src/platform/vulkan/render_graph_vk.cc | 4 ++-- src/platform/vulkan/wrapper/translate_vk.cc | 15 +++++++++++++++ src/platform/vulkan/wrapper/translate_vk.hh | 3 +++ 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/core/graphite/imgui.hh b/src/core/graphite/imgui.hh index 0cc0493..3b3a3ee 100644 --- a/src/core/graphite/imgui.hh +++ b/src/core/graphite/imgui.hh @@ -35,7 +35,6 @@ struct ImGUIFunctions { class AgnImGUI { protected: GPUAdapter* gpu = nullptr; - bool clear_screen = false; /* Collection of imgui functions. */ ImGUIFunctions functions {}; @@ -47,9 +46,6 @@ public: /* Initialize the immediate mode GUI. */ PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt, ImGUIFunctions functions) = 0; - /* Set whether the immediate mode GUI should clear the screen before rendering. (default: false) */ - void set_clear_screen(bool value = false) { clear_screen = value; }; - /* Start a new immediate frame. */ PLATFORM_SPECIFIC void new_frame() = 0; diff --git a/src/core/graphite/nodes/raster_node.cc b/src/core/graphite/nodes/raster_node.cc index 28dcbf7..834a1f6 100644 --- a/src/core/graphite/nodes/raster_node.cc +++ b/src/core/graphite/nodes/raster_node.cc @@ -45,6 +45,11 @@ RasterNode& RasterNode::topology(const Topology type) { return *this; } +RasterNode& RasterNode::load_op(const LoadOp op) { + pixel_load_op = op; + return *this; +} + DrawCall::DrawCall( RasterNode& parent_pass, const Buffer vertex_buffer, const u32 vertex_count, const u32 vertex_offset, const u32 instance_count, const u32 instance_offset diff --git a/src/core/graphite/nodes/raster_node.hh b/src/core/graphite/nodes/raster_node.hh index b47f3d9..3d34466 100644 --- a/src/core/graphite/nodes/raster_node.hh +++ b/src/core/graphite/nodes/raster_node.hh @@ -24,6 +24,12 @@ enum class Topology : u32 { EnumLimit /* Anything above or equal is invalid. */ }; +/* Pixel load operation. */ +enum class LoadOp : u32 { + Load, /* Load pixel data already present. */ + Clear /* Clear pixel data. */ +}; + /** * Render Graph Rasterisation Node. * Used to build a rasterisation shader pass. @@ -41,6 +47,7 @@ class RasterNode : public Node { /* Vertex shader attributes */ std::vector attributes {}; Topology prim_topology = Topology::Invalid; + LoadOp pixel_load_op = LoadOp::Load; /* Extents */ u32 raster_w = 0u, raster_h = 0u, raster_x = 0u, raster_y = 0u; @@ -58,6 +65,9 @@ class RasterNode : public Node { /* Set the vertex primitive topology of the pass. */ RasterNode& topology(const Topology type); + /* Set the pixel load operation of the pass. */ + RasterNode& load_op(const LoadOp op); + /* Add a bindable resource as an output for this node. */ RasterNode& write(BindHandle resource, ShaderStages stages); diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index f8760a7..f4e9d6a 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -329,7 +329,7 @@ Result RenderGraph::queue_raster_node(const GraphExecution& graph, const R VkRenderingAttachmentInfo attachment { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO }; attachment.imageView = attachment_view; attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + attachment.loadOp = translate::load_operation(node.pixel_load_op); attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; color_attachments.emplace_back(attachment); } @@ -466,7 +466,7 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { VkRenderingAttachmentInfoKHR attachment_info { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR }; attachment_info.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment_info.loadOp = imgui->clear_screen ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; + attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; attachment_info.imageView = rt.view(); /* Rendering info */ diff --git a/src/platform/vulkan/wrapper/translate_vk.cc b/src/platform/vulkan/wrapper/translate_vk.cc index 542bc62..5384305 100644 --- a/src/platform/vulkan/wrapper/translate_vk.cc +++ b/src/platform/vulkan/wrapper/translate_vk.cc @@ -137,6 +137,7 @@ VkBorderColor sampler_border_color(BorderColor color) { } } +/* Get the number of bytes per vertex attribute for a given vertex attribute format. */ u32 vertex_attribute_size(const AttrFormat fmt) { switch (fmt) { case AttrFormat::X32_SFloat: @@ -152,6 +153,7 @@ u32 vertex_attribute_size(const AttrFormat fmt) { } } +/* Convert the platform-agnostic vertex attribute format to a vertex format. */ VkFormat vertex_format(const AttrFormat fmt) { switch (fmt) { case AttrFormat::X32_SFloat: @@ -167,6 +169,7 @@ VkFormat vertex_format(const AttrFormat fmt) { } } +/* Convert the platform-agnostic primitive topology. */ VkPrimitiveTopology primitive_topology(const Topology topology) { switch (topology) { case Topology::TriangleList: @@ -178,4 +181,16 @@ VkPrimitiveTopology primitive_topology(const Topology topology) { } } +/* Convert the platform-agnostic load operation. */ +VkAttachmentLoadOp load_operation(const LoadOp op) { + switch (op) { + case LoadOp::Load: + return VK_ATTACHMENT_LOAD_OP_LOAD; + case LoadOp::Clear: + return VK_ATTACHMENT_LOAD_OP_CLEAR; + default: + return VK_ATTACHMENT_LOAD_OP_DONT_CARE; + } +} + } /* translate */ diff --git a/src/platform/vulkan/wrapper/translate_vk.hh b/src/platform/vulkan/wrapper/translate_vk.hh index 9ce2cdb..673b104 100644 --- a/src/platform/vulkan/wrapper/translate_vk.hh +++ b/src/platform/vulkan/wrapper/translate_vk.hh @@ -57,4 +57,7 @@ VkFormat vertex_format(const AttrFormat fmt); /* Convert the platform-agnostic primitive topology. */ VkPrimitiveTopology primitive_topology(const Topology topology); +/* Convert the platform-agnostic load operation. */ +VkAttachmentLoadOp load_operation(const LoadOp op); + } /* translate */ From e617e78c718c97dae1d00332f81a1db6e531bb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Thu, 27 Nov 2025 20:46:38 +0100 Subject: [PATCH 03/28] fix: add imgui volk compile definition --- extern/CMakeLists.txt | 1 + extern/volk/CMakeLists.txt | 174 +++++++++++++++++++++++++++++++------ 2 files changed, 147 insertions(+), 28 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 10e6ea8..ba9504b 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -2,6 +2,7 @@ if(GRAPHITE_PLATFORM STREQUAL "Vulkan") # Meta-loader for Vulkan add_subdirectory("volk") target_link_libraries(graphite PUBLIC volk) + target_compile_definitions(graphite PUBLIC IMGUI_IMPL_VULKAN_USE_VOLK) # VMA target_include_directories(graphite PUBLIC "./vma") diff --git a/extern/volk/CMakeLists.txt b/extern/volk/CMakeLists.txt index aec1727..6bd2010 100644 --- a/extern/volk/CMakeLists.txt +++ b/extern/volk/CMakeLists.txt @@ -1,28 +1,146 @@ -cmake_minimum_required(VERSION 3.15) -project(volk VERSION 313 LANGUAGES C) - -# Volk library -add_library(volk STATIC volk.h volk.c) -add_library(volk::volk ALIAS volk) -target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_WIN32_KHR) -target_include_directories(volk PUBLIC ".") - -# Vulkan -# find_package(Vulkan REQUIRED) -target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_WIN32_KHR) -target_compile_definitions(volk PRIVATE VK_NO_PROTOTYPES) -# if(TARGET Vulkan::Vulkan) - # Note: We don't use target_link_libraries for Vulkan::Vulkan to avoid a static dependency on libvulkan1 - # target_include_directories(volk PUBLIC ${Vulkan_INCLUDE_DIRS}) -# elseif(DEFINED ENV{VULKAN_SDK}) - #target_include_directories(volk PUBLIC "$ENV{VULKAN_SDK}/include") -# endif() - -if(DEFINED ENV{VULKAN_SDK_INSTALL_DIR}) - target_include_directories(volk PUBLIC "$ENV{VULKAN_SDK_INSTALL_DIR}/include") -elseif(DEFINED ENV{VULKAN_SDK}) - target_include_directories(volk PUBLIC "$ENV{VULKAN_SDK}/include") -else() - message(FATAL_ERROR "No Vulkan SDK found!") -endif() - \ No newline at end of file +cmake_minimum_required(VERSION 3.5...3.30) + +project(volk VERSION +# VOLK_GENERATE_VERSION +334 +# VOLK_GENERATE_VERSION + LANGUAGES C +) + +# CMake 3.12 changes the default behaviour of option() to leave local variables +# unchanged if they exist (which we want), but we must work with older CMake versions. +if(NOT DEFINED VOLK_STATIC_DEFINES) + set(VOLK_STATIC_DEFINES "" CACHE STRING "Additional defines for building the volk static library, e.g. Vulkan platform defines") +endif() +if(NOT DEFINED VOLK_PULL_IN_VULKAN) + option(VOLK_PULL_IN_VULKAN "Vulkan as a transitive dependency" ON) +endif() +if(NOT DEFINED VOLK_INSTALL) + option(VOLK_INSTALL "Create installation targets" OFF) +endif() +if(NOT DEFINED VOLK_NAMESPACE) + option(VOLK_NAMESPACE "Use C++ namespace for vk* functions" OFF) +endif() +if(NOT DEFINED VOLK_HEADERS_ONLY) + option(VOLK_HEADERS_ONLY "Add interface library only" OFF) +endif() +if(NOT DEFINED VULKAN_HEADERS_INSTALL_DIR) + set(VULKAN_HEADERS_INSTALL_DIR "" CACHE PATH "Where to get the Vulkan headers") +endif() + +# ----------------------------------------------------- +# Static library + +if(NOT VOLK_HEADERS_ONLY OR VOLK_INSTALL) + add_library(volk STATIC volk.h volk.c) + add_library(volk::volk ALIAS volk) + target_compile_definitions(volk PRIVATE VK_USE_PLATFORM_WIN32_KHR) + target_include_directories(volk PUBLIC + $ + $ + ) + if(VOLK_NAMESPACE) + target_compile_definitions(volk PUBLIC VOLK_NAMESPACE) + set_source_files_properties(volk.c PROPERTIES LANGUAGE CXX) + endif() + if(VOLK_STATIC_DEFINES) + target_compile_definitions(volk PUBLIC ${VOLK_STATIC_DEFINES}) + endif() + if (NOT WIN32) + target_link_libraries(volk PUBLIC ${CMAKE_DL_LIBS}) + endif() +endif() + +# ----------------------------------------------------- +# Interface library + +add_library(volk_headers INTERFACE) +add_library(volk::volk_headers ALIAS volk_headers) +target_include_directories(volk_headers INTERFACE + $ + $ +) +if (NOT WIN32) + target_link_libraries(volk_headers INTERFACE ${CMAKE_DL_LIBS}) +endif() + +# ----------------------------------------------------- +# Vulkan transitive dependency + +if(VOLK_PULL_IN_VULKAN) + # Try an explicit CMake variable first, then any Vulkan paths + # discovered by FindVulkan.cmake, then the $VULKAN_SDK environment + # variable if nothing else works. + if(VULKAN_HEADERS_INSTALL_DIR) + message("volk: using VULKAN_HEADERS_INSTALL_DIR option") + set(VOLK_INCLUDES "${VULKAN_HEADERS_INSTALL_DIR}/include") + else() + # If CMake has the FindVulkan module and it works, use it. + find_package(Vulkan QUIET) + if(Vulkan_INCLUDE_DIRS) + message("volk: using Vulkan_INCLUDE_DIRS from FindVulkan module") + set(VOLK_INCLUDES "${Vulkan_INCLUDE_DIRS}") + elseif(DEFINED ENV{VULKAN_SDK}) + message("volk: using VULKAN_SDK environment variable") + set(VOLK_INCLUDES "$ENV{VULKAN_SDK}/include") + elseif(TARGET Vulkan-Headers) + message("volk: using Vulkan-Headers include directories") + get_target_property(VOLK_INCLUDES Vulkan-Headers INTERFACE_INCLUDE_DIRECTORIES) + endif() + endif() + + if(VOLK_INCLUDES) + if(TARGET volk) + target_include_directories(volk PUBLIC "${VOLK_INCLUDES}") + endif() + target_include_directories(volk_headers INTERFACE "${VOLK_INCLUDES}") + endif() +endif() + +# ----------------------------------------------------- +# Installation + +if(VOLK_INSTALL) + + include(GNUInstallDirs) + set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/volk) + + # Install files + install(FILES volk.h volk.c DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + # Install library target and add it and any dependencies to export set. + install(TARGETS volk volk_headers + EXPORT volk-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + + # Actually write exported config w/ imported targets + install(EXPORT volk-targets + FILE volkTargets.cmake + NAMESPACE volk:: + DESTINATION ${INSTALL_CONFIGDIR} + ) + + # Create a ConfigVersion.cmake file: + include(CMakePackageConfigHelpers) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/volkConfigVersion.cmake + COMPATIBILITY AnyNewerVersion + ) + + # Configure config file + configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/volkConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/volkConfig.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} + ) + + # Install the fully generated config and configVersion files + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/volkConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/volkConfigVersion.cmake + DESTINATION ${INSTALL_CONFIGDIR} + ) + +endif() From 5d2d77da3e686bbb91307af46b6f6f2a1e84a63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Fri, 28 Nov 2025 10:57:25 +0100 Subject: [PATCH 04/28] fix: wait queue idle only for render targets --- src/platform/vulkan/vram_bank_vk.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 85c335f..f10d74a 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -609,6 +609,9 @@ Texture VRAMBank::get_texture(Image image) { } void VRAMBank::destroy_render_target(RenderTarget &render_target) { + /* For render targets we need to wait for queue idle */ + vkQueueWaitIdle(gpu->queues.queue_combined); + /* Push the handle back onto the stock, and get its slot for cleanup */ RenderTargetSlot& slot = render_targets.push(render_target); From ea08934dec84460b9104b4aad9b0621326d5d5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Fri, 28 Nov 2025 11:24:37 +0100 Subject: [PATCH 05/28] fix: reserve staging copy command vectors --- src/platform/vulkan/render_graph_vk.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index f4e9d6a..ce14822 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -392,6 +392,8 @@ void RenderGraph::queue_staging(const GraphExecution& graph) { /* Compile the staging copy commands */ std::vector regions {}; std::vector copies {}; + regions.reserve(graph.staging_commands.size()); + copies.reserve(graph.staging_commands.size()); VRAMBank& bank = gpu->get_vram_bank(); for (const StagingCommand& cmd : graph.staging_commands) { From 867e773cc9123b2555c45069291d1ff778f5bf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Fri, 28 Nov 2025 11:33:49 +0100 Subject: [PATCH 06/28] fix: queue all staging copy commands --- src/platform/vulkan/render_graph_vk.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index ce14822..f29db1e 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -426,7 +426,9 @@ void RenderGraph::queue_staging(const GraphExecution& graph) { } /* Queue copy commands */ - vkCmdCopyBuffer2KHR(graph.cmd, copies.data()); + for (const VkCopyBufferInfo2& copy : copies) { + vkCmdCopyBuffer2KHR(graph.cmd, ©); + } /* End debug label for this node */ if (gpu->validation) vkCmdEndDebugUtilsLabelEXT(graph.cmd); From af7a5b1a382495931cceacdd957063c763150b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Mon, 1 Dec 2025 21:33:31 +0100 Subject: [PATCH 07/28] fix: remove unused forward declaration --- src/core/graphite/nodes/compute_node.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/graphite/nodes/compute_node.hh b/src/core/graphite/nodes/compute_node.hh index 73407a3..3e83d9e 100644 --- a/src/core/graphite/nodes/compute_node.hh +++ b/src/core/graphite/nodes/compute_node.hh @@ -4,8 +4,6 @@ #include "node.hh" -class RenderTarget; - /** * Render Graph Compute Node. * Used to build a compute shader pass. From 0d080fe0f1451c5022c941d7ef6b39c70473d4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Mon, 1 Dec 2025 21:34:39 +0100 Subject: [PATCH 08/28] fix: do not upload if size is zero --- src/platform/vulkan/render_graph_vk.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index f29db1e..640775a 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -61,6 +61,8 @@ Result RenderGraph::init(GPUAdapter& gpu) { } void RenderGraph::upload_buffer(Buffer& buffer, const void* data, u64 dst_offset, u64 size) { + if (size == 0u) return; /* Return early if there's no data to upload */ + /* Fetch the buffer resource slot from the vram bank */ VRAMBank& bank = gpu->get_vram_bank(); const BufferSlot& slot = bank.buffers.get(buffer); From b3dfc29347a04eabc3e0e700cec357bb41c143c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Wed, 3 Dec 2025 13:48:17 +0100 Subject: [PATCH 09/28] feat: render target vsync option --- src/core/graphite/vram_bank.hh | 2 +- src/platform/vulkan/vram_bank_vk.cc | 30 +++++++++++++++++++++++++++-- src/platform/vulkan/vram_bank_vk.hh | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/core/graphite/vram_bank.hh b/src/core/graphite/vram_bank.hh index d53f832..95fc1b6 100644 --- a/src/core/graphite/vram_bank.hh +++ b/src/core/graphite/vram_bank.hh @@ -60,7 +60,7 @@ protected: public: /* Create a new render target resource. (aka, swapchain) */ - PLATFORM_SPECIFIC Result create_render_target(const TargetDesc& target, u32 width = 1440u, u32 height = 810u) = 0; + PLATFORM_SPECIFIC Result create_render_target(const TargetDesc& target, bool vsync = true, u32 width = 1440u, u32 height = 810u) = 0; /** * @brief Create a new buffer resource. * @param count If "stride" is 0 this represents the number of bytes in the buffer (for Constant buffers), diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index f10d74a..de34bcb 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -162,7 +162,7 @@ Result VRAMBank::deinit() { return Ok(); } -Result VRAMBank::create_render_target(const TargetDesc& target, u32 width, u32 height) { +Result VRAMBank::create_render_target(const TargetDesc& target, bool vsync, u32 width, u32 height) { /* Pop a new render target off the stock */ StockPair resource = render_targets.pop(); @@ -207,6 +207,32 @@ Result VRAMBank::create_render_target(const TargetDesc& target, u3 return Err("failed to find rgba unorm surface format."); } + /* Get the available surface presentation modes */ + u32 present_mode_count = 0u; + vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->physical_device, resource.data.surface, &present_mode_count, nullptr); + VkPresentModeKHR* present_modes = new VkPresentModeKHR[present_mode_count] {}; + vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->physical_device, resource.data.surface, &present_mode_count, present_modes); + + /* Find the presentation mode we want */ + VkPresentModeKHR present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; + for (u32 i = 0u; i < present_mode_count; ++i) { + /* Mailbox is the preferred vsync present mode */ + if (vsync == true && present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) { + present_mode = present_modes[i]; + break; + } + /* FIFO is the back-up vsync present mode */ + if (vsync == true && present_modes[i] == VK_PRESENT_MODE_FIFO_KHR) { + present_mode = present_modes[i]; + } + /* Immediate is the preferred non-vsync present mode */ + if (vsync == false && present_modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR) { + present_mode = present_modes[i]; + break; + } + } + delete[] present_modes; /* Free the present modes */ + /* Swapchain creation info */ VkSwapchainCreateInfoKHR swapchain_ci { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR }; swapchain_ci.surface = resource.data.surface; @@ -219,7 +245,7 @@ Result VRAMBank::create_render_target(const TargetDesc& target, u3 swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapchain_ci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; swapchain_ci.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - swapchain_ci.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; /* TODO: Vsync parameter. */ + swapchain_ci.presentMode = present_mode; swapchain_ci.clipped = true; /* Create the swapchain */ diff --git a/src/platform/vulkan/vram_bank_vk.hh b/src/platform/vulkan/vram_bank_vk.hh index 3a3ade5..e933af6 100644 --- a/src/platform/vulkan/vram_bank_vk.hh +++ b/src/platform/vulkan/vram_bank_vk.hh @@ -59,7 +59,7 @@ class VRAMBank : public AgnVRAMBank { public: /* Create a new render target resource. (aka, swapchain) */ - PLATFORM_SPECIFIC Result create_render_target(const TargetDesc& target, u32 width = 1440u, u32 height = 810u); + PLATFORM_SPECIFIC Result create_render_target(const TargetDesc& target, bool vsync = true, u32 width = 1440u, u32 height = 810u); /** * @brief Create a new buffer resource. * @param count If "stride" is 0 this represents the number of bytes in the buffer (for Constant buffers), From 5751f4f5a691286f7e5395c68ca8d316d81be2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Thu, 4 Dec 2025 14:21:03 +0100 Subject: [PATCH 10/28] fix: resource reference counting --- src/core/graphite/render_graph.cc | 28 +++++++++++++++++++------- src/core/graphite/render_graph.hh | 3 +++ src/core/graphite/resources/stock.hh | 4 ++-- src/platform/vulkan/render_graph_vk.cc | 9 +++------ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/core/graphite/render_graph.cc b/src/core/graphite/render_graph.cc index d13f75a..a8d4272 100644 --- a/src/core/graphite/render_graph.cc +++ b/src/core/graphite/render_graph.cc @@ -12,6 +12,15 @@ const GraphExecution &AgnRenderGraph::active_graph() const { return graphs[activ GraphExecution &AgnRenderGraph::active_graph() { return graphs[active_graph_index]; } +void AgnRenderGraph::flush_graph() { + /* Wait for all graph executions to finish */ + for (u32 i = 0u; i < max_graphs_in_flight; ++i) { + new_graph(); + end_graph(); + next_graph(); + } +} + Result AgnRenderGraph::new_graph(u32 node_count) { /* Wait until it's safe to release resources */ VRAMBank& bank = gpu->get_vram_bank(); @@ -19,13 +28,6 @@ Result AgnRenderGraph::new_graph(u32 node_count) { /* Decrement reference counters for all resources used in the graph */ for (Node* old_node : nodes) { - for (const Dependency& dep : old_node->dependencies) { - bank.remove_reference(dep.resource); - if (dep.resource.get_type() == ResourceType::Image) { - /* For images, we also need to add a reference to the underlying texture */ - bank.remove_reference(bank.get_texture((Image&)dep.resource)); - } - } delete old_node; } @@ -66,8 +68,11 @@ Result AgnRenderGraph::end_graph() { VRAMBank& bank = gpu->get_vram_bank(); /* Increment reference counters for all resources used in the graph */ + std::vector prev_resources = resources[active_graph_index]; + resources[active_graph_index].clear(); for (Node* node : nodes) { for (const Dependency& dep : node->dependencies) { + resources[active_graph_index].push_back(dep.resource); bank.add_reference(dep.resource); if (dep.resource.get_type() == ResourceType::Image) { /* For images, we also need to add a reference to the underlying texture */ @@ -76,6 +81,15 @@ Result AgnRenderGraph::end_graph() { } } + /* Decrement reference counters for all resources previously used in the graph */ + for (BindHandle resource : prev_resources) { + bank.remove_reference(resource); + if (resource.get_type() == ResourceType::Image) { + /* For images, we also need to add a reference to the underlying texture */ + bank.remove_reference(bank.get_texture((Image&)resource)); + } + } + /* Propegate dependency versions through the graph */ std::vector node_meta(nodes.size()); for (u32 i = 0u; i < nodes.size(); ++i) { diff --git a/src/core/graphite/render_graph.hh b/src/core/graphite/render_graph.hh index 4cabe75..4014b8e 100644 --- a/src/core/graphite/render_graph.hh +++ b/src/core/graphite/render_graph.hh @@ -53,6 +53,7 @@ protected: /* List of graph executions */ GraphExecution* graphs = nullptr; + std::vector* resources = nullptr; u32 active_graph_index = 0u; /* Get a reference to the active graph execution. */ @@ -61,6 +62,8 @@ protected: GraphExecution& active_graph(); /* Move on to the next graph execution, should be called at the end of `dispatch()`. */ inline void next_graph() { if (++active_graph_index >= max_graphs_in_flight) active_graph_index = 0u; }; + /* Waits for all graph executions to finish. */ + void flush_graph(); /* Wait until it's safe to create a new graph. */ PLATFORM_SPECIFIC Result wait_until_safe() = 0; diff --git a/src/core/graphite/resources/stock.hh b/src/core/graphite/resources/stock.hh index e588628..9335870 100644 --- a/src/core/graphite/resources/stock.hh +++ b/src/core/graphite/resources/stock.hh @@ -82,12 +82,12 @@ class Stock { /* Increment handle reference counter. */ void add_reference(OpaqueHandle handle) { - refs[handle.index - 1u]++; + refs[handle.index - 1u] += 1u; } /* Decrement handle reference counter. (returns true if there are no more references) */ bool remove_reference(OpaqueHandle handle) { - if (refs[handle.index - 1u] > 0u) refs[handle.index - 1u]--; + if (refs[handle.index - 1u] > 0u) refs[handle.index - 1u] -= 1u; return refs[handle.index - 1u] == 0u; } diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 640775a..6e91f0c 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -11,6 +11,7 @@ Result RenderGraph::init(GPUAdapter& gpu) { /* Allocate graph executions ring buffer */ graphs = new GraphExecution[max_graphs_in_flight] {}; + resources = new std::vector[max_graphs_in_flight] {}; active_graph_index = 0u; /* Command buffer allocation info */ @@ -497,12 +498,7 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { Result RenderGraph::deinit() { /* Wait for all graph executions to finish */ - for (u32 i = 0u; i < max_graphs_in_flight; ++i) { - new_graph(); - } - - /* Wait for the queue to idle */ - vkQueueWaitIdle(gpu->queues.queue_combined); + flush_graph(); /* Evict the pipeline cache */ pipeline_cache.evict(); @@ -513,6 +509,7 @@ Result RenderGraph::deinit() { vkDestroySemaphore(gpu->logical_device, graphs[i].start_semaphore, nullptr); vmaDestroyBuffer(gpu->get_vram_bank().vma_allocator, graphs[i].staging_buffer, graphs[i].staging_alloc); } + delete[] resources; delete[] graphs; return Ok(); From a63c243b58f4d3e2d6182b01dc955cddebb1c4dd Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Mon, 8 Dec 2025 11:43:07 +0100 Subject: [PATCH 11/28] feat: resize texture function --- src/core/graphite/vram_bank.hh | 3 +++ src/platform/vulkan/vram_bank_vk.cc | 36 +++++++++++++++++++++++++++++ src/platform/vulkan/vram_bank_vk.hh | 3 +++ 3 files changed, 42 insertions(+) diff --git a/src/core/graphite/vram_bank.hh b/src/core/graphite/vram_bank.hh index 95fc1b6..d9d0f62 100644 --- a/src/core/graphite/vram_bank.hh +++ b/src/core/graphite/vram_bank.hh @@ -77,6 +77,9 @@ public: /* Resize a render target resource. (aka, swapchain) */ PLATFORM_SPECIFIC Result resize_render_target(RenderTarget& render_target, u32 width, u32 height) = 0; + /* Resize a texture resource. */ + PLATFORM_SPECIFIC Result resize_texture(Texture& texture, Size3D size) = 0; + /* Upload data to a GPU buffer resource. */ PLATFORM_SPECIFIC Result upload_buffer(Buffer& buffer, const void* data, u64 dst_offset, u64 size) = 0; /* Upload data to a GPU texture resource. */ diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index de34bcb..98e8649 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -523,6 +523,42 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid return Ok(); } +Result VRAMBank::resize_texture(Texture& texture, Size3D size) { + /* Wait for the queue to idle */ + vkQueueWaitIdle(gpu->queues.queue_combined); + TextureSlot& data = textures.get(texture); + + /* Destroy Image */ + vmaDestroyImage(vma_allocator, data.image, data.alloc); + + VkFormat format = translate::texture_format(data.format); + + /* Image creation info */ + VkImageCreateInfo texture_ci {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; + texture_ci.imageType = size.is_2d() ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_3D; + texture_ci.format = format; + texture_ci.extent = {MAX(size.x, 1u), MAX(size.y, 1u), MAX(size.z, 1u)}; + texture_ci.mipLevels = MAX(1u, data.meta.mips); + texture_ci.arrayLayers = MAX(1u, data.meta.arrays); + texture_ci.samples = VK_SAMPLE_COUNT_1_BIT; /* No MSAA */ + texture_ci.tiling = VK_IMAGE_TILING_OPTIMAL; + texture_ci.usage = translate::texture_usage(data.usage); + texture_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + /* Memory allocation info */ + VmaAllocationCreateInfo alloc_ci {}; + alloc_ci.flags = 0x00u; + alloc_ci.usage = VMA_MEMORY_USAGE_AUTO; + + /* Create the texture & allocate it using VMA */ + if (vmaCreateImage(vma_allocator, &texture_ci, &alloc_ci, &data.image, &data.alloc, nullptr) != + VK_SUCCESS) { + return Err("failed to allocate image resource."); + } + + return Ok(); +} + Result VRAMBank::upload_buffer(Buffer& buffer, const void* data, u64 dst_offset, u64 size) { if (size == 0u) return Err("size is 0."); diff --git a/src/platform/vulkan/vram_bank_vk.hh b/src/platform/vulkan/vram_bank_vk.hh index e933af6..1f5f706 100644 --- a/src/platform/vulkan/vram_bank_vk.hh +++ b/src/platform/vulkan/vram_bank_vk.hh @@ -76,6 +76,9 @@ public: /* Resize a render target resource. (aka, swapchain) */ PLATFORM_SPECIFIC Result resize_render_target(RenderTarget& render_target, u32 width, u32 height); + /* Resize a texture resource. */ + PLATFORM_SPECIFIC Result resize_texture(Texture& texture, Size3D size); + /* Upload data to a GPU buffer resource. */ PLATFORM_SPECIFIC Result upload_buffer(Buffer& buffer, const void* data, u64 dst_offset, u64 size); /* Upload data to a GPU texture resource. */ From 15f96d37634f592c914737105194651d909f1e5d Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Mon, 8 Dec 2025 14:26:29 +0100 Subject: [PATCH 12/28] wip: texture resize test --- samples/testing/kernels/test.slang | 4 +- samples/testing/src/main.cc | 74 +++++++++++++++--------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/samples/testing/kernels/test.slang b/samples/testing/kernels/test.slang index ad540c7..8473f10 100644 --- a/samples/testing/kernels/test.slang +++ b/samples/testing/kernels/test.slang @@ -3,7 +3,7 @@ import common; RWTexture2D out_texture; ConstantBuffer frame_data; //StructuredBuffer in_buffer; -Texture2D debug_tex; +Texture2D attachment_tex; SamplerState linear_sampler; /* Source: XorDev */ @@ -62,5 +62,5 @@ void entry(int2 thread_id: SV_DispatchThreadID) { StructuredBuffer buf = bindless::storage_buffer>(3); out_texture[thread_id] = buf[int(thread_id.x + thread_id.y * frame_data.win_width)].color; - out_texture[thread_id] = debug_tex.SampleLevel(linear_sampler, uv, 0); + out_texture[thread_id] = attachment_tex.SampleLevel(linear_sampler, uv, 0); } diff --git a/samples/testing/src/main.cc b/samples/testing/src/main.cc index 77f38f6..bbad6ae 100644 --- a/samples/testing/src/main.cc +++ b/samples/testing/src/main.cc @@ -129,38 +129,38 @@ int main() { bank.upload_buffer(storage_buffer, pixels, 0, sizeof(float) * 4 * 1440 * 810); delete[] pixels; - int tex_width = -1; - int tex_height = -1; - int channels = -1; - unsigned char* data = nullptr; - - data = stbi_load("samples/testing/assets/test.png", &tex_width, &tex_height, &channels, 4); - if (!data) { - printf("failed to load image.\n"); - return EXIT_SUCCESS; - } - - /* Initialise a debug texture */ - Texture debug_texture {}; - if (const Result r = bank.create_texture(TextureUsage::Sampled | TextureUsage::TransferDst, TextureFormat::RGBA8Unorm, {(u32)tex_width, (u32)tex_height, 0}); - r.is_err()) { - printf("failed to initialize debug texture.\nreason: %s\n", r.unwrap_err().c_str()); - return EXIT_SUCCESS; - } else - debug_texture = r.unwrap(); - - if (const Result r = bank.upload_texture(debug_texture, data, tex_width * tex_height * channels); r.is_err()) { - printf("failed to upload the debug texture.\nreason: %s\n", r.unwrap_err().c_str()); - return EXIT_SUCCESS; - } - free(data); - - Image debug_image {}; - if (const Result r = bank.create_image(debug_texture); r.is_err()) { - printf("failed to initialize debug image.\nreason: %s\n", r.unwrap_err().c_str()); - return EXIT_SUCCESS; - } else - debug_image = r.unwrap(); + //int tex_width = -1; + //int tex_height = -1; + //int channels = -1; + //unsigned char* data = nullptr; + + //data = stbi_load("samples/testing/assets/test.png", &tex_width, &tex_height, &channels, 4); + //if (!data) { + // printf("failed to load image.\n"); + // return EXIT_SUCCESS; + //} + + ///* Initialise a debug texture */ + //Texture debug_texture {}; + //if (const Result r = bank.create_texture(TextureUsage::Sampled | TextureUsage::TransferDst, TextureFormat::RGBA8Unorm, {(u32)tex_width, (u32)tex_height, 0}); + // r.is_err()) { + // printf("failed to initialize debug texture.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + //} else + // debug_texture = r.unwrap(); + + //if (const Result r = bank.upload_texture(debug_texture, data, tex_width * tex_height * channels); r.is_err()) { + // printf("failed to upload the debug texture.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + //} + //free(data); + + //Image debug_image {}; + //if (const Result r = bank.create_image(debug_texture); r.is_err()) { + // printf("failed to initialize debug image.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + //} else + // debug_image = r.unwrap(); Sampler linear_sampler {}; if (const Result r = bank.create_sampler(); r.is_err()) { @@ -183,7 +183,7 @@ int main() { return EXIT_SUCCESS; } - imgui.add_image(debug_image); + //imgui.add_image(debug_image); /* Main loop */ for (;;) { @@ -211,7 +211,7 @@ int main() { ImGui::NewFrame(); ImGui::ShowDemoWindow(); - ImGui::Image(ImTextureRef(imgui.get_image(debug_image)), ImVec2(480, 480)); + //ImGui::Image(ImTextureRef(imgui.get_image(debug_image)), ImVec2(480, 480)); /* End the imgui frame */ ImGui::Render(); @@ -238,7 +238,7 @@ int main() { rg.add_compute_pass("render pass", "test") .write(rt) .read(const_buffer) - .read(debug_image) + .read(attachment_img) .read(linear_sampler) .group_size(16, 8) .work_size(win_w, win_h); @@ -262,8 +262,8 @@ int main() { bank.destroy(vertex_buffer); bank.destroy(attachment); bank.destroy(attachment_img); - bank.destroy(debug_texture); - bank.destroy(debug_image); + //bank.destroy(debug_texture); + //bank.destroy(debug_image); bank.destroy(linear_sampler); imgui.deinit().expect("failed to destroy imgui."); ImGui_ImplGlfw_Shutdown(); From ed1dd9f31a416fe1467f33b530c20e3b9b34ed23 Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Mon, 8 Dec 2025 15:13:41 +0100 Subject: [PATCH 13/28] fix: correct layout for attachment --- samples/testing/kernels/test.slang | 8 +++++++- src/platform/vulkan/wrapper/translate_vk.cc | 11 +++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/samples/testing/kernels/test.slang b/samples/testing/kernels/test.slang index 8473f10..2300c65 100644 --- a/samples/testing/kernels/test.slang +++ b/samples/testing/kernels/test.slang @@ -62,5 +62,11 @@ void entry(int2 thread_id: SV_DispatchThreadID) { StructuredBuffer buf = bindless::storage_buffer>(3); out_texture[thread_id] = buf[int(thread_id.x + thread_id.y * frame_data.win_width)].color; - out_texture[thread_id] = attachment_tex.SampleLevel(linear_sampler, uv, 0); + uint2 resolution = 0; + attachment_tex.GetDimensions(resolution.x, resolution.y); + + uint2 pixel = thread_id.xy; + float2 attachment_tex_uv = (float2(pixel) + 0.5f) / float2(resolution); + out_texture[thread_id] = attachment_tex.SampleLevel(linear_sampler, attachment_tex_uv, 0); + out_texture[thread_id] = float4(attachment_tex_uv, 0.0f, 1.0f); } diff --git a/src/platform/vulkan/wrapper/translate_vk.cc b/src/platform/vulkan/wrapper/translate_vk.cc index 5384305..5581539 100644 --- a/src/platform/vulkan/wrapper/translate_vk.cc +++ b/src/platform/vulkan/wrapper/translate_vk.cc @@ -20,6 +20,7 @@ VkImageLayout desired_image_layout(TextureUsage usage, DependencyFlags flags) { } else { /* If texture is used as write resource, only Storage will work. */ if (has_flag(usage, TextureUsage::Storage)) return VK_IMAGE_LAYOUT_GENERAL; + if (has_flag(flags, DependencyFlags::Attachment)) return VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL; } return VK_IMAGE_LAYOUT_UNDEFINED; } @@ -63,8 +64,8 @@ VkBufferUsageFlags buffer_usage(BufferUsage usage) { if (has_flag(usage, BufferUsage::Constant)) flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; if (has_flag(usage, BufferUsage::Storage)) flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; if (has_flag(usage, BufferUsage::Vertex)) flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - //if (has_flag(usage, BufferUsage::eIndex)) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - //if (has_flag(usage, BufferUsage::eIndirect)) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; + // if (has_flag(usage, BufferUsage::eIndex)) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + // if (has_flag(usage, BufferUsage::eIndirect)) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; return flags; } @@ -97,9 +98,7 @@ VkImageUsageFlags texture_usage(TextureUsage usage) { } /* Convert the platform-agnostic filter to Vulkan sampler filter. */ -VkFilter sampler_filter(Filter filter) { - return filter == Filter::Nearest ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; -} +VkFilter sampler_filter(Filter filter) { return filter == Filter::Nearest ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; } /* Convert the platform-agnostic address mode to Vulkan sampler address mode. */ VkSamplerAddressMode sampler_address_mode(AddressMode mode) { @@ -193,4 +192,4 @@ VkAttachmentLoadOp load_operation(const LoadOp op) { } } -} /* translate */ +} // namespace translate From 0871d48c4e2315549f607c6b5f1b4cd1b6d16088 Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Mon, 8 Dec 2025 16:45:41 +0100 Subject: [PATCH 14/28] wip: texture resize --- samples/testing/kernels/test.slang | 1 - samples/testing/src/main.cc | 132 ++++++++++++++++------------ src/platform/vulkan/vram_bank_vk.cc | 55 +++++++++++- src/platform/vulkan/vram_bank_vk.hh | 5 ++ 4 files changed, 135 insertions(+), 58 deletions(-) diff --git a/samples/testing/kernels/test.slang b/samples/testing/kernels/test.slang index 2300c65..ada59d4 100644 --- a/samples/testing/kernels/test.slang +++ b/samples/testing/kernels/test.slang @@ -68,5 +68,4 @@ void entry(int2 thread_id: SV_DispatchThreadID) { uint2 pixel = thread_id.xy; float2 attachment_tex_uv = (float2(pixel) + 0.5f) / float2(resolution); out_texture[thread_id] = attachment_tex.SampleLevel(linear_sampler, attachment_tex_uv, 0); - out_texture[thread_id] = float4(attachment_tex_uv, 0.0f, 1.0f); } diff --git a/samples/testing/src/main.cc b/samples/testing/src/main.cc index bbad6ae..7a02ac1 100644 --- a/samples/testing/src/main.cc +++ b/samples/testing/src/main.cc @@ -19,6 +19,8 @@ #include #include +static bool resized = false; + struct FrameData { float time; float win_width; @@ -41,13 +43,14 @@ void win_resize_cb(GLFWwindow* win, int width, int height) { if (width == 0 || height == 0) return; /* Don't resize when minimized */ WindowUserData* user_data = (WindowUserData*)glfwGetWindowUserPointer(win); user_data->bank->resize_render_target(user_data->rt, width, height); + resized = true; } int main() { float dt = 0.0f; float last_frame = 0.0f; float total_time = 0.0f; - + /* Set a custom debug logger callback */ GPUAdapter gpu = GPUAdapter(); gpu.set_logger(color_logger, DebugLevel::Verbose); @@ -79,32 +82,38 @@ int main() { DwmSetWindowAttribute(glfwGetWin32Window(win), 20, &dark, sizeof(BOOL)); /* Initialize the Render Target */ - const TargetDesc target { glfwGetWin32Window(win) }; + const TargetDesc target {glfwGetWin32Window(win)}; RenderTarget rt {}; if (const Result r = bank.create_render_target(target); r.is_err()) { printf("failed to initialize render target.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else rt = r.unwrap(); + } else + rt = r.unwrap(); /* Initialise a texture that will be used as a color attachment */ Texture attachment {}; - if (const Result r = bank.create_texture(TextureUsage::ColorAttachment | TextureUsage::Sampled, TextureFormat::RGBA8Unorm, {1440, 810, 0}); r.is_err()) { + if (const Result r = bank.create_texture( + TextureUsage::ColorAttachment | TextureUsage::Sampled, TextureFormat::RGBA8Unorm, {1440, 810, 0} + ); + r.is_err()) { printf("failed to initialize attachment texture.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else attachment = r.unwrap(); + } else + attachment = r.unwrap(); Image attachment_img {}; - if (const Result r = bank.create_image(attachment); - r.is_err()) { + if (const Result r = bank.create_image(attachment); r.is_err()) { printf("failed to initialize attachment image.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else attachment_img = r.unwrap(); + } else + attachment_img = r.unwrap(); /* Initialise a test buffer */ Buffer const_buffer {}; if (const Result r = bank.create_buffer(BufferUsage::Constant | BufferUsage::TransferDst, sizeof(FrameData)); r.is_err()) { printf("failed to initialise constant buffer.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else const_buffer = r.unwrap(); + } else + const_buffer = r.unwrap(); /* Initialise a vertex buffer */ Buffer vertex_buffer {}; @@ -112,55 +121,59 @@ int main() { r.is_err()) { printf("failed to initialise constant buffer.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else vertex_buffer = r.unwrap(); + } else + vertex_buffer = r.unwrap(); std::vector vertices {}; - vertices.push_back({ -0.5f, 0.5f, 0.0f }); - vertices.push_back({ 0.0f, -0.5f, 0.0f }); - vertices.push_back({ 0.5f, 0.5f, 0.0f }); + vertices.push_back({-0.5f, 0.5f, 0.0f}); + vertices.push_back({0.0f, -0.5f, 0.0f}); + vertices.push_back({0.5f, 0.5f, 0.0f}); bank.upload_buffer(vertex_buffer, vertices.data(), 0, sizeof(Vertex) * 3); /* Initialise a storage buffer */ Buffer storage_buffer {}; - if (const Result r = bank.create_buffer(BufferUsage::Storage | BufferUsage::TransferDst, 1440 * 810, sizeof(float) * 4); r.is_err()) { + if (const Result r = bank.create_buffer(BufferUsage::Storage | BufferUsage::TransferDst, 1440 * 810, sizeof(float) * 4); + r.is_err()) { printf("failed to initialise constant buffer.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; - } else storage_buffer = r.unwrap(); + } else + storage_buffer = r.unwrap(); float* pixels = new float[4 * 1440 * 810] {}; bank.upload_buffer(storage_buffer, pixels, 0, sizeof(float) * 4 * 1440 * 810); delete[] pixels; - //int tex_width = -1; - //int tex_height = -1; - //int channels = -1; - //unsigned char* data = nullptr; + // int tex_width = -1; + // int tex_height = -1; + // int channels = -1; + // unsigned char* data = nullptr; - //data = stbi_load("samples/testing/assets/test.png", &tex_width, &tex_height, &channels, 4); - //if (!data) { - // printf("failed to load image.\n"); - // return EXIT_SUCCESS; - //} + // data = stbi_load("samples/testing/assets/test.png", &tex_width, &tex_height, &channels, 4); + // if (!data) { + // printf("failed to load image.\n"); + // return EXIT_SUCCESS; + // } ///* Initialise a debug texture */ - //Texture debug_texture {}; - //if (const Result r = bank.create_texture(TextureUsage::Sampled | TextureUsage::TransferDst, TextureFormat::RGBA8Unorm, {(u32)tex_width, (u32)tex_height, 0}); - // r.is_err()) { - // printf("failed to initialize debug texture.\nreason: %s\n", r.unwrap_err().c_str()); - // return EXIT_SUCCESS; - //} else - // debug_texture = r.unwrap(); - - //if (const Result r = bank.upload_texture(debug_texture, data, tex_width * tex_height * channels); r.is_err()) { - // printf("failed to upload the debug texture.\nreason: %s\n", r.unwrap_err().c_str()); - // return EXIT_SUCCESS; - //} - //free(data); - - //Image debug_image {}; - //if (const Result r = bank.create_image(debug_texture); r.is_err()) { - // printf("failed to initialize debug image.\nreason: %s\n", r.unwrap_err().c_str()); - // return EXIT_SUCCESS; - //} else - // debug_image = r.unwrap(); + // Texture debug_texture {}; + // if (const Result r = bank.create_texture(TextureUsage::Sampled | TextureUsage::TransferDst, TextureFormat::RGBA8Unorm, + // {(u32)tex_width, (u32)tex_height, 0}); + // r.is_err()) { + // printf("failed to initialize debug texture.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + // } else + // debug_texture = r.unwrap(); + + // if (const Result r = bank.upload_texture(debug_texture, data, tex_width * tex_height * channels); r.is_err()) { + // printf("failed to upload the debug texture.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + // } + // free(data); + + // Image debug_image {}; + // if (const Result r = bank.create_image(debug_texture); r.is_err()) { + // printf("failed to initialize debug image.\nreason: %s\n", r.unwrap_err().c_str()); + // return EXIT_SUCCESS; + // } else + // debug_image = r.unwrap(); Sampler linear_sampler {}; if (const Result r = bank.create_sampler(); r.is_err()) { @@ -169,8 +182,8 @@ int main() { } else linear_sampler = r.unwrap(); - /* Setup the framebuffer resize callback */ - WindowUserData user_data { &bank, rt }; + /* Setup the framebuffer resize callback */ + WindowUserData user_data {&bank, rt}; glfwSetWindowUserPointer(win, &user_data); glfwSetFramebufferSizeCallback(win, win_resize_cb); @@ -183,7 +196,7 @@ int main() { return EXIT_SUCCESS; } - //imgui.add_image(debug_image); + // imgui.add_image(debug_image); /* Main loop */ for (;;) { @@ -192,12 +205,19 @@ int main() { dt = currentFrame - last_frame; total_time += dt; last_frame = currentFrame; - + /* Poll events */ glfwPollEvents(); int win_w, win_h; glfwGetWindowSize(win, &win_w, &win_h); + if (resized) { + int width, height; + glfwGetWindowSize(win, &width, &height); + + gpu.get_vram_bank().resize_texture(attachment, {(u32)width, (u32)height, 0}); + resized = false; + } /* Update constant buffer */ FrameData frame_data {}; frame_data.time = total_time; @@ -211,7 +231,7 @@ int main() { ImGui::NewFrame(); ImGui::ShowDemoWindow(); - //ImGui::Image(ImTextureRef(imgui.get_image(debug_image)), ImVec2(480, 480)); + // ImGui::Image(ImTextureRef(imgui.get_image(debug_image)), ImVec2(480, 480)); /* End the imgui frame */ ImGui::Render(); @@ -227,11 +247,11 @@ int main() { /* Test Rasterisation Pass */ RasterNode& graphics_pass = rg.add_raster_pass("graphics pass", "graphics-test-vert", "graphics-test-frag") - .topology(Topology::TriangleList) - .attribute(AttrFormat::XYZ32_SFloat) // Position - .read(const_buffer, ShaderStages::Pixel) - .attach(attachment_img) - .raster_extent(win_w, win_h); + .topology(Topology::TriangleList) + .attribute(AttrFormat::XYZ32_SFloat) // Position + .read(const_buffer, ShaderStages::Pixel) + .attach(attachment_img) + .raster_extent(win_w, win_h); graphics_pass.draw(vertex_buffer, 3); /* Test Pass */ @@ -262,8 +282,8 @@ int main() { bank.destroy(vertex_buffer); bank.destroy(attachment); bank.destroy(attachment_img); - //bank.destroy(debug_texture); - //bank.destroy(debug_image); + // bank.destroy(debug_texture); + // bank.destroy(debug_image); bank.destroy(linear_sampler); imgui.deinit().expect("failed to destroy imgui."); ImGui_ImplGlfw_Shutdown(); diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 98e8649..3253a5d 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -387,6 +387,7 @@ Result VRAMBank::create_image(Texture texture, u32 mip, u32 layer) { StockPair resource = images.pop(); resource.data.texture = texture; TextureSlot& texture_slot = textures.get(texture); + texture_slot.images.push_back(resource.handle); /* Image access sub resource range */ VkImageSubresourceRange sub_range {}; @@ -525,8 +526,15 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid Result VRAMBank::resize_texture(Texture& texture, Size3D size) { /* Wait for the queue to idle */ - vkQueueWaitIdle(gpu->queues.queue_combined); + vkDeviceWaitIdle(gpu->logical_device); TextureSlot& data = textures.get(texture); + data.size = size; + + /* Destroy All Image Views */ + for (u32 i = 0; i < data.images.size(); i++) { + ImageSlot& image = images.get(data.images[i]); + vkDestroyImageView(gpu->logical_device, image.view, nullptr); + } /* Destroy Image */ vmaDestroyImage(vma_allocator, data.image, data.alloc); @@ -556,6 +564,51 @@ Result VRAMBank::resize_texture(Texture& texture, Size3D size) { return Err("failed to allocate image resource."); } + /* Re-create Image Views */ + for (u32 i = 0; i < data.images.size(); i++) { + ImageSlot& image = images.get(data.images[i]); + + ///* Image access sub resource range */ + //VkImageSubresourceRange sub_range {}; + //sub_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; /* Color hardcoded! (might want depth too) */ + //sub_range.baseMipLevel = ; + //sub_range.levelCount = MAX(1u, texture_slot.meta.mips - mip); + //sub_range.baseArrayLayer = layer; + //sub_range.layerCount = MAX(1u, texture_slot.meta.arrays - layer); + //resource.data.sub_range = sub_range; + + /* Image view creation info */ + VkImageViewCreateInfo view_ci {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; + view_ci.image = data.image; + view_ci.viewType = size.is_2d() ? VK_IMAGE_VIEW_TYPE_2D : VK_IMAGE_VIEW_TYPE_3D; + view_ci.format = translate::texture_format(data.format); + view_ci.subresourceRange = image.sub_range; + + /* Create the image view */ + if (vkCreateImageView(gpu->logical_device, &view_ci, nullptr, &image.view) != VK_SUCCESS) { + return Err("failed to create image view."); + } + + /* Insert readonly images into the bindless descriptor set */ + if (has_flag(data.usage, TextureUsage::Sampled)) { + /* Create the bindless descriptor write template */ + VkDescriptorImageInfo image_info {}; + image_info.sampler = VK_NULL_HANDLE; + image_info.imageView = image.view; + image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + VkWriteDescriptorSet bindless_write {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}; + bindless_write.dstSet = bindless_set; + bindless_write.dstArrayElement = data.images[i].get_index() - 1u; + bindless_write.descriptorCount = 1u; + bindless_write.pImageInfo = &image_info; + bindless_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + bindless_write.dstBinding = BINDLESS_TEXTURE_SLOT; + + vkUpdateDescriptorSets(gpu->logical_device, 1u, &bindless_write, 0u, nullptr); + } + } + return Ok(); } diff --git a/src/platform/vulkan/vram_bank_vk.hh b/src/platform/vulkan/vram_bank_vk.hh index 1f5f706..2cea12d 100644 --- a/src/platform/vulkan/vram_bank_vk.hh +++ b/src/platform/vulkan/vram_bank_vk.hh @@ -1,5 +1,7 @@ #pragma once +#include + /* Interface header */ #include "graphite/vram_bank.hh" @@ -153,6 +155,9 @@ struct TextureSlot { TextureUsage usage {}; TextureFormat format {}; TextureMeta meta {}; + + /* List of Images created from this Texture */ + std::vector images {}; }; /* Image resource slot. */ From 3ce43ba3b589c24fdd863ed3be90c93765514cd1 Mon Sep 17 00:00:00 2001 From: George Bolba Date: Mon, 8 Dec 2025 18:04:35 +0100 Subject: [PATCH 15/28] fix: update old layout on resize --- src/platform/vulkan/vram_bank_vk.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 3253a5d..3973dab 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -525,10 +525,11 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid } Result VRAMBank::resize_texture(Texture& texture, Size3D size) { - /* Wait for the queue to idle */ + /* Wait for the device to idle */ vkDeviceWaitIdle(gpu->logical_device); TextureSlot& data = textures.get(texture); data.size = size; + data.layout = VK_IMAGE_LAYOUT_UNDEFINED; /* Destroy All Image Views */ for (u32 i = 0; i < data.images.size(); i++) { @@ -552,6 +553,7 @@ Result VRAMBank::resize_texture(Texture& texture, Size3D size) { texture_ci.tiling = VK_IMAGE_TILING_OPTIMAL; texture_ci.usage = translate::texture_usage(data.usage); texture_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + texture_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; /* Memory allocation info */ VmaAllocationCreateInfo alloc_ci {}; From 59b66e19cd7d366cd1c0f37f039d86e913bcf0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Tue, 9 Dec 2025 10:14:56 +0100 Subject: [PATCH 16/28] feat: imgui clear screen option --- src/core/graphite/imgui.hh | 4 ++++ src/platform/vulkan/render_graph_vk.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/graphite/imgui.hh b/src/core/graphite/imgui.hh index 3b3a3ee..6bb66c8 100644 --- a/src/core/graphite/imgui.hh +++ b/src/core/graphite/imgui.hh @@ -35,6 +35,7 @@ struct ImGUIFunctions { class AgnImGUI { protected: GPUAdapter* gpu = nullptr; + bool clear_screen = false; /* Collection of imgui functions. */ ImGUIFunctions functions {}; @@ -46,6 +47,9 @@ public: /* Initialize the immediate mode GUI. */ PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt, ImGUIFunctions functions) = 0; + /* Set whether the immediate mode GUI should clear the screen before rendering. (default: false) */ + void set_clear_screen(bool value = false) { clear_screen = value; }; + /* Start a new immediate frame. */ PLATFORM_SPECIFIC void new_frame() = 0; diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 6e91f0c..7495d7b 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -473,7 +473,7 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { VkRenderingAttachmentInfoKHR attachment_info { VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR }; attachment_info.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + attachment_info.loadOp = imgui->clear_screen ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;; attachment_info.imageView = rt.view(); /* Rendering info */ From 619b21ab56caaaa18743385cf9a6c3bcd54e2525 Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Tue, 9 Dec 2025 14:04:27 +0100 Subject: [PATCH 17/28] fix: clear staging commands on window minimize --- src/platform/vulkan/render_graph_vk.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 7495d7b..fccf0b8 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -116,7 +116,14 @@ Result RenderGraph::dispatch() { const VkResult swapchain_result = vkAcquireNextImageKHR(gpu->logical_device, rt->swapchain, TIMEOUT, graph.start_semaphore, VK_NULL_HANDLE, &rt->current_image); /* Don't render anything if the swapchain is out of date */ - if (swapchain_result == VK_ERROR_OUT_OF_DATE_KHR) return Ok(); + if (swapchain_result == VK_ERROR_OUT_OF_DATE_KHR) { + /* Reset the staging buffer for the next graph */ + GraphExecution& next_graph = active_graph(); + next_graph.staging_stack_ptr = 0u; + next_graph.staging_commands.clear(); + + return Ok(); + } if (swapchain_result != VK_SUCCESS) { return Err("failed to acquire next swapchain image for render target."); From 92011fc3b0ed63758899fd5beff0a05bdcfc626b Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Tue, 9 Dec 2025 20:06:44 +0100 Subject: [PATCH 18/28] feat: imgui fixes --- src/core/graphite/imgui.hh | 2 +- src/core/graphite/resources/handle.hh | 2 +- src/platform/vulkan/imgui_vk.cc | 8 +++--- src/platform/vulkan/render_graph_vk.cc | 35 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/core/graphite/imgui.hh b/src/core/graphite/imgui.hh index 6bb66c8..5d6ee84 100644 --- a/src/core/graphite/imgui.hh +++ b/src/core/graphite/imgui.hh @@ -57,7 +57,7 @@ public: PLATFORM_SPECIFIC u64 add_image(Image image) = 0; /* Get the image index of an image resource. */ - u64 get_image(Image image) { return image_map[image.get_index()]; }; + u64 get_image(Image image) { return image_map[image.raw()]; }; /* Remove an image resource from the immediate mode GUI. */ PLATFORM_SPECIFIC void remove_image(Image image) = 0; diff --git a/src/core/graphite/resources/handle.hh b/src/core/graphite/resources/handle.hh index a07ffcb..c761f32 100644 --- a/src/core/graphite/resources/handle.hh +++ b/src/core/graphite/resources/handle.hh @@ -18,7 +18,7 @@ struct OpaqueHandle { OpaqueHandle() = default; /* Get the raw handle for debugging. */ - inline u32 raw() const { return index | static_cast(type); } + inline u32 raw() const { return index | (static_cast(type) << 28); } /* Get the resource index. */ inline u32 get_index() const { return index; } /* Get the type of this resource handle. */ diff --git a/src/platform/vulkan/imgui_vk.cc b/src/platform/vulkan/imgui_vk.cc index f135c3b..c3a2727 100644 --- a/src/platform/vulkan/imgui_vk.cc +++ b/src/platform/vulkan/imgui_vk.cc @@ -150,14 +150,14 @@ u64 ImGUI::add_image(Image image) { const ImageSlot& image_data = gpu->get_vram_bank().images.get(image); const VkDescriptorSet handle = ImGui_ImplGraphics_AddTexture(functions, bilinear_sampler, image_data.view, VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL); - image_map[image.get_index()] = (u64&)handle; + image_map[image.raw()] = (u64&)handle; return (u64&)handle; } void ImGUI::remove_image(Image image) { - if (image_map.count(image.get_index()) == 0) return; - ImGui_ImplGraphics_RemoveTexture(functions, (VkDescriptorSet&)image_map[image.get_index()]); - image_map.erase(image.get_index()); + if (image_map.count(image.raw()) == 0) return; + ImGui_ImplGraphics_RemoveTexture(functions, (VkDescriptorSet&)image_map[image.raw()]); + image_map.erase(image.raw()); } void ImGUI::render(VkCommandBuffer cmd) { diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index fccf0b8..8223b32 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -449,6 +449,41 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { if (imgui == nullptr || target.is_null()) return; RenderTargetSlot& rt = gpu->get_vram_bank().render_targets.get(target); + /* Transition all imgui images */ + for (const auto& [raw, imgui_image] : imgui->image_map) { + VRAMBank& bank = gpu->get_vram_bank(); + + const ImageSlot& image = bank.images.get((Image&)raw); + TextureSlot& texture = bank.textures.get(image.texture); + + /* Imgui image sync barrier */ + VkImageMemoryBarrier2 barrier {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2}; + barrier.srcStageMask = VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT; + barrier.srcAccessMask = VK_ACCESS_2_SHADER_READ_BIT | VK_ACCESS_2_SHADER_WRITE_BIT; + barrier.dstStageMask = VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT; + barrier.dstAccessMask = VK_ACCESS_2_SHADER_READ_BIT | VK_ACCESS_2_SHADER_WRITE_BIT; + barrier.oldLayout = texture.layout; + barrier.newLayout = VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL; + texture.layout = barrier.newLayout; + barrier.image = texture.image; + barrier.subresourceRange = image.sub_range; + + /* Render target dependency info */ + VkDependencyInfo viewport_dep_info {VK_STRUCTURE_TYPE_DEPENDENCY_INFO}; + viewport_dep_info.imageMemoryBarrierCount = 1u; + viewport_dep_info.pImageMemoryBarriers = &barrier; + + if (gpu->validation) { + /* Start debug label for imgui */ + VkDebugUtilsLabelEXT debug_label {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT}; + debug_label.pLabelName = "transition imgui images"; + vkCmdBeginDebugUtilsLabelEXT(graph.cmd, &debug_label); + } + + /* Insert a pipeline barrier for the image */ + vkCmdPipelineBarrier2KHR(graph.cmd, &viewport_dep_info); + } + /* Make imgui render target sync barrier */ VkImageMemoryBarrier2 viewport_barrier { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2 }; viewport_barrier.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT; From 7dfe1391e44136b84e0f779780af0d14aee59443 Mon Sep 17 00:00:00 2001 From: George Bolba Date: Wed, 10 Dec 2025 10:18:48 +0100 Subject: [PATCH 19/28] fix: resize texture size too large --- src/platform/vulkan/vram_bank_vk.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 3973dab..8a54cde 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -328,7 +328,6 @@ Result VRAMBank::create_buffer(BufferUsage usage, u64 count, u64 stride) VkWriteDescriptorSet bindless_write { VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET }; bindless_write.dstSet = bindless_set; - bindless_write.dstBinding = 0u; bindless_write.dstArrayElement = resource.handle.get_index() - 1u; bindless_write.descriptorCount = 1u; bindless_write.pBufferInfo = &buffer_info; @@ -526,7 +525,15 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid Result VRAMBank::resize_texture(Texture& texture, Size3D size) { /* Wait for the device to idle */ - vkDeviceWaitIdle(gpu->logical_device); + vkQueueWaitIdle(gpu->queues.queue_combined); + + size.x = MAX(1, size.x); + size.y = MAX(1, size.y); + + if (size.x > 8192 || size.y > 8192) { + return Err("texture size was larger 8192."); + } + TextureSlot& data = textures.get(texture); data.size = size; data.layout = VK_IMAGE_LAYOUT_UNDEFINED; @@ -570,15 +577,6 @@ Result VRAMBank::resize_texture(Texture& texture, Size3D size) { for (u32 i = 0; i < data.images.size(); i++) { ImageSlot& image = images.get(data.images[i]); - ///* Image access sub resource range */ - //VkImageSubresourceRange sub_range {}; - //sub_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; /* Color hardcoded! (might want depth too) */ - //sub_range.baseMipLevel = ; - //sub_range.levelCount = MAX(1u, texture_slot.meta.mips - mip); - //sub_range.baseArrayLayer = layer; - //sub_range.layerCount = MAX(1u, texture_slot.meta.arrays - layer); - //resource.data.sub_range = sub_range; - /* Image view creation info */ VkImageViewCreateInfo view_ci {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; view_ci.image = data.image; From 4c162b62cdcc5b5b990c4d087123a349a00e69b4 Mon Sep 17 00:00:00 2001 From: George Bolba Date: Wed, 10 Dec 2025 10:53:43 +0100 Subject: [PATCH 20/28] fix: mem leak fixed --- src/core/graphite/nodes/node.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/graphite/nodes/node.hh b/src/core/graphite/nodes/node.hh index da7b7d0..1e110b4 100644 --- a/src/core/graphite/nodes/node.hh +++ b/src/core/graphite/nodes/node.hh @@ -60,4 +60,5 @@ public: Node() = delete; Node(std::string_view label, NodeType type); + virtual ~Node() = default; }; From 628332b1e934a9dada60651697d4e979c56a8f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Wed, 10 Dec 2025 21:51:07 +0100 Subject: [PATCH 21/28] refactor: imgui support --- CMakeLists.txt | 28 ++++++-- src/core/graphite/imgui.hh | 28 ++------ src/platform/vulkan/imgui_vk.cc | 88 ++++---------------------- src/platform/vulkan/imgui_vk.hh | 15 ++--- src/platform/vulkan/render_graph_vk.cc | 2 + 5 files changed, 51 insertions(+), 110 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2b568c..90157ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,17 +4,18 @@ project(graphite) # C++ standard version set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE) +# Options +option(GRAPHITE_SAMPLES "Include Graphite samples directory." ON) +set(GRAPHITE_PLATFORM "Vulkan") + # Library target add_library(graphite) -# set_target_properties(graphite PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME}) # Add compiler definitions target_compile_definitions(graphite PRIVATE $<$:DEBUG=1>) target_compile_definitions(graphite PRIVATE $<$:NDEBUG=1>) # Target build platform -set(GRAPHITE_PLATFORM "Vulkan") - if(GRAPHITE_PLATFORM STREQUAL "Vulkan") set(PLATFORM_EXT vk) set(PLATFORM vulkan) @@ -23,6 +24,22 @@ endif() target_compile_definitions(graphite PUBLIC PLATFORM_EXT=${PLATFORM_EXT}) target_compile_definitions(graphite PUBLIC PLATFORM=${PLATFORM}) +# ImGUI support +if(GRAPHITE_IMGUI_DIR) + # Sources + target_sources(graphite + PRIVATE "${GRAPHITE_IMGUI_DIR}/backends/imgui_impl_vulkan.cpp" + ) + + # Includes + target_include_directories(graphite + PUBLIC "${GRAPHITE_IMGUI_DIR}" + PUBLIC "${GRAPHITE_IMGUI_DIR}/backends" + ) + + target_compile_definitions(graphite PUBLIC GRAPHITE_IMGUI=1) +endif() + # Include directories target_include_directories(graphite PUBLIC "./src/") target_include_directories(graphite PUBLIC "./src/platform/") @@ -70,7 +87,10 @@ if(GRAPHITE_PLATFORM STREQUAL "Vulkan") ) endif() -add_subdirectory("samples") +# Samples directory +if(GRAPHITE_SAMPLES) + add_subdirectory("samples") +endif() # External dependencies add_subdirectory("extern") diff --git a/src/core/graphite/imgui.hh b/src/core/graphite/imgui.hh index 5d6ee84..b9ba1eb 100644 --- a/src/core/graphite/imgui.hh +++ b/src/core/graphite/imgui.hh @@ -1,7 +1,11 @@ #pragma once +#ifdef GRAPHITE_IMGUI + #include +#include /* ImGUI header */ + #include "platform/platform.hh" #include "resources/handle.hh" @@ -11,23 +15,6 @@ class GPUAdapter; -struct ImGUIFunctions { - /* e.g. ImGui_ImplVulkan_Init */ - void* graphics_init {}; - /* e.g. ImGui_ImplVulkan_AddTexture */ - void* add_texture {}; - /* e.g. ImGui_ImplVulkan_RemoveTexture */ - void* remove_texture {}; - /* e.g. ImGui_ImplVulkan_NewFrame */ - void* new_frame {}; - /* ImGui::GetDrawData */ - void* draw_data {}; - /* e.g. ImGui_ImplVulkan_RenderDrawData */ - void* render {}; - /* e.g. ImGui_ImplVulkan_Shutdown */ - void* graphics_shutdown {}; -}; - /** * @warning Never use this class directly! * This is an interface for the platform-specific class. @@ -37,15 +24,12 @@ protected: GPUAdapter* gpu = nullptr; bool clear_screen = false; - /* Collection of imgui functions. */ - ImGUIFunctions functions {}; - /* Map of image resources mapped to imgui. */ std::unordered_map image_map {}; public: /* Initialize the immediate mode GUI. */ - PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt, ImGUIFunctions functions) = 0; + PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt) = 0; /* Set whether the immediate mode GUI should clear the screen before rendering. (default: false) */ void set_clear_screen(bool value = false) { clear_screen = value; }; @@ -67,3 +51,5 @@ public: }; #include PLATFORM_INCLUDE(imgui) + +#endif diff --git a/src/platform/vulkan/imgui_vk.cc b/src/platform/vulkan/imgui_vk.cc index c3a2727..3be9d24 100644 --- a/src/platform/vulkan/imgui_vk.cc +++ b/src/platform/vulkan/imgui_vk.cc @@ -1,5 +1,9 @@ #include "imgui_vk.hh" +#ifdef GRAPHITE_IMGUI + +#include /* Vulkan impl for ImGUI */ + #include "graphite/gpu_adapter.hh" #include "graphite/vram_bank.hh" @@ -18,74 +22,8 @@ const VkDescriptorPoolSize DESC_POOL_SIZES[] { {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 256u} }; -/* ImGUI vulkan pipeline info */ -struct ImGui_ImplVulkan_PipelineInfo { - VkRenderPass RenderPass; - uint32_t Subpass; - VkSampleCountFlagBits MSAASamples = {}; - VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; -}; - -/* ImGUI vulkan init info */ -struct ImGui_ImplVulkan_InitInfo { - uint32_t ApiVersion; - VkInstance Instance; - VkPhysicalDevice PhysicalDevice; - VkDevice Device; - uint32_t QueueFamily; - VkQueue Queue; - VkDescriptorPool DescriptorPool; - uint32_t DescriptorPoolSize; - uint32_t MinImageCount; - uint32_t ImageCount; - VkPipelineCache PipelineCache; - ImGui_ImplVulkan_PipelineInfo PipelineInfoMain; - bool UseDynamicRendering; - const VkAllocationCallbacks* Allocator; - void (*CheckVkResultFn)(VkResult err); - VkDeviceSize MinAllocationSize; - VkShaderModuleCreateInfo CustomShaderVertCreateInfo; - VkShaderModuleCreateInfo CustomShaderFragCreateInfo; -}; - -/* ImGUI graphics init function. */ -bool ImGui_ImplGraphics_Init(ImGUIFunctions functions, ImGui_ImplVulkan_InitInfo* init_info) { - return reinterpret_cast(functions.graphics_init)(init_info); -} - -/* ImGUI add texture function. */ -VkDescriptorSet ImGui_ImplGraphics_AddTexture(ImGUIFunctions functions, VkSampler sampler, VkImageView image_view, VkImageLayout image_layout) { - return reinterpret_cast(functions.add_texture)(sampler, image_view, image_layout); -} - -/* ImGUI remove texture function. */ -void ImGui_ImplGraphics_RemoveTexture(ImGUIFunctions functions, VkDescriptorSet desc_set) { - reinterpret_cast(functions.remove_texture)(desc_set); -} - -/* ImGUI graphics new frame function. */ -void ImGui_ImplGraphics_NewFrame(ImGUIFunctions functions) { - reinterpret_cast(functions.new_frame)(); -} - -/* ImGUI get draw data function. */ -void* ImGui_GetDrawData(ImGUIFunctions functions) { - return reinterpret_cast(functions.draw_data)(); -} - -/* ImGUI graphics render draw data function. */ -void ImGui_ImplGraphics_RenderDrawData(ImGUIFunctions functions, void* draw_data, VkCommandBuffer cmd) { - reinterpret_cast(functions.render)(draw_data, cmd, nullptr); -} - -/* ImGUI graphics shutdown function. */ -void ImGui_ImplGraphics_Shutdown(ImGUIFunctions functions) { - reinterpret_cast(functions.graphics_shutdown)(); -} - -Result ImGUI::init(GPUAdapter &gpu, RenderTarget rt, ImGUIFunctions functions) { +Result ImGUI::init(GPUAdapter &gpu, RenderTarget rt) { this->gpu = &gpu; - this->functions = functions; /* Allocate the imgui descriptor pool */ VkDescriptorPoolCreateInfo pool_ci { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO }; @@ -121,7 +59,7 @@ Result ImGUI::init(GPUAdapter &gpu, RenderTarget rt, ImGUIFunctions functi init_info.PipelineInfoMain.PipelineRenderingCreateInfo.pColorAttachmentFormats = &rt_data.format; /* Initialize ImGUI */ - if (!ImGui_ImplGraphics_Init(functions, &init_info)) { + if (!ImGui_ImplVulkan_Init(&init_info)) { return Err("failed to init imgui for vulkan."); } @@ -143,12 +81,12 @@ Result ImGUI::init(GPUAdapter &gpu, RenderTarget rt, ImGUIFunctions functi } void ImGUI::new_frame() { - ImGui_ImplGraphics_NewFrame(functions); + ImGui_ImplVulkan_NewFrame(); } u64 ImGUI::add_image(Image image) { const ImageSlot& image_data = gpu->get_vram_bank().images.get(image); - const VkDescriptorSet handle = ImGui_ImplGraphics_AddTexture(functions, bilinear_sampler, image_data.view, VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL); + const VkDescriptorSet handle = ImGui_ImplVulkan_AddTexture(bilinear_sampler, image_data.view, VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL); image_map[image.raw()] = (u64&)handle; return (u64&)handle; @@ -156,20 +94,22 @@ u64 ImGUI::add_image(Image image) { void ImGUI::remove_image(Image image) { if (image_map.count(image.raw()) == 0) return; - ImGui_ImplGraphics_RemoveTexture(functions, (VkDescriptorSet&)image_map[image.raw()]); + ImGui_ImplVulkan_RemoveTexture((VkDescriptorSet&)image_map[image.raw()]); image_map.erase(image.raw()); } void ImGUI::render(VkCommandBuffer cmd) { - void* draw_data = ImGui_GetDrawData(functions); + ImDrawData* draw_data = ImGui::GetDrawData(); if (draw_data == nullptr) return; - ImGui_ImplGraphics_RenderDrawData(functions, draw_data, cmd); + ImGui_ImplVulkan_RenderDrawData(draw_data, cmd); } Result ImGUI::deinit() { vkDeviceWaitIdle(gpu->logical_device); - ImGui_ImplGraphics_Shutdown(functions); + ImGui_ImplVulkan_Shutdown(); vkDestroyDescriptorPool(gpu->logical_device, desc_pool, nullptr); vkDestroySampler(gpu->logical_device, bilinear_sampler, nullptr); return Ok(); } + +#endif diff --git a/src/platform/vulkan/imgui_vk.hh b/src/platform/vulkan/imgui_vk.hh index d77fb0c..e0f5f9d 100644 --- a/src/platform/vulkan/imgui_vk.hh +++ b/src/platform/vulkan/imgui_vk.hh @@ -1,5 +1,7 @@ #pragma once +#ifdef GRAPHITE_IMGUI + /* Interface header */ #include "graphite/imgui.hh" @@ -19,7 +21,7 @@ class ImGUI : public AgnImGUI { public: /* Initialize the immediate mode GUI. */ - PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt, ImGUIFunctions functions); + PLATFORM_SPECIFIC Result init(GPUAdapter& gpu, RenderTarget rt); /* Start a new immediate frame. */ PLATFORM_SPECIFIC void new_frame(); @@ -37,13 +39,4 @@ public: friend class RenderGraph; }; -/* List of imgui platform specific functions. */ -#define IMGUI_FUNCTIONS { \ - ImGui_ImplVulkan_Init, \ - ImGui_ImplVulkan_AddTexture, \ - ImGui_ImplVulkan_RemoveTexture, \ - ImGui_ImplVulkan_NewFrame, \ - ImGui::GetDrawData, \ - ImGui_ImplVulkan_RenderDrawData, \ - ImGui_ImplVulkan_Shutdown \ -} +#endif diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 8223b32..b525672 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -445,6 +445,7 @@ void RenderGraph::queue_staging(const GraphExecution& graph) { } void RenderGraph::queue_imgui(const GraphExecution &graph) { +#ifdef GRAPHITE_IMGUI /* If this graph doesn't have a render target, don't render imgui */ if (imgui == nullptr || target.is_null()) return; RenderTargetSlot& rt = gpu->get_vram_bank().render_targets.get(target); @@ -536,6 +537,7 @@ void RenderGraph::queue_imgui(const GraphExecution &graph) { /* End debug label for this node */ if (gpu->validation) vkCmdEndDebugUtilsLabelEXT(graph.cmd); +#endif } Result RenderGraph::deinit() { From e3c2690961eb9ef857969c692a54e08eb9c50030 Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Mon, 15 Dec 2025 16:54:08 +0100 Subject: [PATCH 22/28] feat: user set max resources count --- src/core/graphite/gpu_adapter.cc | 12 ++++++++++++ src/core/graphite/gpu_adapter.hh | 23 +++++++++++++++++++++++ src/platform/vulkan/vram_bank_vk.cc | 10 +++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/core/graphite/gpu_adapter.cc b/src/core/graphite/gpu_adapter.cc index d9c0ec2..0c2ad55 100644 --- a/src/core/graphite/gpu_adapter.cc +++ b/src/core/graphite/gpu_adapter.cc @@ -40,3 +40,15 @@ void AgnGPUAdapter::deinit_vram_bank() { delete vram_bank; } VRAMBank& AgnGPUAdapter::get_vram_bank() { return *vram_bank; } + +void AgnGPUAdapter::set_max_render_targets(const u32 count) { max_render_targets = count; } +void AgnGPUAdapter::set_max_buffers(const u32 count) { max_buffers = count; } +void AgnGPUAdapter::set_max_textures(const u32 count) { max_textures = count; } +void AgnGPUAdapter::set_max_images(const u32 count) { max_images = count; } +void AgnGPUAdapter::set_max_samplers(const u32 count) { max_samplers = count; } + +u32 AgnGPUAdapter::get_max_render_targets() const { return max_render_targets; } +u32 AgnGPUAdapter::get_max_buffers() const { return max_buffers; } +u32 AgnGPUAdapter::get_max_textures() const { return max_textures; } +u32 AgnGPUAdapter::get_max_images() const { return max_images; } +u32 AgnGPUAdapter::get_max_samplers() const { return max_samplers; } diff --git a/src/core/graphite/gpu_adapter.hh b/src/core/graphite/gpu_adapter.hh index 4e4997a..7edd5fd 100644 --- a/src/core/graphite/gpu_adapter.hh +++ b/src/core/graphite/gpu_adapter.hh @@ -5,6 +5,8 @@ #include "utils/result.hh" #include "utils/debug.hh" +#include "utils/types.hh" + class VRAMBank; /* Debug logger data. */ @@ -25,6 +27,13 @@ protected: /* VRAM bank for this GPU adapter. */ VRAMBank* vram_bank = nullptr; + + /* Maximum amount of resources. */ + u32 max_render_targets = 8u; + u32 max_buffers = 8u; + u32 max_textures = 8u; + u32 max_images = 8u; + u32 max_samplers = 8u; /* Log a message using the active debug logger. */ void log(DebugSeverity severity, const char* msg); @@ -47,6 +56,20 @@ public: /* De-initialize the GPU adapter, free all its resources. */ PLATFORM_SPECIFIC Result deinit() = 0; + + /* Set maximum resource count. */ + void set_max_render_targets(const u32 count); + void set_max_buffers(const u32 count); + void set_max_textures(const u32 count); + void set_max_images(const u32 count); + void set_max_samplers(const u32 count); + + /* Get maximum resource count. */ + u32 get_max_render_targets() const; + u32 get_max_buffers() const; + u32 get_max_textures() const; + u32 get_max_images() const; + u32 get_max_samplers() const; }; #include PLATFORM_INCLUDE(gpu_adapter) diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 8a54cde..57f4c6b 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -28,11 +28,11 @@ Result VRAMBank::init(GPUAdapter& gpu) { } /* Initialize the Stack Pools */ - render_targets.init(8u); - buffers.init(8u); - textures.init(8u); - images.init(8u); - samplers.init(8u); + render_targets.init(gpu.get_max_render_targets()); + buffers.init(gpu.get_max_buffers()); + textures.init(gpu.get_max_textures()); + images.init(gpu.get_max_images()); + samplers.init(gpu.get_max_samplers()); { /* Init Bindless */ /* Initialize the bindless resources */ From fff46b8e3004f4b6917379405774c7163e99b9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Tue, 16 Dec 2025 13:51:38 +0100 Subject: [PATCH 23/28] fix: remove windows min & max --- extern/CMakeLists.txt | 1 + extern/volk/CMakeLists.txt | 1 - samples/testing/extern/imgui/imconfig.h | 2 +- src/platform/vulkan/render_graph_vk.cc | 10 ++++---- src/platform/vulkan/vram_bank_vk.cc | 31 ++++++++++++------------- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index ba9504b..c1cf263 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -5,5 +5,6 @@ if(GRAPHITE_PLATFORM STREQUAL "Vulkan") target_compile_definitions(graphite PUBLIC IMGUI_IMPL_VULKAN_USE_VOLK) # VMA + target_compile_definitions(graphite PRIVATE NOMINMAX) target_include_directories(graphite PUBLIC "./vma") endif() diff --git a/extern/volk/CMakeLists.txt b/extern/volk/CMakeLists.txt index 6bd2010..b46bc63 100644 --- a/extern/volk/CMakeLists.txt +++ b/extern/volk/CMakeLists.txt @@ -142,5 +142,4 @@ if(VOLK_INSTALL) ${CMAKE_CURRENT_BINARY_DIR}/volkConfigVersion.cmake DESTINATION ${INSTALL_CONFIGDIR} ) - endif() diff --git a/samples/testing/extern/imgui/imconfig.h b/samples/testing/extern/imgui/imconfig.h index 82adec1..4c237a2 100644 --- a/samples/testing/extern/imgui/imconfig.h +++ b/samples/testing/extern/imgui/imconfig.h @@ -139,7 +139,7 @@ //#define IMGUI_DEBUG_PARANOID //---- Indicate we're using VOLK for the render graph -#define IMGUI_IMPL_VULKAN_USE_VOLK +//#define IMGUI_IMPL_VULKAN_USE_VOLK //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) /* diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 640775a..a360dd9 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -1,5 +1,7 @@ #include "render_graph_vk.hh" +#include + #include "graphite/imgui.hh" #include "graphite/vram_bank.hh" #include "graphite/nodes/node.hh" @@ -316,15 +318,15 @@ Result RenderGraph::queue_raster_node(const GraphExecution& graph, const R if (dep.resource.get_type() == ResourceType::RenderTarget) { RenderTargetSlot& rt = bank.render_targets.get(target); attachment_view = rt.view(); - min_raster_w = min(min_raster_w, rt.extent.width); - min_raster_h = min(min_raster_h, rt.extent.height); + min_raster_w = std::min(min_raster_w, (i32)rt.extent.width); + min_raster_h = std::min(min_raster_h, (i32)rt.extent.height); } else { const ImageSlot& image = bank.images.get(dep.resource); const TextureSlot& texture = bank.textures.get(image.texture); if (has_flag(texture.usage, TextureUsage::ColorAttachment) == false) continue; attachment_view = image.view; - min_raster_w = min(min_raster_w, texture.size.x); - min_raster_h = min(min_raster_h, texture.size.y); + min_raster_w = std::min(min_raster_w, (i32)texture.size.x); + min_raster_h = std::min(min_raster_h, (i32)texture.size.y); } /* Fill in the attachment info */ diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index f10d74a..e4b7da1 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -1,9 +1,8 @@ #include "vram_bank_vk.hh" -#include "wrapper/translate_vk.hh" +#include -#define MAX(A, B) ((A > B) ? A : B) -#define MIN(A, B) ((A < B) ? A : B) +#include "wrapper/translate_vk.hh" Result VRAMBank::init(GPUAdapter& gpu) { this->gpu = &gpu; @@ -180,11 +179,11 @@ Result VRAMBank::create_render_target(const TargetDesc& target, u3 } /* Use up to 4 images that are available, this allows for triple buffering */ - resource.data.image_count = MIN(4, MAX(1, surface_features.maxImageCount)); + resource.data.image_count = std::min(4u, std::max(1u, surface_features.maxImageCount)); /* Set the width and height, with respect to the surface limits */ - resource.data.extent.width = MIN(MAX(width, surface_features.minImageExtent.width), surface_features.maxImageExtent.width); - resource.data.extent.height = MIN(MAX(width, surface_features.minImageExtent.height), surface_features.maxImageExtent.height); + resource.data.extent.width = std::min(std::max(width, surface_features.minImageExtent.width), surface_features.maxImageExtent.width); + resource.data.extent.height = std::min(std::max(width, surface_features.minImageExtent.height), surface_features.maxImageExtent.height); /* Get the available surface formats */ u32 format_count = 0u; @@ -332,9 +331,9 @@ Result VRAMBank::create_texture(TextureUsage usage, TextureFormat fmt, VkImageCreateInfo texture_ci { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; texture_ci.imageType = size.is_2d() ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_3D; texture_ci.format = format; - texture_ci.extent = { MAX(size.x, 1u), MAX(size.y, 1u), MAX(size.z, 1u) }; - texture_ci.mipLevels = MAX(1u, meta.mips); - texture_ci.arrayLayers = MAX(1u, meta.arrays); + texture_ci.extent = { std::max(size.x, 1u), std::max(size.y, 1u), std::max(size.z, 1u) }; + texture_ci.mipLevels = std::max(1u, meta.mips); + texture_ci.arrayLayers = std::max(1u, meta.arrays); texture_ci.samples = VK_SAMPLE_COUNT_1_BIT; /* No MSAA */ texture_ci.tiling = VK_IMAGE_TILING_OPTIMAL; texture_ci.usage = translate::texture_usage(usage); @@ -366,9 +365,9 @@ Result VRAMBank::create_image(Texture texture, u32 mip, u32 layer) { VkImageSubresourceRange sub_range {}; sub_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; /* Color hardcoded! (might want depth too) */ sub_range.baseMipLevel = mip; - sub_range.levelCount = MAX(1u, texture_slot.meta.mips - mip); + sub_range.levelCount = std::max(1u, texture_slot.meta.mips - mip); sub_range.baseArrayLayer = layer; - sub_range.layerCount = MAX(1u, texture_slot.meta.arrays - layer); + sub_range.layerCount = std::max(1u, texture_slot.meta.arrays - layer); resource.data.sub_range = sub_range; /* Image view creation info */ @@ -443,8 +442,8 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid } /* Set the width and height, with respect to the surface limits */ - data.extent.width = MIN(MAX(width, surface_features.minImageExtent.width), surface_features.maxImageExtent.width); - data.extent.height = MIN(MAX(width, surface_features.minImageExtent.height), surface_features.maxImageExtent.height); + data.extent.width = std::min(std::max(width, surface_features.minImageExtent.width), surface_features.maxImageExtent.width); + data.extent.height = std::min(std::max(width, surface_features.minImageExtent.height), surface_features.maxImageExtent.height); /* Swapchain re-creation info */ VkSwapchainCreateInfoKHR swapchain_ci { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR }; @@ -574,8 +573,8 @@ Result VRAMBank::upload_texture(Texture& texture, const void* data, const vmaUnmapMemory(vma_allocator, alloc); VkBufferImageCopy copy {}; - copy.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u}; - copy.imageExtent = VkExtent3D{MAX(texture_slot.size.x, 1u), MAX(texture_slot.size.y, 1u), MAX(texture_slot.size.z, 1u)}; + copy.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u }; + copy.imageExtent = VkExtent3D { std::max(texture_slot.size.x, 1u), std::max(texture_slot.size.y, 1u), std::max(texture_slot.size.z, 1u) }; /* Create an image layout transition barrier */ VkImageMemoryBarrier2 image_barrier { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2 }; @@ -586,7 +585,7 @@ Result VRAMBank::upload_texture(Texture& texture, const void* data, const image_barrier.oldLayout = texture_slot.layout; image_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; image_barrier.image = texture_slot.image; - image_barrier.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u}; + image_barrier.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }; texture_slot.layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; /* Render target dependency info */ From e491e8007d850e5124faf29f613eca0d301245a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Tue, 16 Dec 2025 14:50:39 +0100 Subject: [PATCH 24/28] fix: graphite sample --- CMakeLists.txt | 11 ++++---- sample/CMakeLists.txt | 20 +++++++++++++++ {samples/testing => sample}/assets/test.png | Bin .../testing => sample}/extern/CMakeLists.txt | 8 +++--- .../extern/glfw/.editorconfig | 0 .../testing => sample}/extern/glfw/.mailmap | 0 .../extern/glfw/CMake/GenerateMappings.cmake | 0 .../extern/glfw/CMake/Info.plist.in | 0 .../glfw/CMake/cmake_uninstall.cmake.in | 0 .../extern/glfw/CMake/glfw3.pc.in | 0 .../extern/glfw/CMake/glfw3Config.cmake.in | 0 .../glfw/CMake/i686-w64-mingw32-clang.cmake | 0 .../extern/glfw/CMake/i686-w64-mingw32.cmake | 0 .../glfw/CMake/modules/FindEpollShim.cmake | 0 .../glfw/CMake/x86_64-w64-mingw32-clang.cmake | 0 .../glfw/CMake/x86_64-w64-mingw32.cmake | 0 .../extern/glfw/CMakeLists.txt | 0 .../extern/glfw/CONTRIBUTORS.md | 0 .../testing => sample}/extern/glfw/LICENSE.md | 0 .../testing => sample}/extern/glfw/README.md | 0 .../extern/glfw/deps/getopt.c | 0 .../extern/glfw/deps/getopt.h | 0 .../extern/glfw/deps/glad/gl.h | 0 .../extern/glfw/deps/glad/gles2.h | 0 .../extern/glfw/deps/glad/vulkan.h | 0 .../extern/glfw/deps/linmath.h | 0 .../extern/glfw/deps/mingw/_mingw_dxhelper.h | 0 .../extern/glfw/deps/mingw/dinput.h | 0 .../extern/glfw/deps/mingw/xinput.h | 0 .../extern/glfw/deps/nuklear.h | 0 .../extern/glfw/deps/nuklear_glfw_gl2.h | 0 .../extern/glfw/deps/stb_image_write.h | 0 .../extern/glfw/deps/tinycthread.c | 0 .../extern/glfw/deps/tinycthread.h | 0 .../glfw/deps/wayland/fractional-scale-v1.xml | 0 .../deps/wayland/idle-inhibit-unstable-v1.xml | 0 .../pointer-constraints-unstable-v1.xml | 0 .../wayland/relative-pointer-unstable-v1.xml | 0 .../extern/glfw/deps/wayland/viewporter.xml | 0 .../extern/glfw/deps/wayland/wayland.xml | 0 .../glfw/deps/wayland/xdg-activation-v1.xml | 0 .../wayland/xdg-decoration-unstable-v1.xml | 0 .../extern/glfw/deps/wayland/xdg-shell.xml | 0 .../extern/glfw/include/GLFW/glfw3.h | 0 .../extern/glfw/include/GLFW/glfw3native.h | 0 .../extern/glfw/src/CMakeLists.txt | 0 .../extern/glfw/src/cocoa_init.m | 0 .../extern/glfw/src/cocoa_joystick.h | 0 .../extern/glfw/src/cocoa_joystick.m | 0 .../extern/glfw/src/cocoa_monitor.m | 0 .../extern/glfw/src/cocoa_platform.h | 0 .../extern/glfw/src/cocoa_time.c | 0 .../extern/glfw/src/cocoa_time.h | 0 .../extern/glfw/src/cocoa_window.m | 0 .../extern/glfw/src/context.c | 0 .../extern/glfw/src/egl_context.c | 0 .../extern/glfw/src/glfw.rc.in | 0 .../extern/glfw/src/glx_context.c | 0 .../testing => sample}/extern/glfw/src/init.c | 0 .../extern/glfw/src/input.c | 0 .../extern/glfw/src/internal.h | 0 .../extern/glfw/src/linux_joystick.c | 0 .../extern/glfw/src/linux_joystick.h | 0 .../extern/glfw/src/mappings.h | 0 .../extern/glfw/src/mappings.h.in | 0 .../extern/glfw/src/monitor.c | 0 .../extern/glfw/src/nsgl_context.m | 0 .../extern/glfw/src/null_init.c | 0 .../extern/glfw/src/null_joystick.c | 0 .../extern/glfw/src/null_joystick.h | 0 .../extern/glfw/src/null_monitor.c | 0 .../extern/glfw/src/null_platform.h | 0 .../extern/glfw/src/null_window.c | 0 .../extern/glfw/src/osmesa_context.c | 0 .../extern/glfw/src/platform.c | 0 .../extern/glfw/src/platform.h | 0 .../extern/glfw/src/posix_module.c | 0 .../extern/glfw/src/posix_poll.c | 0 .../extern/glfw/src/posix_poll.h | 0 .../extern/glfw/src/posix_thread.c | 0 .../extern/glfw/src/posix_thread.h | 0 .../extern/glfw/src/posix_time.c | 0 .../extern/glfw/src/posix_time.h | 0 .../extern/glfw/src/vulkan.c | 0 .../extern/glfw/src/wgl_context.c | 0 .../extern/glfw/src/win32_init.c | 0 .../extern/glfw/src/win32_joystick.c | 0 .../extern/glfw/src/win32_joystick.h | 0 .../extern/glfw/src/win32_module.c | 0 .../extern/glfw/src/win32_monitor.c | 0 .../extern/glfw/src/win32_platform.h | 0 .../extern/glfw/src/win32_thread.c | 0 .../extern/glfw/src/win32_thread.h | 0 .../extern/glfw/src/win32_time.c | 0 .../extern/glfw/src/win32_time.h | 0 .../extern/glfw/src/win32_window.c | 0 .../extern/glfw/src/window.c | 0 .../extern/glfw/src/wl_init.c | 0 .../extern/glfw/src/wl_monitor.c | 0 .../extern/glfw/src/wl_platform.h | 0 .../extern/glfw/src/wl_window.c | 0 .../extern/glfw/src/x11_init.c | 0 .../extern/glfw/src/x11_monitor.c | 0 .../extern/glfw/src/x11_platform.h | 0 .../extern/glfw/src/x11_window.c | 0 .../extern/glfw/src/xkb_unicode.c | 0 .../extern/glfw/src/xkb_unicode.h | 0 .../extern/imgui/.editorconfig | 0 .../extern/imgui/.gitattributes | 0 .../extern/imgui/.gitignore | 0 .../extern/imgui/LICENSE.txt | 0 .../imgui/backends/imgui_impl_allegro5.cpp | 0 .../imgui/backends/imgui_impl_allegro5.h | 0 .../imgui/backends/imgui_impl_android.cpp | 0 .../imgui/backends/imgui_impl_android.h | 0 .../extern/imgui/backends/imgui_impl_dx10.cpp | 0 .../extern/imgui/backends/imgui_impl_dx10.h | 0 .../extern/imgui/backends/imgui_impl_dx11.cpp | 0 .../extern/imgui/backends/imgui_impl_dx11.h | 0 .../extern/imgui/backends/imgui_impl_dx12.cpp | 0 .../extern/imgui/backends/imgui_impl_dx12.h | 0 .../extern/imgui/backends/imgui_impl_dx9.cpp | 0 .../extern/imgui/backends/imgui_impl_dx9.h | 0 .../extern/imgui/backends/imgui_impl_glfw.cpp | 0 .../extern/imgui/backends/imgui_impl_glfw.h | 0 .../extern/imgui/backends/imgui_impl_glut.cpp | 0 .../extern/imgui/backends/imgui_impl_glut.h | 0 .../extern/imgui/backends/imgui_impl_metal.h | 0 .../extern/imgui/backends/imgui_impl_metal.mm | 0 .../imgui/backends/imgui_impl_opengl2.cpp | 0 .../imgui/backends/imgui_impl_opengl2.h | 0 .../imgui/backends/imgui_impl_opengl3.cpp | 0 .../imgui/backends/imgui_impl_opengl3.h | 0 .../backends/imgui_impl_opengl3_loader.h | 0 .../extern/imgui/backends/imgui_impl_osx.h | 0 .../extern/imgui/backends/imgui_impl_osx.mm | 0 .../extern/imgui/backends/imgui_impl_sdl2.cpp | 0 .../extern/imgui/backends/imgui_impl_sdl2.h | 0 .../extern/imgui/backends/imgui_impl_sdl3.cpp | 0 .../extern/imgui/backends/imgui_impl_sdl3.h | 0 .../imgui/backends/imgui_impl_sdlgpu3.cpp | 0 .../imgui/backends/imgui_impl_sdlgpu3.h | 0 .../backends/imgui_impl_sdlgpu3_shaders.h | 0 .../backends/imgui_impl_sdlrenderer2.cpp | 0 .../imgui/backends/imgui_impl_sdlrenderer2.h | 0 .../backends/imgui_impl_sdlrenderer3.cpp | 0 .../imgui/backends/imgui_impl_sdlrenderer3.h | 0 .../imgui/backends/imgui_impl_vulkan.cpp | 0 .../extern/imgui/backends/imgui_impl_vulkan.h | 0 .../extern/imgui/backends/imgui_impl_wgpu.cpp | 0 .../extern/imgui/backends/imgui_impl_wgpu.h | 0 .../imgui/backends/imgui_impl_win32.cpp | 0 .../extern/imgui/backends/imgui_impl_win32.h | 0 .../backends/sdlgpu3/build_instructions.txt | 0 .../extern/imgui/backends/sdlgpu3/shader.frag | 0 .../extern/imgui/backends/sdlgpu3/shader.vert | 0 .../backends/vulkan/build_instructions.txt | 0 .../imgui/backends/vulkan/generate_spv.sh | 0 .../imgui/backends/vulkan/glsl_shader.frag | 0 .../imgui/backends/vulkan/glsl_shader.vert | 0 .../extern/imgui/imconfig.h | 0 .../testing => sample}/extern/imgui/imgui.cpp | 0 .../testing => sample}/extern/imgui/imgui.h | 0 .../extern/imgui/imgui_demo.cpp | 0 .../extern/imgui/imgui_draw.cpp | 0 .../extern/imgui/imgui_internal.h | 0 .../extern/imgui/imgui_tables.cpp | 0 .../extern/imgui/imgui_widgets.cpp | 0 .../extern/imgui/imstb_rectpack.h | 0 .../extern/imgui/imstb_textedit.h | 0 .../extern/imgui/imstb_truetype.h | 0 .../extern/imgui/misc/README.txt | 0 .../extern/imgui/misc/cpp/README.txt | 0 .../extern/imgui/misc/cpp/imgui_stdlib.cpp | 0 .../extern/imgui/misc/cpp/imgui_stdlib.h | 0 .../extern/imgui/misc/debuggers/README.txt | 0 .../extern/imgui/misc/debuggers/imgui.gdb | 0 .../imgui/misc/debuggers/imgui.natstepfilter | 0 .../extern/imgui/misc/debuggers/imgui.natvis | 0 .../extern/imgui/misc/debuggers/imgui_lldb.py | 0 .../imgui/misc/fonts/Cousine-Regular.ttf | Bin .../extern/imgui/misc/fonts/DroidSans.ttf | Bin .../extern/imgui/misc/fonts/Karla-Regular.ttf | Bin .../extern/imgui/misc/fonts/ProggyClean.ttf | Bin .../extern/imgui/misc/fonts/ProggyTiny.ttf | Bin .../extern/imgui/misc/fonts/Roboto-Medium.ttf | Bin .../misc/fonts/binary_to_compressed_c.cpp | 0 .../extern/imgui/misc/freetype/README.md | 0 .../imgui/misc/freetype/imgui_freetype.cpp | 0 .../imgui/misc/freetype/imgui_freetype.h | 0 .../misc/single_file/imgui_single_file.h | 0 .../extern/stb_image/stb_image.h | 0 .../kernels/buffer-fill.slang | 0 .../testing => sample}/kernels/common.slang | 0 .../testing => sample}/kernels/compile.cmd | 0 .../kernels/graphics-test.slang | 0 .../testing => sample}/kernels/image.slang | 0 .../testing => sample}/kernels/test.slang | 0 {samples/testing => sample}/src/main.cc | 4 +-- samples/CMakeLists.txt | 24 ------------------ samples/testing/CMakeLists.txt | 1 - src/platform/vulkan/vram_bank_vk.cc | 10 ++++---- 202 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 sample/CMakeLists.txt rename {samples/testing => sample}/assets/test.png (100%) rename {samples/testing => sample}/extern/CMakeLists.txt (74%) rename {samples/testing => sample}/extern/glfw/.editorconfig (100%) rename {samples/testing => sample}/extern/glfw/.mailmap (100%) rename {samples/testing => sample}/extern/glfw/CMake/GenerateMappings.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMake/Info.plist.in (100%) rename {samples/testing => sample}/extern/glfw/CMake/cmake_uninstall.cmake.in (100%) rename {samples/testing => sample}/extern/glfw/CMake/glfw3.pc.in (100%) rename {samples/testing => sample}/extern/glfw/CMake/glfw3Config.cmake.in (100%) rename {samples/testing => sample}/extern/glfw/CMake/i686-w64-mingw32-clang.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMake/i686-w64-mingw32.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMake/modules/FindEpollShim.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMake/x86_64-w64-mingw32-clang.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMake/x86_64-w64-mingw32.cmake (100%) rename {samples/testing => sample}/extern/glfw/CMakeLists.txt (100%) rename {samples/testing => sample}/extern/glfw/CONTRIBUTORS.md (100%) rename {samples/testing => sample}/extern/glfw/LICENSE.md (100%) rename {samples/testing => sample}/extern/glfw/README.md (100%) rename {samples/testing => sample}/extern/glfw/deps/getopt.c (100%) rename {samples/testing => sample}/extern/glfw/deps/getopt.h (100%) rename {samples/testing => sample}/extern/glfw/deps/glad/gl.h (100%) rename {samples/testing => sample}/extern/glfw/deps/glad/gles2.h (100%) rename {samples/testing => sample}/extern/glfw/deps/glad/vulkan.h (100%) rename {samples/testing => sample}/extern/glfw/deps/linmath.h (100%) rename {samples/testing => sample}/extern/glfw/deps/mingw/_mingw_dxhelper.h (100%) rename {samples/testing => sample}/extern/glfw/deps/mingw/dinput.h (100%) rename {samples/testing => sample}/extern/glfw/deps/mingw/xinput.h (100%) rename {samples/testing => sample}/extern/glfw/deps/nuklear.h (100%) rename {samples/testing => sample}/extern/glfw/deps/nuklear_glfw_gl2.h (100%) rename {samples/testing => sample}/extern/glfw/deps/stb_image_write.h (100%) rename {samples/testing => sample}/extern/glfw/deps/tinycthread.c (100%) rename {samples/testing => sample}/extern/glfw/deps/tinycthread.h (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/fractional-scale-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/idle-inhibit-unstable-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/pointer-constraints-unstable-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/relative-pointer-unstable-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/viewporter.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/wayland.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/xdg-activation-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/xdg-decoration-unstable-v1.xml (100%) rename {samples/testing => sample}/extern/glfw/deps/wayland/xdg-shell.xml (100%) rename {samples/testing => sample}/extern/glfw/include/GLFW/glfw3.h (100%) rename {samples/testing => sample}/extern/glfw/include/GLFW/glfw3native.h (100%) rename {samples/testing => sample}/extern/glfw/src/CMakeLists.txt (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_init.m (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_joystick.h (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_joystick.m (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_monitor.m (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_time.c (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_time.h (100%) rename {samples/testing => sample}/extern/glfw/src/cocoa_window.m (100%) rename {samples/testing => sample}/extern/glfw/src/context.c (100%) rename {samples/testing => sample}/extern/glfw/src/egl_context.c (100%) rename {samples/testing => sample}/extern/glfw/src/glfw.rc.in (100%) rename {samples/testing => sample}/extern/glfw/src/glx_context.c (100%) rename {samples/testing => sample}/extern/glfw/src/init.c (100%) rename {samples/testing => sample}/extern/glfw/src/input.c (100%) rename {samples/testing => sample}/extern/glfw/src/internal.h (100%) rename {samples/testing => sample}/extern/glfw/src/linux_joystick.c (100%) rename {samples/testing => sample}/extern/glfw/src/linux_joystick.h (100%) rename {samples/testing => sample}/extern/glfw/src/mappings.h (100%) rename {samples/testing => sample}/extern/glfw/src/mappings.h.in (100%) rename {samples/testing => sample}/extern/glfw/src/monitor.c (100%) rename {samples/testing => sample}/extern/glfw/src/nsgl_context.m (100%) rename {samples/testing => sample}/extern/glfw/src/null_init.c (100%) rename {samples/testing => sample}/extern/glfw/src/null_joystick.c (100%) rename {samples/testing => sample}/extern/glfw/src/null_joystick.h (100%) rename {samples/testing => sample}/extern/glfw/src/null_monitor.c (100%) rename {samples/testing => sample}/extern/glfw/src/null_platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/null_window.c (100%) rename {samples/testing => sample}/extern/glfw/src/osmesa_context.c (100%) rename {samples/testing => sample}/extern/glfw/src/platform.c (100%) rename {samples/testing => sample}/extern/glfw/src/platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/posix_module.c (100%) rename {samples/testing => sample}/extern/glfw/src/posix_poll.c (100%) rename {samples/testing => sample}/extern/glfw/src/posix_poll.h (100%) rename {samples/testing => sample}/extern/glfw/src/posix_thread.c (100%) rename {samples/testing => sample}/extern/glfw/src/posix_thread.h (100%) rename {samples/testing => sample}/extern/glfw/src/posix_time.c (100%) rename {samples/testing => sample}/extern/glfw/src/posix_time.h (100%) rename {samples/testing => sample}/extern/glfw/src/vulkan.c (100%) rename {samples/testing => sample}/extern/glfw/src/wgl_context.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_init.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_joystick.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_joystick.h (100%) rename {samples/testing => sample}/extern/glfw/src/win32_module.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_monitor.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/win32_thread.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_thread.h (100%) rename {samples/testing => sample}/extern/glfw/src/win32_time.c (100%) rename {samples/testing => sample}/extern/glfw/src/win32_time.h (100%) rename {samples/testing => sample}/extern/glfw/src/win32_window.c (100%) rename {samples/testing => sample}/extern/glfw/src/window.c (100%) rename {samples/testing => sample}/extern/glfw/src/wl_init.c (100%) rename {samples/testing => sample}/extern/glfw/src/wl_monitor.c (100%) rename {samples/testing => sample}/extern/glfw/src/wl_platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/wl_window.c (100%) rename {samples/testing => sample}/extern/glfw/src/x11_init.c (100%) rename {samples/testing => sample}/extern/glfw/src/x11_monitor.c (100%) rename {samples/testing => sample}/extern/glfw/src/x11_platform.h (100%) rename {samples/testing => sample}/extern/glfw/src/x11_window.c (100%) rename {samples/testing => sample}/extern/glfw/src/xkb_unicode.c (100%) rename {samples/testing => sample}/extern/glfw/src/xkb_unicode.h (100%) rename {samples/testing => sample}/extern/imgui/.editorconfig (100%) rename {samples/testing => sample}/extern/imgui/.gitattributes (100%) rename {samples/testing => sample}/extern/imgui/.gitignore (100%) rename {samples/testing => sample}/extern/imgui/LICENSE.txt (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_allegro5.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_allegro5.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_android.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_android.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx10.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx10.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx11.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx11.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx12.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx12.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx9.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_dx9.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_glfw.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_glfw.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_glut.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_glut.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_metal.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_metal.mm (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_opengl2.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_opengl2.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_opengl3.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_opengl3.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_opengl3_loader.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_osx.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_osx.mm (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdl2.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdl2.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdl3.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdl3.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlgpu3.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlgpu3.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlgpu3_shaders.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlrenderer2.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlrenderer2.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlrenderer3.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_sdlrenderer3.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_vulkan.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_vulkan.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_wgpu.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_wgpu.h (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_win32.cpp (100%) rename {samples/testing => sample}/extern/imgui/backends/imgui_impl_win32.h (100%) rename {samples/testing => sample}/extern/imgui/backends/sdlgpu3/build_instructions.txt (100%) rename {samples/testing => sample}/extern/imgui/backends/sdlgpu3/shader.frag (100%) rename {samples/testing => sample}/extern/imgui/backends/sdlgpu3/shader.vert (100%) rename {samples/testing => sample}/extern/imgui/backends/vulkan/build_instructions.txt (100%) rename {samples/testing => sample}/extern/imgui/backends/vulkan/generate_spv.sh (100%) rename {samples/testing => sample}/extern/imgui/backends/vulkan/glsl_shader.frag (100%) rename {samples/testing => sample}/extern/imgui/backends/vulkan/glsl_shader.vert (100%) rename {samples/testing => sample}/extern/imgui/imconfig.h (100%) rename {samples/testing => sample}/extern/imgui/imgui.cpp (100%) rename {samples/testing => sample}/extern/imgui/imgui.h (100%) rename {samples/testing => sample}/extern/imgui/imgui_demo.cpp (100%) rename {samples/testing => sample}/extern/imgui/imgui_draw.cpp (100%) rename {samples/testing => sample}/extern/imgui/imgui_internal.h (100%) rename {samples/testing => sample}/extern/imgui/imgui_tables.cpp (100%) rename {samples/testing => sample}/extern/imgui/imgui_widgets.cpp (100%) rename {samples/testing => sample}/extern/imgui/imstb_rectpack.h (100%) rename {samples/testing => sample}/extern/imgui/imstb_textedit.h (100%) rename {samples/testing => sample}/extern/imgui/imstb_truetype.h (100%) rename {samples/testing => sample}/extern/imgui/misc/README.txt (100%) rename {samples/testing => sample}/extern/imgui/misc/cpp/README.txt (100%) rename {samples/testing => sample}/extern/imgui/misc/cpp/imgui_stdlib.cpp (100%) rename {samples/testing => sample}/extern/imgui/misc/cpp/imgui_stdlib.h (100%) rename {samples/testing => sample}/extern/imgui/misc/debuggers/README.txt (100%) rename {samples/testing => sample}/extern/imgui/misc/debuggers/imgui.gdb (100%) rename {samples/testing => sample}/extern/imgui/misc/debuggers/imgui.natstepfilter (100%) rename {samples/testing => sample}/extern/imgui/misc/debuggers/imgui.natvis (100%) rename {samples/testing => sample}/extern/imgui/misc/debuggers/imgui_lldb.py (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/Cousine-Regular.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/DroidSans.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/Karla-Regular.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/ProggyClean.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/ProggyTiny.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/Roboto-Medium.ttf (100%) rename {samples/testing => sample}/extern/imgui/misc/fonts/binary_to_compressed_c.cpp (100%) rename {samples/testing => sample}/extern/imgui/misc/freetype/README.md (100%) rename {samples/testing => sample}/extern/imgui/misc/freetype/imgui_freetype.cpp (100%) rename {samples/testing => sample}/extern/imgui/misc/freetype/imgui_freetype.h (100%) rename {samples/testing => sample}/extern/imgui/misc/single_file/imgui_single_file.h (100%) rename {samples/testing => sample}/extern/stb_image/stb_image.h (100%) rename {samples/testing => sample}/kernels/buffer-fill.slang (100%) rename {samples/testing => sample}/kernels/common.slang (100%) rename {samples/testing => sample}/kernels/compile.cmd (100%) rename {samples/testing => sample}/kernels/graphics-test.slang (100%) rename {samples/testing => sample}/kernels/image.slang (100%) rename {samples/testing => sample}/kernels/test.slang (100%) rename {samples/testing => sample}/src/main.cc (98%) delete mode 100644 samples/CMakeLists.txt delete mode 100644 samples/testing/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 90157ec..d08277c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,12 @@ endif() target_compile_definitions(graphite PUBLIC PLATFORM_EXT=${PLATFORM_EXT}) target_compile_definitions(graphite PUBLIC PLATFORM=${PLATFORM}) +# Samples directory +if(GRAPHITE_SAMPLES) + add_subdirectory("sample") + set(GRAPHITE_IMGUI_DIR "${CMAKE_SOURCE_DIR}/sample/extern/imgui/") +endif() + # ImGUI support if(GRAPHITE_IMGUI_DIR) # Sources @@ -87,10 +93,5 @@ if(GRAPHITE_PLATFORM STREQUAL "Vulkan") ) endif() -# Samples directory -if(GRAPHITE_SAMPLES) - add_subdirectory("samples") -endif() - # External dependencies add_subdirectory("extern") diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..5cf8fd8 --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,20 @@ +set(SAMPLE_DIR .) +set(EXE_NAME sample) + +# Executable target +project(${EXE_NAME}) +add_executable(${EXE_NAME} "${SAMPLE_DIR}/src/main.cc") +set_target_properties(${EXE_NAME} PROPERTIES OUTPUT_NAME ${EXE_NAME}) + +# Add compiler definitions +target_compile_definitions(${EXE_NAME} PRIVATE $<$:DEBUG=1>) +target_compile_definitions(${EXE_NAME} PRIVATE $<$:NDEBUG=1>) + +# Include directories +target_include_directories(${EXE_NAME} PRIVATE "${SAMPLE_DIR}/src/") + +# Link to the Graphite library +target_link_libraries(${EXE_NAME} PRIVATE graphite) + +# External dependencies +add_subdirectory("extern") diff --git a/samples/testing/assets/test.png b/sample/assets/test.png similarity index 100% rename from samples/testing/assets/test.png rename to sample/assets/test.png diff --git a/samples/testing/extern/CMakeLists.txt b/sample/extern/CMakeLists.txt similarity index 74% rename from samples/testing/extern/CMakeLists.txt rename to sample/extern/CMakeLists.txt index a1b41f2..c0f52c0 100644 --- a/samples/testing/extern/CMakeLists.txt +++ b/sample/extern/CMakeLists.txt @@ -1,9 +1,9 @@ # GLFW add_subdirectory("glfw") -target_link_libraries(sample-testing PRIVATE glfw) +target_link_libraries(sample PRIVATE glfw) # ImGUI -target_sources(sample-testing +target_sources(sample PRIVATE "./imgui/imgui_demo.cpp" PRIVATE "./imgui/imgui_draw.cpp" PRIVATE "./imgui/imgui_tables.cpp" @@ -13,12 +13,12 @@ target_sources(sample-testing PRIVATE "./imgui/backends/imgui_impl_vulkan.cpp" PRIVATE "./imgui/backends/imgui_impl_win32.cpp" ) -target_include_directories(sample-testing +target_include_directories(sample PRIVATE "./imgui" PRIVATE "./imgui/backends" ) # STB Image -target_include_directories(sample-testing +target_include_directories(sample PRIVATE "./stb_image" ) \ No newline at end of file diff --git a/samples/testing/extern/glfw/.editorconfig b/sample/extern/glfw/.editorconfig similarity index 100% rename from samples/testing/extern/glfw/.editorconfig rename to sample/extern/glfw/.editorconfig diff --git a/samples/testing/extern/glfw/.mailmap b/sample/extern/glfw/.mailmap similarity index 100% rename from samples/testing/extern/glfw/.mailmap rename to sample/extern/glfw/.mailmap diff --git a/samples/testing/extern/glfw/CMake/GenerateMappings.cmake b/sample/extern/glfw/CMake/GenerateMappings.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/GenerateMappings.cmake rename to sample/extern/glfw/CMake/GenerateMappings.cmake diff --git a/samples/testing/extern/glfw/CMake/Info.plist.in b/sample/extern/glfw/CMake/Info.plist.in similarity index 100% rename from samples/testing/extern/glfw/CMake/Info.plist.in rename to sample/extern/glfw/CMake/Info.plist.in diff --git a/samples/testing/extern/glfw/CMake/cmake_uninstall.cmake.in b/sample/extern/glfw/CMake/cmake_uninstall.cmake.in similarity index 100% rename from samples/testing/extern/glfw/CMake/cmake_uninstall.cmake.in rename to sample/extern/glfw/CMake/cmake_uninstall.cmake.in diff --git a/samples/testing/extern/glfw/CMake/glfw3.pc.in b/sample/extern/glfw/CMake/glfw3.pc.in similarity index 100% rename from samples/testing/extern/glfw/CMake/glfw3.pc.in rename to sample/extern/glfw/CMake/glfw3.pc.in diff --git a/samples/testing/extern/glfw/CMake/glfw3Config.cmake.in b/sample/extern/glfw/CMake/glfw3Config.cmake.in similarity index 100% rename from samples/testing/extern/glfw/CMake/glfw3Config.cmake.in rename to sample/extern/glfw/CMake/glfw3Config.cmake.in diff --git a/samples/testing/extern/glfw/CMake/i686-w64-mingw32-clang.cmake b/sample/extern/glfw/CMake/i686-w64-mingw32-clang.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/i686-w64-mingw32-clang.cmake rename to sample/extern/glfw/CMake/i686-w64-mingw32-clang.cmake diff --git a/samples/testing/extern/glfw/CMake/i686-w64-mingw32.cmake b/sample/extern/glfw/CMake/i686-w64-mingw32.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/i686-w64-mingw32.cmake rename to sample/extern/glfw/CMake/i686-w64-mingw32.cmake diff --git a/samples/testing/extern/glfw/CMake/modules/FindEpollShim.cmake b/sample/extern/glfw/CMake/modules/FindEpollShim.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/modules/FindEpollShim.cmake rename to sample/extern/glfw/CMake/modules/FindEpollShim.cmake diff --git a/samples/testing/extern/glfw/CMake/x86_64-w64-mingw32-clang.cmake b/sample/extern/glfw/CMake/x86_64-w64-mingw32-clang.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/x86_64-w64-mingw32-clang.cmake rename to sample/extern/glfw/CMake/x86_64-w64-mingw32-clang.cmake diff --git a/samples/testing/extern/glfw/CMake/x86_64-w64-mingw32.cmake b/sample/extern/glfw/CMake/x86_64-w64-mingw32.cmake similarity index 100% rename from samples/testing/extern/glfw/CMake/x86_64-w64-mingw32.cmake rename to sample/extern/glfw/CMake/x86_64-w64-mingw32.cmake diff --git a/samples/testing/extern/glfw/CMakeLists.txt b/sample/extern/glfw/CMakeLists.txt similarity index 100% rename from samples/testing/extern/glfw/CMakeLists.txt rename to sample/extern/glfw/CMakeLists.txt diff --git a/samples/testing/extern/glfw/CONTRIBUTORS.md b/sample/extern/glfw/CONTRIBUTORS.md similarity index 100% rename from samples/testing/extern/glfw/CONTRIBUTORS.md rename to sample/extern/glfw/CONTRIBUTORS.md diff --git a/samples/testing/extern/glfw/LICENSE.md b/sample/extern/glfw/LICENSE.md similarity index 100% rename from samples/testing/extern/glfw/LICENSE.md rename to sample/extern/glfw/LICENSE.md diff --git a/samples/testing/extern/glfw/README.md b/sample/extern/glfw/README.md similarity index 100% rename from samples/testing/extern/glfw/README.md rename to sample/extern/glfw/README.md diff --git a/samples/testing/extern/glfw/deps/getopt.c b/sample/extern/glfw/deps/getopt.c similarity index 100% rename from samples/testing/extern/glfw/deps/getopt.c rename to sample/extern/glfw/deps/getopt.c diff --git a/samples/testing/extern/glfw/deps/getopt.h b/sample/extern/glfw/deps/getopt.h similarity index 100% rename from samples/testing/extern/glfw/deps/getopt.h rename to sample/extern/glfw/deps/getopt.h diff --git a/samples/testing/extern/glfw/deps/glad/gl.h b/sample/extern/glfw/deps/glad/gl.h similarity index 100% rename from samples/testing/extern/glfw/deps/glad/gl.h rename to sample/extern/glfw/deps/glad/gl.h diff --git a/samples/testing/extern/glfw/deps/glad/gles2.h b/sample/extern/glfw/deps/glad/gles2.h similarity index 100% rename from samples/testing/extern/glfw/deps/glad/gles2.h rename to sample/extern/glfw/deps/glad/gles2.h diff --git a/samples/testing/extern/glfw/deps/glad/vulkan.h b/sample/extern/glfw/deps/glad/vulkan.h similarity index 100% rename from samples/testing/extern/glfw/deps/glad/vulkan.h rename to sample/extern/glfw/deps/glad/vulkan.h diff --git a/samples/testing/extern/glfw/deps/linmath.h b/sample/extern/glfw/deps/linmath.h similarity index 100% rename from samples/testing/extern/glfw/deps/linmath.h rename to sample/extern/glfw/deps/linmath.h diff --git a/samples/testing/extern/glfw/deps/mingw/_mingw_dxhelper.h b/sample/extern/glfw/deps/mingw/_mingw_dxhelper.h similarity index 100% rename from samples/testing/extern/glfw/deps/mingw/_mingw_dxhelper.h rename to sample/extern/glfw/deps/mingw/_mingw_dxhelper.h diff --git a/samples/testing/extern/glfw/deps/mingw/dinput.h b/sample/extern/glfw/deps/mingw/dinput.h similarity index 100% rename from samples/testing/extern/glfw/deps/mingw/dinput.h rename to sample/extern/glfw/deps/mingw/dinput.h diff --git a/samples/testing/extern/glfw/deps/mingw/xinput.h b/sample/extern/glfw/deps/mingw/xinput.h similarity index 100% rename from samples/testing/extern/glfw/deps/mingw/xinput.h rename to sample/extern/glfw/deps/mingw/xinput.h diff --git a/samples/testing/extern/glfw/deps/nuklear.h b/sample/extern/glfw/deps/nuklear.h similarity index 100% rename from samples/testing/extern/glfw/deps/nuklear.h rename to sample/extern/glfw/deps/nuklear.h diff --git a/samples/testing/extern/glfw/deps/nuklear_glfw_gl2.h b/sample/extern/glfw/deps/nuklear_glfw_gl2.h similarity index 100% rename from samples/testing/extern/glfw/deps/nuklear_glfw_gl2.h rename to sample/extern/glfw/deps/nuklear_glfw_gl2.h diff --git a/samples/testing/extern/glfw/deps/stb_image_write.h b/sample/extern/glfw/deps/stb_image_write.h similarity index 100% rename from samples/testing/extern/glfw/deps/stb_image_write.h rename to sample/extern/glfw/deps/stb_image_write.h diff --git a/samples/testing/extern/glfw/deps/tinycthread.c b/sample/extern/glfw/deps/tinycthread.c similarity index 100% rename from samples/testing/extern/glfw/deps/tinycthread.c rename to sample/extern/glfw/deps/tinycthread.c diff --git a/samples/testing/extern/glfw/deps/tinycthread.h b/sample/extern/glfw/deps/tinycthread.h similarity index 100% rename from samples/testing/extern/glfw/deps/tinycthread.h rename to sample/extern/glfw/deps/tinycthread.h diff --git a/samples/testing/extern/glfw/deps/wayland/fractional-scale-v1.xml b/sample/extern/glfw/deps/wayland/fractional-scale-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/fractional-scale-v1.xml rename to sample/extern/glfw/deps/wayland/fractional-scale-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/idle-inhibit-unstable-v1.xml b/sample/extern/glfw/deps/wayland/idle-inhibit-unstable-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/idle-inhibit-unstable-v1.xml rename to sample/extern/glfw/deps/wayland/idle-inhibit-unstable-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/pointer-constraints-unstable-v1.xml b/sample/extern/glfw/deps/wayland/pointer-constraints-unstable-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/pointer-constraints-unstable-v1.xml rename to sample/extern/glfw/deps/wayland/pointer-constraints-unstable-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/relative-pointer-unstable-v1.xml b/sample/extern/glfw/deps/wayland/relative-pointer-unstable-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/relative-pointer-unstable-v1.xml rename to sample/extern/glfw/deps/wayland/relative-pointer-unstable-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/viewporter.xml b/sample/extern/glfw/deps/wayland/viewporter.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/viewporter.xml rename to sample/extern/glfw/deps/wayland/viewporter.xml diff --git a/samples/testing/extern/glfw/deps/wayland/wayland.xml b/sample/extern/glfw/deps/wayland/wayland.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/wayland.xml rename to sample/extern/glfw/deps/wayland/wayland.xml diff --git a/samples/testing/extern/glfw/deps/wayland/xdg-activation-v1.xml b/sample/extern/glfw/deps/wayland/xdg-activation-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/xdg-activation-v1.xml rename to sample/extern/glfw/deps/wayland/xdg-activation-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/xdg-decoration-unstable-v1.xml b/sample/extern/glfw/deps/wayland/xdg-decoration-unstable-v1.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/xdg-decoration-unstable-v1.xml rename to sample/extern/glfw/deps/wayland/xdg-decoration-unstable-v1.xml diff --git a/samples/testing/extern/glfw/deps/wayland/xdg-shell.xml b/sample/extern/glfw/deps/wayland/xdg-shell.xml similarity index 100% rename from samples/testing/extern/glfw/deps/wayland/xdg-shell.xml rename to sample/extern/glfw/deps/wayland/xdg-shell.xml diff --git a/samples/testing/extern/glfw/include/GLFW/glfw3.h b/sample/extern/glfw/include/GLFW/glfw3.h similarity index 100% rename from samples/testing/extern/glfw/include/GLFW/glfw3.h rename to sample/extern/glfw/include/GLFW/glfw3.h diff --git a/samples/testing/extern/glfw/include/GLFW/glfw3native.h b/sample/extern/glfw/include/GLFW/glfw3native.h similarity index 100% rename from samples/testing/extern/glfw/include/GLFW/glfw3native.h rename to sample/extern/glfw/include/GLFW/glfw3native.h diff --git a/samples/testing/extern/glfw/src/CMakeLists.txt b/sample/extern/glfw/src/CMakeLists.txt similarity index 100% rename from samples/testing/extern/glfw/src/CMakeLists.txt rename to sample/extern/glfw/src/CMakeLists.txt diff --git a/samples/testing/extern/glfw/src/cocoa_init.m b/sample/extern/glfw/src/cocoa_init.m similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_init.m rename to sample/extern/glfw/src/cocoa_init.m diff --git a/samples/testing/extern/glfw/src/cocoa_joystick.h b/sample/extern/glfw/src/cocoa_joystick.h similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_joystick.h rename to sample/extern/glfw/src/cocoa_joystick.h diff --git a/samples/testing/extern/glfw/src/cocoa_joystick.m b/sample/extern/glfw/src/cocoa_joystick.m similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_joystick.m rename to sample/extern/glfw/src/cocoa_joystick.m diff --git a/samples/testing/extern/glfw/src/cocoa_monitor.m b/sample/extern/glfw/src/cocoa_monitor.m similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_monitor.m rename to sample/extern/glfw/src/cocoa_monitor.m diff --git a/samples/testing/extern/glfw/src/cocoa_platform.h b/sample/extern/glfw/src/cocoa_platform.h similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_platform.h rename to sample/extern/glfw/src/cocoa_platform.h diff --git a/samples/testing/extern/glfw/src/cocoa_time.c b/sample/extern/glfw/src/cocoa_time.c similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_time.c rename to sample/extern/glfw/src/cocoa_time.c diff --git a/samples/testing/extern/glfw/src/cocoa_time.h b/sample/extern/glfw/src/cocoa_time.h similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_time.h rename to sample/extern/glfw/src/cocoa_time.h diff --git a/samples/testing/extern/glfw/src/cocoa_window.m b/sample/extern/glfw/src/cocoa_window.m similarity index 100% rename from samples/testing/extern/glfw/src/cocoa_window.m rename to sample/extern/glfw/src/cocoa_window.m diff --git a/samples/testing/extern/glfw/src/context.c b/sample/extern/glfw/src/context.c similarity index 100% rename from samples/testing/extern/glfw/src/context.c rename to sample/extern/glfw/src/context.c diff --git a/samples/testing/extern/glfw/src/egl_context.c b/sample/extern/glfw/src/egl_context.c similarity index 100% rename from samples/testing/extern/glfw/src/egl_context.c rename to sample/extern/glfw/src/egl_context.c diff --git a/samples/testing/extern/glfw/src/glfw.rc.in b/sample/extern/glfw/src/glfw.rc.in similarity index 100% rename from samples/testing/extern/glfw/src/glfw.rc.in rename to sample/extern/glfw/src/glfw.rc.in diff --git a/samples/testing/extern/glfw/src/glx_context.c b/sample/extern/glfw/src/glx_context.c similarity index 100% rename from samples/testing/extern/glfw/src/glx_context.c rename to sample/extern/glfw/src/glx_context.c diff --git a/samples/testing/extern/glfw/src/init.c b/sample/extern/glfw/src/init.c similarity index 100% rename from samples/testing/extern/glfw/src/init.c rename to sample/extern/glfw/src/init.c diff --git a/samples/testing/extern/glfw/src/input.c b/sample/extern/glfw/src/input.c similarity index 100% rename from samples/testing/extern/glfw/src/input.c rename to sample/extern/glfw/src/input.c diff --git a/samples/testing/extern/glfw/src/internal.h b/sample/extern/glfw/src/internal.h similarity index 100% rename from samples/testing/extern/glfw/src/internal.h rename to sample/extern/glfw/src/internal.h diff --git a/samples/testing/extern/glfw/src/linux_joystick.c b/sample/extern/glfw/src/linux_joystick.c similarity index 100% rename from samples/testing/extern/glfw/src/linux_joystick.c rename to sample/extern/glfw/src/linux_joystick.c diff --git a/samples/testing/extern/glfw/src/linux_joystick.h b/sample/extern/glfw/src/linux_joystick.h similarity index 100% rename from samples/testing/extern/glfw/src/linux_joystick.h rename to sample/extern/glfw/src/linux_joystick.h diff --git a/samples/testing/extern/glfw/src/mappings.h b/sample/extern/glfw/src/mappings.h similarity index 100% rename from samples/testing/extern/glfw/src/mappings.h rename to sample/extern/glfw/src/mappings.h diff --git a/samples/testing/extern/glfw/src/mappings.h.in b/sample/extern/glfw/src/mappings.h.in similarity index 100% rename from samples/testing/extern/glfw/src/mappings.h.in rename to sample/extern/glfw/src/mappings.h.in diff --git a/samples/testing/extern/glfw/src/monitor.c b/sample/extern/glfw/src/monitor.c similarity index 100% rename from samples/testing/extern/glfw/src/monitor.c rename to sample/extern/glfw/src/monitor.c diff --git a/samples/testing/extern/glfw/src/nsgl_context.m b/sample/extern/glfw/src/nsgl_context.m similarity index 100% rename from samples/testing/extern/glfw/src/nsgl_context.m rename to sample/extern/glfw/src/nsgl_context.m diff --git a/samples/testing/extern/glfw/src/null_init.c b/sample/extern/glfw/src/null_init.c similarity index 100% rename from samples/testing/extern/glfw/src/null_init.c rename to sample/extern/glfw/src/null_init.c diff --git a/samples/testing/extern/glfw/src/null_joystick.c b/sample/extern/glfw/src/null_joystick.c similarity index 100% rename from samples/testing/extern/glfw/src/null_joystick.c rename to sample/extern/glfw/src/null_joystick.c diff --git a/samples/testing/extern/glfw/src/null_joystick.h b/sample/extern/glfw/src/null_joystick.h similarity index 100% rename from samples/testing/extern/glfw/src/null_joystick.h rename to sample/extern/glfw/src/null_joystick.h diff --git a/samples/testing/extern/glfw/src/null_monitor.c b/sample/extern/glfw/src/null_monitor.c similarity index 100% rename from samples/testing/extern/glfw/src/null_monitor.c rename to sample/extern/glfw/src/null_monitor.c diff --git a/samples/testing/extern/glfw/src/null_platform.h b/sample/extern/glfw/src/null_platform.h similarity index 100% rename from samples/testing/extern/glfw/src/null_platform.h rename to sample/extern/glfw/src/null_platform.h diff --git a/samples/testing/extern/glfw/src/null_window.c b/sample/extern/glfw/src/null_window.c similarity index 100% rename from samples/testing/extern/glfw/src/null_window.c rename to sample/extern/glfw/src/null_window.c diff --git a/samples/testing/extern/glfw/src/osmesa_context.c b/sample/extern/glfw/src/osmesa_context.c similarity index 100% rename from samples/testing/extern/glfw/src/osmesa_context.c rename to sample/extern/glfw/src/osmesa_context.c diff --git a/samples/testing/extern/glfw/src/platform.c b/sample/extern/glfw/src/platform.c similarity index 100% rename from samples/testing/extern/glfw/src/platform.c rename to sample/extern/glfw/src/platform.c diff --git a/samples/testing/extern/glfw/src/platform.h b/sample/extern/glfw/src/platform.h similarity index 100% rename from samples/testing/extern/glfw/src/platform.h rename to sample/extern/glfw/src/platform.h diff --git a/samples/testing/extern/glfw/src/posix_module.c b/sample/extern/glfw/src/posix_module.c similarity index 100% rename from samples/testing/extern/glfw/src/posix_module.c rename to sample/extern/glfw/src/posix_module.c diff --git a/samples/testing/extern/glfw/src/posix_poll.c b/sample/extern/glfw/src/posix_poll.c similarity index 100% rename from samples/testing/extern/glfw/src/posix_poll.c rename to sample/extern/glfw/src/posix_poll.c diff --git a/samples/testing/extern/glfw/src/posix_poll.h b/sample/extern/glfw/src/posix_poll.h similarity index 100% rename from samples/testing/extern/glfw/src/posix_poll.h rename to sample/extern/glfw/src/posix_poll.h diff --git a/samples/testing/extern/glfw/src/posix_thread.c b/sample/extern/glfw/src/posix_thread.c similarity index 100% rename from samples/testing/extern/glfw/src/posix_thread.c rename to sample/extern/glfw/src/posix_thread.c diff --git a/samples/testing/extern/glfw/src/posix_thread.h b/sample/extern/glfw/src/posix_thread.h similarity index 100% rename from samples/testing/extern/glfw/src/posix_thread.h rename to sample/extern/glfw/src/posix_thread.h diff --git a/samples/testing/extern/glfw/src/posix_time.c b/sample/extern/glfw/src/posix_time.c similarity index 100% rename from samples/testing/extern/glfw/src/posix_time.c rename to sample/extern/glfw/src/posix_time.c diff --git a/samples/testing/extern/glfw/src/posix_time.h b/sample/extern/glfw/src/posix_time.h similarity index 100% rename from samples/testing/extern/glfw/src/posix_time.h rename to sample/extern/glfw/src/posix_time.h diff --git a/samples/testing/extern/glfw/src/vulkan.c b/sample/extern/glfw/src/vulkan.c similarity index 100% rename from samples/testing/extern/glfw/src/vulkan.c rename to sample/extern/glfw/src/vulkan.c diff --git a/samples/testing/extern/glfw/src/wgl_context.c b/sample/extern/glfw/src/wgl_context.c similarity index 100% rename from samples/testing/extern/glfw/src/wgl_context.c rename to sample/extern/glfw/src/wgl_context.c diff --git a/samples/testing/extern/glfw/src/win32_init.c b/sample/extern/glfw/src/win32_init.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_init.c rename to sample/extern/glfw/src/win32_init.c diff --git a/samples/testing/extern/glfw/src/win32_joystick.c b/sample/extern/glfw/src/win32_joystick.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_joystick.c rename to sample/extern/glfw/src/win32_joystick.c diff --git a/samples/testing/extern/glfw/src/win32_joystick.h b/sample/extern/glfw/src/win32_joystick.h similarity index 100% rename from samples/testing/extern/glfw/src/win32_joystick.h rename to sample/extern/glfw/src/win32_joystick.h diff --git a/samples/testing/extern/glfw/src/win32_module.c b/sample/extern/glfw/src/win32_module.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_module.c rename to sample/extern/glfw/src/win32_module.c diff --git a/samples/testing/extern/glfw/src/win32_monitor.c b/sample/extern/glfw/src/win32_monitor.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_monitor.c rename to sample/extern/glfw/src/win32_monitor.c diff --git a/samples/testing/extern/glfw/src/win32_platform.h b/sample/extern/glfw/src/win32_platform.h similarity index 100% rename from samples/testing/extern/glfw/src/win32_platform.h rename to sample/extern/glfw/src/win32_platform.h diff --git a/samples/testing/extern/glfw/src/win32_thread.c b/sample/extern/glfw/src/win32_thread.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_thread.c rename to sample/extern/glfw/src/win32_thread.c diff --git a/samples/testing/extern/glfw/src/win32_thread.h b/sample/extern/glfw/src/win32_thread.h similarity index 100% rename from samples/testing/extern/glfw/src/win32_thread.h rename to sample/extern/glfw/src/win32_thread.h diff --git a/samples/testing/extern/glfw/src/win32_time.c b/sample/extern/glfw/src/win32_time.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_time.c rename to sample/extern/glfw/src/win32_time.c diff --git a/samples/testing/extern/glfw/src/win32_time.h b/sample/extern/glfw/src/win32_time.h similarity index 100% rename from samples/testing/extern/glfw/src/win32_time.h rename to sample/extern/glfw/src/win32_time.h diff --git a/samples/testing/extern/glfw/src/win32_window.c b/sample/extern/glfw/src/win32_window.c similarity index 100% rename from samples/testing/extern/glfw/src/win32_window.c rename to sample/extern/glfw/src/win32_window.c diff --git a/samples/testing/extern/glfw/src/window.c b/sample/extern/glfw/src/window.c similarity index 100% rename from samples/testing/extern/glfw/src/window.c rename to sample/extern/glfw/src/window.c diff --git a/samples/testing/extern/glfw/src/wl_init.c b/sample/extern/glfw/src/wl_init.c similarity index 100% rename from samples/testing/extern/glfw/src/wl_init.c rename to sample/extern/glfw/src/wl_init.c diff --git a/samples/testing/extern/glfw/src/wl_monitor.c b/sample/extern/glfw/src/wl_monitor.c similarity index 100% rename from samples/testing/extern/glfw/src/wl_monitor.c rename to sample/extern/glfw/src/wl_monitor.c diff --git a/samples/testing/extern/glfw/src/wl_platform.h b/sample/extern/glfw/src/wl_platform.h similarity index 100% rename from samples/testing/extern/glfw/src/wl_platform.h rename to sample/extern/glfw/src/wl_platform.h diff --git a/samples/testing/extern/glfw/src/wl_window.c b/sample/extern/glfw/src/wl_window.c similarity index 100% rename from samples/testing/extern/glfw/src/wl_window.c rename to sample/extern/glfw/src/wl_window.c diff --git a/samples/testing/extern/glfw/src/x11_init.c b/sample/extern/glfw/src/x11_init.c similarity index 100% rename from samples/testing/extern/glfw/src/x11_init.c rename to sample/extern/glfw/src/x11_init.c diff --git a/samples/testing/extern/glfw/src/x11_monitor.c b/sample/extern/glfw/src/x11_monitor.c similarity index 100% rename from samples/testing/extern/glfw/src/x11_monitor.c rename to sample/extern/glfw/src/x11_monitor.c diff --git a/samples/testing/extern/glfw/src/x11_platform.h b/sample/extern/glfw/src/x11_platform.h similarity index 100% rename from samples/testing/extern/glfw/src/x11_platform.h rename to sample/extern/glfw/src/x11_platform.h diff --git a/samples/testing/extern/glfw/src/x11_window.c b/sample/extern/glfw/src/x11_window.c similarity index 100% rename from samples/testing/extern/glfw/src/x11_window.c rename to sample/extern/glfw/src/x11_window.c diff --git a/samples/testing/extern/glfw/src/xkb_unicode.c b/sample/extern/glfw/src/xkb_unicode.c similarity index 100% rename from samples/testing/extern/glfw/src/xkb_unicode.c rename to sample/extern/glfw/src/xkb_unicode.c diff --git a/samples/testing/extern/glfw/src/xkb_unicode.h b/sample/extern/glfw/src/xkb_unicode.h similarity index 100% rename from samples/testing/extern/glfw/src/xkb_unicode.h rename to sample/extern/glfw/src/xkb_unicode.h diff --git a/samples/testing/extern/imgui/.editorconfig b/sample/extern/imgui/.editorconfig similarity index 100% rename from samples/testing/extern/imgui/.editorconfig rename to sample/extern/imgui/.editorconfig diff --git a/samples/testing/extern/imgui/.gitattributes b/sample/extern/imgui/.gitattributes similarity index 100% rename from samples/testing/extern/imgui/.gitattributes rename to sample/extern/imgui/.gitattributes diff --git a/samples/testing/extern/imgui/.gitignore b/sample/extern/imgui/.gitignore similarity index 100% rename from samples/testing/extern/imgui/.gitignore rename to sample/extern/imgui/.gitignore diff --git a/samples/testing/extern/imgui/LICENSE.txt b/sample/extern/imgui/LICENSE.txt similarity index 100% rename from samples/testing/extern/imgui/LICENSE.txt rename to sample/extern/imgui/LICENSE.txt diff --git a/samples/testing/extern/imgui/backends/imgui_impl_allegro5.cpp b/sample/extern/imgui/backends/imgui_impl_allegro5.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_allegro5.cpp rename to sample/extern/imgui/backends/imgui_impl_allegro5.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_allegro5.h b/sample/extern/imgui/backends/imgui_impl_allegro5.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_allegro5.h rename to sample/extern/imgui/backends/imgui_impl_allegro5.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_android.cpp b/sample/extern/imgui/backends/imgui_impl_android.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_android.cpp rename to sample/extern/imgui/backends/imgui_impl_android.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_android.h b/sample/extern/imgui/backends/imgui_impl_android.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_android.h rename to sample/extern/imgui/backends/imgui_impl_android.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx10.cpp b/sample/extern/imgui/backends/imgui_impl_dx10.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx10.cpp rename to sample/extern/imgui/backends/imgui_impl_dx10.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx10.h b/sample/extern/imgui/backends/imgui_impl_dx10.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx10.h rename to sample/extern/imgui/backends/imgui_impl_dx10.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx11.cpp b/sample/extern/imgui/backends/imgui_impl_dx11.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx11.cpp rename to sample/extern/imgui/backends/imgui_impl_dx11.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx11.h b/sample/extern/imgui/backends/imgui_impl_dx11.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx11.h rename to sample/extern/imgui/backends/imgui_impl_dx11.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx12.cpp b/sample/extern/imgui/backends/imgui_impl_dx12.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx12.cpp rename to sample/extern/imgui/backends/imgui_impl_dx12.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx12.h b/sample/extern/imgui/backends/imgui_impl_dx12.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx12.h rename to sample/extern/imgui/backends/imgui_impl_dx12.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx9.cpp b/sample/extern/imgui/backends/imgui_impl_dx9.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx9.cpp rename to sample/extern/imgui/backends/imgui_impl_dx9.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_dx9.h b/sample/extern/imgui/backends/imgui_impl_dx9.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_dx9.h rename to sample/extern/imgui/backends/imgui_impl_dx9.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_glfw.cpp b/sample/extern/imgui/backends/imgui_impl_glfw.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_glfw.cpp rename to sample/extern/imgui/backends/imgui_impl_glfw.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_glfw.h b/sample/extern/imgui/backends/imgui_impl_glfw.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_glfw.h rename to sample/extern/imgui/backends/imgui_impl_glfw.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_glut.cpp b/sample/extern/imgui/backends/imgui_impl_glut.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_glut.cpp rename to sample/extern/imgui/backends/imgui_impl_glut.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_glut.h b/sample/extern/imgui/backends/imgui_impl_glut.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_glut.h rename to sample/extern/imgui/backends/imgui_impl_glut.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_metal.h b/sample/extern/imgui/backends/imgui_impl_metal.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_metal.h rename to sample/extern/imgui/backends/imgui_impl_metal.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_metal.mm b/sample/extern/imgui/backends/imgui_impl_metal.mm similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_metal.mm rename to sample/extern/imgui/backends/imgui_impl_metal.mm diff --git a/samples/testing/extern/imgui/backends/imgui_impl_opengl2.cpp b/sample/extern/imgui/backends/imgui_impl_opengl2.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_opengl2.cpp rename to sample/extern/imgui/backends/imgui_impl_opengl2.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_opengl2.h b/sample/extern/imgui/backends/imgui_impl_opengl2.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_opengl2.h rename to sample/extern/imgui/backends/imgui_impl_opengl2.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_opengl3.cpp b/sample/extern/imgui/backends/imgui_impl_opengl3.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_opengl3.cpp rename to sample/extern/imgui/backends/imgui_impl_opengl3.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_opengl3.h b/sample/extern/imgui/backends/imgui_impl_opengl3.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_opengl3.h rename to sample/extern/imgui/backends/imgui_impl_opengl3.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_opengl3_loader.h b/sample/extern/imgui/backends/imgui_impl_opengl3_loader.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_opengl3_loader.h rename to sample/extern/imgui/backends/imgui_impl_opengl3_loader.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_osx.h b/sample/extern/imgui/backends/imgui_impl_osx.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_osx.h rename to sample/extern/imgui/backends/imgui_impl_osx.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_osx.mm b/sample/extern/imgui/backends/imgui_impl_osx.mm similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_osx.mm rename to sample/extern/imgui/backends/imgui_impl_osx.mm diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdl2.cpp b/sample/extern/imgui/backends/imgui_impl_sdl2.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdl2.cpp rename to sample/extern/imgui/backends/imgui_impl_sdl2.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdl2.h b/sample/extern/imgui/backends/imgui_impl_sdl2.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdl2.h rename to sample/extern/imgui/backends/imgui_impl_sdl2.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdl3.cpp b/sample/extern/imgui/backends/imgui_impl_sdl3.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdl3.cpp rename to sample/extern/imgui/backends/imgui_impl_sdl3.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdl3.h b/sample/extern/imgui/backends/imgui_impl_sdl3.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdl3.h rename to sample/extern/imgui/backends/imgui_impl_sdl3.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3.cpp b/sample/extern/imgui/backends/imgui_impl_sdlgpu3.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3.cpp rename to sample/extern/imgui/backends/imgui_impl_sdlgpu3.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3.h b/sample/extern/imgui/backends/imgui_impl_sdlgpu3.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3.h rename to sample/extern/imgui/backends/imgui_impl_sdlgpu3.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3_shaders.h b/sample/extern/imgui/backends/imgui_impl_sdlgpu3_shaders.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlgpu3_shaders.h rename to sample/extern/imgui/backends/imgui_impl_sdlgpu3_shaders.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer2.cpp b/sample/extern/imgui/backends/imgui_impl_sdlrenderer2.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer2.cpp rename to sample/extern/imgui/backends/imgui_impl_sdlrenderer2.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer2.h b/sample/extern/imgui/backends/imgui_impl_sdlrenderer2.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer2.h rename to sample/extern/imgui/backends/imgui_impl_sdlrenderer2.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer3.cpp b/sample/extern/imgui/backends/imgui_impl_sdlrenderer3.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer3.cpp rename to sample/extern/imgui/backends/imgui_impl_sdlrenderer3.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer3.h b/sample/extern/imgui/backends/imgui_impl_sdlrenderer3.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_sdlrenderer3.h rename to sample/extern/imgui/backends/imgui_impl_sdlrenderer3.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_vulkan.cpp b/sample/extern/imgui/backends/imgui_impl_vulkan.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_vulkan.cpp rename to sample/extern/imgui/backends/imgui_impl_vulkan.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_vulkan.h b/sample/extern/imgui/backends/imgui_impl_vulkan.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_vulkan.h rename to sample/extern/imgui/backends/imgui_impl_vulkan.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_wgpu.cpp b/sample/extern/imgui/backends/imgui_impl_wgpu.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_wgpu.cpp rename to sample/extern/imgui/backends/imgui_impl_wgpu.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_wgpu.h b/sample/extern/imgui/backends/imgui_impl_wgpu.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_wgpu.h rename to sample/extern/imgui/backends/imgui_impl_wgpu.h diff --git a/samples/testing/extern/imgui/backends/imgui_impl_win32.cpp b/sample/extern/imgui/backends/imgui_impl_win32.cpp similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_win32.cpp rename to sample/extern/imgui/backends/imgui_impl_win32.cpp diff --git a/samples/testing/extern/imgui/backends/imgui_impl_win32.h b/sample/extern/imgui/backends/imgui_impl_win32.h similarity index 100% rename from samples/testing/extern/imgui/backends/imgui_impl_win32.h rename to sample/extern/imgui/backends/imgui_impl_win32.h diff --git a/samples/testing/extern/imgui/backends/sdlgpu3/build_instructions.txt b/sample/extern/imgui/backends/sdlgpu3/build_instructions.txt similarity index 100% rename from samples/testing/extern/imgui/backends/sdlgpu3/build_instructions.txt rename to sample/extern/imgui/backends/sdlgpu3/build_instructions.txt diff --git a/samples/testing/extern/imgui/backends/sdlgpu3/shader.frag b/sample/extern/imgui/backends/sdlgpu3/shader.frag similarity index 100% rename from samples/testing/extern/imgui/backends/sdlgpu3/shader.frag rename to sample/extern/imgui/backends/sdlgpu3/shader.frag diff --git a/samples/testing/extern/imgui/backends/sdlgpu3/shader.vert b/sample/extern/imgui/backends/sdlgpu3/shader.vert similarity index 100% rename from samples/testing/extern/imgui/backends/sdlgpu3/shader.vert rename to sample/extern/imgui/backends/sdlgpu3/shader.vert diff --git a/samples/testing/extern/imgui/backends/vulkan/build_instructions.txt b/sample/extern/imgui/backends/vulkan/build_instructions.txt similarity index 100% rename from samples/testing/extern/imgui/backends/vulkan/build_instructions.txt rename to sample/extern/imgui/backends/vulkan/build_instructions.txt diff --git a/samples/testing/extern/imgui/backends/vulkan/generate_spv.sh b/sample/extern/imgui/backends/vulkan/generate_spv.sh similarity index 100% rename from samples/testing/extern/imgui/backends/vulkan/generate_spv.sh rename to sample/extern/imgui/backends/vulkan/generate_spv.sh diff --git a/samples/testing/extern/imgui/backends/vulkan/glsl_shader.frag b/sample/extern/imgui/backends/vulkan/glsl_shader.frag similarity index 100% rename from samples/testing/extern/imgui/backends/vulkan/glsl_shader.frag rename to sample/extern/imgui/backends/vulkan/glsl_shader.frag diff --git a/samples/testing/extern/imgui/backends/vulkan/glsl_shader.vert b/sample/extern/imgui/backends/vulkan/glsl_shader.vert similarity index 100% rename from samples/testing/extern/imgui/backends/vulkan/glsl_shader.vert rename to sample/extern/imgui/backends/vulkan/glsl_shader.vert diff --git a/samples/testing/extern/imgui/imconfig.h b/sample/extern/imgui/imconfig.h similarity index 100% rename from samples/testing/extern/imgui/imconfig.h rename to sample/extern/imgui/imconfig.h diff --git a/samples/testing/extern/imgui/imgui.cpp b/sample/extern/imgui/imgui.cpp similarity index 100% rename from samples/testing/extern/imgui/imgui.cpp rename to sample/extern/imgui/imgui.cpp diff --git a/samples/testing/extern/imgui/imgui.h b/sample/extern/imgui/imgui.h similarity index 100% rename from samples/testing/extern/imgui/imgui.h rename to sample/extern/imgui/imgui.h diff --git a/samples/testing/extern/imgui/imgui_demo.cpp b/sample/extern/imgui/imgui_demo.cpp similarity index 100% rename from samples/testing/extern/imgui/imgui_demo.cpp rename to sample/extern/imgui/imgui_demo.cpp diff --git a/samples/testing/extern/imgui/imgui_draw.cpp b/sample/extern/imgui/imgui_draw.cpp similarity index 100% rename from samples/testing/extern/imgui/imgui_draw.cpp rename to sample/extern/imgui/imgui_draw.cpp diff --git a/samples/testing/extern/imgui/imgui_internal.h b/sample/extern/imgui/imgui_internal.h similarity index 100% rename from samples/testing/extern/imgui/imgui_internal.h rename to sample/extern/imgui/imgui_internal.h diff --git a/samples/testing/extern/imgui/imgui_tables.cpp b/sample/extern/imgui/imgui_tables.cpp similarity index 100% rename from samples/testing/extern/imgui/imgui_tables.cpp rename to sample/extern/imgui/imgui_tables.cpp diff --git a/samples/testing/extern/imgui/imgui_widgets.cpp b/sample/extern/imgui/imgui_widgets.cpp similarity index 100% rename from samples/testing/extern/imgui/imgui_widgets.cpp rename to sample/extern/imgui/imgui_widgets.cpp diff --git a/samples/testing/extern/imgui/imstb_rectpack.h b/sample/extern/imgui/imstb_rectpack.h similarity index 100% rename from samples/testing/extern/imgui/imstb_rectpack.h rename to sample/extern/imgui/imstb_rectpack.h diff --git a/samples/testing/extern/imgui/imstb_textedit.h b/sample/extern/imgui/imstb_textedit.h similarity index 100% rename from samples/testing/extern/imgui/imstb_textedit.h rename to sample/extern/imgui/imstb_textedit.h diff --git a/samples/testing/extern/imgui/imstb_truetype.h b/sample/extern/imgui/imstb_truetype.h similarity index 100% rename from samples/testing/extern/imgui/imstb_truetype.h rename to sample/extern/imgui/imstb_truetype.h diff --git a/samples/testing/extern/imgui/misc/README.txt b/sample/extern/imgui/misc/README.txt similarity index 100% rename from samples/testing/extern/imgui/misc/README.txt rename to sample/extern/imgui/misc/README.txt diff --git a/samples/testing/extern/imgui/misc/cpp/README.txt b/sample/extern/imgui/misc/cpp/README.txt similarity index 100% rename from samples/testing/extern/imgui/misc/cpp/README.txt rename to sample/extern/imgui/misc/cpp/README.txt diff --git a/samples/testing/extern/imgui/misc/cpp/imgui_stdlib.cpp b/sample/extern/imgui/misc/cpp/imgui_stdlib.cpp similarity index 100% rename from samples/testing/extern/imgui/misc/cpp/imgui_stdlib.cpp rename to sample/extern/imgui/misc/cpp/imgui_stdlib.cpp diff --git a/samples/testing/extern/imgui/misc/cpp/imgui_stdlib.h b/sample/extern/imgui/misc/cpp/imgui_stdlib.h similarity index 100% rename from samples/testing/extern/imgui/misc/cpp/imgui_stdlib.h rename to sample/extern/imgui/misc/cpp/imgui_stdlib.h diff --git a/samples/testing/extern/imgui/misc/debuggers/README.txt b/sample/extern/imgui/misc/debuggers/README.txt similarity index 100% rename from samples/testing/extern/imgui/misc/debuggers/README.txt rename to sample/extern/imgui/misc/debuggers/README.txt diff --git a/samples/testing/extern/imgui/misc/debuggers/imgui.gdb b/sample/extern/imgui/misc/debuggers/imgui.gdb similarity index 100% rename from samples/testing/extern/imgui/misc/debuggers/imgui.gdb rename to sample/extern/imgui/misc/debuggers/imgui.gdb diff --git a/samples/testing/extern/imgui/misc/debuggers/imgui.natstepfilter b/sample/extern/imgui/misc/debuggers/imgui.natstepfilter similarity index 100% rename from samples/testing/extern/imgui/misc/debuggers/imgui.natstepfilter rename to sample/extern/imgui/misc/debuggers/imgui.natstepfilter diff --git a/samples/testing/extern/imgui/misc/debuggers/imgui.natvis b/sample/extern/imgui/misc/debuggers/imgui.natvis similarity index 100% rename from samples/testing/extern/imgui/misc/debuggers/imgui.natvis rename to sample/extern/imgui/misc/debuggers/imgui.natvis diff --git a/samples/testing/extern/imgui/misc/debuggers/imgui_lldb.py b/sample/extern/imgui/misc/debuggers/imgui_lldb.py similarity index 100% rename from samples/testing/extern/imgui/misc/debuggers/imgui_lldb.py rename to sample/extern/imgui/misc/debuggers/imgui_lldb.py diff --git a/samples/testing/extern/imgui/misc/fonts/Cousine-Regular.ttf b/sample/extern/imgui/misc/fonts/Cousine-Regular.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/Cousine-Regular.ttf rename to sample/extern/imgui/misc/fonts/Cousine-Regular.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/DroidSans.ttf b/sample/extern/imgui/misc/fonts/DroidSans.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/DroidSans.ttf rename to sample/extern/imgui/misc/fonts/DroidSans.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/Karla-Regular.ttf b/sample/extern/imgui/misc/fonts/Karla-Regular.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/Karla-Regular.ttf rename to sample/extern/imgui/misc/fonts/Karla-Regular.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/ProggyClean.ttf b/sample/extern/imgui/misc/fonts/ProggyClean.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/ProggyClean.ttf rename to sample/extern/imgui/misc/fonts/ProggyClean.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/ProggyTiny.ttf b/sample/extern/imgui/misc/fonts/ProggyTiny.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/ProggyTiny.ttf rename to sample/extern/imgui/misc/fonts/ProggyTiny.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/Roboto-Medium.ttf b/sample/extern/imgui/misc/fonts/Roboto-Medium.ttf similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/Roboto-Medium.ttf rename to sample/extern/imgui/misc/fonts/Roboto-Medium.ttf diff --git a/samples/testing/extern/imgui/misc/fonts/binary_to_compressed_c.cpp b/sample/extern/imgui/misc/fonts/binary_to_compressed_c.cpp similarity index 100% rename from samples/testing/extern/imgui/misc/fonts/binary_to_compressed_c.cpp rename to sample/extern/imgui/misc/fonts/binary_to_compressed_c.cpp diff --git a/samples/testing/extern/imgui/misc/freetype/README.md b/sample/extern/imgui/misc/freetype/README.md similarity index 100% rename from samples/testing/extern/imgui/misc/freetype/README.md rename to sample/extern/imgui/misc/freetype/README.md diff --git a/samples/testing/extern/imgui/misc/freetype/imgui_freetype.cpp b/sample/extern/imgui/misc/freetype/imgui_freetype.cpp similarity index 100% rename from samples/testing/extern/imgui/misc/freetype/imgui_freetype.cpp rename to sample/extern/imgui/misc/freetype/imgui_freetype.cpp diff --git a/samples/testing/extern/imgui/misc/freetype/imgui_freetype.h b/sample/extern/imgui/misc/freetype/imgui_freetype.h similarity index 100% rename from samples/testing/extern/imgui/misc/freetype/imgui_freetype.h rename to sample/extern/imgui/misc/freetype/imgui_freetype.h diff --git a/samples/testing/extern/imgui/misc/single_file/imgui_single_file.h b/sample/extern/imgui/misc/single_file/imgui_single_file.h similarity index 100% rename from samples/testing/extern/imgui/misc/single_file/imgui_single_file.h rename to sample/extern/imgui/misc/single_file/imgui_single_file.h diff --git a/samples/testing/extern/stb_image/stb_image.h b/sample/extern/stb_image/stb_image.h similarity index 100% rename from samples/testing/extern/stb_image/stb_image.h rename to sample/extern/stb_image/stb_image.h diff --git a/samples/testing/kernels/buffer-fill.slang b/sample/kernels/buffer-fill.slang similarity index 100% rename from samples/testing/kernels/buffer-fill.slang rename to sample/kernels/buffer-fill.slang diff --git a/samples/testing/kernels/common.slang b/sample/kernels/common.slang similarity index 100% rename from samples/testing/kernels/common.slang rename to sample/kernels/common.slang diff --git a/samples/testing/kernels/compile.cmd b/sample/kernels/compile.cmd similarity index 100% rename from samples/testing/kernels/compile.cmd rename to sample/kernels/compile.cmd diff --git a/samples/testing/kernels/graphics-test.slang b/sample/kernels/graphics-test.slang similarity index 100% rename from samples/testing/kernels/graphics-test.slang rename to sample/kernels/graphics-test.slang diff --git a/samples/testing/kernels/image.slang b/sample/kernels/image.slang similarity index 100% rename from samples/testing/kernels/image.slang rename to sample/kernels/image.slang diff --git a/samples/testing/kernels/test.slang b/sample/kernels/test.slang similarity index 100% rename from samples/testing/kernels/test.slang rename to sample/kernels/test.slang diff --git a/samples/testing/src/main.cc b/sample/src/main.cc similarity index 98% rename from samples/testing/src/main.cc rename to sample/src/main.cc index 7a02ac1..fbab74e 100644 --- a/samples/testing/src/main.cc +++ b/sample/src/main.cc @@ -63,7 +63,7 @@ int main() { /* Initialize the Render Graph */ RenderGraph rg = RenderGraph(); - rg.set_shader_path("samples/testing/kernels"); + rg.set_shader_path("sample/kernels"); rg.set_max_graphs_in_flight(2u); /* Double buffering */ if (const Result r = rg.init(gpu); r.is_err()) { printf("failed to initialize render graph.\nreason: %s\n", r.unwrap_err().c_str()); @@ -191,7 +191,7 @@ int main() { ImGui::CreateContext(); ImGui_ImplGlfw_InitForVulkan(win, true); ImGUI imgui = ImGUI(); - if (const Result r = imgui.init(gpu, rt, IMGUI_FUNCTIONS); r.is_err()) { + if (const Result r = imgui.init(gpu, rt); r.is_err()) { printf("failed to initialize imgui.\nreason: %s\n", r.unwrap_err().c_str()); return EXIT_SUCCESS; } diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt deleted file mode 100644 index e4f05bb..0000000 --- a/samples/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Function for adding a new sample -function(add_sample SAMPLE_NAME) - set(SAMPLE_DIR ./${SAMPLE_NAME}) - set(EXE_NAME sample-${SAMPLE_NAME}) - - # Executable target - project(${EXE_NAME}) - add_executable(${EXE_NAME} "${SAMPLE_DIR}/src/main.cc") - set_target_properties(${EXE_NAME} PROPERTIES OUTPUT_NAME ${EXE_NAME}) - - # Add compiler definitions - target_compile_definitions(${EXE_NAME} PRIVATE $<$:DEBUG=1>) - target_compile_definitions(${EXE_NAME} PRIVATE $<$:NDEBUG=1>) - - # Include directories - target_include_directories(${EXE_NAME} PRIVATE "${SAMPLE_DIR}/src/") - - # Link to the Graphite library - target_link_libraries(${EXE_NAME} PRIVATE graphite) - - add_subdirectory(${SAMPLE_NAME}) -endfunction() - -add_sample(testing) diff --git a/samples/testing/CMakeLists.txt b/samples/testing/CMakeLists.txt deleted file mode 100644 index c8e67df..0000000 --- a/samples/testing/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory("extern") \ No newline at end of file diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index 9bf79bd..d54329a 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -526,8 +526,8 @@ Result VRAMBank::resize_texture(Texture& texture, Size3D size) { /* Wait for the device to idle */ vkQueueWaitIdle(gpu->queues.queue_combined); - size.x = MAX(1, size.x); - size.y = MAX(1, size.y); + size.x = std::max(1u, size.x); + size.y = std::max(1u, size.y); if (size.x > 8192 || size.y > 8192) { return Err("texture size was larger 8192."); @@ -552,9 +552,9 @@ Result VRAMBank::resize_texture(Texture& texture, Size3D size) { VkImageCreateInfo texture_ci {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; texture_ci.imageType = size.is_2d() ? VK_IMAGE_TYPE_2D : VK_IMAGE_TYPE_3D; texture_ci.format = format; - texture_ci.extent = {MAX(size.x, 1u), MAX(size.y, 1u), MAX(size.z, 1u)}; - texture_ci.mipLevels = MAX(1u, data.meta.mips); - texture_ci.arrayLayers = MAX(1u, data.meta.arrays); + texture_ci.extent = {std::max(size.x, 1u), std::max(size.y, 1u), std::max(size.z, 1u)}; + texture_ci.mipLevels = std::max(1u, data.meta.mips); + texture_ci.arrayLayers = std::max(1u, data.meta.arrays); texture_ci.samples = VK_SAMPLE_COUNT_1_BIT; /* No MSAA */ texture_ci.tiling = VK_IMAGE_TILING_OPTIMAL; texture_ci.usage = translate::texture_usage(data.usage); From 89c780983ef47ab8c541e42222c6e6d18edafd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Wed, 17 Dec 2025 14:40:11 +0100 Subject: [PATCH 25/28] fix: render target present mode --- src/core/graphite/resources/texture.hh | 1 + src/platform/vulkan/vram_bank_vk.cc | 16 ++++++++-------- src/platform/vulkan/vram_bank_vk.hh | 1 + src/platform/vulkan/wrapper/translate_vk.cc | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/graphite/resources/texture.hh b/src/core/graphite/resources/texture.hh index 89f8e91..9a11f93 100644 --- a/src/core/graphite/resources/texture.hh +++ b/src/core/graphite/resources/texture.hh @@ -18,6 +18,7 @@ ENUM_CLASS_FLAGS(TextureUsage); enum class TextureFormat : u32 { Invalid = 0u, /* Invalid texture format. */ RGBA8Unorm, /* RGBA 8 bits per channel, unsigned normalized. */ + RG32Uint, /* RG 32 bits per channel, unsigned integer. */ EnumLimit /* Anything above or equal is invalid. */ }; diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index d54329a..fc2a4ae 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -18,12 +18,12 @@ Result VRAMBank::init(GPUAdapter& gpu) { vma_info.instance = gpu.instance; if (vmaImportVulkanFunctionsFromVolk(&vma_info, &vulkan_functions) != VK_SUCCESS) - return Err("Failed to import vulakn functions from volk (required for VMA init)."); + return Err("failed to import vulkan functions from volk (required for vma init)."); vma_info.pVulkanFunctions = &vulkan_functions; if (vmaCreateAllocator(&vma_info, &vma_allocator) != VK_SUCCESS) - return Err("Failed to initialise VMA."); + return Err("failed to initialise vma."); } /* Initialize the Stack Pools */ @@ -213,20 +213,20 @@ Result VRAMBank::create_render_target(const TargetDesc& target, bo vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->physical_device, resource.data.surface, &present_mode_count, present_modes); /* Find the presentation mode we want */ - VkPresentModeKHR present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; + resource.data.present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; for (u32 i = 0u; i < present_mode_count; ++i) { /* Mailbox is the preferred vsync present mode */ if (vsync == true && present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) { - present_mode = present_modes[i]; + resource.data.present_mode = present_modes[i]; break; } /* FIFO is the back-up vsync present mode */ if (vsync == true && present_modes[i] == VK_PRESENT_MODE_FIFO_KHR) { - present_mode = present_modes[i]; + resource.data.present_mode = present_modes[i]; } /* Immediate is the preferred non-vsync present mode */ if (vsync == false && present_modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR) { - present_mode = present_modes[i]; + resource.data.present_mode = present_modes[i]; break; } } @@ -244,7 +244,7 @@ Result VRAMBank::create_render_target(const TargetDesc& target, bo swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapchain_ci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; swapchain_ci.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - swapchain_ci.presentMode = present_mode; + swapchain_ci.presentMode = resource.data.present_mode; swapchain_ci.clipped = true; /* Create the swapchain */ @@ -483,7 +483,7 @@ Result VRAMBank::resize_render_target(RenderTarget &render_target, u32 wid swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapchain_ci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; swapchain_ci.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - swapchain_ci.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; /* TODO: Vsync parameter. */ + swapchain_ci.presentMode = data.present_mode; swapchain_ci.clipped = true; swapchain_ci.oldSwapchain = data.swapchain; diff --git a/src/platform/vulkan/vram_bank_vk.hh b/src/platform/vulkan/vram_bank_vk.hh index 2cea12d..4ea57df 100644 --- a/src/platform/vulkan/vram_bank_vk.hh +++ b/src/platform/vulkan/vram_bank_vk.hh @@ -109,6 +109,7 @@ struct RenderTargetSlot { u32 image_count = 0u; VkFormat format {}; VkColorSpaceKHR color_space {}; + VkPresentModeKHR present_mode {}; /* Swapchain resources */ VkSwapchainKHR swapchain {}; diff --git a/src/platform/vulkan/wrapper/translate_vk.cc b/src/platform/vulkan/wrapper/translate_vk.cc index 5581539..2f428bc 100644 --- a/src/platform/vulkan/wrapper/translate_vk.cc +++ b/src/platform/vulkan/wrapper/translate_vk.cc @@ -81,6 +81,8 @@ VkFormat texture_format(TextureFormat format) { switch (format) { case TextureFormat::RGBA8Unorm: return VK_FORMAT_R8G8B8A8_UNORM; + case TextureFormat::RG32Uint: + return VK_FORMAT_R32G32_UINT; default: return VK_FORMAT_UNDEFINED; } From 9fe0afe955e4de6216df4a258b994d0234721f68 Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Thu, 18 Dec 2025 13:43:15 +0000 Subject: [PATCH 26/28] feat: shader draw params extension --- src/platform/vulkan/wrapper/extensions_vk.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/vulkan/wrapper/extensions_vk.hh b/src/platform/vulkan/wrapper/extensions_vk.hh index 8a382ab..703e53d 100644 --- a/src/platform/vulkan/wrapper/extensions_vk.hh +++ b/src/platform/vulkan/wrapper/extensions_vk.hh @@ -18,6 +18,8 @@ const char* const device_ext[] = { VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME, /* Merging of copy commands */ VK_KHR_COPY_COMMANDS_2_EXTENSION_NAME, + /* Draw/Instance IDs in the shader (ex: SV_InstanceID) */ + VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, }; const u32 device_ext_count = sizeof(device_ext) / sizeof(char*); From 6130daae8c62b4c8e731c9ebcd6e231e2fcbfbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=CE=9BX?= Date: Thu, 25 Dec 2025 00:05:55 +0100 Subject: [PATCH 27/28] feat: ufloat texture format --- src/core/graphite/resources/texture.hh | 9 +++++---- src/platform/vulkan/wrapper/translate_vk.cc | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/graphite/resources/texture.hh b/src/core/graphite/resources/texture.hh index 9a11f93..a19a071 100644 --- a/src/core/graphite/resources/texture.hh +++ b/src/core/graphite/resources/texture.hh @@ -16,10 +16,11 @@ ENUM_CLASS_FLAGS(TextureUsage); /* Texture formats. */ enum class TextureFormat : u32 { - Invalid = 0u, /* Invalid texture format. */ - RGBA8Unorm, /* RGBA 8 bits per channel, unsigned normalized. */ - RG32Uint, /* RG 32 bits per channel, unsigned integer. */ - EnumLimit /* Anything above or equal is invalid. */ + Invalid = 0u, /* Invalid texture format. */ + RGBA8Unorm, /* RGBA 8 bits per channel, unsigned normalized. */ + RG32Uint, /* RG 32 bits per channel, unsigned integer. */ + RG11B10Ufloat, /* RG 11 bits per channel, B 10 bits per channel, unsigned float. */ + EnumLimit /* Anything above or equal is invalid. */ }; /* Texture meta data. */ diff --git a/src/platform/vulkan/wrapper/translate_vk.cc b/src/platform/vulkan/wrapper/translate_vk.cc index 2f428bc..14df2ad 100644 --- a/src/platform/vulkan/wrapper/translate_vk.cc +++ b/src/platform/vulkan/wrapper/translate_vk.cc @@ -83,6 +83,8 @@ VkFormat texture_format(TextureFormat format) { return VK_FORMAT_R8G8B8A8_UNORM; case TextureFormat::RG32Uint: return VK_FORMAT_R32G32_UINT; + case TextureFormat::RG11B10Ufloat: + return VK_FORMAT_B10G11R11_UFLOAT_PACK32; default: return VK_FORMAT_UNDEFINED; } From c62bec081598b85c5506ca747c772b4b1df24b8a Mon Sep 17 00:00:00 2001 From: Gikster007 Date: Thu, 25 Dec 2025 20:42:00 +0000 Subject: [PATCH 28/28] feat: indirect dispatch and draw --- src/core/graphite/nodes/compute_node.hh | 7 +++++++ src/core/graphite/nodes/raster_node.cc | 11 ++++++++++ src/core/graphite/nodes/raster_node.hh | 5 +++++ src/core/graphite/resources/buffer.hh | 13 ++++++------ src/platform/vulkan/render_graph_vk.cc | 23 +++++++++++++++++---- src/platform/vulkan/vram_bank_vk.cc | 10 ++++----- src/platform/vulkan/vram_bank_vk.hh | 2 +- src/platform/vulkan/wrapper/translate_vk.cc | 3 +-- 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/core/graphite/nodes/compute_node.hh b/src/core/graphite/nodes/compute_node.hh index 3e83d9e..5f27ce0 100644 --- a/src/core/graphite/nodes/compute_node.hh +++ b/src/core/graphite/nodes/compute_node.hh @@ -19,6 +19,10 @@ public: u32 group_x = 1u, group_y = 1u, group_z = 1u; /* Thread group size */ u32 work_x = 1u, work_y = 1u, work_z = 1u; /* Work size */ + + /* Indirect Dispatch. */ + Buffer indirect_buffer {}; + uint32_t indirect_offset = 0u; /* No copies allowed */ ComputeNode(const ComputeNode&) = delete; @@ -36,6 +40,9 @@ public: /* Set the work size for this node. (this will be divided by the `group_size` to get the dispatch size) */ inline ComputeNode& work_size(u32 x, u32 y = 1u, u32 z = 1u) { work_x = x; work_y = y; work_z = z; return *this; } + /* Set the indirect_buffer which will be used to get the dispatch args buffer for the vkCmdDispatchIndirect call. */ + inline ComputeNode& indirect_size(Buffer buffer) { indirect_buffer = buffer; return *this; } + /* To access constructors */ friend class AgnRenderGraph; }; diff --git a/src/core/graphite/nodes/raster_node.cc b/src/core/graphite/nodes/raster_node.cc index 834a1f6..b6c3a1f 100644 --- a/src/core/graphite/nodes/raster_node.cc +++ b/src/core/graphite/nodes/raster_node.cc @@ -35,6 +35,10 @@ DrawCall& RasterNode::draw( return draws.emplace_back(*this, vertex_buffer, vertex_count, vertex_offset, instance_count, instance_offset); } +DrawCall& RasterNode::draw_indirect(const Buffer vertex_buffer, const Buffer indirect_buffer) { + return draws.emplace_back(*this, vertex_buffer, indirect_buffer); +} + RasterNode& RasterNode::attribute(const AttrFormat format) { attributes.emplace_back(format); return *this; @@ -64,3 +68,10 @@ DrawCall::DrawCall( vertex_buffer, DependencyFlags::Readonly | DependencyFlags::Unbound, DependencyStages::Vertex ); } + +DrawCall::DrawCall(RasterNode& parent_pass, const Buffer vertex_buffer, const Buffer indirect_buffer) + : parent_pass(parent_pass), vertex_buffer(vertex_buffer), indirect_buffer(indirect_buffer) { + parent_pass.dependencies.emplace_back( + vertex_buffer, DependencyFlags::Readonly | DependencyFlags::Unbound, DependencyStages::Vertex + ); +} \ No newline at end of file diff --git a/src/core/graphite/nodes/raster_node.hh b/src/core/graphite/nodes/raster_node.hh index 3d34466..ef7256e 100644 --- a/src/core/graphite/nodes/raster_node.hh +++ b/src/core/graphite/nodes/raster_node.hh @@ -85,6 +85,8 @@ class RasterNode : public Node { const Buffer vertex_buffer, const u32 vertex_count, const u32 vertex_offset = 0u, const u32 instance_count = 1u, const u32 instance_offset = 0u ); + /* Create an indirect draw call for this raster pass. */ + DrawCall& draw_indirect(const Buffer vertex_buffer, const Buffer indirect_buffer); /* To access constructors */ friend class AgnRenderGraph; @@ -95,6 +97,7 @@ struct DrawCall { RasterNode& parent_pass; Buffer vertex_buffer {}; + Buffer indirect_buffer {}; u32 vertex_count = 0u, vertex_offset = 0u; u32 instance_count = 0u, instance_offset = 0u; @@ -103,4 +106,6 @@ struct DrawCall { RasterNode& parent_pass, const Buffer vertex_buffer, const u32 vertex_count, const u32 vertex_offset, const u32 instance_count, const u32 instance_offset ); + /* Vertex buffer and indirect draw call constructor. */ + DrawCall(RasterNode& parent_pass, const Buffer vertex_buffer, const Buffer indirect_buffer); }; \ No newline at end of file diff --git a/src/core/graphite/resources/buffer.hh b/src/core/graphite/resources/buffer.hh index 9c5b11f..380e7ac 100644 --- a/src/core/graphite/resources/buffer.hh +++ b/src/core/graphite/resources/buffer.hh @@ -5,11 +5,12 @@ /* Buffer usage flags. */ enum class BufferUsage : u32 { - Invalid = 0u, /* Invalid buffer usage. */ - TransferDst = 1u << 1u, /* This buffer can be a GPU transfer destination. */ - TransferSrc = 1u << 2u, /* This buffer can be a GPU transfer source. */ - Constant = 1u << 3u, /* Read-only buffer, aka. `UniformBuffer` */ - Storage = 1u << 4u, /* Read/Write buffer, aka. `StructuredBuffer` */ - Vertex = 1u << 5u, /* Vertex buffer */ + Invalid = 0u, /* Invalid buffer usage. */ + TransferDst = 1u << 1u, /* This buffer can be a GPU transfer destination. */ + TransferSrc = 1u << 2u, /* This buffer can be a GPU transfer source. */ + Constant = 1u << 3u, /* Read-only buffer, aka. `UniformBuffer` */ + Storage = 1u << 4u, /* Read/Write buffer, aka. `StructuredBuffer` */ + Vertex = 1u << 5u, /* Vertex buffer */ + Indirect = 1u << 6u, /* Draw/Dispatch Indirect Commands */ }; ENUM_CLASS_FLAGS(BufferUsage); diff --git a/src/platform/vulkan/render_graph_vk.cc b/src/platform/vulkan/render_graph_vk.cc index 72a01d6..720d3c2 100644 --- a/src/platform/vulkan/render_graph_vk.cc +++ b/src/platform/vulkan/render_graph_vk.cc @@ -286,6 +286,14 @@ Result RenderGraph::queue_compute_node(const GraphExecution& graph, const if (push_result.is_err()) return push_result; vkCmdBindDescriptorSets(graph.cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline.layout, 1u, 1u, &gpu->get_vram_bank().bindless_set, 0u, nullptr); + /* Indirect Dispatch */ + if (!node.indirect_buffer.is_null()) + { + VRAMBank& bank = gpu->get_vram_bank(); + vkCmdDispatchIndirect(graph.cmd, bank.buffers.get(node.indirect_buffer).buffer, node.indirect_offset); + return Ok(); + } + /* Calculate the dispatch size */ const u32 dispatch_x = div_up(node.work_x, node.group_x); const u32 dispatch_y = div_up(node.work_y, node.group_y); @@ -385,10 +393,17 @@ Result RenderGraph::queue_raster_node(const GraphExecution& graph, const R const VkDeviceSize offset = 0u; vkCmdBindVertexBuffers(graph.cmd, 0u, 1u, &vertex_buffer.buffer, &offset); - /* Execute the draw */ - vkCmdDraw( - graph.cmd, draw_call.vertex_count, draw_call.instance_count, draw_call.vertex_offset, draw_call.instance_offset - ); + /* Check for indirect draw */ + if (!draw_call.indirect_buffer.is_null()) { + vkCmdDrawIndirect( + graph.cmd, bank.buffers.get(draw_call.indirect_buffer).buffer, 0, 1, sizeof(VkDrawIndirectCommand) + ); + } else { + /* Execute direct draw */ + vkCmdDraw( + graph.cmd, draw_call.vertex_count, draw_call.instance_count, draw_call.vertex_offset, draw_call.instance_offset + ); + } } /* End rendering */ diff --git a/src/platform/vulkan/vram_bank_vk.cc b/src/platform/vulkan/vram_bank_vk.cc index fc2a4ae..4045acc 100644 --- a/src/platform/vulkan/vram_bank_vk.cc +++ b/src/platform/vulkan/vram_bank_vk.cc @@ -665,11 +665,11 @@ Result VRAMBank::upload_texture(Texture& texture, const void* data, const /* Staging buffer creation info */ VkBufferCreateInfo staging_buffer_ci { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; - staging_buffer_ci.size= size; - staging_buffer_ci.usage= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - staging_buffer_ci.sharingMode= VK_SHARING_MODE_EXCLUSIVE; - staging_buffer_ci.queueFamilyIndexCount= 1u; - staging_buffer_ci.pQueueFamilyIndices= &gpu->queue_families.queue_combined; + staging_buffer_ci.size = size; + staging_buffer_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + staging_buffer_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + staging_buffer_ci.queueFamilyIndexCount = 1u; + staging_buffer_ci.pQueueFamilyIndices = &gpu->queue_families.queue_combined; /* Staging memory allocation info */ VmaAllocationCreateInfo alloc_ci {}; diff --git a/src/platform/vulkan/vram_bank_vk.hh b/src/platform/vulkan/vram_bank_vk.hh index 4ea57df..8436708 100644 --- a/src/platform/vulkan/vram_bank_vk.hh +++ b/src/platform/vulkan/vram_bank_vk.hh @@ -64,7 +64,7 @@ public: PLATFORM_SPECIFIC Result create_render_target(const TargetDesc& target, bool vsync = true, u32 width = 1440u, u32 height = 810u); /** * @brief Create a new buffer resource. - * @param count If "stride" is 0 this represents the number of bytes in the buffer (for Constant buffers), + * @param count If "stride" is 0 this represents the number of bytes in the buffer, * otherwise it is the number of elements in the buffer. * @param stride The size in bytes of an element in the buffer, leave 0 for Constant buffers. */ diff --git a/src/platform/vulkan/wrapper/translate_vk.cc b/src/platform/vulkan/wrapper/translate_vk.cc index 2f428bc..558dad4 100644 --- a/src/platform/vulkan/wrapper/translate_vk.cc +++ b/src/platform/vulkan/wrapper/translate_vk.cc @@ -64,8 +64,7 @@ VkBufferUsageFlags buffer_usage(BufferUsage usage) { if (has_flag(usage, BufferUsage::Constant)) flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; if (has_flag(usage, BufferUsage::Storage)) flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; if (has_flag(usage, BufferUsage::Vertex)) flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - // if (has_flag(usage, BufferUsage::eIndex)) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - // if (has_flag(usage, BufferUsage::eIndirect)) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; + if (has_flag(usage, BufferUsage::Indirect)) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; return flags; }