Skip to content

Commit

Permalink
Use surface types created in trace as hint
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-purcell committed Aug 3, 2018
1 parent fc2480e commit b6a56e6
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 28 deletions.
22 changes: 17 additions & 5 deletions gapir/cc/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,27 @@ void* createWin32Window(uint32_t width, uint32_t height) {
}
#endif

void* CreateSurface(uint32_t width, uint32_t height) {
const void* CreateSurface(uint32_t width, uint32_t height, SurfaceType& type) {
switch (type) {
#if TARGET_OS == GAPID_OS_ANDROID
return (void*)android_window;
case SurfaceType::Android:
case SurfaceType::Unknown:
type = SurfaceType::Android;
return (void*)android_window;
#elif TARGET_OS == GAPID_OS_LINUX
return createXcbWindow(width, height);
case SurfaceType::Xcb:
case SurfaceType::Unknown:
type = SurfaceType::Xcb;
return createXcbWindow(width, height);
#elif TARGET_OS == GAPID_OS_WINDOWS
return createWin32Window(width, height);
case SurfaceType::Win32:
case SurfaceType::Unknown:
type = SurfaceType::Win32;
return createWin32Window(width, height);
#endif
return nullptr;
default:
return nullptr;
}
}

void WaitForWindowClose() {
Expand Down
9 changes: 8 additions & 1 deletion gapir/cc/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ struct Win32WindowInfo {
};
#endif

enum SurfaceType {
Unknown,
Android,
Win32,
Xcb,
};

// Get the platform-specific data pointer to create the surface
void* CreateSurface(uint32_t width, uint32_t height);
const void* CreateSurface(uint32_t width, uint32_t height, SurfaceType& type);

void WaitForWindowClose();

Expand Down
60 changes: 45 additions & 15 deletions gapis/api/templates/vulkan_gfx_api_extras.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -356,27 +356,57 @@ bool Vulkan::replayCreateVkDeviceImpl(Stack* stack, size_val physicalDevice,
// Copy any extra fields
vsPNext = *pNext;

void* data = CreateSurface(newCreateInfo.imageExtent.Width,
newCreateInfo.imageExtent.Height);
gapir::SurfaceType target = gapir::SurfaceType::Unknown;
switch (*(uint32_t*)pNext->surfaceCreateInfo) {
case VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR:
target = gapir::SurfaceType::Android;
break;
// These are all linux, so just make an Xcb surface
case VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR:
case VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR:
case VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR:
case VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR:
target = gapir::SurfaceType::Xcb;
break;
case VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR:
target = gapir::SurfaceType::Win32;
}

const void* data = CreateSurface(newCreateInfo.imageExtent.Width,
newCreateInfo.imageExtent.Height, target);
void* createInfo = nullptr;
if (data != nullptr) {
switch (target) {
#if TARGET_OS == GAPID_OS_ANDROID
createInfo = &surfaceInfo;
surfaceInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
surfaceInfo.window = (ANativeWindow*)data;
case gapir::SurfaceType::Android:
createInfo = &surfaceInfo;
surfaceInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
surfaceInfo.window = (ANativeWindow*)data;
break;
#elif TARGET_OS == GAPID_OS_LINUX
createInfo = &surfaceInfo;
auto info = (XcbWindowInfo*)data;
surfaceInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
surfaceInfo.connection = info->connection;
surfaceInfo.window = info->window;
case gapir::SurfaceType::Xcb:
createInfo = &surfaceInfo;
{
auto info = (XcbWindowInfo*)data;
surfaceInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
surfaceInfo.connection = info->connection;
surfaceInfo.window = info->window;
}
break;
#elif TARGET_OS == GAPID_OS_WINDOWS
createInfo = &surfaceInfo;
auto info = (Win32WindowInfo*)data;
surfaceInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surfaceInfo.hinstance = (HINSTANCE)info->instance;
surfaceInfo.hwnd = (HWND)info->window;
case gapir::SurfaceType::Win32:
createInfo = &surfaceInfo;
{
auto info = (Win32WindowInfo*)data;
surfaceInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surfaceInfo.hinstance = (HINSTANCE)info->instance;
surfaceInfo.hwnd = (HWND)info->window;
}
break;
#endif
default:
break;
}
}
vsPNext.surfaceCreateInfo = createInfo;
vsPNext.pNext = newCreateInfo.pNext;
Expand Down
8 changes: 6 additions & 2 deletions gapis/api/vulkan/custom_replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,13 @@ func (a *VkCreateSwapchainKHR) Mutate(ctx context.Context, id api.CmdID, s *api.
0, // surfaceCreateInfo
)
for _, extra := range a.Extras().All() {
if _, ok := extra.(*DisplayToSurface); ok {
if d, ok := extra.(*DisplayToSurface); ok {
log.D(ctx, "Activating display to surface")
pNext.SetSurfaceCreateInfo(1)
sType, _ := d.SurfaceTypes[uint64(info.Surface())]
sTypeData := s.AllocDataOrPanic(ctx, sType)
defer sTypeData.Free()
pNext.SetSurfaceCreateInfo(NewVoidᶜᵖ(sTypeData.Ptr()))
hijack.AddRead(sTypeData.Data())
}
}
pNextData := s.AllocDataOrPanic(ctx, pNext)
Expand Down
39 changes: 35 additions & 4 deletions gapis/api/vulkan/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,19 +441,50 @@ func (t *destroyResourcesAtEOS) Flush(ctx context.Context, out transform.Writer)
}
}

func newDisplayToSurface() *DisplayToSurface {
return &DisplayToSurface{
SurfaceTypes: map[uint64]uint32{},
}
}

// DisplayToSurface is a transformation that enables rendering during replay to
// the original surface.
func (t *DisplayToSurface) Transform(ctx context.Context, id api.CmdID, cmd api.Cmd, out transform.Writer) {
if c, ok := cmd.(*VkCreateSwapchainKHR); ok {
switch c := cmd.(type) {
case *VkCreateSwapchainKHR:
newCmd := c.Clone(out.State().Arena)
newCmd.extras = api.CmdExtras{}
// Add an extra to indicate to custom_replay to add a flag to
// the virtual swapchain pNext
newCmd.extras = append(api.CmdExtras{t}, cmd.Extras().All()...)
out.MutateAndWrite(ctx, id, newCmd)
} else {
out.MutateAndWrite(ctx, id, cmd)
return
case *VkCreateAndroidSurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR)
case *VkCreateMirSurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR)
case *VkCreateWaylandSurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR)
case *VkCreateWin32SurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR)
case *VkCreateXcbSurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR)
case *VkCreateXlibSurfaceKHR:
cmd.Extras().Observations().ApplyWrites(out.State().Memory.ApplicationPool())
surface := c.PSurface().MustRead(ctx, cmd, out.State(), nil)
t.SurfaceTypes[uint64(surface)] = uint32(VkStructureType_VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR)
}
out.MutateAndWrite(ctx, id, cmd)
}

func (t *DisplayToSurface) Flush(ctx context.Context, out transform.Writer) {
Expand Down Expand Up @@ -630,7 +661,7 @@ func (a API) Replay(
}

if doDisplayToSurface {
transforms.Add(&DisplayToSurface{})
transforms.Add(newDisplayToSurface())
}

if issues != nil {
Expand Down
1 change: 1 addition & 0 deletions gapis/api/vulkan/replay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ option go_package = "github.com/google/gapid/gapis/api/vulkan";
// DisplayToSurface is an extra added to VkCreateSwapchainKHR to indicate the
// replay should display to the original surface.
message DisplayToSurface {
map<uint64, uint32> surface_types = 1;
}
4 changes: 3 additions & 1 deletion gapis/api/vulkan/synthetic.api
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ cmd VkResult ReplayCreateSwapchain(
switch sType {
case VK_STRUCTURE_TYPE_VIRTUAL_SWAPCHAIN_PNEXT: {
ext := as!VirtualSwapchainPNext*(next.Ptr)[0:1][0]
_ = ext.surfaceCreateInfo
if ext.surfaceCreateInfo != null {
_ = as!VkStructureType*(ext.surfaceCreateInfo)[0:1][0]
}
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0:1][0].PNext
Expand Down

0 comments on commit b6a56e6

Please sign in to comment.