This commit is contained in:
2025-11-13 17:40:28 +08:00
parent 962ab49609
commit 10156da245
5503 changed files with 805282 additions and 0 deletions

View File

@@ -0,0 +1,591 @@
#if !PICO_OPENXR_SDK
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.XR.PXR.SecureMR
{
public abstract class OperatorConfiguration
{
}
public class ArithmeticComposeOperatorConfiguration : OperatorConfiguration
{
public string configText { get; set; }
public ArithmeticComposeOperatorConfiguration(string configText)
{
this.configText = configText;
}
}
public class ComparisonOperatorConfiguration : OperatorConfiguration
{
public SecureMRComparison comparison { get; set; }
public ComparisonOperatorConfiguration(SecureMRComparison comparison)
{
this.comparison = comparison;
}
}
public class NmsOperatorConfiguration : OperatorConfiguration
{
public float threshold { get; set; }
public NmsOperatorConfiguration(float threshold)
{
this.threshold = threshold;
}
}
public class NormalizeOperatorConfiguration : OperatorConfiguration
{
public SecureMRNormalizeType normalizeType { get; set; }
public NormalizeOperatorConfiguration(SecureMRNormalizeType normalizeType)
{
this.normalizeType = normalizeType;
}
}
public class ColorConvertOperatorConfiguration : OperatorConfiguration
{
public int convert { get; set; }
public ColorConvertOperatorConfiguration(int convert)
{
this.convert = convert;
}
}
public class SortMatrixOperatorConfiguration : OperatorConfiguration
{
public SecureMRMatrixSortType sortType { get; set; }
public SortMatrixOperatorConfiguration(SecureMRMatrixSortType sortType)
{
this.sortType = sortType;
}
}
public class UpdateGltfOperatorConfiguration : OperatorConfiguration
{
public SecureMRGltfOperatorAttribute attribute { get; set; }
public UpdateGltfOperatorConfiguration(SecureMRGltfOperatorAttribute attribute)
{
this.attribute = attribute;
}
}
public class RenderTextOperatorConfiguration : OperatorConfiguration
{
public SecureMRFontTypeface typeface { get; set; }
public string languageAndLocale { get; set; }
public int width { get; set; }
public int height { get; set; }
public RenderTextOperatorConfiguration(SecureMRFontTypeface typeface, string languageAndLocale, int width, int height)
{
this.typeface = typeface;
this.languageAndLocale = languageAndLocale;
this.width = width;
this.height = height;
}
}
public class ModelOperatorConfiguration : OperatorConfiguration
{
public List<SecureMROperatorModelConfig> inputConfigs { get; set; }
public List<SecureMROperatorModelConfig> outputConfigs { get; set; }
public byte[] modelData { get; set; }
public SecureMRModelType modelType { get; set; }
public string modelName { get; set; }
public ModelOperatorConfiguration(List<SecureMROperatorModelConfig> inputConfigs, List<SecureMROperatorModelConfig> outputConfigs, byte[] modelData, SecureMRModelType modelType, string modelName)
{
this.inputConfigs = inputConfigs;
this.outputConfigs = outputConfigs;
this.modelData = modelData;
this.modelType = modelType;
this.modelName = modelName;
}
public ModelOperatorConfiguration(byte[] modelData, SecureMRModelType modelType, string modelName)
{
this.inputConfigs = new List<SecureMROperatorModelConfig>();
this.outputConfigs = new List<SecureMROperatorModelConfig>();
this.modelData = modelData;
this.modelType = modelType;
this.modelName = modelName;
}
public void AddInputMapping(string nodeName, string operatorIOName, SecureMRModelEncoding encodingType)
{
var config = new SecureMROperatorModelConfig
{ encodingType = encodingType, nodeName = nodeName, operatorIOName = operatorIOName };
inputConfigs.Add(config);
}
public void AddOutputMapping(string nodeName, string operatorIOName, SecureMRModelEncoding encodingType)
{
var config = new SecureMROperatorModelConfig
{ encodingType = encodingType, nodeName = nodeName, operatorIOName = operatorIOName };
outputConfigs.Add(config);
}
}
public abstract class Operator
{
public SecureMROperatorType OperatorType { get; private set; }
public ulong OperatorHandle { get; internal set; }
public ulong PipelineHandle { get; private set; }
public PxrResult SetOperand(string name, Tensor tensor)
{
return PXR_Plugin.SecureMR.UPxr_SetSecureMROperatorOperandByName(PipelineHandle, OperatorHandle, tensor.TensorHandle, name);
}
public PxrResult SetResult(string name, Tensor tensor)
{
return PXR_Plugin.SecureMR.UPxr_SetSecureMROperatorResultByName(PipelineHandle, OperatorHandle, tensor.TensorHandle, name);
}
public Operator(ulong pipelineHandle, SecureMROperatorType operatorType)
{
PipelineHandle = pipelineHandle;
OperatorType = operatorType;
}
}
public class ArithmeticComposeOperator : Operator
{
public ArithmeticComposeOperator(ulong pipelineHandle, SecureMROperatorType operatorType, ArithmeticComposeOperatorConfiguration config) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorArithmeticCompose(base.PipelineHandle, config.configText, out var operatorHandle);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ElementwiseMinOperator : Operator
{
public ElementwiseMinOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ElementwiseMaxOperator : Operator
{
public ElementwiseMaxOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ElementwiseMultiplyOperator : Operator
{
public ElementwiseMultiplyOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class CustomizedCompareOperator : Operator
{
public CustomizedCompareOperator(ulong pipelineHandle, SecureMROperatorType operatorType, ComparisonOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorComparison(base.PipelineHandle, configuration.comparison, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ElementwiseOrOperator : Operator
{
public ElementwiseOrOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ElementwiseAndOperator : Operator
{
public ElementwiseAndOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class AllOperator : Operator
{
public AllOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class AnyOperator : Operator
{
public AnyOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class NmsOperator : Operator
{
public NmsOperator(ulong pipelineHandle, SecureMROperatorType operatorType, NmsOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorNonMaximumSuppression(base.PipelineHandle, configuration.threshold, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SolvePnPOperator : Operator
{
public SolvePnPOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class GetAffineOperator : Operator
{
public GetAffineOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ApplyAffineOperator : Operator
{
public ApplyAffineOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ApplyAffinePointOperator : Operator
{
public ApplyAffinePointOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class UvTo3DInCameraSpaceOperator : Operator
{
public UvTo3DInCameraSpaceOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorUVTo3D(pipelineHandle, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class AssignmentOperator : Operator
{
public AssignmentOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class RunModelInferenceOperator : Operator
{
public RunModelInferenceOperator(ulong pipelineHandle, SecureMROperatorType operatorType, ModelOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMrOperatorModel(pipelineHandle, configuration.inputConfigs, configuration.outputConfigs, configuration.modelData, configuration.modelType, configuration.modelName, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class NormalizeOperator : Operator
{
public NormalizeOperator(ulong pipelineHandle, SecureMROperatorType operatorType, NormalizeOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorNormalize(pipelineHandle, configuration.normalizeType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class CameraSpaceToWorldOperator : Operator
{
public CameraSpaceToWorldOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class RectifiedVstAccessOperator : Operator
{
public RectifiedVstAccessOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ArgmaxOperator : Operator
{
public ArgmaxOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class ConvertColorOperator : Operator
{
public ConvertColorOperator(ulong pipelineHandle, SecureMROperatorType operatorType, ColorConvertOperatorConfiguration convertConfiguration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorColorConvert(pipelineHandle, convertConfiguration.convert, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SortVectorOperator : Operator
{
public SortVectorOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class InversionOperator : Operator
{
public InversionOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class GetTransformMatrixOperator : Operator
{
public GetTransformMatrixOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SortMatrixOperator : Operator
{
public SortMatrixOperator(ulong pipelineHandle, SecureMROperatorType operatorType, SortMatrixOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorSortMatrix(pipelineHandle, configuration.sortType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SwitchGltfRenderStatusOperator : Operator
{
public SwitchGltfRenderStatusOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class UpdateGltfOperator : Operator
{
public UpdateGltfOperator(ulong pipelineHandle, SecureMROperatorType operatorType, UpdateGltfOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorUpdateGltf(pipelineHandle, configuration.attribute, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class RenderTextOperator : Operator
{
public RenderTextOperator(ulong pipelineHandle, SecureMROperatorType operatorType, RenderTextOperatorConfiguration configuration) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperatorRenderText(pipelineHandle, configuration.typeface, configuration.languageAndLocale, configuration.width, configuration.height, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class LoadTextureOperator : Operator
{
public LoadTextureOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SvdOperator : Operator
{
public SvdOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class NormOperator : Operator
{
public NormOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
public class SwapHwcChwOperator : Operator
{
public SwapHwcChwOperator(ulong pipelineHandle, SecureMROperatorType operatorType) : base(pipelineHandle, operatorType)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMROperator(pipelineHandle, operatorType, out var operatorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, $"Create {operatorType} operator" + result, false);
if (result == PxrResult.SUCCESS)
{
base.OperatorHandle = operatorHandle;
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d416ffe3ba818044cbdb36ff404b68ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,201 @@
#if !PICO_OPENXR_SDK
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.XR.PXR.SecureMR
{
public class Pipeline
{
public ulong pipelineHandle;
internal Pipeline(ulong frameworkHandle)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRPipeline(frameworkHandle, out pipelineHandle);
if (result != PxrResult.SUCCESS)
{
throw new InvalidOperationException("Failed to create SecureMR pipeline" + result);
}
else
{
PLog.i(PXR_Plugin.SecureMR.TAG, "Create SecureMR pipeline success", false);
}
}
public T CreateOperator<T>() where T : Operator
{
PXR_Plugin.SecureMR.OperatorClassToEnum.TryGetValue(typeof(T), out var enumValue);
return (T)Activator.CreateInstance(typeof(T), pipelineHandle,enumValue);
}
public T CreateOperator<T>(OperatorConfiguration configuration) where T : Operator
{
PXR_Plugin.SecureMR.OperatorClassToEnum.TryGetValue(typeof(T), out var enumValue);
return (T)Activator.CreateInstance(typeof(T), pipelineHandle, enumValue, configuration);
}
public Tensor CreateTensor<T, TType>(int channels, TensorShape shape, T[] data = null)
where T : struct
where TType : TensorBase, new()
{
PXR_Plugin.SecureMR.TensorDataTypeToEnum.TryGetValue(typeof(T), out var dataType);
PXR_Plugin.SecureMR.TensorClassToEnum.TryGetValue(typeof(TType), out var enumValue);
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRPipelineTensorByShape(pipelineHandle, false, dataType, shape.Dimensions, (sbyte)channels, enumValue, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
if (data != null)
{
result = PXR_Plugin.SecureMR.UPxr_ResetSecureMRPipelineTensor(pipelineHandle, tensorHandle, data);
if (result != PxrResult.SUCCESS)
{
throw new InvalidOperationException("Failed to set tensor data:" + result);
}
}
return new Tensor(tensorHandle, pipelineHandle, false, false);
}
else
{
throw new InvalidOperationException("Failed to create local tensor:" + result);
}
}
public Tensor CreateTensor<TType>(byte[] data)
where TType : Gltf, new()
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRPipelineTensorByGltf(pipelineHandle, false, data, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
if (data != null)
{
result = PXR_Plugin.SecureMR.UPxr_ResetSecureMRPipelineTensor(pipelineHandle, tensorHandle, data);
if (result != PxrResult.SUCCESS)
{
throw new InvalidOperationException("Failed to set tensor data:" + result);
}
}
return new Tensor(tensorHandle, pipelineHandle, false, false);
}
else
{
throw new InvalidOperationException("Failed to create local gltf tensor:" + result);
}
}
public Tensor CreateTensorReference<T, TType>(int channels, TensorShape shape)
where T : struct
where TType : TensorBase, new()
{
PXR_Plugin.SecureMR.TensorDataTypeToEnum.TryGetValue(typeof(T), out var dataType);
PXR_Plugin.SecureMR.TensorClassToEnum.TryGetValue(typeof(TType), out var enumValue);
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRPipelineTensorByShape(pipelineHandle, true, dataType, shape.Dimensions, (sbyte)channels, enumValue, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
return new Tensor(tensorHandle, pipelineHandle, true, false);
}
else
{
throw new InvalidOperationException("Failed to create local tensor reference:" + result);
}
}
public Tensor CreateTensorReference<TType>()
where TType : Gltf, new()
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRPipelineTensorByGltf(pipelineHandle, true, null, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
return new Tensor(tensorHandle, pipelineHandle, true, false);
}
else
{
throw new InvalidOperationException("Failed to create local tensor reference:" + result);
}
}
public TensorMapping CreateTensorMapping()
{
return new TensorMapping();
}
public void Destroy()
{
var result = PXR_Plugin.SecureMR.UPxr_DestroySecureMRPipeline(pipelineHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, "Destroy SecureMR pipeline:" + result, false);
}
public ulong Execute(TensorMapping tensorMappings = null)
{
PxrResult result;
ulong pipelineRunHandle;
if (tensorMappings != null)
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipeline(pipelineHandle, tensorMappings.TensorMappings, out pipelineRunHandle);
}
else
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipeline(pipelineHandle, null, out pipelineRunHandle);
}
if (result == PxrResult.SUCCESS)
{
return pipelineRunHandle;
}
else
{
throw new InvalidOperationException("Failed to execute pipeline:" + result);
}
}
public ulong ExecuteAfter(ulong runId, TensorMapping tensorMappings = null)
{
PxrResult result;
ulong pipelineRunHandle;
if (tensorMappings != null)
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipelineAfter(pipelineHandle, runId, tensorMappings.TensorMappings, out pipelineRunHandle);
}
else
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipelineAfter(pipelineHandle, runId, null, out pipelineRunHandle);
}
if (result == PxrResult.SUCCESS)
{
return pipelineRunHandle;
}
else
{
throw new InvalidOperationException("Failed to execute after pipeline:" + result);
}
}
public ulong ExecuteConditional(ulong conditionTensorHandle, TensorMapping tensorMappings = null)
{
PxrResult result;
ulong pipelineRunHandle;
if (tensorMappings != null)
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipelineConditional(pipelineHandle, conditionTensorHandle, tensorMappings.TensorMappings, out pipelineRunHandle);
}
else
{
result = PXR_Plugin.SecureMR.UPxr_ExecuteSecureMRPipelineConditional(pipelineHandle, conditionTensorHandle, null, out pipelineRunHandle);
}
if (result == PxrResult.SUCCESS)
{
return pipelineRunHandle;
}
else
{
throw new InvalidOperationException("Failed to execute conditional pipeline:" + result);
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b502f489e4f24894fa0f2507435afba3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
#if !PICO_OPENXR_SDK
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.XR.PXR.SecureMR
{
public class Provider
{
private ulong providerHandle;
public Provider(int width,int height)
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRProvider(width, height, out providerHandle);
if (result != PxrResult.SUCCESS)
{
throw new InvalidOperationException("Failed to create SecureMRProvider" + result);
}
else
{
PLog.i(PXR_Plugin.SecureMR.TAG,"Create SecureMR provider success",false);
}
}
public Pipeline CreatePipeline()
{
return new Pipeline(providerHandle);
}
public Tensor CreateTensor<T, TType>(int channels, TensorShape shape, T[] data = null)
where T : struct
where TType : TensorBase, new()
{
PXR_Plugin.SecureMR.TensorDataTypeToEnum.TryGetValue(typeof(T), out var dataType);
PXR_Plugin.SecureMR.TensorClassToEnum.TryGetValue(typeof(TType), out var enumValue);
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRTensorByShape(providerHandle, dataType, shape.Dimensions, (sbyte)channels, enumValue, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
if (data != null)
{
result = PXR_Plugin.SecureMR.UPxr_ResetSecureMRTensor(tensorHandle, data);
if (result != PxrResult.SUCCESS)
{
throw new InvalidOperationException("Failed to set tensor data" + result);
}
}
return new Tensor(tensorHandle, 0, false, true);
}
else
{
throw new InvalidOperationException("Failed to create global tensor" + result);
}
}
public Tensor CreateTensor<TType>(byte[] data)
where TType : Gltf, new()
{
var result = PXR_Plugin.SecureMR.UPxr_CreateSecureMRTensorByGltf(providerHandle, data, out var tensorHandle);
if (result == PxrResult.SUCCESS)
{
return new Tensor(tensorHandle, 0, false, true);
}
else
{
throw new InvalidOperationException("Failed to create global gltf tensor" + result);
}
}
public void Destroy()
{
var result = PXR_Plugin.SecureMR.UPxr_DestroySecureMRProvider(providerHandle);
if (result == PxrResult.SUCCESS)
{
providerHandle = 0;
}
else
{
PLog.i(PXR_Plugin.SecureMR.TAG, "Destroy SecureMR provider failed" + result, false);
}
}
~Provider()
{
Destroy();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf5175349b375c2498481b2a6f6af304
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
#if !PICO_OPENXR_SDK
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.XR.PXR.SecureMR
{
public class Tensor
{
public ulong TensorHandle { get; private set; }
public ulong PipelineHandle { get; private set; }
public bool PlaceHolder { get; private set; }
public bool IsGlobalTensor { get; private set; }
public Tensor(ulong tensorHandle,ulong pipelineHandle,bool placeHolder,bool isGlobalTensor)
{
this.TensorHandle = tensorHandle;
this.PipelineHandle = pipelineHandle;
this.PlaceHolder = placeHolder;
this.IsGlobalTensor = isGlobalTensor;
}
public void Reset<T>(T[] tensorData)
{
if (IsGlobalTensor)
{
var result = PXR_Plugin.SecureMR.UPxr_ResetSecureMRTensor(TensorHandle, tensorData);
PLog.i(PXR_Plugin.SecureMR.TAG, "Reset global tensor data" + result, false);
}
else
{
var result = PXR_Plugin.SecureMR.UPxr_ResetSecureMRPipelineTensor(PipelineHandle, TensorHandle, tensorData);
PLog.i(PXR_Plugin.SecureMR.TAG, "Reset local tensor data" + result, false);
}
}
public void Destroy()
{
if (IsGlobalTensor)
{
var result = PXR_Plugin.SecureMR.UPxr_DestroySecureMRTensor(TensorHandle);
PLog.i(PXR_Plugin.SecureMR.TAG, "Destroy global tensor" + result, false);
}
}
}
public abstract class TensorBase{}
public class Color : TensorBase{}
public class Gltf { }
public class Matrix : TensorBase{}
public class Point : TensorBase{}
public class Scalar : TensorBase{}
public class Slice : TensorBase{}
public class TimeStamp : TensorBase { }
public class TensorShape
{
public int[] Dimensions { get; }
public TensorShape(params int[] dimensions)
{
if (dimensions == null || dimensions.Length == 0)
{
throw new ArgumentException("Dimensions array cannot be null or empty.");
}
Dimensions = dimensions;
}
}
public class TensorMapping
{
public Dictionary<ulong, ulong> TensorMappings { get; private set; }
public TensorMapping()
{
TensorMappings = new Dictionary<ulong, ulong>();
}
public void Set(Tensor localTensorReference, Tensor globalTensor)
{
TensorMappings.TryAdd(localTensorReference.TensorHandle, globalTensor.TensorHandle);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b1ab1b5f011d5b44a58551399e4bba4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: