Giter Club home page Giter Club logo

Comments (15)

realitix avatar realitix commented on May 22, 2024

Hello @sunbearc22.

Take a look at this part of the README: https://github.com/realitix/vulkan#functions

1

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')

2

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 ?

from vulkan.

realitix avatar realitix commented on May 22, 2024

Don't forget that I am on IRC, we can speak faster by chatting

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

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?

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

Just tried IRC ##vulkan but you are offline. I am sunbearc22.

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

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")

from vulkan.

realitix avatar realitix commented on May 22, 2024

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 ?

from vulkan.

realitix avatar realitix commented on May 22, 2024

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')

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

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.

from vulkan.

realitix avatar realitix commented on May 22, 2024

I have just answered above.

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

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?

from vulkan.

realitix avatar realitix commented on May 22, 2024

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.

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

Got it.

from vulkan.

realitix avatar realitix commented on May 22, 2024

Can I close this issue ?

from vulkan.

sunbearc22 avatar sunbearc22 commented on May 22, 2024

yep. Thanks.

from vulkan.

realitix avatar realitix commented on May 22, 2024

You're welcome !

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.