VulkanComputeDevice
Package: Libraries.Compute.Hardware.Vulkan · Inherits from: Libraries.Compute.Hardware.HardwareComputeDevice, Libraries.Language.Object
The VulkanComputeDevice class is a HardwareComputeDevice that computes with Vulkan: the instance, graphics card, device and descriptor set manager every VulkanCompute made from it shares. Start looks at the game's graphics. If a game is drawing with Vulkan, the device shares its instance, device and descriptor sets, so results could later be used for drawing too. If no game is drawing with Vulkan (no game at all, or one using OpenGL), it makes its own instance and device with no window and no surface, asking only for compute. Either way there is one per program (GameStateManager:GetComputeDevice), and it is never released: a device lives as long as the program, as a game's does. Shaders are compiled, and their modules freed, by the library's VulkanShaderManager with this device (CompileShader and DisposeShader take the device), so a headless device needs no game graphics.
Example Code
use Libraries.Compute.Hardware.HardwareComputeDevice
use Libraries.Compute.Hardware.HardwareCompute
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
VulkanComputeDevice vulkan
HardwareComputeDevice device = vulkan
if device:Start()
HardwareCompute compute = device:CreateCompute()
compute:Dispose()
end
Actions
Compile(Libraries.Compute.Hardware.Vulkan.VulkanComputeShader shader)
This action compiles a compute shader for this device: GLSL to SPIR-V and the device's shader module. VulkanCompute calls it.
Parameters
shaderLibraries.Compute.Hardware.Vulkan.VulkanComputeShader: the shader, named and with its source set.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Compute.Hardware.Vulkan.VulkanComputeShader
VulkanComputeDevice device
if device:Start()
VulkanComputeShader shader
shader:SetName("Empty")
shader:SetCode("#version 450
layout (local_size_x = 1) in;
void main() {}
")
device:Compile(shader)
end
CreateCompute()
This action makes a VulkanCompute on this device, with its own queue, command pool, command buffer, program and data.
Returns
Libraries.Compute.Hardware.HardwareCompute: the new computation, or undefined if no queue on this device can compute.
Example
See the same action in HardwareComputeDevice.
GetDescriptorSetManager()
This action returns the descriptor set manager computations make their descriptor sets with.
Returns
Libraries.Game.Graphics.Vulkan.VulkanDescriptorSetManager: the manager, or undefined before Start.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Game.Graphics.Vulkan.VulkanDescriptorSetManager
VulkanComputeDevice computeDevice
VulkanDescriptorSetManager manager = computeDevice:GetDescriptorSetManager()
GetDevice()
This action returns the Vulkan device.
Returns
Libraries.Game.Graphics.Vulkan.VulkanDevice: the device, or undefined before Start.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Game.Graphics.Vulkan.VulkanDevice
VulkanComputeDevice computeDevice
VulkanDevice device = computeDevice:GetDevice()
GetInstance()
This action returns the Vulkan instance.
Returns
Libraries.Game.Graphics.Vulkan.VulkanInstance: the instance, or undefined before Start.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Game.Graphics.Vulkan.VulkanInstance
VulkanComputeDevice computeDevice
VulkanInstance vulkanInstance = computeDevice:GetInstance()
GetLimits()
This action returns the graphics card's limits for compute, read from Vulkan's limits and features once and kept.
Returns
Libraries.Compute.Hardware.HardwareComputeLimits: the limits, or undefined before Start.
Example
See the same action in HardwareComputeDevice.
GetPhysicalDevice()
This action returns the Vulkan graphics card.
Returns
Libraries.Game.Graphics.Vulkan.VulkanPhysicalDevice: the physical device, or undefined before Start.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Game.Graphics.Vulkan.VulkanPhysicalDevice
VulkanComputeDevice computeDevice
VulkanPhysicalDevice card = computeDevice:GetPhysicalDevice()
GetSystemName()
This action returns the name of this graphics system.
Returns
text: "Vulkan".
Example
See the same action in HardwareComputeDevice.
IsHeadless()
This action says whether this device made its own instance and device, with no window, rather than sharing a Vulkan game's.
Returns
boolean: true if the device is headless.
Example
See the same action in HardwareComputeDevice.
IsStarted()
This action says whether Start has succeeded.
Returns
boolean: true if the device is ready.
Example
See the same action in HardwareComputeDevice.
ReleaseShader(Libraries.Compute.Hardware.Vulkan.VulkanComputeShader shader)
This action frees a compute shader's module on this device, once nothing still uses it. Pipelines made with it keep working. VulkanCompute calls it.
Parameters
shaderLibraries.Compute.Hardware.Vulkan.VulkanComputeShader: a shader compiled with Compile.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Compute.Hardware.Vulkan.VulkanComputeShader
VulkanComputeDevice device
if device:Start()
VulkanComputeShader shader
shader:SetName("Empty")
shader:SetCode("#version 450
layout (local_size_x = 1) in;
void main() {}
")
device:Compile(shader)
device:ReleaseShader(shader)
end
Share(Libraries.Game.Graphics.Vulkan.VulkanGraphics graphics)
This action starts the device as a share of a game's Vulkan graphics: its instance, graphics card, device and descriptor sets. VulkanGraphics calls it when it has finished starting, and gives the result to GameStateManager:SetComputeDevice, so computations use the game's device from then on.
Parameters
graphicsLibraries.Game.Graphics.Vulkan.VulkanGraphics: the game's graphics, initialized.
Returns
boolean: true if the graphics were initialized and are now shared, false if not.
Example
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
use Libraries.Game.GameStateManager
use Libraries.Game.Graphics.Vulkan.VulkanGraphics
GameStateManager manager
VulkanGraphics graphics = cast(VulkanGraphics, manager:GetGameGraphics())
VulkanComputeDevice device
if device:Share(graphics)
manager:SetComputeDevice(device)
end
Start()
This action finds the graphics card: shares a Vulkan game's device, or makes an instance and device of its own with no window. Calling it again once it has started does nothing.
Returns
boolean: true if a graphics card can compute with Vulkan, false if there is none.
Example
See the same action in HardwareComputeDevice.