UsdOptimizeCore#

Fully qualified name: usd_optimize::UsdOptimizeCore

class UsdOptimizeCore#

Usd Optimize Plugin Manager.

This class is a singleton that allows plugins to register themselves with usd optimize.

Public Functions

bool isInitialized() const#

Returns whether the core has been initialised yet - aka loadPlugins has been called.

std::vector<std::string> getOperations() const#

Get all registered operations.

OperationUPtr getOperation(const std::string &name) const#

Find the specified operation.

void registerOperation(
UsdOptimizeOperationCreate creation,
UsdOptimizeOperationDestroy destruction,
)#

Register an operation.

void deregisterOperation(const std::string &name)#

Deregister an operation.

void loadPlugin(const std::string &pluginPath)#

Load a plugin from a library path.

void loadPluginsFromPath(const std::string &path)#

Loads plugins contained in a directory.

void loadPlugins()#

Load the plugins that ship usd optimize and from any paths defined in the USD_OPTIMIZE_PLUGIN_PATH environment variable.

PXR_NS::JsObject mapOperation(
const std::string &name,
const PXR_NS::JsObject &config,
) const#

Map the arguments of an individual operation to deal with renamed args.

PXR_NS::JsArray mapConfig(const PXR_NS::JsArray &config) const#

Map a full JSON config - all operation names and arguments.

void registerShutdownCallback(std::function<void()> callback)#

Register a callback to be invoked at process shutdown, before C++ static destructors run. Use this for cleanup that must occur while external runtimes (CUDA, etc.) are still alive — releasing GPU buffers from a static destructor risks the driver having torn down first, which throws from inside the destructor and terminates the process.

The Python binding wires a single Py_AtExit to runShutdownCallbacks(), so when the library is loaded as a Python module the queue drains automatically during Py_Finalize (before any C++ exit-time teardown begins). std::atexit is not a reliable hook for this — it interleaves LIFO with the CUDA driver’s own atexit registration, which can cause our callback to run after CUDA has already torn down.

Note

Non-Python embedders must call runShutdownCallbacks() themselves before the process tears down external runtimes — typically right before main returns or before cuDeviceReset-style cleanup.

Note

Callbacks fire in registration order. Each callback should be idempotent. After shutdown begins, additional calls to this method are silently dropped.

void runShutdownCallbacks()#

Invoke every callback registered via registerShutdownCallback(), in registration order, then clear the list. Safe to call multiple times; the second call is a no-op. Driven automatically by the Python binding’s Py_AtExit; non-Python embedders should call this themselves before exit.

OperationResult executeOperation(
const std::string &operationName,
ExecutionContext *context,
const std::string &args,
)#

Executes the operation with the given name.

Parameters:
  • operationName – The name of the operation to execute.

  • context – The ExecutionContext to run the operation in.

  • args – A string of json containing the args to execute the operation with.

Returns:

A OperationResult struct which contains the results of the execution. Note: usd_optimize_operation_result_free must be used to clean up this struct.

std::vector<OperationResult> executeConfig(
ExecutionContext *context,
const std::string &config,
)#

Executes a JSON configuration containing a sequence of operations.

The config is a JSON string representing an array of objects, where each object has an “operation” key and optional argument keys. An “executionContext” operation can be used to override context settings for subsequent operations.

Operations are executed in order. Execution stops on the first failure.

Parameters:
  • context – The ExecutionContext to run the operations in.

  • config – A JSON string containing an array of operation configurations.

Returns:

A vector of OperationResult structs, one per executed operation (excluding executionContext entries). The caller must call usd_optimize_operation_result_free on each result.

UsdOptimizeCore(const UsdOptimizeCore&) = delete#
void operator=(const UsdOptimizeCore&) = delete#
carb::logging::ILogging *getLoggingInterface() const#
void setLoggingInterface(carb::logging::ILogging *ilogging)#

Public Static Functions

static UsdOptimizeCore &getInstance()#

Get the usd optimize core object.