Skip to content

Carry out a matrix operation of a name beside a written matrix in a shader - #2562

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
shader-matrix-operations-over-numbers
Nov 26, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
shader-matrix-operations-over-numbers

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Closes #2561.

MathS.Shaders.Hlsl and Glsl refused a dot, cross, det, transpose, trace or entry of an expression with a name beside a written matrix. The reason they gave was that "every variable of the shader is a number", and that is why each of these has a value. #2558 made both compilers carry these out; the shader still refused them.

What was refused

MathS.Shaders.Hlsl of the output o 2.9.0 and master this PR
dot(x * [1, 2], [3, 4]) refused at the dot o = ((x * 3.0) + ((x * 2.0) * 4.0));
dot([1, 0], cos(y) * [x, y]) refused at the dot o = (cos(y) * x);
det(x * [[1, 2], [3, 4]]) refused at the det o = (-(2.0 * (x * x)));
[0, 0, 1]T * cross(x * [1, 0, 0], [0, y, 0]) refused at [[0, 0, 1]] o = (x * y);
[1, 0]T * transpose(x * [[1, 2], [3, y]]) * [0, 1] refused at [[1, 0]] o = (x * 3.0);
[1, 0]T * [[x, y], [1, 2]] * [0, 1] refused at [[1, 0]] o = y;
x + dot(x * [1, 2], [3, 4, 5]) refused at the dot refused at dot([x, x * 2], [3, 4, 5])

The full table, measured on the 2.9.0 package and on this branch, is the new BREAKING-CHANGES entry.

How

ShaderSource.Prepared now does what Compile does before compiling:

  1. It calls Compile dot, cross, det and transpose of a name compiled as a number #2558's MatrixOperationsOverNumbers.Rewritten with every variable a number. That replaces its own rule, which carried out an operation only when every operand was a written matrix.
  2. If written matrices are still left and no matrix operation is, it takes InnerSimplified. This reduces a product of written matrices to the number it gives, as Compile does (Matrix should be compileable #425).

This only applies where the expression has a written matrix in it. Where every operand was already a written matrix, the operation is now carried out by CarriedOut rather than InnerSimplified. On the six such shapes that printed before (a dot, a det, a trace, a cross inside a dot, a transpose and an entry), the printed text is identical on 2.9.0 and on this branch.

Tested

  • Values: nine new rows in ShadersTest.MatrixOperations. The printed shader code is compiled as C# and compared with Compile<double, double, double> at 200 points. Each row was refused on 2.9.0 (measured above), so each fails there.
  • Refusals: two new rows in WhatHasNoFaithfulFormIsDeclined, vectors of different lengths and a transpose of a variable.
  • Docs: Usage/Shaders.md says what is carried out and what is still declined.

🤖 Generated with Claude Code

…hader

MathS.Shaders.Hlsl and Glsl refused dot, cross, det, transpose, trace and an entry of an
expression with a name beside a written matrix, such as dot(x * [1, 2], [3, 4]), giving as the
reason that every variable of the shader is a number, which is why each has a value. The shader
now carries them out with MatrixOperationsOverNumbers, as Compile does since #2558, and a product
of written matrices left after that is reduced to the number it gives, as Compile reduces it
(#425). An operation still left, such as a transpose of a variable, is refused before
simplification could read it as a number beside the written matrices (#2557).

Closes #2561.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.72%. Comparing base (6165a84) to head (a126f00).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2562      +/-   ##
==========================================
- Coverage   86.73%   86.72%   -0.01%     
==========================================
  Files         344      344              
  Lines       74813    74833      +20     
  Branches    21825    21837      +12     
==========================================
+ Hits        64888    64901      +13     
- Misses       5358     5364       +6     
- Partials     4567     4568       +1     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.23% <100.00%> (-0.01%) ⬇️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...h/Functions/Compilation/IntoSource/ShaderSource.cs 86.87% <100.00%> (+0.27%) ⬆️

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	BREAKING-CHANGES.md
@Rafael-SOWNet
Rafael-SOWNet merged commit 482e3e5 into master Nov 26, 2026
39 of 42 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 26, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the shader-matrix-operations-over-numbers branch November 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Shaders refuse dot, det and the rest of a name beside a written matrix, though every shader variable is a number

1 participant