diff --git a/framegen/public/lsfg_3_1.hpp b/framegen/public/lsfg_3_1.hpp index 71871d0..6620008 100644 --- a/framegen/public/lsfg_3_1.hpp +++ b/framegen/public/lsfg_3_1.hpp @@ -25,6 +25,14 @@ namespace LSFG_3_1 { bool isHdr, float flowScale, uint64_t generationCount, const std::function(const std::string&)>& loader); + /// + /// Initialize the renderdoc API. + /// + /// @throws LSFG::vulkan_error if the renderdoc API cannot be initialized. + /// + [[gnu::visibility("default")]] + void initializeRenderDoc(); + /// /// Create a new LSFG context on a swapchain. /// diff --git a/framegen/public/lsfg_3_1p.hpp b/framegen/public/lsfg_3_1p.hpp index 8c1af41..14df35c 100644 --- a/framegen/public/lsfg_3_1p.hpp +++ b/framegen/public/lsfg_3_1p.hpp @@ -25,6 +25,14 @@ namespace LSFG_3_1P { bool isHdr, float flowScale, uint64_t generationCount, const std::function(const std::string&)>& loader); + /// + /// Initialize the renderdoc API. + /// + /// @throws LSFG::vulkan_error if the renderdoc API cannot be initialized. + /// + [[gnu::visibility("default")]] + void initializeRenderDoc(); + /// /// Create a new LSFG context on a swapchain. /// diff --git a/framegen/v3.1_src/lsfg.cpp b/framegen/v3.1_src/lsfg.cpp index a894f12..1f4c2dc 100644 --- a/framegen/v3.1_src/lsfg.cpp +++ b/framegen/v3.1_src/lsfg.cpp @@ -10,6 +10,9 @@ #include "common/exception.hpp" #include "common/utils.hpp" +#include +#include + #include #include #include @@ -26,6 +29,8 @@ namespace { std::optional instance; std::optional device; std::unordered_map contexts; + + std::optional renderdoc; } void LSFG_3_1::initialize(uint64_t deviceUUID, @@ -52,6 +57,23 @@ void LSFG_3_1::initialize(uint64_t deviceUUID, std::srand(static_cast(std::time(nullptr))); } +void LSFG_3_1::initializeRenderDoc() { + if (renderdoc.has_value()) + return; + + if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) { + auto rdocGetAPI = reinterpret_cast(dlsym(mod, "RENDERDOC_GetAPI")); + RENDERDOC_API_1_6_0* rdoc{}; + rdocGetAPI(eRENDERDOC_API_Version_1_6_0, reinterpret_cast(&rdoc)); + + renderdoc.emplace(rdoc); + } + + if (!renderdoc.has_value()) { + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "RenderDoc API not found"); + } +} + int32_t LSFG_3_1::createContext( int in0, int in1, const std::vector& outN, VkExtent2D extent, VkFormat format) { @@ -71,7 +93,15 @@ void LSFG_3_1::presentContext(int32_t id, int inSem, const std::vector& out if (it == contexts.end()) throw LSFG::vulkan_error(VK_ERROR_UNKNOWN, "Context not found"); + if (renderdoc.has_value()) + (*renderdoc)->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance->handle()), nullptr); + it->second.present(*device, inSem, outSem); + + if (renderdoc.has_value()) { + vkDeviceWaitIdle(device->device.handle()); + (*renderdoc)->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance->handle()), nullptr); + } } void LSFG_3_1::deleteContext(int32_t id) { diff --git a/framegen/v3.1p_src/lsfg.cpp b/framegen/v3.1p_src/lsfg.cpp index a22609d..1bca0ce 100644 --- a/framegen/v3.1p_src/lsfg.cpp +++ b/framegen/v3.1p_src/lsfg.cpp @@ -10,6 +10,9 @@ #include "common/exception.hpp" #include "common/utils.hpp" +#include +#include + #include #include #include @@ -26,6 +29,8 @@ namespace { std::optional instance; std::optional device; std::unordered_map contexts; + + std::optional renderdoc; } void LSFG_3_1P::initialize(uint64_t deviceUUID, @@ -52,6 +57,23 @@ void LSFG_3_1P::initialize(uint64_t deviceUUID, std::srand(static_cast(std::time(nullptr))); } +void LSFG_3_1P::initializeRenderDoc() { + if (renderdoc.has_value()) + return; + + if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) { + auto rdocGetAPI = reinterpret_cast(dlsym(mod, "RENDERDOC_GetAPI")); + RENDERDOC_API_1_6_0* rdoc{}; + rdocGetAPI(eRENDERDOC_API_Version_1_6_0, reinterpret_cast(&rdoc)); + + renderdoc.emplace(rdoc); + } + + if (!renderdoc.has_value()) { + throw LSFG::vulkan_error(VK_ERROR_INITIALIZATION_FAILED, "RenderDoc API not found"); + } +} + int32_t LSFG_3_1P::createContext( int in0, int in1, const std::vector& outN, VkExtent2D extent, VkFormat format) { @@ -71,7 +93,15 @@ void LSFG_3_1P::presentContext(int32_t id, int inSem, const std::vector& ou if (it == contexts.end()) throw LSFG::vulkan_error(VK_ERROR_UNKNOWN, "Context not found"); + if (renderdoc.has_value()) + (*renderdoc)->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance->handle()), nullptr); + it->second.present(*device, inSem, outSem); + + if (renderdoc.has_value()) { + vkDeviceWaitIdle(device->device.handle()); + (*renderdoc)->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance->handle()), nullptr); + } } void LSFG_3_1P::deleteContext(int32_t id) { diff --git a/test/src/main.cpp b/test/src/main.cpp index 36018a2..e5de8fc 100644 --- a/test/src/main.cpp +++ b/test/src/main.cpp @@ -7,10 +7,8 @@ #include "extract/trans.hpp" #include -#include -#include -#include +#include #include #include #include @@ -24,16 +22,16 @@ using namespace LSFG; const VkExtent2D SRC_EXTENT = { 2560 , 1440 }; const VkFormat SRC_FORMAT = VK_FORMAT_R8G8B8A8_UNORM; -const std::array SRC_FILES = { +const std::array SRC_FILES = { "test/f0.dds", - "test/f1.dds" + "test/f1.dds", + "test/f2.dds" }; -const size_t MULTIPLIER = 4; +const size_t MULTIPLIER = 3; const bool IS_HDR = false; -const float FLOW_SCALE = 1.0F; -#define PERFORMANCE_MODE true - +const float FLOW_SCALE = 0.7F; +#define PERFORMANCE_MODE false // test configuration end @@ -46,16 +44,6 @@ using namespace LSFG_3_1; #endif namespace { - RENDERDOC_API_1_6_0* rdoc{}; - - /// Attempt to load the RenderDoc API. - void setup_renderdoc() { - if(void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) { - auto rdocGetAPI = reinterpret_cast(dlsym(mod, "RENDERDOC_GetAPI")); - rdocGetAPI(eRENDERDOC_API_Version_1_1_2, reinterpret_cast(&rdoc)); - } - } - /// Create images for frame generation std::pair create_images(const Core::Device& device, std::array& fds, @@ -86,13 +74,14 @@ namespace { Extract::extractShaders(); initialize( 0x1463ABAC, - IS_HDR, FLOW_SCALE, MULTIPLIER - 3, + IS_HDR, 1.0F / FLOW_SCALE, MULTIPLIER - 1, [](const std::string& name) -> std::vector { auto dxbc = Extract::getShader(name); auto spirv = Extract::translateShader(dxbc); return spirv; } ); + initializeRenderDoc(); return createContext( fds.at(0), fds.at(1), outFds, SRC_EXTENT, SRC_FORMAT @@ -121,7 +110,6 @@ int main() { const Core::CommandPool commandPool{device}; // setup test - setup_renderdoc(); frames = create_images(device, fds, outFds, out_n); lsfg_id = create_lsfg(fds, outFds); @@ -135,16 +123,8 @@ int main() { else Utils::uploadImage(device, commandPool, frames.second, SRC_FILES.at(fc)); - if (rdoc) rdoc->StartFrameCapture(nullptr, nullptr); - // run the present - const std::vector null_sems(MULTIPLIER - 1, -1); - presentContext(lsfg_id, -1, null_sems); - - // wait until the present is done - usleep(1000 * 100); - - if (rdoc) rdoc->EndFrameCapture(nullptr, nullptr); + presentContext(lsfg_id, -1, {}); } // destroy test