packages feed

fir-0.1.0.0: test/Tests/Layout/RuntimeArray.hs

{-# LANGUAGE BlockArguments   #-}
{-# LANGUAGE DataKinds        #-}
{-# LANGUAGE PolyKinds        #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators    #-}

module Tests.Layout.RuntimeArray where

-- fir
import FIR
import Math.Linear

------------------------------------------------
-- structures containing matrices, in a run-time array

type E = Struct '[ "p" ':-> V 3 Float, "m" ':-> M 4 3 Float, "a" ':-> Array 2 ( M 2 2 Float ) ]

type Defs =
  '[ "ssbo" ':-> StorageBuffer '[ DescriptorSet 0, Binding 0 ]
                   ( Struct '[ "n" ':-> Word32, "arr" ':-> RuntimeArray E ] )
   , "main" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
   ]

program :: Module Defs
program = Module do
  entryPoint @"main" @Compute do
    i <- use @( Name "gl_LocalInvocationIndex" )
    e <- use @( Name "ssbo" :.: Name "arr" :.: AnIndex Word32 ) i
    let e' = set @( Name "p" ) ( Vec3 1 2 3 ) e
    assign @( Name "ssbo" :.: Name "arr" :.: AnIndex Word32 ) ( i + 1 ) ( if i > 3 then e else e' )