Vulkan Apps Now Functional

minimalsmall physical device enumeration example followed(require vulkan/unsafe)huge.

“Forward Declarations” Didn’t Work

(define-cstruct)vk.xml

Creating Healthy Distance from ffi/unsafe Wrapper Functions

Matthew Flatt#define_fun_fun
uint32_t num;
f(&num, NULL);

X* array = (X*)malloc(num * sizeof(X));
f(&num, array);
(define-vulkan vkEnumerateInstanceLayerProperties
(_fun (o0 : (_ptr o _uint32_t))
      (o1 : (_ptr o _VkLayerProperties))
      -> (r : _VkResult)
      -> (begin (check-vkResult r (quote vkEnumerateInstanceLayerProperties))
                (values o0 o1))))
o0o1(_ptr o ...)notvalueso1o0(_ptr o ...)reduces the arity of the wrapping Racket procedure
(define-values (num pArray) (vkEnumerateInstanceLayerProperties))
not a faithful reproduction of the Vulkan API, despite attempts to follow the Vulkan API Registry.

“Hey, this is Vulkan, except every pointer to non-const data you see in a parameter meant that parameter is not actually there and is instead one of the return values.”

_funsuccess codesVK_INCOMPLETE_fun_funThe collection—and _fun in particular—gives you access to C functions, but obliges you to hide C concerns at the same time.one of the suggestions from the user list
(define-vulkan vkEnumerateInstanceLayerProperties
(_fun (o0 : (_ptr io _uint32_t))
      _pointer
      -> (r : _VkResult)
      -> (begin
           (check-vkResult r 'vkEnumerateInstanceLayerProperties)
           o0)))
o1_VkLayerProperties_pointer_fun

Getting struct layouts right

#definevk.xmland(ctype-sizeof X)sizeof(X)

What’s Next?


1