ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

Metal shader validation crash on macOS: read-only buffer bound to writable shader argument

Open advaitian opened this issue 6 months ago • 2 comments

Summary

Running ds4 with the Metal backend on macOS aborts during shader argument validation with the following assertion:

validateComputeFunctionArguments:1066: failed assertion `Compute Function(kernel_set_rows_f32_i32): Read-only bytes are being bound at index 2 to a shader argument with write access enabled (did you mean to use const or constant in the shader?).'

The process exits with:

zsh: abort ./ds4 -p "Explain Redis streams in one paragraph."

This appears to be caused by a Metal compute shader parameter declared as writable while the runtime binds a read-only buffer.

Environment Platform: macOS Backend: Metal GPU: Apple Silicon GPU

Command: ./ds4 -p "Explain Redis streams in one paragraph."

Full Output ❯ ./ds4 -p "Explain Redis streams in one paragraph."

ds4: context buffers 1061.71 MiB (ctx=32768, backend=metal, prefill_chunk=2048, raw_kv_rows=2304, compressed_kv_rows=8194)

2026-05-09 09:03:07.838 ds4[18719:8143797] Metal API Validation Enabled

ds4: requesting Metal residency (may take tens of seconds)... done ds4: warming Metal model views... done

ds4: Metal model views created in 3.610 ms, residency requested in 27301.094 ms, warmup 22.475 ms (mapped 82697.67 MiB from offset 5.08 MiB)

ds4: Metal mapped mmaped model as 2 overlapping shared buffers ds4: Metal backend initialized for graph diagnostics

validateComputeFunctionArguments:1066: failed assertion `Compute Function(kernel_set_rows_f32_i32): Read-only bytes are being bound at index 2 to a shader argument with write access enabled (did you mean to use const or constant in the shader?).'

zsh: abort ./ds4 -p "Explain Redis streams in one paragraph."

advaitian avatar May 09 '26 16:05 advaitian

ds4 currently does not support running metal with debug on. Not sure if there are other ways to trigger that validation, but just make sure you don't set that.

#39 should fix this.

mitsuhiko avatar May 09 '26 17:05 mitsuhiko

Fixed merging #39, thanks for the report @advaitian, and for the fix @mitsuhiko

antirez avatar May 09 '26 20:05 antirez