Skip to content

vk: offset descriptor template entries by their element counts - #197

Merged
jmacnak merged 3 commits into
google:mainfrom
qiyinxi:fix/descriptor-template-linearized-offset
Oct 2, 2026
Merged

jmacnak merged 3 commits into
google:mainfrom
qiyinxi:fix/descriptor-template-linearized-offset

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

calcLinearizedDescriptorUpdateTemplateInfo() sizes the linearized buffers by the sum of descriptorCount, and the guest sends every element of every entry in entry order, but the per-entry offsets advanced by only one element per entry. Any image, buffer or buffer view entry that follows an entry with descriptorCount > 1 therefore reads the wrong elements, and the host writes the wrong descriptors. We hit this with a game on an x86_64 android-34 guest, where it showed up as a GPU fault.

The first commit only moves the function and the three type helpers it uses to file scope (no functional change), so that vk_decoder_global_state_unittest.cpp can call it. The second commit advances the offsets by descriptorCount, as the inline uniform block path already does, and adds a test.

Testing: on Windows, I compiled vk_decoder_global_state_unittest.cpp from this branch with clang-cl and the Android Emulator's CMake flags. I linked it into Vulkan_unittests with that build's other objects, plus this branch's vk_emulated_physical_device_memory.cpp and goldfish_vk_supported_extensions.cpp. Then I ran --gtest_filter=VkDecoderGlobalState*: 7/7 pass. Without the fix, the new test fails on entries 1, 3 and 5. I have not run a full CMake or Bazel build of main. The test is only in the CMake Vulkan_unittests target; Bazel has no target for this file.

This change was developed with AI assistance (Claude Code; see the Assisted-by trailer). The tests above were run on my machine, and I am responsible for the change.

calcLinearizedDescriptorUpdateTemplateInfo() and the three descriptor type
helpers it calls do not use any decoder state. Make them file scope
functions so that vk_decoder_global_state_unittest.cpp, which includes the
source file, can test the template layout without a VkDecoderGlobalState.

No functional change.

Test: Vulkan_unittests --gtest_filter=VkDecoderGlobalState*
Assisted-by: Claude Code:Claude-Opus-5.5
calcLinearizedDescriptorUpdateTemplateInfo() sizes the linearized buffers
by the sum of descriptorCount over the entries, and the guest sends every
element of every entry in entry order (vkUpdateDescriptorSetWithTemplateSized
and Sized2), but the per-entry offsets advanced by one element per entry.
An entry that follows an array entry therefore read the array's second
element instead of its own, so the host wrote the wrong image, buffer or
buffer view into every binding after the first array of a template.

Advance the image info, buffer info and buffer view cursors by the entry's
descriptorCount, as the inline uniform block path already does.

Test: Vulkan_unittests --gtest_filter=VkDecoderGlobalState*; the new
      VkDecoderGlobalStateDescriptorUpdateTemplateTest fails on entries
      1, 3 and 5 without the fix and passes with it.
Assisted-by: Claude Code:Claude-Opus-5.5

@jmacnak jmacnak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM, one minor readability nit about the unit test.

Comment thread host/vulkan/vk_decoder_global_state_unittest.cpp Outdated
Describe each template entry together with its expected offset and stride,
written as the previous entries' descriptorCount times their descriptor
sizes, so every expectation sits next to the entry it belongs to.

Test: Vulkan_unittests --gtest_filter=VkDecoderGlobalState*; the test still
      fails on entries 1, 3 and 5 without the offset fix.
Assisted-by: Claude Code:Claude-Opus-5.5
@qiyinxi

qiyinxi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Overall LGTM, one minor readability nit about the unit test.

Done — switched to a TestEntryInfo table as suggested.

@jmacnak jmacnak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you for the fix!

@jmacnak
jmacnak enabled auto-merge October 2, 2026 20:48
@jmacnak
jmacnak disabled auto-merge October 2, 2026 21:52
@jmacnak
jmacnak added this pull request to the merge queue Oct 2, 2026
Merged via the queue into google:main with commit 07ee40e Oct 2, 2026
19 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