In the LinAlg spec the Splat() method of the matrix class creates a new matrix and not modify the current matrix as might be commonly misterpreted. A user writing this code:
MatTy mat1;
if (uniform_val)
mat1.Splat(0)
else
mat1.Splat(1);
Buffer.Store(0,mat1.Get(0));
might expect mat1 to contain the Splatted value, but in reality since Splat is a static function that creates a new matrix, mat1 is unmodified and lowered to undef in dxil, while the newly generated matrices are silently dropped.
Describe the solution you'd like
To improve user experience the following would be ideal:
- Change the method name to make it clear and explicit that a new matrix is created. Some suggestions: (Create/Make)And(Initialize/Splat)Matrix
- Add an attribute like [[nodiscard]] on the method to catch cases like above where the result is ignored.
- Have DXIL validator flag undef matrix usage. (Also tracked as a standalone issue)
- Add the same mechanisms to other creator methods like Load, CopyConvert, OuterProduct.
Describe alternatives you've considered
-> Add custom attributes to the creator mehods and detect usage in Sema to fire approriate warnings when used with instance syntax vesus a static method on the class. Rejected: Donot disallow legal C++.
-> Make Splat a free function. Rejected: Having Splat inherit the Matrix template parameters than manually laying them out is better user experience.
Additional context
Spec changes also needed, similar to Load and CopyConvert, the spec should call out that Splat (and dx.op.linAlgFillMatrix) creates a new matrix.
In the LinAlg spec the Splat() method of the matrix class creates a new matrix and not modify the current matrix as might be commonly misterpreted. A user writing this code:
might expect
mat1to contain the Splatted value, but in reality since Splat is a static function that creates a new matrix, mat1 is unmodified and lowered toundefin dxil, while the newly generated matrices are silently dropped.Describe the solution you'd like
To improve user experience the following would be ideal:
Describe alternatives you've considered
-> Add custom attributes to the creator mehods and detect usage in Sema to fire approriate warnings when used with instance syntax vesus a static method on the class. Rejected: Donot disallow legal C++.
-> Make Splat a free function. Rejected: Having Splat inherit the Matrix template parameters than manually laying them out is better user experience.
Additional context
Spec changes also needed, similar to
LoadandCopyConvert, the spec should call out that Splat (and dx.op.linAlgFillMatrix) creates a new matrix.