mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:30:52 +01:00
[PR #1947] runtime: eliminate per-instruction allocations in spirv_f16_halves #1954
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1954
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1947
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/rt-spirv-f16-halves-flat-scan📝 Commits (1)
2bf5c6cruntime: eliminate per-instruction allocations in spirv_f16_halves📊 Changes
2 files changed (+327 additions, -152 deletions)
View changed files
📝
runtime/src/spirv_f16_halves.h(+265 -152)📝
runtime/test/spirv_f16_halves_test.cpp(+62 -0)📄 Description
Item ID:
RT-SPIRV-F16-HALVES-FLAT-SCAN-PERF(claimed in #1608 comment #7167909660).Summary
Eliminates per-instruction
std::vector<uint32_t>heap allocations inleonida::link_f16_halves()(runtime/src/spirv_f16_halves.h), directly speeding up graphics PSO creation under--f16-interp-fallback(MoltenVK / macOS and GPUs withoutVK_KHR_fragment_shader_barycentric) while preserving bit-exact SPIR-V output:validate_and_collect_located_vars):link_f16_halvesparsed every VS and PS instruction intostd::vector<Inst>(eachInstowning a separate heapstd::vector<uint32_t>), even on the no-opalready_linkedfast path where neither module is modified.wc > words.size() - pos) and collectsOutput/InputLocationvariables directly over the flatstd::span<const uint32_t>with zero per-instruction allocations.f16_halvesre-serialized the entireps_modinstruction vector; now records{word_index, new_location}patches from the PS preamble and applies them in place only after VS succeeds (zero full-buffer PS copy, and PS stays untouched on any VS failure).OpAccessChainscan & single-buffer VS rebuild:OpAccessChain/OpInBoundsAccessChainwhen static half variables are actually being demoted, using binary search over the demoted ID list instead of inserting every access chain into astd::set.std::vector<uint32_t>(bulk-copying the entire function section in oneinsertwhen no epilogue synthesis is required), avoidsptr_pointee[...]silent insertion, and guards againstheader[3]ID bound overflow andOpEntryPoint16-bit word-count overflow.spirv_detail::Module,Inst, andcollect_located_varsintact for existing tests and helpers (also hardeningModule::parsewithwc > words.size() - pos).runtime/test/spirv_f16_halves_test.cpp:OpAccessChaindemotion failure and ID bound overflow leaving both VS and PS untouched, and for malformed/truncated instructions inside function bodies still failing on the fast path.A/B Benchmark (
-O2, 8,000-instruction VS + 12,000-instruction PS, 200 iters, 2 runs)All three scenarios produced bit-exact output FNV-64 hashes between base and head:
main)already_linked)Verification
clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror:spirv_f16_halves_testPASSclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror:spirv_f16_halves_testPASSclang++ -std=c++20 -O2 -Wall -Wextra -Werror:spirv_f16_halves_test× 3 runs PASScheck_no_game_data.pyPASS,tests/test_text_write_line_endings.pyPASS (3/3)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.