Repository navigation
Carry out a matrix operation of a name beside a written matrix in a shader - #2562
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # BREAKING-CHANGES.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2561.
MathS.Shaders.HlslandGlslrefused adot,cross,det,transpose,traceor 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.Hlslof the outputodot(x * [1, 2], [3, 4])doto = ((x * 3.0) + ((x * 2.0) * 4.0));dot([1, 0], cos(y) * [x, y])doto = (cos(y) * x);det(x * [[1, 2], [3, 4]])deto = (-(2.0 * (x * x)));[0, 0, 1]T * cross(x * [1, 0, 0], [0, y, 0])[[0, 0, 1]]o = (x * y);[1, 0]T * transpose(x * [[1, 2], [3, y]]) * [0, 1][[1, 0]]o = (x * 3.0);[1, 0]T * [[x, y], [1, 2]] * [0, 1][[1, 0]]o = y;x + dot(x * [1, 2], [3, 4, 5])dotdot([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.Preparednow does whatCompiledoes before compiling:MatrixOperationsOverNumbers.Rewrittenwith every variable a number. That replaces its own rule, which carried out an operation only when every operand was a written matrix.InnerSimplified. This reduces a product of written matrices to the number it gives, asCompiledoes (Matrixshould be compileable #425).transpose(x), it does not simplify, because simplification would read the transpose as a number beside the written matrices (InnerSimplified reads transpose(A) as a number: [1, 0]T * transpose(A) * [0, 1] is 0 #2557). The expression is refused as it stands.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
CarriedOutrather thanInnerSimplified. On the six such shapes that printed before (adot, adet, atrace, acrossinside adot, atransposeand an entry), the printed text is identical on 2.9.0 and on this branch.Tested
ShadersTest.MatrixOperations. The printed shader code is compiled as C# and compared withCompile<double, double, double>at 200 points. Each row was refused on 2.9.0 (measured above), so each fails there.WhatHasNoFaithfulFormIsDeclined, vectors of different lengths and a transpose of a variable.Usage/Shaders.mdsays what is carried out and what is still declined.🤖 Generated with Claude Code