Session

class lluvia.core.Session
compileComputeNode(self, ports, shaderCode, functionName='main', builderName='', localSize=1, 1, 1, gridSize=1, 1, 1, includeDirs=None, compileFlags=['-Werror'])

Compiles a ComputeNode from GLSL shader code.

This method assumes that glslc command is avialable in the system.

Parameters
  • ports (list of PortDescriptor.) – List of port descriptors the compute node receives.

  • shaderCode (file or str.) –

    If file, it must contain the GLSL code of the shader to compile. The file is not closed during the execution of this method.

    If str, it must be valid GLSL code. A temporal file is created and its path is passed to glslc for compilation.

  • functionName (str. Defaults to 'main'.) – Function name whitin the shader the compute node will execute.

  • builderName (str. Defaults to '' (empty string)) – Builder name associated to this node.

  • localSize (list or tuple of length 3. Defaults to (1, 1, 1)) – Local group size for each XYZ dimension. Each value must be greater or equal to 1.

  • gridSize (list or tuple of length 3. Defaults to (1, 1, 1)) – Grid size for each XYZ dimension. The grid size defines the number of local groups in each dimension. Each value must be greater or equal to 1.

  • includeDirs (list of strings. Defaults to None.) – List of include directories to pass to glslc through -I flag.

  • compileFlags (list of strings. Defaults to ['-Werror']) – Extra compile flags to pass to glslc.

Returns

node – Compiled node.

Return type

lluvia.ComputeNode.

:raises RuntimeError : if the compilation fails.:

See also

compileProgram()

Compiles a Program from GLSL shader code.

compileProgram(self, shaderCode, includeDirs=None, compileFlags=['-Werror'])

Compiles a Program from GLSL shader code.

This method assumes that glslc command is avialable in the system.

Parameters
  • shaderCode (file or str.) –

    If file, it must contain the GLSL code of the shader to compile. The file is not closed during the execution of this method.

    If str, it must be valid GLSL code. A temporal file is created and its path is passed to glslc for compilation.

  • includeDirs (list of strings. Defaults to None.) – List of include directories to pass to glslc through -I flag.

  • compileFlags (list of strings. Defaults to ['-Werror']) – Extra compile flags to pass to glslc.

Returns

program – Compiled program.

Return type

lluvia.Program.

:raises RuntimeError : if the compilation fails.:

createCommandBuffer(self)

Creates a command buffer object.

Command buffers are used to record commands to be executed by the device. Once the recording finishes, the command buffer can be sent for execution using the run method.

:raises RuntimeError : if the command buffer cannot be created.:

createComputeNode(self, desc)

Creates a ComputeNode from a given descriptor or builder name.

Parameters

desc (string or lluvia.ComputeNodeDescriptor) – If string, denotes the builder name used to create the ComputeNodeDescriptor for this node. Otherwise, a valid lluvia.ComputeNodeDescriptor must be provided.

Returns

node

Return type

lluvia.ComputeNode

:raises RuntimeError : if desc is a string and the node builder is not found in the registry.: :raises ValueError : if desc type is not string nor ComputeNodeDescriptor.:

createComputeNodeDescriptor(self, unicode builderName)

Creates a ComputeNodeDescriptor from its name in the registry.

Parameters

builderName (string.) – Name of the builder.

Returns

desc – The descriptor

Return type

lluvia.ComputeNodeDescriptor.

:raises RuntimeError : if builderName is not in the registry.:

createContainerNode(self, desc)

Creates a ComputeNode from a given descriptor or builder name.

Parameters

desc (string or lluvia.ContainerNodeDescriptor) – If string, denotes the builder name used to create the ContainerNodeDescriptor for this node. Otherwise, a valid lluvia.ContainerNodeDescriptor must be provided.

Returns

node

Return type

lluvia.ComputeNode

:raises RuntimeError : if desc is a string and the node builder is not found in the registry.: :raises ValueError : if desc type is not string nor ContainerNodeDescriptor.:

createContainerNodeDescriptor(self, unicode builderName)

Creates a ContainerNodeDescriptor from its name in the registry.

Parameters

builderName (string.) – Name of the builder.

Returns

desc – The descriptor

Return type

lluvia.ContainerNodeDescriptor.

:raises RuntimeError : if builderName is not in the registry.:

createDuration(self)

Creates a Duration object.

Returns

d – A new Duration object.

Return type

ll.Duration.

createMemory(self, flags=MemoryPropertyFlagBits.DeviceLocal, uint64_t pageSize=33554432, bool exactFlagsMatch=False)

Creates a new memory.

```

import lluvia as ll

session = ll.createSession() memory = session.createMemory([ll.MemoryPropertyFlagBits.HostVisible,

ll.MemoryPropertyFlagBits.HostCoherent],

4096, False)

```

The flags parameter can contain one string or a list of strings specifying the memory property flags the new memory will be created with. The possible values are defined in lluvia.MemoryPropertyFlagBits:

  • DeviceLocal

  • HostCached

  • HostCoherent

  • HostVisible

  • LazilyAllocated

See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryPropertyFlagBits for more information.

Parameters
  • flags (string or list of strings. Defaults to 'DeviceLocal') – Flags to determine the type of memory to be created. Each flag should be one of the strings in lluvia.MemoryPropertyFlags.

  • pageSize (uint64_t. Defaults to 32MB (33554432L)) – The size in bytes of each page the new memory object will allocate when there is no space for creating new objects.

  • exactFlagsMatch (bool defaults to False.) – Tells whether or not flags should match exactly one of the values in lluvia.Session.getSupportedMemoryFlags() or if it is enough that it contains at least the flags values.

Returns

memory

Return type

a new lluvia.Memory object.

See also

getSupportedMemoryPropertyFlags()

Returns the supported memory property flags for creating memories in this session.

createProgram(self, unicode path)

Creates a Program object reading the SPIR-V code from a given file.

Parameters

path (string) – path to the file where the SPIR-V code is stored.

Returns

program

Return type

lluvia.Program

:raises IOError : if there is any problem reading the file at the given path.:

getHostMemory(self)

Returns a memory object that is HOST_LOCAL and HOST_COHERENT. This memory can be used to create uniform buffers to pass to shaders.

Returns

mem

Return type

ll.Memory

getProgram(self, unicode name)

Returns a program from the registry

Parameters

name (string.) – Name of the program.

Returns

program – The program.

Return type

lluvia.Program

:raises KeyError : if the program does not exists in the registry:

getSupportedMemoryPropertyFlags(self)

Returns the supported memory property flags for creating memories in this session.

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

See https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VkMemoryPropertyFlagBits for more information.

Returns

supportedMemoryFlags – The supported memory property flags combinations supported by this session.

Return type

list of string lists

run(self, obj)

Runs a CommandBuffer or ComputeNode

Parameters

obj (CommandBuffer or ComputeNode) –

script(self, unicode code)

Runs a Lua script in the session’s interpreter

Parameters

code (string) – The Lua code.

scriptFile(self, unicode filename)

Read and run a Lua script file in the session’s interpreter

Parameters

code (string) – Path to the script file.

setProgram(self, unicode name, program)

Sets a program into the registry with a given name

Parameters
  • name (string) – The name of the program in the registry.

  • program (string or lluvia.Program.) – If string, this parameter denotes a path to a SPIR-V file used to build the program. This is equivalent to call session.setProgram(name, session.createProgram(program))

Raises

ValueError – if program’s type is not string nor lluvia.Program: