Commit 45881ab3 by Ian Elliott Committed by Commit Bot

Enable debug-util markers with an env var/property

Enable the Vulkan debug-util markers by setting the ANGLE_ENABLE_DEBUG_MARKERS" environment variable to any 1+-character value. On Android, this is set with the "debug.angle.markers" Android property. Bug: b/170249632 Change-Id: I66503fac71397c59cc641dd903faad152e0ec449 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2500186Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Ian Elliott <ianelliott@google.com>
parent 94900b69
...@@ -26,6 +26,42 @@ std::string GetExecutableName() ...@@ -26,6 +26,42 @@ std::string GetExecutableName()
#endif // ANGLE_PLATFORM_ANDROID #endif // ANGLE_PLATFORM_ANDROID
} }
// Call out to 'getprop' on a shell to get an Android property. If the value was set, set an
// environment variable with that value. Return the value of the environment variable.
std::string GetEnvironmentVarFromAndroidProperty(const char *variableName, const char *propertyName)
{
#if defined(ANGLE_PLATFORM_ANDROID) && __ANDROID_API__ >= 21
std::string sanitizedPropertyName = propertyName;
sanitizedPropertyName.erase(
std::remove(sanitizedPropertyName.begin(), sanitizedPropertyName.end(), '\''),
sanitizedPropertyName.end());
std::string command("getprop '");
command += sanitizedPropertyName;
command += "'";
// Run the command and open a I/O stream to read the value
constexpr int kStreamSize = 64;
char stream[kStreamSize] = {};
FILE *pipe = popen(command.c_str(), "r");
if (pipe != nullptr)
{
fgets(stream, kStreamSize, pipe);
pclose(pipe);
}
// Right strip white space
std::string value(stream);
value.erase(value.find_last_not_of(" \n\r\t") + 1);
// Set the environment variable with the value.
SetEnvironmentVar(variableName, value.c_str());
return value;
#endif // ANGLE_PLATFORM_ANDROID
// Return the environment variable's value.
return GetEnvironmentVar(variableName);
}
bool PrependPathToEnvironmentVar(const char *variableName, const char *path) bool PrependPathToEnvironmentVar(const char *variableName, const char *path)
{ {
std::string oldValue = GetEnvironmentVar(variableName); std::string oldValue = GetEnvironmentVar(variableName);
......
...@@ -28,6 +28,8 @@ bool SetCWD(const char *dirName); ...@@ -28,6 +28,8 @@ bool SetCWD(const char *dirName);
bool SetEnvironmentVar(const char *variableName, const char *value); bool SetEnvironmentVar(const char *variableName, const char *value);
bool UnsetEnvironmentVar(const char *variableName); bool UnsetEnvironmentVar(const char *variableName);
std::string GetEnvironmentVar(const char *variableName); std::string GetEnvironmentVar(const char *variableName);
std::string GetEnvironmentVarFromAndroidProperty(const char *variableName,
const char *propertyName);
const char *GetPathSeparatorForEnvironmentVar(); const char *GetPathSeparatorForEnvironmentVar();
bool PrependPathToEnvironmentVar(const char *variableName, const char *path); bool PrependPathToEnvironmentVar(const char *variableName, const char *path);
bool IsDirectory(const char *filename); bool IsDirectory(const char *filename);
......
...@@ -442,6 +442,9 @@ ANGLE_MAYBE_UNUSED bool SemaphorePropertiesCompatibleWithAndroid( ...@@ -442,6 +442,9 @@ ANGLE_MAYBE_UNUSED bool SemaphorePropertiesCompatibleWithAndroid(
return true; return true;
} }
// Environment variable (and associated Android property) to enable Vulkan debug-utils markers
constexpr char kEnableDebugMarkersVarName[] = "ANGLE_ENABLE_DEBUG_MARKERS";
constexpr char kEnableDebugMarkersPropertyName[] = "debug.angle.markers";
} // namespace } // namespace
// RendererVk implementation. // RendererVk implementation.
...@@ -2462,12 +2465,29 @@ void RendererVk::onCompletedSerial(Serial serial) ...@@ -2462,12 +2465,29 @@ void RendererVk::onCompletedSerial(Serial serial)
void RendererVk::setGlobalDebugAnnotator() void RendererVk::setGlobalDebugAnnotator()
{ {
// If the vkCmd*DebugUtilsLabelEXT functions exist, initialize DebugAnnotatorVk to log the // If the vkCmd*DebugUtilsLabelEXT functions exist, and if the kEnableDebugMarkersVarName
// OpenGL ES commands that are used, for debuggers (e.g. AGI). // environment variable is set, initialize DebugAnnotatorVk to log the OpenGL ES commands that
// are used, for debuggers (e.g. AGI). Otherwise, uninitialize the global DebugAnnotator
// pointer so that applications run full speed.
bool enableDebugAnnotatorVk = false;
if (vkCmdBeginDebugUtilsLabelEXT) if (vkCmdBeginDebugUtilsLabelEXT)
{ {
std::string enabled = angle::GetEnvironmentVarFromAndroidProperty(
kEnableDebugMarkersVarName, kEnableDebugMarkersPropertyName);
if (!enabled.empty() && enabled.compare("0") != 0)
{
enableDebugAnnotatorVk = true;
}
}
if (enableDebugAnnotatorVk)
{
gl::InitializeDebugAnnotations(&mAnnotator); gl::InitializeDebugAnnotations(&mAnnotator);
} }
else
{
gl::UninitializeDebugAnnotations();
}
} }
void RendererVk::reloadVolkIfNeeded() const void RendererVk::reloadVolkIfNeeded() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment