diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bfc20a..f3a2da2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,7 @@ set( SOURCES src/lightmap/glsl_frag.h src/lightmap/glsl_vert.h src/lightmap/glsl_frag_resolve.h + src/lightmap/renderdoc_app.h src/math/mat.cpp src/math/plane.cpp src/math/angle.cpp diff --git a/src/lightmap/gpuraytracer.cpp b/src/lightmap/gpuraytracer.cpp index d3f6f40..ba1553f 100644 --- a/src/lightmap/gpuraytracer.cpp +++ b/src/lightmap/gpuraytracer.cpp @@ -8,6 +8,7 @@ #include "framework/halffloat.h" #include "vulkanbuilders.h" #include "vulkancompatibledevice.h" +#include "renderdoc_app.h" #include "stacktrace.h" #include #include @@ -23,6 +24,42 @@ extern bool VKDebug; extern bool NoRtx; +RENDERDOC_API_1_4_2* rdoc_api; + +void LoadRenderDoc() +{ +#ifdef _WIN32 + if (auto mod = GetModuleHandle("renderdoc.dll")) + { + pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); + int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_4_2, (void**)&rdoc_api); + assert(ret == 1); + + if (ret != 1) + { + printf("RENDERDOC_GetAPI returned %d\n", ret); + } + } +#else + if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) + { + pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); + int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_4_2, (void**)&rdoc_api); + assert(ret == 1); + + if (ret != 1) + { + printf("RENDERDOC_GetAPI returned %d\n", ret); + } + } +#endif + + if (rdoc_api) + { + printf("RenderDoc enabled\n"); + } +} + void VulkanPrintLog(const char* typestr, const std::string& msg) { printf("[%s] %s\n", typestr, msg.c_str()); @@ -36,6 +73,9 @@ void VulkanError(const char* text) GPURaytracer::GPURaytracer() { + if(!rdoc_api) + LoadRenderDoc(); + auto instance = std::make_shared(VKDebug); device = std::make_unique(instance, nullptr, VulkanCompatibleDevice::SelectDevice(instance, nullptr, 0)); useRayQuery = !NoRtx && device->PhysicalDevice.Features.RayQuery.rayQuery; @@ -48,6 +88,8 @@ GPURaytracer::~GPURaytracer() void GPURaytracer::Raytrace(LevelMesh* level) { + if (rdoc_api) rdoc_api->StartFrameCapture(nullptr, nullptr); + mesh = level; printf("Building Vulkan acceleration structures\n"); @@ -91,6 +133,8 @@ void GPURaytracer::Raytrace(LevelMesh* level) } printf("Ray trace complete\n"); + + if (rdoc_api) rdoc_api->EndFrameCapture(nullptr, nullptr); } void GPURaytracer::RenderAtlasImage(size_t pageIndex)