alan icon indicating copy to clipboard operation
alan copied to clipboard

Implement GPU types and methods

Open dfellis opened this issue 1 year ago • 2 comments

The exact shape of this isn't super clear, yet, but either a set of opaque types and bound functions, or pure Alan code on top of a thin wrapper over wgpu/WebGPU is needed to construct an AST to serialize to wgsl and then execute on the GPU.

This is the purpose of Alan v0.2

dfellis avatar Jun 11 '24 01:06 dfellis

Remaining built-in functions of wgsl to bind using this as the reference:

  • [x] countLeadingZeros
  • [x] countOneBits
  • [x] countTrailingZeros
  • [x] cross
  • [ ] degrees
  • [x] determinant
  • [ ] distance and length (these will get different names. length has become magnitude, not yet decided on distance)
  • [x] dot
  • [ ] exp2 (maybe? Not sure if I need to include this when pow exists. I did include exp but only because that's actually pretty commonly used)
  • [x] extractBits
  • [ ] faceForward (this appears to be a composite function on its own, unsure if I should include it)
  • [x] firstLeadingBit (renamed flb)
  • [x] firstTrailingBit (renamed ftb)
  • [x] fma
  • [x] fract
  • [ ] frexp (including it in the list as considered, but I don't see any value in it)
  • [x] insertBits
  • [x] inverseSqrt
  • [ ] ldexp (also doesn't seem necessary? it's the inverse of frexp but I don't see the expressive value here)
  • [ ] mix
  • [ ] modf (also weird to include when the other functions already exist)
  • [x] normalize
  • [ ] radians
  • [ ] reflect
  • [ ] refract
  • [x] reverseBits
  • [x] round
  • [x] saturate
  • [ ] sign (do we need this?)
  • [ ] smoothstep (also a compound function, but if its backed by hardware maybe?)
  • [ ] step
  • [x] transpose
  • [x] pack4x8snorm
  • [x] pack4x8unorm
  • [x] pack2x16snorm
  • [x] pack2x16unorm
  • [x] pack2x16float
  • [x] unpack4x8snorm
  • [x] unpack4x8unorm
  • [x] unpack2x16snorm
  • [x] unpack2x16unorm
  • [x] unpack2x16float
  • [x] storageBarrier storageBarrier is broken on ARM Macs, it's essentially equivalent to workgroupBarrier may or may not block usage on Mac and Browser because of this.
  • [ ] ~~workgroupBarrier (not including this at first, as I have no way to represent the workgroup pointer at the moment)~~
  • [ ] ~~workgroupUniformLoad (not including this at first, as I have no way to represent the workgroup pointer at the moment)~~

I am not including any of the derivative functions because they're only for pixel shaders, I'm not including any of the texture functions because I do not have any texture functionality at the moment (and I hope to get away with just the copy-buffer-to-shader functionality to do rendering), and I'm not including any atomic operations at the moment as I have no representation of atomics.

This is just the list of things I want to get done for compute shaders, which are the only shaders I'm exposing at the moment.

I also still feel like there's some work to be done on the GBuffer type and its usage, but I'm not going to consider that blocking to close this issue out.

dfellis avatar Nov 13 '24 15:11 dfellis

I think I have implemented enough of this to unblock a v0.2 beta, so I'm removing that label.

dfellis avatar Jan 08 '25 17:01 dfellis