chuigda / vulkan4j

Vulkan bindings for Java using Project-Panama (java.lang.foreign) APIs
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

合理运用 `param` 节点中的 `optional` 属性 #8

Closed chuigda closed 5 days ago

chuigda commented 5 days ago
        <command api="vulkan" successcodes="VK_SUCCESS" errorcodes="VK_ERROR_OUT_OF_HOST_MEMORY,VK_ERROR_OUT_OF_DEVICE_MEMORY,VK_ERROR_INITIALIZATION_FAILED,VK_ERROR_EXTENSION_NOT_PRESENT,VK_ERROR_FEATURE_NOT_PRESENT,VK_ERROR_TOO_MANY_OBJECTS,VK_ERROR_DEVICE_LOST">
            <proto><type>VkResult</type> <name>vkCreateDevice</name></proto>
            <param><type>VkPhysicalDevice</type> <name>physicalDevice</name></param>
            <param>const <type>VkDeviceCreateInfo</type>* <name>pCreateInfo</name></param>
            <param optional="true">const <type>VkAllocationCallbacks</type>* <name>pAllocator</name></param>
            <param><type>VkDevice</type>* <name>pDevice</name></param>
        </command>

比如这里的 VkAllocationCallbacks 是 optional 的,我们可以在对应的 binding 上面加 @nullable 注解,并且在 invoke 的时候检查 pAllocator != null ? pAllocator.segment() : MemorySegment.NULL。对于没有 optional 的情况则可以不检查。

CousinZe commented 5 days ago

Fixed by https://github.com/chuigda/vulkan4j/commit/71e776ff8165dc33135e7b5e7c3ad73e262a6f82