This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

UUSL Compute Shaders

UUSL supports compute shaders: there are special functions, semantics and parameters for compute shaders.

In UNIGINE, compute shaders have a *.comp extension.

A compute shader is a special part of the graphics pipeline. It allows to execute code on the GPU, read and write buffer data.

Prior Knowledge
This article assumes you have prior knowledge of the compute shaders. Also, read the following topics on UUSL before proceeding:

Main Function#

To start and end the void Main function of the compute shader, use the following instructions:

UUSL
#include <core/materials/shaders/render/common.h>

MAIN_COMPUTE_BEGIN(WIDTH_GROUP,HEIGHT_GROUP)
	<your code here>
MAIN_COMPUTE_END

This code is equivalent to:

OpenGL
#include <core/materials/shaders/render/common.h>

layout (local_size_x = WIDTH_GROUP, local_size_y = HEIGHT_GROUP) in;
void main() {
	<your code here>
}
Direct3D
#include <core/materials/shaders/render/common.h>

[numthreads(WIDTH_GROUP, HEIGHT_GROUP, 1)]
void main(DISPATCH_INFO dispatch_info) {
	<your code here>
}

Semantics#

UUSL OpenGL Direct3D Description
GROUP_ID gl_WorkGroupID SV_GroupID Contains the index of the workgroup currently being operated on by a compute shader
GROUP_THREAD_ID gl_LocalInvocationID SV_GroupThreadID Contains the index of work item currently being operated on by a compute shader
DISPATCH_THREAD_ID gl_GlobalInvocationID SV_DispatchThreadID Contains the global index of work item currently being operated on by a compute shader
GROUP_INDEX gl_LocalInvocationIndex SV_GroupIndex Contains the local linear index of work item currently being operated on by a compute shader

Keywords#

UUSL OpenGL Direct3D Description
SHARED shared groupshared Mark a variable for thread-group-shared memory for compute shaders
MEMORY_BARRIER_SHARED memoryBarrierShared() GroupMemoryBarrier() Blocks execution of all threads in a group until all group shared accesses have been completed
MEMORY_BARRIER_SHARED_SYNC memoryBarrierShared() barrier() GroupMemoryBarrierWithGroupSync() Blocks execution of all threads in a group until all group shared accesses have been completed and all threads in the group have reached this call
Last update: 2023-11-30
Build: ()