Skip to content

Conversation

kvark
Copy link
Member

@kvark kvark commented Sep 20, 2025

Connections
Blocked by gfx-rs/rspirv#265
Since rspirv fails validation of the product, even though it's correct.

Description
Adding shader support for KHR_cooperative_matrix. Considering a rather simple scope that is portable between Vulkan and Metal.

Testing
Adds tests.

Squash or Rebase?
Rebase.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

API choices

SPIRV and Metal have a fine intersection of the cooperative matrix functionality, with some caveats:

  • GLSL calls it "coopmat" while Metal has "simdgroup_typeNxY". I decided to go with "coop_mat" since WGSL fairly consistently separates sub-words with an underscore, e.g. "texture_cube".
  • SPIRV requires a "use" to be associated with each matrix type. It's one of A/B/Acc. Metal doesn't. The API decision here is to expose it as a "role" being one of the generic parameters of coop_mat.
  • SPIRV has OpCooperativeMatrixLoadKHR and OpCooperativeMatrixMulAddKHR as expressions and OpCooperativeMatrixStoreKHR as a statement. Metal has all of them 3 as statements. I figured the arithmetic operation is defined as "a*b + c", which is an expression, and also the inference of the result type is straightforward. The "store" has to be a statement, and it has practically the same signature as "load", which can't trivially infer the result type. So both of them are expressed as statements.
    • the "T" suffix is for transposed load/store. No strong opinion here.
  • Metal also has just the multiplication (as opposed to multiply-add). I opted to not expose this, since we can always follow-up if needed.

@kvark kvark force-pushed the cooperative branch 4 times, most recently from 9f2070f to 881da16 Compare September 25, 2025 04:47
@kvark kvark marked this pull request as ready for review September 26, 2025 03:30
@cwfitzgerald
Copy link
Member

Haven't actually looked in the PR yet, but you should take a look at the presentation about cooperative matrices from the F2F: https://docs.google.com/presentation/d/1wiy3-ar58ah1W9Qc5trd0gG7fwCo93IJ9YCtQoR6W6c/edit?slide=id.g30fc39156ff_0_0#slide=id.g30fc39156ff_0_0 and the dawn design doc https://dawn.googlesource.com/dawn/+/refs/heads/main/docs/dawn/features/subgroup_matrix.md just to make sure things are synced up with upstream.

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