Skip to content

Fix SPIRV validation: use array ptr for cooperative vector ops#2

Merged
cmarcelo merged 1 commit intocmarcelo:cmat-cvec-ir-opsfrom
jkwak-work:fix/spirv-coopvec-array-ptr
Mar 31, 2026
Merged

Fix SPIRV validation: use array ptr for cooperative vector ops#2
cmarcelo merged 1 commit intocmarcelo:cmat-cvec-ir-opsfrom
jkwak-work:fix/spirv-coopvec-array-ptr

Conversation

@jkwak-work
Copy link
Copy Markdown

Summary

  • OpCooperativeVectorMatrixMulNV (and related NV cooperative vector ops) require the matrix/buffer operand to be a pointer to an array type, not a pointer to a struct
  • After SPIRV legalization, ByteAddressBuffer/StructuredBuffer global params become ptr-to-struct{runtimeArray<T>}, which fails the SPIRV validator with: Pointer <id>'s Type must be an array type
  • Adds emitBufferPtrAsArrayPtr() helper that emits OpAccessChain index 0 to pierce through the wrapper struct when needed; for Ptr<T[]> inputs that already point directly to an unsized array, the pointer is returned as-is

Affected functions

  • emitCoopVecMatMulAdd — matrix ptr and bias ptr
  • emitCoopVecOuterProductAccumulate — matrix ptr
  • emitCoopVecReduceSumAccumulate — buffer ptr

Test

SLANG_RUN_SPIRV_VALIDATION=1 build/Debug/bin/slangc.exe \
  -entry computeMain -stage compute -target spirv-asm \
  tests/cooperative-vector/matrix-mul.slang

Before: error: line 80: spv::Op::OpCooperativeVectorMatrixMulNV Pointer <id>'s Type must be an array type.
After: compiles cleanly, generates correct OpAccessChain before the matrix mul op.

All 214 cooperative-vector tests pass.

OpCooperativeVectorMatrixMulNV (and related NV ops) require the matrix/buffer
operand to be a pointer to an array type. After SPIRV legalization,
ByteAddressBuffer/StructuredBuffer global params become ptr-to-struct, which
fails the SPIRV validator with "Pointer's Type must be an array type".

Add emitBufferPtrAsArrayPtr() that emits OpAccessChain index 0 to pierce through
the wrapper struct when needed. For Ptr<T[]> inputs that already point directly to
an unsized array, the pointer is returned as-is.

Apply the helper in emitCoopVecMatMulAdd (matrix and bias operands),
emitCoopVecOuterProductAccumulate (matrix operand), and
emitCoopVecReduceSumAccumulate (buffer operand).
@jkwak-work jkwak-work force-pushed the fix/spirv-coopvec-array-ptr branch from 7e5ac66 to d3e24e5 Compare March 30, 2026 23:56
@cmarcelo cmarcelo merged commit fc3c27e into cmarcelo:cmat-cvec-ir-ops Mar 31, 2026
@jkwak-work jkwak-work deleted the fix/spirv-coopvec-array-ptr branch March 31, 2026 15:52
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.

2 participants