packages feed

fir-0.1.0.0: test/Tests/Builtins/SharedBuiltin.hs

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

module Tests.Builtins.SharedBuiltin where

-- fir
import FIR
import Math.Linear

------------------------------------------------
-- program

-- Two entry points of the same module using the same built-in variable.

type Defs =
  '[ "out"   ':-> StorageBuffer '[ DescriptorSet 0, Binding 0 ]
                    ( Struct '[ "res" ':-> RuntimeArray Word32 ] )
   , "main1" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
   , "main2" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
   ]

program :: Module Defs
program = Module do

  entryPoint @"main1" @Compute do
    ~( Vec3 x _ _ ) <- get @"gl_GlobalInvocationID"
    assign @( Name "out" :.: Name "res" :.: AnIndex Word32 ) x x

  entryPoint @"main2" @Compute do
    ~( Vec3 x _ _ ) <- get @"gl_GlobalInvocationID"
    assign @( Name "out" :.: Name "res" :.: AnIndex Word32 ) x ( x + 1 )