Giter VIP home page Giter VIP logo

Comments (10)

expipiplus1 avatar expipiplus1 commented on August 21, 2024 1

Unsafe calls are now enabled by default, they can be made safe with the safe-foreign-calls flag.

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

Unfortunately the very first call one makes to Vulkan (vkCreateInstance) takes a bunch of callbacks and is entitled to remember them and call them at any time.

Any Create call is able to remember (and use) the allocation callbacks until the corresponding Destroy call.

See here: https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#memory-allocation

If an implementation intends to make calls through an VkAllocationCallbacks structure between the time a vkCreate* command returns and the time a corresponding vkDestroy* begins, that implementation must save a copy of the allocator before the vkCreate* command returns.

Because of this by default I think it's best to keep these as safe calls to avoid surprises.

Although: I imagine that lots of users are going to just stick with the default malloc/free pair and don't need to be bothered with the safe call overhead so the unsafe alternatives should probably be provided too.

How would be best to expose these unsafe variants?

  • Duplicating every Vulkan command and adding a suffix along the lines of UnsafeNoCallbacks or NoCallbacks
  • Duplicating every Vulkan command and adding a low profile suffix such as '
  • Duplicating every module so one could import Graphics.Vulkan.Device or Graphics.Vulkan.Device.NoCallbacks
  • Duplicating every module so one could import Graphics.Vulkan.NoCallbacks.Device instead.
  • Something else altogether

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

It might even make more sense to invert those alternatives and provide the unsafe functions by default, and require using alternative command or module names if one requires using Haskell callbacks.

from vulkan.

jmcarthur avatar jmcarthur commented on August 21, 2024

I like the duplicated modules. It gives users more control over scope and module qualification. I have no opinion on whether to put the NoCallbacks portion of the name near the beginning or the end, nor on which alternative should be the default.

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

Sounds good to me.

I'll get down to closing this issue after the other issues with this package are fixed (Show instances etc...). I can't imagine that anyone's going to be requiring losing this safe call overhead for a little while yet.

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

Hmm, I wonder if this could be done with a configuration flag. Along the same lines as vector's "don't do any bounds checking" flag.

from vulkan.

achirkin avatar achirkin commented on August 21, 2024

I would suggest having a special flag for this. Moreover, maybe it makes sense to generalize the flag idea for something like dev with safe calls and automatic error checking after each command?
I've seen nice a approach in some yesod's projects:

vulkan.cabal:

flag dev
    description: Turn on development settings.
    default: True

library
    if (flag(dev))
        cpp-options: -DDEVELOPMENT
        ghc-options: -Wall -fwarn-tabs -O0
...

*.hs:

{-# Language CPP #-}
...
#if DEVELOPMENT
foreign import ccall "vkFunc" vkFunc :: Param -> IO VkResult
#else
foreign import ccall unsafe "vkFunc" vkFunc :: Param -> IO VkResult
#endif

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

Well, it's not exactly a development setting. It's an optimization which is only safe to do when one hasn't given Vulkan any callbacks which could come back into Haskell-land.

from vulkan.

expipiplus1 avatar expipiplus1 commented on August 21, 2024

After consulting with the #vulkan channel it seems as though idiomatic usage is for development to track allocations. Seems like custom allocators are not a widely used feature anyway.

from vulkan.

achirkin avatar achirkin commented on August 21, 2024

I just made two copies of each function to let user decide if they want to play risky or not :)
Also, I think it may be ok to call some vulkan functions unsafe even with callbacks attached, because the functions seem return immediately (callbacks are executed later, when the haskell runtime is resumed and there is no danger of blocking during FFI call). Though, I have not tested this yet.

from vulkan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.