Skip to content

[0035] Make Matrix::Splat() more user friendly with improved diagnostics for potentially incorrect usage. #8463

@anupamachandra

Description

@anupamachandra

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:

  1. Change the method name to make it clear and explicit that a new matrix is created. Some suggestions: (Create/Make)And(Initialize/Splat)Matrix
  2. Add an attribute like [[nodiscard]] on the method to catch cases like above where the result is ignored.
  3. Have DXIL validator flag undef matrix usage. (Also tracked as a standalone issue)
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions