HardwareComputeDevice
Package: Libraries.Compute.Hardware · Inherits from: Libraries.Language.Object
The HardwareComputeDevice class is a graphics card that can run compute programs, whatever the graphics system underneath (Vulkan today, WebGPU on the web later). A program asks the system for one and makes its computations from it; it never needs to know which system it got. There is one per program, shared by every computation: the running game's device when a game is drawing with the same graphics system, or one with no window (headless), made the first time it is asked for and kept until the program ends. GameStateManager:GetComputeDevice returns it.
Example Code
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
use Libraries.Compute.Hardware.HardwareCompute
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device = undefined
output "This computer has no graphics card that can compute."
else
output "Computing with " + device:GetSystemName()
HardwareCompute compute = device:CreateCompute()
// SetProgram, SetData, Run, GetValues, then Dispose
compute:Dispose()
end
Actions
CreateCompute()
This action makes a computation on this device: a HardwareCompute with its own program, data and commands, ready for SetProgram. Dispose it when done; the device stays.
Returns
Libraries.Compute.Hardware.HardwareCompute: the new computation, or undefined if the device can't make one.
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
use Libraries.Compute.Hardware.HardwareCompute
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined
HardwareCompute compute = device:CreateCompute()
compute:Dispose()
end
DescribeLimits()
This action describes the device's limits in a line of text, for reports.
Returns
text: the description.
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined
output device:DescribeLimits()
end
GetLimits()
This action returns what the device allows: work group sizes, work groups per run, shared memory, data size, and 64-bit numbers.
Returns
Libraries.Compute.Hardware.HardwareComputeLimits: the limits.
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
use Libraries.Compute.Hardware.HardwareComputeLimits
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined
HardwareComputeLimits limits = device:GetLimits()
output limits:GetMaxWorkGroupThreads()
end
GetSystemName()
This action returns the name of the graphics system underneath.
Returns
text: the name, such as "Vulkan" or "WebGPU".
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined
output device:GetSystemName()
end
IsHeadless()
This action says whether the device is one of its own, with no window, rather than a running game's.
Returns
boolean: true if the device is headless.
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined and device:IsHeadless()
output "Computing without a game."
end
IsStarted()
This action says whether Start has succeeded.
Returns
boolean: true if the device is ready.
Example
use Libraries.Game.GameStateManager
use Libraries.Compute.Hardware.HardwareComputeDevice
GameStateManager manager
HardwareComputeDevice device = manager:GetComputeDevice()
if device not= undefined
output device:IsStarted()
end
Start()
This action finds the graphics card and makes the device, or shares a running game's. The system calls it before handing the device out (GameStateManager:GetComputeDevice); programs don't need to.
Returns
boolean: true if a graphics card can compute, false if there is none.
Example
use Libraries.Compute.Hardware.HardwareComputeDevice
use Libraries.Compute.Hardware.Vulkan.VulkanComputeDevice
VulkanComputeDevice vulkan
HardwareComputeDevice device = vulkan
if not device:Start()
output "No graphics card can compute with Vulkan."
end