This page has been translated automatically.
Видеоуроки
Interface
Essentials
Advanced
Полезные советы
Программирование на C#
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Настройки и предпочтения
Работа с проектами
Настройка параметров узла
Setting Up Materials
Setting Up Properties
Освещение
Landscape Tool
Sandworm (Experimental)
Использование инструментов редактора для конкретных задач
Extending Editor Functionality
Встроенные объекты
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Программирование
Основы
Настройка среды разработки
Примеры использования
UnigineScript
C++
C#
Унифицированный язык шейдеров UUSL
File Formats
Rebuilding the Engine Tools
GUI
Двойная точность координат
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
Работа с контентом
Оптимизация контента
Материалы
Art Samples
Tutorials
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Unigine::CPUShader Class

Header: #include <UnigineThread.h>

This class is used to create a custom CPU shader, for example, to implement multi-threaded mesh cluster update. Your custom CPU-shader must be inherited from this class. The corresponding sample is included in the SDK(/samples/Api/Systems/CPUShader/). Engine::swap() always waits for CPU shaders, therefore they cannot be used as tasks. CPU shader is updated with the current framerate of the application.

Here is an example of implementing a custom CPU shader:

Source code (C++)
struct UpdateClustersCPUShader: public CPUShader
{
	UpdateClustersCPUShader() {}
	virtual ~UpdateClustersCPUShader() 
	{ 
		// wait until all asynchronous operations are completed
		wait(); 
	}

	Vector<AsyncCluster> clusters;

	volatile int counter{0};
	
	// overriding the process method to performa our calculations
	void process(int thread_num, int threads_count) override
	{
		UNIGINE_PROFILER_FUNCTION;

		while (true)
		{
			int num = AtomicAdd(&counter, 1);
			if (num >= clusters.size())
				break;
			clusters[num].update();
		}
	}

	void run()
	{
		for (auto &c : clusters)
			c.swap();

		counter = 0;
		
		// running shader code in asynchronous mode
		runAsync();
	}
};

CPUShader Class

Members


static CPUShaderPtr create ( ) #

Default CPUShader class constructor.

void runSync ( int threads_count ) #

Runs CPU shader code synchronously. This method is blocking. No additional threads are created, as the Engine's thread pool is used.

Arguments

  • int threads_count - Number of threads to be used. The default value of -1 sets the number of threads equal to the number of CPU cores.

void runAsync ( int threads_count ) #

Runs CPU shader code asynchronously. This method is non-blocking. No additional threads are created, as the Engine's thread pool is used.

Arguments

  • int threads_count - Number of threads to be used. The default value of -1 sets the number of threads equal to the number of CPU cores.

void wait ( ) #

Waits for running asynchronous shader code execution.

int isRunning ( ) #

Returns a value indicating if the CPU shader code is currently executed.

Return value

1 if the shader code is currently executed; otherwise, 0.

int getNumThreads ( ) #

Returns the currently used number of threads.

Return value

Number of currently used threads.

virtual void process ( int thread_num, int threads_count ) #

Override this method to implement calculations.

Arguments

  • int thread_num - Current thread number. This number is not a thread ID, it just a virtual number.
  • int threads_count - Number of threads to be used. The default value of -1 sets the number of threads equal to the number of CPU cores.
Last update: 24.11.2020
Build: ()