shader-slang / slang

Making it easier to work with shaders
MIT License
1.94k stars 166 forks source link

Metal: Metal ignores default Matrix layout options of Slang #4537

Closed ArielG-NV closed 1 month ago

ArielG-NV commented 1 month ago

Related to: #4291 tests/compute/column-major.slang test produces incorrect results. The results seem to hint that the matrix used is not swapping its major'ness.

The emitting-code seems to reflect this, getTargetProgram()->getOptionSet().getMatrixLayoutMode() is not taken-into-account when emitting metal code.

ArielG-NV commented 1 month ago

Requirements:

[1] - we hack around mul currently (not all multiplies are intrinsic_op's, need to make them intrinsic_op's). Require to add the following:

ArielG-NV commented 1 month ago

note: old method to solve the problem is being phased out for a new method which fixes and unifies the solution with GLSL/HLSL/SPIRV

  1. fix packing not being respected by cpp/metal/cuda
  2. lowerBufferElementTypeToStorageType() is where we should legalize matrix-load and matrix-store
  3. remove all unneeded row_major/column_major modifier emits. Account the translation for the current set default layout (HLSL/GLSL/SPIRV). CPP/Metal/CUDA should always convert matrix layout from global to row_major since there is no default layout allowed for these targets.

// optional...

  1. kIROp for transpose to legalize load/store?
  2. autodiff transpose?