Skip to content

Allocate the replacement DFD before mutating the texture in the UASTC HDR 4x4 relabel path - #1236

Merged
MarkCallow merged 1 commit into
KhronosGroup:mainfrom
SashaRX:fix/hdr4x4-relabel-dfd-alloc-order
Aug 6, 2026
Merged

Allocate the replacement DFD before mutating the texture in the UASTC HDR 4x4 relabel path#1236
MarkCallow merged 1 commit into
KhronosGroup:mainfrom
SashaRX:fix/hdr4x4-relabel-dfd-alloc-order

Conversation

@SashaRX

@SashaRX SashaRX commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Small defensive robustness fix in the UASTC_HDR_4x4 → ASTC_HDR_4x4 early exit of
ktxTexture2_TranscodeBasis, related to the passthrough discussion in #1224.

Problem

The early exit frees This->pDfd and updates This->vkFormat before constructing
the replacement DFD with vk2dfd().

If DFD creation ever reports a failure, the function returns with a partially
mutated texture: the original DFD has already been freed and vkFormat already
describes ASTC HDR.

Fix

Construct the replacement DFD first. Only after successful construction, free
the old DFD and commit the new pDfd and vkFormat.

There is no behavior change on the success path. The path was smoke-tested with
an encode → relabel-transcode round trip.

No regression test is included because the current generated mapping contains
VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK, and there is no existing failure-injection
mechanism for vk2dfd(). This is therefore a defensive transactional-ordering
fix rather than a currently reproducible input-driven failure.

@CLAassistant

CLAassistant commented Aug 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@SashaRX SashaRX changed the title Create replacement DFD before mutating texture in HDR 4x4 relabel path Allocate the replacement DFD before mutating the texture in the UASTC HDR 4x4 relabel path Aug 5, 2026
@SashaRX
SashaRX marked this pull request as ready for review August 5, 2026 14:59
@MarkCallow

Copy link
Copy Markdown
Collaborator

Please sign the CLA.

Comment thread lib/src/basis_transcode.cpp Outdated
@SashaRX
SashaRX force-pushed the fix/hdr4x4-relabel-dfd-alloc-order branch 3 times, most recently from b57f0f9 to 9b0f9cb Compare August 6, 2026 12:19
The UASTC HDR 4x4 to ASTC HDR 4x4 early exit in
ktxTexture2_TranscodeBasis freed the texture's DFD and relabelled
vkFormat before calling vk2dfd(). If vk2dfd() returned NULL the
function returned an error while leaving the texture with a freed pDfd
and an already-changed vkFormat. Allocate the replacement DFD first and
only then modify the texture, so failure leaves it untouched.

No behavior change on the success path.
@SashaRX
SashaRX force-pushed the fix/hdr4x4-relabel-dfd-alloc-order branch from 9b0f9cb to e8354e1 Compare August 6, 2026 12:22
@MarkCallow
MarkCallow merged commit 8c915cd into KhronosGroup:main Aug 6, 2026
41 checks passed
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.

3 participants