content: {-# LANGUAGE QuasiQuotes #-}
  {-# LANGUAGE OverloadedStrings #-}
  {-# LANGUAGE OverloadedLists #-}
  
  module RenderPass
    ( RenderPass.createRenderPass
    ) where
  
  import           Control.Monad.Trans.Resource
  import           Data.Bits
  import           MonadVulkan
  import           Vulkan.Core10                 as Vk
                                           hiding ( withBuffer
                                                  , withImage
                                                  )
  import           Vulkan.Zero
  
  -- | Create a renderpass with a single subpass
  createRenderPass :: Format -> V (ReleaseKey, RenderPass)
  createRenderPass imageFormat = do
    let
      attachmentDescription :: AttachmentDescription
      attachmentDescription = zero
        { format         = imageFormat
        , samples        = SAMPLE_COUNT_1_BIT
        , loadOp         = ATTACHMENT_LOAD_OP_CLEAR
        , storeOp        = ATTACHMENT_STORE_OP_STORE
        , stencilLoadOp  = ATTACHMENT_LOAD_OP_DONT_CARE
        , stencilStoreOp = ATTACHMENT_STORE_OP_DONT_CARE
        , initialLayout  = IMAGE_LAYOUT_UNDEFINED
        , finalLayout    = IMAGE_LAYOUT_PRESENT_SRC_KHR
        }
      subpass :: SubpassDescription
      subpass = zero
        { pipelineBindPoint = PIPELINE_BIND_POINT_GRAPHICS
        , colorAttachments  =
          [ zero { attachment = 0
                 , layout     = IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
                 }
          ]
        }
      subpassDependency :: SubpassDependency
      subpassDependency = zero
        { srcSubpass    = SUBPASS_EXTERNAL
        , dstSubpass    = 0
        , srcStageMask  = PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
        , srcAccessMask = zero
        , dstStageMask  = PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
        , dstAccessMask = ACCESS_COLOR_ATTACHMENT_READ_BIT
                            .|. ACCESS_COLOR_ATTACHMENT_WRITE_BIT
        }
    withRenderPass' zero { attachments  = [attachmentDescription]
                         , subpasses    = [subpass]
                         , dependencies = [subpassDependency]
                         }
  