From e4419f51a54695534162fe99d86716753b2297b8 Mon Sep 17 00:00:00 2001 From: wakqasahmed Date: Mon, 17 Aug 2026 11:16:20 +0200 Subject: [PATCH 1/2] feat(allowlist): add Shader Languages support Add .glsl/.hlsl/.wgsl/.metal to the supported file types allowlist, a shared shader.md review rule doc covering precision/NaN handling, texture and buffer bounds safety, cross-stage binding layout contracts, compute-shader synchronization, and GPU-specific performance/security pitfalls, and register the glob-to-rule mapping in system_rules.json. No conventional test-file exclusion pattern exists for shader source files, matching the tracking issue's guidance. Part of the language-allowlist expansion tracked in #470. --- internal/config/allowlist/allowed_ext_test.go | 14 +++++++ .../allowlist/supported_file_types.json | 6 ++- internal/config/rules/rule_docs/shader.md | 40 +++++++++++++++++++ internal/config/rules/system_rules.json | 3 +- internal/config/rules/system_rules_test.go | 4 ++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 internal/config/rules/rule_docs/shader.md diff --git a/internal/config/allowlist/allowed_ext_test.go b/internal/config/allowlist/allowed_ext_test.go index 00391f80d..bc156a456 100644 --- a/internal/config/allowlist/allowed_ext_test.go +++ b/internal/config/allowlist/allowed_ext_test.go @@ -71,6 +71,14 @@ func TestIsAllowedExt(t *testing.T) { {".PO", true}, {".pot", true}, {".POT", true}, + {".glsl", true}, + {".GLSL", true}, + {".hlsl", true}, + {".HLSL", true}, + {".wgsl", true}, + {".WGSL", true}, + {".metal", true}, + {".METAL", true}, {".txt", false}, {".md", false}, {".png", false}, @@ -187,6 +195,12 @@ func TestIsExcludedPath(t *testing.T) { {"elm non-test", "src/Parser.elm", false}, {"elm tests in filename", "src/TestsHelper.elm", false}, + // Shader languages have no conventional default test-file exclusion. + {"glsl shader", "shaders/fragment.glsl", false}, + {"hlsl shader", "shaders/lighting.hlsl", false}, + {"wgsl shader", "shaders/compute.wgsl", false}, + {"metal shader", "shaders/blur.metal", false}, + // Snapshot files {"jest snapshot dir", "src/__snapshots__/App.test.js.snap", true}, {"snap file", "src/components/Button.snap", true}, diff --git a/internal/config/allowlist/supported_file_types.json b/internal/config/allowlist/supported_file_types.json index 736a58650..d9694fc2e 100644 --- a/internal/config/allowlist/supported_file_types.json +++ b/internal/config/allowlist/supported_file_types.json @@ -88,5 +88,9 @@ ".elm", ".properties", ".po", - ".pot" + ".pot", + ".glsl", + ".hlsl", + ".wgsl", + ".metal" ] diff --git a/internal/config/rules/rule_docs/shader.md b/internal/config/rules/rule_docs/shader.md new file mode 100644 index 000000000..380a2d09e --- /dev/null +++ b/internal/config/rules/rule_docs/shader.md @@ -0,0 +1,40 @@ +> Favor precision over recall: only raise an issue when you are confident it is a real defect on the target shading language and pipeline stage; stay silent when the surrounding pipeline setup (bindings, render pass, vertex layout) is defined outside this file and cannot be verified. Treat correctness and security findings as blocking, and style or naming suggestions as non-blocking. + +#### Obvious Typos or Spelling Errors +- Spelling errors in uniform/binding names, semantic names (HLSL `SV_*`), varying/interpolant names, or shader entry-point names at their declaration sites +- Typos in preprocessor macros or `#include` paths that would fail to compile or silently pull in the wrong header + +#### Precision, Range, and Numeric Correctness +- Low/`half`/`mediump` precision qualifiers used for values that need full range or precision (depth, world-space position, accumulation buffers), risking banding or z-fighting +- Division, `rsqrt`, `normalize`, `log`, or `pow` calls on values that can be zero or negative without a guard, producing `NaN`/`Inf` that propagates through the pipeline +- Implicit or explicit type conversions between `float`/`half`/`int`/`uint` that truncate or wrap in a way that changes shading results, especially in loop counters and texture indices +- Non-uniform control flow around `pow`, `log`, or matrix operations that assumes IEEE-754 behavior not guaranteed across all target GPUs/drivers + +#### Texture and Buffer Access Safety +- Texture, buffer, or resource array indices computed from vertex/instance/thread IDs or user data without a bounds check, particularly on `RWStructuredBuffer`/`RWBuffer`/`ssbo`/`storage` writes +- Texture sampling (`tex2D`, `sample`, `textureLod`) called inside non-uniform control flow (e.g. inside an `if` that diverges per-lane) without an explicit LOD, which is undefined or produces incorrect derivatives on some hardware +- Mismatched texture format, channel count, or sRGB/linear color space assumptions between the shader and the resource binding declared on the host side +- Out-of-bounds writes to shared/groupshared/threadgroup memory in compute shaders, or missing barriers (`GroupMemoryBarrierWithGroupSync`, `barrier()`, `workgroupBarrier()`) before reading data another invocation wrote + +#### Binding, Layout, and Cross-Stage Contracts +- Uniform/constant buffer, descriptor set, or binding-slot indices that do not match the layout the host application (or a companion shader stage) expects, since mismatches fail silently at runtime rather than at compile time +- Struct layout (`std140`/`std430` in GLSL, register/space in HLSL, `@binding`/`@group` in WGSL) whose field alignment or padding does not match the CPU-side struct, causing misread values +- Vertex output / fragment input (varyings, `SV_Position`, `[[stage_in]]`) whose interpolation qualifiers (`flat`, `noperspective`, `centroid`) are inconsistent with how the value is used downstream +- Shader variants driven by preprocessor defines or pipeline permutations where a new code path is not covered by all defined permutations, leaving some variants uncompiled or behaviorally inconsistent + +#### Concurrency and Compute Correctness (Compute/Kernel Shaders) +- Race conditions on shared/groupshared/threadgroup memory or storage buffers written by multiple invocations without atomics or synchronization +- Workgroup/threadgroup size assumptions hardcoded in the shader that do not match the dispatch size declared on the host side +- Atomic operations used on types or backends that do not actually support atomics for that format, or atomics used where a simple reduction would be both correct and faster +- Divergent branches or early `return`/`discard` inside a compute kernel placed before a required barrier, causing a deadlock or undefined synchronization on affected lanes + +#### Performance Anti-Patterns +- Expensive operations (dynamic branching, texture-dependent reads, transcendental functions) inside tight loops that could be hoisted, precomputed on the CPU, or baked into a lookup texture +- Dynamic (non-uniform) branching on GPUs where the target hardware executes both sides of a branch per-warp/wavefront, negating the intended savings +- Redundant texture fetches or matrix multiplications recomputed per-fragment/per-thread that are invariant across the invocation and could be computed once (e.g. in the vertex stage or as a uniform) +- Overly large local/register usage (long-lived temporaries, unrolled loops) that reduces occupancy without a documented profiling justification + +#### Security-Sensitive and Portability Concerns +- Shader code paths that read attacker- or user-controlled buffer sizes/offsets (e.g. from a compute dispatch driven by untrusted input) without validating them before use as an index +- Vendor-specific intrinsics or extensions (`GL_ARB_*`, `SV_Barycentrics`, wave/subgroup intrinsics) used without a fallback or capability check, breaking portability across GPUs that lack the extension +- `discard`/`clip` used to implement alpha testing in a way that defeats early-Z/early-depth-test optimizations without a documented performance tradeoff diff --git a/internal/config/rules/system_rules.json b/internal/config/rules/system_rules.json index 8f4a1f5c5..2933e280d 100644 --- a/internal/config/rules/system_rules.json +++ b/internal/config/rules/system_rules.json @@ -36,6 +36,7 @@ "**/*.{hs,lhs}": "haskell.md", "**/*.{nim,nims,nimble}": "nim.md", "**/*.swift": "swift.md", - "**/*.elm": "elm.md" + "**/*.elm": "elm.md", + "**/*.{glsl,hlsl,wgsl,metal}": "shader.md" } } diff --git a/internal/config/rules/system_rules_test.go b/internal/config/rules/system_rules_test.go index 0d90110ba..84a055b89 100644 --- a/internal/config/rules/system_rules_test.go +++ b/internal/config/rules/system_rules_test.go @@ -122,6 +122,10 @@ func TestResolve_DefaultRules(t *testing.T) { {"ChattyFit/ChattyFit/Views/WorkoutSessionView.swift", "SwiftUI State and Lifecycle"}, {"src/Main.elm", "Elm Architecture"}, {"app/Page/Home.elm", "Elm Architecture"}, + {"shaders/fragment.glsl", "Texture and Buffer Access Safety"}, + {"Shaders/Lighting.hlsl", "Texture and Buffer Access Safety"}, + {"shaders/compute.wgsl", "Texture and Buffer Access Safety"}, + {"Shaders/Blur.metal", "Texture and Buffer Access Safety"}, } for _, tt := range tests { From 0d37e4339ed68a8e9d19affe024391e8a4c7645f Mon Sep 17 00:00:00 2001 From: wakqasahmed Date: Tue, 18 Aug 2026 02:48:53 +0200 Subject: [PATCH 2/2] docs: add Shader Languages to review-rules (#975) --- pages/src/content/docs/en/review-rules.md | 1 + pages/src/content/docs/ja/review-rules.md | 1 + pages/src/content/docs/ru/review-rules.md | 1 + pages/src/content/docs/zh/review-rules.md | 1 + 4 files changed, 4 insertions(+) diff --git a/pages/src/content/docs/en/review-rules.md b/pages/src/content/docs/en/review-rules.md index 1e15169d2..8913d9d7d 100644 --- a/pages/src/content/docs/en/review-rules.md +++ b/pages/src/content/docs/en/review-rules.md @@ -177,6 +177,7 @@ matching order: | `**/*.jl` | `julia.md` — Julia source. | | `**/*.{tf,hcl,tfvars}` | `terraform.md` — Terraform / HCL. | | `**/*.bicep` | `bicep.md` — Bicep (Azure) templates. | +| `**/*.{glsl,hlsl,wgsl,metal}` | `shader.md` — GLSL, HLSL, WGSL, and Metal shaders. | | *(fallback)* | `default.md` | The resolved rule body becomes the `{{system_rule}}` placeholder in the diff --git a/pages/src/content/docs/ja/review-rules.md b/pages/src/content/docs/ja/review-rules.md index e86bcbeda..1f01a928a 100644 --- a/pages/src/content/docs/ja/review-rules.md +++ b/pages/src/content/docs/ja/review-rules.md @@ -139,6 +139,7 @@ OCR は [`bmatcuk/doublestar/v4`](https://pkg.go.dev/github.com/bmatcuk/doublest | `**/*.jl` | `julia.md`: Julia ソースコード。 | | `**/*.{tf,hcl,tfvars}` | `terraform.md`: Terraform / HCL。 | | `**/*.bicep` | `bicep.md`: Bicep(Azure)テンプレート。 | +| `**/*.{glsl,hlsl,wgsl,metal}` | `shader.md` - GLSL、HLSL、WGSL、Metal シェーダー。 | | *(fallback)* | `default.md` | 解決されたルール本文は、plan および main task prompt 内の `{{system_rule}}` プレースホルダーの内容になります。 diff --git a/pages/src/content/docs/ru/review-rules.md b/pages/src/content/docs/ru/review-rules.md index f332bb474..6455d5a6e 100644 --- a/pages/src/content/docs/ru/review-rules.md +++ b/pages/src/content/docs/ru/review-rules.md @@ -179,6 +179,7 @@ OCR использует [`bmatcuk/doublestar/v4`](https://pkg.go.dev/github.com | `**/*.jl` | `julia.md` — исходный код Julia. | | `**/*.{tf,hcl,tfvars}` | `terraform.md` — Terraform / HCL. | | `**/*.bicep` | `bicep.md` — шаблоны Bicep (Azure). | +| `**/*.{glsl,hlsl,wgsl,metal}` | `shader.md` - шейдеры GLSL, HLSL, WGSL и Metal. | | *(fallback)* | `default.md` | Разрешённое тело правила становится значением плейсхолдера `{{system_rule}}` diff --git a/pages/src/content/docs/zh/review-rules.md b/pages/src/content/docs/zh/review-rules.md index c477c4e54..b7e5f7af2 100644 --- a/pages/src/content/docs/zh/review-rules.md +++ b/pages/src/content/docs/zh/review-rules.md @@ -160,6 +160,7 @@ OCR 用 [`bmatcuk/doublestar/v4`](https://pkg.go.dev/github.com/bmatcuk/doublest | `**/*.jl` | `julia.md`——Julia 源代码。 | | `**/*.{tf,hcl,tfvars}` | `terraform.md`——Terraform / HCL。 | | `**/*.bicep` | `bicep.md`——Bicep(Azure)模板。 | +| `**/*.{glsl,hlsl,wgsl,metal}` | `shader.md` - GLSL、HLSL、WGSL、Metal 着色器。 | | *(fallback)* | `default.md` | 解析出的规则正文成为 plan 和 main task prompt 中 `{{system_rule}}` 占位符的内容。