Skip to content

CheerWizard/KSL

Repository files navigation

Kotlin Shading Language

Core Language Features

Types & Operators

  • ✅ Basic types (Float2/3/4, Int2/3/4, UInt2/3/4, Mat2/3/4)
  • ✅ Vector/matrix arithmetic operators
  • ✅ Swizzling (xyz, rgb, xyzw, rgba etc.)
  • ✅ Type casting (toFloat, toInt, toUInt etc.)
  • ✅ Bitwise operators (and, or, xor, shl, shr, inv)
  • ✅ Unary minus, unary not
  • ✅ Constants (const val PI = 3.14159f)
  • ✅ Arrays - fixed-size (Array<Light>(4))
  • ✅ Arrays - unsized (in storage buffers)
  • ✅ Array indexing (lights[i])

Control Flow

  • ✅ if / else if / else
  • ✅ for loop
  • ✅ while loop
  • ✅ switch / when
  • ✅ break / continue
  • ✅ return

Functions

  • ✅ Helper functions (utility @Shader classes / includes)
  • ✅ User-defined functions
  • ✅ kotlin.math builtins (sin, cos, sqrt etc.)
  • ✅ KSL math builtins (dot, cross, normalize, mix, clamp etc.)
  • ✅ pow() vector broadcasting for GLSL
  • 🔲 transpose()
  • 🔲 determinant()
  • 🔲 Derivative functions - dFdx, dFdy, fwidth (fragment only)
  • 🔲 Atomic operations - atomicAdd, atomicMin, atomicMax etc.

Resources

  • ✅ Uniform buffers (@UniformBuffer)
  • ✅ Storage buffers (@StorageBuffer, read/write + read-only)
  • ✅ Samplers (Sampler, SamplerShadow)
  • ✅ Textures (Texture2D, Texture3D, TextureCube, Texture2DArray etc.)
  • ✅ Sampler methods (sample, sampleLod, sampleBias, sampleGrad, sampleShadow)
  • 🔲 Push constants (@PushConstant)
  • 🔲 Shared/threadgroup memory (@Shared) for compute
  • 🔲 Storage textures — read/write textures in compute

Builtin Variables

  • ✅ Vertex - position, vertexIndex, instanceIndex
  • ✅ Fragment - fragCoord, frontFacing
  • ✅ Compute - globalInvocationId, localInvocationId, workgroupId, localInvocationIndex

Translation

GLSL

  • ✅ Version header (#version 460)
  • ✅ in/out flat globals with in_/out_ prefix
  • ✅ gl_Position, gl_FragCoord etc.
  • ✅ Uniform buffer (std140)
  • ✅ Storage buffer (std430)
  • ✅ Sampler + texture separate objects
  • ✅ texture(sampler2D(tex, samp), uv) call site
  • ✅ Reserved keyword validation

WGSL

  • ✅ Struct-based I/O
  • ✅ @group/@binding layout
  • ✅ var / var
  • ✅ sampler / texture_2d etc.
  • ✅ Entry point builtin parameters (@builtin annotation)
  • 🔲 Storage texture (texture_storage_2d)

MSL

  • ✅ Struct-based I/O with [[attribute(n)]]
  • ✅ [[buffer(n)]] layout
  • ✅ Sampler/texture as function parameters [[sampler(n)]] [[texture(n)]]
  • ✅ Entry point builtin parameters ([[thread_position_in_grid]] etc.)
  • 🔲 Inject resources as parameters into main() function
  • 🔲 Storage texture

Testing

  • 🔲 Snapshot testing, erasing whitespacing and formatting
  • 🔲 SPIR-V validation as test assertion
  • 🔲 WGSL validation (naga or tint)
  • 🔲 MSL validation (xcrun metal on macOS)
  • 🔲 Array tests
  • 🔲 Bitwise operator tests
  • 🔲 Type casting tests
  • 🔲 Compute shader tests
  • 🔲 Include/utility shader tests
  • 🔲 Edge case tests for all new features

IntelliJ Plugin

  • ✅ Live type validation (@Shader class property types)
  • ✅ Reserved keyword inspection per language
  • ✅ K2 Analysis API (KaSession)
  • ✅ Hot reload via ProjectService + VFS file watcher
  • ✅ Gradle continuous build triggered on .kt save
  • ✅ Build success/failure notifications
  • ✅ Read and apply configs from build.gradle.kts from correct KSL project
  • 🔲 File creation/deletion watcher fix (cleanup is not working)
  • 🔲 In-process compiler (replace ProcessBuilder - faster hot reload)
  • 🔲 Show shader errors inline in editor (not just notification)
  • 🔲 Publish KSL plugin and compiler to Maven and IDE

Kanvas Integration

  • 🔲 @NativeData binary encoding aligned with std140/std430
  • 🔲 UniformBuffer<T> base class with correct size/layout
  • 🔲 StorageBuffer<T> base class
  • 🔲 Shader pipeline binding matching KSL group/binding indices
  • 🔲 Hot reload in Kanvas engine viewport
  • 🔲 Shader error reporting in Kanvas editor UI

Tooling

  • 🔲 Shader playground (web API or desktop app)
  • 🔲 Source maps - map shader errors back to Kotlin line numbers
  • 🔲 KSL version in generated shader file header comment

Known Bugs

  • 🐛 No cleanup by KSL watcher of stale generated shaders
  • 🐛 MSL samplers/textures not injected as entry point parameters
  • 🐛 WGSL samplers/textures not injected as entry point parameters

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages