fir-0.1.0.0: test/Tests/Layout/LocalVariables.hs
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Tests.Layout.LocalVariables where
-- fir
import FIR
------------------------------------------------
-- local variables holding values loaded from a buffer
type S = Struct '[ "i" ':-> Word32, "arr" ':-> Array 4 Float ]
type Defs =
'[ "ubo" ':-> Uniform '[ DescriptorSet 0, Binding 0 ]
( Struct '[ "s" ':-> S ] )
, "out" ':-> StorageBuffer '[ DescriptorSet 0, Binding 1 ]
( Struct '[ "res" ':-> Float, "s" ':-> S ] )
, "main" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
]
program :: Module Defs
program = Module do
entryPoint @"main" @Compute do
s <- use @( Name "ubo" :.: Name "s" )
let i = view @( Name "i" ) s
-- run-time indexing into a loaded value
assign @( Name "out" :.: Name "res" )
( view @( Name "arr" :.: AnIndex ( Code Word32 ) ) i s )
-- mutable local copy of a loaded value
_ <- def @"t" @RW s
assign @( Name "t" :.: Name "arr" :.: AnIndex Word32 ) i 7
assign @( Name "out" :.: Name "s" ) =<< get @"t"