fix(surface): centralize acquisition and teardown ownership#269
Open
besmpl wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the existing public lifetime contract enforceable without adding a HAL interface:
core.Surfaceowns an opaque acquisition lease, invalidated by present, discard, unconfigure, replacement, and destruction.TextureandTextureViewuse one private HAL resolver, so retained swapchain wrappers fail before native access at render, copy, binding, write, and submit boundaries.Instanceowns the wrappers it creates and releases devices, then platform surfaces, then the native instance; cross-instance surface/device configuration is rejected.Deviceowns the set of configured swapchains and retires all of them in one device-destroy pass. VulkanSurfacecontinues to own onlyVkSurfaceKHR; VulkanInstanceneeds no child registry.Queue.WriteTextureretains and revalidates the wrapper that authorized it, so a write recorded before present/discard cannot later submit a retired swapchain image.This is an Android-independent prerequisite for #268. Android exposed the ownership gap, but the borrowed-surface-texture rule is common to every backend.
Ownership and release order
Active acquisitions are discarded while the device is alive. After device teardown, the logical core configuration is retired before the platform surface is destroyed. Small DX12 guards keep its surface-owned swapchain cleanup safe in that order; Vulkan device loss uses a handle-abandon path rather than issuing child destroys through a lost device.
Verification
GOWORK=off go test ./...GOWORK=off go test -race . ./core ./hal/vulkanGOWORK=off go vet . ./core ./hal/vulkanGOWORK=off go test -tags rust ./...GOWORK=off go mod verifygolangci-lint v2.12.2 run --new-from-rev upstream/main(0 issues)Focused public tests cover present, discard, reconfigure, unconfigure, surface release, device/instance release, foreign acquisition, retained views, idempotent wrapper release, render/copy/bind/submit rejection, deferred writes, submit failure cleanup, and cross-instance ownership. Vulkan tests cover configured-surface ownership and the device-loss abandon path.
Android preview relationship
This Android-independent prerequisite is stacked into draft #268 at exact head
85eeeb02a278bf4caebf66310b6baad8c328dd87. The draft will rebase it out after merge; Android runtime claims remain gated in that PR.