1

stupid question, sorry

first question

void init_something(...){
    VkTypeSomething data[100];
    VkResourceStruct resource={... .pointer_data=data};
    VkCreateSomething(... , resource); //isit safe? resource[] is not lost?
}

void vk_clean(...){
    VkDestroySomething_that_use_resource(...);
    // free resource?
}

second question

same code, changes VkTypeSomething *data; and data=malloc(...); (no free in function)

when I need to free that data if I malloc it, and do I need to free it

Vulkan pages tell that "structures are destroyed on VkDestroy... call" and "VkDestroy... must have valid poiinters in structures on call" so there no way to free it before call (I know it can not work like this)

so there no way to get pointer inside structure that was created somewhere... do I need save all my created pointers and free them my self, after VkDestroy?

look like I understand, but still not sure as I understand its "VkCreate... use setup-data only once" and it safe to delete everything after call VkCreate... its true?

Danil S
  • 67
  • 7

1 Answers1

1

Vulkan handles are created by vkCreate*, and destroyed by vkDestroy*. They have nothing to do with any structures. I am not sure what your custom VkCreate* is or does, so that is outside of the scope of Vulkan.

You are the owner of all the structs. Generally, Vulkan only borrows them for the duration of a function call (Vulkan spec):

The ownership of application-owned memory is immediately acquired by any Vulkan command it is passed into. Ownership of such memory must be released back to the application at the end of the duration of the command, so that the application can alter or free this memory as soon as all the commands that acquired it have returned.

krOoze
  • 12,301
  • 1
  • 20
  • 34
  • "Vulkan only borrows them for the duration of a function call (Vulkan spec):" - that what I need to know, thanks – Danil S Feb 02 '20 at 16:01