packages feed

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

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

module Tests.Layout.Offsets where

-- fir
import FIR
import Math.Linear

------------------------------------------------
-- offsets of structures nested in arrays, and arrays of matrices

type Defs =
  '[ "ssbo" ':-> StorageBuffer '[ DescriptorSet 0, Binding 0 ]
                   ( Struct
                      '[ "a"  ':-> Float
                       , "xs" ':-> Array 2 ( Struct '[ "x" ':-> Float ] )
                       , "ms" ':-> Array 2 ( M 4 4 Float )
                       ]
                   )
   , "main" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
   ]

program :: Module Defs
program = Module do
  entryPoint @"main" @Compute do
    x <- use @( Name "ssbo" :.: Name "xs" :.: Index 1 :.: Name "x" )
    m <- use @( Name "ssbo" :.: Name "ms" :.: Index 0 )
    assign @( Name "ssbo" :.: Name "a" ) x
    assign @( Name "ssbo" :.: Name "ms" :.: Index 1 ) m