The current internal graph representation for LineDependencies does not work well for more complex use cases and relies heavily on implementation details of the GLSL shader AST. Even simple assignmentscan result in complex code due. Applications only care about the unmodified parameter value. Other example include detecting texture layering functions. The source code in PC shaders can server as a reference to match with decompiled output.
This will require some sort of query for the structure of the graph since variable names and line ordering may change. A query would match the operations of a function like sqrt(x) <- abs(x) <- 1-x <- input. This can probably just be done manually with helper methods instead of a query language or macro.
A graph representation where each node represents an assignment operation can allow the same queries to run with assembly or code as input. This should also make it possible to implement the necessary support for Xenoblade X in the future. Switch support could even use alternative sources like assembly instead of GLSL. This was described and partially implemented for Smash Ultimate to detect premultiplied alpha in https://github.com/ScanMountGoat/Smush-Material-Research/blob/69120fe954f005b37a798f1b9ea232c7df2c38e3/smush_materials/src/main.rs#L628.
[x] directed graph representation where each node is an operation, inputs, and output
[x] convert GLSL to the graph representation
[x] convert graph to GLSL
[x] graph queries to find structures and extract variables
The current internal graph representation for
LineDependencies
does not work well for more complex use cases and relies heavily on implementation details of the GLSL shader AST. Even simple assignmentscan result in complex code due. Applications only care about the unmodified parameter value. Other example include detecting texture layering functions. The source code in PC shaders can server as a reference to match with decompiled output.This will require some sort of query for the structure of the graph since variable names and line ordering may change. A query would match the operations of a function like
sqrt(x) <- abs(x) <- 1-x <- input
. This can probably just be done manually with helper methods instead of a query language or macro.A graph representation where each node represents an assignment operation can allow the same queries to run with assembly or code as input. This should also make it possible to implement the necessary support for Xenoblade X in the future. Switch support could even use alternative sources like assembly instead of GLSL. This was described and partially implemented for Smash Ultimate to detect premultiplied alpha in https://github.com/ScanMountGoat/Smush-Material-Research/blob/69120fe954f005b37a798f1b9ea232c7df2c38e3/smush_materials/src/main.rs#L628.
ASM -> directed graph -> input dependencies GLSL -> directed graph -> input dependencies
examples:
gWrkFl4[2].y
to out_attr1.y for ch11021013, body_skert2, technique 28 (calcGeometricSpecularAA)