Lluvia
ll::Session Class Reference

Class that contains all the state required to run compute operations on a compute device. More...

#include <Session.h>

Inheritance diagram for ll::Session:
Collaboration diagram for ll::Session:

Public Member Functions

 Session (const Session &session)=delete
 
 Session (Session &&session)=delete
 
 ~Session ()
 
Sessionoperator= (const Session &session)=delete
 
Sessionoperator= (Session &&session)=delete
 
std::shared_ptr< ll::MemorygetHostMemory () const noexcept
 Returns a pointer to ll::Memory object that is HOST_LOCAL and HOST_COHERENT. More...
 
std::shared_ptr< ll::MemorygetDeviceMemory () const noexcept
 Returns a pointer to ll::Memory object that is DEVICE_LOCAL. More...
 
vk::PhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties () const
 Gets the Lua interpreter. More...
 
std::vector< ll::MemoryPropertyFlagsgetSupportedMemoryFlags () const
 Gets the supported memory flags. More...
 
const ll::DeviceDescriptorgetDeviceDescriptor () const noexcept
 Gets the device descriptor associated to this session. More...
 
bool isImageDescriptorSupported (const ll::ImageDescriptor &descriptor) const noexcept
 Determines if parameters in image descriptor are supported for image creation. More...
 
std::shared_ptr< ll::MemorycreateMemory (const ll::MemoryPropertyFlags &flags, const uint64_t pageSize, bool exactFlagsMatch=false)
 Creates a memory. More...
 
std::unique_ptr< ll::CommandBuffercreateCommandBuffer () const
 Creates a command buffer. More...
 
std::unique_ptr< ll::DurationcreateDuration () const
 Creates a Duration object. More...
 
std::shared_ptr< ll::ProgramcreateProgram (const std::string &spirvPath) const
 Creates a program object reading a file at a given path. More...
 
std::shared_ptr< ll::ProgramcreateProgram (const std::vector< uint8_t > &spirv) const
 Creates a program providing the SPIR-V code directly. More...
 
void setProgram (const std::string &name, const std::shared_ptr< ll::Program > &program)
 Sets a program with a given name into the registry. More...
 
std::shared_ptr< ll::ProgramgetProgram (const std::string &name) const
 Gets a program given its name in the registry. More...
 
std::vector< ll::NodeBuilderDescriptorgetNodeBuilderDescriptors () const
 Gets the node builder descriptors currently registered. More...
 
std::shared_ptr< ll::ComputeNodecreateComputeNode (const ll::ComputeNodeDescriptor &descriptor)
 Creates a compute node. More...
 
std::shared_ptr< ll::ComputeNodecreateComputeNode (const std::string &builderName)
 Creates a compute node given its builder name. More...
 
ll::ComputeNodeDescriptor createComputeNodeDescriptor (const std::string &builderName) const
 Creates a compute node descriptor given its builder name. More...
 
std::shared_ptr< ll::ContainerNodecreateContainerNode (const ll::ContainerNodeDescriptor &descriptor)
 
std::shared_ptr< ll::ContainerNodecreateContainerNode (const std::string &builderName)
 
ll::ContainerNodeDescriptor createContainerNodeDescriptor (const std::string &builderName) const
 
void run (const ll::CommandBuffer &cmdBuffer)
 Runs a ll::CommandBuffer. More...
 
void run (const ll::ComputeNode &node)
 Runs a ll::ComputeNode. More...
 
void run (const ll::ContainerNode &node)
 Runs a ll::ContainerNode. More...
 
void script (const std::string &code)
 Runs Lua script code into the session's internal interpreter. More...
 
void scriptFile (const std::string &filename)
 Runs a Lua script file into the the session's internal interpreter. More...
 
void loadLibrary (const std::string &filename)
 Loads a library made of SPIR-V shader code and Lua scripts. More...
 
ll::vec3ui getGoodComputeLocalShape (ll::ComputeDimension dimensions) const noexcept
 Returns the suggested local grid shape for compute nodes given the number of dimensions. More...
 
std::string help (const std::string &builderName) const
 Returns the help string of a given node builder. More...
 
bool hasReceivedVulkanWarningMessages () const noexcept
 Tells whether or not this session has triggered Vulkan warning messages. More...
 

Static Public Member Functions

static std::vector< ll::DeviceDescriptorgetAvailableDevices ()
 Gets the available devices. More...
 
static std::vector< vk::LayerProperties > getVulkanInstanceLayerProperties ()
 Gets the Vulkan instance layer properties available to this machine. More...
 
static std::vector< vk::ExtensionProperties > getVulkanExtensionProperties ()
 Gets the Vulkan extension properties available to this machine. More...
 
static std::shared_ptr< ll::Sessioncreate ()
 Creates a new ll::Session object. More...
 
static std::shared_ptr< ll::Sessioncreate (const ll::SessionDescriptor &descriptor)
 Creates a new ll::Session object. More...
 

Detailed Description

Class that contains all the state required to run compute operations on a compute device.

Constructor & Destructor Documentation

◆ Session() [1/2]

ll::Session::Session ( const Session session)
delete

◆ Session() [2/2]

ll::Session::Session ( Session &&  session)
delete

◆ ~Session()

ll::Session::~Session ( )

Member Function Documentation

◆ create() [1/2]

static std::shared_ptr<ll::Session> ll::Session::create ( )
static

Creates a new ll::Session object.

Returns
A new session.
Exceptions
std::system_errorwith error code ll::ErrorCode::PhysicalDevicesNotFound if not physical devices are available.

◆ create() [2/2]

static std::shared_ptr<ll::Session> ll::Session::create ( const ll::SessionDescriptor descriptor)
static

Creates a new ll::Session object.

Parameters
[in]descriptorfor this session.
Returns
A new session.
Exceptions
std::system_errorwith error code ll::ErrorCode::PhysicalDevicesNotFound if not physical devices are available.

◆ createCommandBuffer()

std::unique_ptr<ll::CommandBuffer> ll::Session::createCommandBuffer ( ) const

Creates a command buffer.

Returns
A new ll::CommandBuffer object.

◆ createComputeNode() [1/2]

std::shared_ptr<ll::ComputeNode> ll::Session::createComputeNode ( const ll::ComputeNodeDescriptor descriptor)

Creates a compute node.

Parameters
[in]descriptorThe node's descriptor
Returns
A new ll::ComputeNode object.

◆ createComputeNode() [2/2]

std::shared_ptr<ll::ComputeNode> ll::Session::createComputeNode ( const std::string &  builderName)

Creates a compute node given its builder name.

Builders can be registered by running Lua scripts using ll::Session::script method.

Parameters
[in]builderNameThe builder name.
Returns
A new ll::ComputeNode object

◆ createComputeNodeDescriptor()

ll::ComputeNodeDescriptor ll::Session::createComputeNodeDescriptor ( const std::string &  builderName) const

Creates a compute node descriptor given its builder name.

Builders can be registered by running Lua scripts using ll::Session::script method.

Parameters
[in]builderNameThe builder name.
Returns
the ll::ComputeNodeDescriptor generated by the builder.

◆ createContainerNode() [1/2]

std::shared_ptr<ll::ContainerNode> ll::Session::createContainerNode ( const ll::ContainerNodeDescriptor descriptor)

◆ createContainerNode() [2/2]

std::shared_ptr<ll::ContainerNode> ll::Session::createContainerNode ( const std::string &  builderName)

◆ createContainerNodeDescriptor()

ll::ContainerNodeDescriptor ll::Session::createContainerNodeDescriptor ( const std::string &  builderName) const

◆ createDuration()

std::unique_ptr<ll::Duration> ll::Session::createDuration ( ) const

Creates a Duration object.

Returns
A new ll::Duration object.

◆ createMemory()

std::shared_ptr<ll::Memory> ll::Session::createMemory ( const ll::MemoryPropertyFlags flags,
const uint64_t  pageSize,
bool  exactFlagsMatch = false 
)

Creates a memory.

TODO Exceptions

Parameters
[in]flagsThe flags. It should be one of the values returned by ll::Session::getSupportedMemoryFlags().
[in]pageSizeThe page size. The size in bytes of each page the new memory object will allocate when there is no space for creating new objects.
[in]exactFlagsMatchThe exact flags match. Tells whether or not flags should match exactly one of the values in ll::Session::getSupportedMemoryFlags() or if it is enough that it contains at least the flags bits.
Returns
A new ll::Memory object or nullptr if it could not be created.
Exceptions
std::system_errorWith error code ll::ErrorCode::MemoryCreationError if no memory was found that matched the requested flags.

◆ createProgram() [1/2]

std::shared_ptr<ll::Program> ll::Session::createProgram ( const std::string &  spirvPath) const

Creates a program object reading a file at a given path.

TODO Exceptions

Parameters
[in]spirvPathThe path to the SPIR-V file containing the program code.
Returns
A new ll::Program object.
Exceptions
std::ios_base::failureif there is a problem reading the file at spirvPath.

◆ createProgram() [2/2]

std::shared_ptr<ll::Program> ll::Session::createProgram ( const std::vector< uint8_t > &  spirv) const

Creates a program providing the SPIR-V code directly.

TODO Exceptions

Parameters
[in]spirvThe SPIR-V code.
Returns
A new ll::Program object.
Exceptions
std::system_errorWith error code ll::ErrorCode::ProgramCompilationError if the supplied spirv code is empty.

◆ getAvailableDevices()

static std::vector<ll::DeviceDescriptor> ll::Session::getAvailableDevices ( )
static

Gets the available devices.

Returns
The avaiable devices.

◆ getDeviceDescriptor()

const ll::DeviceDescriptor& ll::Session::getDeviceDescriptor ( ) const
noexcept

Gets the device descriptor associated to this session.

Returns
The device descriptor

◆ getDeviceMemory()

std::shared_ptr<ll::Memory> ll::Session::getDeviceMemory ( ) const
noexcept

Returns a pointer to ll::Memory object that is DEVICE_LOCAL.

This memory can be used to create images and buffers that will be used in shaders. The page size is set to 0 in order to create independent memories for each object.

Returns
The device memory

◆ getGoodComputeLocalShape()

ll::vec3ui ll::Session::getGoodComputeLocalShape ( ll::ComputeDimension  dimensions) const
noexcept

Returns the suggested local grid shape for compute nodes given the number of dimensions.

The local shape depends on the underlying device.

◆ getHostMemory()

std::shared_ptr<ll::Memory> ll::Session::getHostMemory ( ) const
noexcept

Returns a pointer to ll::Memory object that is HOST_LOCAL and HOST_COHERENT.

This memory can be used to create uniform buffers to pass to shaders. The page size is set to 0 in order to create independent memories for each object allocated in this memory. This allows for each object to be mapped and stay mapped indefinitely, thus saving map/unmap operations.

Returns
The host memory.

◆ getNodeBuilderDescriptors()

std::vector<ll::NodeBuilderDescriptor> ll::Session::getNodeBuilderDescriptors ( ) const

Gets the node builder descriptors currently registered.

Returns
The node builder descriptors.

◆ getPhysicalDeviceMemoryProperties()

vk::PhysicalDeviceMemoryProperties ll::Session::getPhysicalDeviceMemoryProperties ( ) const

Gets the Lua interpreter.

Returns
The interpreter.

Gets the physical device memory properties for this session.

Returns
The physical device memory properties.

◆ getProgram()

std::shared_ptr<ll::Program> ll::Session::getProgram ( const std::string &  name) const

Gets a program given its name in the registry.

Parameters
[in]nameThe name.
Returns
The program.
See also
ll::Session::setProgram Sets a program with a given name into the registry.

◆ getSupportedMemoryFlags()

std::vector<ll::MemoryPropertyFlags> ll::Session::getSupportedMemoryFlags ( ) const

Gets the supported memory flags.

The length of the returned vector equals the number of Vulkan memory types available for the physical device this session was created from.

Returns
The supported memory flags.

◆ getVulkanExtensionProperties()

static std::vector<vk::ExtensionProperties> ll::Session::getVulkanExtensionProperties ( )
static

Gets the Vulkan extension properties available to this machine.

Returns
The Vulkan extension properties.

◆ getVulkanInstanceLayerProperties()

static std::vector<vk::LayerProperties> ll::Session::getVulkanInstanceLayerProperties ( )
static

Gets the Vulkan instance layer properties available to this machine.

Returns
The Vulkan instance layer properties.

◆ hasReceivedVulkanWarningMessages()

bool ll::Session::hasReceivedVulkanWarningMessages ( ) const
noexcept

Tells whether or not this session has triggered Vulkan warning messages.

For this method to return a correct value, the session must be created enabling debug.

Returns
Whether or not vulkan warning messages have been received.

◆ help()

std::string ll::Session::help ( const std::string &  builderName) const

Returns the help string of a given node builder.

Parameters
[in]builderNameThe builder name.
Returns
The help string of the builder.

◆ isImageDescriptorSupported()

bool ll::Session::isImageDescriptorSupported ( const ll::ImageDescriptor descriptor) const
noexcept

Determines if parameters in image descriptor are supported for image creation.

This method tests whether or not the combination of image shape, tiling and usage flags is supported by the physical device.

Parameters
[in]descriptorThe descriptor
Returns
True if image descriptor is supported, False otherwise.

◆ loadLibrary()

void ll::Session::loadLibrary ( const std::string &  filename)

Loads a library made of SPIR-V shader code and Lua scripts.

Parameters
[in]filenameThe path of the library file. It must be a valid zip archive.
Exceptions
std::system_errorWith error code ll::ErrorCode::IOError if there is some problem reading the library archive.

◆ operator=() [1/2]

Session& ll::Session::operator= ( const Session session)
delete

◆ operator=() [2/2]

Session& ll::Session::operator= ( Session &&  session)
delete

◆ run() [1/3]

void ll::Session::run ( const ll::CommandBuffer cmdBuffer)

Runs a ll::CommandBuffer.

This is a blocking call. The host thread will wait until execution of this command buffer is completed.

Parameters
[in]cmdBufferThe command buffer.

◆ run() [2/3]

void ll::Session::run ( const ll::ComputeNode node)

Runs a ll::ComputeNode.

Internally, this function creates a ll::CommandBuffer using ll::Session::createCommandBuffer, records the execution of the compute node and submits to the device.

Calling this function is equivalent to:

auto cmdBuffer = session->createCommandBuffer();
cmdBuffer->begin();
cmdBuffer->run(node);
cmdBuffer->end();
session->run(*cmdBuffer);
Parameters
[in]nodeThe node

◆ run() [3/3]

void ll::Session::run ( const ll::ContainerNode node)

Runs a ll::ContainerNode.

Internally, this function creates a ll::CommandBuffer using ll::Session::createCommandBuffer, records the execution of the container node and submits to the device.

Calling this function is equivalent to:

auto cmdBuffer = session->createCommandBuffer();
cmdBuffer->begin();
node.record(*cmdBuffer)
cmdBuffer->end();
session->run(*cmdBuffer);
Parameters
[in]nodeThe node

◆ script()

void ll::Session::script ( const std::string &  code)

Runs Lua script code into the session's internal interpreter.

Parameters
[in]codeThe Lua code

◆ scriptFile()

void ll::Session::scriptFile ( const std::string &  filename)

Runs a Lua script file into the the session's internal interpreter.

Parameters
[in]filenameThe filename.

◆ setProgram()

void ll::Session::setProgram ( const std::string &  name,
const std::shared_ptr< ll::Program > &  program 
)

Sets a program with a given name into the registry.

Parameters
[in]nameThe name
[in]programThe program
See also
ll::Session::getProgram Gets a program given its name in the registry.

The documentation for this class was generated from the following file: