fir-0.1.0.0: test/Tests/Control/TemporarySetter.hs
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Tests.Control.TemporarySetter where
-- base
import Data.Maybe
( fromJust )
-- vector-sized
import qualified Data.Vector.Sized as Vector
-- fir
import FIR
------------------------------------------------
-- program
-- Setting an element of an array value at a run-time index goes through a local copy
-- of the array. Indexing the original array afterwards must not read the modified copy.
table :: Array 4 Float
table = MkArray ( fromJust $ Vector.fromList [ 1, 2, 3, 4 ] )
type Defs =
'[ "ubo" ':-> Uniform '[ DescriptorSet 0, Binding 0 ]
( Struct '[ "i" ':-> Word32 ] )
, "out" ':-> StorageBuffer '[ DescriptorSet 0, Binding 1 ]
( Struct '[ "res" ':-> Float ] )
, "main" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
]
program :: Module Defs
program = Module do
entryPoint @"main" @Compute do
let
arr :: Code ( Array 4 Float )
arr = Lit table
i <- use @( Name "ubo" :.: Name "i" )
new <- let' $ view @( AnIndex ( Code Word32 ) ) i ( set @( AnIndex ( Code Word32 ) ) i 7 arr )
old <- let' $ view @( AnIndex ( Code Word32 ) ) i arr
assign @( Name "out" :.: Name "res" ) ( new + old )