Skip to content

Commit

Permalink
Vulkan: Fix crash at VkDestroyDebugReportCallbackEXT (#1998)
Browse files Browse the repository at this point in the history
If the application uses debug report callback, we should not use our
synthetic commands to process their callback handles.
  • Loading branch information
Qining committed Jun 20, 2018
1 parent ea00362 commit e5b2d6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 10 additions & 2 deletions gapis/api/vulkan/find_issues.go
Expand Up @@ -72,8 +72,9 @@ type findIssues struct {

func newFindIssues(ctx context.Context, c *capture.Capture, numInitialCmds int) *findIssues {
t := &findIssues{
state: c.NewState(ctx),
numInitialCmds: numInitialCmds,
state: c.NewState(ctx),
numInitialCmds: numInitialCmds,
reportCallbacks: map[VkInstance]VkDebugReportCallbackEXT{},
}
t.state.OnError = func(err interface{}) {
if issue, ok := err.(replay.Issue); ok {
Expand Down Expand Up @@ -116,6 +117,7 @@ func (t *findIssues) Transform(ctx context.Context, id api.CmdID, cmd api.Cmd, o
inst := di.Instance()
if ch, ok := t.reportCallbacks[inst]; ok {
out.MutateAndWrite(ctx, api.CmdNoID, cb.ReplayDestroyVkDebugReportCallback(inst, ch))
delete(t.reportCallbacks, inst)
}
}

Expand Down Expand Up @@ -262,11 +264,17 @@ func (t *findIssues) Transform(ctx context.Context, id api.CmdID, cmd api.Cmd, o
).AddWrite(
callbackHandleData.Data(),
))
t.reportCallbacks[inst] = callbackHandle
}
}

func (t *findIssues) Flush(ctx context.Context, out transform.Writer) {
cb := CommandBuilder{Thread: 0, Arena: t.state.Arena}
for inst, ch := range t.reportCallbacks {
out.MutateAndWrite(ctx, api.CmdNoID, cb.ReplayDestroyVkDebugReportCallback(inst, ch))
// It is safe to delete keys in loop in Go
delete(t.reportCallbacks, inst)
}
out.MutateAndWrite(ctx, api.CmdNoID, cb.Custom(func(ctx context.Context, s *api.GlobalState, b *builder.Builder) error {
b.RegisterNotificationReader(func(n gapir.Notification) {
vkApi := API{}
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/replay.go
Expand Up @@ -431,7 +431,7 @@ func (t *destroyResourcesAtEOS) Flush(ctx context.Context, out transform.Writer)

// Debug report callbacks
for handle, object := range so.DebugReportCallbacks().All() {
out.MutateAndWrite(ctx, id, cb.ReplayDestroyVkDebugReportCallback(object.Instance(), handle))
out.MutateAndWrite(ctx, id, cb.VkDestroyDebugReportCallbackEXT(object.Instance(), handle, p))
}

// Instances.
Expand Down
11 changes: 1 addition & 10 deletions gapis/api/vulkan/synthetic.api
Expand Up @@ -209,16 +209,10 @@ cmd bool ReplayCreateVkDebugReportCallback(
VkDebugReportCallbackEXT* pCallback) {
if !(instance in Instances) { vkErrorInvalidInstance(instance) }
if pCreateInfo == null { vkErrorNullPointer("VkDebugReportCallbackCreateInfoEXT") }
info := pCreateInfo[0]
read(pCreateInfo[0:1])
handle := ?
if pCallback == null { vkErrorNullPointer("VkDebugReportCallbackEXT") }
pCallback[0] = handle
object := new!DebugReportCallbackObject(
Instance: instance,
Flags: info.flags,
VulkanHandle: handle,
)
DebugReportCallbacks[handle] = object
return ?
}

Expand All @@ -227,7 +221,4 @@ cmd void ReplayDestroyVkDebugReportCallback(
VkInstance instance,
VkDebugReportCallbackEXT callback) {
if !(instance in Instances) { vkErrorInvalidInstance(instance) }
if (callback != as!VkDebugReportCallbackEXT(0)) {
delete(DebugReportCallbacks, callback)
}
}

0 comments on commit e5b2d6b

Please sign in to comment.