Vulkan Cookbook 第一章 17 获取设备队列

获取设备队列

译者注:示例代码点击此处

在Vulkan中,为了利用给定设备的处理能力,需要向设备的队列提交操作。 队列不是由应用程序显式创建的。 在设备创建期间请求它们:检查可用的族和每个族包含的队列数。 我们只能询问现有队列族中可用队列,并且我们不能请求比给定族暴露更多的队列。
请求的队列与逻辑设备一起自动创建。 我们不管理和创建它们。 也不能摧毁它们,它们会随逻辑设备一起销毁。 要使用它们并能够将工作提交到设备的队列,只需要获取它们的句柄即可。

怎么做...

1.获取已创建的逻辑设备对象句柄。将其储存在名为logical_deviceVkDevice类型变量中。
2.在逻辑设备创建期间在VkDeviceQueueCreateInfo类型的结构的queueFamilyIndex成员中获取其中一个队列族的索引。将其存储在名为queue_family_indexuint32_t类型的变量中。
3.获取给定队列族中一个队列的索引:索引必须小于VkDeviceQueueCreateInfo结构的queueCount成员中给定族请求的队列总数。将索引储存在名为queue_indexuint32_t类型的变量中。
4.准备名为queueVkQueue类型变量。
5.调用vkGetDeviceQueue( logical_device, queue_family_index, queue_index, &queue )。第一个参数提供逻辑设备,第二个参数必须是所选队列族索引,第三个参数必须是第二个参数队列族中一个请求过的队列索引,然后在最后一个参数中提供指向队列变量的指针,设备队列的句柄将储存在此变量中。
6.对从其他队列族获取队列重复步骤2到5。

这个怎么运作...

获取给定队列句柄的代码非常简单:

vkGetDeviceQueue( logical_device, queue_family_index, queue_index, &queue );

提供句柄逻辑设备,队列族的索引以及其中队列的索引。我们必须提供逻辑设备创建期间提供的族索引之一,这意味着我们无法从逻辑设备创建期间未指定的族获取队列句柄。同样,我们只能提供一个队列索引,该索引小于给定族请求的队列总数。

让我们想象一下下面的情况:给定的物理设备支持的队列族3中的五个队列。在逻辑设备创建期间,我们只请求来自这个队列族3的两个队列。因此在这里当我们调用vkGetDeviceQueue()函数时,必须将值3作为队列族索引,对于队列索引,只能提供值0和1。

请求的队列的句柄储存在一个变量中,我们在vkGetDeviceQueue()函数最后参数中提供指向该变量的指针。可以多次请求同一队列的句柄(尽管这样做可能没有多大意义)。此调用不创建队列(他们是在创建逻辑设备期间隐式创建的)。

Computer graphics have a very long and interesting history. Many APIs or custom approaches to the generation of 2D or 3D images have come and gone. A landmark in this history was the invention of OpenGL, one of the first graphics libraries, which allowed us to create real-time, high-performance 3D graphics, and which was available for everyone on multiple operating systems. It is still developed and widely used even today. And this year we can celebrate its 25th birthday! But many things have changed since OpenGL was created. The graphics hardware industry is evolving very quickly. And recently, to accommodate these changes, a new approach to 3D graphics rendering was presented. It took the form of a low-level access to the graphics hardware. OpenGL was designed as a high-level API, which allows users to easily render images on screen. But this high-level approach, convenient for users, is difficult for graphics drivers to handle. This is one of the main reasons for restricting the hardware to show its full potential. The new approach tries to overcome these struggles–it gives users much more control over the hardware, but also many more responsibilities. This way application developers can release the full potential of the graphics hardware, because the drivers no longer block them. Low-level access allows drivers to be much smaller, much thinner. But these benefits come at the expense of much more work that needs to done by the developers. The first evangelist of the new approach to graphics rendering was a Mantle API designed by AMD. When it proved that low-level access can give considerable performance benefits, other companies started working on their own graphics libraries. One of the most notable representatives of the new trend were Metal API, designed by Apple, and DirectX 12, developed by Microsoft. But all of the above libraries were developed with specific operating systems and/or hardware in mind. There was no open and multiplatform standard such as OpenGL. Until last year. Year 2016 saw the release of the Vulkan API, developed by Khronos consortium, which maintains the OpenGL library. Vulkan also represents the new approach, a low-level access to the graphics hardware, but unlike the other libraries it is available for everyone on multiple operating systems and hardware platforms–from high-performance desktop computers with Windows or Linux operating systems, to mobile devices with Android OS. And as it is still being very new, there are few resources teaching developers how to use it. This book tries to fill this gap.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值