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

Vulkan on Android: Keep VkGraphicsSpy layer around after VkCreateInstance #1796

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions gapii/cc/vulkan_extras.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ static uint32_t EnumeratePhysicalDevicesAndCacheProperties(

bool m_coherent_memory_tracking_enabled = false;

#if TARGET_OS == GAPID_OS_ANDROID
bool m_should_unset_debug_vulkan_layers = true;
#endif // TARGET_OS == GAPID_OS_ANDROID

void SpyOverride_cacheImageSparseMemoryRequirements(
VkDevice device, VkImage image, uint32_t count,
VkSparseImageMemoryRequirements* pSparseMemoryRequirements);
Expand Down
43 changes: 1 addition & 42 deletions gapii/client/adb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ package client

import (
"context"
"fmt"
"net"
"time"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/app/crash"
"github.com/google/gapid/core/context/keys"
"github.com/google/gapid/core/event/task"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/os/android"
"github.com/google/gapid/core/os/android/adb"
Expand Down Expand Up @@ -117,49 +114,11 @@ func StartOrAttach(ctx context.Context, p *android.InstalledPackage, a *android.
// if we aren't debuggable regardless.
var m *flock.Mutex
if o.APIs&VulkanAPI != uint32(0) {
m, err := reserveVulkanDevice(ctx, d)
m, err = reserveVulkanDevice(ctx, d)
if err != nil {
d.RemoveForward(ctx, port)
return nil, log.Err(ctx, err, "Setting up for tracing Vulkan")
}
// Make a thread to listen to the signal for unsetting Vulkan implicit
// layers property.
// TODO: This mechanism will be dropped once the whole communication
// with GAPII being migrated to gRPC.
crash.Go(func() {
port, err := adb.LocalFreeTCPPort()
if err != nil {
log.Err(ctx, err, "Finding free port for listening to debug.vulkan.layers unset signal.")
return
}
if err = d.Forward(ctx, adb.TCPPort(port), adb.NamedAbstractSocket("unset-debug-vulkan-layers")); err != nil {
log.Err(ctx, err, "Setting up port forwarding for listening to debug.vulkan.layers unset signal.")
return
}
defer d.RemoveForward(ctx, port)
// Try to connect to the unset signal port, if the port is open
// and messages can be received, unset the Vulkan implicit layers
// property.
log.I(ctx, "Waiting for signal to unset %s on localhost:%d", vkImplicitLayersProp, port)
task.Retry(ctx, 0, time.Second, func(ctx context.Context) (bool, error) {
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
return false, err
}
conn.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
var n int
// No need to read the whole message
n, err = conn.Read(make([]byte, 1))
if err != nil || n == 0 {
return false, err
}
log.I(ctx, "VkGraphcsSpy loaded, unset %s now.", vkImplicitLayersProp)
if err = releaseVulkanDevice(ctx, d, m); err != nil {
log.Errf(ctx, err, "Unsetting %s", vkImplicitLayersProp)
}
return true, nil
})
})
}

app.AddCleanup(ctx, func() {
Expand Down
19 changes: 0 additions & 19 deletions gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
#include "gapii/cc/vulkan_imports.h"
#include "gapii/cc/vulkan_spy.h"
#if TARGET_OS == GAPID_OS_ANDROID
#include "gapii/cc/connection_stream.h"
#endif
#include "core/os/device/deviceinfo/cc/query.h"
extern "C" {«
Expand Down Expand Up @@ -314,21 +310,6 @@ uint32_t VulkanSpy::SpyOverride_vkCreateInstance(
{{end}}
{{end}}
}
// On Android once the loader finishes loadinging layers, unset the system
// property: debug.vulkan.layers, to minimize the potential possibility to
// affect other processes.
#if TARGET_OS == GAPID_OS_ANDROID
if (m_should_unset_debug_vulkan_layers) {
const char* unset_pipe = "unset-debug-vulkan-layers";
GAPID_INFO("Waiting for connection from host on %s", unset_pipe);
auto connForUnset = ConnectionStream::listenPipe(unset_pipe, true);
const char* msg = "Drop VkGraphicsSpy";
GAPID_INFO("Sending message: \"%s\" to host", msg);
connForUnset->write(msg, sizeof(msg));
connForUnset->close();
m_should_unset_debug_vulkan_layers = false;
}
#endif // TARGET_OS == GAPID_OS_ANDROID
return result;
}

Expand Down