Skip to content

Fix shared image and effect shader compilation - #39

Merged
treeform merged 1 commit into
masterfrom
nibby-shader-parity
Nov 15, 2026
Merged

treeform merged 1 commit into
masterfrom
nibby-shader-parity

Conversation

@treeform

Copy link
Copy Markdown
Owner

Shared image and effect shaders exposed several gaps when compiling the same Nim procedures to GLSL, HLSL, and Metal. This fixes those translations so callers can keep their shader logic in Nim without handwritten shader copies or generated-source patches.

  • Correct textureGrad(Uniform[Sampler2D], ...) to accept Vec2 coordinates and emit HLSL SampleGrad or Metal gradient2d sampling. Metal array sampling separates the layer from the 2D coordinates.
  • Add component-wise pow(Vec3, Vec3) and recognize step as a native shader intrinsic, supporting vector color-space conversion expressions.
  • Escape HLSL primitive and interpolation keywords consistently in parameters, locals, globals, and struct fields.
  • Check original built-in names before collecting globals, preventing Vulkan vertex/instance IDs from being redeclared after renaming.
  • Add regression assertions for generated source and the CPU behavior of vector pow.

Compatibility: the previous 2D textureGrad signature incorrectly accepted Vec3; callers using that form should pass uv.xy or another Vec2. The texture-array overload continues to take Vec3.

Validation:

  • nim check --hints:off src/shady.nim and tests/test_backends.nim passed.
  • Downstream Nibby validation compiled six shader entry points for six targets (desktop GLSL 4.10 and 3.30, GLSL ES 3.00, Vulkan GLSL 4.50, HLSL, and Metal): 48 compile/link checks passed, zero failures or skips. HLSL used glslang to produce SPIR-V, not DXIL; Metal used Apple's native library compiler.
  • Downstream OpenGL pixel tests passed, and all 29 comparison renders were byte-identical to the previous handwritten-GLSL output. This verifies the OpenGL migration; it does not establish rendering parity for the other backends.

@treeform
treeform merged commit faf1079 into master Nov 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant