Skip to content

Commit 3364603

Browse files
committed
fix: track divergent shader loop controls
1 parent b9ce568 commit 3364603

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

packages/oxlint-plugin-react-doctor/src/plugin/rules/r3f/three-shader-no-derivatives-in-nonuniform-flow.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe("three-shader-no-derivatives-in-nonuniform-flow", () => {
1515
`import { ShaderMaterial } from "three"; new ShaderMaterial({ fragmentShader: "varying float choice; void main() { switch (int(choice)) { case 0: gl_FragColor = vec4(fwidth(choice)); break; default: break; } }" });`,
1616
`import { ShaderMaterial } from "three"; new ShaderMaterial({ fragmentShader: "/* #define fwidth(value) value */ varying float value; void main() { if (value > 0.0) gl_FragColor = vec4(fwidth(value)); }" });`,
1717
`import { ShaderMaterial } from "three"; new ShaderMaterial({ fragmentShader: "varying float value; void main() { do { gl_FragColor = vec4(fwidth(value)); } while (value > 0.0); }" });`,
18+
`import { ShaderMaterial } from "three"; new ShaderMaterial({ fragmentShader: "varying float value; void main() { for (float index = value; index < 1.0; index += 0.25) { gl_FragColor = vec4(fwidth(value)); } }" });`,
19+
`import { ShaderMaterial } from "three"; new ShaderMaterial({ fragmentShader: "varying float value; void main() { for (float index = 0.0; index < 2.0; index += value) { gl_FragColor = vec4(fwidth(value)); } }" });`,
1820
])("reports derivatives in proven fragment-dependent control flow", (code) => {
1921
expect(runRule(threeShaderNoDerivativesInNonuniformFlow, code).diagnostics).toHaveLength(1);
2022
});

packages/oxlint-plugin-react-doctor/src/plugin/rules/r3f/three-shader-no-derivatives-in-nonuniform-flow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ const getControllingExpressions = (path: Path<FunctionCallNode>): AstNode[] => {
4646
controllingExpressions.push(parent.expression);
4747
}
4848
if (parent.type === "for_statement" && currentPath.key === "body" && parent.condition) {
49-
controllingExpressions.push(parent.condition);
49+
controllingExpressions.push(
50+
...[parent.init, parent.condition, parent.operation].filter(Boolean),
51+
);
5052
}
5153
if (parent.type === "ternary" && (currentPath.key === "left" || currentPath.key === "right")) {
5254
controllingExpressions.push(parent.expression);

0 commit comments

Comments
 (0)