Add RenderDoc support

This commit is contained in:
RaveYard 2022-10-26 11:52:10 +02:00
parent ee0740b0eb
commit bfbf97c2f6
2 changed files with 45 additions and 0 deletions

View file

@ -195,6 +195,7 @@ set( SOURCES
src/lightmap/glsl_frag.h src/lightmap/glsl_frag.h
src/lightmap/glsl_vert.h src/lightmap/glsl_vert.h
src/lightmap/glsl_frag_resolve.h src/lightmap/glsl_frag_resolve.h
src/lightmap/renderdoc_app.h
src/math/mat.cpp src/math/mat.cpp
src/math/plane.cpp src/math/plane.cpp
src/math/angle.cpp src/math/angle.cpp

View file

@ -8,6 +8,7 @@
#include "framework/halffloat.h" #include "framework/halffloat.h"
#include "vulkanbuilders.h" #include "vulkanbuilders.h"
#include "vulkancompatibledevice.h" #include "vulkancompatibledevice.h"
#include "renderdoc_app.h"
#include "stacktrace.h" #include "stacktrace.h"
#include <map> #include <map>
#include <vector> #include <vector>
@ -23,6 +24,42 @@
extern bool VKDebug; extern bool VKDebug;
extern bool NoRtx; 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) void VulkanPrintLog(const char* typestr, const std::string& msg)
{ {
printf("[%s] %s\n", typestr, msg.c_str()); printf("[%s] %s\n", typestr, msg.c_str());
@ -36,6 +73,9 @@ void VulkanError(const char* text)
GPURaytracer::GPURaytracer() GPURaytracer::GPURaytracer()
{ {
if(!rdoc_api)
LoadRenderDoc();
auto instance = std::make_shared<VulkanInstance>(VKDebug); auto instance = std::make_shared<VulkanInstance>(VKDebug);
device = std::make_unique<VulkanDevice>(instance, nullptr, VulkanCompatibleDevice::SelectDevice(instance, nullptr, 0)); device = std::make_unique<VulkanDevice>(instance, nullptr, VulkanCompatibleDevice::SelectDevice(instance, nullptr, 0));
useRayQuery = !NoRtx && device->PhysicalDevice.Features.RayQuery.rayQuery; useRayQuery = !NoRtx && device->PhysicalDevice.Features.RayQuery.rayQuery;
@ -48,6 +88,8 @@ GPURaytracer::~GPURaytracer()
void GPURaytracer::Raytrace(LevelMesh* level) void GPURaytracer::Raytrace(LevelMesh* level)
{ {
if (rdoc_api) rdoc_api->StartFrameCapture(nullptr, nullptr);
mesh = level; mesh = level;
printf("Building Vulkan acceleration structures\n"); printf("Building Vulkan acceleration structures\n");
@ -91,6 +133,8 @@ void GPURaytracer::Raytrace(LevelMesh* level)
} }
printf("Ray trace complete\n"); printf("Ray trace complete\n");
if (rdoc_api) rdoc_api->EndFrameCapture(nullptr, nullptr);
} }
void GPURaytracer::RenderAtlasImage(size_t pageIndex) void GPURaytracer::RenderAtlasImage(size_t pageIndex)