diff --git a/.gitignore b/.gitignore index 9efb5f82..8b75980d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ Library obj obj.meta # User-specific files -*.csproj.meta *.csproj.user *.suo *.user @@ -177,6 +176,7 @@ ClientBin/ [Ss]tyle[Cc]op.* ~$* *~ +!*CodeGen~ *.dbmdl *.dbproj.schemaview *.pfx diff --git a/.yamato/upm-ci.yml b/.yamato/upm-ci.yml index ee8ad143..27b41405 100644 --- a/.yamato/upm-ci.yml +++ b/.yamato/upm-ci.yml @@ -1,72 +1,89 @@ build_platforms: - name: windows type: Unity::VM - image: sdet/burst-devimage:stable + image: package-ci/win10:v4 flavor: b1.large - name: linux - image: package-ci/ubuntu:stable + image: package-ci/ubuntu-22.04:v4 type: Unity::VM flavor: b1.large - name: macOS - image: burst/burst_mac:stable + image: package-ci/macos-13:v4 type: Unity::VM::osx flavor: b1.large upmci_platforms: - name: windows type: Unity::VM - image: package-ci/win10:stable + image: package-ci/win10:v4 flavor: b1.large - name: linux - image: package-ci/ubuntu:stable + image: package-ci/ubuntu-22.04:v4 type: Unity::VM flavor: b1.large - name: macOS - image: package-ci/mac:stable + image: package-ci/macos-13:v4 type: Unity::VM::osx flavor: b1.large -editor_versions: - - version: "2018.4" - display_name: "2018.4" - - version: "2019.2" - display_name: "2019.2" - - version: "2019.3" - display_name: "2019.3" - - version: "2020.2/partner/staging" - display_name: "2020.2_partner_staging" - - version: "trunk" - display_name: "trunk" +validate_editor_versions: + - version: "6000.0" + display_name: "6000.0" + - version: "6000.3" + display_name: "6000.3" + +package_tests_editor_versions: + - version: "6000.0" + display_name: "6000.0" + - version: "6000.3" + display_name: "6000.3" --- -{% for platform in build_platforms %} -{% unless platform.name == "linux" %} -run_tests_on_mono_{{platform.name}}: - name: Tests NUnit on {{platform.name}} +{% for platform in upmci_platforms %} +{% for editor in package_tests_editor_versions %} +package_tests_{{platform.name}}_{{editor.display_name}}: + name: Package tests {{platform.name}} {{editor.display_name}} agent: - type: {{platform.type}} - image: {{platform.image}} - flavor: {{platform.flavor}} + image: {{platform.image}} + type: {{platform.type}} + flavor: {{platform.flavor}} commands: - {% if platform.name == "windows" %} - - choco install nuget.commandline - {% endif %} - - nuget restore src - - msbuild src/Unity.Mathematics.sln - - mono src/packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe src/Tests/bin/Debug/Unity.Mathematics.Tests.dll --process=single -{% endunless %} + - npm install upm-ci-utils@stable --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm -g + - upm-ci package pack --package-path src/ + - upm-ci package test --type package-tests --package-path src/ --unity-version {{ editor.version }} + artifacts: + test_results: + paths: + - "upm-ci~/**/*" +{% endfor %} {% endfor %} +package_tests_all: + name: Package tests all + dependencies: + {% for platform in upmci_platforms %} + {% for editor in package_tests_editor_versions %} + - .yamato/upm-ci.yml#package_tests_{{platform.name}}_{{editor.display_name}} + {% endfor %} + {% endfor %} + +package_tests_minimal: + name: Package tests minimal + dependencies: + {% for platform in upmci_platforms %} + - .yamato/upm-ci.yml#package_tests_{{platform.name}}_6000.3 + {% endfor %} + validate_package_minimal: name: Validate Package Linux Minimal agent: - image: package-ci/ubuntu:stable + image: package-ci/ubuntu-22.04:v4 type: Unity::VM flavor: b1.large commands: - npm install upm-ci-utils@stable --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm -g - upm-ci package pack --package-path src/ - - upm-ci package test --package-path src/ --unity-version 2019.1 + - upm-ci package test --package-path src/ --unity-version 6000.3 artifacts: packages: paths: @@ -74,15 +91,9 @@ validate_package_minimal: test_results: paths: - "upm-ci~/**/*" - dependencies: - {% for platform in build_platforms %} - {% unless platform.name == "linux" %} - - .yamato/upm-ci.yml#run_tests_on_mono_{{platform.name}} - {% endunless %} - {% endfor %} - {% for platform in upmci_platforms %} - {% for editor in editor_versions %} +{% for platform in upmci_platforms %} +{% for editor in validate_editor_versions %} validate_package_{{platform.name}}_{{editor.display_name}}: name: Validate package {{platform.name}} {{editor.display_name}} agent: @@ -100,22 +111,26 @@ validate_package_{{platform.name}}_{{editor.display_name}}: results_{{platform.name}}_{{editor.display_name}}: paths: - "upm-ci~/**/*" +{% endfor %} +{% endfor %} + +validate_package_all: + name: Validate package all dependencies: - {% for platform in build_platforms %} - {% unless platform.name == "linux" %} - - .yamato/upm-ci.yml#run_tests_on_mono_{{platform.name}} - {% endunless %} + {% for platform in upmci_platforms %} + {% for editor in validate_editor_versions %} + - .yamato/upm-ci.yml#validate_package_{{platform.name}}_{{editor.display_name}} + {% endfor %} {% endfor %} - {% endfor %} - {% endfor %} - publish: name: Publish agent: type: Unity::VM - image: package-ci/win10:stable + image: package-ci/win10:v4 flavor: b1.large + variables: + UPMCI_ENABLE_PACKAGE_SIGNING: 1 commands: - npm install upm-ci-utils@stable --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm -g - upm-ci package publish --package-path src/ @@ -124,14 +139,18 @@ publish: paths: - "upm-ci~/packages/**/*" dependencies: - - .yamato/upm-ci.yml#validate_package_minimal - + {% for platform in build_platforms %} + {% for editor in validate_editor_versions %} + - .yamato/upm-ci.yml#validate_package_{{platform.name}}_{{editor.display_name}} + {% endfor %} + {% endfor %} + - .yamato/upm-ci.yml#package_tests_minimal promote: name: Promote agent: type: Unity::VM - image: package-ci/win10:stable + image: package-ci/win10:v4 flavor: b1.large variables: UPMCI_PROMOTION: 1 @@ -145,7 +164,6 @@ promote: dependencies: - .yamato/upm-ci.yml#publish - publish_ci: name: all Publish Pipeline triggers: @@ -162,18 +180,13 @@ nightly_ci: - branch: master frequency: daily dependencies: - {% for platform in build_platforms %} - {% for editor in editor_versions %} - - .yamato/upm-ci.yml#validate_package_{{platform.name}}_{{editor.display_name}} - {% endfor %} - {% endfor %} - + - .yamato/upm-ci.yml#validate_package_all commit_ci: - name: all CI pipeline + name: Commit CI pipeline triggers: branches: only: - "/.*/" dependencies: - - .yamato/upm-ci.yml#validate_package_minimal + - .yamato/upm-ci.yml#package_tests_minimal diff --git a/LICENSE.md b/LICENSE.md index 311c9904..0c7f3fac 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,30 +1,4 @@ -Unity Companion License (“License”) -Software Copyright © 2019 Unity Technologies ApS - -Unity Technologies ApS (“Unity”) grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available under this License (“Software”), subject to the following terms and conditions: - -1. Unity Companion Use Only. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity content authoring and rendering engine software license (“Engine License”). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted, and in no event may the Software be used for competitive analysis or to develop a competing product or service. - -2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way. - -3. Ownership & Grant Back to You. +com.unity.mathematics copyright © 2023 Unity Technologies ApS -3.1 You own your content. In this License, “derivative works” means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content. - -3.2 Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity. - -3.3 You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License. - -4. Trademarks. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates (“Trademarks”). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at https://unity3d.com/public-relations/brand. - -5. Notices & Third-Party Rights. This License, including the copyright notice associated with the Software, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity “third-party notices” or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms. - -6. DISCLAIMER, LIMITATION OF LIABILITY. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -7. USE IS ACCEPTANCE and License Versions. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License. - -8. Use in Compliance with Law and Termination. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License. - -9. Severability. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect. - -10. Governing Law and Venue. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License (“Dispute”). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute. \ No newline at end of file +Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license). +Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. diff --git a/Unity.Mathematics.TestProject/Assets/Scenes/SampleScene.unity b/Unity.Mathematics.TestProject/Assets/Scenes/SampleScene.unity index 7cdec2a0..b819a102 100644 --- a/Unity.Mathematics.TestProject/Assets/Scenes/SampleScene.unity +++ b/Unity.Mathematics.TestProject/Assets/Scenes/SampleScene.unity @@ -38,24 +38,23 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.44402242, g: 0.49316543, b: 0.5722324, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 11 + serializedVersion: 12 m_GIWorkflowMode: 0 m_GISettings: serializedVersion: 2 m_BounceScale: 1 m_IndirectOutputScale: 1 m_AlbedoBoost: 1 - m_TemporalCoherenceThreshold: 1 m_EnvironmentLightingMode: 0 m_EnableBakedLightmaps: 1 m_EnableRealtimeLightmaps: 1 m_LightmapEditorSettings: - serializedVersion: 10 + serializedVersion: 12 m_Resolution: 2 m_BakeResolution: 40 m_AtlasSize: 1024 @@ -63,6 +62,7 @@ LightmapSettings: m_AOMaxDistance: 1 m_CompAOExponent: 1 m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 m_Padding: 2 m_LightmapParameters: {fileID: 0} m_LightmapsBakeMode: 1 @@ -77,10 +77,16 @@ LightmapSettings: m_PVRDirectSampleCount: 32 m_PVRSampleCount: 500 m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 500 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 2 + m_PVRDenoiserTypeDirect: 0 + m_PVRDenoiserTypeIndirect: 0 + m_PVRDenoiserTypeAO: 0 m_PVRFilterTypeDirect: 0 m_PVRFilterTypeIndirect: 0 m_PVRFilterTypeAO: 0 - m_PVRFilteringMode: 1 + m_PVREnvironmentMIS: 0 m_PVRCulling: 1 m_PVRFilteringGaussRadiusDirect: 1 m_PVRFilteringGaussRadiusIndirect: 5 @@ -88,15 +94,18 @@ LightmapSettings: m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaAO: 1 - m_ShowResolutionOverlay: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 m_LightingDataAsset: {fileID: 0} - m_UseShadowmask: 1 + m_LightingSettings: {fileID: 4890085278179872738, guid: 20c8488ac153b4f45944c2d7c85a094e, + type: 2} --- !u!196 &4 NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -109,15 +118,49 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &206998647 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 206998649} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &206998649 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 206998647} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - component: {fileID: 705507995} @@ -133,15 +176,18 @@ GameObject: Light: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 705507993} m_Enabled: 1 - serializedVersion: 8 + serializedVersion: 10 m_Type: 1 + m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_Intensity: 1 m_Range: 10 m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 m_CookieSize: 10 m_Shadows: m_Type: 2 @@ -151,6 +197,24 @@ Light: m_Bias: 0.05 m_NormalBias: 0.4 m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 m_Cookie: {fileID: 0} m_DrawHalo: 0 m_Flare: {fileID: 0} @@ -158,32 +222,39 @@ Light: m_CullingMask: serializedVersion: 2 m_Bits: 4294967295 + m_RenderingLayerMask: 1 m_Lightmapping: 1 m_LightShadowCasterMode: 0 m_AreaSize: {x: 1, y: 1} m_BounceIntensity: 1 m_ColorTemperature: 6570 m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 m_ShadowRadius: 0 m_ShadowAngle: 0 --- !u!4 &705507995 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 705507993} + serializedVersion: 2 m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} --- !u!1 &963194225 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - component: {fileID: 963194228} @@ -200,24 +271,35 @@ GameObject: AudioListener: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} m_Enabled: 1 --- !u!20 &963194227 Camera: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 1 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_projectionMatrixMode: 1 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -248,12 +330,21 @@ Camera: Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 1, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 963194228} + - {fileID: 705507995} + - {fileID: 206998649} diff --git a/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting b/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting new file mode 100644 index 00000000..e595ed65 --- /dev/null +++ b/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting @@ -0,0 +1,66 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!850595691 &4890085278179872738 +LightingSettings: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: SampleSceneSettings + serializedVersion: 6 + m_GIWorkflowMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 1 + m_RealtimeEnvironmentLighting: 1 + m_BounceScale: 1 + m_AlbedoBoost: 1 + m_IndirectOutputScale: 1 + m_UsingShadowmask: 1 + m_BakeBackend: 1 + m_LightmapMaxSize: 1024 + m_BakeResolution: 40 + m_Padding: 2 + m_LightmapCompression: 3 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAO: 0 + m_MixedBakeMode: 2 + m_LightmapsBakeMode: 1 + m_FilterMode: 1 + m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0} + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_RealtimeResolution: 2 + m_ForceWhiteAlbedo: 0 + m_ForceUpdates: 0 + m_FinalGather: 0 + m_FinalGatherRayCount: 256 + m_FinalGatherFiltering: 1 + m_PVRCulling: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVREnvironmentSampleCount: 512 + m_PVREnvironmentReferencePointCount: 2048 + m_LightProbeSampleCountMultiplier: 4 + m_PVRBounces: 2 + m_PVRMinBounces: 2 + m_PVREnvironmentImportanceSampling: 0 + m_PVRFilteringMode: 2 + m_PVRDenoiserTypeDirect: 0 + m_PVRDenoiserTypeIndirect: 0 + m_PVRDenoiserTypeAO: 0 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_PVRTiledBaking: 0 + m_NumRaysToShootPerTexel: -1 + m_RespectSceneVisibilityWhenBakingGI: 0 diff --git a/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting.meta b/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting.meta new file mode 100644 index 00000000..daa2a351 --- /dev/null +++ b/Unity.Mathematics.TestProject/Assets/Scenes/SampleSceneSettings.lighting.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 20c8488ac153b4f45944c2d7c85a094e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 4890085278179872738 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef b/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef deleted file mode 100644 index 45bb135b..00000000 --- a/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Tests", - "optionalUnityReferences": [ - "TestAssemblies" - ] -} diff --git a/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef.meta b/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef.meta deleted file mode 100644 index cf7cb66a..00000000 --- a/Unity.Mathematics.TestProject/Assets/Tests/Tests.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 5f5c2087bc52f4f7c8326e51ec5a628d -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Unity.Mathematics.TestProject/Packages/manifest.json b/Unity.Mathematics.TestProject/Packages/manifest.json index 5b27463f..932cc93d 100644 --- a/Unity.Mathematics.TestProject/Packages/manifest.json +++ b/Unity.Mathematics.TestProject/Packages/manifest.json @@ -1,13 +1,15 @@ { "dependencies": { - "com.unity.burst": "1.2.3", - "com.unity.ide.rider": "1.1.4", - "com.unity.ide.vscode": "1.1.4", + "com.unity.ai.navigation": "2.0.0", + "com.unity.burst": "1.8.11", + "com.unity.ide.rider": "3.0.27", + "com.unity.ide.visualstudio": "2.0.22", "com.unity.mathematics": "file:../../src", - "com.unity.package-validation-suite": "0.8.1-preview", - "com.unity.properties": "0.10.4-preview", - "com.unity.test-framework": "1.1.11", - "com.unity.test-framework.performance": "2.8.0-preview" + "com.unity.package-validation-suite": "0.62.0-preview", + "com.unity.properties": "2.1.0-exp.3", + "com.unity.test-framework": "1.3.9", + "com.unity.test-framework.performance": "3.0.3", + "com.unity.modules.accessibility": "1.0.0" }, "testables": [ "com.unity.mathematics" diff --git a/Unity.Mathematics.TestProject/ProjectSettings/EditorBuildSettings.asset b/Unity.Mathematics.TestProject/ProjectSettings/EditorBuildSettings.asset index 0147887e..40917b05 100644 --- a/Unity.Mathematics.TestProject/ProjectSettings/EditorBuildSettings.asset +++ b/Unity.Mathematics.TestProject/ProjectSettings/EditorBuildSettings.asset @@ -4,5 +4,8 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/Scenes/SampleScene.unity + guid: 9fc0d4010bbf28b4594072e72b8655ab m_configObjects: {} diff --git a/Unity.Mathematics.TestProject/ProjectSettings/GraphicsSettings.asset b/Unity.Mathematics.TestProject/ProjectSettings/GraphicsSettings.asset index 35a0fa7f..bea55798 100644 --- a/Unity.Mathematics.TestProject/ProjectSettings/GraphicsSettings.asset +++ b/Unity.Mathematics.TestProject/ProjectSettings/GraphicsSettings.asset @@ -36,6 +36,10 @@ GraphicsSettings: - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} diff --git a/Unity.Mathematics.TestProject/ProjectSettings/ProjectSettings.asset b/Unity.Mathematics.TestProject/ProjectSettings/ProjectSettings.asset index f8345c9f..9eb3e0b5 100644 --- a/Unity.Mathematics.TestProject/ProjectSettings/ProjectSettings.asset +++ b/Unity.Mathematics.TestProject/ProjectSettings/ProjectSettings.asset @@ -3,7 +3,7 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 20 + serializedVersion: 26 productGUID: 50c0163089a174a7ab9f46f0020a809f AndroidProfiler: 0 AndroidFilterTouchesWhenObscured: 0 @@ -48,12 +48,15 @@ PlayerSettings: defaultScreenHeightWeb: 600 m_StereoRenderingPath: 0 m_ActiveColorSpace: 0 + m_SpriteBatchVertexThreshold: 300 m_MTRendering: 1 + mipStripping: 0 + numberOfMipsStripped: 0 + numberOfMipsStrippedPerMipmapLimitGroup: {} m_StackTraceTypes: 010000000100000001000000010000000100000001000000 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 iosUseCustomAppBackgroundBehavior: 0 - iosAllowHTTPDownload: 1 allowedAutorotateToPortrait: 1 allowedAutorotateToPortraitUpsideDown: 1 allowedAutorotateToLandscapeRight: 1 @@ -66,6 +69,12 @@ PlayerSettings: androidRenderOutsideSafeArea: 1 androidUseSwappy: 0 androidBlitType: 0 + androidResizableWindow: 0 + androidDefaultWindowWidth: 1920 + androidDefaultWindowHeight: 1080 + androidMinimumWindowWidth: 400 + androidMinimumWindowHeight: 300 + androidFullscreenMode: 1 defaultIsNativeResolution: 1 macRetinaSupport: 1 runInBackground: 1 @@ -103,6 +112,7 @@ PlayerSettings: xboxOneMonoLoggingLevel: 0 xboxOneLoggingLevel: 1 xboxOneDisableEsram: 0 + xboxOneEnableTypeOptimization: 0 xboxOnePresentImmediateThreshold: 0 switchQueueCommandMemory: 0 switchQueueControlMemory: 16384 @@ -110,14 +120,19 @@ PlayerSettings: switchNVNShaderPoolsGranularity: 33554432 switchNVNDefaultPoolsGranularity: 16777216 switchNVNOtherPoolsGranularity: 16777216 + switchGpuScratchPoolGranularity: 2097152 + switchAllowGpuScratchShrinking: 0 + switchNVNMaxPublicTextureIDCount: 0 + switchNVNMaxPublicSamplerIDCount: 0 + switchNVNGraphicsFirmwareMemory: 32 + stadiaPresentMode: 0 + stadiaTargetFramerate: 0 vulkanNumSwapchainBuffers: 3 vulkanEnableSetSRGBWrite: 0 - m_SupportedAspectRatios: - 4:3: 1 - 5:4: 1 - 16:10: 1 - 16:9: 1 - Others: 1 + vulkanEnablePreTransform: 0 + vulkanEnableLateAcquireNextImage: 0 + vulkanEnableCommandBufferRecycling: 1 + loadStoreDebugModeEnabled: 0 bundleVersion: 0.1 preloadedAssets: [] metroInputSource: 0 @@ -126,45 +141,28 @@ PlayerSettings: xboxOneDisableKinectGpuReservation: 0 xboxOneEnable7thCore: 0 vrSettings: - cardboard: - depthFormat: 0 - enableTransitionView: 0 - daydream: - depthFormat: 0 - useSustainedPerformanceMode: 0 - enableVideoLayer: 0 - useProtectedVideoMemory: 0 - minimumSupportedHeadTracking: 0 - maximumSupportedHeadTracking: 1 - hololens: - depthFormat: 1 - depthBufferSharingEnabled: 0 - lumin: - depthFormat: 0 - frameTiming: 2 - enableGLCache: 0 - glCacheMaxBlobSize: 524288 - glCacheMaxFileSize: 8388608 - oculus: - sharedDepthBuffer: 1 - dashSupport: 1 - lowOverheadMode: 0 - protectedContext: 0 - v2Signing: 1 enable360StereoCapture: 0 isWsaHolographicRemotingEnabled: 0 enableFrameTimingStats: 0 + enableOpenGLProfilerGPURecorders: 1 useHDRDisplay: 0 - D3DHDRBitDepth: 0 + hdrBitDepth: 0 m_ColorGamuts: 00000000 targetPixelDensity: 30 resolutionScalingMode: 0 + resetResolutionOnWindowResize: 0 androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 - applicationIdentifier: {} - buildNumber: {} + applicationIdentifier: + Android: com.UnityTestRunner.UnityTestRunner + buildNumber: + Standalone: 0 + VisionOS: 0 + iPhone: 0 + tvOS: 0 + overrideDefaultApplicationIdentifier: 1 AndroidBundleVersionCode: 1 - AndroidMinSdkVersion: 19 + AndroidMinSdkVersion: 22 AndroidTargetSdkVersion: 0 AndroidPreferredInstallLocation: 1 aotOptions: @@ -177,34 +175,21 @@ PlayerSettings: APKExpansionFiles: 0 keepLoadedShadersAlive: 0 StripUnusedMeshComponents: 1 + strictShaderVariantMatching: 0 VertexChannelCompressionMask: 4054 iPhoneSdkVersion: 988 - iOSTargetOSVersionString: 10.0 + iOSTargetOSVersionString: 12.0 tvOSSdkVersion: 0 tvOSRequireExtendedGameController: 0 - tvOSTargetOSVersionString: 10.0 + tvOSTargetOSVersionString: 12.0 + VisionOSSdkVersion: 0 + VisionOSTargetOSVersionString: 1.0 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 uIStatusBarHidden: 1 uIExitOnSuspend: 0 uIStatusBarStyle: 0 - iPhoneSplashScreen: {fileID: 0} - iPhoneHighResSplashScreen: {fileID: 0} - iPhoneTallHighResSplashScreen: {fileID: 0} - iPhone47inSplashScreen: {fileID: 0} - iPhone55inPortraitSplashScreen: {fileID: 0} - iPhone55inLandscapeSplashScreen: {fileID: 0} - iPhone58inPortraitSplashScreen: {fileID: 0} - iPhone58inLandscapeSplashScreen: {fileID: 0} - iPadPortraitSplashScreen: {fileID: 0} - iPadHighResPortraitSplashScreen: {fileID: 0} - iPadLandscapeSplashScreen: {fileID: 0} - iPadHighResLandscapeSplashScreen: {fileID: 0} - iPhone65inPortraitSplashScreen: {fileID: 0} - iPhone65inLandscapeSplashScreen: {fileID: 0} - iPhone61inPortraitSplashScreen: {fileID: 0} - iPhone61inLandscapeSplashScreen: {fileID: 0} appleTVSplashScreen: {fileID: 0} appleTVSplashScreen2x: {fileID: 0} tvOSSmallIconLayers: [] @@ -232,32 +217,47 @@ PlayerSettings: iOSLaunchScreeniPadFillPct: 100 iOSLaunchScreeniPadSize: 100 iOSLaunchScreeniPadCustomXibPath: - iOSUseLaunchScreenStoryboard: 0 iOSLaunchScreenCustomStoryboardPath: + iOSLaunchScreeniPadCustomStoryboardPath: iOSDeviceRequirements: [] iOSURLSchemes: [] + macOSURLSchemes: [] iOSBackgroundModes: 0 iOSMetalForceHardShadows: 0 metalEditorSupport: 1 metalAPIValidation: 1 iOSRenderExtraFrameOnPause: 0 + iosCopyPluginsCodeInsteadOfSymlink: 0 appleDeveloperTeamID: iOSManualSigningProvisioningProfileID: tvOSManualSigningProvisioningProfileID: + VisionOSManualSigningProvisioningProfileID: iOSManualSigningProvisioningProfileType: 0 tvOSManualSigningProvisioningProfileType: 0 + VisionOSManualSigningProvisioningProfileType: 0 appleEnableAutomaticSigning: 0 iOSRequireARKit: 0 iOSAutomaticallyDetectAndAddCapabilities: 1 appleEnableProMotion: 0 + shaderPrecisionModel: 0 clonedFromGUID: c0afd0d1d80e3634a9dac47e8a0426ea templatePackageId: com.unity.template.3d@1.0.11 templateDefaultScene: Assets/Scenes/SampleScene.unity + useCustomMainManifest: 0 + useCustomLauncherManifest: 0 + useCustomMainGradleTemplate: 0 + useCustomLauncherGradleManifest: 0 + useCustomBaseGradleTemplate: 0 + useCustomGradlePropertiesTemplate: 0 + useCustomGradleSettingsTemplate: 0 + useCustomProguardFile: 0 AndroidTargetArchitectures: 1 + AndroidTargetDevices: 0 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} AndroidKeystoreName: '{inproject}: ' AndroidKeyaliasName: + AndroidEnableArmv9SecurityFeatures: 0 AndroidBuildApkPerCpuArchitecture: 0 AndroidTVCompatibility: 0 AndroidIsGame: 1 @@ -270,10 +270,105 @@ PlayerSettings: height: 180 banner: {fileID: 0} androidGamepadSupportLevel: 0 + chromeosInputEmulation: 1 + AndroidMinifyRelease: 0 + AndroidMinifyDebug: 0 AndroidValidateAppBundleSize: 1 AndroidAppBundleSizeToValidate: 100 m_BuildTargetIcons: [] - m_BuildTargetPlatformIcons: [] + m_BuildTargetPlatformIcons: + - m_BuildTarget: Android + m_Icons: + - m_Textures: [] + m_Width: 432 + m_Height: 432 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 324 + m_Height: 324 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 216 + m_Height: 216 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 162 + m_Height: 162 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 108 + m_Height: 108 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 81 + m_Height: 81 + m_Kind: 2 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 0 + m_SubKind: + - m_Textures: [] + m_Width: 192 + m_Height: 192 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 144 + m_Height: 144 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 96 + m_Height: 96 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 72 + m_Height: 72 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 48 + m_Height: 48 + m_Kind: 1 + m_SubKind: + - m_Textures: [] + m_Width: 36 + m_Height: 36 + m_Kind: 1 + m_SubKind: m_BuildTargetBatching: - m_BuildTarget: Standalone m_StaticBatching: 1 @@ -290,6 +385,7 @@ PlayerSettings: - m_BuildTarget: WebGL m_StaticBatching: 0 m_DynamicBatching: 0 + m_BuildTargetShaderSettings: [] m_BuildTargetGraphicsJobs: - m_BuildTarget: MacStandaloneSupport m_GraphicsJobs: 0 @@ -325,13 +421,13 @@ PlayerSettings: m_BuildTargetGraphicsAPIs: - m_BuildTarget: AndroidPlayer m_APIs: 150000000b000000 - m_Automatic: 0 + m_Automatic: 1 - m_BuildTarget: iOSSupport m_APIs: 10000000 m_Automatic: 1 - m_BuildTarget: AppleTVSupport m_APIs: 10000000 - m_Automatic: 0 + m_Automatic: 1 - m_BuildTarget: WebGLSupport m_APIs: 0b000000 m_Automatic: 1 @@ -341,6 +437,8 @@ PlayerSettings: m_Devices: - Oculus - OpenVR + m_DefaultShaderChunkSizeInMB: 16 + m_DefaultShaderChunkCount: 0 openGLRequireES31: 0 openGLRequireES31AEP: 0 openGLRequireES32: 0 @@ -350,7 +448,11 @@ PlayerSettings: iPhone: 1 tvOS: 1 m_BuildTargetGroupLightmapEncodingQuality: [] + m_BuildTargetGroupHDRCubemapEncodingQuality: [] m_BuildTargetGroupLightmapSettings: [] + m_BuildTargetGroupLoadStoreDebugModeSettings: [] + m_BuildTargetNormalMapEncoding: [] + m_BuildTargetDefaultTextureCompressionFormat: [] playModeTestRunnerEnabled: 0 runPlayModeTestAsEditModeTest: 0 actionOnDotNetUnhandledException: 1 @@ -360,14 +462,20 @@ PlayerSettings: cameraUsageDescription: locationUsageDescription: microphoneUsageDescription: + bluetoothUsageDescription: + macOSTargetOSVersion: 10.13.0 + switchNMETAOverride: switchNetLibKey: switchSocketMemoryPoolSize: 6144 switchSocketAllocatorPoolSize: 128 switchSocketConcurrencyLimit: 14 switchScreenResolutionBehavior: 2 switchUseCPUProfiler: 0 + switchUseGOLDLinker: 0 + switchLTOSetting: 0 switchApplicationID: 0x01004b9000490000 switchNSODependencies: + switchCompilerFlags: switchTitleNames_0: switchTitleNames_1: switchTitleNames_2: @@ -383,6 +491,7 @@ PlayerSettings: switchTitleNames_12: switchTitleNames_13: switchTitleNames_14: + switchTitleNames_15: switchPublisherNames_0: switchPublisherNames_1: switchPublisherNames_2: @@ -398,6 +507,7 @@ PlayerSettings: switchPublisherNames_12: switchPublisherNames_13: switchPublisherNames_14: + switchPublisherNames_15: switchIcons_0: {fileID: 0} switchIcons_1: {fileID: 0} switchIcons_2: {fileID: 0} @@ -413,6 +523,7 @@ PlayerSettings: switchIcons_12: {fileID: 0} switchIcons_13: {fileID: 0} switchIcons_14: {fileID: 0} + switchIcons_15: {fileID: 0} switchSmallIcons_0: {fileID: 0} switchSmallIcons_1: {fileID: 0} switchSmallIcons_2: {fileID: 0} @@ -428,6 +539,7 @@ PlayerSettings: switchSmallIcons_12: {fileID: 0} switchSmallIcons_13: {fileID: 0} switchSmallIcons_14: {fileID: 0} + switchSmallIcons_15: {fileID: 0} switchManualHTML: switchAccessibleURLs: switchLegalInformation: @@ -437,7 +549,6 @@ PlayerSettings: switchReleaseVersion: 0 switchDisplayVersion: 1.0.0 switchStartupUserAccount: 0 - switchTouchScreenUsage: 0 switchSupportedLanguagesMask: 0 switchLogoType: 0 switchApplicationErrorCodeCategory: @@ -479,6 +590,7 @@ PlayerSettings: switchNativeFsCacheSize: 32 switchIsHoldTypeHorizontal: 0 switchSupportedNpadCount: 8 + switchEnableTouchScreen: 1 switchSocketConfigEnabled: 0 switchTcpInitialSendBufferSize: 32 switchTcpInitialReceiveBufferSize: 64 @@ -490,6 +602,12 @@ PlayerSettings: switchSocketInitializeEnabled: 1 switchNetworkInterfaceManagerInitializeEnabled: 1 switchPlayerConnectionEnabled: 1 + switchUseNewStyleFilepaths: 1 + switchUseLegacyFmodPriorities: 0 + switchUseMicroSleepForYield: 1 + switchEnableRamDiskSupport: 0 + switchMicroSleepForYieldTime: 25 + switchRamDiskSpaceSize: 12 ps4NPAgeRating: 12 ps4NPTitleSecret: ps4NPTrophyPackPath: @@ -516,6 +634,7 @@ PlayerSettings: ps4ShareFilePath: ps4ShareOverlayImagePath: ps4PrivacyGuardImagePath: + ps4ExtraSceSysFile: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: @@ -541,6 +660,7 @@ PlayerSettings: ps4UseResolutionFallback: 0 ps4ReprojectionSupport: 0 ps4UseAudio3dBackend: 0 + ps4UseLowGarlicFragmentationMode: 1 ps4SocialScreenEnabled: 0 ps4ScriptOptimizationLevel: 0 ps4Audio3dVirtualSpeakerCount: 14 @@ -557,6 +677,9 @@ PlayerSettings: ps4disableAutoHideSplash: 0 ps4videoRecordingFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0 + ps4CompatibilityPS5: 0 + ps4AllowPS5Detection: 0 + ps4GPU800MHz: 1 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] ps4attribVROutputEnabled: 0 @@ -568,6 +691,7 @@ PlayerSettings: webGLMemorySize: 16 webGLExceptionSupport: 1 webGLNameFilesAsHashes: 0 + webGLShowDiagnostics: 0 webGLDataCaching: 1 webGLDebugSymbols: 0 webGLEmscriptenArgs: @@ -576,16 +700,45 @@ PlayerSettings: webGLAnalyzeBuildSize: 0 webGLUseEmbeddedResources: 0 webGLCompressionFormat: 1 + webGLWasmArithmeticExceptions: 0 webGLLinkerTarget: 1 webGLThreadsSupport: 0 - webGLWasmStreaming: 0 + webGLDecompressionFallback: 0 + webGLInitialMemorySize: 32 + webGLMaximumMemorySize: 2048 + webGLMemoryGrowthMode: 2 + webGLMemoryLinearGrowthStep: 16 + webGLMemoryGeometricGrowthStep: 0.2 + webGLMemoryGeometricGrowthCap: 96 + webGLPowerPreference: 2 scriptingDefineSymbols: {} + additionalCompilerArguments: {} platformArchitecture: {} - scriptingBackend: {} + scriptingBackend: + Android: 1 + Standalone: 1 il2cppCompilerConfiguration: {} - managedStrippingLevel: {} + il2cppCodeGeneration: {} + managedStrippingLevel: + Android: 1 + EmbeddedLinux: 1 + GameCoreScarlett: 1 + GameCoreXboxOne: 1 + Nintendo Switch: 1 + PS4: 1 + PS5: 1 + QNX: 1 + Stadia: 1 + VisionOS: 1 + WebGL: 1 + Windows Store Apps: 1 + XboxOne: 1 + iPhone: 1 + tvOS: 1 incrementalIl2cppBuild: {} - allowUnsafeCode: 0 + suppressCommonWarnings: 1 + allowUnsafeCode: 1 + useDeterministicCompilation: 1 additionalIl2CppArgs: scriptingRuntimeVersion: 1 gcIncremental: 0 @@ -620,6 +773,7 @@ PlayerSettings: metroFTAName: metroFTAFileTypes: [] metroProtocolName: + vcxProjDefaultLanguage: XboxOneProductId: XboxOneUpdateKey: XboxOneSandboxId: @@ -638,6 +792,7 @@ PlayerSettings: XboxOneCapability: [] XboxOneGameRating: {} XboxOneIsContentPackage: 0 + XboxOneEnhancedXboxCompatibilityMode: 0 XboxOneEnableGPUVariability: 0 XboxOneSockets: {} XboxOneSplashScreen: {fileID: 0} @@ -645,10 +800,8 @@ PlayerSettings: XboxOnePersistentLocalStorageSize: 0 XboxOneXTitleMemory: 8 XboxOneOverrideIdentityName: - vrEditorSettings: - daydream: - daydreamIconForeground: {fileID: 0} - daydreamIconBackground: {fileID: 0} + XboxOneOverrideIdentityPublisher: + vrEditorSettings: {} cloudServicesEnabled: UNet: 1 luminIcon: @@ -662,12 +815,22 @@ PlayerSettings: luminVersion: m_VersionCode: 1 m_VersionName: + hmiPlayerDataPath: + hmiForceSRGBBlit: 1 + embeddedLinuxEnableGamepadInput: 1 + hmiLogStartupTiming: 0 + hmiCpuConfiguration: apiCompatibilityLevel: 6 + activeInputHandler: 0 + windowsGamepadBackendHint: 0 cloudProjectId: framebufferDepthMemorylessMode: 0 + qualitySettingsNames: [] projectName: organizationId: cloudEnabled: 0 - enableNativePlatformBackendsForNewInputSystem: 0 - disableOldInputManagerSupport: 0 legacyClampBlendShapeWeights: 1 + hmiLoadingImage: {fileID: 0} + platformRequiresReadableAssets: 0 + virtualTexturingSupportEnabled: 0 + insecureHttpOption: 0 diff --git a/Unity.Mathematics.TestProject/ProjectSettings/ProjectVersion.txt b/Unity.Mathematics.TestProject/ProjectSettings/ProjectVersion.txt index 798259ba..78a77889 100644 --- a/Unity.Mathematics.TestProject/ProjectSettings/ProjectVersion.txt +++ b/Unity.Mathematics.TestProject/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2019.3.0f6 -m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf) +m_EditorVersion: 2022.3.7f1 +m_EditorVersionWithRevision: 2022.3.7f1 (b16b3b16c7a0) diff --git a/Unity.Mathematics.TestProject/ProjectSettings/UnityConnectSettings.asset b/Unity.Mathematics.TestProject/ProjectSettings/UnityConnectSettings.asset index fa0b1465..a88bee0f 100644 --- a/Unity.Mathematics.TestProject/ProjectSettings/UnityConnectSettings.asset +++ b/Unity.Mathematics.TestProject/ProjectSettings/UnityConnectSettings.asset @@ -9,6 +9,7 @@ UnityConnectSettings: m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events m_ConfigUrl: https://config.uca.cloud.unity3d.com + m_DashboardUrl: https://dashboard.unity3d.com m_TestInitMode: 0 CrashReportingSettings: m_EventUrl: https://perf-events.cloud.unity3d.com @@ -22,6 +23,7 @@ UnityConnectSettings: m_Enabled: 0 m_TestMode: 0 m_InitializeOnStartup: 1 + m_PackageRequiringCoreStatsPresent: 0 UnityAdsSettings: m_Enabled: 0 m_InitializeOnStartup: 1 diff --git a/src/.npmignore b/src/.npmignore index 72855d0d..e2e54865 100755 --- a/src/.npmignore +++ b/src/.npmignore @@ -10,7 +10,6 @@ QAReport.md QAReport.md.meta Unity.Mathematics.CodeGen* Unity.Mathematics.PerformanceTests* -Unity.Mathematics.Shaders* *.sln* *.db* **/*.csproj* diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 7f0d7db1..595ffd52 100755 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -1,30 +1,63 @@ # Changelog ## [Unreleased] +* Added a documentation remark for Random NextFloat and NextDouble methods with a min and max parameter. + +## [1.3.2] - 2024-01-11 + +### Fixed +* Fixed `math.hash` crash when using IL2CPP builds on Arm 32 bit devices. +* Fixed obsolete method usage warnings for `MatrixDrawer.CanCacheInspectorGUI` and `PrimitiveVectorDrawer.CanCacheInspectorGUI` in UNITY_2023_2_OR_NEWER. +* Updated minimum editor version to 2021.3 + +## [1.3.1] - 2023-07-12 + +### Added +* Added `math.square` to compute the square (x * x). +* Added `math.orthonormal_basis` to compute an orthonormal basis from a single unit length vector. +* Added `math.sign` for int, int2, int3 and int4. +* Added `math.chgsign` for float, float2, float3, and float4. +* Added `math.Euler` to convert a quaternion to Euler angles. +* Added `math.angle` to compute the angle between two unit quaternions. +* Added `math.rotation` to extract a quaternion rotation from a float3x3 (that may have scale). +* Added `math.mulScale` to scale columns of a float3x3 with scaling coefficients in a float3. +* Added `math.scaleMul` to scale rows of a float3x3 with scaling coefficients in a float3. +* Added `AffineTransform` type. +* Added `PI2`, `PIHALF`, `TAU`, `TODEGREES` and `TORADIANS` constants. + +### Changed +* `asfloat(uint)`, `asuint(float)`, `asint(float)` and other related methods are now faster in mono without Burst. Other methods which use these will see a performance improvement. +* Modified `quaternion.nlerp` to be branchless. +* More descriptive parameter names for many methods in `math` class. +* Made `Il2CppEagerStaticClassConstructionAttribute` internal to avoid conflicts with other definitions outside of the package. + +## [1.2.6] - 2022-02-11 + +### Changed +* Made Il2CppEagerStaticClassConstructionAttribute internal to avoid conflicts with other definitions outside of the package. + +## [1.2.5] - 2021-11-01 + +### Fixed +* Fixed property drawing when manually drawing a property that was hidden with [HideInInspector]. + +## [1.2.4] - 2021-09-22 + ### Added * Added `[Il2CppEagerStaticClassConstruction]` to Unity.Mathematics types to run static constructors at startup. This improves IL2CPP performance slightly for types that have static constructors. -* Added `math.square()` to compute the square (x * x). -* Added `math.orthonormal_basis()` to compute an orthonormal basis from a single unit length vector. -* Added `math.sign(x)` for int, int2, int3 and int4. ### Changed +* License file updated to satisfy Unity's package validation tests. * Changed noise documentation in comments to xmldoc comments. -### Deprecated -### Removed ### Fixed * Fixed Equals(object) override which did not check type before casting. This could cause exceptions to be thrown when the object did not match the expected type. * Fixed incorrect `math.tzcnt` documentation which mentioned leading zero counts instead of trailing zero counts. * Fixed `float2x2.Rotate` documentation to mention radians instead of degrees. - -### Internal (Not ready for production) +* Fixed documentation for methods and properties that were previously undocumented. ## [1.2.1] - 2020-08-06 -### Added -### Changed -### Deprecated -### Removed ### Fixed * Fixed warnings for meta files existing even though the files they represent did not exist. @@ -48,9 +81,6 @@ * Added some performance tests which can be run from the Unity test project. * Added `Random.CreateFromIndex()` to assist in creating Random instances from loop indices. -### Changed -### Deprecated -### Removed ### Fixed * Fixed documentation bug where `quaternion.RotateX/Y/Z` referred to a `float4x4` instead of quaternion. * Fixed code generation bugs which could cause Windows and Mac to generate different test code. diff --git a/src/Documentation~/4x4-matrices.md b/src/Documentation~/4x4-matrices.md new file mode 100644 index 00000000..266ec670 --- /dev/null +++ b/src/Documentation~/4x4-matrices.md @@ -0,0 +1,48 @@ +# 4×4 matrices + +To create a 4×4 transformation matrix, use the constructors in [`float4x4`](xref:Unity.Mathematics.float4x4) to assign one value to all elements of the matrix, or individually set all 16 elements directly: + + +```c# +// Unity Mathematics example +void Build4x4UnityMathematics() +{ + var c0 = new float4(1.0f, 0.0f, 0.0f, 0.0f); + var c1 = new float4(0.0f, 1.0f, 0.0f, 0.0f); + var c2 = new float4(0.0f, 0.0f, 1.0f, 0.0f); + var c3 = new float4(0.0f, 0.0f, 0.0f, 1.0f); + var m = new float4x4(c0, c1, c2, c3); +} +``` + +## Multiplying a 4×4 matrix + +Unity Mathematics and `UnityEngine` define the `*` operator differently. The `*` operator for [`float4x4`](xref:Unity.Mathematics.float4x4) implements componentwise multiplication. If you multiply a `float4x4` of all 1s with 0.5 on the diagonal, you get back the half identity because the upper and lower triangles of the matrix are multiplied by the respective zero entries from `f4x4_HalfIdentity`: + +```c# +// Unity Mathematics example +void OperatorMultiply4x4UnityMathematics() +{ + float4x4 result = f4x4_Ones * f4x4_HalfIdentity; + // result: + // 0.5, 0.0, 0.0, 0.0, + // 0.0, 0.5, 0.0, 0.0, + // 0.0, 0.0, 0.5, 0.0, + // 0.0, 0.0, 0.0, 0.5 +} +``` + +## Multiplying a 4×4 matrix and a 4D vector + +Use the [`math.mul`](xref:Unity.Mathematics.math.mul*) method to multiply a 4×4 matrix and a 4D vector. If you supply a `float4x4` as the first parameter and a `float4` as the second, it performs a 4×4 matrix multiplication with a 4×1 column vector, which returns a 4×1 column vector as a `float4`. + +`math.mul` can also multiply a 1×4 row vector by a 4×4 matrix to produce a 1×4 row vector by taking a `float4` as the first parameter and a `float4×4` as the second. Unity Mathematics stores the row vector in a `float4` and it isn't treated as a separate type. + +```c# +// Unity Mathematics example +void Multiply4x4AndVector4UnityMathematics() +{ + float4 result1 = math.mul(f4x4, f4); // 4x4 * 4x1 = 4x1 + float4 result2 = math.mul(f4, f4x4); // 1x4 * 4x4 = 1x4 +} +``` \ No newline at end of file diff --git a/src/Documentation~/TableOfContents.md b/src/Documentation~/TableOfContents.md new file mode 100644 index 00000000..1dc7d3b2 --- /dev/null +++ b/src/Documentation~/TableOfContents.md @@ -0,0 +1,8 @@ +* [Unity Mathematics](index.md) +* [Compatibility with Mathf](compatibility.md) +* [Getting started](getting-started.md) +* Common operations + * [4×4 matrices](4x4-matrices.md) + * [Vector multiplication](vector-multiplication.md) + * [Quaternion multiplication](quaternion-multiplication.md) + * [Random numbers](random-numbers.md) diff --git a/src/Documentation~/compatibility.md b/src/Documentation~/compatibility.md new file mode 100644 index 00000000..9113e0a4 --- /dev/null +++ b/src/Documentation~/compatibility.md @@ -0,0 +1,17 @@ +# Compatibility with `UnityEngine` mathematics + +If you want to Burst-compile your project, it's best practice to use the Unity Mathematics package by default and only use `Mathf` when necessary. Unity Mathematics isn't implemented in the same way as the [`UnityEngine.Mathf`](https://docs.unity3d.com/ScriptReference/Mathf.html) struct in the core Unity engine. Because of this, if your application relies on the specific behaviors of `Mathf`, you'll have to reimplement them to get similar behavior in Unity Mathematics. + +>[!IMPORTANT] +>For performance reasons, if your project uses the Mono compiler, you should continue to use the mathematical operations in `Mathf`, rather than Unity Mathematics. + +You can use both `Mathf` and Unity Mathematics methods in your project, but it might impact on the performance of your application because the conversions between the `UnityEngine` and `Unity.Mathematics` types such as `Vector3` to `float3` and vice-versa are performance-intensive. + +## Porting `UnityEngine` code to `Unity.Mathematics` + +If you want to migrate code from `UnityEngine` to `Unity.Mathematics`, you need to make the following changes first: + +* Update `UnityEngine` types to `Unity.Mathematics` types. For example, [`Vector4`](https://docs.unity3d.com/ScriptReference/Vector4.html) to [`float4`](xref:Unity.Mathematics.float4), and [`Quaternion`](https://docs.unity3d.com/ScriptReference/Quaternion.html) to [`quaternion`](xref:Unity.Mathematics.quaternion). These examples aren't exhaustive: see the [Scripting API reference](https://docs.unity3d.com/Packages/com.unity.mathematics@latest/index.html?subfolder=/api/index.html) for the full list of Unity Mathematics types available. +* Update any operators involved in matrices or vectors. For example, the `Matrix4x4` multiplication operator implements matrix multiplication, but the `float4x4` multiplication operator implements componentwise multiplication. +* Degrees to radians +* How your code generates random numbers. `Random` in `Unity.Mathematics` works differently to [`Random`](https://docs.unity3d.com/ScriptReference/Random.html) in `UnityEngine`. You can completely control random number generation with `Random` in `Unity.Mathematics`, and it's instanced, rather than static. It's also exclusive with its upper bound, which is important to bear in mind if you want to convert `UnityEngine` code which is sensitive to the bounds. For more information, see the documentation on [Random numbers](random-numbers.md). diff --git a/src/Documentation~/getting-started.md b/src/Documentation~/getting-started.md new file mode 100644 index 00000000..7ed246e5 --- /dev/null +++ b/src/Documentation~/getting-started.md @@ -0,0 +1,29 @@ +# Getting started + +To use Unity Mathematics, add `using Unity.Mathematics` to your code: + +```C# +using static Unity.Mathematics.math; +namespace MyNamespace +{ + using Unity.Mathematics; + + ... + var v1 = float3(1,2,3); + var v2 = float3(4,5,6); + v1 = normalize(v1); + v2 = normalize(v2); + var v3 = dot(v1, v2); + ... +} +``` + +## Naming convention + +In C# `int` and `float` are built-in types. The Burst compiler extends this set of built-in types to also include vectors, matrices, and quaternions. These types are built-in because the Burst compiler already has implementations of these types, and so can use them to generate better code than for custom types. + +To signify that these types are built-in their type names are in all lower case. The operators on these built-in types in [`Unity.Mathematics.math`](xref:Unity.Mathematics.math) are intrinsics and are always in lower case. + +There are no plans to extend the set of intrinsic types beyond the current set of vectors (`typeN`), matrices (`typeNxN`) and quaternions (`quaternion`). + +This convention has the added benefit of making the library highly compatible with shader code and makes porting or sharing code between the two almost frictionless. diff --git a/src/Documentation~/index.md b/src/Documentation~/index.md new file mode 100644 index 00000000..0b61abb2 --- /dev/null +++ b/src/Documentation~/index.md @@ -0,0 +1,30 @@ +# Unity Mathematics + +Unity Mathematics is a C# math library that provides vector types and math functions that have a shader-like +syntax, similar to [SIMD](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) or [HLSL](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl). The [Burst compiler](https://docs.unity3d.com/Packages/com.unity.burst@latest) uses Unity Mathematics to compile C#/IL code into highly efficient native code. + +It implements the following vector and matrix types: + +* floatN, quaternion +* float3×3, float4×4 + +Plus elementary functions: +* min, max, fabs, etc. +* sin, cos, sqrt, normalize, dot, cross, etc. + +## Installation + +You can install the Mathematics package through Unity's Package Manager. For more information, see the Unity User Manual documentation on [Adding and removing packages](https://docs.unity3d.com/Manual/upm-ui-actions.html). + +>[!IMPORTANT] +>From Unity 6.5, Unity Mathematics is a built-in module of the core Editor and Engine and its APIs are available to user code by default in the `Unity.Mathematics` namespace, with no package installation required. Accordingly, from Unity 6.5 the Unity Mathematics API documentation is part of the [core Scripting API reference](https://docs.unity3d.com/ScriptReference/Unity.Mathematics.math.html), and the user manual is integrated with [the core Unity user manual](https://docs.unity3d.com/Manual/unity-mathematics.html). + +### Editor config + +Unity Mathematics uses [editorconfig](http://editorconfig.org/) to keep files formatted for EOL and spaces. + +Your IDE should have support for `editorconfig`. If it doesn't, you can get the extension for it here: + +* [VS2015/VS2017 EditorConfig extension](https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig) +* [Visual Studio Code EditorConfig extension](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) +* [SublimeText EditorConfig extension](https://github.com/sindresorhus/editorconfig-sublime) diff --git a/src/Documentation~/mathematics.md b/src/Documentation~/mathematics.md deleted file mode 100644 index 992642fc..00000000 --- a/src/Documentation~/mathematics.md +++ /dev/null @@ -1,79 +0,0 @@ -# Unity.Mathematics - -A C# math library providing vector types and math functions with a shader like -syntax. Used by the Burst compiler to compile C#/IL to highly efficient -native code. - -The main goal of this library is to provide a friendly Math API familiar to SIMD and graphic/shaders developers, using the well known `float4`, `float3` types...etc. with all intrinsics functions provided by a static class `math` that can be imported easily into your C# program with `using static Unity.Mathematics.math`. - -In addition to this, the Burst compiler is able to recognize these types and provide the optimized SIMD type for the running CPU on all supported platforms (x64, ARMv7a...etc.) - -NOTICE: The API is a work in progress and we may introduce breaking changes (API and underlying behavior) - -## Usage - -You can use this library in your Unity game by using the Package Manager and referencing the package `com.unity.mathematics`. See the forum [Welcome](https://forum.unity.com/threads/welcome.522627) page for more details. - -```C# -using static Unity.Mathematics.math; -namespace MyNamespace -{ - using Unity.Mathematics; - - ... - var v1 = float3(1,2,3); - var v2 = float3(4,5,6); - v1 = normalize(v1); - v2 = normalize(v2); - var v3 = dot(v1, v2); - ... -} -``` - -## Building - -Open the `src\Unity.Mathematics.sln` under Visual Studio 2015 or MonoDevelop and compile in Debug\Release. - -## Contributing - -We don't yet accept PR on this repository. See the FAQ below. - -The project is using [editorconfig](http://editorconfig.org/) to keep files correctly formatted for EOL and spaces. - -We assume that your IDE has support for `editorconfig`, you can download the following extensions if your IDE is listed: - -- [VS2015/VS2017 EditorConfig extension](https://marketplace.visualstudio.com/items?itemName=EditorConfigTeam.EditorConfig) -- [Visual Studio Code EditorConfig extension](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) -- [SublimeText EditorConfig extension](https://github.com/sindresorhus/editorconfig-sublime) - -## Frequently Asked Question - -### Why developing another Math library instead of using existing Unity Vector3...etc.? - -After years of feedback and experience with the previous API, we believe that providing an API that is closer to the way graphics developers have been using math libraries should better help its adoption and the ease of its usage. HLSL / GLSL math library is a very well designed, well understood math library leading to greater consistency. - -### Why not using `System.Numerics.Vectors`? - -Mainly for the reason mentioned above, `System.Numerics.Vectors` is in many ways similar to our previous Vector library (more object oriented than graphics programming oriented). -Also the fact that our Burst compiler is able to recognize a lot more patterns for SIMD types and math intrinsics makes it easier to work with a dedicated API that reflects this ability. - -### Naming convention - -In C# `int` and `float` are considered builtin types. Burst extends this set of bultin types to also include vectors, matrices and quaternions. These types are bultin in the sense that Burst knows about them and is be able to generate better code using these types than what would be possible with equivalent code using custom types. - -To signify that these types are bultin their type names are in all lower case. The operators on these bultin types found in `Unity.Mathematics.math` are considered intrinsics and are thus always in lower case. - -There are no plans to extend the set of intrinsic types beyond the current set of vectors (`typeN`), matrices (`typeNxN`) and quaternions (`quaternion`). - -This convention has the added benefit of making the library highly compatible with shader code and makes porting or sharing code between the two almost frictionless. - -### Why can't we send a PR yet? - -We are working on providing a Contributor License Agreement (CLA) with a sign-over functionality and our UCL License doesn't cover this yet. - -## Licensing - -Unity Companion License (“License”) Software Copyright © 2019 Unity Technologies ApS - -For licensing details see [LICENSE.md](LICENSE.md) - diff --git a/src/Documentation~/quaternion-multiplication.md b/src/Documentation~/quaternion-multiplication.md new file mode 100644 index 00000000..d6f70f4d --- /dev/null +++ b/src/Documentation~/quaternion-multiplication.md @@ -0,0 +1,17 @@ +# Quaternion multiplication + +To rotate a quaternion, use the [`AxisAngle`](xref:Unity.Mathematics.quaternion.AxisAngle*) method. You need to specify the axis of rotation and the angle of rotation, in that order. All are in radians rather than degrees. `math.mul` multiplies the quaternion, just as with [matrices](4x4-matrices.md) and vectors. + +```c# +// Unity Mathematics example +void QuaternionMultiplicationUnityMathematics() +{ + var axis = new float3(0.0f, 1.0f, 0.0f); + var q = quaternion.AxisAngle(axis,math.radians(45.0f)); + var orientation = quaternion.Euler( + math.radians(45.0f), + math.radians(90.0f), + math.radians(180.0f)); + var result = math.mul(q, orientation); +} +``` diff --git a/src/Documentation~/random-numbers.md b/src/Documentation~/random-numbers.md new file mode 100644 index 00000000..5a09e9d9 --- /dev/null +++ b/src/Documentation~/random-numbers.md @@ -0,0 +1,21 @@ +## Random numbers + +To generate random numbers, you must create and manage the random number generator state yourself with the [`Random`](xref:Unity.Mathematics.Random) struct. You can control the random number generator state explicitly, which is useful if you're using parallel code, or if you want to make sure that one source of random numbers is seeded differently than another source. You can also have as many `Random` instances as you like. + +Once you set up the state, use [`NextFloat`](xref:Unity.Mathematics.Random.NextFloat) to get random floats. By default it returns random numbers between `[0, 1)`, exclusive: + +```c# +// Unity Mathematics example +void RandomNumberUnityMathematics() +{ + // Choose some non-zero seed and set up the random number generator state. + uint seed = 1; + Unity.Mathematics.Random rng = new Unity.Mathematics.Random(seed); + + // [0, 1) exclusive + float randomFloat1 = rng.NextFloat(); + + // [-5, 5) exclusive + float randomFloat2 = rng.NextFloat(-5.0f, 5.0f); +} +``` diff --git a/src/Documentation~/vector-multiplication.md b/src/Documentation~/vector-multiplication.md new file mode 100644 index 00000000..123fe6bb --- /dev/null +++ b/src/Documentation~/vector-multiplication.md @@ -0,0 +1,16 @@ +# Vector multiplication + +To multiply vectors, use the `*`: + +```c# +// Unity Mathematics example +void ComponentwiseVectorMultiplyUnityMathematics() +{ + var v0 = new float4(2.0f, 4.0f, 6.0f, 8.0f); + var v1 = new float4(1.0f, -1.0f, 1.0f, -1.0f); + var result = v0 * v1; + // result == new float4(2.0f, -4.0f, 6.0f, -8.0f). +} +``` + +This is a common way of writing [SIMD](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) code, which applies a single instruction to multiple data elements. Other operators such as addition, subtraction, and division work in the same way. \ No newline at end of file diff --git a/src/LICENSE.md b/src/LICENSE.md index 311c9904..1f5c0f44 100755 --- a/src/LICENSE.md +++ b/src/LICENSE.md @@ -1,30 +1,4 @@ -Unity Companion License (“License”) -Software Copyright © 2019 Unity Technologies ApS - -Unity Technologies ApS (“Unity”) grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available under this License (“Software”), subject to the following terms and conditions: - -1. Unity Companion Use Only. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity content authoring and rendering engine software license (“Engine License”). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted, and in no event may the Software be used for competitive analysis or to develop a competing product or service. - -2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way. - -3. Ownership & Grant Back to You. +com.unity.mathematics copyright © 2023 Unity Technologies ApS -3.1 You own your content. In this License, “derivative works” means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content. - -3.2 Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity. - -3.3 You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License. - -4. Trademarks. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates (“Trademarks”). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at https://unity3d.com/public-relations/brand. - -5. Notices & Third-Party Rights. This License, including the copyright notice associated with the Software, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity “third-party notices” or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms. - -6. DISCLAIMER, LIMITATION OF LIABILITY. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -7. USE IS ACCEPTANCE and License Versions. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License. - -8. Use in Compliance with Law and Termination. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License. - -9. Severability. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect. - -10. Governing Law and Venue. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License (“Dispute”). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute. \ No newline at end of file +Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license). +Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. \ No newline at end of file diff --git a/src/Tests/Tests/Shared/TestAffineTransform.cs b/src/Tests/Tests/Shared/TestAffineTransform.cs new file mode 100644 index 00000000..b663fd65 --- /dev/null +++ b/src/Tests/Tests/Shared/TestAffineTransform.cs @@ -0,0 +1,173 @@ +using NUnit.Framework; +using static Unity.Mathematics.math; +using Burst.Compiler.IL.Tests; + +namespace Unity.Mathematics.Tests +{ + [TestFixture] + class TestAffineTransform + { + [TestCompiler] + public static void affine_transform_construct_from_float3x3() + { + const float tolerance = 1e-6f; + + float3x3 m3x3 = TestMatrix.test3x3_zyx; + AffineTransform tx = AffineTransform(m3x3); + + float3x3 testM3x3 = float3x3(tx); + + TestUtils.AreEqual(m3x3, testM3x3, tolerance); + } + + [TestCompiler] + public static void affine_transform_construct_from_float3x4() + { + const float tolerance = 1e-6f; + + float3x4 m3x4 = float3x4(TestMatrix.test3x3_zyx.c0, TestMatrix.test3x3_zyx.c1, TestMatrix.test3x3_zyx.c2, float3(1f, 2f, 3f)); + AffineTransform tx = AffineTransform(m3x4); + + float3x4 testM3x4 = float3x4(tx); + + TestUtils.AreEqual(m3x4, testM3x4, tolerance); + } + + [TestCompiler] + public static void affine_transform_construct_from_float4x4() + { + const float tolerance = 1e-6f; + + float4x4 m4x4 = TestMatrix.test4x4_zyx; + AffineTransform tx = AffineTransform(m4x4); + + float4x4 testM4x4 = float4x4(tx); + + TestUtils.AreEqual(m4x4, testM4x4, tolerance); + } + + [TestCompiler] + public static void affine_transform_construct_from_RigidTransform() + { + const float tolerance = 1e-6f; + + RigidTransform r = RigidTransform(TestMatrix.test4x4_xyz); + AffineTransform tx = AffineTransform(r); + + TestUtils.AreEqual(math.float3x3(r.rot), tx.rs, tolerance); + TestUtils.AreEqual(r.pos, tx.t, tolerance); + } + + [TestCompiler] + public static void affine_transform_inverse() + { + const float tolerance = 1e-6f; + + var tx = AffineTransform(float3(5f, 6f, 7f), normalize(math.float4(1f, 2f, 3f, 4f)), float3(2f, 3f, 4f)); + var invTx = inverse(tx); + + TestUtils.AreEqual(float4x4.identity, mul(tx, invTx), tolerance); + } + + [TestCompiler] + public static void affine_transform_inverse_zero_rs_returns_zero() + { + const float tolerance = 1e-30f; + + var tx = AffineTransform(float3(5f, 6f, 7f), normalize(float4(1f, 2f, 3f, 4f)), float3.zero); + var invTx = inverse(tx); + + TestUtils.AreEqual(float3x4.zero, invTx, tolerance); + } + + [TestCompiler] + public static void affine_transform_inverse_pico_scale() + { + // slightly larger tolerance (vs 1e-6f) for PS4 + const float tolerance = 2e-6f; + + var tx = AffineTransform(float3(5f, 6f, 7f), normalize(float4(1f, 2f, 3f, 4f)), float3(1e-12f, 1e-12f, 1e-12f)); + var invTx = inverse(tx); + + TestUtils.AreEqual(float4x4.identity, mul(tx, invTx), tolerance); + } + + [TestCompiler] + public static void affine_transform_inverse_singular() + { + // it needs a bit larger tolerance for singular + // since it uses the svd iterative solver + const float tolerance = 1e-1f; + + var tx = AffineTransform(float3(5f, 6f, 7f), normalize(float4(1f, 2f, 3f, 4f)), float3(0f, 3f, 4f)); + var invTx = inverse(tx); + + // pseudo inverse penrose #1 test + var testTx = mul(mul(tx, invTx), tx); + TestUtils.AreEqual(float4x4(tx), float4x4(testTx), tolerance); + } + + [TestCompiler] + public static void affine_transform_decompose() + { + const float tolerance = 1e-6f; + + var tx = AffineTransform(float3(5f, 6f, 7f), normalize(float4(1f, 2f, 3f, 4f)), float3(2f, 3f, 4f)); + decompose(tx, out var t, out var r, out var s); + + // Recompose matrix + var testTx = AffineTransform(t, r, s); + TestUtils.AreEqual(float4x4(tx), float4x4(testTx), tolerance); + } + + [TestCompiler] + public static void affine_transform_mul_vector() + { + float4x4 m = TestMatrix.test4x4_xyz; + AffineTransform tx = AffineTransform(m); + + float3 vector = float3(1.1f, -2.2f, 3.5f); + + float4 mvector0 = mul(m, float4(vector, 0f)); + float4 txvector0 = mul(tx, float4(vector, 0f)); + TestUtils.AreEqual(mvector0, txvector0, 0.0001f); + + float4 mvector1 = mul(m, float4(vector, 1f)); + float4 txvector1 = mul(tx, float4(vector, 1f)); + TestUtils.AreEqual(mvector1, txvector1, 0.0001f); + } + + [TestCompiler] + public static void affine_transform_rotate_vector() + { + float3x3 m = TestMatrix.test3x3_xyz; + AffineTransform tx = AffineTransform(m); + + float3 vector = float3(1.1f, -2.2f, 3.5f); + + float3 mvector0 = mul(m, vector); + float3 txvector0 = rotate(tx, vector); + TestUtils.AreEqual(mvector0, txvector0, 0.0001f); + } + + [TestCompiler] + public static void affine_transform_transform_point() + { + float4x4 m = float4x4(TestMatrix.test3x3_zyx, float3(1f, 2f, 3f)); + AffineTransform tx = AffineTransform(m); + + float3 pt = float3(1.1f, -2.2f, 3.5f); + + float3 mPt0 = transform(m, pt); + float3 txPt0 = transform(tx, pt); + TestUtils.AreEqual(mPt0, txPt0, 0.0001f); + } + + [TestCompiler] + public static void affine_transform_zero() + { + TestUtils.AreEqual(float3x3.zero, AffineTransform.zero.rs); + TestUtils.AreEqual(float3.zero, AffineTransform.zero.t); + } + } +} diff --git a/src/Unity.Mathematics.Shaders/hlsl.cs.meta b/src/Tests/Tests/Shared/TestAffineTransform.cs.meta similarity index 83% rename from src/Unity.Mathematics.Shaders/hlsl.cs.meta rename to src/Tests/Tests/Shared/TestAffineTransform.cs.meta index 9b45b04e..01d27e82 100644 --- a/src/Unity.Mathematics.Shaders/hlsl.cs.meta +++ b/src/Tests/Tests/Shared/TestAffineTransform.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f1451d4ccf06c1c4aa11ee0097e37220 +guid: 534e18de5e70ccf468bf46c917dfdac4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/Tests/Tests/Shared/TestBool2.gen.cs b/src/Tests/Tests/Shared/TestBool2.gen.cs index 3546ddd3..11c32ff2 100644 --- a/src/Tests/Tests/Shared/TestBool2.gen.cs +++ b/src/Tests/Tests/Shared/TestBool2.gen.cs @@ -427,7 +427,7 @@ public static void bool2_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool2_EqualsObjectOverride() { TestUtils.IsFalse(new bool2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool2x2.gen.cs b/src/Tests/Tests/Shared/TestBool2x2.gen.cs index dbfd2fa1..1646031c 100644 --- a/src/Tests/Tests/Shared/TestBool2x2.gen.cs +++ b/src/Tests/Tests/Shared/TestBool2x2.gen.cs @@ -395,7 +395,7 @@ public static void bool2x2_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool2x2_EqualsObjectOverride() { TestUtils.IsFalse(new bool2x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool2x3.gen.cs b/src/Tests/Tests/Shared/TestBool2x3.gen.cs index e0f8f2d3..8157a008 100644 --- a/src/Tests/Tests/Shared/TestBool2x3.gen.cs +++ b/src/Tests/Tests/Shared/TestBool2x3.gen.cs @@ -395,7 +395,7 @@ public static void bool2x3_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool2x3_EqualsObjectOverride() { TestUtils.IsFalse(new bool2x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool2x4.gen.cs b/src/Tests/Tests/Shared/TestBool2x4.gen.cs index 4200e9ee..fdfdb454 100644 --- a/src/Tests/Tests/Shared/TestBool2x4.gen.cs +++ b/src/Tests/Tests/Shared/TestBool2x4.gen.cs @@ -395,7 +395,7 @@ public static void bool2x4_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool2x4_EqualsObjectOverride() { TestUtils.IsFalse(new bool2x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool3.gen.cs b/src/Tests/Tests/Shared/TestBool3.gen.cs index e6b69c43..ee345f1e 100644 --- a/src/Tests/Tests/Shared/TestBool3.gen.cs +++ b/src/Tests/Tests/Shared/TestBool3.gen.cs @@ -431,7 +431,7 @@ public static void bool3_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool3_EqualsObjectOverride() { TestUtils.IsFalse(new bool3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool3x2.gen.cs b/src/Tests/Tests/Shared/TestBool3x2.gen.cs index d41f918c..816c30fd 100644 --- a/src/Tests/Tests/Shared/TestBool3x2.gen.cs +++ b/src/Tests/Tests/Shared/TestBool3x2.gen.cs @@ -395,7 +395,7 @@ public static void bool3x2_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool3x2_EqualsObjectOverride() { TestUtils.IsFalse(new bool3x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool3x3.gen.cs b/src/Tests/Tests/Shared/TestBool3x3.gen.cs index 4a2301d9..6c5b1b9b 100644 --- a/src/Tests/Tests/Shared/TestBool3x3.gen.cs +++ b/src/Tests/Tests/Shared/TestBool3x3.gen.cs @@ -395,7 +395,7 @@ public static void bool3x3_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool3x3_EqualsObjectOverride() { TestUtils.IsFalse(new bool3x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool3x4.gen.cs b/src/Tests/Tests/Shared/TestBool3x4.gen.cs index c0981361..8d7d6245 100644 --- a/src/Tests/Tests/Shared/TestBool3x4.gen.cs +++ b/src/Tests/Tests/Shared/TestBool3x4.gen.cs @@ -395,7 +395,7 @@ public static void bool3x4_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool3x4_EqualsObjectOverride() { TestUtils.IsFalse(new bool3x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool4.gen.cs b/src/Tests/Tests/Shared/TestBool4.gen.cs index 69e823ab..c2c8be05 100644 --- a/src/Tests/Tests/Shared/TestBool4.gen.cs +++ b/src/Tests/Tests/Shared/TestBool4.gen.cs @@ -435,7 +435,7 @@ public static void bool4_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool4_EqualsObjectOverride() { TestUtils.IsFalse(new bool4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool4x2.gen.cs b/src/Tests/Tests/Shared/TestBool4x2.gen.cs index 0a2a54ca..40511294 100644 --- a/src/Tests/Tests/Shared/TestBool4x2.gen.cs +++ b/src/Tests/Tests/Shared/TestBool4x2.gen.cs @@ -395,7 +395,7 @@ public static void bool4x2_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool4x2_EqualsObjectOverride() { TestUtils.IsFalse(new bool4x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool4x3.gen.cs b/src/Tests/Tests/Shared/TestBool4x3.gen.cs index 8be23641..ea0d9fe2 100644 --- a/src/Tests/Tests/Shared/TestBool4x3.gen.cs +++ b/src/Tests/Tests/Shared/TestBool4x3.gen.cs @@ -395,7 +395,7 @@ public static void bool4x3_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool4x3_EqualsObjectOverride() { TestUtils.IsFalse(new bool4x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestBool4x4.gen.cs b/src/Tests/Tests/Shared/TestBool4x4.gen.cs index c83c5d8d..11b5e424 100644 --- a/src/Tests/Tests/Shared/TestBool4x4.gen.cs +++ b/src/Tests/Tests/Shared/TestBool4x4.gen.cs @@ -395,7 +395,7 @@ public static void bool4x4_operator_logical_not() TestUtils.AreEqual(r3, !a3); } - [TestCase] + [TestCase /* For player builds */] public static void bool4x4_EqualsObjectOverride() { TestUtils.IsFalse(new bool4x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble2.gen.cs b/src/Tests/Tests/Shared/TestDouble2.gen.cs index cd44e120..f07b51f5 100644 --- a/src/Tests/Tests/Shared/TestDouble2.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble2.gen.cs @@ -1050,7 +1050,7 @@ public static void double2_shuffle_result_4() TestUtils.AreEqual(double4(2, 0, 0, 0), shuffle(a, b, ShuffleComponent.RightX, ShuffleComponent.LeftX, ShuffleComponent.LeftX, ShuffleComponent.LeftX)); } - [TestCase] + [TestCase /* For player builds */] public static void double2_EqualsObjectOverride() { TestUtils.IsFalse(new double2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble2x2.gen.cs b/src/Tests/Tests/Shared/TestDouble2x2.gen.cs index c7fc90d5..5b035267 100644 --- a/src/Tests/Tests/Shared/TestDouble2x2.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble2x2.gen.cs @@ -945,7 +945,7 @@ public static void double2x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double2x2_EqualsObjectOverride() { TestUtils.IsFalse(new double2x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble2x3.gen.cs b/src/Tests/Tests/Shared/TestDouble2x3.gen.cs index d95bba8d..0b5cb5cf 100644 --- a/src/Tests/Tests/Shared/TestDouble2x3.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble2x3.gen.cs @@ -938,7 +938,7 @@ public static void double2x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double2x3_EqualsObjectOverride() { TestUtils.IsFalse(new double2x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble2x4.gen.cs b/src/Tests/Tests/Shared/TestDouble2x4.gen.cs index aac05afe..c519d6f4 100644 --- a/src/Tests/Tests/Shared/TestDouble2x4.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble2x4.gen.cs @@ -940,7 +940,7 @@ public static void double2x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double2x4_EqualsObjectOverride() { TestUtils.IsFalse(new double2x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble3.gen.cs b/src/Tests/Tests/Shared/TestDouble3.gen.cs index cc53ddbf..59b1478b 100644 --- a/src/Tests/Tests/Shared/TestDouble3.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble3.gen.cs @@ -1057,7 +1057,7 @@ public static void double3_shuffle_result_4() TestUtils.AreEqual(double4(2, 5, 0, 4), shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftX, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void double3_EqualsObjectOverride() { TestUtils.IsFalse(new double3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble3x2.gen.cs b/src/Tests/Tests/Shared/TestDouble3x2.gen.cs index 382e68b6..0fd677a3 100644 --- a/src/Tests/Tests/Shared/TestDouble3x2.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble3x2.gen.cs @@ -938,7 +938,7 @@ public static void double3x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double3x2_EqualsObjectOverride() { TestUtils.IsFalse(new double3x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble3x3.gen.cs b/src/Tests/Tests/Shared/TestDouble3x3.gen.cs index 56364618..d066be3d 100644 --- a/src/Tests/Tests/Shared/TestDouble3x3.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble3x3.gen.cs @@ -955,7 +955,7 @@ public static void double3x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double3x3_EqualsObjectOverride() { TestUtils.IsFalse(new double3x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble3x4.gen.cs b/src/Tests/Tests/Shared/TestDouble3x4.gen.cs index c54ef5be..03ea5969 100644 --- a/src/Tests/Tests/Shared/TestDouble3x4.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble3x4.gen.cs @@ -944,7 +944,7 @@ public static void double3x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double3x4_EqualsObjectOverride() { TestUtils.IsFalse(new double3x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble4.gen.cs b/src/Tests/Tests/Shared/TestDouble4.gen.cs index 2d907e2a..0344dae9 100644 --- a/src/Tests/Tests/Shared/TestDouble4.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble4.gen.cs @@ -1064,7 +1064,7 @@ public static void double4_shuffle_result_4() TestUtils.AreEqual(double4(3, 7, 1, 5), shuffle(a, b, ShuffleComponent.LeftW, ShuffleComponent.RightW, ShuffleComponent.LeftY, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void double4_EqualsObjectOverride() { TestUtils.IsFalse(new double4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble4x2.gen.cs b/src/Tests/Tests/Shared/TestDouble4x2.gen.cs index 0e02dc29..80b2e856 100644 --- a/src/Tests/Tests/Shared/TestDouble4x2.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble4x2.gen.cs @@ -940,7 +940,7 @@ public static void double4x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double4x2_EqualsObjectOverride() { TestUtils.IsFalse(new double4x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble4x3.gen.cs b/src/Tests/Tests/Shared/TestDouble4x3.gen.cs index 66d6e952..6debf3f6 100644 --- a/src/Tests/Tests/Shared/TestDouble4x3.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble4x3.gen.cs @@ -944,7 +944,7 @@ public static void double4x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double4x3_EqualsObjectOverride() { TestUtils.IsFalse(new double4x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestDouble4x4.gen.cs b/src/Tests/Tests/Shared/TestDouble4x4.gen.cs index bd638617..3fcaff74 100644 --- a/src/Tests/Tests/Shared/TestDouble4x4.gen.cs +++ b/src/Tests/Tests/Shared/TestDouble4x4.gen.cs @@ -969,7 +969,7 @@ public static void double4x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void double4x4_EqualsObjectOverride() { TestUtils.IsFalse(new double4x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat2.gen.cs b/src/Tests/Tests/Shared/TestFloat2.gen.cs index b14288cc..885cbf2c 100644 --- a/src/Tests/Tests/Shared/TestFloat2.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat2.gen.cs @@ -1050,7 +1050,7 @@ public static void float2_shuffle_result_4() TestUtils.AreEqual(float4(2, 0, 0, 0), shuffle(a, b, ShuffleComponent.RightX, ShuffleComponent.LeftX, ShuffleComponent.LeftX, ShuffleComponent.LeftX)); } - [TestCase] + [TestCase /* For player builds */] public static void float2_EqualsObjectOverride() { TestUtils.IsFalse(new float2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat2x2.gen.cs b/src/Tests/Tests/Shared/TestFloat2x2.gen.cs index 5b818da7..b56dd1c0 100644 --- a/src/Tests/Tests/Shared/TestFloat2x2.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat2x2.gen.cs @@ -945,7 +945,7 @@ public static void float2x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float2x2_EqualsObjectOverride() { TestUtils.IsFalse(new float2x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat2x3.gen.cs b/src/Tests/Tests/Shared/TestFloat2x3.gen.cs index 8a93998c..ee756468 100644 --- a/src/Tests/Tests/Shared/TestFloat2x3.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat2x3.gen.cs @@ -938,7 +938,7 @@ public static void float2x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float2x3_EqualsObjectOverride() { TestUtils.IsFalse(new float2x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat2x4.gen.cs b/src/Tests/Tests/Shared/TestFloat2x4.gen.cs index d959a802..769a761e 100644 --- a/src/Tests/Tests/Shared/TestFloat2x4.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat2x4.gen.cs @@ -940,7 +940,7 @@ public static void float2x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float2x4_EqualsObjectOverride() { TestUtils.IsFalse(new float2x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat3.gen.cs b/src/Tests/Tests/Shared/TestFloat3.gen.cs index 48c5b1a4..29bbf5a0 100644 --- a/src/Tests/Tests/Shared/TestFloat3.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat3.gen.cs @@ -1057,7 +1057,7 @@ public static void float3_shuffle_result_4() TestUtils.AreEqual(float4(2, 5, 0, 4), shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftX, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void float3_EqualsObjectOverride() { TestUtils.IsFalse(new float3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat3x2.gen.cs b/src/Tests/Tests/Shared/TestFloat3x2.gen.cs index a497e7be..a9fcca5b 100644 --- a/src/Tests/Tests/Shared/TestFloat3x2.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat3x2.gen.cs @@ -938,7 +938,7 @@ public static void float3x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float3x2_EqualsObjectOverride() { TestUtils.IsFalse(new float3x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat3x3.gen.cs b/src/Tests/Tests/Shared/TestFloat3x3.gen.cs index 37e72288..7561ab09 100644 --- a/src/Tests/Tests/Shared/TestFloat3x3.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat3x3.gen.cs @@ -955,7 +955,7 @@ public static void float3x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float3x3_EqualsObjectOverride() { TestUtils.IsFalse(new float3x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat3x4.gen.cs b/src/Tests/Tests/Shared/TestFloat3x4.gen.cs index 57e75392..b688cda8 100644 --- a/src/Tests/Tests/Shared/TestFloat3x4.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat3x4.gen.cs @@ -944,7 +944,7 @@ public static void float3x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float3x4_EqualsObjectOverride() { TestUtils.IsFalse(new float3x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat4.gen.cs b/src/Tests/Tests/Shared/TestFloat4.gen.cs index eec3bd88..1e0d3ab1 100644 --- a/src/Tests/Tests/Shared/TestFloat4.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat4.gen.cs @@ -1064,7 +1064,7 @@ public static void float4_shuffle_result_4() TestUtils.AreEqual(float4(3, 7, 1, 5), shuffle(a, b, ShuffleComponent.LeftW, ShuffleComponent.RightW, ShuffleComponent.LeftY, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void float4_EqualsObjectOverride() { TestUtils.IsFalse(new float4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat4x2.gen.cs b/src/Tests/Tests/Shared/TestFloat4x2.gen.cs index ef36f471..9b0cd505 100644 --- a/src/Tests/Tests/Shared/TestFloat4x2.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat4x2.gen.cs @@ -940,7 +940,7 @@ public static void float4x2_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float4x2_EqualsObjectOverride() { TestUtils.IsFalse(new float4x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat4x3.gen.cs b/src/Tests/Tests/Shared/TestFloat4x3.gen.cs index f14618d1..f2d4f21f 100644 --- a/src/Tests/Tests/Shared/TestFloat4x3.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat4x3.gen.cs @@ -944,7 +944,7 @@ public static void float4x3_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float4x3_EqualsObjectOverride() { TestUtils.IsFalse(new float4x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestFloat4x4.gen.cs b/src/Tests/Tests/Shared/TestFloat4x4.gen.cs index cc444939..1e706448 100644 --- a/src/Tests/Tests/Shared/TestFloat4x4.gen.cs +++ b/src/Tests/Tests/Shared/TestFloat4x4.gen.cs @@ -969,7 +969,7 @@ public static void float4x4_operator_postfix_dec() TestUtils.AreEqual(r3, a3--); } - [TestCase] + [TestCase /* For player builds */] public static void float4x4_EqualsObjectOverride() { TestUtils.IsFalse(new float4x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt2.gen.cs b/src/Tests/Tests/Shared/TestInt2.gen.cs index 78c07923..75f6aba0 100644 --- a/src/Tests/Tests/Shared/TestInt2.gen.cs +++ b/src/Tests/Tests/Shared/TestInt2.gen.cs @@ -1334,7 +1334,7 @@ public static void int2_shuffle_result_4() TestUtils.AreEqual(int4(2, 0, 0, 0), shuffle(a, b, ShuffleComponent.RightX, ShuffleComponent.LeftX, ShuffleComponent.LeftX, ShuffleComponent.LeftX)); } - [TestCase] + [TestCase /* For player builds */] public static void int2_EqualsObjectOverride() { TestUtils.IsFalse(new int2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt2x2.gen.cs b/src/Tests/Tests/Shared/TestInt2x2.gen.cs index 517c4586..754451d3 100644 --- a/src/Tests/Tests/Shared/TestInt2x2.gen.cs +++ b/src/Tests/Tests/Shared/TestInt2x2.gen.cs @@ -1229,7 +1229,7 @@ public static void int2x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int2x2_EqualsObjectOverride() { TestUtils.IsFalse(new int2x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt2x3.gen.cs b/src/Tests/Tests/Shared/TestInt2x3.gen.cs index e6b88941..8e25e359 100644 --- a/src/Tests/Tests/Shared/TestInt2x3.gen.cs +++ b/src/Tests/Tests/Shared/TestInt2x3.gen.cs @@ -1222,7 +1222,7 @@ public static void int2x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int2x3_EqualsObjectOverride() { TestUtils.IsFalse(new int2x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt2x4.gen.cs b/src/Tests/Tests/Shared/TestInt2x4.gen.cs index f9650035..3fd7b8b3 100644 --- a/src/Tests/Tests/Shared/TestInt2x4.gen.cs +++ b/src/Tests/Tests/Shared/TestInt2x4.gen.cs @@ -1224,7 +1224,7 @@ public static void int2x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int2x4_EqualsObjectOverride() { TestUtils.IsFalse(new int2x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt3.gen.cs b/src/Tests/Tests/Shared/TestInt3.gen.cs index 29f8ec66..7dac46ed 100644 --- a/src/Tests/Tests/Shared/TestInt3.gen.cs +++ b/src/Tests/Tests/Shared/TestInt3.gen.cs @@ -1341,7 +1341,7 @@ public static void int3_shuffle_result_4() TestUtils.AreEqual(int4(2, 5, 0, 4), shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftX, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void int3_EqualsObjectOverride() { TestUtils.IsFalse(new int3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt3x2.gen.cs b/src/Tests/Tests/Shared/TestInt3x2.gen.cs index 11b9edb4..db159df9 100644 --- a/src/Tests/Tests/Shared/TestInt3x2.gen.cs +++ b/src/Tests/Tests/Shared/TestInt3x2.gen.cs @@ -1222,7 +1222,7 @@ public static void int3x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int3x2_EqualsObjectOverride() { TestUtils.IsFalse(new int3x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt3x3.gen.cs b/src/Tests/Tests/Shared/TestInt3x3.gen.cs index e5b804e0..5d82264a 100644 --- a/src/Tests/Tests/Shared/TestInt3x3.gen.cs +++ b/src/Tests/Tests/Shared/TestInt3x3.gen.cs @@ -1239,7 +1239,7 @@ public static void int3x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int3x3_EqualsObjectOverride() { TestUtils.IsFalse(new int3x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt3x4.gen.cs b/src/Tests/Tests/Shared/TestInt3x4.gen.cs index 254a797c..f9b43392 100644 --- a/src/Tests/Tests/Shared/TestInt3x4.gen.cs +++ b/src/Tests/Tests/Shared/TestInt3x4.gen.cs @@ -1228,7 +1228,7 @@ public static void int3x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int3x4_EqualsObjectOverride() { TestUtils.IsFalse(new int3x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt4.gen.cs b/src/Tests/Tests/Shared/TestInt4.gen.cs index 065bb609..3c712b61 100644 --- a/src/Tests/Tests/Shared/TestInt4.gen.cs +++ b/src/Tests/Tests/Shared/TestInt4.gen.cs @@ -1348,7 +1348,7 @@ public static void int4_shuffle_result_4() TestUtils.AreEqual(int4(3, 7, 1, 5), shuffle(a, b, ShuffleComponent.LeftW, ShuffleComponent.RightW, ShuffleComponent.LeftY, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void int4_EqualsObjectOverride() { TestUtils.IsFalse(new int4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt4x2.gen.cs b/src/Tests/Tests/Shared/TestInt4x2.gen.cs index 564c7aa7..8eaa8828 100644 --- a/src/Tests/Tests/Shared/TestInt4x2.gen.cs +++ b/src/Tests/Tests/Shared/TestInt4x2.gen.cs @@ -1224,7 +1224,7 @@ public static void int4x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int4x2_EqualsObjectOverride() { TestUtils.IsFalse(new int4x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt4x3.gen.cs b/src/Tests/Tests/Shared/TestInt4x3.gen.cs index 6fdd2f07..c8662413 100644 --- a/src/Tests/Tests/Shared/TestInt4x3.gen.cs +++ b/src/Tests/Tests/Shared/TestInt4x3.gen.cs @@ -1228,7 +1228,7 @@ public static void int4x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int4x3_EqualsObjectOverride() { TestUtils.IsFalse(new int4x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestInt4x4.gen.cs b/src/Tests/Tests/Shared/TestInt4x4.gen.cs index 87f3887b..408529a2 100644 --- a/src/Tests/Tests/Shared/TestInt4x4.gen.cs +++ b/src/Tests/Tests/Shared/TestInt4x4.gen.cs @@ -1253,7 +1253,7 @@ public static void int4x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void int4x4_EqualsObjectOverride() { TestUtils.IsFalse(new int4x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestMath.cs b/src/Tests/Tests/Shared/TestMath.cs index ffe458f6..d22d82a7 100644 --- a/src/Tests/Tests/Shared/TestMath.cs +++ b/src/Tests/Tests/Shared/TestMath.cs @@ -3838,5 +3838,363 @@ public static void orthonormal_basis_double() TestUtils.IsTrue(OrthonormalBasisSquaredError(v1, v2, v3) < kOrthonormalBasisSqErrorTolerance); } } + + [TestCompiler] + public static void chgsign_float() + { + float c = chgsign(1f, -1f); + TestUtils.AreEqual(-1f, c); + + c = chgsign(1f, 1f); + TestUtils.AreEqual(1f, c); + + c = chgsign(-1f, -1f); + TestUtils.AreEqual(1f, c); + + c = chgsign(-1f, 1f); + TestUtils.AreEqual(-1f, c); + + c = chgsign(-1f, 0f); + TestUtils.AreEqual(-1f, c); + + c = chgsign(-1f, -0f); + TestUtils.AreEqual(1f, c); + + c = chgsign(1f, TestUtils.SignedFloatQNaN()); + TestUtils.AreEqual(-1f, c); + + c = chgsign(-1f, TestUtils.SignedFloatQNaN()); + TestUtils.AreEqual(1f, c); + + c = chgsign(1f, TestUtils.UnsignedFloatQNaN()); + TestUtils.AreEqual(1f, c); + + c = chgsign(-1f, TestUtils.UnsignedFloatQNaN()); + TestUtils.AreEqual(-1f, c); + + c = chgsign(1f, INFINITY); + TestUtils.AreEqual(1f, c); + + c = chgsign(-1f, INFINITY); + TestUtils.AreEqual(-1f, c); + + c = chgsign(1f, -INFINITY); + TestUtils.AreEqual(-1f, c); + + c = chgsign(-1f, -INFINITY); + TestUtils.AreEqual(1f, c); + + c = chgsign(TestUtils.UnsignedFloatQNaN(), 1f); + TestUtils.IsTrue(isnan(c)); + TestUtils.AreEqual(asuint(TestUtils.UnsignedFloatQNaN()), asuint(c)); + + c = chgsign(TestUtils.UnsignedFloatQNaN(), -1f); + TestUtils.IsTrue(isnan(c)); + TestUtils.AreEqual(asuint(TestUtils.SignedFloatQNaN()), asuint(c)); + + c = chgsign(0f, 1f); + TestUtils.AreEqual(0f, c); + TestUtils.AreEqual(0u, asuint(c)); + + c = chgsign(0f, -1f); + TestUtils.AreEqual(0f, c); + TestUtils.AreEqual(asuint(TestUtils.SignedFloatZero()), asuint(c)); + } + + [TestCompiler] + public static void chgsign_float2() + { + float2 c = chgsign(float2(1f, -2f), float2(-1f, 23.548f)); + TestUtils.AreEqual(float2(-1f, -2f), c); + + c = chgsign(float2(-1f), float2(-1f, 1f)); + TestUtils.AreEqual(float2(1f, -1f), c); + + c = chgsign(float2(-1f), float2(1f, -1f)); + TestUtils.AreEqual(float2(-1f, 1f), c); + + c = chgsign(float2(-1f), float2(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN())); + TestUtils.AreEqual(float2(1f, -1f), c); + + c = chgsign(float2(-1f), float2(TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN())); + TestUtils.AreEqual(float2(-1f, 1f), c); + + c = chgsign(float2(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN()), float2(-1f, 1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float2(TestUtils.UnsignedFloatQNaN())), asuint(c)); + + c = chgsign(float2(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN()), float2(1f, -1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float2(TestUtils.SignedFloatQNaN())), asuint(c)); + + c = chgsign(float2(TestUtils.SignedFloatZero(), 0f), float2(TestUtils.SignedFloatZero(), 0f)); + TestUtils.AreEqual(float2.zero, c); + TestUtils.AreEqual(uint2.zero, asuint(c)); + + c = chgsign(float2(TestUtils.SignedFloatZero(), 0f), float2(0f, TestUtils.SignedFloatZero())); + TestUtils.AreEqual(float2.zero, c); + TestUtils.AreEqual(asuint(math.float2(TestUtils.SignedFloatZero())), asuint(c)); + } + + [TestCompiler] + public static void chgsign_float3() + { + float3 c = chgsign(float3(1f, -2f, 3f), float3(-1f, 23.548f, -0f)); + TestUtils.AreEqual(float3(-1f, -2f, -3f), c); + + c = chgsign(float3(-1f), float3(-1f, 1f, -1f)); + TestUtils.AreEqual(float3(1f, -1f, 1f), c); + + c = chgsign(float3(-1f), float3(1f, -1f, 1f)); + TestUtils.AreEqual(float3(-1f, 1f, -1f), c); + + c = chgsign(float3(-1f), float3(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN())); + TestUtils.AreEqual(float3(1f, -1f, 1f), c); + + c = chgsign(float3(-1f), float3(TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN())); + TestUtils.AreEqual(float3(-1f, 1f, -1f), c); + + c = chgsign(float3(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN()), float3(-1f, 1f, -1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float3(TestUtils.UnsignedFloatQNaN())), asuint(c)); + + c = chgsign(float3(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN()), float3(1f, -1f, 1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float3(TestUtils.SignedFloatQNaN())), asuint(c)); + + c = chgsign(float3(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero()), float3(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero())); + TestUtils.AreEqual(float3.zero, c); + TestUtils.AreEqual(uint3.zero, asuint(c)); + + c = chgsign(float3(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero()), float3(0f, TestUtils.SignedFloatZero(), 0f)); + TestUtils.AreEqual(float3.zero, c); + TestUtils.AreEqual(asuint(math.float3(TestUtils.SignedFloatZero())), asuint(c)); + } + + [TestCompiler] + public static void chgsign_float4() + { + float4 c = chgsign(float4(1f, 2f, 3f, -4f), float4(-1f, 0f, -0f, -23.56f)); + TestUtils.AreEqual(float4(-1f, 2f, -3f, 4f), c); + + c = chgsign(float4(-1f), float4(-1f, 1f, -1f, 1f)); + TestUtils.AreEqual(float4(1f, -1f, 1f, -1f), c); + + c = chgsign(float4(-1f), float4(1f, -1f, 1f, -1f)); + TestUtils.AreEqual(float4(-1f, 1f, -1f, 1f), c); + + c = chgsign(float4(-1f), float4(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN())); + TestUtils.AreEqual(float4(1f, -1f, 1f, -1f), c); + + c = chgsign(float4(-1f), float4(TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN())); + TestUtils.AreEqual(float4(-1f, 1f, -1f, 1f), c); + + c = chgsign(float4(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN()), float4(-1f, 1f, -1f, 1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float4(TestUtils.UnsignedFloatQNaN())), asuint(c)); + + c = chgsign(float4(TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN(), TestUtils.SignedFloatQNaN(), TestUtils.UnsignedFloatQNaN()), float4(1f, -1f, 1f, -1f)); + TestUtils.IsTrue(all(isnan(c))); + TestUtils.AreEqual(asuint(float4(TestUtils.SignedFloatQNaN())), asuint(c)); + + c = chgsign(float4(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero(), 0f), float4(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero(), 0f)); + TestUtils.AreEqual(float4.zero, c); + TestUtils.AreEqual(uint4.zero, asuint(c)); + + c = chgsign(float4(TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero(), 0f), float4(0f, TestUtils.SignedFloatZero(), 0f, TestUtils.SignedFloatZero())); + TestUtils.AreEqual(float4.zero, c); + TestUtils.AreEqual(asuint(math.float4(TestUtils.SignedFloatZero())), asuint(c)); + } + + [TestCompiler] + public static unsafe void quaternion_to_euler() + { + const float epsilon = 0.0045f; + const float PI_div_6 = PI / 6f; + const int testAngleCount = 13 * 13 * 13 * 20; + + float3* testAngles = stackalloc float3[testAngleCount]; + + int idx = 0; + for (int i = 0; i < 13; ++i) + { + float x = -PI + i * PI; + for (int j = 0; j < 13; ++j) + { + float y = -PI + j * PI_div_6; + for (int k = 0; k < 13; ++k) + { + float z = -PI + k * PI_div_6; + for (int l = 0; l < 20; ++l) + { + testAngles[idx++] = float3(x, y, z) * (0.99f + l * 0.001f); + } + } + } + } + + for (int order = 0; order < 6; ++order) + { + for (int i = 0; i < testAngleCount; ++i) + { + // We cannot directly compare Euler angles, as different angles may represent the same rotation, + // so we have to transform them back to quats to test. + // We also need to create our initial test quaternion, as what we generated was euler angles. + quaternion expected = TestRefEulerToQuat(testAngles[i], math.RotationOrder.Default); + + float3 actualEulers = Euler(expected, (math.RotationOrder)order); + quaternion actualQuat = TestRefEulerToQuat(actualEulers, (math.RotationOrder)order); + + float error = angle(expected, actualQuat); + TestUtils.AreEqual(0f, error, epsilon); + } + } + } + + static quaternion TestRefEulerToQuat(float3 angle, math.RotationOrder order) + { + float3 halfRot = angle * 0.5f; + sincos(halfRot, out float3 s, out float3 c); + + quaternion qX = quaternion(s.x, 0f, 0f, c.x); + quaternion qY = quaternion(0f, s.y, 0f, c.y); + quaternion qZ = quaternion(0f, 0f, s.z, c.z); + + switch (order) + { + case math.RotationOrder.XYZ: + return mul(mul(qZ, qY), qX); + case math.RotationOrder.XZY: + return mul(mul(qY, qZ), qX); + case math.RotationOrder.YXZ: + return mul(mul(qZ, qX), qY); + case math.RotationOrder.YZX: + return mul(mul(qX, qZ), qY); + case math.RotationOrder.ZXY: + return mul(mul(qY, qX), qZ); + case math.RotationOrder.ZYX: + return mul(mul(qX, qY), qZ); + default: + return quaternion(float4(1f)); + } + } + + [TestCompiler] + public static void mulScale() + { + var tolerance = 1e-5f; + + // Random matrix. + var m = new float3x3( + 0.891724169254302978516f, 0.156217902898788452148f, 0.492261469364166259766f, + 0.562758803367614746094f, 0.00122839550022035837173f, 0.437942296266555786133f, + 0.2576503753662109375f, 0.200372591614723205566f, 0.515525519847869873047f); + + // Random scale. + var scale = new float3(0.235540181398391723633f, 0.215966641902923583984f, 0.533130943775177001953f); + var actual = math.mulScale(m, scale); + var expected = new float3x3( + 0.210036873817443847656f, 0.0337378568947315216064f, 0.262439817190170288086f, + 0.132552310824394226074f, 0.000265292444964870810509f, 0.233480587601661682129f, + 0.0606870166957378387451f, 0.043273795396089553833f, 0.274842619895935058594f); + + TestUtils.AreEqual(expected, actual, tolerance); + } + + [TestCompiler] + public static void scaleMul() + { + var tolerance = 1e-5f; + + // Random matrix, same as in mulScale test. + var m = new float3x3( + 0.891724169254302978516f, 0.156217902898788452148f, 0.492261469364166259766f, + 0.562758803367614746094f, 0.00122839550022035837173f, 0.437942296266555786133f, + 0.2576503753662109375f, 0.200372591614723205566f, 0.515525519847869873047f); + + // Random scale, same as in mulScale test. + var scale = new float3(0.235540181398391723633f, 0.215966641902923583984f, 0.533130943775177001953f); + var actual = math.scaleMul(scale, m); + var expected = new float3x3( + 0.210036873817443847656f, 0.0367955937981605529785f, 0.115947358310222625732f, + 0.121537126600742340088f, 0.000265292444964870810509f, 0.0945809260010719299316f, + 0.137361392378807067871f, 0.106824830174446105957f, 0.274842619895935058594f); + + TestUtils.AreEqual(expected, actual, tolerance); + } + + [TestCompiler] + public static void piDoubleConstants() + { + var expectedPi = 3.141592653589793116; + TestUtils.AreEqual(expectedPi, PI_DBL); + TestUtils.AreEqual(expectedPi * 0.5, PIHALF_DBL); + TestUtils.AreEqual(expectedPi * 2.0, PI2_DBL); + TestUtils.AreEqual(expectedPi * 2.0, TAU_DBL); + } + + [TestCompiler] + public static void piSingleConstants() + { + var expectedPi = 3.141592653589793116f; + TestUtils.AreEqual(expectedPi, PI); + TestUtils.AreEqual(expectedPi * 0.5f, PIHALF); + TestUtils.AreEqual(expectedPi * 2.0f, PI2); + TestUtils.AreEqual(expectedPi * 2.0f, TAU); + } + + [TestCompiler] + public static void toDegreesConstants() + { + TestUtils.AreEqual(360.0, PI2_DBL * TODEGREES_DBL); + TestUtils.AreEqual(360.0, TAU_DBL * TODEGREES_DBL); + TestUtils.AreEqual(180.0, PI_DBL * TODEGREES_DBL); + TestUtils.AreEqual(90.0, PIHALF_DBL * TODEGREES_DBL); + + TestUtils.AreEqual(360.0f, PI2 * TODEGREES); + TestUtils.AreEqual(360.0f, TAU * TODEGREES); + TestUtils.AreEqual(180.0f, PI * TODEGREES); + TestUtils.AreEqual(90.0f, PIHALF * TODEGREES); + } + + [TestCompiler] + public static void toRadiansConstants() + { + TestUtils.AreEqual(PI2_DBL, 360.0 * TORADIANS_DBL); + TestUtils.AreEqual(TAU_DBL, 360.0 * TORADIANS_DBL); + TestUtils.AreEqual(PI_DBL, 180.0 * TORADIANS_DBL); + TestUtils.AreEqual(PIHALF_DBL, 90.0 * TORADIANS_DBL); + + TestUtils.AreEqual(PI2, 360.0f * TORADIANS); + TestUtils.AreEqual(TAU, 360.0f * TORADIANS); + TestUtils.AreEqual(PI, 180.0f * TORADIANS); + TestUtils.AreEqual(PIHALF, 90.0f * TORADIANS); + } + + [TestCompiler] + public static void degreesConversionGivesSameResult() + { + int n = 360; + + for (int i = 0; i <= n; ++i) + { + double radians = math.unlerp((double)0, (double)n, (double)i) * PI_DBL; + TestUtils.AreEqual(math.degrees(radians), radians * TODEGREES_DBL); + TestUtils.AreEqual(math.degrees((float)radians), (float)radians * TODEGREES); + } + } + + [TestCompiler] + public static void radiansConversionGivesSameResult() + { + int n = 360; + + for (int i = 0; i <= n; ++i) + { + double degrees = (double)i; + TestUtils.AreEqual(math.radians(degrees), degrees * TORADIANS_DBL); + TestUtils.AreEqual(math.radians((float)degrees), (float)degrees * TORADIANS); + } + } } } diff --git a/src/Tests/Tests/Shared/TestMatrix.cs b/src/Tests/Tests/Shared/TestMatrix.cs index 5bc45842..558ce482 100644 --- a/src/Tests/Tests/Shared/TestMatrix.cs +++ b/src/Tests/Tests/Shared/TestMatrix.cs @@ -1169,5 +1169,46 @@ public static void float3x3_from_float4x4_without_new() TestUtils.AreEqual(expected, float3x3(f4x4)); } + + [TestCompiler] + public static void float3x3_pseudoinverse_non_singular() + { + const float kTolerance = 1e-5f; + + // A random 3x3 matrix, non-singular, generated from octave. + var a = new float3x3( + 0.806710600852966308594f, 0.985506594181060791016f, 0.593669593334197998047f, + 0.0869068726897239685059f, 0.754145503044128417969f, 0.222692146897315979004f, + 0.917483031749725341797f, 0.443894535303115844727f, 0.138771042227745056152f); + + // The regular inverse of a, as computed by octave. + var expected = new float3x3( + -0.0299495235085487365723f, -0.654392063617706298828f, 1.17825806140899658203f, + -0.992458224296569824219f, 2.23384380340576171875f, 0.661037027835845947266f, + 3.37264156341552734375f, -2.81901407241821289063f, -2.69841933250427246094f); + + TestUtils.AreEqual(expected, pseudoinverse(a), kTolerance); + TestUtils.AreEqual(expected, inverse(a), kTolerance); + } + + [TestCompiler] + public static void float3x3_pseudoinverse_singular() + { + const float kTolerance = 1e-5f; + + // A singular matrix. + var a = new float3x3( + 0.0548239313066005706787f, 0.462397903203964233398f, 0.0501357726752758026123f, + 0.0548239313066005706787f, 0.462397903203964233398f, 0.0501357726752758026123f, + 0.938165545463562011719f, 0.542225778102874755859f, 0.10684439539909362793f); + + // The pseudoinverse computed by octave. + var expected = new float3x3( + -0.675357639789581298828f, -0.675357699394226074219f, 1.14166188240051269531f, + 1.15268361568450927734f, 1.15268361568450927734f, -0.140613287687301635742f, + 0.0803283303976058959961f, 0.0803283303976058959961f, 0.0484490357339382171631f); + + TestUtils.AreEqual(expected, pseudoinverse(a), kTolerance); + } } } diff --git a/src/Tests/Tests/Shared/TestPlane.cs b/src/Tests/Tests/Shared/TestPlane.cs index 91e60044..2fbd3251 100644 --- a/src/Tests/Tests/Shared/TestPlane.cs +++ b/src/Tests/Tests/Shared/TestPlane.cs @@ -263,4 +263,4 @@ public static void CreateFromUnitNormalAndPointInPlane() TestUtils.AreEqual(expected, p.NormalAndDistance, Tolerance); } } -} \ No newline at end of file +} diff --git a/src/Tests/Tests/Shared/TestQuaternion.cs b/src/Tests/Tests/Shared/TestQuaternion.cs index 9bd5ebf6..301725ee 100644 --- a/src/Tests/Tests/Shared/TestQuaternion.cs +++ b/src/Tests/Tests/Shared/TestQuaternion.cs @@ -89,7 +89,7 @@ public static void quaternion_axis_angle_consistency() } [TestCompiler] - public static void quaternion_euler() + public static void euler_to_quaternion() { float3 test_angles = TestMatrix.test_angles; quaternion q0 = quaternion.Euler(test_angles); @@ -344,5 +344,121 @@ public static void quaternion_EqualsObjectOverride() TestUtils.IsFalse(new quaternion().Equals((object) new int())); TestUtils.IsTrue(new quaternion().Equals((object) new quaternion())); } + + [TestCase] + public static void quaternion_angle() + { + // Test variations of angles + for (int i = 0; i < 18; ++i) + { + for (int j = 0; j < 18; ++j) + { + float angle1 = radians(i * 10f); + float angle2 = radians(j * 10f); + + quaternion q1 = quaternion.Euler(0f, angle1, 0f); + quaternion q2 = quaternion.Euler(0f, angle2, 0f); + TestUtils.AreEqual(abs(angle2 - angle1), math.angle(q1, q2), 1e-5f); + } + } + + quaternion q = quaternion.identity; + float angle = math.angle(q, q); + TestUtils.AreEqual(0f, angle); + + quaternion nq = -q.value; + angle = math.angle(q, nq); + TestUtils.AreEqual(0f, angle); + + // Nearly normalized quaternion to self is zero + q = new quaternion(0.6244676f, -0.7761726f, -0.06790633f, -0.05463386f); // dot(q, q) = 0.999999816753 + angle = math.angle(q, q); + TestUtils.AreEqual(0f, angle); + + // Nearly normalized quaternion to negative self is zero + nq = -q.value; // dot(q, nq) = -0.999999816753 + angle = math.angle(q, nq); + TestUtils.AreEqual(0f, angle); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_identity() + { + const float tolerance = 1e-5f; + var q = rotation(float3x3.identity); + TestUtils.AreEqual(quaternion.identity, q, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_uniform_scale() + { + const float tolerance = 1e-5f; + var random = new Random(6173u); + var expectedQuaternion = random.NextQuaternionRotation(); + var m = new float3x3(expectedQuaternion); + m = mul(m, float3x3.Scale(5.18f)); + var actualQuaternion = rotation(m); + TestUtils.AreEqual(0.0f, angle(actualQuaternion, expectedQuaternion) % PI * 2.0f, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_nonuniform_scale() + { + const float tolerance = 1e-5f; + var m = new float3x3( + 2.0f, 0.0f, 0.0f, + 0.0f, 1.5f, 0.0f, + 0.0f, 0.0f, 3.1f); + var q = rotation(m); + TestUtils.AreEqual(quaternion.identity, q, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_negative_scale_x() + { + const float tolerance = 1e-5f; + var random = new Random(281u); + var expectedQuaternion = random.NextQuaternionRotation(); + var m = new float3x3(expectedQuaternion); + m = mul(m, float3x3.Scale(-1.5f, 0.2f, 51.281f)); + var actualQuaternion = rotation(m); + TestUtils.AreEqual(0.0f, angle(actualQuaternion, expectedQuaternion) % PI * 2.0f, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_negative_scale_y() + { + const float tolerance = 1e-5f; + var random = new Random(10000u); + var expectedQuaternion = random.NextQuaternionRotation(); + var m = new float3x3(expectedQuaternion); + m = mul(m, float3x3.Scale(1.5f, -0.2f, 51.281f)); + var actualQuaternion = rotation(m); + TestUtils.AreEqual(0.0f, angle(actualQuaternion, expectedQuaternion) % PI * 2.0f, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_negative_scale_z() + { + const float tolerance = 1e-5f; + var random = new Random(9891712u); + var expectedQuaternion = random.NextQuaternionRotation(); + var m = new float3x3(expectedQuaternion); + m = mul(m, float3x3.Scale(1.5f, 0.2f, -51.281f)); + var actualQuaternion = rotation(m); + TestUtils.AreEqual(0.0f, angle(actualQuaternion, expectedQuaternion) % PI * 2.0f, tolerance); + } + + [TestCompiler] + public static void quaternion_rotation_from_3x3_with_negative_nonuniform_scale() + { + const float tolerance = 1e-5f; + var random = new Random(912u); + var expectedQuaternion = random.NextQuaternionRotation(); + var m = new float3x3(expectedQuaternion); + m = mul(m, float3x3.Scale(-1.5f, -0.2f, -51.281f)); + var actualQuaternion = rotation(m); + TestUtils.AreEqual(0.0f, angle(actualQuaternion, expectedQuaternion) % PI * 2.0f, tolerance); + } } } diff --git a/src/Tests/Tests/Shared/TestSvd.cs b/src/Tests/Tests/Shared/TestSvd.cs new file mode 100644 index 00000000..e75cf04f --- /dev/null +++ b/src/Tests/Tests/Shared/TestSvd.cs @@ -0,0 +1,185 @@ +using System.Collections.Generic; +using NUnit.Framework; +using Burst.Compiler.IL.Tests; + +namespace Unity.Mathematics.Tests +{ + [TestFixture] + public class TestSvd + { + const float k_SVDTolerance = 1e-4f; + + static bool QuaternionEquals(quaternion expected, quaternion actual, float tolerance) => + (math.lengthsq(expected) == 0f && math.lengthsq(actual) == 0f) || math.abs(math.dot(expected, actual)) > (1f - tolerance); + + // Validate Penrose condition that [aba = a] + static void ValidatePenrose1(in float3x3 a, in float3x3 b) + { + var testA = math.mul(math.mul(a, b), a); + + TestUtils.AreEqual(a.c0.x, testA.c0.x, k_SVDTolerance); + TestUtils.AreEqual(a.c0.y, testA.c0.y, k_SVDTolerance); + TestUtils.AreEqual(a.c0.z, testA.c0.z, k_SVDTolerance); + TestUtils.AreEqual(a.c1.x, testA.c1.x, k_SVDTolerance); + TestUtils.AreEqual(a.c1.y, testA.c1.y, k_SVDTolerance); + TestUtils.AreEqual(a.c1.z, testA.c1.z, k_SVDTolerance); + TestUtils.AreEqual(a.c2.x, testA.c2.x, k_SVDTolerance); + TestUtils.AreEqual(a.c2.y, testA.c2.y, k_SVDTolerance); + TestUtils.AreEqual(a.c2.z, testA.c2.z, k_SVDTolerance); + } + + // Validate Penrose condition that [transpose(ab) = ab] + static void ValidatePenrose2(in float3x3 a, in float3x3 b) + { + var ab = math.mul(a, b); + var testAB = math.transpose(ab); + + TestUtils.AreEqual(ab.c0.x, testAB.c0.x, k_SVDTolerance); + TestUtils.AreEqual(ab.c0.y, testAB.c0.y, k_SVDTolerance); + TestUtils.AreEqual(ab.c0.z, testAB.c0.z, k_SVDTolerance); + TestUtils.AreEqual(ab.c1.x, testAB.c1.x, k_SVDTolerance); + TestUtils.AreEqual(ab.c1.y, testAB.c1.y, k_SVDTolerance); + TestUtils.AreEqual(ab.c1.z, testAB.c1.z, k_SVDTolerance); + TestUtils.AreEqual(ab.c2.x, testAB.c2.x, k_SVDTolerance); + TestUtils.AreEqual(ab.c2.y, testAB.c2.y, k_SVDTolerance); + TestUtils.AreEqual(ab.c2.z, testAB.c2.z, k_SVDTolerance); + } + + static void ValidateSingular(in float3x3 a) => + TestUtils.AreEqual(0.0f, math.determinant(a), k_SVDTolerance); + + [TestCompiler] + public static void CanSVDInverseNonSingularFloat3x3() + { + var mat = math.float3x3( + math.float3(9f, 1f, 2f), + math.float3(3f, 8f, 4f), + math.float3(5f, 6f, 7f) + ); + + var inv = svd.svdInverse(mat); + var testIdentity = math.mul(mat, inv); + + TestUtils.AreEqual(1f, testIdentity.c0.x, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c0.y, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c0.z, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c1.x, k_SVDTolerance); + TestUtils.AreEqual(1f, testIdentity.c1.y, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c1.z, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c2.x, k_SVDTolerance); + TestUtils.AreEqual(0f, testIdentity.c2.y, k_SVDTolerance); + TestUtils.AreEqual(1f, testIdentity.c2.z, k_SVDTolerance); + } + + [TestCompiler] + public static void CanSVDInverseFloat3x3With_NullColumn() + { + var mat = math.float3x3( + math.float3(9f, 1f, 0f), + math.float3(3f, 8f, 0f), + math.float3(5f, 6f, 0f) + ); + + ValidateSingular(mat); + var inv = svd.svdInverse(mat); + + ValidatePenrose1(mat, inv); + ValidatePenrose1(inv, mat); + ValidatePenrose2(mat, inv); + ValidatePenrose2(inv, mat); + } + + [TestCompiler] + public static void CanSVDInverseFloat3x3With_NullRow() + { + var mat = math.float3x3( + math.float3(9f, 1f, 2f), + math.float3(0f, 0f, 0f), + math.float3(5f, 6f, 7f) + ); + + ValidateSingular(mat); + var inv = svd.svdInverse(mat); + + ValidatePenrose1(mat, inv); + ValidatePenrose1(inv, mat); + ValidatePenrose2(mat, inv); + ValidatePenrose2(inv, mat); + } + + [TestCompiler] + public static void CanSVDInverseFloat3x3With_LinearDependentColumn() + { + var mat = math.float3x3( + math.float3(9f, 4f, 2f), + math.float3(3f, 8f, 4f), + math.float3(5f, 14f, 7f) + ); + + ValidateSingular(mat); + var inv = svd.svdInverse(mat); + + ValidatePenrose1(mat, inv); + ValidatePenrose1(inv, mat); + ValidatePenrose2(mat, inv); + ValidatePenrose2(inv, mat); + } + + [TestCompiler] + public static void CanSVDInverseFloat3x3With_LinearDependentRow() + { + var mat = math.float3x3( + math.float3(9f, 1f, 2f), + math.float3(10f, 12f, 14f), + math.float3(5f, 6f, 7f) + ); + + ValidateSingular(mat); + var inv = svd.svdInverse(mat); + + ValidatePenrose1(mat, inv); + ValidatePenrose1(inv, mat); + ValidatePenrose2(mat, inv); + ValidatePenrose2(inv, mat); + } + + [TestCompiler] + public static void CanSVDInverseFloat3x3With_RotatedZeroScale() + { + var m102030 = math.float3x3(quaternion.Euler(math.radians(10f), math.radians(20f), math.radians(30f))); + var parent = math.mulScale(m102030, math.float3(1f, 1f, 0f)); + var mat = math.mul(parent, m102030); + + ValidateSingular(mat); + var inv = svd.svdInverse(mat); + + ValidatePenrose1(mat, inv); + ValidatePenrose1(inv, mat); + ValidatePenrose2(mat, inv); + ValidatePenrose2(inv, mat); + } + + // Case 928598: The errors appear, when GameObject has a child with ParticleSystem which is rotated along the y-axis to -180 and is moved + [TestCompiler] + public static void CanExtractSVDRotationFromFloat3x3With_X180_Y0_Z181() + { + var q = quaternion.Euler(math.radians(180f), math.radians(0f), math.radians(181f)); + var qSVD = svd.svdRotation(math.float3x3(q)); + + TestUtils.IsTrue(QuaternionEquals(q, qSVD, k_SVDTolerance)); + } + + // Case 938548: Assertion failed on expression: 'CompareApproximately(det, 1.0F, .005f)' when scaling system to 0 on at least 2 axes + [TestCompiler] + public static void CanExtractSVDRotationFromFloat3x3With_ZeroScaleXY() + { + var q0 = quaternion.Euler(math.radians(10f), math.radians(20f), math.radians(30f)); + var m0 = math.float3x3(q0); + var m0Scaled = math.mulScale(m0, math.float3(1f, 0f, 0f)); + var q1 = svd.svdRotation(m0Scaled); + var m1 = math.float3x3(q1); + + TestUtils.AreEqual(0.0f, math.length(m0.c0 - m1.c0), k_SVDTolerance); + } + } +} diff --git a/src/Tests/Tests/Shared/TestSvd.cs.meta b/src/Tests/Tests/Shared/TestSvd.cs.meta new file mode 100644 index 00000000..824a25f5 --- /dev/null +++ b/src/Tests/Tests/Shared/TestSvd.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8218cb7d87dac4432871cd5bd00fd333 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Tests/Tests/Shared/TestUint2.gen.cs b/src/Tests/Tests/Shared/TestUint2.gen.cs index 67c0813b..d853e034 100644 --- a/src/Tests/Tests/Shared/TestUint2.gen.cs +++ b/src/Tests/Tests/Shared/TestUint2.gen.cs @@ -1334,7 +1334,7 @@ public static void uint2_shuffle_result_4() TestUtils.AreEqual(uint4(2, 0, 0, 0), shuffle(a, b, ShuffleComponent.RightX, ShuffleComponent.LeftX, ShuffleComponent.LeftX, ShuffleComponent.LeftX)); } - [TestCase] + [TestCase /* For player builds */] public static void uint2_EqualsObjectOverride() { TestUtils.IsFalse(new uint2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint2x2.gen.cs b/src/Tests/Tests/Shared/TestUint2x2.gen.cs index a5f371ec..012db8aa 100644 --- a/src/Tests/Tests/Shared/TestUint2x2.gen.cs +++ b/src/Tests/Tests/Shared/TestUint2x2.gen.cs @@ -1229,7 +1229,7 @@ public static void uint2x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint2x2_EqualsObjectOverride() { TestUtils.IsFalse(new uint2x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint2x3.gen.cs b/src/Tests/Tests/Shared/TestUint2x3.gen.cs index d8aa9b0a..ac053495 100644 --- a/src/Tests/Tests/Shared/TestUint2x3.gen.cs +++ b/src/Tests/Tests/Shared/TestUint2x3.gen.cs @@ -1222,7 +1222,7 @@ public static void uint2x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint2x3_EqualsObjectOverride() { TestUtils.IsFalse(new uint2x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint2x4.gen.cs b/src/Tests/Tests/Shared/TestUint2x4.gen.cs index 7783684e..f9a8f210 100644 --- a/src/Tests/Tests/Shared/TestUint2x4.gen.cs +++ b/src/Tests/Tests/Shared/TestUint2x4.gen.cs @@ -1224,7 +1224,7 @@ public static void uint2x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint2x4_EqualsObjectOverride() { TestUtils.IsFalse(new uint2x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint3.gen.cs b/src/Tests/Tests/Shared/TestUint3.gen.cs index 6fca57ce..6443db9b 100644 --- a/src/Tests/Tests/Shared/TestUint3.gen.cs +++ b/src/Tests/Tests/Shared/TestUint3.gen.cs @@ -1341,7 +1341,7 @@ public static void uint3_shuffle_result_4() TestUtils.AreEqual(uint4(2, 5, 0, 4), shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftX, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void uint3_EqualsObjectOverride() { TestUtils.IsFalse(new uint3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint3x2.gen.cs b/src/Tests/Tests/Shared/TestUint3x2.gen.cs index 106b90dc..0072a061 100644 --- a/src/Tests/Tests/Shared/TestUint3x2.gen.cs +++ b/src/Tests/Tests/Shared/TestUint3x2.gen.cs @@ -1222,7 +1222,7 @@ public static void uint3x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint3x2_EqualsObjectOverride() { TestUtils.IsFalse(new uint3x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint3x3.gen.cs b/src/Tests/Tests/Shared/TestUint3x3.gen.cs index 5861b8a2..9e91fc32 100644 --- a/src/Tests/Tests/Shared/TestUint3x3.gen.cs +++ b/src/Tests/Tests/Shared/TestUint3x3.gen.cs @@ -1239,7 +1239,7 @@ public static void uint3x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint3x3_EqualsObjectOverride() { TestUtils.IsFalse(new uint3x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint3x4.gen.cs b/src/Tests/Tests/Shared/TestUint3x4.gen.cs index 9832a2a7..4768c755 100644 --- a/src/Tests/Tests/Shared/TestUint3x4.gen.cs +++ b/src/Tests/Tests/Shared/TestUint3x4.gen.cs @@ -1228,7 +1228,7 @@ public static void uint3x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint3x4_EqualsObjectOverride() { TestUtils.IsFalse(new uint3x4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint4.gen.cs b/src/Tests/Tests/Shared/TestUint4.gen.cs index 49e0be49..8d0b8a6b 100644 --- a/src/Tests/Tests/Shared/TestUint4.gen.cs +++ b/src/Tests/Tests/Shared/TestUint4.gen.cs @@ -1348,7 +1348,7 @@ public static void uint4_shuffle_result_4() TestUtils.AreEqual(uint4(3, 7, 1, 5), shuffle(a, b, ShuffleComponent.LeftW, ShuffleComponent.RightW, ShuffleComponent.LeftY, ShuffleComponent.RightY)); } - [TestCase] + [TestCase /* For player builds */] public static void uint4_EqualsObjectOverride() { TestUtils.IsFalse(new uint4().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint4x2.gen.cs b/src/Tests/Tests/Shared/TestUint4x2.gen.cs index 4cf1fc14..7f42bc6a 100644 --- a/src/Tests/Tests/Shared/TestUint4x2.gen.cs +++ b/src/Tests/Tests/Shared/TestUint4x2.gen.cs @@ -1224,7 +1224,7 @@ public static void uint4x2_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint4x2_EqualsObjectOverride() { TestUtils.IsFalse(new uint4x2().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint4x3.gen.cs b/src/Tests/Tests/Shared/TestUint4x3.gen.cs index 0bcde5e9..f750426b 100644 --- a/src/Tests/Tests/Shared/TestUint4x3.gen.cs +++ b/src/Tests/Tests/Shared/TestUint4x3.gen.cs @@ -1228,7 +1228,7 @@ public static void uint4x3_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint4x3_EqualsObjectOverride() { TestUtils.IsFalse(new uint4x3().Equals((object)new int())); diff --git a/src/Tests/Tests/Shared/TestUint4x4.gen.cs b/src/Tests/Tests/Shared/TestUint4x4.gen.cs index 67f34ee1..b9fc3f5e 100644 --- a/src/Tests/Tests/Shared/TestUint4x4.gen.cs +++ b/src/Tests/Tests/Shared/TestUint4x4.gen.cs @@ -1253,7 +1253,7 @@ public static void uint4x4_operator_bitwise_not() TestUtils.AreEqual(r3, ~a3); } - [TestCase] + [TestCase /* For player builds */] public static void uint4x4_EqualsObjectOverride() { TestUtils.IsFalse(new uint4x4().Equals((object)new int())); diff --git a/src/Tests/Tests/TestMath2.cs b/src/Tests/Tests/TestMath2.cs index 09e2d3a9..02b48ddb 100644 --- a/src/Tests/Tests/TestMath2.cs +++ b/src/Tests/Tests/TestMath2.cs @@ -1,6 +1,7 @@ using NUnit.Framework; using static Unity.Mathematics.math; using Burst.Compiler.IL.Tests; +using System; namespace Unity.Mathematics.Tests { @@ -59,5 +60,71 @@ public unsafe void hash_blob() } } } + + [TestCompiler] + public unsafe void hash_blob_unaligned() + { + byte[] testData = { + 0x0d, 0x26, 0x1c, 0xeb, 0x56, 0x3a, 0x9c, 0x18, 0x93, 0xb6, + 0xc1, 0x99, 0x5e, 0x04, 0x92, 0x4f, 0x6e, 0xb7, 0x42, 0x53, + 0x23, 0xcf, 0xe3, 0xbf, 0x16, 0x64, 0x79, 0x08, 0xc1, 0x01, + 0x43, 0x89, 0x73, 0x8f, 0x76, 0x22, 0x0c, 0xee, 0x9b, 0x80, + 0x31, 0x83, 0xce, 0x33, 0x8b, 0xc7, 0x3f, 0x94, 0x33 + }; + + uint[] resultsWithZeroSeed = + { + 0x02cc5d05, 0x376a5b3f, 0x8ae13198, 0xf5b14d72, 0xcc7ddc84, + 0x763e5905, 0x58759392, 0x6bccbd00, 0x7d0f80c8, 0xef01ae48, + 0xe40aa3ad, 0x805e04ad, 0xf98a471c, 0xdd960ac1, 0x76a71750, + 0xd35e2baa, 0x0219f7da, 0xd5bd1fbd, 0x5f28c87e, 0xfe6f7995, + 0x69a43ac5, 0xec1a1a15, 0x7ae9f103, 0x8d04a688, 0xce3b35be, + 0x6b3f040c, 0xd5ea2e8c, 0x6989e79c, 0x8772f1fb, 0x0d7b7bf6, + 0x0796214b, 0x98ea65c4, 0x3884dd82, 0x59632484, 0x91c92822, + 0x72d28404, 0x167061b0, 0x32adc2ef, 0xbac3e672, 0xd39936b7, + 0x94e2c154, 0x8b4ff46c, 0x68976fd4, 0x04bee59a, 0x2ed62c69, + 0xabee69fd, 0xda11e266, 0xcebd9d38, 0x28eea5fd, 0x0210d6ee + }; + + + uint[] resultsWith_0xeb69cf40_seed = + { + 0x12c3b280, 0x9bc1f68d, 0x2f900b51, 0xdb77e20e, 0xf6e8f561, + 0x3f3f72f6, 0x15f9700f, 0x28beb671, 0xceece5e1, 0x7a9b5c81, + 0x62a84642, 0xf75666af, 0x8939f8ca, 0x6b84792b, 0x527ee836, + 0xa0782090, 0xce6b9926, 0xa608c73b, 0xa08ee6a3, 0xab77a6b2, + 0x4e174e68, 0x596f10d5, 0xa14c4d85, 0x509ab88d, 0xd14698a4, + 0xbaad2308, 0xbd04c3df, 0x5715fed1, 0x5cf23a74, 0xd4e844f9, + 0x166dcfba, 0xe3495e37, 0x1b18b2b3, 0x2e8c2aab, 0x40993321, + 0x4b84998a, 0xd062937d, 0x1b2c9f7b, 0x8a613ed3, 0x70d71291, + 0x1af38ea4, 0x460cb7e9, 0xf806e3a9, 0xec9b6b2e, 0x9972a843, + 0x1ff06d2a, 0xe8c5007b, 0x37d8fc40, 0x0dc4f639, 0x36edff4f + }; + + byte* buffer = stackalloc byte[testData.Length + 1]; + fixed (byte* p = testData) + { + UIntPtr address = (UIntPtr)p; + bool isUnaligned = ((ulong)address & 1) > 0; + byte* unalignedPtr = buffer; + + if (!isUnaligned) + { + ++unalignedPtr; + } + + Buffer.MemoryCopy(p, unalignedPtr, testData.Length + 1, testData.Length); + + for (int i = 0; i < 50; ++i) + { + TestUtils.AreEqual(hash(unalignedPtr, i, 0), resultsWithZeroSeed[i]); + } + + for (int i = 0; i < 50; ++i) + { + TestUtils.AreEqual(hash(unalignedPtr, i, 0xeb69cf40), resultsWith_0xeb69cf40_seed[i]); + } + } + } } } diff --git a/src/Tests/Unity.Mathematics.Tests.asmdef b/src/Tests/Unity.Mathematics.Tests.asmdef index 6b374c8a..29a41728 100644 --- a/src/Tests/Unity.Mathematics.Tests.asmdef +++ b/src/Tests/Unity.Mathematics.Tests.asmdef @@ -1,13 +1,21 @@ { "name": "Unity.Mathematics.Tests", - "optionalUnityReferences": [ - "TestAssemblies" - ], + "rootNamespace": "", "references": [ - "Unity.Mathematics" + "Unity.Mathematics", + "UnityEngine.TestRunner" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" ], - "includePlatforms": [ - "Editor" + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" ], - "allowUnsafeCode": true -} + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/src/Tests/Unity.Mathematics.Tests.csproj b/src/Tests/Unity.Mathematics.Tests.csproj index 4ca36bde..db3c9463 100644 --- a/src/Tests/Unity.Mathematics.Tests.csproj +++ b/src/Tests/Unity.Mathematics.Tests.csproj @@ -12,6 +12,7 @@ v4.7.1 512 + latest true @@ -49,6 +50,7 @@ + @@ -106,6 +108,7 @@ + @@ -142,4 +145,4 @@ --> - \ No newline at end of file + diff --git a/Unity.Mathematics.TestProject/Assets/Tests.meta b/src/Tests/Unity.Mathematics.Tests.csproj.meta similarity index 67% rename from Unity.Mathematics.TestProject/Assets/Tests.meta rename to src/Tests/Unity.Mathematics.Tests.csproj.meta index 9f5f1a30..24e5c128 100644 --- a/Unity.Mathematics.TestProject/Assets/Tests.meta +++ b/src/Tests/Unity.Mathematics.Tests.csproj.meta @@ -1,6 +1,5 @@ fileFormatVersion: 2 -guid: 6ea92fda216cb44a1b5e2bf49e9ef2ad -folderAsset: yes +guid: e393530e16da0c6498af8f6417806c74 DefaultImporter: externalObjects: {} userData: diff --git a/src/Unity.Mathematics.CodeGen/Program.cs b/src/Unity.Mathematics.CodeGen~/Program.cs similarity index 100% rename from src/Unity.Mathematics.CodeGen/Program.cs rename to src/Unity.Mathematics.CodeGen~/Program.cs diff --git a/src/Unity.Mathematics.CodeGen/Program.cs.meta b/src/Unity.Mathematics.CodeGen~/Program.cs.meta similarity index 100% rename from src/Unity.Mathematics.CodeGen/Program.cs.meta rename to src/Unity.Mathematics.CodeGen~/Program.cs.meta diff --git a/src/Unity.Mathematics.CodeGen/Properties.meta b/src/Unity.Mathematics.CodeGen~/Properties.meta similarity index 100% rename from src/Unity.Mathematics.CodeGen/Properties.meta rename to src/Unity.Mathematics.CodeGen~/Properties.meta diff --git a/src/Unity.Mathematics.CodeGen/Properties/AssemblyInfo.cs b/src/Unity.Mathematics.CodeGen~/Properties/AssemblyInfo.cs similarity index 100% rename from src/Unity.Mathematics.CodeGen/Properties/AssemblyInfo.cs rename to src/Unity.Mathematics.CodeGen~/Properties/AssemblyInfo.cs diff --git a/src/Unity.Mathematics.CodeGen/Properties/AssemblyInfo.cs.meta b/src/Unity.Mathematics.CodeGen~/Properties/AssemblyInfo.cs.meta similarity index 100% rename from src/Unity.Mathematics.CodeGen/Properties/AssemblyInfo.cs.meta rename to src/Unity.Mathematics.CodeGen~/Properties/AssemblyInfo.cs.meta diff --git a/src/Unity.Mathematics.CodeGen/Unity.Mathematics.CodeGen.csproj b/src/Unity.Mathematics.CodeGen~/Unity.Mathematics.CodeGen.csproj similarity index 100% rename from src/Unity.Mathematics.CodeGen/Unity.Mathematics.CodeGen.csproj rename to src/Unity.Mathematics.CodeGen~/Unity.Mathematics.CodeGen.csproj diff --git a/src/Unity.Mathematics.CodeGen/VectorGenerator.cs b/src/Unity.Mathematics.CodeGen~/VectorGenerator.cs similarity index 93% rename from src/Unity.Mathematics.CodeGen/VectorGenerator.cs rename to src/Unity.Mathematics.CodeGen~/VectorGenerator.cs index 35d58e12..c53afabc 100644 --- a/src/Unity.Mathematics.CodeGen/VectorGenerator.cs +++ b/src/Unity.Mathematics.CodeGen~/VectorGenerator.cs @@ -2079,7 +2079,7 @@ private void BeginTest(StringBuilder str, string name, bool testCompiler = true) } else { - str.Append("\t\t[TestCase]\n"); + str.Append("\t\t[TestCase /* For player builds */]\n"); } str.AppendFormat("\t\tpublic static void {0}()\n", name); @@ -3224,6 +3224,9 @@ void GenerateInversePerformanceTests(StringBuilder str) GeneratePerformanceTest(str, "quaternion_inverse", new PerformanceTestArrayArgument[] { new PerformanceTestArrayArgument { m_ElementType = "quaternion", m_MemberName = "q", m_ElementInitializer = "quaternion.identity" }, }, "args.q[i] = math.inverse(args.q[i]);", 10000); + GeneratePerformanceTest(str, "pseudoinverse", new PerformanceTestArrayArgument[] { + new PerformanceTestArrayArgument { m_ElementType = "float3x3", m_MemberName = "m", m_ElementInitializer = "new float3x3(0.054824f, 0.462398f, 0.050136f, 0.054824f, 0.462398f, 0.050136f, 0.938166f, 0.542226f, 0.106844f)" }, + }, "args.m[i] = math.pseudoinverse(args.m[i]);", 1000); EndPerformanceTestCodeGen(str); } @@ -3295,55 +3298,43 @@ void GenerateRandomPerformanceTests(StringBuilder str) BeginPerformanceTestCodeGen(str, "TestRandom"); GeneratePerformanceTest(str, "Random_NextUint", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "uint", m_MemberName = "u", m_ElementInitializer = "0" }, - }, "args.u[i] = args.rng[i].NextUInt();", 10000); + }, "args.u[i] = args.rng.NextUInt();", 10000); GeneratePerformanceTest(str, "Random_NextUint2", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "uint2", m_MemberName = "u", m_ElementInitializer = "0" }, - }, "args.u[i] = args.rng[i].NextUInt2();", 10000); + }, "args.u[i] = args.rng.NextUInt2();", 10000); GeneratePerformanceTest(str, "Random_NextUint3", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "uint3", m_MemberName = "u", m_ElementInitializer = "0" }, - }, "args.u[i] = args.rng[i].NextUInt3();", 10000); + }, "args.u[i] = args.rng.NextUInt3();", 10000); GeneratePerformanceTest(str, "Random_NextUint4", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "uint4", m_MemberName = "u", m_ElementInitializer = "0" }, - }, "args.u[i] = args.rng[i].NextUInt4();", 10000); + }, "args.u[i] = args.rng.NextUInt4();", 10000); GeneratePerformanceTest(str, "Random_NextFloat", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "f", m_ElementInitializer = "0.0f" }, - }, "args.f[i] = args.rng[i].NextFloat();", 10000); + }, "args.f[i] = args.rng.NextFloat();", 10000); GeneratePerformanceTest(str, "Random_NextFloat2", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "f", m_ElementInitializer = "new float2(0.0f)" }, - }, "args.f[i] = args.rng[i].NextFloat2();", 10000); + }, "args.f[i] = args.rng.NextFloat2();", 10000); GeneratePerformanceTest(str, "Random_NextFloat3", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "f", m_ElementInitializer = "new float3(0.0f)" }, - }, "args.f[i] = args.rng[i].NextFloat3();", 10000); + }, "args.f[i] = args.rng.NextFloat3();", 10000); GeneratePerformanceTest(str, "Random_NextFloat4", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "f", m_ElementInitializer = "new float4(0.0f)" }, - }, "args.f[i] = args.rng[i].NextFloat4();", 10000); + }, "args.f[i] = args.rng.NextFloat4();", 10000); GeneratePerformanceTest(str, "Random_NextDouble", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "double", m_MemberName = "f", m_ElementInitializer = "0.0" }, - }, "args.f[i] = args.rng[i].NextDouble();", 10000); + }, "args.f[i] = args.rng.NextDouble();", 10000); GeneratePerformanceTest(str, "Random_NextDouble2", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "double2", m_MemberName = "f", m_ElementInitializer = "new double2(0.0)" }, - }, "args.f[i] = args.rng[i].NextDouble2();", 10000); + }, "args.f[i] = args.rng.NextDouble2();", 10000); GeneratePerformanceTest(str, "Random_NextDouble3", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "double3", m_MemberName = "f", m_ElementInitializer = "new double3(0.0)" }, - }, "args.f[i] = args.rng[i].NextDouble3();", 10000); + }, "args.f[i] = args.rng.NextDouble3();", 10000); GeneratePerformanceTest(str, "Random_NextDouble4", new PerformanceTestArrayArgument[] { - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Unity.Mathematics.Random(1)" }, new PerformanceTestArrayArgument { m_ElementType = "double4", m_MemberName = "f", m_ElementInitializer = "new double4(0.0)" }, - }, "args.f[i] = args.rng[i].NextDouble4();", 10000); + }, "args.f[i] = args.rng.NextDouble4();", 10000); EndPerformanceTestCodeGen(str); } @@ -3691,22 +3682,221 @@ public void GenerateMathPerformanceTests(StringBuilder str) GeneratePerformanceTest(str, "orthonormal_basis_float", new PerformanceTestArrayArgument[] { - // This rng array is totally wasteful since we create loopIterations of them when we just need one. - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Random(1234u)" }, - new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v1", m_ElementInitializer = "rng[0].NextFloat3Direction()" }, + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v1", m_ElementInitializer = "rng.NextFloat3Direction()" }, new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v2", m_ElementInitializer = "new float3()" }, new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v3", m_ElementInitializer = "new float3()" }, }, "math.orthonormal_basis(args.v1[i], out args.v2[i], out args.v3[i]);", 1000000); GeneratePerformanceTest(str, "orthonormal_basis_double", new PerformanceTestArrayArgument[] { - // This rng array is totally wasteful since we create loopIterations of them when we just need one. - new PerformanceTestArrayArgument { m_ElementType = "Random", m_MemberName = "rng", m_ElementInitializer = "new Random(1234u)" }, - new PerformanceTestArrayArgument { m_ElementType = "double3", m_MemberName = "v1", m_ElementInitializer = "rng[0].NextDouble3Direction()" }, + new PerformanceTestArrayArgument { m_ElementType = "double3", m_MemberName = "v1", m_ElementInitializer = "rng.NextDouble3Direction()" }, new PerformanceTestArrayArgument { m_ElementType = "double3", m_MemberName = "v2", m_ElementInitializer = "new double()" }, new PerformanceTestArrayArgument { m_ElementType = "double3", m_MemberName = "v3", m_ElementInitializer = "new double()" }, }, "math.orthonormal_basis(args.v1[i], out args.v2[i], out args.v3[i]);", 1000000); + GeneratePerformanceTest(str, "asuint_float", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint", m_MemberName = "result", m_ElementInitializer = "new uint()" }, + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_float2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint2", m_MemberName = "result", m_ElementInitializer = "new uint2()" }, + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat2(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_float3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint3", m_MemberName = "result", m_ElementInitializer = "new uint3()" }, + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat3(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_float4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint4", m_MemberName = "result", m_ElementInitializer = "new uint4()" }, + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat4(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_float", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int", m_MemberName = "result", m_ElementInitializer = "new int()" }, + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_float2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int2", m_MemberName = "result", m_ElementInitializer = "new int2()" }, + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat2(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_float3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int3", m_MemberName = "result", m_ElementInitializer = "new int3()" }, + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat3(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_float4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int4", m_MemberName = "result", m_ElementInitializer = "new int4()" }, + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "v", m_ElementInitializer = "rng.NextFloat4(-1.0f, 1.0f)" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_uint", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "result", m_ElementInitializer = "new uint()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_uint2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "result", m_ElementInitializer = "new uint2()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint2", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt2()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_uint3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "result", m_ElementInitializer = "new uint3()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint3", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt3()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_uint4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "result", m_ElementInitializer = "new uint4()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint4", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt4()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_int", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "result", m_ElementInitializer = "new int()" }, + new PerformanceTestArrayArgument { m_ElementType = "int", m_MemberName = "v", m_ElementInitializer = "rng.NextInt()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_int2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "result", m_ElementInitializer = "new int2()" }, + new PerformanceTestArrayArgument { m_ElementType = "int2", m_MemberName = "v", m_ElementInitializer = "rng.NextInt2()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_int3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "result", m_ElementInitializer = "new int3()" }, + new PerformanceTestArrayArgument { m_ElementType = "int3", m_MemberName = "v", m_ElementInitializer = "rng.NextInt3()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asfloat_int4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "result", m_ElementInitializer = "new int4()" }, + new PerformanceTestArrayArgument { m_ElementType = "int4", m_MemberName = "v", m_ElementInitializer = "rng.NextInt4()" }, + }, "args.result[i] = math.asfloat(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asdouble_ulong", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "double", m_MemberName = "result", m_ElementInitializer = "new double()" }, + new PerformanceTestArrayArgument { m_ElementType = "ulong", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt()" }, + }, "args.result[i] = math.asdouble(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asdouble_long", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "double", m_MemberName = "result", m_ElementInitializer = "new double()" }, + new PerformanceTestArrayArgument { m_ElementType = "long", m_MemberName = "v", m_ElementInitializer = "rng.NextInt()" }, + }, "args.result[i] = math.asdouble(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "aslong_double", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "long", m_MemberName = "result", m_ElementInitializer = "new long()" }, + new PerformanceTestArrayArgument { m_ElementType = "double", m_MemberName = "v", m_ElementInitializer = "rng.NextDouble(-1.0, 1.0)" }, + }, "args.result[i] = math.aslong(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asulong_double", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "ulong", m_MemberName = "result", m_ElementInitializer = "new ulong()" }, + new PerformanceTestArrayArgument { m_ElementType = "double", m_MemberName = "v", m_ElementInitializer = "rng.NextDouble(-1.0, 1.0)" }, + }, "args.result[i] = math.asulong(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_int", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint", m_MemberName = "result", m_ElementInitializer = "new uint()" }, + new PerformanceTestArrayArgument { m_ElementType = "int", m_MemberName = "v", m_ElementInitializer = "rng.NextInt()" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_int2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint2", m_MemberName = "result", m_ElementInitializer = "new uint2()" }, + new PerformanceTestArrayArgument { m_ElementType = "int2", m_MemberName = "v", m_ElementInitializer = "rng.NextInt2()" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_int3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint3", m_MemberName = "result", m_ElementInitializer = "new uint3()" }, + new PerformanceTestArrayArgument { m_ElementType = "int3", m_MemberName = "v", m_ElementInitializer = "rng.NextInt3()" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asuint_int4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "uint4", m_MemberName = "result", m_ElementInitializer = "new uint4()" }, + new PerformanceTestArrayArgument { m_ElementType = "int4", m_MemberName = "v", m_ElementInitializer = "rng.NextInt4()" }, + }, "args.result[i] = math.asuint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_uint", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int", m_MemberName = "result", m_ElementInitializer = "new int()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt()" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_uint2", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int2", m_MemberName = "result", m_ElementInitializer = "new int2()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint2", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt2()" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_uint3", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int3", m_MemberName = "result", m_ElementInitializer = "new int3()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint3", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt3()" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "asint_uint4", new[] + { + new PerformanceTestArrayArgument { m_ElementType = "int4", m_MemberName = "result", m_ElementInitializer = "new int4()" }, + new PerformanceTestArrayArgument { m_ElementType = "uint4", m_MemberName = "v", m_ElementInitializer = "rng.NextUInt4()" }, + }, "args.result[i] = math.asint(args.v[i]);", 400000); + + GeneratePerformanceTest(str, "chgsign_float", new PerformanceTestArrayArgument[] + { + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "f", m_ElementInitializer = "1.0f" }, + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "sign", m_ElementInitializer = "rng.NextFloat(-1.0f, 1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "result", m_ElementInitializer = "0.0f" }, + }, "args.result[i] = math.chgsign(args.f[i], args.sign[i]);", 100000); + + GeneratePerformanceTest(str, "chgsign_float2", new PerformanceTestArrayArgument[] + { + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "f", m_ElementInitializer = "new float2(1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "sign", m_ElementInitializer = "rng.NextFloat2(-1.0f, 1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float2", m_MemberName = "result", m_ElementInitializer = "new float2()" }, + }, "args.result[i] = math.chgsign(args.f[i], args.sign[i]);", 100000); + + GeneratePerformanceTest(str, "chgsign_float3", new PerformanceTestArrayArgument[] + { + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "f", m_ElementInitializer = "new float3(1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "sign", m_ElementInitializer = "rng.NextFloat3(-1.0f, 1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float3", m_MemberName = "result", m_ElementInitializer = "new float3()" }, + }, "args.result[i] = math.chgsign(args.f[i], args.sign[i]);", 100000); + + GeneratePerformanceTest(str, "chgsign_float4", new PerformanceTestArrayArgument[] + { + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "f", m_ElementInitializer = "new float4(1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "sign", m_ElementInitializer = "rng.NextFloat4(-1.0f, 1.0f)" }, + new PerformanceTestArrayArgument { m_ElementType = "float4", m_MemberName = "result", m_ElementInitializer = "new float4()" }, + }, "args.result[i] = math.chgsign(args.f[i], args.sign[i]);", 100000); + + GeneratePerformanceTest(str, "angle_quaternion_quaternion", new PerformanceTestArrayArgument[] + { + new PerformanceTestArrayArgument { m_ElementType = "quaternion", m_MemberName = "q1", m_ElementInitializer = "rng.NextQuaternionRotation()" }, + new PerformanceTestArrayArgument { m_ElementType = "quaternion", m_MemberName = "q2", m_ElementInitializer = "rng.NextQuaternionRotation()" }, + new PerformanceTestArrayArgument { m_ElementType = "float", m_MemberName = "result", m_ElementInitializer = "new float()" }, + }, "args.result[i] = math.angle(args.q1[i], args.q2[i]);", 10000); + EndPerformanceTestCodeGen(str); } @@ -3717,13 +3907,15 @@ public struct PerformanceTestArrayArgument public string m_ElementInitializer; } - void GeneratePerformanceTest(StringBuilder str, string testName, PerformanceTestArrayArgument[] testArguments, string loopBody, int loopIterations) + void GeneratePerformanceTest(StringBuilder str, string testName, PerformanceTestArrayArgument[] testArguments, string loopBody, int loopIterations, uint rngSeed = 1u) { str.AppendFormat("\t\t[BurstCompile(CompileSynchronously = true)]\n"); str.AppendFormat("\t\tpublic unsafe class {0}\n", testName); str.AppendFormat("\t\t{{\n"); + str.AppendFormat("\t\t\tpublic const int iterations = {0};\n\n", loopIterations); str.AppendFormat("\t\t\tpublic struct Arguments : IDisposable\n"); str.AppendFormat("\t\t\t{{\n"); + str.AppendFormat("\t\t\t\tpublic Random rng;\n"); foreach (var argument in testArguments) { @@ -3733,11 +3925,12 @@ void GeneratePerformanceTest(StringBuilder str, string testName, PerformanceTest str.AppendFormat("\n"); str.AppendFormat("\t\t\t\tpublic void Init()\n"); str.AppendFormat("\t\t\t\t{{\n"); + str.AppendFormat("\t\t\t\t\trng = new Random({0});\n", rngSeed); foreach (var argument in testArguments) { - str.AppendFormat("\t\t\t\t\t{0} = ({1}*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf<{1}>() * {2}, UnsafeUtility.AlignOf<{1}>(), Allocator.Persistent);\n", argument.m_MemberName, argument.m_ElementType, loopIterations); - str.AppendFormat("\t\t\t\t\tfor (int i = 0; i < {0}; ++i)\n", loopIterations); + str.AppendFormat("\t\t\t\t\t{0} = ({1}*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf<{1}>() * iterations, UnsafeUtility.AlignOf<{1}>(), Allocator.Persistent);\n", argument.m_MemberName, argument.m_ElementType); + str.AppendFormat("\t\t\t\t\tfor (int i = 0; i < iterations; ++i)\n"); str.AppendFormat("\t\t\t\t\t{{\n"); str.AppendFormat("\t\t\t\t\t {0}[i] = {1};\n", argument.m_MemberName, argument.m_ElementInitializer); str.AppendFormat("\t\t\t\t\t}}\n\n"); @@ -3758,7 +3951,7 @@ void GeneratePerformanceTest(StringBuilder str, string testName, PerformanceTest str.AppendFormat("\t\t\tpublic static void CommonTestFunction(ref Arguments args)\n"); str.AppendFormat("\t\t\t{{\n"); - str.AppendFormat("\t\t\t\tfor (int i = 0; i < {0}; ++i)\n", loopIterations); + str.AppendFormat("\t\t\t\tfor (int i = 0; i < iterations; ++i)\n"); str.AppendFormat("\t\t\t\t{{\n"); str.AppendFormat("\t\t\t\t\t{0}\n", loopBody); str.AppendFormat("\t\t\t\t}}\n"); diff --git a/src/Unity.Mathematics.CodeGen/VectorGenerator.cs.meta b/src/Unity.Mathematics.CodeGen~/VectorGenerator.cs.meta similarity index 100% rename from src/Unity.Mathematics.CodeGen/VectorGenerator.cs.meta rename to src/Unity.Mathematics.CodeGen~/VectorGenerator.cs.meta diff --git a/src/Unity.Mathematics.Editor/MatrixDrawer.cs b/src/Unity.Mathematics.Editor/MatrixDrawer.cs index 3f31a0c7..f59d2c91 100644 --- a/src/Unity.Mathematics.Editor/MatrixDrawer.cs +++ b/src/Unity.Mathematics.Editor/MatrixDrawer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using UnityEditor; @@ -23,10 +23,12 @@ namespace Unity.Mathematics.Editor [CustomPropertyDrawer(typeof(uint4x2)), CustomPropertyDrawer(typeof(uint4x3)), CustomPropertyDrawer(typeof(uint4x4))] class MatrixDrawer : PropertyDrawer { +#if !UNITY_2023_2_OR_NEWER public override bool CanCacheInspectorGUI(SerializedProperty property) { return false; } +#endif public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { diff --git a/src/Unity.Mathematics.Editor/PostNormalizedVectorDrawer.cs b/src/Unity.Mathematics.Editor/PostNormalizedVectorDrawer.cs index d4189eda..eaa2a07d 100644 --- a/src/Unity.Mathematics.Editor/PostNormalizedVectorDrawer.cs +++ b/src/Unity.Mathematics.Editor/PostNormalizedVectorDrawer.cs @@ -12,8 +12,10 @@ class PostNormalizedVectorDrawer : PrimitiveVectorDrawer { static class Content { - public static readonly string tooltip = - L10n.Tr("Values you enter will be post-normalized. You will see the normalized result if you change selection and view the values again."); + public static readonly GUIContent Tooltip = new ( + string.Empty, + L10n.Tr("Values you enter will be post-normalized. You will see the normalized result if you " + + "change selection and view the values again.")); } class VectorPropertyGUIData @@ -181,8 +183,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten return; } + // Avoid polluting the passed-in GUIContent - it might be static and shared. if (string.IsNullOrEmpty(label.tooltip)) - label.tooltip = Content.tooltip; + { + Content.Tooltip.text = label.text; + label = Content.Tooltip; + } guiData.RebuildIfDirty(); guiData.ApplyPreNormalizedValues(); diff --git a/src/Unity.Mathematics.Editor/PrimitiveVectorDrawer.cs b/src/Unity.Mathematics.Editor/PrimitiveVectorDrawer.cs index d84d81f9..5353bdcb 100644 --- a/src/Unity.Mathematics.Editor/PrimitiveVectorDrawer.cs +++ b/src/Unity.Mathematics.Editor/PrimitiveVectorDrawer.cs @@ -1,4 +1,4 @@ -using System; +using System; using UnityEditor; using UnityEngine; @@ -36,18 +36,20 @@ static class Content public static readonly string doNotNormalizeCompatibility = L10n.Tr( $"{typeof(DoNotNormalizeAttribute).Name} only works with {typeof(quaternion)} and primitive vector types." ); - public static readonly string doNotNormalizeTooltip = - L10n.Tr("This value is not normalized, which may produce unexpected results."); + public static readonly GUIContent doNotNormalizeContent = new GUIContent("", + L10n.Tr("This value is not normalized, which may produce unexpected results.")); public static readonly GUIContent[] labels2 = { new GUIContent("X"), new GUIContent("Y") }; public static readonly GUIContent[] labels3 = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") }; public static readonly GUIContent[] labels4 = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") }; } +#if !UNITY_2023_2_OR_NEWER public override bool CanCacheInspectorGUI(SerializedProperty property) { return false; } +#endif public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { @@ -87,11 +89,156 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten } if (attribute is DoNotNormalizeAttribute && string.IsNullOrEmpty(label.tooltip)) - label.tooltip = Content.doNotNormalizeTooltip; - - EditorGUI.BeginProperty(position, label, property); - EditorGUI.MultiPropertyField(position, subLabels, property.FindPropertyRelative(startIter), label); + { + Content.doNotNormalizeContent.text = label.text; + label = Content.doNotNormalizeContent; + } + label = EditorGUI.BeginProperty(position, label, property); + var valuesIterator = property.FindPropertyRelative(startIter); + MultiPropertyField(position, subLabels, valuesIterator, label); EditorGUI.EndProperty(); } + + void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, GUIContent label) + { +#if UNITY_2022_1_OR_NEWER + EditorGUI.MultiPropertyField(position, subLabels, valuesIterator, label, EditorGUI.PropertyVisibility.All); +#else + EditorGUICopy.MultiPropertyField(position, subLabels, valuesIterator, label); +#endif + } + } + +#if !UNITY_2022_1_OR_NEWER + internal class EditorGUICopy + { + internal const float kSpacingSubLabel = 4; + private const float kIndentPerLevel = 15; + internal const float kPrefixPaddingRight = 2; + internal static int indentLevel = 0; + private static readonly int s_FoldoutHash = "Foldout".GetHashCode(); + + // internal static readonly SVC kVerticalSpacingMultiField = new SVC("--theme-multifield-vertical-spacing", 0.0f); + // kVerticalSpacingMultiField should actually look like the above line ^^^ but we don't have access to SVC, + // so instead we just set this value to what is observed in the debugger with the Unity dark theme. + internal const float kVerticalSpacingMultiField = 2; + + internal enum PropertyVisibility + { + All, + OnlyVisible + } + + // This code is basically EditorGUI.MultiPropertyField(Rect, GUIContent[], SerializedProperty, GUIContent), + // but with the property visibility assumed to be "All" instead of "OnlyVisible". We really want to have "All" + // because it's possible for someone to hide something in the inspector with [HideInInspector] but then manually + // draw it themselves later. In this case, if you called EditorGUI.MultiPropertyField() directly, you'd + // end up with some fields that point to some unrelated visible property. + public static void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, GUIContent label) + { + int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, position); + position = MultiFieldPrefixLabel(position, id, label, subLabels.Length); + position.height = EditorGUIUtility.singleLineHeight; + MultiPropertyFieldInternal(position, subLabels, valuesIterator, PropertyVisibility.All); + } + + internal static void BeginDisabled(bool disabled) + { + // Unused, but left here to minimize changes in EditorGUICopy.MultiPropertyFieldInternal(). + } + + internal static void EndDisabled() + { + // Unused, but left here to minimize changes in EditorGUICopy.MultiPropertyFieldInternal(). + } + + internal static float CalcPrefixLabelWidth(GUIContent label, GUIStyle style = null) + { + if (style == null) + style = EditorStyles.label; + return style.CalcSize(label).x; + } + + internal static void MultiPropertyFieldInternal(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, PropertyVisibility visibility, bool[] disabledMask = null, float prefixLabelWidth = -1) + { + int eCount = subLabels.Length; + float w = (position.width - (eCount - 1) * kSpacingSubLabel) / eCount; + Rect nr = new Rect(position) {width = w}; + float t = EditorGUIUtility.labelWidth; + int l = indentLevel; + indentLevel = 0; + for (int i = 0; i < subLabels.Length; i++) + { + EditorGUIUtility.labelWidth = prefixLabelWidth > 0 ? prefixLabelWidth : CalcPrefixLabelWidth(subLabels[i]); + + if (disabledMask != null) + BeginDisabled(disabledMask[i]); + EditorGUI.PropertyField(nr, valuesIterator, subLabels[i]); + if (disabledMask != null) + EndDisabled(); + nr.x += w + kSpacingSubLabel; + + switch (visibility) + { + case PropertyVisibility.All: + valuesIterator.Next(false); + break; + + case PropertyVisibility.OnlyVisible: + valuesIterator.NextVisible(false); + break; + } + } + EditorGUIUtility.labelWidth = t; + indentLevel = l; + } + + internal static bool LabelHasContent(GUIContent label) + { + if (label == null) + { + return true; + } + // @TODO: find out why checking for GUIContent.none doesn't work + return label.text != string.Empty || label.image != null; + } + + internal static float indent => indentLevel * kIndentPerLevel; + + internal static Rect MultiFieldPrefixLabel(Rect totalPosition, int id, GUIContent label, int columns) + { + if (!LabelHasContent(label)) + { + return EditorGUI.IndentedRect(totalPosition); + } + + if (EditorGUIUtility.wideMode) + { + Rect labelPosition = new Rect(totalPosition.x + indent, totalPosition.y, EditorGUIUtility.labelWidth - indent, EditorGUIUtility.singleLineHeight); + Rect fieldPosition = totalPosition; + fieldPosition.xMin += EditorGUIUtility.labelWidth + kPrefixPaddingRight; + + // If there are 2 columns we use the same column widths as if there had been 3 columns + // in order to make columns line up neatly. + if (columns == 2) + { + float columnWidth = (fieldPosition.width - (3 - 1) * kSpacingSubLabel) / 3f; + fieldPosition.xMax -= (columnWidth + kSpacingSubLabel); + } + + EditorGUI.HandlePrefixLabel(totalPosition, labelPosition, label, id); + return fieldPosition; + } + else + { + Rect labelPosition = new Rect(totalPosition.x + indent, totalPosition.y, totalPosition.width - indent, EditorGUIUtility.singleLineHeight); + Rect fieldPosition = totalPosition; + fieldPosition.xMin += indent + kIndentPerLevel; + fieldPosition.yMin += EditorGUIUtility.singleLineHeight + kVerticalSpacingMultiField; + EditorGUI.HandlePrefixLabel(totalPosition, labelPosition, label, id); + return fieldPosition; + } + } } +#endif } diff --git a/src/Unity.Mathematics.PerformanceTests/TestConversions.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestConversions.gen.cs index 08266759..3050d7f5 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestConversions.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestConversions.gen.cs @@ -21,21 +21,25 @@ partial class TestConversions [BurstCompile(CompileSynchronously = true)] public unsafe class quaternion_to_float3x3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public float3x3* f3x3; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } - f3x3 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + f3x3 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f3x3[i] = float3x3.identity; } @@ -51,7 +55,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.f3x3[i] = new float3x3(args.q[i]); } @@ -109,21 +113,25 @@ public void quaternion_to_float3x3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_to_quaternion { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public float3x3* f3x3; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } - f3x3 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + f3x3 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f3x3[i] = float3x3.identity; } @@ -139,7 +147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.q[i] = new quaternion(args.f3x3[i]); } @@ -197,21 +205,25 @@ public void float3x3_to_quaternion_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_to_half4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* f4; public half4* h4; public void Init() { - f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } - h4 = (half4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + h4 = (half4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { h4[i] = new half4(new float4(-1.0f, -2.0f, -3.0f, -4.0f)); } @@ -227,7 +239,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.h4[i] = new half4(args.f4[i]); } @@ -285,21 +297,25 @@ public void float4_to_half4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class half4_to_float4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* f4; public half4* h4; public void Init() { - f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } - h4 = (half4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + h4 = (half4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { h4[i] = new half4(new float4(-1.0f, -2.0f, -3.0f, -4.0f)); } @@ -315,7 +331,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.f4[i] = new float4(args.h4[i]); } @@ -373,28 +389,32 @@ public void half4_to_float4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class quaternion_to_RigidTransform { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public RigidTransform* rt; public float3* pos; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } - rt = (RigidTransform*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rt = (RigidTransform*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { rt[i] = RigidTransform.identity; } - pos = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + pos = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { pos[i] = new float3(); } @@ -411,7 +431,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.rt[i] = new RigidTransform(args.q[i], args.pos[i]); } @@ -469,21 +489,25 @@ public void quaternion_to_RigidTransform_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class quaternion_to_float4x4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public float4x4* f4x4; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } - f4x4 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + f4x4 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4x4[i] = float4x4.identity; } @@ -499,7 +523,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.q[i] = new quaternion(args.f4x4[i]); } @@ -557,28 +581,32 @@ public void quaternion_to_float4x4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_to_quaternion { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public float4x4* f4x4; public float3* f3; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } - f4x4 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + f4x4 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4x4[i] = float4x4.identity; } - f3 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + f3 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f3[i] = new float3(); } @@ -595,7 +623,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.f4x4[i] = new float4x4(args.q[i], args.f3[i]); } @@ -653,21 +681,25 @@ public void float4x4_to_quaternion_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_to_uint4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* f4; public uint4* u4; public void Init() { - f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } - u4 = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + u4 = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u4[i] = new uint4(100, 101, 102, 103); } @@ -683,7 +715,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.u4[i] = new uint4(args.f4[i]); } @@ -741,21 +773,25 @@ public void float4_to_uint4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class uint4_to_float4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* f4; public uint4* u4; public void Init() { - f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f4 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f4[i] = new float4(1.0f, 2.0f, 3.0f, 4.0f); } - u4 = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + u4 = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u4[i] = new uint4(100, 101, 102, 103); } @@ -771,7 +807,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.f4[i] = new float4(args.u4[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestFastInverse.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestFastInverse.gen.cs index b133ff85..570951dd 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestFastInverse.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestFastInverse.gen.cs @@ -21,14 +21,18 @@ partial class TestFastInverse [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_fastinverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* m1; public void Init() { - m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float4x4.identity; } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.fastinverse(args.m1[i]); } @@ -101,14 +105,18 @@ public void float4x4_fastinverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double4x4_fastinverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double4x4* m1; public void Init() { - m1 = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = double4x4.identity; } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.fastinverse(args.m1[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestHash.cs b/src/Unity.Mathematics.PerformanceTests/TestHash.cs new file mode 100644 index 00000000..106f451f --- /dev/null +++ b/src/Unity.Mathematics.PerformanceTests/TestHash.cs @@ -0,0 +1,58 @@ +using Unity.Burst; +using Unity.PerformanceTesting; +using NUnit.Framework; +using Unity.Collections.LowLevel.Unsafe; +using System; +using UnityEngine; + +namespace Unity.Mathematics.PerformanceTests +{ + [BurstCompile] + partial class TestHash + { + static readonly long kBufferBytes = 1024 * 1024; + static readonly long kBytesToHash = kBufferBytes - 1; + static readonly uint kExpectedHash = 1781740882; + + [Test, Performance] + public static unsafe void HashAligned() + { + Assert.AreEqual(kExpectedHash, Hash(false)); + } + + [Test, Performance] + public static unsafe void HashUnaligned() + { + Assert.AreEqual(kExpectedHash, Hash(true)); + } + + [BurstCompile(CompileSynchronously = true)] + static unsafe uint Hash(bool useUnalignedBuffer) + { + var ptr = (ulong)(UIntPtr)UnsafeUtility.Malloc(kBufferBytes, 16, Collections.Allocator.Persistent); + var ulongptr = (ulong)ptr; + uint seed = 0; + + if (useUnalignedBuffer && ((ulongptr & 1) == 0)) + { + ++ulongptr; + } + + var buffer = (void*)ulongptr; + + for (int i = 0; i < kBytesToHash; ++i) + { + ((byte*)buffer)[i] = 123; + } + + for (int i = 0; i < 100; ++i) + { + seed = math.hash(buffer, (int)kBytesToHash, seed); + } + + UnsafeUtility.Free((void*)ptr, Collections.Allocator.Persistent); + + return seed; + } + } +} \ No newline at end of file diff --git a/src/Unity.Mathematics.PerformanceTests/TestHash.cs.meta b/src/Unity.Mathematics.PerformanceTests/TestHash.cs.meta new file mode 100644 index 00000000..fcfb809b --- /dev/null +++ b/src/Unity.Mathematics.PerformanceTests/TestHash.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1a8761ebc1ffa240aa484721a63ba9f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Unity.Mathematics.PerformanceTests/TestHash.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestHash.gen.cs index b26397f9..e90cf82c 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestHash.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestHash.gen.cs @@ -21,21 +21,25 @@ partial class TestHash [BurstCompile(CompileSynchronously = true)] public unsafe class float2_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public uint* hash; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -51,7 +55,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -109,21 +113,25 @@ public void float2_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public uint* hash; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -139,7 +147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -197,21 +205,25 @@ public void float3_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public uint* hash; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -227,7 +239,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -285,21 +297,25 @@ public void float4_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double2_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public double2* v; public uint* hash; public void Init() { - v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double2(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -315,7 +331,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -373,21 +389,25 @@ public void double2_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double3_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public double3* v; public uint* hash; public void Init() { - v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double3(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -403,7 +423,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -461,21 +481,25 @@ public void double3_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double4_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public double4* v; public uint* hash; public void Init() { - v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double4(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -491,7 +515,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -549,21 +573,25 @@ public void double4_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2x2_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* v; public uint* hash; public void Init() { - v = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2x2(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -579,7 +607,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -637,21 +665,25 @@ public void float2x2_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* v; public uint* hash; public void Init() { - v = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3x3(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -667,7 +699,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -725,21 +757,25 @@ public void float3x3_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_hash { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* v; public uint* hash; public void Init() { - v = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4x4(1.0f); } - hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -755,7 +791,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hash(args.v[i]); } @@ -813,21 +849,25 @@ public void float4x4_hash_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2x2_hashwide { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* v; public uint2* hash; public void Init() { - v = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2x2(1.0f); } - hash = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -843,7 +883,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hashwide(args.v[i]); } @@ -901,21 +941,25 @@ public void float2x2_hashwide_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_hashwide { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* v; public uint3* hash; public void Init() { - v = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3x3(1.0f); } - hash = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -931,7 +975,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hashwide(args.v[i]); } @@ -989,21 +1033,25 @@ public void float3x3_hashwide_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_hashwide { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* v; public uint4* hash; public void Init() { - v = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4x4(1.0f); } - hash = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = 0; } @@ -1019,7 +1067,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hashwide(args.v[i]); } @@ -1077,21 +1125,25 @@ public void float4x4_hashwide_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2_hashwide { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public uint2* hash; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(1.0f); } - hash = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + hash = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { hash[i] = new uint2(); } @@ -1107,7 +1159,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.hash[i] = math.hashwide(args.v[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestInverse.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestInverse.gen.cs index 5450d48c..26bfc7da 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestInverse.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestInverse.gen.cs @@ -21,14 +21,18 @@ partial class TestInverse [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* m1; public void Init() { - m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float4x4.identity; } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -101,14 +105,18 @@ public void float4x4_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* m1; public void Init() { - m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float3x3.identity; } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -181,14 +189,18 @@ public void float3x3_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2x2_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* m1; public void Init() { - m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float2x2.identity; } @@ -203,7 +215,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -261,14 +273,18 @@ public void float2x2_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double4x4_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double4x4* m1; public void Init() { - m1 = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = double4x4.identity; } @@ -283,7 +299,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -341,14 +357,18 @@ public void double4x4_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double3x3_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double3x3* m1; public void Init() { - m1 = (double3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (double3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = double3x3.identity; } @@ -363,7 +383,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -421,14 +441,18 @@ public void double3x3_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double2x2_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double2x2* m1; public void Init() { - m1 = (double2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (double2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = double2x2.identity; } @@ -443,7 +467,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.inverse(args.m1[i]); } @@ -501,14 +525,18 @@ public void double2x2_inverse_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class quaternion_inverse { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q; public void Init() { - q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q[i] = quaternion.identity; } @@ -523,7 +551,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.q[i] = math.inverse(args.q[i]); } @@ -568,6 +596,90 @@ public void quaternion_inverse_burst() var args = new quaternion_inverse.Arguments(); args.Init(); + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class pseudoinverse + { + public const int iterations = 1000; + + public struct Arguments : IDisposable + { + public Random rng; + public float3x3* m; + + public void Init() + { + rng = new Random(1); + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + m[i] = new float3x3(0.054824f, 0.462398f, 0.050136f, 0.054824f, 0.462398f, 0.050136f, 0.938166f, 0.542226f, 0.106844f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(m, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.m[i] = math.pseudoinverse(args.m[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void pseudoinverse_mono() + { + pseudoinverse.TestFunction testFunction = pseudoinverse.MonoTestFunction; + var args = new pseudoinverse.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void pseudoinverse_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(pseudoinverse.BurstTestFunction); + var args = new pseudoinverse.Arguments(); + args.Init(); + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); diff --git a/src/Unity.Mathematics.PerformanceTests/TestMath.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestMath.gen.cs index d2efa23f..dfab18d9 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestMath.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestMath.gen.cs @@ -21,35 +21,32 @@ partial class TestMath [BurstCompile(CompileSynchronously = true)] public unsafe class orthonormal_basis_float { + public const int iterations = 1000000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public float3* v1; public float3* v2; public float3* v3; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) - { - rng[i] = new Random(1234u); - } - - v1 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + rng = new Random(1); + v1 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { - v1[i] = rng[0].NextFloat3Direction(); + v1[i] = rng.NextFloat3Direction(); } - v2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + v2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v2[i] = new float3(); } - v3 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + v3 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v3[i] = new float3(); } @@ -58,7 +55,6 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(v1, Allocator.Persistent); UnsafeUtility.Free(v2, Allocator.Persistent); UnsafeUtility.Free(v3, Allocator.Persistent); @@ -67,7 +63,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 1000000; ++i) + for (int i = 0; i < iterations; ++i) { math.orthonormal_basis(args.v1[i], out args.v2[i], out args.v3[i]); } @@ -125,35 +121,32 @@ public void orthonormal_basis_float_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class orthonormal_basis_double { + public const int iterations = 1000000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public double3* v1; public double3* v2; public double3* v3; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) - { - rng[i] = new Random(1234u); - } - - v1 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + rng = new Random(1); + v1 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { - v1[i] = rng[0].NextDouble3Direction(); + v1[i] = rng.NextDouble3Direction(); } - v2 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + v2 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v2[i] = new double(); } - v3 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 1000000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 1000000; ++i) + v3 = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v3[i] = new double(); } @@ -162,7 +155,6 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(v1, Allocator.Persistent); UnsafeUtility.Free(v2, Allocator.Persistent); UnsafeUtility.Free(v3, Allocator.Persistent); @@ -171,7 +163,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 1000000; ++i) + for (int i = 0; i < iterations; ++i) { math.orthonormal_basis(args.v1[i], out args.v2[i], out args.v3[i]); } @@ -216,6 +208,3082 @@ public void orthonormal_basis_double_burst() var args = new orthonormal_basis_double.Arguments(); args.Init(); + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_float + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint* result; + public float* v; + + public void Init() + { + rng = new Random(1); + result = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint(); + } + + v = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_float_mono() + { + asuint_float.TestFunction testFunction = asuint_float.MonoTestFunction; + var args = new asuint_float.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_float_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_float.BurstTestFunction); + var args = new asuint_float.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_float2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint2* result; + public float2* v; + + public void Init() + { + rng = new Random(1); + result = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint2(); + } + + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat2(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_float2_mono() + { + asuint_float2.TestFunction testFunction = asuint_float2.MonoTestFunction; + var args = new asuint_float2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_float2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_float2.BurstTestFunction); + var args = new asuint_float2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_float3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint3* result; + public float3* v; + + public void Init() + { + rng = new Random(1); + result = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint3(); + } + + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat3(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_float3_mono() + { + asuint_float3.TestFunction testFunction = asuint_float3.MonoTestFunction; + var args = new asuint_float3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_float3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_float3.BurstTestFunction); + var args = new asuint_float3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_float4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint4* result; + public float4* v; + + public void Init() + { + rng = new Random(1); + result = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint4(); + } + + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat4(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_float4_mono() + { + asuint_float4.TestFunction testFunction = asuint_float4.MonoTestFunction; + var args = new asuint_float4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_float4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_float4.BurstTestFunction); + var args = new asuint_float4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_float + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int* result; + public float* v; + + public void Init() + { + rng = new Random(1); + result = (int*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int(); + } + + v = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_float_mono() + { + asint_float.TestFunction testFunction = asint_float.MonoTestFunction; + var args = new asint_float.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_float_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_float.BurstTestFunction); + var args = new asint_float.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_float2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int2* result; + public float2* v; + + public void Init() + { + rng = new Random(1); + result = (int2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int2(); + } + + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat2(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_float2_mono() + { + asint_float2.TestFunction testFunction = asint_float2.MonoTestFunction; + var args = new asint_float2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_float2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_float2.BurstTestFunction); + var args = new asint_float2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_float3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int3* result; + public float3* v; + + public void Init() + { + rng = new Random(1); + result = (int3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int3(); + } + + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat3(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_float3_mono() + { + asint_float3.TestFunction testFunction = asint_float3.MonoTestFunction; + var args = new asint_float3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_float3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_float3.BurstTestFunction); + var args = new asint_float3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_float4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int4* result; + public float4* v; + + public void Init() + { + rng = new Random(1); + result = (int4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int4(); + } + + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextFloat4(-1.0f, 1.0f); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_float4_mono() + { + asint_float4.TestFunction testFunction = asint_float4.MonoTestFunction; + var args = new asint_float4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_float4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_float4.BurstTestFunction); + var args = new asint_float4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_uint + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float* result; + public uint* v; + + public void Init() + { + rng = new Random(1); + result = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint(); + } + + v = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_uint_mono() + { + asfloat_uint.TestFunction testFunction = asfloat_uint.MonoTestFunction; + var args = new asfloat_uint.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_uint_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_uint.BurstTestFunction); + var args = new asfloat_uint.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_uint2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float2* result; + public uint2* v; + + public void Init() + { + rng = new Random(1); + result = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint2(); + } + + v = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt2(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_uint2_mono() + { + asfloat_uint2.TestFunction testFunction = asfloat_uint2.MonoTestFunction; + var args = new asfloat_uint2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_uint2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_uint2.BurstTestFunction); + var args = new asfloat_uint2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_uint3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float3* result; + public uint3* v; + + public void Init() + { + rng = new Random(1); + result = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint3(); + } + + v = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt3(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_uint3_mono() + { + asfloat_uint3.TestFunction testFunction = asfloat_uint3.MonoTestFunction; + var args = new asfloat_uint3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_uint3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_uint3.BurstTestFunction); + var args = new asfloat_uint3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_uint4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float4* result; + public uint4* v; + + public void Init() + { + rng = new Random(1); + result = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint4(); + } + + v = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt4(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_uint4_mono() + { + asfloat_uint4.TestFunction testFunction = asfloat_uint4.MonoTestFunction; + var args = new asfloat_uint4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_uint4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_uint4.BurstTestFunction); + var args = new asfloat_uint4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_int + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float* result; + public int* v; + + public void Init() + { + rng = new Random(1); + result = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int(); + } + + v = (int*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_int_mono() + { + asfloat_int.TestFunction testFunction = asfloat_int.MonoTestFunction; + var args = new asfloat_int.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_int_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_int.BurstTestFunction); + var args = new asfloat_int.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_int2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float2* result; + public int2* v; + + public void Init() + { + rng = new Random(1); + result = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int2(); + } + + v = (int2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt2(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_int2_mono() + { + asfloat_int2.TestFunction testFunction = asfloat_int2.MonoTestFunction; + var args = new asfloat_int2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_int2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_int2.BurstTestFunction); + var args = new asfloat_int2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_int3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float3* result; + public int3* v; + + public void Init() + { + rng = new Random(1); + result = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int3(); + } + + v = (int3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt3(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_int3_mono() + { + asfloat_int3.TestFunction testFunction = asfloat_int3.MonoTestFunction; + var args = new asfloat_int3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_int3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_int3.BurstTestFunction); + var args = new asfloat_int3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asfloat_int4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public float4* result; + public int4* v; + + public void Init() + { + rng = new Random(1); + result = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int4(); + } + + v = (int4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt4(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asfloat(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asfloat_int4_mono() + { + asfloat_int4.TestFunction testFunction = asfloat_int4.MonoTestFunction; + var args = new asfloat_int4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asfloat_int4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asfloat_int4.BurstTestFunction); + var args = new asfloat_int4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asdouble_ulong + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public double* result; + public ulong* v; + + public void Init() + { + rng = new Random(1); + result = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new double(); + } + + v = (ulong*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asdouble(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asdouble_ulong_mono() + { + asdouble_ulong.TestFunction testFunction = asdouble_ulong.MonoTestFunction; + var args = new asdouble_ulong.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asdouble_ulong_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asdouble_ulong.BurstTestFunction); + var args = new asdouble_ulong.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asdouble_long + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public double* result; + public long* v; + + public void Init() + { + rng = new Random(1); + result = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new double(); + } + + v = (long*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asdouble(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asdouble_long_mono() + { + asdouble_long.TestFunction testFunction = asdouble_long.MonoTestFunction; + var args = new asdouble_long.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asdouble_long_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asdouble_long.BurstTestFunction); + var args = new asdouble_long.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class aslong_double + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public long* result; + public double* v; + + public void Init() + { + rng = new Random(1); + result = (long*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new long(); + } + + v = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextDouble(-1.0, 1.0); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.aslong(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void aslong_double_mono() + { + aslong_double.TestFunction testFunction = aslong_double.MonoTestFunction; + var args = new aslong_double.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void aslong_double_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(aslong_double.BurstTestFunction); + var args = new aslong_double.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asulong_double + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public ulong* result; + public double* v; + + public void Init() + { + rng = new Random(1); + result = (ulong*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new ulong(); + } + + v = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextDouble(-1.0, 1.0); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asulong(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asulong_double_mono() + { + asulong_double.TestFunction testFunction = asulong_double.MonoTestFunction; + var args = new asulong_double.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asulong_double_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asulong_double.BurstTestFunction); + var args = new asulong_double.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_int + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint* result; + public int* v; + + public void Init() + { + rng = new Random(1); + result = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint(); + } + + v = (int*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_int_mono() + { + asuint_int.TestFunction testFunction = asuint_int.MonoTestFunction; + var args = new asuint_int.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_int_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_int.BurstTestFunction); + var args = new asuint_int.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_int2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint2* result; + public int2* v; + + public void Init() + { + rng = new Random(1); + result = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint2(); + } + + v = (int2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt2(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_int2_mono() + { + asuint_int2.TestFunction testFunction = asuint_int2.MonoTestFunction; + var args = new asuint_int2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_int2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_int2.BurstTestFunction); + var args = new asuint_int2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_int3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint3* result; + public int3* v; + + public void Init() + { + rng = new Random(1); + result = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint3(); + } + + v = (int3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt3(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_int3_mono() + { + asuint_int3.TestFunction testFunction = asuint_int3.MonoTestFunction; + var args = new asuint_int3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_int3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_int3.BurstTestFunction); + var args = new asuint_int3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asuint_int4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public uint4* result; + public int4* v; + + public void Init() + { + rng = new Random(1); + result = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new uint4(); + } + + v = (int4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextInt4(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asuint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asuint_int4_mono() + { + asuint_int4.TestFunction testFunction = asuint_int4.MonoTestFunction; + var args = new asuint_int4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asuint_int4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asuint_int4.BurstTestFunction); + var args = new asuint_int4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_uint + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int* result; + public uint* v; + + public void Init() + { + rng = new Random(1); + result = (int*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int(); + } + + v = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_uint_mono() + { + asint_uint.TestFunction testFunction = asint_uint.MonoTestFunction; + var args = new asint_uint.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_uint_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_uint.BurstTestFunction); + var args = new asint_uint.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_uint2 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int2* result; + public uint2* v; + + public void Init() + { + rng = new Random(1); + result = (int2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int2(); + } + + v = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt2(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_uint2_mono() + { + asint_uint2.TestFunction testFunction = asint_uint2.MonoTestFunction; + var args = new asint_uint2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_uint2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_uint2.BurstTestFunction); + var args = new asint_uint2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_uint3 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int3* result; + public uint3* v; + + public void Init() + { + rng = new Random(1); + result = (int3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int3(); + } + + v = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt3(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_uint3_mono() + { + asint_uint3.TestFunction testFunction = asint_uint3.MonoTestFunction; + var args = new asint_uint3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_uint3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_uint3.BurstTestFunction); + var args = new asint_uint3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class asint_uint4 + { + public const int iterations = 400000; + + public struct Arguments : IDisposable + { + public Random rng; + public int4* result; + public uint4* v; + + public void Init() + { + rng = new Random(1); + result = (int4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new int4(); + } + + v = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + v[i] = rng.NextUInt4(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(result, Allocator.Persistent); + UnsafeUtility.Free(v, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.asint(args.v[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void asint_uint4_mono() + { + asint_uint4.TestFunction testFunction = asint_uint4.MonoTestFunction; + var args = new asint_uint4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void asint_uint4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(asint_uint4.BurstTestFunction); + var args = new asint_uint4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class chgsign_float + { + public const int iterations = 100000; + + public struct Arguments : IDisposable + { + public Random rng; + public float* f; + public float* sign; + public float* result; + + public void Init() + { + rng = new Random(1); + f = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + f[i] = 1.0f; + } + + sign = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + sign[i] = rng.NextFloat(-1.0f, 1.0f); + } + + result = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = 0.0f; + } + + } + + public void Dispose() + { + UnsafeUtility.Free(f, Allocator.Persistent); + UnsafeUtility.Free(sign, Allocator.Persistent); + UnsafeUtility.Free(result, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.chgsign(args.f[i], args.sign[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void chgsign_float_mono() + { + chgsign_float.TestFunction testFunction = chgsign_float.MonoTestFunction; + var args = new chgsign_float.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void chgsign_float_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(chgsign_float.BurstTestFunction); + var args = new chgsign_float.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class chgsign_float2 + { + public const int iterations = 100000; + + public struct Arguments : IDisposable + { + public Random rng; + public float2* f; + public float2* sign; + public float2* result; + + public void Init() + { + rng = new Random(1); + f = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + f[i] = new float2(1.0f); + } + + sign = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + sign[i] = rng.NextFloat2(-1.0f, 1.0f); + } + + result = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new float2(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(f, Allocator.Persistent); + UnsafeUtility.Free(sign, Allocator.Persistent); + UnsafeUtility.Free(result, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.chgsign(args.f[i], args.sign[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void chgsign_float2_mono() + { + chgsign_float2.TestFunction testFunction = chgsign_float2.MonoTestFunction; + var args = new chgsign_float2.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void chgsign_float2_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(chgsign_float2.BurstTestFunction); + var args = new chgsign_float2.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class chgsign_float3 + { + public const int iterations = 100000; + + public struct Arguments : IDisposable + { + public Random rng; + public float3* f; + public float3* sign; + public float3* result; + + public void Init() + { + rng = new Random(1); + f = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + f[i] = new float3(1.0f); + } + + sign = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + sign[i] = rng.NextFloat3(-1.0f, 1.0f); + } + + result = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new float3(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(f, Allocator.Persistent); + UnsafeUtility.Free(sign, Allocator.Persistent); + UnsafeUtility.Free(result, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.chgsign(args.f[i], args.sign[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void chgsign_float3_mono() + { + chgsign_float3.TestFunction testFunction = chgsign_float3.MonoTestFunction; + var args = new chgsign_float3.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void chgsign_float3_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(chgsign_float3.BurstTestFunction); + var args = new chgsign_float3.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class chgsign_float4 + { + public const int iterations = 100000; + + public struct Arguments : IDisposable + { + public Random rng; + public float4* f; + public float4* sign; + public float4* result; + + public void Init() + { + rng = new Random(1); + f = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + f[i] = new float4(1.0f); + } + + sign = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + sign[i] = rng.NextFloat4(-1.0f, 1.0f); + } + + result = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new float4(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(f, Allocator.Persistent); + UnsafeUtility.Free(sign, Allocator.Persistent); + UnsafeUtility.Free(result, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.chgsign(args.f[i], args.sign[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void chgsign_float4_mono() + { + chgsign_float4.TestFunction testFunction = chgsign_float4.MonoTestFunction; + var args = new chgsign_float4.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void chgsign_float4_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(chgsign_float4.BurstTestFunction); + var args = new chgsign_float4.Arguments(); + args.Init(); + + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(burstSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + [BurstCompile(CompileSynchronously = true)] + public unsafe class angle_quaternion_quaternion + { + public const int iterations = 10000; + + public struct Arguments : IDisposable + { + public Random rng; + public quaternion* q1; + public quaternion* q2; + public float* result; + + public void Init() + { + rng = new Random(1); + q1 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + q1[i] = rng.NextQuaternionRotation(); + } + + q2 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + q2[i] = rng.NextQuaternionRotation(); + } + + result = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) + { + result[i] = new float(); + } + + } + + public void Dispose() + { + UnsafeUtility.Free(q1, Allocator.Persistent); + UnsafeUtility.Free(q2, Allocator.Persistent); + UnsafeUtility.Free(result, Allocator.Persistent); + } + } + + public static void CommonTestFunction(ref Arguments args) + { + for (int i = 0; i < iterations; ++i) + { + args.result[i] = math.angle(args.q1[i], args.q2[i]); + } + } + + public static void MonoTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + [BurstCompile(CompileSynchronously = true)] + public static void BurstTestFunction(ref Arguments args) + { + CommonTestFunction(ref args); + } + + public delegate void TestFunction(ref Arguments args); + } + + [Test, Performance] + public void angle_quaternion_quaternion_mono() + { + angle_quaternion_quaternion.TestFunction testFunction = angle_quaternion_quaternion.MonoTestFunction; + var args = new angle_quaternion_quaternion.Arguments(); + args.Init(); + + var monoSampleGroup = new SampleGroup("Mono", SampleUnit.Microsecond); Measure.Method(() => + { + testFunction.Invoke(ref args); + }) + .SampleGroup(monoSampleGroup) + .WarmupCount(1) + .MeasurementCount(10) + .Run(); + args.Dispose(); + } + + [Test, Performance] + public void angle_quaternion_quaternion_burst() + { + FunctionPointer testFunction = BurstCompiler.CompileFunctionPointer(angle_quaternion_quaternion.BurstTestFunction); + var args = new angle_quaternion_quaternion.Arguments(); + args.Init(); + var burstSampleGroup = new SampleGroup("Burst", SampleUnit.Microsecond); Measure.Method(() => { testFunction.Invoke(ref args); diff --git a/src/Unity.Mathematics.PerformanceTests/TestMinMaxAABB.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestMinMaxAABB.gen.cs index 41590ed8..ab4406c2 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestMinMaxAABB.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestMinMaxAABB.gen.cs @@ -21,14 +21,18 @@ partial class TestMinMaxAABB [BurstCompile(CompileSynchronously = true)] public unsafe class Transform_float4x4 { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public Geometry.MinMaxAABB* a; public void Init() { - a = (Geometry.MinMaxAABB*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + a = (Geometry.MinMaxAABB*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { a[i] = new Geometry.MinMaxAABB(); } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.a[i] = Geometry.Math.Transform(float4x4.identity, args.a[i]); } @@ -101,14 +105,18 @@ public void Transform_float4x4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Transform_float3x3 { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public Geometry.MinMaxAABB* a; public void Init() { - a = (Geometry.MinMaxAABB*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + a = (Geometry.MinMaxAABB*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { a[i] = new Geometry.MinMaxAABB(); } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.a[i] = Geometry.Math.Transform(float3x3.identity, args.a[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestMul.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestMul.gen.cs index 85bf5525..2cd2c55a 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestMul.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestMul.gen.cs @@ -21,21 +21,25 @@ partial class TestMul [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_float4x4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* m1; public float4x4* m2; public void Init() { - m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float4x4.identity; } - m2 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = float4x4.identity; } @@ -51,7 +55,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m1[i] = math.mul(args.m1[i], args.m2[i]); } @@ -109,21 +113,25 @@ public void float4x4_float4x4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_float4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* m1; public float4* m2; public void Init() { - m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float4x4.identity; } - m2 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = new float4(1.0f, 0.0f, 0.0f, 1.0f); } @@ -139,7 +147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m2[i] = math.mul(args.m1[i], args.m2[i]); } @@ -197,21 +205,25 @@ public void float4x4_float4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class quaternion_quaternion { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public quaternion* q1; public quaternion* q2; public void Init() { - q1 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + q1 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q1[i] = quaternion.identity; } - q2 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + q2 = (quaternion*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { q2[i] = quaternion.identity; } @@ -227,7 +239,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.q2[i] = math.mul(args.q1[i], args.q2[i]); } @@ -285,21 +297,25 @@ public void quaternion_quaternion_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_float3x3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* m1; public float3x3* m2; public void Init() { - m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float3x3.identity; } - m2 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = float3x3.identity; } @@ -315,7 +331,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m2[i] = math.mul(args.m1[i], args.m2[i]); } @@ -373,21 +389,25 @@ public void float3x3_float3x3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2x2_float2x2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* m1; public float2x2* m2; public void Init() { - m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float2x2.identity; } - m2 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = float2x2.identity; } @@ -403,7 +423,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m2[i] = math.mul(args.m1[i], args.m2[i]); } @@ -461,21 +481,25 @@ public void float2x2_float2x2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_float3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* m1; public float3* m2; public void Init() { - m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float3x3.identity; } - m2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = new float3(1.0f, 0.0f, 0.0f); } @@ -491,7 +515,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m2[i] = math.mul(args.m1[i], args.m2[i]); } @@ -549,21 +573,25 @@ public void float3x3_float3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2x2_float2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* m1; public float2* m2; public void Init() { - m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m1 = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m1[i] = float2x2.identity; } - m2 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m2 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m2[i] = new float2(1.0f, 0.0f); } @@ -579,7 +607,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m2[i] = math.mul(args.m1[i], args.m2[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestNoise.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestNoise.gen.cs index c9d18d8d..d87c6612 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestNoise.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestNoise.gen.cs @@ -21,14 +21,18 @@ partial class TestNoise [BurstCompile(CompileSynchronously = true)] public unsafe class snoise2D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.snoise(args.v[i]); } @@ -101,14 +105,18 @@ public void snoise2D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class snoise3D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.snoise(args.v[i]); } @@ -181,14 +189,18 @@ public void snoise3D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class snoise4D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(); } @@ -203,7 +215,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.snoise(args.v[i]); } @@ -261,21 +273,25 @@ public void snoise4D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class snoise3Dgrad { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public float3* gradient; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } - gradient = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + gradient = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { gradient[i] = new float3(); } @@ -291,7 +307,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.snoise(args.v[i], out args.gradient[i]); } @@ -349,14 +365,18 @@ public void snoise3Dgrad_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cnoise2D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -371,7 +391,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.cnoise(args.v[i]); } @@ -429,14 +449,18 @@ public void cnoise2D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cnoise3D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } @@ -451,7 +475,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.cnoise(args.v[i]); } @@ -509,14 +533,18 @@ public void cnoise3D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cnoise4D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(); } @@ -531,7 +559,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.cnoise(args.v[i]); } @@ -589,14 +617,18 @@ public void cnoise4D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class pnoise2D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -611,7 +643,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.pnoise(args.v[i], args.v[i]); } @@ -669,14 +701,18 @@ public void pnoise2D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class pnoise3D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } @@ -691,7 +727,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.pnoise(args.v[i], args.v[i]); } @@ -749,14 +785,18 @@ public void pnoise3D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class pnoise4D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(); } @@ -771,7 +811,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.pnoise(args.v[i], args.v[i]); } @@ -829,14 +869,18 @@ public void pnoise4D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cellular2D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -851,7 +895,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = noise.cellular(args.v[i]); } @@ -909,14 +953,18 @@ public void cellular2D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cellular3D { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } @@ -931,7 +979,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].xy = noise.cellular(args.v[i]); } @@ -989,14 +1037,18 @@ public void cellular3D_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cellular2x2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -1011,7 +1063,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = noise.cellular2x2(args.v[i]); } @@ -1069,14 +1121,18 @@ public void cellular2x2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class cellular2x2x2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(); } @@ -1091,7 +1147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].xy = noise.cellular2x2x2(args.v[i]); } @@ -1149,14 +1205,18 @@ public void cellular2x2x2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class psrdnoise { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -1171,7 +1231,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = noise.psrdnoise(args.v[i], args.v[i], args.v[i].y).xy; } @@ -1229,14 +1289,18 @@ public void psrdnoise_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class psrnoise { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -1251,7 +1315,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.psrnoise(args.v[i], args.v[i], args.v[i].y); } @@ -1309,14 +1373,18 @@ public void psrnoise_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class srdnoise { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -1331,7 +1399,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = noise.srdnoise(args.v[i], args.v[i].y).xy; } @@ -1389,14 +1457,18 @@ public void srdnoise_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class srnoise { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(); } @@ -1411,7 +1483,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i].x = noise.srnoise(args.v[i], args.v[i].y); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestNormalize.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestNormalize.gen.cs index 869b5f14..5f70e74d 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestNormalize.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestNormalize.gen.cs @@ -21,14 +21,18 @@ partial class TestNormalize [BurstCompile(CompileSynchronously = true)] public unsafe class float4_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(1.0f); } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -101,14 +105,18 @@ public void float4_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(1.0f); } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -181,14 +189,18 @@ public void float3_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(1.0f); } @@ -203,7 +215,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -261,14 +273,18 @@ public void float2_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double4_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double4* v; public void Init() { - v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double4(1.0f); } @@ -283,7 +299,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -341,14 +357,18 @@ public void double4_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double3_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double3* v; public void Init() { - v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double3(1.0f); } @@ -363,7 +383,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -421,14 +441,18 @@ public void double3_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double2_normalize { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double2* v; public void Init() { - v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double2(1.0f); } @@ -443,7 +467,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalize(args.v[i]); } @@ -501,14 +525,18 @@ public void double2_normalize_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* v; public void Init() { - v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float4(1.0f); } @@ -523,7 +551,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } @@ -581,14 +609,18 @@ public void float4_normalizesafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(1.0f); } @@ -603,7 +635,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } @@ -661,14 +693,18 @@ public void float3_normalizesafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* v; public void Init() { - v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float2(1.0f); } @@ -683,7 +719,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } @@ -741,14 +777,18 @@ public void float2_normalizesafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double4_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double4* v; public void Init() { - v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double4(1.0f); } @@ -763,7 +803,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } @@ -821,14 +861,18 @@ public void double4_normalizesafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double3_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double3* v; public void Init() { - v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double3(1.0f); } @@ -843,7 +887,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } @@ -901,14 +945,18 @@ public void double3_normalizesafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class double2_normalizesafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double2* v; public void Init() { - v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new double2(1.0f); } @@ -923,7 +971,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.v[i] = math.normalizesafe(args.v[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestPlane.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestPlane.gen.cs index ae1818bc..59b6949c 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestPlane.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestPlane.gen.cs @@ -21,14 +21,18 @@ partial class TestPlane [BurstCompile(CompileSynchronously = true)] public unsafe class Normalize_Plane { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public Plane* p; public void Init() { - p = (Plane*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + p = (Plane*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { p[i] = new Plane { NormalAndDistance = new float4(1.0f) }; } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.p[i] = Plane.Normalize(args.p[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestRandom.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestRandom.gen.cs index 51055cc9..c318f90f 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestRandom.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestRandom.gen.cs @@ -21,21 +21,18 @@ partial class TestRandom [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextUint { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public uint* u; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - u = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + u = (uint*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u[i] = 0; } @@ -44,16 +41,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(u, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.u[i] = args.rng[i].NextUInt(); + args.u[i] = args.rng.NextUInt(); } } @@ -109,21 +105,18 @@ public void Random_NextUint_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextUint2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public uint2* u; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - u = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + u = (uint2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u[i] = 0; } @@ -132,16 +125,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(u, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.u[i] = args.rng[i].NextUInt2(); + args.u[i] = args.rng.NextUInt2(); } } @@ -197,21 +189,18 @@ public void Random_NextUint2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextUint3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public uint3* u; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - u = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + u = (uint3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u[i] = 0; } @@ -220,16 +209,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(u, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.u[i] = args.rng[i].NextUInt3(); + args.u[i] = args.rng.NextUInt3(); } } @@ -285,21 +273,18 @@ public void Random_NextUint3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextUint4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public uint4* u; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - u = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + u = (uint4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { u[i] = 0; } @@ -308,16 +293,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(u, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.u[i] = args.rng[i].NextUInt4(); + args.u[i] = args.rng.NextUInt4(); } } @@ -373,21 +357,18 @@ public void Random_NextUint4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextFloat { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public float* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = 0.0f; } @@ -396,16 +377,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextFloat(); + args.f[i] = args.rng.NextFloat(); } } @@ -461,21 +441,18 @@ public void Random_NextFloat_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextFloat2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public float2* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new float2(0.0f); } @@ -484,16 +461,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextFloat2(); + args.f[i] = args.rng.NextFloat2(); } } @@ -549,21 +525,18 @@ public void Random_NextFloat2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextFloat3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public float3* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new float3(0.0f); } @@ -572,16 +545,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextFloat3(); + args.f[i] = args.rng.NextFloat3(); } } @@ -637,21 +609,18 @@ public void Random_NextFloat3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextFloat4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public float4* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new float4(0.0f); } @@ -660,16 +629,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextFloat4(); + args.f[i] = args.rng.NextFloat4(); } } @@ -725,21 +693,18 @@ public void Random_NextFloat4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextDouble { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public double* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (double*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = 0.0; } @@ -748,16 +713,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextDouble(); + args.f[i] = args.rng.NextDouble(); } } @@ -813,21 +777,18 @@ public void Random_NextDouble_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextDouble2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public double2* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (double2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new double2(0.0); } @@ -836,16 +797,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextDouble2(); + args.f[i] = args.rng.NextDouble2(); } } @@ -901,21 +861,18 @@ public void Random_NextDouble2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextDouble3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public double3* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (double3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new double3(0.0); } @@ -924,16 +881,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextDouble3(); + args.f[i] = args.rng.NextDouble3(); } } @@ -989,21 +945,18 @@ public void Random_NextDouble3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class Random_NextDouble4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { - public Random* rng; + public Random rng; public double4* f; public void Init() { - rng = (Random*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) - { - rng[i] = new Unity.Mathematics.Random(1); - } - - f = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + f = (double4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { f[i] = new double4(0.0); } @@ -1012,16 +965,15 @@ public void Init() public void Dispose() { - UnsafeUtility.Free(rng, Allocator.Persistent); UnsafeUtility.Free(f, Allocator.Persistent); } } public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { - args.f[i] = args.rng[i].NextDouble4(); + args.f[i] = args.rng.NextDouble4(); } } diff --git a/src/Unity.Mathematics.PerformanceTests/TestRotation.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestRotation.gen.cs index 27fbc1dd..81d0a164 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestRotation.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestRotation.gen.cs @@ -21,21 +21,25 @@ partial class TestRotation [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_EulerXYZ { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public float4x4* m; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(1.0f); } - m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float4x4.identity; } @@ -51,7 +55,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float4x4.EulerXYZ(args.v[i]); } @@ -109,21 +113,25 @@ public void float4x4_EulerXYZ_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_EulerXYZ { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public float3x3* m; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = new float3(1.0f); } - m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float3x3.identity; } @@ -139,7 +147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float3x3.EulerXYZ(args.v[i]); } @@ -197,28 +205,32 @@ public void float3x3_EulerXYZ_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_AxisAngle { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public float4x4* m; public float* angle; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = math.normalize(new float3(1.0f)); } - m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float4x4.identity; } - angle = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + angle = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { angle[i] = 1.0f; } @@ -235,7 +247,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float4x4.AxisAngle(args.v[i], args.angle[i]); } @@ -293,28 +305,32 @@ public void float4x4_AxisAngle_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_AxisAngle { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* v; public float3x3* m; public float* angle; public void Init() { - v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + v = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v[i] = math.normalize(new float3(1.0f)); } - m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float3x3.identity; } - angle = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + angle = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { angle[i] = 1.0f; } @@ -331,7 +347,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float3x3.AxisAngle(args.v[i], args.angle[i]); } @@ -389,28 +405,32 @@ public void float3x3_AxisAngle_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_LookRotation { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* forward; public float3* up; public float3x3* m; public void Init() { - forward = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + forward = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { forward[i] = math.normalize(new float3(1.0f)); } - up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { up[i] = math.normalize(new float3(0.0f, 1.0f, 0.0f)); } - m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float3x3.identity; } @@ -427,7 +447,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float3x3.LookRotation(args.forward[i], args.up[i]); } @@ -485,28 +505,32 @@ public void float3x3_LookRotation_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3x3_LookRotationSafe { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* forward; public float3* up; public float3x3* m; public void Init() { - forward = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + forward = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { forward[i] = math.normalize(new float3(1.0f)); } - up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { up[i] = math.normalize(new float3(0.0f, 1.0f, 0.0f)); } - m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float3x3.identity; } @@ -523,7 +547,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float3x3.LookRotationSafe(args.forward[i], args.up[i]); } @@ -581,8 +605,11 @@ public void float3x3_LookRotationSafe_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4x4_LookAt { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* eye; public float3* target; public float3* up; @@ -590,26 +617,27 @@ public struct Arguments : IDisposable public void Init() { - eye = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + eye = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { eye[i] = math.normalize(new float3(1.0f)); } - target = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + target = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { target[i] = math.normalize(new float3(0.0f, 1.0f, 0.0f)); } - up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + up = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { up[i] = math.normalize(new float3(-5.0f, 2.0f, 3.0f)); } - m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float4x4.identity; } @@ -627,7 +655,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = float4x4.LookAt(args.eye[i], args.target[i], args.up[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestShuffle.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestShuffle.gen.cs index a4d37840..03742fd4 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestShuffle.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestShuffle.gen.cs @@ -21,28 +21,32 @@ partial class TestShuffle [BurstCompile(CompileSynchronously = true)] public unsafe class float2_shuffle { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float2* v1; public float2* v2; public float2* result; public void Init() { - v1 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v1 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v1[i] = new float2(1.0f); } - v2 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + v2 = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v2[i] = new float2(2.0f); } - result = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + result = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { result[i] = new float2(1.0f); } @@ -59,7 +63,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.result[i] = math.shuffle(args.v1[i], args.v2[i], math.ShuffleComponent.RightX, math.ShuffleComponent.LeftY); } @@ -117,28 +121,32 @@ public void float2_shuffle_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3_shuffle { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float3* v1; public float3* v2; public float3* result; public void Init() { - v1 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v1 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v1[i] = new float3(1.0f); } - v2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + v2 = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v2[i] = new float3(2.0f); } - result = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + result = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { result[i] = new float3(1.0f); } @@ -155,7 +163,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.result[i] = math.shuffle(args.v1[i], args.v2[i], math.ShuffleComponent.RightX, math.ShuffleComponent.LeftZ, math.ShuffleComponent.LeftX); } @@ -213,28 +221,32 @@ public void float3_shuffle_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_shuffle { + public const int iterations = 100000; + public struct Arguments : IDisposable { + public Random rng; public float4* v1; public float4* v2; public float4* result; public void Init() { - v1 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + rng = new Random(1); + v1 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v1[i] = new float4(1.0f); } - v2 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + v2 = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { v2[i] = new float4(2.0f); } - result = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 100000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 100000; ++i) + result = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { result[i] = new float4(1.0f); } @@ -251,7 +263,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 100000; ++i) + for (int i = 0; i < iterations; ++i) { args.result[i] = math.shuffle(args.v1[i], args.v2[i], math.ShuffleComponent.RightX, math.ShuffleComponent.LeftZ, math.ShuffleComponent.LeftX, math.ShuffleComponent.RightY); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestTranspose.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestTranspose.gen.cs index 67625c77..53198cd8 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestTranspose.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestTranspose.gen.cs @@ -21,14 +21,18 @@ partial class TestTranspose [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_float4x4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4x4* m; public void Init() { - m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (float4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float4x4.identity; } @@ -43,7 +47,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } @@ -101,14 +105,18 @@ public void transpose_float4x4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_float3x3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3x3* m; public void Init() { - m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (float3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float3x3.identity; } @@ -123,7 +131,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } @@ -181,14 +189,18 @@ public void transpose_float3x3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_float2x2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2x2* m; public void Init() { - m = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (float2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = float2x2.identity; } @@ -203,7 +215,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } @@ -261,14 +273,18 @@ public void transpose_float2x2_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_double4x4 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double4x4* m; public void Init() { - m = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (double4x4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = double4x4.identity; } @@ -283,7 +299,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } @@ -341,14 +357,18 @@ public void transpose_double4x4_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_double3x3 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double3x3* m; public void Init() { - m = (double3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (double3x3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = double3x3.identity; } @@ -363,7 +383,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } @@ -421,14 +441,18 @@ public void transpose_double3x3_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class transpose_double2x2 { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public double2x2* m; public void Init() { - m = (double2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + m = (double2x2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { m[i] = double2x2.identity; } @@ -443,7 +467,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { args.m[i] = math.transpose(args.m[i]); } diff --git a/src/Unity.Mathematics.PerformanceTests/TestTrig.gen.cs b/src/Unity.Mathematics.PerformanceTests/TestTrig.gen.cs index 55e88160..ba2b8ab5 100644 --- a/src/Unity.Mathematics.PerformanceTests/TestTrig.gen.cs +++ b/src/Unity.Mathematics.PerformanceTests/TestTrig.gen.cs @@ -21,21 +21,25 @@ partial class TestTrig [BurstCompile(CompileSynchronously = true)] public unsafe class float_sincos { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float* sin; public float* cos; public void Init() { - sin = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + sin = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { sin[i] = 0.0f; } - cos = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + cos = (float*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { cos[i] = 1.0f; } @@ -51,7 +55,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { math.sincos(args.sin[i], out args.sin[i], out args.cos[i]); } @@ -109,21 +113,25 @@ public void float_sincos_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float2_sincos { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float2* sin; public float2* cos; public void Init() { - sin = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + sin = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { sin[i] = new float2(0.0f); } - cos = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + cos = (float2*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { cos[i] = new float2(1.0f); } @@ -139,7 +147,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { math.sincos(args.sin[i], out args.sin[i], out args.cos[i]); } @@ -197,21 +205,25 @@ public void float2_sincos_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float3_sincos { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float3* sin; public float3* cos; public void Init() { - sin = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + sin = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { sin[i] = new float3(0.0f); } - cos = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + cos = (float3*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { cos[i] = new float3(1.0f); } @@ -227,7 +239,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { math.sincos(args.sin[i], out args.sin[i], out args.cos[i]); } @@ -285,21 +297,25 @@ public void float3_sincos_burst() [BurstCompile(CompileSynchronously = true)] public unsafe class float4_sincos { + public const int iterations = 10000; + public struct Arguments : IDisposable { + public Random rng; public float4* sin; public float4* cos; public void Init() { - sin = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + rng = new Random(1); + sin = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { sin[i] = new float4(0.0f); } - cos = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * 10000, UnsafeUtility.AlignOf(), Allocator.Persistent); - for (int i = 0; i < 10000; ++i) + cos = (float4*)UnsafeUtility.Malloc(UnsafeUtility.SizeOf() * iterations, UnsafeUtility.AlignOf(), Allocator.Persistent); + for (int i = 0; i < iterations; ++i) { cos[i] = new float4(1.0f); } @@ -315,7 +331,7 @@ public void Dispose() public static void CommonTestFunction(ref Arguments args) { - for (int i = 0; i < 10000; ++i) + for (int i = 0; i < iterations; ++i) { math.sincos(args.sin[i], out args.sin[i], out args.cos[i]); } diff --git a/src/Unity.Mathematics.Shaders.meta b/src/Unity.Mathematics.PerformanceTests/Unity.Mathematics.PerformanceTests.csproj.meta similarity index 67% rename from src/Unity.Mathematics.Shaders.meta rename to src/Unity.Mathematics.PerformanceTests/Unity.Mathematics.PerformanceTests.csproj.meta index 85226af8..178e830f 100644 --- a/src/Unity.Mathematics.Shaders.meta +++ b/src/Unity.Mathematics.PerformanceTests/Unity.Mathematics.PerformanceTests.csproj.meta @@ -1,6 +1,5 @@ fileFormatVersion: 2 -guid: 9b10a64aa490dfe46a4bdee58b85da27 -folderAsset: yes +guid: 83a70727fa33a914d9c1049386e82be7 DefaultImporter: externalObjects: {} userData: diff --git a/src/Unity.Mathematics.Shaders/hlsl.cs b/src/Unity.Mathematics.Shaders/hlsl.cs deleted file mode 100644 index c49ad5e8..00000000 --- a/src/Unity.Mathematics.Shaders/hlsl.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System.Runtime.CompilerServices; - -namespace Unity.Mathematics.Shaders -{ - public static class hlsl - { - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddx(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddx(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddx(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddx(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddx(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddx(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddx(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddx_fine(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddx_fine(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddx_fine(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddx_fine(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddx_fine(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddx_fine(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddx_fine(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddx_coarse(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddx_coarse(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddx_coarse(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddx_coarse(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddx_coarse(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddx_coarse(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddx_coarse(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddy(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddy(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddy(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddy(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddy(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddy(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddy(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddy_fine(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddy_fine(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddy_fine(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddy_fine(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddy_fine(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddy_fine(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddy_fine(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float ddy_coarse(float x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2 ddy_coarse(float2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 ddy_coarse(float3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4 ddy_coarse(float4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float2x2 ddy_coarse(float2x2 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3x3 ddy_coarse(float3x3 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float4x4 ddy_coarse(float4x4 x) { throw new System.NotImplementedException(); } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static void discard() { } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static void clip(float i) { } - - [MethodImpl((MethodImplOptions)0x100)] // agressive inline - public static float3 faceforward(float3 n, float3 i, float3 ng) { return math.cross(-n, math.sign(math.dot(i, ng))); } - } -} diff --git a/src/Unity.Mathematics.sln b/src/Unity.Mathematics.sln index 19d5c88a..2af7740a 100644 --- a/src/Unity.Mathematics.sln +++ b/src/Unity.Mathematics.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29806.167 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Mathematics", "Unity.Mathematics\Unity.Mathematics.csproj", "{19810344-7387-4155-935F-BDD5CC61F0BF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Mathematics.CodeGen", "Unity.Mathematics.CodeGen\Unity.Mathematics.CodeGen.csproj", "{293EBCD6-CACD-4DA8-A518-FBC629268C0F}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "General", "General", "{B11ECCE1-1A78-40B2-956F-CBE615FF5DF9}" ProjectSection(SolutionItems) = preProject CHANGELOG.md = CHANGELOG.md @@ -16,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "General", "General", "{B11E EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Mathematics.Tests", "Tests\Unity.Mathematics.Tests.csproj", "{2E7C74D3-42F1-482F-8BB7-E199D9E3B412}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Mathematics.CodeGen", "Unity.Mathematics.CodeGen~\Unity.Mathematics.CodeGen.csproj", "{293EBCD6-CACD-4DA8-A518-FBC629268C0F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,28 +28,16 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x64.ActiveCfg = Debug|x64 - {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x64.Build.0 = Debug|x64 + {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x64.ActiveCfg = Debug|Any CPU + {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x64.Build.0 = Debug|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x86.ActiveCfg = Debug|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Debug|x86.Build.0 = Debug|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|Any CPU.Build.0 = Release|Any CPU - {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x64.ActiveCfg = Release|x64 - {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x64.Build.0 = Release|x64 + {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x64.ActiveCfg = Release|Any CPU + {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x64.Build.0 = Release|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x86.ActiveCfg = Release|Any CPU {19810344-7387-4155-935F-BDD5CC61F0BF}.Release|x86.Build.0 = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x64.ActiveCfg = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x64.Build.0 = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x86.ActiveCfg = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x86.Build.0 = Debug|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|Any CPU.Build.0 = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x64.ActiveCfg = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x64.Build.0 = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x86.ActiveCfg = Release|Any CPU - {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x86.Build.0 = Release|Any CPU {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -62,6 +50,18 @@ Global {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Release|x64.Build.0 = Release|Any CPU {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Release|x86.ActiveCfg = Release|Any CPU {2E7C74D3-42F1-482F-8BB7-E199D9E3B412}.Release|x86.Build.0 = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x64.ActiveCfg = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x64.Build.0 = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x86.ActiveCfg = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Debug|x86.Build.0 = Debug|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|Any CPU.Build.0 = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x64.ActiveCfg = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x64.Build.0 = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x86.ActiveCfg = Release|Any CPU + {293EBCD6-CACD-4DA8-A518-FBC629268C0F}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Unity.Mathematics/Geometry/MinMaxAABB.cs b/src/Unity.Mathematics/Geometry/MinMaxAABB.cs index eb4a3876..6b5b666d 100644 --- a/src/Unity.Mathematics/Geometry/MinMaxAABB.cs +++ b/src/Unity.Mathematics/Geometry/MinMaxAABB.cs @@ -16,7 +16,7 @@ namespace Unity.Mathematics.Geometry /// [System.Serializable] [Il2CppEagerStaticClassConstruction] - internal struct MinMaxAABB : IEquatable + public struct MinMaxAABB : IEquatable { /// /// The minimum point contained by the AABB. @@ -213,7 +213,7 @@ public override string ToString() } } - internal static partial class Math + public static partial class Math { /// /// Transforms the AABB with the given transform. diff --git a/src/Unity.Mathematics/Geometry/Plane.cs b/src/Unity.Mathematics/Geometry/Plane.cs index 92d47c5e..5094bb94 100644 --- a/src/Unity.Mathematics/Geometry/Plane.cs +++ b/src/Unity.Mathematics/Geometry/Plane.cs @@ -15,7 +15,7 @@ namespace Unity.Mathematics.Geometry [DebuggerDisplay("{Normal}, {Distance}")] [Serializable] [Il2CppEagerStaticClassConstruction] - internal struct Plane + public struct Plane { /// /// A plane in the form Ax + By + Cz + Dw = 0. diff --git a/src/Unity.Mathematics/Il2CppEagerStaticClassConstructionAttribute.cs b/src/Unity.Mathematics/Il2CppEagerStaticClassConstructionAttribute.cs index 1588a77e..6f64b476 100644 --- a/src/Unity.Mathematics/Il2CppEagerStaticClassConstructionAttribute.cs +++ b/src/Unity.Mathematics/Il2CppEagerStaticClassConstructionAttribute.cs @@ -7,7 +7,7 @@ namespace Unity.IL2CPP.CompilerServices /// rather than lazily at runtime. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] - public class Il2CppEagerStaticClassConstructionAttribute : Attribute + internal class Il2CppEagerStaticClassConstructionAttribute : Attribute { } } \ No newline at end of file diff --git a/src/Unity.Mathematics/Properties/AssemblyInfo.cs b/src/Unity.Mathematics/Properties/AssemblyInfo.cs index c090f5b4..582cdee0 100644 --- a/src/Unity.Mathematics/Properties/AssemblyInfo.cs +++ b/src/Unity.Mathematics/Properties/AssemblyInfo.cs @@ -1,47 +1,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if !UNITY_DOTSPLAYER -using System.Reflection; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("Unity.Mathematics")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Unity.Mathematics")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. - -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM - -[assembly: Guid("19810344-7387-4155-935F-BDD5CC61F0BF")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -#endif - [assembly: InternalsVisibleTo("Unity.Mathematics.Tests")] [assembly: InternalsVisibleTo("Unity.Mathematics.PerformanceTests")] -[assembly: InternalsVisibleTo("btests")] \ No newline at end of file diff --git a/src/Unity.Mathematics/Properties/AssemblyInfo.cs.meta b/src/Unity.Mathematics/Properties/AssemblyInfo.cs.meta index 8b36ead0..048f3093 100644 --- a/src/Unity.Mathematics/Properties/AssemblyInfo.cs.meta +++ b/src/Unity.Mathematics/Properties/AssemblyInfo.cs.meta @@ -1,11 +1,2 @@ fileFormatVersion: 2 -guid: 512db12834bb1f645a5c18af6c16e398 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: +guid: fb0d7ffc71c40bd49a849e6427f80cb5 \ No newline at end of file diff --git a/src/Unity.Mathematics/Unity.Mathematics.csproj b/src/Unity.Mathematics/Unity.Mathematics.csproj index 11383fbb..6a97724f 100644 --- a/src/Unity.Mathematics/Unity.Mathematics.csproj +++ b/src/Unity.Mathematics/Unity.Mathematics.csproj @@ -1,162 +1,21 @@ - - - + - Debug - AnyCPU - {19810344-7387-4155-935F-BDD5CC61F0BF} - {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Properties - Unity - Unity.Mathematics - v4.7.1 - 512 - - - AnyCPU - true - full - false - ..\..\build\bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - true - - - AnyCPU - pdbonly - true - ..\..\build\bin\Release\ - TRACE - prompt - 4 - true - true - - - AnyCPU - true - full - false - ..\..\build\bin\Debug\ - DEBUG;TRACE - prompt - 4 - true - true - - + net471 AnyCPU - pdbonly - true - ..\..\build\bin\Release\ - TRACE - prompt - 4 true - true + false + ..\..\build\bin\$(Configuration)\ + + 1.0.0.0 - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - + \ No newline at end of file diff --git a/src/Unity.Mathematics.CodeGen.meta b/src/Unity.Mathematics/Unity.Mathematics.csproj.meta similarity index 67% rename from src/Unity.Mathematics.CodeGen.meta rename to src/Unity.Mathematics/Unity.Mathematics.csproj.meta index 192a75dc..ebf3a017 100644 --- a/src/Unity.Mathematics.CodeGen.meta +++ b/src/Unity.Mathematics/Unity.Mathematics.csproj.meta @@ -1,6 +1,5 @@ fileFormatVersion: 2 -guid: ba9313d729590a14dbcd58e38024613d -folderAsset: yes +guid: adc57cbbc95b9e449ba89e2bd869e8d9 DefaultImporter: externalObjects: {} userData: diff --git a/src/Unity.Mathematics/affine_transform.cs b/src/Unity.Mathematics/affine_transform.cs new file mode 100644 index 00000000..6ba30887 --- /dev/null +++ b/src/Unity.Mathematics/affine_transform.cs @@ -0,0 +1,322 @@ +using System; +using System.Runtime.CompilerServices; +using Unity.IL2CPP.CompilerServices; +using static Unity.Mathematics.math; + +namespace Unity.Mathematics +{ + /// + /// An affine transformation type. + /// + [Il2CppEagerStaticClassConstruction] + [Serializable] + public struct AffineTransform : IEquatable, IFormattable + { + /// + /// The rotation and scale part of the affine transformation. + /// + public float3x3 rs; + + /// + /// The translation part of the affine transformation. + /// + public float3 t; + + /// An AffineTransform representing the identity transform. + public static readonly AffineTransform identity = new AffineTransform(float3.zero, float3x3.identity); + + /// + /// An AffineTransform zero value. + /// + public static readonly AffineTransform zero; + + /// Constructs an AffineTransform from a translation represented by a float3 vector and rotation represented by a unit quaternion. + /// The translation vector. + /// The rotation quaternion. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float3 translation, quaternion rotation) + { + rs = float3x3(rotation); + t = translation; + } + + /// Constructs an AffineTransform from a translation represented by a float3 vector, rotation represented by a unit quaternion and scale represented by a float3 vector. + /// The translation vector. + /// The rotation quaternion. + /// The scale vector. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float3 translation, quaternion rotation, float3 scale) + { + rs = mulScale(math.float3x3(rotation), scale); + t = translation; + } + + /// Constructs an AffineTransform from a translation represented by float3 vector and a float3x3 matrix representing both rotation and scale. + /// The translation vector. + /// The rotation and scale matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float3 translation, float3x3 rotationScale) + { + rs = rotationScale; + t = translation; + } + + /// Constructs an AffineTransform from float3x3 matrix representating both rotation and scale. + /// The rotation and scale matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float3x3 rotationScale) + { + rs = rotationScale; + t = float3.zero; + } + + /// Constructs an AffineTransform from a RigidTransform. + /// The RigidTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(RigidTransform rigid) + { + rs = math.float3x3(rigid.rot); + t = rigid.pos; + } + + /// Constructs an AffineTransform from a float3x4 matrix. + /// The float3x4 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float3x4 m) + { + rs = math.float3x3(m.c0, m.c1, m.c2); + t = m.c3; + } + + /// Constructs an AffineTransform from a float4x4 matrix. + /// The float4x4 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public AffineTransform(float4x4 m) + { + rs = math.float3x3(m.c0.xyz, m.c1.xyz, m.c2.xyz); + t = m.c3.xyz; + } + + /// Implicit float3x4 cast operator. + /// The AffineTransform. + /// The converted AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator float3x4(AffineTransform m) { return float3x4(m.rs.c0, m.rs.c1, m.rs.c2, m.t); } + + /// Implicit float4x4 cast operator. + /// The AffineTransform. + /// The converted AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator float4x4(AffineTransform m) { return float4x4(float4(m.rs.c0, 0f), float4(m.rs.c1, 0f), float4(m.rs.c2, 0f), float4(m.t, 1f)); } + + /// Returns true if the AffineTransform is equal to a given AffineTransform, false otherwise. + /// Right hand side argument to compare equality with. + /// The result of the equality comparison. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(AffineTransform rhs) { return rs.Equals(rhs.rs) && t.Equals(rhs.t); } + + /// Returns true if the AffineTransform is equal to a given AffineTransform, false otherwise. + /// Right hand side argument to compare equality with. + /// The result of the equality comparison. + public override bool Equals(object o) { return o is AffineTransform converted && Equals(converted); } + + /// Returns a hash code for the AffineTransform. + /// The computed hash code. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() { return (int)hash(this); } + + /// Returns a string representation of the AffineTransform. + /// String representation of the value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override string ToString() + { + return string.Format("AffineTransform(({0}f, {1}f, {2}f, {3}f, {4}f, {5}f, {6}f, {7}f, {8}f), ({9}f, {10}f, {11}f))", + rs.c0.x, rs.c1.x, rs.c2.x, rs.c0.y, rs.c1.y, rs.c2.y, rs.c0.z, rs.c1.z, rs.c2.z, t.x, t.y, t.z + ); + } + + /// Returns a string representation of the AffineTransform using a specified format and culture-specific format information. + /// Format string to use during string formatting. + /// Format provider to use during string formatting. + /// String representation of the value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public string ToString(string format, IFormatProvider formatProvider) + { + return string.Format("AffineTransform(({0}f, {1}f, {2}f, {3}f, {4}f, {5}f, {6}f, {7}f, {8}f), ({9}f, {10}f, {11}f))", + rs.c0.x.ToString(format, formatProvider), rs.c1.x.ToString(format, formatProvider), rs.c2.x.ToString(format, formatProvider), + rs.c0.y.ToString(format, formatProvider), rs.c1.y.ToString(format, formatProvider), rs.c2.y.ToString(format, formatProvider), + rs.c0.z.ToString(format, formatProvider), rs.c1.z.ToString(format, formatProvider), rs.c2.z.ToString(format, formatProvider), + t.x.ToString(format, formatProvider), t.y.ToString(format, formatProvider), t.z.ToString(format, formatProvider) + ); + } + } + + public static partial class math + { + /// Returns an AffineTransform constructed from a translation represented by a float3 vector and rotation represented by a unit quaternion. + /// The AffineTransform translation. + /// The AffineTransform rotation. + /// The AffineTransform given the translation vector and rotation quaternion. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float3 translation, quaternion rotation) { return new AffineTransform(translation, rotation); } + + /// Returns an AffineTransform constructed from a translation represented by a float3 vector, rotation represented by a unit quaternion and scale represented by a float3 vector. + /// The translation vector. + /// The rotation quaternion. + /// The scale vector. + /// The AffineTransform given the translation vector, rotation quaternion and scale vector. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float3 translation, quaternion rotation, float3 scale) { return new AffineTransform(translation, rotation, scale); } + + /// Returns an AffineTransform constructed from a translation represented by float3 vector and a float3x3 matrix representing both rotation and scale. + /// The translation vector. + /// The rotation and scale matrix. + /// The AffineTransform given the translation vector and float3x3 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float3 translation, float3x3 rotationScale) { return new AffineTransform(translation, rotationScale); } + + /// Returns an AffineTransform constructed from a float3x3 matrix representing both rotation and scale. + /// The rotation and scale matrix. + /// The AffineTransform given a float3x3 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float3x3 rotationScale) { return new AffineTransform(rotationScale); } + + /// Returns an AffineTransform constructed from a float4x4 matrix. + /// The float4x4 matrix. + /// The AffineTransform given a float4x4 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float4x4 m) { return new AffineTransform(m); } + + /// Returns an AffineTransform constructed from a float3x4 matrix. + /// The float3x4 matrix. + /// The AffineTransform given a float3x4 matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(float3x4 m) { return new AffineTransform(m); } + + /// Returns an AffineTransform constructed from a RigidTransform. + /// The RigidTransform. + /// The AffineTransform given a RigidTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform AffineTransform(RigidTransform rigid) { return new AffineTransform (rigid); } + + /// Returns a float4x4 matrix constructed from an AffineTransform. + /// The AffineTransform. + /// The float4x4 matrix given an AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float4x4 float4x4(AffineTransform transform) { return float4x4(float4(transform.rs.c0, 0f), float4(transform.rs.c1, 0f), float4(transform.rs.c2, 0f), float4(transform.t, 1f)); } + + /// Returns a float3x4 matrix constructed from an AffineTransform. + /// The AffineTransform. + /// The float3x4 matrix given an AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3x4 float3x4(AffineTransform transform) { return float3x4(transform.rs.c0, transform.rs.c1, transform.rs.c2, transform.t); } + + /// Returns the result of transforming the AffineTransform b by the AffineTransform a. + /// The AffineTransform on the left. + /// The AffineTransform on the right. + /// The AffineTransform of a transforming b. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform mul(AffineTransform a, AffineTransform b) + { + return new AffineTransform(transform(a, b.t), mul(a.rs, b.rs)); + } + + /// Returns the result of transforming the AffineTransform b by a float3x3 matrix a. + /// The float3x3 matrix on the left. + /// The AffineTransform on the right. + /// The AffineTransform of a transforming b. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform mul(float3x3 a, AffineTransform b) + { + return new AffineTransform(mul(a, b.t), mul(a, b.rs)); + } + + /// Returns the result of transforming the float3x3 b by an AffineTransform a. + /// The AffineTransform on the left. + /// The float3x3 matrix on the right. + /// The AffineTransform of a transforming b. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform mul(AffineTransform a, float3x3 b) + { + return new AffineTransform(a.t, mul(b, a.rs)); + } + + /// Returns the result of transforming a float4 homogeneous coordinate by an AffineTransform. + /// The AffineTransform. + /// The position to be transformed. + /// The transformed position. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float4 mul(AffineTransform a, float4 pos) + { + return float4(mul(a.rs, pos.xyz) + a.t * pos.w, pos.w); + } + + /// Returns the result of rotating a float3 vector by an AffineTransform. + /// The AffineTransform. + /// The direction vector to rotate. + /// The rotated direction vector. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 rotate(AffineTransform a, float3 dir) + { + return mul(a.rs, dir); + } + + /// Returns the result of transforming a float3 point by an AffineTransform. + /// The AffineTransform. + /// The position to transform. + /// The transformed position. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 transform(AffineTransform a, float3 pos) + { + return a.t + mul(a.rs, pos); + } + + /// Returns the inverse of an AffineTransform. + /// The AffineTransform to invert. + /// The inverse AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AffineTransform inverse(AffineTransform a) + { + AffineTransform inv; + inv.rs = pseudoinverse(a.rs); + inv.t = mul(inv.rs, -a.t); + return inv; + } + + /// Decomposes the AffineTransform in translation, rotation and scale. + /// The AffineTransform + /// The decomposed translation vector of the AffineTransform. + /// The decomposed rotation quaternion of the AffineTransform. + /// The decomposed scale of the AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void decompose(AffineTransform a, out float3 translation, out quaternion rotation, out float3 scale) + { + translation = a.t; + rotation = math.rotation(a.rs); + var sm = mul(float3x3(conjugate(rotation)), a.rs); + scale = float3(sm.c0.x, sm.c1.y, sm.c2.z); + } + + /// Returns a uint hash code of an AffineTransform. + /// The AffineTransform to hash. + /// The hash code of the input AffineTransform. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint hash(AffineTransform a) + { + return hash(a.rs) + 0xC5C5394Bu * hash(a.t); + } + + /// + /// Returns a uint4 vector hash code of an AffineTransform. + /// When multiple elements are to be hashes together, it can more efficient to calculate and combine wide hash + /// that are only reduced to a narrow uint hash at the very end instead of at every step. + /// + /// The AffineTransform to hash. + /// The uint4 wide hash code. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint4 hashwide(AffineTransform a) + { + return hashwide(a.rs).xyzz + 0xC5C5394Bu * hashwide(a.t).xyzz; + } + } +} diff --git a/src/Unity.Mathematics/affine_transform.cs.meta b/src/Unity.Mathematics/affine_transform.cs.meta new file mode 100644 index 00000000..19d69b1d --- /dev/null +++ b/src/Unity.Mathematics/affine_transform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 25c2cff1b9e35e648980b04c895d7332 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Unity.Mathematics/math.cs b/src/Unity.Mathematics/math.cs index 3400cc01..b17d04fe 100644 --- a/src/Unity.Mathematics/math.cs +++ b/src/Unity.Mathematics/math.cs @@ -70,6 +70,33 @@ public enum ShuffleComponent : byte /// The mathematical constant pi. Approximately 3.14. This is a f64/double precision constant. public const double PI_DBL = 3.14159265358979323846; + /// + /// The mathematical constant (2 * pi). Approximately 6.28. This is a f64/double precision constant. Also known as . + /// + public const double PI2_DBL = PI_DBL * 2.0; + + /// + /// The mathematical constant (pi / 2). Approximately 1.57. This is a f64/double precision constant. + /// + public const double PIHALF_DBL = PI_DBL * 0.5; + + /// + /// The mathematical constant tau. Approximately 6.28. This is a f64/double precision constant. Also known as . + /// + public const double TAU_DBL = PI2_DBL; + + /// + /// The conversion constant used to convert radians to degrees. Multiply the radian value by this constant to get degrees. + /// + /// Multiplying by this constant is equivalent to using . + public const double TODEGREES_DBL = 57.29577951308232; + + /// + /// The conversion constant used to convert degrees to radians. Multiply the degree value by this constant to get radians. + /// + /// Multiplying by this constant is equivalent to using . + public const double TORADIANS_DBL = 0.017453292519943296; + /// The square root 2. Approximately 1.41. This is a f64/double precision constant. public const double SQRT2_DBL = 1.41421356237309504880; @@ -121,6 +148,33 @@ public enum ShuffleComponent : byte /// The mathematical constant pi. Approximately 3.14. public const float PI = (float)PI_DBL; + /// + /// The mathematical constant (2 * pi). Approximately 6.28. Also known as . + /// + public const float PI2 = (float)PI2_DBL; + + /// + /// The mathematical constant (pi / 2). Approximately 1.57. + /// + public const float PIHALF = (float)PIHALF_DBL; + + /// + /// The mathematical constant tau. Approximately 6.28. Also known as . + /// + public const float TAU = (float)PI2_DBL; + + /// + /// The conversion constant used to convert radians to degrees. Multiply the radian value by this constant to get degrees. + /// + /// Multiplying by this constant is equivalent to using . + public const float TODEGREES = (float)TODEGREES_DBL; + + /// + /// The conversion constant used to convert degrees to radians. Multiply the degree value by this constant to get radians. + /// + /// Multiplying by this constant is equivalent to using . + public const float TORADIANS = (float)TORADIANS_DBL; + /// The square root 2. Approximately 1.41. public const float SQRT2 = (float)SQRT2_DBL; @@ -152,56 +206,97 @@ public enum ShuffleComponent : byte /// The uint bits to copy. /// The int with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int asint(uint x) { return (int)x; } + public static int asint(uint x) + { + unsafe + { + return *(int*)&x; + } + } /// Returns the bit pattern of a uint2 as an int2. /// The uint2 bits to copy. /// The int2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 asint(uint2 x) { return int2((int)x.x, (int)x.y); } + public static int2 asint(uint2 x) + { + unsafe + { + return *(int2*)&x; + } + } /// Returns the bit pattern of a uint3 as an int3. /// The uint3 bits to copy. /// The int3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 asint(uint3 x) { return int3((int)x.x, (int)x.y, (int)x.z); } + public static int3 asint(uint3 x) + { + unsafe + { + return *(int3*)&x; + } + } /// Returns the bit pattern of a uint4 as an int4. /// The uint4 bits to copy. /// The int4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 asint(uint4 x) { return int4((int)x.x, (int)x.y, (int)x.z, (int)x.w); } - + public static int4 asint(uint4 x) + { + unsafe + { + return *(int4*)&x; + } + } /// Returns the bit pattern of a float as an int. /// The float bits to copy. /// The int with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int asint(float x) { - IntFloatUnion u; - u.intValue = 0; - u.floatValue = x; - return u.intValue; + public static int asint(float x) + { + unsafe + { + return *(int*)&x; + } } /// Returns the bit pattern of a float2 as an int2. /// The float2 bits to copy. /// The int2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 asint(float2 x) { return int2(asint(x.x), asint(x.y)); } + public static int2 asint(float2 x) + { + unsafe + { + return *(int2*)&x; + } + } /// Returns the bit pattern of a float3 as an int3. /// The float3 bits to copy. /// The int3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 asint(float3 x) { return int3(asint(x.x), asint(x.y), asint(x.z)); } + public static int3 asint(float3 x) + { + unsafe + { + return *(int3*)&x; + } + } /// Returns the bit pattern of a float4 as an int4. /// The float4 bits to copy. /// The int4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 asint(float4 x) { return int4(asint(x.x), asint(x.y), asint(x.z), asint(x.w)); } - + public static int4 asint(float4 x) + { + unsafe + { + return *(int4*)&x; + } + } /// Returns the bit pattern of an int as a uint. /// The int bits to copy. @@ -213,45 +308,85 @@ public static int asint(float x) { /// The int2 bits to copy. /// The uint2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 asuint(int2 x) { return uint2((uint)x.x, (uint)x.y); } + public static uint2 asuint(int2 x) + { + unsafe + { + return *(uint2*)&x; + } + } /// Returns the bit pattern of an int3 as a uint3. /// The int3 bits to copy. /// The uint3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 asuint(int3 x) { return uint3((uint)x.x, (uint)x.y, (uint)x.z); } + public static uint3 asuint(int3 x) + { + unsafe + { + return *(uint3*)&x; + } + } /// Returns the bit pattern of an int4 as a uint4. /// The int4 bits to copy. /// The uint4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 asuint(int4 x) { return uint4((uint)x.x, (uint)x.y, (uint)x.z, (uint)x.w); } - + public static uint4 asuint(int4 x) + { + unsafe + { + return *(uint4*)&x; + } + } /// Returns the bit pattern of a float as a uint. /// The float bits to copy. /// The uint with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint asuint(float x) { return (uint)asint(x); } + public static uint asuint(float x) + { + unsafe + { + return *(uint*)&x; + } + } /// Returns the bit pattern of a float2 as a uint2. /// The float2 bits to copy. /// The uint2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 asuint(float2 x) { return uint2(asuint(x.x), asuint(x.y)); } + public static uint2 asuint(float2 x) + { + unsafe + { + return *(uint2*)&x; + } + } /// Returns the bit pattern of a float3 as a uint3. /// The float3 bits to copy. /// The uint3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 asuint(float3 x) { return uint3(asuint(x.x), asuint(x.y), asuint(x.z)); } + public static uint3 asuint(float3 x) + { + unsafe + { + return *(uint3*)&x; + } + } /// Returns the bit pattern of a float4 as a uint4. /// The float4 bits to copy. /// The uint4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 asuint(float4 x) { return uint4(asuint(x.x), asuint(x.y), asuint(x.z), asuint(x.w)); } - + public static uint4 asuint(float4 x) + { + unsafe + { + return *(uint4*)&x; + } + } /// Returns the bit pattern of a ulong as a long. /// The ulong bits to copy. @@ -265,13 +400,12 @@ public static int asint(float x) { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long aslong(double x) { - LongDoubleUnion u; - u.longValue = 0; - u.doubleValue = x; - return u.longValue; + unsafe + { + return *(long*)&x; + } } - /// Returns the bit pattern of a long as a ulong. /// The long bits to copy. /// The ulong with the same bit pattern as the input. @@ -282,8 +416,13 @@ public static long aslong(double x) /// The double bits to copy. /// The ulong with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong asulong(double x) { return (ulong) aslong(x); } - + public static ulong asulong(double x) + { + unsafe + { + return *(ulong*)&x; + } + } /// Returns the bit pattern of an int as a float. /// The int bits to copy. @@ -291,55 +430,95 @@ public static long aslong(double x) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float asfloat(int x) { - IntFloatUnion u; - u.floatValue = 0; - u.intValue = x; - - return u.floatValue; + unsafe + { + return *(float*)&x; + } } /// Returns the bit pattern of an int2 as a float2. /// The int2 bits to copy. /// The float2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 asfloat(int2 x) { return float2(asfloat(x.x), asfloat(x.y)); } + public static float2 asfloat(int2 x) + { + unsafe + { + return *(float2*)&x; + } + } /// Returns the bit pattern of an int3 as a float3. /// The int3 bits to copy. /// The float3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 asfloat(int3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); } + public static float3 asfloat(int3 x) + { + unsafe + { + return *(float3*)&x; + } + } /// Returns the bit pattern of an int4 as a float4. /// The int4 bits to copy. /// The float4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 asfloat(int4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); } - + public static float4 asfloat(int4 x) + { + unsafe + { + return *(float4*)&x; + } + } /// Returns the bit pattern of a uint as a float. /// The uint bits to copy. /// The float with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float asfloat(uint x) { return asfloat((int)x); } + public static float asfloat(uint x) + { + unsafe + { + return *(float*)&x; + } + } /// Returns the bit pattern of a uint2 as a float2. /// The uint2 bits to copy. /// The float2 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 asfloat(uint2 x) { return float2(asfloat(x.x), asfloat(x.y)); } + public static float2 asfloat(uint2 x) + { + unsafe + { + return *(float2*)&x; + } + } /// Returns the bit pattern of a uint3 as a float3. /// The uint3 bits to copy. /// The float3 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 asfloat(uint3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); } + public static float3 asfloat(uint3 x) + { + unsafe + { + return *(float3*)&x; + } + } /// Returns the bit pattern of a uint4 as a float4. /// The uint4 bits to copy. /// The float4 with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 asfloat(uint4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); } + public static float4 asfloat(uint4 x) + { + unsafe + { + return *(float4*)&x; + } + } /// /// Returns a bitmask representation of a bool4. Storing one 1 bit per component @@ -368,19 +547,23 @@ public static int bitmask(bool4 value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double asdouble(long x) { - LongDoubleUnion u; - u.doubleValue = 0; - u.longValue = x; - return u.doubleValue; + unsafe + { + return *(double*)&x; + } } - /// Returns the bit pattern of a ulong as a double. /// The ulong bits to copy. /// The double with the same bit pattern as the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double asdouble(ulong x) { return asdouble((long)x); } - + public static double asdouble(ulong x) + { + unsafe + { + return *(double*)&x; + } + } /// Returns true if the input float is a finite floating point value, false otherwise. /// The float value to test. @@ -928,394 +1111,394 @@ public static bool4 ispow2(uint4 x) public static double4 max(double4 x, double4 y) { return new double4(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)); } - /// Returns the result of linearly interpolating from x to y using the interpolation parameter s. + /// Returns the result of linearly interpolating from start to end using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. - /// The interpolation from x to y. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The interpolation from start to end. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float lerp(float x, float y, float s) { return x + s * (y - x); } + public static float lerp(float start, float end, float t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 lerp(float2 x, float2 y, float s) { return x + s * (y - x); } + public static float2 lerp(float2 start, float2 end, float t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 lerp(float3 x, float3 y, float s) { return x + s * (y - x); } + public static float3 lerp(float3 start, float3 end, float t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 lerp(float4 x, float4 y, float s) { return x + s * (y - x); } + public static float4 lerp(float4 start, float4 end, float t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 lerp(float2 x, float2 y, float2 s) { return x + s * (y - x); } + public static float2 lerp(float2 start, float2 end, float2 t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 lerp(float3 x, float3 y, float3 s) { return x + s * (y - x); } + public static float3 lerp(float3 start, float3 end, float3 t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 lerp(float4 x, float4 y, float4 s) { return x + s * (y - x); } + public static float4 lerp(float4 start, float4 end, float4 t) { return start + t * (end - start); } - /// Returns the result of linearly interpolating from x to y using the interpolation parameter s. + /// Returns the result of linearly interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double lerp(double x, double y, double s) { return x + s * (y - x); } + public static double lerp(double start, double end, double t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 lerp(double2 x, double2 y, double s) { return x + s * (y - x); } + public static double2 lerp(double2 start, double2 end, double t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 lerp(double3 x, double3 y, double s) { return x + s * (y - x); } + public static double3 lerp(double3 start, double3 end, double t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 lerp(double4 x, double4 y, double s) { return x + s * (y - x); } + public static double4 lerp(double4 start, double4 end, double t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 lerp(double2 x, double2 y, double2 s) { return x + s * (y - x); } + public static double2 lerp(double2 start, double2 end, double2 t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 lerp(double3 x, double3 y, double3 s) { return x + s * (y - x); } + public static double3 lerp(double3 start, double3 end, double3 t) { return start + t * (end - start); } - /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. + /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t. /// /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates. /// - /// The first endpoint, corresponding to the interpolation parameter value of 0. - /// The second endpoint, corresponding to the interpolation parameter value of 1. - /// The interpolation parameter. May be a value outside the interval [0, 1]. + /// The start point, corresponding to the interpolation parameter value of 0. + /// The end point, corresponding to the interpolation parameter value of 1. + /// The interpolation parameter. May be a value outside the interval [0, 1]. /// The componentwise interpolation from x to y. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 lerp(double4 x, double4 y, double4 s) { return x + s * (y - x); } + public static double4 lerp(double4 start, double4 end, double4 t) { return start + t * (end - start); } /// Returns the result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float unlerp(float a, float b, float x) { return (x - a) / (b - a); } + public static float unlerp(float start, float end, float x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 unlerp(float2 a, float2 b, float2 x) { return (x - a) / (b - a); } + public static float2 unlerp(float2 start, float2 end, float2 x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 unlerp(float3 a, float3 b, float3 x) { return (x - a) / (b - a); } + public static float3 unlerp(float3 start, float3 end, float3 x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 unlerp(float4 a, float4 b, float4 x) { return (x - a) / (b - a); } + public static float4 unlerp(float4 start, float4 end, float4 x) { return (x - start) / (end - start); } /// Returns the result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double unlerp(double a, double b, double x) { return (x - a) / (b - a); } + public static double unlerp(double start, double end, double x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 unlerp(double2 a, double2 b, double2 x) { return (x - a) / (b - a); } + public static double2 unlerp(double2 start, double2 end, double2 x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 unlerp(double3 a, double3 b, double3 x) { return (x - a) / (b - a); } + public static double3 unlerp(double3 start, double3 end, double3 x) { return (x - start) / (end - start); } /// Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a). - /// The first endpoint of the range. - /// The second endpoint of the range. + /// The start point of the range. + /// The end point of the range. /// The value to normalize to the range. /// The componentwise interpolation parameter of x with respect to the input range [a, b]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 unlerp(double4 a, double4 b, double4 x) { return (x - a) / (b - a); } + public static double4 unlerp(double4 start, double4 end, double4 x) { return (x - start) / (end - start); } - /// Returns the result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float remap(float a, float b, float c, float d, float x) { return lerp(c, d, unlerp(a, b, x)); } + public static float remap(float srcStart, float srcEnd, float dstStart, float dstEnd, float x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 remap(float2 a, float2 b, float2 c, float2 d, float2 x) { return lerp(c, d, unlerp(a, b, x)); } + public static float2 remap(float2 srcStart, float2 srcEnd, float2 dstStart, float2 dstEnd, float2 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 remap(float3 a, float3 b, float3 c, float3 d, float3 x) { return lerp(c, d, unlerp(a, b, x)); } + public static float3 remap(float3 srcStart, float3 srcEnd, float3 dstStart, float3 dstEnd, float3 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 remap(float4 a, float4 b, float4 c, float4 d, float4 x) { return lerp(c, d, unlerp(a, b, x)); } + public static float4 remap(float4 srcStart, float4 srcEnd, float4 dstStart, float4 dstEnd, float4 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double remap(double a, double b, double c, double d, double x) { return lerp(c, d, unlerp(a, b, x)); } + public static double remap(double srcStart, double srcEnd, double dstStart, double dstEnd, double x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 remap(double2 a, double2 b, double2 c, double2 d, double2 x) { return lerp(c, d, unlerp(a, b, x)); } + public static double2 remap(double2 srcStart, double2 srcEnd, double2 dstStart, double2 dstEnd, double2 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 remap(double3 a, double3 b, double3 c, double3 d, double3 x) { return lerp(c, d, unlerp(a, b, x)); } + public static double3 remap(double3 srcStart, double3 srcEnd, double3 dstStart, double3 dstEnd, double3 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } - /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d]. - /// The first endpoint of the source range [a,b]. - /// The second endpoint of the source range [a, b]. - /// The first endpoint of the destination range [c, d]. - /// The second endpoint of the destination range [c, d]. + /// Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd]. + /// The start point of the source range [srcStart, srcEnd]. + /// The end point of the source range [srcStart, srcEnd]. + /// The start point of the destination range [dstStart, dstEnd]. + /// The end point of the destination range [dstStart, dstEnd]. /// The value to remap from the source to destination range. /// The componentwise remap of input x from the source range to the destination range. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 remap(double4 a, double4 b, double4 c, double4 d, double4 x) { return lerp(c, d, unlerp(a, b, x)); } + public static double4 remap(double4 srcStart, double4 srcEnd, double4 dstStart, double4 dstEnd, double4 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); } /// Returns the result of a multiply-add operation (a * b + c) on 3 int values. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int mad(int a, int b, int c) { return a * b + c; } + public static int mad(int mulA, int mulB, int addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int2 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 mad(int2 a, int2 b, int2 c) { return a * b + c; } + public static int2 mad(int2 mulA, int2 mulB, int2 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int3 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 mad(int3 a, int3 b, int3 c) { return a * b + c; } + public static int3 mad(int3 mulA, int3 mulB, int3 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int4 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 mad(int4 a, int4 b, int4 c) { return a * b + c; } + public static int4 mad(int4 mulA, int4 mulB, int4 addC) { return mulA * mulB + addC; } /// Returns the result of a multiply-add operation (a * b + c) on 3 uint values. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint mad(uint a, uint b, uint c) { return a * b + c; } + public static uint mad(uint mulA, uint mulB, uint addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint2 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 mad(uint2 a, uint2 b, uint2 c) { return a * b + c; } + public static uint2 mad(uint2 mulA, uint2 mulB, uint2 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint3 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 mad(uint3 a, uint3 b, uint3 c) { return a * b + c; } + public static uint3 mad(uint3 mulA, uint3 mulB, uint3 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint4 vectors. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 mad(uint4 a, uint4 b, uint4 c) { return a * b + c; } + public static uint4 mad(uint4 mulA, uint4 mulB, uint4 addC) { return mulA * mulB + addC; } /// Returns the result of a multiply-add operation (a * b + c) on 3 long values. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long mad(long a, long b, long c) { return a * b + c; } + public static long mad(long mulA, long mulB, long addC) { return mulA * mulB + addC; } /// Returns the result of a multiply-add operation (a * b + c) on 3 ulong values. - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong mad(ulong a, ulong b, ulong c) { return a * b + c; } + public static ulong mad(ulong mulA, ulong mulB, ulong addC) { return mulA * mulB + addC; } /// Returns the result of a multiply-add operation (a * b + c) on 3 float values. @@ -1324,12 +1507,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float mad(float a, float b, float c) { return a * b + c; } + public static float mad(float mulA, float mulB, float addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float2 vectors. /// @@ -1337,12 +1520,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 mad(float2 a, float2 b, float2 c) { return a * b + c; } + public static float2 mad(float2 mulA, float2 mulB, float2 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float3 vectors. /// @@ -1350,12 +1533,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 mad(float3 a, float3 b, float3 c) { return a * b + c; } + public static float3 mad(float3 mulA, float3 mulB, float3 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float4 vectors. /// @@ -1363,12 +1546,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 mad(float4 a, float4 b, float4 c) { return a * b + c; } + public static float4 mad(float4 mulA, float4 mulB, float4 addC) { return mulA * mulB + addC; } /// Returns the result of a multiply-add operation (a * b + c) on 3 double values. @@ -1377,12 +1560,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double mad(double a, double b, double c) { return a * b + c; } + public static double mad(double mulA, double mulB, double addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double2 vectors. /// @@ -1390,12 +1573,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 mad(double2 a, double2 b, double2 c) { return a * b + c; } + public static double2 mad(double2 mulA, double2 mulB, double2 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double3 vectors. /// @@ -1403,12 +1586,12 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 mad(double3 a, double3 b, double3 c) { return a * b + c; } + public static double3 mad(double3 mulA, double3 mulB, double3 addC) { return mulA * mulB + addC; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double4 vectors. /// @@ -1416,161 +1599,161 @@ public static bool4 ispow2(uint4 x) /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when /// this computation is not fused. /// - /// First value to multiply. - /// Second value to multiply. - /// Third value to add to the product of a and b. + /// First value to multiply. + /// Second value to multiply. + /// Third value to add to the product of a and b. /// The componentwise multiply-add of the inputs. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 mad(double4 a, double4 b, double4 c) { return a * b + c; } + public static double4 mad(double4 mulA, double4 mulB, double4 addC) { return mulA * mulB + addC; } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are int values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int clamp(int x, int a, int b) { return max(a, min(b, x)); } + public static int clamp(int valueToClamp, int lowerBound, int upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } /// Returns the result of a componentwise clamping of the int2 x into the interval [a, b], where a and b are int2 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 clamp(int2 x, int2 a, int2 b) { return max(a, min(b, x)); } + public static int2 clamp(int2 valueToClamp, int2 lowerBound, int2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } /// Returns the result of a componentwise clamping of the int3 x into the interval [a, b], where x, a and b are int3 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 clamp(int3 x, int3 a, int3 b) { return max(a, min(b, x)); } + public static int3 clamp(int3 valueToClamp, int3 lowerBound, int3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are int4 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int4 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 clamp(int4 x, int4 a, int4 b) { return max(a, min(b, x)); } + public static int4 clamp(int4 valueToClamp, int4 lowerBound, int4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are uint values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint clamp(uint x, uint a, uint b) { return max(a, min(b, x)); } + public static uint clamp(uint valueToClamp, uint lowerBound, uint upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint2 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint2 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 clamp(uint2 x, uint2 a, uint2 b) { return max(a, min(b, x)); } + public static uint2 clamp(uint2 valueToClamp, uint2 lowerBound, uint2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint3 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint3 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 clamp(uint3 x, uint3 a, uint3 b) { return max(a, min(b, x)); } + public static uint3 clamp(uint3 valueToClamp, uint3 lowerBound, uint3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint4 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint4 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 clamp(uint4 x, uint4 a, uint4 b) { return max(a, min(b, x)); } + public static uint4 clamp(uint4 valueToClamp, uint4 lowerBound, uint4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are long values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are long values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long clamp(long x, long a, long b) { return max(a, min(b, x)); } + public static long clamp(long valueToClamp, long lowerBound, long upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are ulong values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are ulong values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong clamp(ulong x, ulong a, ulong b) { return max(a, min(b, x)); } + public static ulong clamp(ulong valueToClamp, ulong lowerBound, ulong upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are float values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float clamp(float x, float a, float b) { return max(a, min(b, x)); } + public static float clamp(float valueToClamp, float lowerBound, float upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float2 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float2 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 clamp(float2 x, float2 a, float2 b) { return max(a, min(b, x)); } + public static float2 clamp(float2 valueToClamp, float2 lowerBound, float2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float3 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float3 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 clamp(float3 x, float3 a, float3 b) { return max(a, min(b, x)); } + public static float3 clamp(float3 valueToClamp, float3 lowerBound, float3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float4 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float4 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 clamp(float4 x, float4 a, float4 b) { return max(a, min(b, x)); } + public static float4 clamp(float4 valueToClamp, float4 lowerBound, float4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are double values. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The clamping of the input x into the interval [a, b]. + /// Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double values. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double clamp(double x, double a, double b) { return max(a, min(b, x)); } + public static double clamp(double valueToClamp, double lowerBound, double upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double2 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double2 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 clamp(double2 x, double2 a, double2 b) { return max(a, min(b, x)); } + public static double2 clamp(double2 valueToClamp, double2 lowerBound, double2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double3 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double3 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 clamp(double3 x, double3 a, double3 b) { return max(a, min(b, x)); } + public static double3 clamp(double3 valueToClamp, double3 lowerBound, double3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } - /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double4 vectors. - /// Input value to be clamped. - /// Lower bound of the interval. - /// Upper bound of the interval. - /// The componentwise clamping of the input x into the interval [a, b]. + /// Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double4 vectors. + /// Input value to be clamped. + /// Lower bound of the interval. + /// Upper bound of the interval. + /// The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 clamp(double4 x, double4 a, double4 b) { return max(a, min(b, x)); } + public static double4 clamp(double4 valueToClamp, double4 lowerBound, double4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); } /// Returns the result of clamping the float value x into the interval [0, 1]. @@ -2328,7 +2511,7 @@ public static bool4 ispow2(uint4 x) public static double4 asin(double4 x) { return new double4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); } - /// Returns the result of rounding a float value up to the nearest integral value less or equal to the original value. + /// Returns the result of rounding a float value down to the nearest integral value less or equal to the original value. /// Input value. /// The round down to nearest integral value of the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2353,7 +2536,7 @@ public static bool4 ispow2(uint4 x) public static float4 floor(float4 x) { return new float4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); } - /// Returns the result of rounding a double value up to the nearest integral value less or equal to the original value. + /// Returns the result of rounding a double value down to the nearest integral value less or equal to the original value. /// Input value. /// The round down to nearest integral value of the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -2627,7 +2810,6 @@ public static bool4 ispow2(uint4 x) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 rcp(double4 x) { return 1.0 / x; } - /// Returns the sign of a int value. -1 if it is less than zero, 0 if it is zero and 1 if it greater than zero. /// Input value. /// The sign of the input. @@ -2652,7 +2834,6 @@ public static bool4 ispow2(uint4 x) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 sign(int4 x) { return new int4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); } - /// Returns the sign of a float value. -1.0f if it is less than zero, 0.0f if it is zero and 1.0f if it greater than zero. /// Input value. /// The sign of the input. @@ -3649,100 +3830,100 @@ public static bool4 ispow2(uint4 x) public static double3 cross(double3 x, double3 y) { return (x * y.yzx - x.yzx * y).yzx; } - /// Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns a value camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float smoothstep(float a, float b, float x) + public static float smoothstep(float xMin, float xMax, float x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0f - (2.0f * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 smoothstep(float2 a, float2 b, float2 x) + public static float2 smoothstep(float2 xMin, float2 xMax, float2 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0f - (2.0f * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 smoothstep(float3 a, float3 b, float3 x) + public static float3 smoothstep(float3 xMin, float3 xMax, float3 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0f - (2.0f * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 smoothstep(float4 a, float4 b, float4 x) + public static float4 smoothstep(float4 xMin, float4 xMax, float4 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0f - (2.0f * t)); } - /// Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns a value camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double smoothstep(double a, double b, double x) + public static double smoothstep(double xMin, double xMax, double x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0 - (2.0 * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 smoothstep(double2 a, double2 b, double2 x) + public static double2 smoothstep(double2 xMin, double2 xMax, double2 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0 - (2.0 * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 smoothstep(double3 a, double3 b, double3 x) + public static double3 smoothstep(double3 xMin, double3 xMax, double3 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0 - (2.0 * t)); } - /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. - /// The minimum range of the x parameter. - /// The maximum range of the x parameter. + /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax]. + /// The minimum range of the x parameter. + /// The maximum range of the x parameter. /// The value to be interpolated. /// Returns component values camped to the range [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 smoothstep(double4 a, double4 b, double4 x) + public static double4 smoothstep(double4 xMin, double4 xMax, double4 x) { - var t = saturate((x - a) / (b - a)); + var t = saturate((x - xMin) / (xMax - xMin)); return t * t * (3.0 - (2.0 * t)); } @@ -3937,346 +4118,346 @@ public static double4 smoothstep(double4 a, double4 b, double4 x) public static bool all(double4 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0 && x.w != 0.0; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int select(int a, int b, bool c) { return c ? b : a; } + public static int select(int falseValue, int trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 select(int2 a, int2 b, bool c) { return c ? b : a; } + public static int2 select(int2 falseValue, int2 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 select(int3 a, int3 b, bool c) { return c ? b : a; } + public static int3 select(int3 falseValue, int3 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 select(int4 a, int4 b, bool c) { return c ? b : a; } + public static int4 select(int4 falseValue, int4 trueValue, bool test) { return test ? trueValue : falseValue; } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int2 select(int2 a, int2 b, bool2 c) { return new int2(c.x ? b.x : a.x, c.y ? b.y : a.y); } + public static int2 select(int2 falseValue, int2 trueValue, bool2 test) { return new int2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int3 select(int3 a, int3 b, bool3 c) { return new int3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } + public static int3 select(int3 falseValue, int3 trueValue, bool3 test) { return new int3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int4 select(int4 a, int4 b, bool4 c) { return new int4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } + public static int4 select(int4 falseValue, int4 trueValue, bool4 test) { return new int4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint select(uint a, uint b, bool c) { return c ? b : a; } + public static uint select(uint falseValue, uint trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 select(uint2 a, uint2 b, bool c) { return c ? b : a; } + public static uint2 select(uint2 falseValue, uint2 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 select(uint3 a, uint3 b, bool c) { return c ? b : a; } + public static uint3 select(uint3 falseValue, uint3 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 select(uint4 a, uint4 b, bool c) { return c ? b : a; } + public static uint4 select(uint4 falseValue, uint4 trueValue, bool test) { return test ? trueValue : falseValue; } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint2 select(uint2 a, uint2 b, bool2 c) { return new uint2(c.x ? b.x : a.x, c.y ? b.y : a.y); } + public static uint2 select(uint2 falseValue, uint2 trueValue, bool2 test) { return new uint2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint3 select(uint3 a, uint3 b, bool3 c) { return new uint3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } + public static uint3 select(uint3 falseValue, uint3 trueValue, bool3 test) { return new uint3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint4 select(uint4 a, uint4 b, bool4 c) { return new uint4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } + public static uint4 select(uint4 falseValue, uint4 trueValue, bool4 test) { return new uint4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long select(long a, long b, bool c) { return c ? b : a; } + public static long select(long falseValue, long trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong select(ulong a, ulong b, bool c) { return c ? b : a; } + public static ulong select(ulong falseValue, ulong trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float select(float a, float b, bool c) { return c ? b : a; } + public static float select(float falseValue, float trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 select(float2 a, float2 b, bool c) { return c ? b : a; } + public static float2 select(float2 falseValue, float2 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 select(float3 a, float3 b, bool c) { return c ? b : a; } + public static float3 select(float3 falseValue, float3 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 select(float4 a, float4 b, bool c) { return c ? b : a; } + public static float4 select(float4 falseValue, float4 trueValue, bool test) { return test ? trueValue : falseValue; } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 select(float2 a, float2 b, bool2 c) { return new float2(c.x ? b.x : a.x, c.y ? b.y : a.y); } + public static float2 select(float2 falseValue, float2 trueValue, bool2 test) { return new float2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 select(float3 a, float3 b, bool3 c) { return new float3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } + public static float3 select(float3 falseValue, float3 trueValue, bool3 test) { return new float3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 select(float4 a, float4 b, bool4 c) { return new float4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } + public static float4 select(float4 falseValue, float4 trueValue, bool4 test) { return new float4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double select(double a, double b, bool c) { return c ? b : a; } + public static double select(double falseValue, double trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 select(double2 a, double2 b, bool c) { return c ? b : a; } + public static double2 select(double2 falseValue, double2 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 select(double3 a, double3 b, bool c) { return c ? b : a; } + public static double3 select(double3 falseValue, double3 trueValue, bool test) { return test ? trueValue : falseValue; } - /// Returns b if c is true, a otherwise. - /// Value to use if c is false. - /// Value to use if c is true. - /// Bool value to choose between a and b. - /// The selection between a and b according to bool c. + /// Returns trueValue if test is true, falseValue otherwise. + /// Value to use if test is false. + /// Value to use if test is true. + /// Bool value to choose between falseValue and trueValue. + /// The selection between falseValue and trueValue according to bool test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 select(double4 a, double4 b, bool c) { return c ? b : a; } + public static double4 select(double4 falseValue, double4 trueValue, bool test) { return test ? trueValue : falseValue; } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 select(double2 a, double2 b, bool2 c) { return new double2(c.x ? b.x : a.x, c.y ? b.y : a.y); } + public static double2 select(double2 falseValue, double2 trueValue, bool2 test) { return new double2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 select(double3 a, double3 b, bool3 c) { return new double3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } + public static double3 select(double3 falseValue, double3 trueValue, bool3 test) { return new double3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); } /// - /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. - /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. + /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test. + /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected. /// - /// Values to use if c is false. - /// Values to use if c is true. - /// Selection mask to choose between a and b. - /// The componentwise selection between a and b according to selection mask c. + /// Values to use if test is false. + /// Values to use if test is true. + /// Selection mask to choose between falseValue and trueValue. + /// The componentwise selection between falseValue and trueValue according to selection mask test. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 select(double4 a, double4 b, bool4 c) { return new double4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } + public static double4 select(double4 falseValue, double4 trueValue, bool4 test) { return new double4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); } - /// Returns the result of a step function where the result is 1.0f when x >= y and 0.0f otherwise. - /// Value to be used as a threshold for returning 1. - /// Value to compare against threshold y. - /// 1 if the comparison x >= y is true, otherwise 0. + /// Returns the result of a step function where the result is 1.0f when x >= threshold and 0.0f otherwise. + /// Value to be used as a threshold for returning 1. + /// Value to compare against threshold. + /// 1 if the comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float step(float y, float x) { return select(0.0f, 1.0f, x >= y); } + public static float step(float threshold, float x) { return select(0.0f, 1.0f, x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 step(float2 y, float2 x) { return select(float2(0.0f), float2(1.0f), x >= y); } + public static float2 step(float2 threshold, float2 x) { return select(float2(0.0f), float2(1.0f), x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 step(float3 y, float3 x) { return select(float3(0.0f), float3(1.0f), x >= y); } + public static float3 step(float3 threshold, float3 x) { return select(float3(0.0f), float3(1.0f), x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 step(float4 y, float4 x) { return select(float4(0.0f), float4(1.0f), x >= y); } + public static float4 step(float4 threshold, float4 x) { return select(float4(0.0f), float4(1.0f), x >= threshold); } - /// Returns the result of a step function where the result is 1.0f when x >= y and 0.0f otherwise. - /// Values to be used as a threshold for returning 1. - /// Values to compare against threshold y. - /// 1 if the comparison x >= y is true, otherwise 0. + /// Returns the result of a step function where the result is 1.0f when x >= threshold and 0.0f otherwise. + /// Values to be used as a threshold for returning 1. + /// Value to compare against threshold. + /// 1 if the comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double step(double y, double x) { return select(0.0, 1.0, x >= y); } + public static double step(double threshold, double x) { return select(0.0, 1.0, x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 step(double2 y, double2 x) { return select(double2(0.0), double2(1.0), x >= y); } + public static double2 step(double2 threshold, double2 x) { return select(double2(0.0), double2(1.0), x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 step(double3 y, double3 x) { return select(double3(0.0), double3(1.0), x >= y); } + public static double3 step(double3 threshold, double3 x) { return select(double3(0.0), double3(1.0), x >= threshold); } - /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. - /// Vector of values to be used as a threshold for returning 1. - /// Vector of values to compare against threshold y. - /// 1 if the componentwise comparison x >= y is true, otherwise 0. + /// Returns the result of a componentwise step function where each component is 1.0f when x >= threshold and 0.0f otherwise. + /// Vector of values to be used as a threshold for returning 1. + /// Vector of values to compare against threshold. + /// 1 if the componentwise comparison x >= threshold is true, otherwise 0. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 step(double4 y, double4 x) { return select(double4(0.0), double4(1.0), x >= y); } + public static double4 step(double4 threshold, double4 x) { return select(double4(0.0), double4(1.0), x >= threshold); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n. @@ -4323,83 +4504,83 @@ public static double4 smoothstep(double4 a, double4 b, double4 x) public static double4 reflect(double4 i, double4 n) { return i - 2 * n * dot(i, n); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 refract(float2 i, float2 n, float eta) + public static float2 refract(float2 i, float2 n, float indexOfRefraction) { float ni = dot(n, i); - float k = 1.0f - eta * eta * (1.0f - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 refract(float3 i, float3 n, float eta) + public static float3 refract(float3 i, float3 n, float indexOfRefraction) { float ni = dot(n, i); - float k = 1.0f - eta * eta * (1.0f - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 refract(float4 i, float4 n, float eta) + public static float4 refract(float4 i, float4 n, float indexOfRefraction) { float ni = dot(n, i); - float k = 1.0f - eta * eta * (1.0f - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 refract(double2 i, double2 n, double eta) + public static double2 refract(double2 i, double2 n, double indexOfRefraction) { double ni = dot(n, i); - double k = 1.0 - eta * eta * (1.0 - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 refract(double3 i, double3 n, double eta) + public static double3 refract(double3 i, double3 n, double indexOfRefraction) { double ni = dot(n, i); - double k = 1.0 - eta * eta * (1.0 - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } - /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. + /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index. /// Incident vector. /// Normal vector. - /// Index of refraction. + /// Index of refraction. /// Refraction vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 refract(double4 i, double4 n, double eta) + public static double4 refract(double4 i, double4 n, double indexOfRefraction) { double ni = dot(n, i); - double k = 1.0 - eta * eta * (1.0 - ni * ni); - return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); + double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni); + return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0); } /// @@ -4412,12 +4593,12 @@ public static double4 refract(double4 i, double4 n, double eta) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 project(float2 a, float2 b) + public static float2 project(float2 a, float2 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4430,12 +4611,12 @@ public static float2 project(float2 a, float2 b) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 project(float3 a, float3 b) + public static float3 project(float3 a, float3 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4448,12 +4629,12 @@ public static float3 project(float3 a, float3 b) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 project(float4 a, float4 b) + public static float4 project(float4 a, float4 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4466,13 +4647,13 @@ public static float4 project(float4 a, float4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 projectsafe(float2 a, float2 b, float2 defaultValue = new float2()) + public static float2 projectsafe(float2 a, float2 ontoB, float2 defaultValue = new float2()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -4487,13 +4668,13 @@ public static float4 project(float4 a, float4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 projectsafe(float3 a, float3 b, float3 defaultValue = new float3()) + public static float3 projectsafe(float3 a, float3 ontoB, float3 defaultValue = new float3()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -4508,13 +4689,13 @@ public static float4 project(float4 a, float4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 projectsafe(float4 a, float4 b, float4 defaultValue = new float4()) + public static float4 projectsafe(float4 a, float4 ontoB, float4 defaultValue = new float4()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -4529,12 +4710,12 @@ public static float4 project(float4 a, float4 b) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 project(double2 a, double2 b) + public static double2 project(double2 a, double2 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4547,12 +4728,12 @@ public static double2 project(double2 a, double2 b) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 project(double3 a, double3 b) + public static double3 project(double3 a, double3 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4565,12 +4746,12 @@ public static double3 project(double3 a, double3 b) /// which will use a given default value if the result is not finite. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Vector projection of a onto b. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 project(double4 a, double4 b) + public static double4 project(double4 a, double4 ontoB) { - return (dot(a, b) / dot(b, b)) * b; + return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB; } /// @@ -4583,13 +4764,13 @@ public static double4 project(double4 a, double4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 projectsafe(double2 a, double2 b, double2 defaultValue = new double2()) + public static double2 projectsafe(double2 a, double2 ontoB, double2 defaultValue = new double2()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -4604,13 +4785,13 @@ public static double4 project(double4 a, double4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 projectsafe(double3 a, double3 b, double3 defaultValue = new double3()) + public static double3 projectsafe(double3 a, double3 ontoB, double3 defaultValue = new double3()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -4625,13 +4806,13 @@ public static double4 project(double4 a, double4 b) /// function. /// /// Vector to project. - /// Non-zero vector to project onto. + /// Non-zero vector to project onto. /// Default value to return if projection is not finite. /// Vector projection of a onto b or the default value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 projectsafe(double4 a, double4 b, double4 defaultValue = new double4()) + public static double4 projectsafe(double4 a, double4 ontoB, double4 defaultValue = new double4()) { - var proj = project(a, b); + var proj = project(a, ontoB); return select(defaultValue, proj, all(isfinite(proj))); } @@ -5333,6 +5514,7 @@ public static ulong reversebits(ulong x) /// Returns the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5348,6 +5530,7 @@ public static int ceilpow2(int x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5363,6 +5546,7 @@ public static int2 ceilpow2(int2 x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5378,6 +5562,7 @@ public static int3 ceilpow2(int3 x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5394,6 +5579,7 @@ public static int4 ceilpow2(int4 x) /// Returns the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5409,6 +5595,7 @@ public static uint ceilpow2(uint x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5424,6 +5611,7 @@ public static uint2 ceilpow2(uint2 x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5439,6 +5627,7 @@ public static uint3 ceilpow2(uint3 x) } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The componentwise smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5455,6 +5644,7 @@ public static uint4 ceilpow2(uint4 x) /// Returns the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5472,6 +5662,7 @@ public static long ceilpow2(long x) /// Returns the smallest power of two greater than or equal to the input. + /// Also known as nextpow2. /// Input value. /// The smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -5699,100 +5890,100 @@ public static int4 floorlog2(uint4 x) /// Angle in degrees. /// Angle converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float radians(float x) { return x * 0.0174532925f; } + public static float radians(float x) { return x * TORADIANS; } /// Returns the result of a componentwise conversion of a float2 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 radians(float2 x) { return x * 0.0174532925f; } + public static float2 radians(float2 x) { return x * TORADIANS; } /// Returns the result of a componentwise conversion of a float3 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 radians(float3 x) { return x * 0.0174532925f; } + public static float3 radians(float3 x) { return x * TORADIANS; } /// Returns the result of a componentwise conversion of a float4 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 radians(float4 x) { return x * 0.0174532925f; } + public static float4 radians(float4 x) { return x * TORADIANS; } /// Returns the result of converting a float value from degrees to radians. /// Angle in degrees. /// Angle converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double radians(double x) { return x * 0.017453292519943296; } + public static double radians(double x) { return x * TORADIANS_DBL; } /// Returns the result of a componentwise conversion of a float2 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 radians(double2 x) { return x * 0.017453292519943296; } + public static double2 radians(double2 x) { return x * TORADIANS_DBL; } /// Returns the result of a componentwise conversion of a float3 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 radians(double3 x) { return x * 0.017453292519943296; } + public static double3 radians(double3 x) { return x * TORADIANS_DBL; } /// Returns the result of a componentwise conversion of a float4 vector from degrees to radians. /// Vector containing angles in degrees. /// Vector containing angles converted to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 radians(double4 x) { return x * 0.017453292519943296; } + public static double4 radians(double4 x) { return x * TORADIANS_DBL; } /// Returns the result of converting a double value from radians to degrees. /// Angle in radians. /// Angle converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float degrees(float x) { return x * 57.295779513f; } + public static float degrees(float x) { return x * TODEGREES; } /// Returns the result of a componentwise conversion of a double2 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing angles converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float2 degrees(float2 x) { return x * 57.295779513f; } + public static float2 degrees(float2 x) { return x * TODEGREES; } /// Returns the result of a componentwise conversion of a double3 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing angles converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float3 degrees(float3 x) { return x * 57.295779513f; } + public static float3 degrees(float3 x) { return x * TODEGREES; } /// Returns the result of a componentwise conversion of a double4 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing angles converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float4 degrees(float4 x) { return x * 57.295779513f; } + public static float4 degrees(float4 x) { return x * TODEGREES; } /// Returns the result of converting a double value from radians to degrees. /// Angle in radians. /// Angle converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double degrees(double x) { return x * 57.29577951308232; } + public static double degrees(double x) { return x * TODEGREES_DBL; } /// Returns the result of a componentwise conversion of a double2 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing angles converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double2 degrees(double2 x) { return x * 57.29577951308232; } + public static double2 degrees(double2 x) { return x * TODEGREES_DBL; } /// Returns the result of a componentwise conversion of a double3 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing values converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double3 degrees(double3 x) { return x * 57.29577951308232; } + public static double3 degrees(double3 x) { return x * TODEGREES_DBL; } /// Returns the result of a componentwise conversion of a double4 vector from radians to degrees. /// Vector containing angles in radians. /// Vector containing angles converted to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double4 degrees(double4 x) { return x * 57.29577951308232; } + public static double4 degrees(double4 x) { return x * TODEGREES_DBL; } /// Returns the minimum component of an int2 vector. @@ -6473,12 +6664,59 @@ public static void orthonormal_basis(double3 normal, out double3 basis1, out dou basis2.z = -normal.y; } - /// Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context. - /// A pointer to the beginning of the data. - /// Number of bytes to hash. - /// Starting seed value. - /// The 32 bit hash of the input data buffer. - public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0) + /// Change the sign of x based on the most significant bit of y [msb(y) ? -x : x]. + /// The single precision float to change the sign. + /// The single precision float used to test the most significant bit. + /// Returns x with changed sign based on y. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float chgsign(float x, float y) + { + return asfloat(asuint(x) ^ (asuint(y) & 0x80000000)); + } + + /// Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x]. + /// The single precision float vector to change the sign. + /// The single precision float vector used to test the most significant bit. + /// Returns vector x with changed sign based on vector y. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float2 chgsign(float2 x, float2 y) + { + return asfloat(asuint(x) ^ (asuint(y) & 0x80000000)); + } + + /// Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x]. + /// The single precision float vector to change the sign. + /// The single precision float vector used to test the most significant bit. + /// Returns vector x with changed sign based on vector y. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 chgsign(float3 x, float3 y) + { + return asfloat(asuint(x) ^ (asuint(y) & 0x80000000)); + } + + /// Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x]. + /// The single precision float vector to change the sign. + /// The single precision float vector used to test the most significant bit. + /// Returns vector x with changed sign based on vector y. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float4 chgsign(float4 x, float4 y) + { + return asfloat(asuint(x) ^ (asuint(y) & 0x80000000)); + } + + /// + /// Read 32 bits of data in little endian format. + /// + /// Memory address to read from. + /// 32 bits in little endian format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint read32_little_endian(void* pBuffer) + { + byte* ptr = (byte*)pBuffer; + return (uint)ptr[0] | ((uint)ptr[1] << 8) | ((uint)ptr[2] << 16) | ((uint)ptr[3] << 24); + } + + private static unsafe uint hash_with_unaligned_loads(void* pBuffer, int numBytes, uint seed) { unchecked { @@ -6531,6 +6769,74 @@ public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0) } } + private static unsafe uint hash_without_unaligned_loads(void* pBuffer, int numBytes, uint seed) + { + unchecked + { + const uint Prime1 = 2654435761; + const uint Prime2 = 2246822519; + const uint Prime3 = 3266489917; + const uint Prime4 = 668265263; + const uint Prime5 = 374761393; + + byte* p = (byte*)pBuffer; + uint hash = seed + Prime5; + if (numBytes >= 16) + { + uint4 state = new uint4(Prime1 + Prime2, Prime2, 0, (uint)-Prime1) + seed; + + int count = numBytes >> 4; + for (int i = 0; i < count; ++i) + { + var data = new uint4(read32_little_endian(p), read32_little_endian(p + 4), read32_little_endian(p + 8), read32_little_endian(p + 12)); + state += data * Prime2; + state = rol(state, 13); + state *= Prime1; + p += 16; + } + + hash = rol(state.x, 1) + rol(state.y, 7) + rol(state.z, 12) + rol(state.w, 18); + } + + hash += (uint)numBytes; + + for (int i = 0; i < ((numBytes >> 2) & 3); ++i) + { + hash += read32_little_endian(p) * Prime3; + hash = rol(hash, 17) * Prime4; + p += 4; + } + + for (int i = 0; i < ((numBytes) & 3); ++i) + { + hash += (*p++) * Prime5; + hash = rol(hash, 11) * Prime1; + } + + hash ^= hash >> 15; + hash *= Prime2; + hash ^= hash >> 13; + hash *= Prime3; + hash ^= hash >> 16; + + return hash; + } + } + + /// Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context. + /// A pointer to the beginning of the data. + /// Number of bytes to hash. + /// Starting seed value. + /// The 32 bit hash of the input data buffer. + public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0) + { +#if !UNITY_64 && UNITY_ANDROID + return hash_without_unaligned_loads(pBuffer, numBytes, seed); +#else + return hash_with_unaligned_loads(pBuffer, numBytes, seed); +#endif + } + /// /// Unity's up axis (0, 1, 0). /// @@ -6579,6 +6885,300 @@ public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 right() { return new float3(1.0f, 0.0f, 0.0f); } + /// + /// Returns the Euler angle representation of the quaternion following the XYZ rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in XYZ order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerXYZ(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + // prepare the data + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.z - d1.y; + if (y1 * y1 < cutoff) + { + var x1 = d2.y + d1.x; + var x2 = d3.z + d3.w - d3.y - d3.x; + var z1 = d2.x + d1.z; + var z2 = d3.x + d3.w - d3.y - d3.z; + euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2)); + } + else //xzx + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.z, d1.y, d2.x, d1.z); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), -asin(y1), 0f); + } + + return euler; + } + + /// + /// Returns the Euler angle representation of the quaternion following the XZY rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in XZY order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerXZY(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + // prepare the data + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.x + d1.z; + if (y1 * y1 < cutoff) + { + var x1 = -d2.y + d1.x; + var x2 = d3.y + d3.w - d3.z - d3.x; + var z1 = -d2.z + d1.y; + var z2 = d3.x + d3.w - d3.y - d3.z; + euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2)); + } + else //xyx + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.x, d1.z, d2.z, d1.y); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), asin(y1), 0f); + } + + return euler.xzy; + } + + /// + /// Returns the Euler angle representation of the quaternion following the YXZ rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in YXZ order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerYXZ(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + // prepare the data + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.y + d1.x; + if (y1 * y1 < cutoff) + { + var x1 = -d2.z + d1.y; + var x2 = d3.z + d3.w - d3.x - d3.y; + var z1 = -d2.x + d1.z; + var z2 = d3.y + d3.w - d3.z - d3.x; + euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2)); + } + else //yzy + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.x, d1.z, d2.y, d1.x); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), asin(y1), 0f); + } + + return euler.yxz; + } + + /// + /// Returns the Euler angle representation of the quaternion following the YZX rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in YZX order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerYZX(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + // prepare the data + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.x - d1.z; + if (y1 * y1 < cutoff) + { + var x1 = d2.z + d1.y; + var x2 = d3.x + d3.w - d3.z - d3.y; + var z1 = d2.y + d1.x; + var z2 = d3.y + d3.w - d3.x - d3.z; + euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2)); + } + else //yxy + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.x, d1.z, d2.y, d1.x); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), -asin(y1), 0f); + } + + return euler.zxy; + } + + /// + /// Returns the Euler angle representation of the quaternion following the ZXY rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in ZXY order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerZXY(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + // prepare the data + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.y - d1.x; + if (y1 * y1 < cutoff) + { + var x1 = d2.x + d1.z; + var x2 = d3.y + d3.w - d3.x - d3.z; + var z1 = d2.z + d1.y; + var z2 = d3.z + d3.w - d3.x - d3.y; + euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2)); + } + else //zxz + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.z, d1.y, d2.y, d1.x); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), -asin(y1), 0f); + } + + return euler.yzx; + } + + /// + /// Returns the Euler angle representation of the quaternion following the ZYX rotation order. + /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. + /// + /// The quaternion to convert to Euler angles. + /// The Euler angle representation of the quaternion in ZYX order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 EulerZYX(quaternion q) + { + const float epsilon = 1e-6f; + const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon); + + var qv = q.value; + var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww + var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww + var d3 = qv * qv; + var euler = Unity.Mathematics.float3.zero; + + var y1 = d2.z + d1.y; + if (y1 * y1 < cutoff) + { + var x1 = -d2.x + d1.z; + var x2 = d3.x + d3.w - d3.y - d3.z; + var z1 = -d2.y + d1.x; + var z2 = d3.z + d3.w - d3.y - d3.x; + euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2)); + } + else //zxz + { + y1 = clamp(y1, -1f, 1f); + var abcd = float4(d2.z, d1.y, d2.y, d1.x); + var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc) + var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f)); + euler = float3(atan2(x1, x2), asin(y1), 0f); + } + + return euler.zyx; + } + + /// + /// Returns the Euler angle representation of the quaternion. The returned angles depend on the specified order to apply the + /// three rotations around the principal axes. All rotation angles are in radians and clockwise when looking along the + /// rotation axis towards the origin. + /// When the rotation order is known at compile time, to get the best performance you should use the specific + /// Euler rotation constructors such as EulerZXY(...). + /// + /// The quaternion to convert to Euler angles. + /// The order in which the rotations are applied. + /// The Euler angle representation of the quaternion in the specified order. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3 Euler(quaternion q, math.RotationOrder order = math.RotationOrder.Default) + { + switch (order) + { + case math.RotationOrder.XYZ: + return EulerXYZ(q); + case math.RotationOrder.XZY: + return EulerXZY(q); + case math.RotationOrder.YXZ: + return EulerYXZ(q); + case math.RotationOrder.YZX: + return EulerYZX(q); + case math.RotationOrder.ZXY: + return EulerZXY(q); + case math.RotationOrder.ZYX: + return EulerZYX(q); + default: + return Unity.Mathematics.float3.zero; + } + } + + /// + /// Matrix columns multiplied by scale components + /// m.c0.x * s.x | m.c1.x * s.y | m.c2.x * s.z + /// m.c0.y * s.x | m.c1.y * s.y | m.c2.y * s.z + /// m.c0.z * s.x | m.c1.z * s.y | m.c2.z * s.z + /// + /// Matrix to scale. + /// Scaling coefficients for each column. + /// The scaled matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3x3 mulScale(float3x3 m, float3 s) => new float3x3(m.c0 * s.x, m.c1 * s.y, m.c2 * s.z); + + /// + /// Matrix rows multiplied by scale components + /// m.c0.x * s.x | m.c1.x * s.x | m.c2.x * s.x + /// m.c0.y * s.y | m.c1.y * s.y | m.c2.y * s.y + /// m.c0.z * s.z | m.c1.z * s.z | m.c2.z * s.z + /// + /// Scaling coefficients for each row. + /// Matrix to scale. + /// The scaled matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3x3 scaleMul(float3 s, float3x3 m) => new float3x3(m.c0 * s, m.c1 * s, m.c2 * s); // Internal @@ -6649,15 +7249,6 @@ internal static double4 movehl(double4 a, double4 b) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static uint4 fold_to_uint(double4 x) { return uint4(fold_to_uint(x.x), fold_to_uint(x.y), fold_to_uint(x.z), fold_to_uint(x.w)); } - [StructLayout(LayoutKind.Explicit)] - internal struct IntFloatUnion - { - [FieldOffset(0)] - public int intValue; - [FieldOffset(0)] - public float floatValue; - } - [StructLayout(LayoutKind.Explicit)] internal struct LongDoubleUnion { diff --git a/src/Unity.Mathematics/matrix.cs b/src/Unity.Mathematics/matrix.cs index fe4a679c..449c7e36 100644 --- a/src/Unity.Mathematics/matrix.cs +++ b/src/Unity.Mathematics/matrix.cs @@ -1089,5 +1089,27 @@ public static float3x3 orthonormalize(float3x3 i) return o; } + + /// + /// Computes the pseudoinverse of a matrix. + /// + /// Matrix to invert. + /// The pseudoinverse of m. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3x3 pseudoinverse(float3x3 m) + { + float scaleSq = 0.333333f * (math.lengthsq(m.c0) + math.lengthsq(m.c1) + math.lengthsq(m.c2)); + if (scaleSq < svd.k_EpsilonNormal) + return Mathematics.float3x3.zero; + + float3 scaleInv = math.rsqrt(scaleSq); + float3x3 ms = mulScale(m, scaleInv); + if (!adjInverse(ms, out float3x3 i, svd.k_EpsilonDeterminant)) + { + i = svd.svdInverse(ms); + } + + return mulScale(i, scaleInv); + } } } diff --git a/src/Unity.Mathematics/quaternion.cs b/src/Unity.Mathematics/quaternion.cs index ae7b0601..b013fd24 100644 --- a/src/Unity.Mathematics/quaternion.cs +++ b/src/Unity.Mathematics/quaternion.cs @@ -666,13 +666,7 @@ public static float3 rotate(quaternion q, float3 v) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static quaternion nlerp(quaternion q1, quaternion q2, float t) { - float dt = dot(q1, q2); - if(dt < 0.0f) - { - q2.value = -q2.value; - } - - return normalize(quaternion(lerp(q1.value, q2.value, t))); + return normalize(q1.value + t * (chgsign(q2.value, dot(q1, q2)) - q1.value)); } /// Returns the result of a spherical interpolation between two quaternions q1 and a2 using an interpolation parameter t. @@ -705,6 +699,62 @@ public static quaternion slerp(quaternion q1, quaternion q2, float t) } } + /// Returns the angle in radians between two unit quaternions. + /// The first quaternion. + /// The second quaternion. + /// The angle between two unit quaternions. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float angle(quaternion q1, quaternion q2) + { + float diff = asin(length(normalize(mul(conjugate(q1), q2)).value.xyz)); + return diff + diff; + } + + /// + /// Extracts the rotation from a matrix. + /// + /// This method supports any type of rotation matrix: if the matrix has a non uniform scale you should use this method. + /// Matrix to extract rotation from + /// Extracted rotation + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static quaternion rotation(float3x3 m) + { + float det = math.determinant(m); + if (math.abs(1f - det) < svd.k_EpsilonDeterminant) + return math.quaternion(m); + + if (math.abs(det) > svd.k_EpsilonDeterminant) + { + float3x3 tmp = mulScale(m, math.rsqrt(math.float3(math.lengthsq(m.c0), math.lengthsq(m.c1), math.lengthsq(m.c2)))); + if (math.abs(1f - math.determinant(tmp)) < svd.k_EpsilonDeterminant) + return math.quaternion(tmp); + } + + return svd.svdRotation(m); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float3x3 adj(float3x3 m, out float det) + { + float3x3 adjT; + adjT.c0 = math.cross(m.c1, m.c2); + adjT.c1 = math.cross(m.c2, m.c0); + adjT.c2 = math.cross(m.c0, m.c1); + det = math.dot(m.c0, adjT.c0); + + return math.transpose(adjT); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static bool adjInverse(float3x3 m, out float3x3 i, float epsilon = svd.k_EpsilonNormal) + { + i = adj(m, out float det); + bool c = math.abs(det) > epsilon; + float3 detInv = math.select(math.float3(1f), math.rcp(det), c); + i = scaleMul(detInv, i); + return c; + } + /// Returns a uint hash code of a quaternion. /// The quaternion to hash. /// The hash code for the input quaternion. @@ -727,7 +777,6 @@ public static uint4 hashwide(quaternion q) return hashwide(q.value); } - /// /// Transforms the forward vector by a quaternion. /// diff --git a/src/Unity.Mathematics/random.cs b/src/Unity.Mathematics/random.cs index 3c94b6e3..a6c77d5c 100644 --- a/src/Unity.Mathematics/random.cs +++ b/src/Unity.Mathematics/random.cs @@ -468,6 +468,7 @@ public float4 NextFloat4() /// The minimum value to generate, inclusive. /// The maximum value to generate, exclusive. /// A uniformly random float value in the range [min, max). + /// The result is computed as `NextFloat() * (max - min) + min`, so floating-point rounding can in rare cases return a value equal to `max` rather than strictly less than it. Clamp the result if you require a value strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public float NextFloat(float min, float max) { return NextFloat() * (max - min) + min; } @@ -475,6 +476,7 @@ public float4 NextFloat4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random float2 value in the range [min, max). + /// Each component is computed as `NextFloat() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public float2 NextFloat2(float2 min, float2 max) { return NextFloat2() * (max - min) + min; } @@ -482,6 +484,7 @@ public float4 NextFloat4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random float3 value in the range [min, max). + /// Each component is computed as `NextFloat() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public float3 NextFloat3(float3 min, float3 max) { return NextFloat3() * (max - min) + min; } @@ -489,6 +492,7 @@ public float4 NextFloat4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random float4 value in the range [min, max). + /// Each component is computed as `NextFloat() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public float4 NextFloat4(float4 min, float4 max) { return NextFloat4() * (max - min) + min; } @@ -572,6 +576,7 @@ public double4 NextDouble4() /// The minimum value to generate, inclusive. /// The maximum value to generate, exclusive. /// A uniformly random double value in the range [min, max). + /// The result is computed as `NextDouble() * (max - min) + min`, so floating-point rounding can in rare cases return a value equal to `max` rather than strictly less than it. Clamp the result if you require a value strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public double NextDouble(double min, double max) { return NextDouble() * (max - min) + min; } @@ -579,6 +584,7 @@ public double4 NextDouble4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random double2 value in the range [min, max). + /// Each component is computed as `NextDouble() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public double2 NextDouble2(double2 min, double2 max) { return NextDouble2() * (max - min) + min; } @@ -586,6 +592,7 @@ public double4 NextDouble4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random double3 value in the range [min, max). + /// Each component is computed as `NextDouble() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public double3 NextDouble3(double3 min, double3 max) { return NextDouble3() * (max - min) + min; } @@ -593,6 +600,7 @@ public double4 NextDouble4() /// The componentwise minimum value to generate, inclusive. /// The componentwise maximum value to generate, exclusive. /// A uniformly random double4 value in the range [min, max). + /// Each component is computed as `NextDouble() * (max - min) + min`, so floating-point rounding can in rare cases return a component equal to the corresponding component of `max` rather than strictly less than it. Clamp the result if you require components strictly less than `max`. [MethodImpl(MethodImplOptions.AggressiveInlining)] public double4 NextDouble4(double4 min, double4 max) { return NextDouble4() * (max - min) + min; } diff --git a/src/Unity.Mathematics/svd.cs b/src/Unity.Mathematics/svd.cs new file mode 100644 index 00000000..d57e748a --- /dev/null +++ b/src/Unity.Mathematics/svd.cs @@ -0,0 +1,170 @@ +using System.Runtime.CompilerServices; +using Unity.IL2CPP.CompilerServices; + +namespace Unity.Mathematics +{ + // SVD algorithm as described in: + // Computing the singular value decomposition of 3x3 matrices with minimal branching and elementary floating point operations, + // A.McAdams, A.Selle, R.Tamstorf, J.Teran and E.Sifakis, University of Wisconsin - Madison technical report TR1690, May 2011 + [Il2CppEagerStaticClassConstruction] + static public class svd + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static void condSwap(bool c, ref float x, ref float y) + { + var tmp = x; + x = math.select(x, y, c); + y = math.select(y, tmp, c); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static void condNegSwap(bool c, ref float3 x, ref float3 y) + { + var tmp = -x; + x = math.select(x, y, c); + y = math.select(y, tmp, c); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static quaternion condNegSwapQuat(bool c, quaternion q, float4 mask) + { + const float halfSqrt2 = 0.707106781186548f; + return math.mul(q, math.select(quaternion.identity.value, mask * halfSqrt2, c)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static void sortSingularValues(ref float3x3 b, ref quaternion v) + { + var l0 = math.lengthsq(b.c0); + var l1 = math.lengthsq(b.c1); + var l2 = math.lengthsq(b.c2); + + var c = l0 < l1; + condNegSwap(c, ref b.c0, ref b.c1); + v = condNegSwapQuat(c, v, math.float4(0f, 0f, 1f, 1f)); + condSwap(c, ref l0, ref l1); + + c = l0 < l2; + condNegSwap(c, ref b.c0, ref b.c2); + v = condNegSwapQuat(c, v, math.float4(0f, -1f, 0f, 1f)); + condSwap(c, ref l0, ref l2); + + c = l1 < l2; + condNegSwap(c, ref b.c1, ref b.c2); + v = condNegSwapQuat(c, v, math.float4(1f, 0f, 0f, 1f)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static quaternion approxGivensQuat(float3 pq, float4 mask) + { + const float c8 = 0.923879532511287f; // cos(pi/8) + const float s8 = 0.38268343236509f; // sin(pi/8) + const float g = 5.82842712474619f; // 3 + 2 * sqrt(2) + + var ch = 2f * (pq.x - pq.y); // approx cos(a/2) + var sh = pq.z; // approx sin(a/2) + var r = math.select(math.float4(s8, s8, s8, c8), math.float4(sh, sh, sh, ch), g * sh * sh < ch * ch) * mask; + return math.normalize(r); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static quaternion qrGivensQuat(float2 pq, float4 mask) + { + var l = math.sqrt(pq.x * pq.x + pq.y * pq.y); + var sh = math.select(0f, pq.y, l > k_EpsilonNormalSqrt); + var ch = math.abs(pq.x) + math.max(l, k_EpsilonNormalSqrt); + condSwap(pq.x < 0f, ref sh, ref ch); + + return math.normalize(math.float4(sh, sh, sh, ch) * mask); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static quaternion givensQRFactorization(float3x3 b, out float3x3 r) + { + var u = qrGivensQuat(math.float2(b.c0.x, b.c0.y), math.float4(0f, 0f, 1f, 1f)); + var qmt = math.float3x3(math.conjugate(u)); + r = math.mul(qmt, b); + + var q = qrGivensQuat(math.float2(r.c0.x, r.c0.z), math.float4(0f, -1f, 0f, 1f)); + u = math.mul(u, q); + qmt = math.float3x3(math.conjugate(q)); + r = math.mul(qmt, r); + + q = qrGivensQuat(math.float2(r.c1.y, r.c1.z), math.float4(1f, 0f, 0f, 1f)); + u = math.mul(u, q); + qmt = math.float3x3(math.conjugate(q)); + r = math.mul(qmt, r); + + return u; + } + + static quaternion jacobiIteration(ref float3x3 s, int iterations = 5) + { + float3x3 qm; + quaternion q; + quaternion v = quaternion.identity; + + for (int i = 0; i < iterations; ++i) + { + q = approxGivensQuat(math.float3(s.c0.x, s.c1.y, s.c0.y), math.float4(0f, 0f, 1f, 1f)); + v = math.mul(v, q); + qm = math.float3x3(q); + s = math.mul(math.mul(math.transpose(qm), s), qm); + + q = approxGivensQuat(math.float3(s.c1.y, s.c2.z, s.c1.z), math.float4(1f, 0f, 0f, 1f)); + v = math.mul(v, q); + qm = math.float3x3(q); + s = math.mul(math.mul(math.transpose(qm), s), qm); + + q = approxGivensQuat(math.float3(s.c2.z, s.c0.x, s.c2.x), math.float4(0f, 1f, 0f, 1f)); + v = math.mul(v, q); + qm = math.float3x3(q); + s = math.mul(math.mul(math.transpose(qm), s), qm); + } + + return v; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float3 singularValuesDecomposition(float3x3 a, out quaternion u, out quaternion v) + { + u = quaternion.identity; + v = quaternion.identity; + + var s = math.mul(math.transpose(a), a); + v = jacobiIteration(ref s); + var b = math.float3x3(v); + b = math.mul(a, b); + sortSingularValues(ref b, ref v); + u = givensQRFactorization(b, out var e); + + return math.float3(e.c0.x, e.c1.y, e.c2.z); + } + + public const float k_EpsilonDeterminant = 1e-6f; + public const float k_EpsilonRCP = 1e-9f; + public const float k_EpsilonNormalSqrt = 1e-15f; + public const float k_EpsilonNormal = 1e-30f; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static float3 rcpsafe(float3 x, float epsilon = k_EpsilonRCP) => + math.select(math.rcp(x), float3.zero, math.abs(x) < epsilon); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float3x3 svdInverse(float3x3 a) + { + var e = singularValuesDecomposition(a, out var u, out var v); + var um = math.float3x3(u); + var vm = math.float3x3(v); + + return math.mul(vm, math.scaleMul(rcpsafe(e, k_EpsilonDeterminant), math.transpose(um))); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static quaternion svdRotation(float3x3 a) + { + singularValuesDecomposition(a, out var u, out var v); + return math.mul(u, math.conjugate(v)); + } + } +} \ No newline at end of file diff --git a/src/Unity.Mathematics/svd.cs.meta b/src/Unity.Mathematics/svd.cs.meta new file mode 100644 index 00000000..e7924355 --- /dev/null +++ b/src/Unity.Mathematics/svd.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bc4f01dc4f3d8489f85ca8dff8563871 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/ValidationExceptions.json b/src/ValidationExceptions.json new file mode 100644 index 00000000..3406ed9e --- /dev/null +++ b/src/ValidationExceptions.json @@ -0,0 +1,10 @@ +{ + "ErrorExceptions": [ + { + "ValidationTest": "Package Unity Version Validation", + "ExceptionMessage": "The Unity version requirement is more strict than in the previous version of the package. Increment the minor version of the package to leave patch versions available for previous version. Read more about this error and potential solutions at https://docs.unity3d.com/Packages/com.unity.package-validation-suite@latest/index.html?preview=1&subfolder=/manual/package_unity_version_validation_error.html#the-unity-version-requirement-is-more-strict-than-in-the-previous-version-of-the-package", + "PackageVersion": "1.3.2" + } + ], + "WarningExceptions": [] +} \ No newline at end of file diff --git a/src/Documentation~/mathematics.md.meta b/src/ValidationExceptions.json.meta similarity index 75% rename from src/Documentation~/mathematics.md.meta rename to src/ValidationExceptions.json.meta index 10f22f41..e0483f02 100644 --- a/src/Documentation~/mathematics.md.meta +++ b/src/ValidationExceptions.json.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d177df5c52517492b85d4191425323a9 +guid: 5ed727127196a4ecc90e24e2cd7af338 TextScriptImporter: externalObjects: {} userData: diff --git a/src/package.json b/src/package.json index ac714659..9944d6fe 100755 --- a/src/package.json +++ b/src/package.json @@ -1,17 +1,12 @@ { "name": "com.unity.mathematics", "displayName": "Mathematics", - "version": "1.2.1", - "unity": "2018.3", + "version": "1.3.2", + "unity": "2021.3", "description": "Unity's C# SIMD math library providing vector types and math functions with a shader like syntax.", "keywords": [ "unity" ], "dependencies": { - }, - "repository": { - "type": "git", - "url": "https://github.com/Unity-Technologies/Unity.Mathematics", - "revision":"" } }