module Vulkan.Utils.Debug
  ( debugCallbackPtr
  , debugCallbackFatalPtr
  , nameObject
  ) where

import           Control.Monad.IO.Class
import           Data.ByteString

import           Vulkan.Core10
import           Vulkan.Extensions.VK_EXT_debug_utils

-- | A debug callback which prints the message prefixed with "Validation: " to
-- stderr.
foreign import ccall unsafe "DebugCallback.c &debugCallback"
  debugCallbackPtr :: PFN_vkDebugUtilsMessengerCallbackEXT

-- | A debug callback the same as 'debugCallbackPtr' except it will call
-- @abort@ when @VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT@ is set.
foreign import ccall unsafe "DebugCallback.c &debugCallbackFatal"
  debugCallbackFatalPtr :: PFN_vkDebugUtilsMessengerCallbackEXT

-- | Assign a name to a handle using 'setDebugUtilsObjectNameEXT', note that
-- the @VK_EXT_debug_utils@ extension must be enabled.
nameObject :: (HasObjectType a, MonadIO m) => Device -> a -> ByteString -> m ()
nameObject :: Device -> a -> ByteString -> m ()
nameObject device :: Device
device object :: a
object name :: ByteString
name = Device -> DebugUtilsObjectNameInfoEXT -> m ()
forall (io :: * -> *).
MonadIO io =>
Device -> DebugUtilsObjectNameInfoEXT -> io ()
setDebugUtilsObjectNameEXT
  Device
device
  ((ObjectType
 -> Word64 -> Maybe ByteString -> DebugUtilsObjectNameInfoEXT)
-> (ObjectType, Word64)
-> Maybe ByteString
-> DebugUtilsObjectNameInfoEXT
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ObjectType
-> Word64 -> Maybe ByteString -> DebugUtilsObjectNameInfoEXT
DebugUtilsObjectNameInfoEXT (a -> (ObjectType, Word64)
forall a. HasObjectType a => a -> (ObjectType, Word64)
objectTypeAndHandle a
object) (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
name))