Closed sunbearc22 closed 7 years ago
Hello @sunbearc22.
Take a look at this part of the README: https://github.com/realitix/vulkan#functions
The wrapper handles VkResult for you. If VkResult is not VK_SUCCESS, an exception is raised. So in your example, If you want to be sure that the function is OK:
try:
instance = vkCreateInstance(
pCreateInfo = inst_Info,
pAllocator = None)#,
#pInstance = inst)
except VkError:
print('error')
Here the magic of this wrapper, functions will return what you wait for. Don't forget something, in Python, there is no pointer like in C. When you pass pInstance
to the function, in the base Vulkan API, it's a pointer which is filled by the driver. You can't do that in pure Python. With CFFI, you can, and the wrapper does that for you. You don't have to know CFFI to use this wrapper, that's my rule.
When you call vkCreateInstance
, you don't pass pInstance
, you receive it. If the Vulkan function returns several elements, you will get a list
. It's what I do in the exemple.py
file.
Is this answer enough for you or do you need more informations ?
Don't forget that I am on IRC, we can speak faster by chatting
Thanks. I understood Ans 1. My bad for forgetting you wrote that in Readme. I was just about to reply with the same answer. I think it will be helpful to include your answer 1 as an example to Readme too. Just a suggestion.
For Ans 2, is there another example you can give?
Just tried IRC ##vulkan but you are offline. I am sunbearc22.
How do i see the next level of error message under VkError
?
VK_ERROR_OUT_OF_{HOST, DEVICE}_MEMORY
VK_ERROR_{INITIALIZATION, MEMORY_MAP}_FAILED
VK_ERROR_DEVICE_LOST
VK_ERROR_{EXTENSION, FEATURE, LAYER}_NOT_PRESENT
VK_ERROR_INCOMPATIBLE_DRIVER
VK_ERROR_TOO_MANY_OBJECTS
VK_ERROR_FORMAT_NOT_SUPPORTED
VK_ERROR_SURFACE_LOST_KHR
VK_ERROR_OUT_OF_DATE_KHR
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
VK_ERROR_VALIDATION_FAILED_EXT
Is this correct?
try:
instance = vkCreateInstance(
pCreateInfo = inst_Info,
pAllocator = None)#,
#pInstance = inst)
except VkError:
print('error')
if VkError == VK_ERROR_INCOMPATIBLE_DRIVER:
print("cannot find a compatible Vulkan ICD")
Sorry I was offline.
For answer 2, I can point you different example in the example.py
file:
Return an object:
https://github.com/realitix/vulkan/blob/master/example/example.py#L18 https://github.com/realitix/vulkan/blob/master/example/example.py#L45 https://github.com/realitix/vulkan/blob/master/example/example.py#L200
Return a list:
https://github.com/realitix/vulkan/blob/master/example/example.py#L26 https://github.com/realitix/vulkan/blob/master/example/example.py#L30 https://github.com/realitix/vulkan/blob/master/example/example.py#L137
Return nothing:
https://github.com/realitix/vulkan/blob/master/example/example.py#L684
You can easily know if a function will return a list or an object, for example, if you look at vkCreateInstance
documentation here, the last parameter is indicated as
pInstance
points a VkInstance
handle in which the resulting instance is returned.
It's clear it will return an object.
For vkEnumerateInstanceExtensionProperties
here:
pProperties is either NULL or a pointer to an array of VkExtensionProperties structures.
It's clear it will return a list
. Moreover, you don't have to bother with pPropertyCount
, the wrapper do it for you. It's why you only pass the first parameter pLayerName
(None
in example.py
)
Is it ok now or do you need more informations ?
For the last question:
You must do:
try:
instance = vkCreateInstance(
pCreateInfo = inst_Info,
pAllocator = None)
except VkErrorIncompatibleDriver:
print("cannot find a compatible Vulkan ICD")
except VkError:
print('error')
Thanks for the Ans 2 elaboration. Helpful.
Can you clarify if my Exception code is correct for my question on Ans 1? I submitted the code with not python error but not sure if it is correct.
I have just answered above.
Sorry. Screen did not refresh so did not see your answer. So what is the purpose of VkError & VkException given that their subsets may be called directly?
It's a classic Python pattern. The goal of the parent exception is to catch all others errors. I mean, errors that you don't care. For example, you could want to react if there is an error (and you don't need to know the exact error)... In well written Python script, you will always find this patter, a precise exception that extend a global exception. It gives you much freedom.
Got it.
Can I close this issue ?
yep. Thanks.
You're welcome !
Error message:
Question 1: How do I call "VkResult" in your wrapper? VkResult is use to return the state of Vulkan function. I noticed your example.py code, VkResult is not used. How can I report the state of a Vulkan function in vulkan?
Question 2: In the definition of
instance
usingvkCreateInstance
, what do I give topInstance
? My confusion here isinstance
is created so what is the purpose ofpInstance
. I triedinst = VkInstance()
but got error messageNameError: name 'VkInstance' is not defined
. At the moment, I commented it out to avoid error.