Skip to content

Conversation

@marleo02
Copy link

This PR allows to disable only external compression, while leaving internal compression untouched, it also include an heuristic in case there is no swapchain creation / presentation that acts on vkCreateImage. Presentations case handled: WSI Swapchain, DMA-buf import/export, AHB import/export. For DMA-buf and AHB import, an error is returned as it is not possible to control external compression with a Vulkan layer.

@marleo02 marleo02 force-pushed the disable-external-compression branch 2 times, most recently from fba9eda to abd053c Compare October 31, 2025 12:30
@marleo02 marleo02 force-pushed the disable-external-compression branch from abd053c to 0af559d Compare October 31, 2025 12:33
Copy link
Contributor

@solidpixel solidpixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick first pass just to align on coding standard. Some bits I comment on first occurrence only, so check for later occurrences too.

VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateSwapchainKHR<user_tag>(VkDevice device,
const VkSwapchainCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSwapchainKHR* pSwapchain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing brace on same line as last parameter to keep clang=tidy happy. Ditto below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted everywhere, I hope. Do we have something to check that all the formatting is compliant?

if (ci->arrayLayers != 1) return false; // Might introduce false negative, stereo images are excluded

// Prefer common present-ish color formats.
switch (ci->format) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brace on new line for coding style. (Ditto in all the files, not tracking per instance).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed, see comment #155 (comment)

// --------------------------------------------
// Heuristic + external export intent detection
// --------------------------------------------
const bool present_like = heuristic_is_present_like_image(pCreateInfo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we know which images came from the swapchain via vkGetSwapchainImagesKHR()? Can't we just track those, and avoid the heuristic based on format alone?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need for this heuristic arose from a Vulkan application (specifically, gfxreconstruct) that was replaying a trace originally captured on an Android device using an AHB for presentation. When replayed on a Linux platform, no swapchain was created, and the AHB was ignored, resulting in no presentation at all.

We’ve since developed a patch in gfxreconstruct to address this issue: a valid swapchain is now created when this situation occurs. However, this change has not yet been merged into either the downstream or upstream official releases.

I suspect there may be other scenarios where such a heuristic could also prove useful. Please share your thoughts on whether we should keep it or remove it.

VkImageCompressionControlEXT* compressionControl = &newCompressionControl;
auto append = [&](VkBaseOutStructure* n){
n->pNext = nullptr;
if (!rebuilt_head) rebuilt_head = rebuilt_tail = n;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style follows MISRA for bracing (if/else should always use braces, and body should be on different line to the condition). It's a lot more readable than long one-liners.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now, see comment #155 (comment)

@marleo02 marleo02 force-pushed the disable-external-compression branch from 520cf16 to cdcf94c Compare November 3, 2025 15:47
@marleo02 marleo02 force-pushed the disable-external-compression branch from cdcf94c to 93221b9 Compare November 3, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants