Abstract
This document discloses a novel method implemented in IKANDY for automatically detecting GPU shader compile errors produced by AI-generated GLSL and WGSL code, silently feeding those exact compiler error strings back to the originating large language model, and retrying compilation — up to a configurable maximum — before surfacing any failure to the user. This method is referred to internally as the AI Shader Error Sandbox.
This publication is intended to establish prior art. Any subsequent patent claim covering this method or substantially similar methods is anticipated by this disclosure.
Background & Problem Statement
GPU shader languages (GLSL, WGSL) are strictly typed and structurally rigid. Large language models produce syntactically valid code for common patterns but frequently generate shaders that fail at the GPU driver's compile stage due to:
| Failure Mode | Example | Frequency |
|---|---|---|
| Immutable binding violation | let x = 1.0; x = 2.0; (WGSL let is immutable) |
Common |
| Undeclared struct / binding | Referencing u.bass without a declared uniform block |
Common |
| Type mismatch | Assigning vec3 to vec4 field |
Occasional |
| Invalid built-in usage | Wrong @builtin attribute for vertex vs fragment stage |
Occasional |
In existing LLM-integrated tools, shader compile errors are surfaced directly to the user as raw driver error strings, requiring manual code intervention. No prior system in the music visualizer or real-time graphics domain closes the feedback loop by automatically returning compiler output to the model for self-correction.
The Novel Method
User submits a natural-language prompt (e.g., "neon audio-reactive waves"). The application sends it to a large language model (Claude Sonnet) with a structured system prompt that constrains output to only the fragment function body — no struct declarations, no binding boilerplate (these are prepended by the host). The model returns a GLSL or WGSL fragment.
The generated fragment is compiled via the WebGL driver (gl.getShaderInfoLog()) or WebGPU driver (device.createShaderModule().getCompilationInfo()). The raw error string from the GPU driver is captured in full — not parsed or summarized.
If compilation succeeds, the shader runs immediately. If it fails and the retry counter is below AUTO_RETRY_MAX (default: 2), the system enters the silent fix loop without notifying the user of a failure. A transient status string (e.g., "compile failed — silent AI auto-fix 1/2…") is shown only in the developer status line.
The system constructs a new LLM request containing the original user prompt, the failed shader source, and the exact GPU compiler error string. The prompt instructs the model: "The shader you wrote produced this GPU compile error: [error]. Rewrite only the fragment function to fix it." No user interaction is required.
The model's corrected fragment replaces the previous version in memory and on disk (the saved .glsl / .wgsl file is overwritten via IPC). Compilation is attempted again. The loop returns to step 2.
If all retries are exhausted without a successful compile, the manual "Fix with AI" button is exposed so the user can intervene. If any retry succeeds, the shader runs immediately and the retry counter resets. From the user's perspective, the shader either works or it doesn't — intermediate failures are invisible.
// Pseudocode — error sandbox retry loop const AUTO_RETRY_MAX = 2; let retryCount = 0; async function compileWithSandbox(source, userPrompt, mode) { const result = await compile(source, mode); if (result.ok) { retryCount = 0; return result; } if (retryCount >= AUTO_RETRY_MAX) { showManualFixButton(); return result; } retryCount++; setStatus(`compile failed — silent AI auto-fix ${retryCount}/${AUTO_RETRY_MAX}…`); const fixed = await requestAiFix({ originalPrompt: userPrompt, failedSource: source, compilerError: result.error, // raw GPU driver string mode }); await saveScene(fixed.code); // overwrite on disk return compileWithSandbox(fixed.code, userPrompt, mode); }
What Makes This Novel
Existing LLM-integrated shader editors (ShaderToy's community, ISF Editor, Bonzomatic) display compiler errors to the user and require manual correction. No prior system in real-time graphics or music visualizer software implements automatic GPU driver error capture → LLM re-submission → silent on-disk overwrite → recompile as a fully closed, user-invisible feedback loop.
The combination of these elements constitutes the novel method:
1 AI fragment generation with structural boilerplate isolation
2 Raw GPU driver error string capture (not parsed or summarized)
3 Closed-loop LLM re-submission with error as context
4 Silent on-disk overwrite of the corrected fragment
5 Configurable retry ceiling with user-visible fallback
6 Zero user interaction required during the fix loop
Shader Type Coverage
| Shader Type | Compiler Error Source | Retry Loop Active | Notes |
|---|---|---|---|
| GLSL (fragment) | gl.getShaderInfoLog() |
Yes — at generate time + at scene mount | scrubGLSL / wrapGLSL applied before each compile |
| WGSL (fragment) | createShaderModule().getCompilationInfo() |
Yes — at generate time + at scene mount | stripUserWgslDuplicates applied before compile; WebGPU async |
The loop applies at two distinct points: during the AI generation flow (immediately after first compile attempt) and during browser-mount (when a user clicks a saved user scene card). This means a shader saved from an older AI output that later fails due to a driver update will also self-correct on next load.
Implementation Context
The AI Shader Error Sandbox is implemented in IKANDY, an Electron 30-based music visualizer running on Windows. AI generation calls target the Anthropic Claude API (claude-sonnet-4-20250514). GLSL shaders compile into inline WebGL contexts; WGSL shaders compile into WebGPU pipelines via _wgpuUserScene() in scenes.js. IPC handlers in main.js manage file writes with strict filename regex validation and size caps.
This technical disclosure was published at ikandy.app and constitutes prior art as of its effective date.
Prior Art Search Summary
A search of npm, GitHub, and general web sources conducted May 2026 found no implementation combining GPU compiler error capture with closed-loop LLM re-submission for automatic shader self-correction in any real-time graphics, music visualization, or creative coding context. Shader editors with AI-assist features (Cursor, GitHub Copilot in VSCode) offer suggestion and inline diff but require manual user acceptance of corrections and do not execute a silent compile-verify-overwrite loop.