Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Gfxr capture through dive cli #146

Merged
merged 10 commits into from
Dec 9, 2024
Merged
119 changes: 93 additions & 26 deletions capture_service/android_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,27 @@ absl::Status VulkanApplication::Setup()
RETURN_IF_ERROR(m_dev.Adb().Run("root"));
RETURN_IF_ERROR(m_dev.Adb().Run("wait-for-device"));
Stop().IgnoreError();

RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell run-as %s cp %s/%s .", m_package, kTargetPath, kVkLayerLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run("shell settings put global enable_gpu_debug_layers 1"));
RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("shell settings put global gpu_debug_app %s", m_package)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layer_app %s", m_package)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layers %s", kVkLayerName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell setprop wrap.%s LD_PRELOAD=%s/%s",
m_package,
kTargetPath,
kWrapLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell getprop wrap.%s", m_package)));
if (m_gfxr_enabled)
{
RETURN_IF_ERROR(GfxrSetup());
}
else
{
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell run-as %s cp %s/%s .", m_package, kTargetPath, kVkLayerLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run("shell settings put global enable_gpu_debug_layers 1"));
RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("shell settings put global gpu_debug_app %s", m_package)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layer_app %s", m_package)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layers %s", kVkLayerName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell setprop wrap.%s LD_PRELOAD=%s/%s",
m_package,
kTargetPath,
kWrapLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell getprop wrap.%s", m_package)));
}
LOGD("Setup Vulkan application %s done\n", m_package.c_str());
return absl::OkStatus();
}
Expand All @@ -222,22 +228,83 @@ absl::Status VulkanApplication::Cleanup()
return absl::OkStatus();
}

void AndroidApplication::SetGfxrEnabled(bool enable)
{
m_gfxr_enabled = enable;
}

absl::Status AndroidApplication::CreateGfxrDirectory(const std::string directory)
{

RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell mkdir -p %s", directory)));

return absl::OkStatus();
}

absl::Status AndroidApplication::GfxrSetup()
{
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("push %s %s",
ResolveAndroidLibPath(kVkGfxrLayerLibName, m_device_architecture)
.generic_string(),
kTargetPath)));

RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell run-as %s cp %s/%s .", m_package, kTargetPath, kVkGfxrLayerLibName)));

RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("shell run-as %s ls %s", m_package, kVkGfxrLayerLibName)));

RETURN_IF_ERROR(m_dev.Adb().Run("shell settings put global enable_gpu_debug_layers 1"));

RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("shell settings put global gpu_debug_app %s", m_package)));

RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layers %s", kVkGfxrLayerName)));

RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layer_app %s", m_package)));

std::string capture_file_location = kGfxrCaptureDirectory + m_gfxr_capture_file_directory +
"/" + m_package + ".gfxr";

std::string gfxr_capture_directory = kGfxrCaptureDirectory + m_gfxr_capture_file_directory;
RETURN_IF_ERROR(CreateGfxrDirectory(gfxr_capture_directory));

RETURN_IF_ERROR(
m_dev.Adb().Run("shell setprop debug.gfxrecon.capture_file " + capture_file_location));

std::string capture_frames_command = "shell setprop debug.gfxrecon.capture_frames " +
m_gfxr_capture_frames;
RETURN_IF_ERROR(m_dev.Adb().Run(capture_frames_command));
LOGD("GFXR capture setup for %s done\n", m_package.c_str());
return absl::OkStatus();
}

absl::Status OpenXRApplication::Setup()
{
LOGD("OpenXRApplication %s Setup\n", m_package.c_str());
RETURN_IF_ERROR(m_dev.Adb().Run("root"));
RETURN_IF_ERROR(m_dev.Adb().Run("wait-for-device"));
RETURN_IF_ERROR(m_dev.Adb().Run("remount"));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell mkdir -p %s", kManifestFilePath)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("push %s %s",
ResolveAndroidLibPath(kManifestFileName).generic_string().c_str(),
kManifestFilePath)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell setprop wrap.%s LD_PRELOAD=%s/%s",
m_package,
kTargetPath,
kWrapLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell getprop wrap.%s", m_package)));
if (m_gfxr_enabled)
{
RETURN_IF_ERROR(GfxrSetup());
}
else
{
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell mkdir -p %s", kManifestFilePath)));
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("push %s %s",
ResolveAndroidLibPath(kManifestFileName, "").generic_string().c_str(),
kManifestFilePath)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell setprop wrap.%s LD_PRELOAD=%s/%s",
m_package,
kTargetPath,
kWrapLibName)));
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell getprop wrap.%s", m_package)));
}
LOGD("OpenXRApplication %s Setup done.\n", m_package.c_str());
return absl::OkStatus();
}
Expand Down Expand Up @@ -283,7 +350,7 @@ absl::Status VulkanCliApplication::Setup()
RETURN_IF_ERROR(m_dev.Adb().Run(absl::StrFormat("shell mkdir -p %s", kVulkanGlobalPath)));
RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("push %s %s",
ResolveAndroidLibPath(kVkLayerLibName).generic_string(),
ResolveAndroidLibPath(kVkLayerLibName, "").generic_string(),
kVulkanGlobalPath)));
RETURN_IF_ERROR(
m_dev.Adb().Run(absl::StrFormat("shell setprop debug.vulkan.layers %s", kVkLayerName), false));
Expand Down
19 changes: 17 additions & 2 deletions capture_service/android_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class AndroidApplication
bool IsDebuggable() const { return m_is_debuggable; }
bool IsStarted() const { return m_started; }
virtual bool IsRunning() const;
void SetGfxrEnabled(bool enable);
void SetArchitecture(const std::string &architecture) { m_device_architecture = architecture; };
void SetFrames(const std::string &frames) { m_gfxr_capture_frames = frames; };
void SetGfxrCaptureFileDirectory(const std::string &capture_file_directory)
{
m_gfxr_capture_file_directory = capture_file_directory;
};
absl::Status CreateGfxrDirectory(const std::string command_args);
absl::Status GfxrSetup();

protected:
absl::Status ParsePackage();
Expand All @@ -61,8 +70,14 @@ class AndroidApplication
ApplicationType m_type;
std::string m_main_activity;
std::string m_command_args;
bool m_is_debuggable;
bool m_started;
// Available architectures are arm64-v8, armeabi-v7a, x86, and x86_64.
std::string m_device_architecture;
std::string m_gfxr_capture_file_directory;
std::string m_gfxr_capture_frames;
bool m_is_debuggable;
bool m_started;

bool m_gfxr_enabled;
};

class VulkanApplication : public AndroidApplication
Expand Down
4 changes: 4 additions & 0 deletions capture_service/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ namespace Dive
inline constexpr char kWrapLibName[] = "libwrap.so";
inline constexpr char kVkLayerLibName[] = "libVkLayer_dive.so";
inline constexpr char kXrLayerLibName[] = "libXrApiLayer_dive.so";
inline constexpr char kVkGfxrLayerLibName[] = "libVkLayer_gfxreconstruct.so";
inline constexpr char kVkGfxrLayerName[] = "VK_LAYER_LUNARG_gfxreconstruct";
inline constexpr char kVkLayerName[] = "VK_LAYER_Dive";
inline constexpr char kXrLayerName[] = "XR_APILAYER_dive";
inline constexpr char kTargetPath[] = "/data/local/tmp";
inline constexpr char kGfxrTargetPath[] = "/data/data/";
inline constexpr char kGfxrCaptureDirectory[] = "/sdcard/Download/";
inline constexpr char kManifestFileName[] = "XrApiLayer_dive.json";
inline constexpr char kManifestFilePath[] = "/system/etc/openxr/1/api_layers/implicit.d/";
inline constexpr char kVulkanGlobalPath[] = "/data/local/debug/vulkan";
Expand Down
Loading