Repository navigation
perf(texture): reuse compatible sampled VkImageView for 2D attachments (P2-A) - #5
Merged
Merged
Conversation
On CPU Vulkan ICDs (Lavapipe), vkCreateImageView serializes behind the single rasterizer thread and accounts for ~13.4-13.9s of CPU stall per 150s ABBA leg (max single-call latency ~846-1,075ms). For 1-mip, 1-layer 2D render targets whose sampled VkImageView already has explicit level_count=1, layer_count=1, identity swizzle, full image aspects, and attachment usage, reuse that sampled VkImageView directly in TextureObject::attachment_view with Attachment.held = None instead of creating a duplicate AttachmentView. Preserves dedicated AttachmentView allocation for combined depth-stencil (where sampled is DEPTH-only), swizzled views, multi-mip/array/cube/3D textures, and usage-restricted cross-format views. Adds on-device tests verifying both zero-create reuse and dedicated allocation for ineligible textures, and updates tests/pass.rs for the reused words attachment view.
Apdelrahman1911
added a commit
to ios-linux/x86sim
that referenced
this pull request
Dec 6, 2026
…ment view reuse) Updates external/metal2vulkan submodule from fdaa1dfb7 to 0a45daf1d3cdc25a3d66e64d8162605330e987a5 (ios-linux/metal2vulkan#5: reuse compatible sampled VkImageView for 2D render-pass attachments) so P2-A and P2-B land together.
Apdelrahman1911
added a commit
to ios-linux/x86sim
that referenced
this pull request
Dec 6, 2026
…ed views, and bump metal2vulkan (P2) (#23) * perf(mtlvk): reuse identity tex_view handles and cache BrokerPlane derived views (P2-B) Eliminates repeated vkCreateImageView churn on Lavapipe from: 1. Identity newTextureViewWithPixelFormat calls in State::tex_view (reuses parent Texture handle with refcounted HeldIndex so OBJ_DEL of parent cannot release the set-1 descriptor index while an identity view remains alive). 2. Repeated non-identity derived views over shared BrokerPlane surfaces (e.g. BGRA8UnormSRGB over BGRA8Unorm) via a bounded per-BrokerPlane Mutex<HashMap<BrokerViewKey, CachedBrokerView>> cache (cap 8, automatically freed with BrokerPlane) consulted by both tex_new_buf and tex_view. Adds unit tests for identity view detection and broker view key differentiation, plus a Lavapipe integration test verifying zero extra vkCreateImageView calls across repeated sRGB broker views and identity tex_view. * chore(deps): bump external/metal2vulkan to PR #5 (P2-A sampled attachment view reuse) Updates external/metal2vulkan submodule from fdaa1dfb7 to 0a45daf1d3cdc25a3d66e64d8162605330e987a5 (ios-linux/metal2vulkan#5: reuse compatible sampled VkImageView for 2D render-pass attachments) so P2-A and P2-B land together.
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
Eliminates redundant
vkCreateImageViewcalls on 1-mip, 1-layer 2D render targets (~42-45% of all remainingimage_view_createson Lavapipe, wherevkCreateImageViewserializes behind the single rasterizer thread for ~13.4-13.9s per 150s ABBA leg).Changes
crates/metal2vulkan-runtime/src/texture.rs:level_count: 1, layer_count: 1(instead ofREMAINING_MIP_LEVELS/REMAINING_ARRAY_LAYERS) when creating the sampled view of 1-mip, 1-layer 2D images so it satisfies Vulkan framebuffer attachment VUIDs verbatim.sampled_is_attachment: boolonImageandViewonly when all Vulkan attachment invariants hold:TYPE_2D, 1 mip, 1 layer, identityComponentMapping, fullimage.aspects, attachment image usage, matching format (forImage), and unrestrictedviews_usage(forView).TextureObject::attachment_viewto returnAttachment { view, held: None, .. }when eligible — zerovkCreateImageView, zeroattachmentsmutex contention, zeroAttachmentViewsgauge churn, and lifetime guaranteed by the owningTexture.crates/metal2vulkan-runtime/src/tests/attachment_views.rs:every_device_reuses_sampled_view_for_single_slice_2d_color_attachment(assertsimage_view_createsdelta == 0,attachment_viewsgauge delta == 0,views(&tex).is_empty()).every_device_allocates_dedicated_attachment_view_when_sampled_view_is_ineligible(asserts dedicated views forDepth32FloatStencil8, swizzled 2D view, and 2-mip 2D target).crates/metal2vulkan-runtime/src/tests/pass.rs:attachment_viewsdelta from3to2(wordsis a 1-mip 2D color target with a compatible sampled view;colors(2 mips) andstencil(no sampled view) still allocate dedicated attachment views).Verification
Fork CI (Ubuntu 24.04)(no local compilation/testing per policy).