9

In OpenGL we need a device per thread in order to do several actions in parallel.

In Vulkan, we can use queue and command pool per thread in order to do several actions in parallel - but they are all can be created from one logical device.

So when do we need more than one Logical Device , if we have only one physical device ?

audi02
  • 559
  • 1
  • 4
  • 16

1 Answers1

10

The concept of a logical device needs to be distinct from a physical device, because you need to be able to register extensions, features, queue counts, and other initialization-time constructs. You need to be able to ask what the physical device's capabilities are, then you need to be able to construct a thing that uses a specified subset of them.

Given that the separation is useful... why bother adding an arbitrary restriction that says that a single application can only create a single VkDevice from a single VkPhysicalDevice?

After all, the physical device already needs to be able to service multiple applications. Each application needs to be able to allocate GPU resources, and those resources need to be distinct from one another. They all have to be able to execute commands in parallel which do not interfere with each other (besides taking up computational resources). So the implementation already has to be able to serve many masters, including the OS.

So there is no reason why an implementation couldn't allow a single application to have multiple interfaces to that implementation. So it's not a question of "need". Implementations already de facto have to be able to do it, so it's hardly a burden to force them to do the thing they already have to do.

However, if you want an example of where it might be useful, consider a program that has a DLL/SO-based plugin architecture. The program uses Vulkan for some purpose. But one of the plugins might also want to use Vulkan for some purpose. They're both part of the same process, but since they're not trying to render into each others' surfaces, they don't need to speak to each other or know that the other VkDevice even exists.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 1
    Yup. As another example where this is definitely needed, an app on Android might do it's own Vulkan rendering into a SurfaceView for a 3D scene, but also use the UI Toolkit for some things. If the UI Toolkit internally uses Vulkan (as an implementation detail), they would each need their own logical device. This happens today with OpenGL ES: app and UI Toolkit have separate GL contexts not because of different threads, but because they're independent clients. – Jesse Hall Jun 04 '19 at 01:18
  • 1
    Maybe the OP was edited, but this answer is confusing to me from an english perspective. OP talks about when you would need **multiple** logical devices. This answer starts off talking as if you can only have **one** logical device, then talks about why this restriction doesn't come out of need, [despite this restriction not existing](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VkDevice). That doesn't appear to address OPs question at all. Then it appears to talk about how this *restriction* is useful? Could you please clear up the language in this answer? – Krupip Jun 05 '19 at 13:40
  • @opa: "*This answer starts off talking as if you can only have one logical device*" Where does it say or imply that? Yes, it starts talking about the relationship between a logical device and a physical device, but I don't see how that is even an implied declaration that there must be a 1:1 relationship between them. I'm talking about the *distinction* between the two. – Nicol Bolas Jun 05 '19 at 13:43
  • 1
    Your sentence : `"Given that the separation is useful... why bother adding an arbitrary restriction that says that a single application can only create a single VkDevice from a single VkPhysicalDevice?"` Comes off as a rhetorical question that would perhaps be explained by the rest of your post. I now suspect you are literally asking OP why one would want an arbitrary restriction. The issue is that if I don't assume you are being snarky, this comes off as a rhetorical, but if I assume you are it doesn't. Regardless, I think your answer would be better served if you were more direct here. – Krupip Jun 05 '19 at 14:06
  • 1
    @NicolBolas Use of "after all" fits perfectly with rhetorical question, and then it's garden pathed with "However" in the last paragraph. Content is great, the way in which it was stated is confusing, at least to me. The answer should probably be ordered in such a way that it stands alone. For example your first paragraph does not directly address the question until you read the second paragraph, it should answer from the start ie: GPUs can already do this, so there is no need to restrict the feature, and it is useful for dynamic libraries which don't need to know about other devices etc. – Krupip Jun 05 '19 at 14:15
  • @opa: I'm still not sure I understand the issue. The question very much is rhetorical. The question is a rhetorical device, posted for the purpose of deconstruction. That's what a rhetorical question is *for*. The question itself doesn't say that there is such a restriction; that restriction is what the OP is asking for/expecting. The rhetorical question is there to clarify the OP's question so that it can be deconstructed. That is, the main reason you can have multiple logical devices is... because there's no reason to *forbid it*. – Nicol Bolas Jun 05 '19 at 14:45