Skip to content

fix(spirv): lower thread pointers to function-local scalars - #5327

Open
iamcipherdev wants to merge 1 commit into
CrossGL:mainfrom
iamcipherdev:fix/spirv-thread-pointer-locals-2026-12-04
Open

iamcipherdev wants to merge 1 commit into
CrossGL:mainfrom
iamcipherdev:fix/spirv-thread-pointer-locals-2026-12-04

Conversation

@iamcipherdev

Copy link
Copy Markdown
Contributor

Closes #2283

SPIR-V output lowers a helper's pointer parameter to inout when a call passes the address of a whole function-local scalar, as HLSL already does: the argument is copied into the parameter's own Function variable and copied back when the call returns. A dereference (*a) or subscript (x[i]) of the parameter in the callee body reads and writes that variable. This covers the issue's Metal reproducer tsum(&mean, ...) and the OpenCL C / CUDA helpers from the 2 Dec note (minmax(x, y, &lo, &hi), swapf(&lo, &hi)). The lowering is fail-closed: only &identifier of a Function-storage scalar whose type matches the declared pointee exactly, on a non-const parameter; anything else keeps the existing refusal. WGSL is out of scope here (follow-up).

Verification

  • New regression tests (fail-first: all 3 failed on unpatched main with SpirvLoweringRefused): Metal tsum, OpenCL minmax/swapf, CUDA minmax — each asserts copy-in/copy-out of the caller's variable, no OpFunctionCall, no WARNING.
  • tests/test_translator/test_codegen/: 8866 passed, 1469 skipped, 0 failed. tests/test_changelog.py: 12 passed.
  • Repo lint gates on changed files: ruff critical checks (--select=E9,F63,F7,F82) pass; black --preview --target-version=py38 clean.

Not verified locally (disclosed): no native validators exist in this environment (no spirv-as/spirv-val, dxc, naga, or slangc), so spirv-val validation of the new tests is CI-guarded — the new tests skip at assert_spirv_module_validates here. Full 46k translator suite not run locally (VM is 1.5 CPU); the SPIR-V/codegen subsets above are green.

SPIR-V output lowers a helper's pointer parameter to inout when a call passes the address of a whole function-local scalar, as HLSL already does: the argument is copied into the parameter's own Function variable and copied back when the call returns. A dereference or subscript of the parameter in the callee body reads and writes that variable, so tsum(&mean, ...) and minmax(x, y, &lo, &hi) now translate instead of being refused with requires a storage buffer argument.

Closes CrossGL#2283
@github-actions github-actions Bot added area:codegen Code generators backend:spirv Vulkan SPIR-V direction:output Generating a native language from CrossGL labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Coverage change against main

Against the coverage published for db2b806890c4 on 2026-12-04, coverage is unchanged.

Not measured in this run: CUDA output, CUDA input, HIP output, HIP input, Metal output, Metal input, Mojo output, Mojo input, Rust output, Rust input.

Measured by this Coverage run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codegen Code generators backend:spirv Vulkan SPIR-V direction:output Generating a native language from CrossGL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lower thread pointers to function-local scalars in SPIR-V helper calls

1 participant