Skip to content

Detect SPIR-V endianness from the magic number - #1

Merged
afxgroup merged 1 commit into
mainfrom
fix/detect_spriv_endianes
May 10, 2026
Merged

afxgroup merged 1 commit into
mainfrom
fix/detect_spriv_endianes

Conversation

@afxgroup

Copy link
Copy Markdown
Owner

Detect SPIR-V endianness from the magic number and swap only when needed. Per the Vulkan spec, the magic word may be supplied in either endianness — the driver must accept both. The previous unconditional byte-swap was wrong for callers that already produce host-byte-order SPIR-V (e.g. uint32_t array literals compiled on a big-endian host like ImGui's _glsl_shader*_spv on PowerPC). Reading the first word as raw bytes gives us a byte-order-independent way to decide.

@afxgroup
afxgroup merged commit 23ed586 into main May 10, 2026
@afxgroup
afxgroup deleted the fix/detect_spriv_endianes branch May 10, 2026 16:28
afxgroup pushed a commit that referenced this pull request Jul 31, 2026
PR #1 commit 3 added DEBUG := to the three Docker Makefiles but the
recipes hardcode the gcc invocations rather than expanding $(CFLAGS),
so $(DEBUG) never reached the compiler — the D(...) traces could only
be enabled in the (then-also-new) Makefile.cross path. Splice $(DEBUG)
into every compile line in the recipes so 'make DEBUG=-DDEBUG' works
on the canonical Docker build.

Also revert software_icd/Makefile.cross clean target from
'rm -f build/*' back to the narrow form it had before PR #1 commit 3,
to avoid wiping co-tenant artifacts in build/.
afxgroup added a commit that referenced this pull request Jul 31, 2026
The ICD's vkGetDeviceProcAddr must return raw (non-APICALL) C-ABI
function pointers — the application calls them directly as PFN_vkXxx
with no Self in r3. ogles2vk_LookupRawProcAddr previously listed only
~25 functions and fell back to ogles2vk_LookupProcAddr, which returns
APICALL trampolines. Those trampolines expect Self in r3, so calling
them as raw PFN_vkXxx slides every argument by one register slot —
manifesting as NULL pCreateInfo/pSwapchain inside the ICD when an
application resolved e.g. vkCreateSwapchainKHR through vkGetDeviceProcAddr.

This is the bug PR #1 commit 2 ("Do NOT fall back to ogles2vk_LookupProcAddr")
correctly diagnosed but incorrectly fixed: replacing the fallback with
NULL regressed the five WSI swapchain entry points (and ~165 others)
that lived only in the DISPATCH table.

Expand the ogles2_icd RAW table to mirror the full DISPATCH table —
each entry now points at the underlying non-_t_ function. Then drop
the trampoline fallback in favour of returning NULL.

Also extend software_icd's RAW table to cover the four WSI surface
queries and five swapchain entry points that were similarly missing.

Co-authored-by: Andrea Palmate' <andrea.palmate@gmail.com>
afxgroup pushed a commit that referenced this pull request Jul 31, 2026
vulkan.library, software_vk.library, ogles2_vk.library all advance
from 1.2 (21.03.2026) to 1.3 (11.05.2026). The release groups together
the curated parts of afxgroup's PR #1 (endianness, varying linkage,
VMA limits, VkFormat 37, D() macros) with the proc-addr ABI fix that
expands the RAW lookup tables to mirror DISPATCH.

Verified: ELF MSB headers intact on all three, version strings land
correctly in the built binaries.
afxgroup pushed a commit that referenced this pull request Jul 31, 2026
Integrate the afxgroup collaborator PRs (#1-3) into main alongside the existing
software_icd fixes:
- SPIR-V endianness auto-detect from the magic word (accept BE or LE streams).
- ogles2_vk: do not fall back to ogles2vk_LookupProcAddr() (returns APICALL
  trampolines, not raw PFN_vkXxx) - return NULL for unknown names instead.
- ogles2_vk: proc-addr ABI, varying linkage, VkFormat 37, VMA-limits fixes.

Conflicts resolved keeping BOTH sides: the software_vk shader-module ref-count
(UAF) fix + the Vulkan Y-down viewport convention, AND the ogles2_vk vsync/
glFinish (FIFO present pacing) work, AND the afxgroup changes. Merged software
ICD builds clean; ogles2vk_exec.c syntax-checks (ogles2vk_main.c needs the
Warp3DNova GPU SDK header, absent from the CI image).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant