diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md new file mode 100644 index 0000000..06bb7b4 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog +All notable changes to this package will be documented in this file. + +## [Unreleased] + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md.meta new file mode 100644 index 0000000..1fcbc55 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b51a25b14eb15204b90d1e2803e4e665 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation.meta new file mode 100644 index 0000000..277ecb2 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 463851d0a2c6a61449351e69182542e8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md new file mode 100644 index 0000000..987a86b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md @@ -0,0 +1,63 @@ +# NVIDIA Streamline Core package + +## Supported versions of Unity + +- DX12 is supported on Unity versions 2019.4 and Unity2022.2.17f1 +- DLSS-G is non supported in DX11. +- Vulkan is not currently supported. + +## Integrating into your Unity application + +- Apply Unity2019.4src.patch to Unity2019.4 source or apply Unity2022.2.17f1src.patch to Unity2022.2.17f1 source. +- For versions later than the ones directly supported you will need to manually merge the changes into your editor source. +- Build Editor and Standalone players. For final packaging of a non-development build you will need the NONDEVELOPMENT version of the player. + jam --help WinPlayer in the Editor src folder will list all possible build commands for building players. See Documentation\BuildDocs\docs\BuildingViaJam.md for more information on building. + + +## Integrating into your Unity application + +- Import com.nvidia.streamline.core package +- Import additional streamline packages. eg com.nvidia.streamline.dlssg, com.nvidia.streamline.reflex + +- Builtin project. + Add Streamline component (Streamline.cs) to Main Camera along with Streamline DLSSG Builtin (StreamlineDLSSG.cs) and Streamline Reflex Builtin (StreamlineReflex.cs) components. + +- HDRP project. + The following also applies to the HDRP 14.0.7 patch. + Apply HDRP 7.7.1 patch to a copy of com.unity.render-pipelines.high-definition@7.7.1 (see below) + Add Streamline component (StreamlineHDRP.cs) to Main Camera. + +- Applying patch to HDRP. + 1. Copy com.unity.render-pipelines.high-definition-config@7.7.1 from \Library\PackageCache\ into \Packages + 2. Open a cmd prompt in \Packages. + 3. git apply -p4 --directory=com.unity.render-pipelines.high-definition@7.7.1 --ignore-whitespace \path\to\com.unity.render-pipelines.high-definition@7.7.1.patch + 4. Edit manifest.json and update the HDRP package entry to read "com.unity.render-pipelines.high-definition": "file:./com.unity.render-pipelines.high-definition@7.7.1", + +## Using Streamline with Unity's NVIDIA DLSS Package. + If DLSS is failing copy the nvngx_dlss.dll from the standalone executable folder into the data/plugins/x86_64 folder. If DLSS fails in the Editor, unpack com.nvidia.streamline.core to a folder and edit + Packages/manifest.json to point to the unpacked folder rather than the tgz. Copy nvngx_dlss.dll from the Editor executable folder (where Unity.exe is found) into the unpacked com.nvidia.streamline.core folder. + +## Debugging DLSS-G with development package, com.nvidia.streamline.core.dev + + NOTE. the GUI is only available with DLSS-G enabled currently. + 1. Close the editor. + 2. Edit YouProject/packages/manifest.json and change the "com.nvidia.streamline.core": field from com.nvidia.streamline.core-???.tgz to com.nvidia.streamline.core-???.dev.tgz + 3. In Unity Hub to the right of your project name open the options "..." and "add command line arguments". Add the argument --nvsl-showgui (this is to ensure the sl.imgui.dll is packaged when building your standalone build) + 4. Open your project and check in package manager that com.nvidia.streamline.core is installed from the .dev.tgz package. + 5. Build a standalone build, ensuring the "development build" option is ticked. You may need to build to a clean path so Unity's build process is forced to copy the new dev DLL files. + 5. Run the standalone build from a cmd line with the --nvsl-showgui command argument. + 6. Your app will run with the Streamline on-screen gui. Here you can check depth and motion vector buffers are being used and that constants are set correctly. + Ctrl-Shift-Insert will show the input buffers to DLSS-G. Ctrl-Shift-Help toggles different buffers. More information on ImGUI is here https://github.com/NVIDIAGameWorks/Streamline/blob/main/docs/Debugging%20-%20SL%20ImGUI%20(Realtime%20Data%20Inspection).md + + New command line options: + -nvsl-disable-all Disable all Streamline interposing. Streamline will not be available at all. + -nvsl-noswapchain Disable hooking the standalone swapchain. Streamline scripts will still see Streamline as available, there just won't be any swapchain processing. Useful for debugging. + -nvsl-showconsole Show the Streamline debug window when running editor or standalone. + -nvsl-logtostderr Log Steamline plugin errors to stdout & Unity logs. + -nvsl-showgui Show IMGUI panel onscreen (if using a development build and the development core package) + + Command line options are not available in non-development builds. + + Streamline debug jsons are not copied to the standalone plugin folder, these need to be manually copied if required and are only available for the development package. + + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md.meta new file mode 100644 index 0000000..3f80659 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Documentation/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bdbb7d35a8f7aa441a87419e207fc987 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md new file mode 100644 index 0000000..2e3dc69 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md @@ -0,0 +1,7 @@ +Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved. + +NVIDIA CORPORATION and its licensors retain all intellectual property +and proprietary rights in and to this software, related documentation +and any modifications thereto. Any use, reproduction, disclosure or +distribution of this software and related documentation without an express +license agreement from NVIDIA CORPORATION is strictly prohibited. diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md.meta new file mode 100644 index 0000000..f36cfe5 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6899f9a40e5d1114c9146ac0d8ddd203 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins.meta new file mode 100644 index 0000000..fb4edf9 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7dbb533ef9b1b8745a2bc09d80a142d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64.meta new file mode 100644 index 0000000..d94bc85 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 382460b4efeded84cbef5762a8b6424b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll new file mode 100644 index 0000000..b2930e1 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta new file mode 100644 index 0000000..549a157 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 98b2974e71a1edc4f886c6e00ab73d79 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll new file mode 100644 index 0000000..a355f61 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll.meta new file mode 100644 index 0000000..b4aaa9d --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/nvngx_dlssg.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 43b00b1a1adef4d41ac98fdb1d73ba83 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll new file mode 100644 index 0000000..b57c849 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll.meta new file mode 100644 index 0000000..884d42b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.common.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: ca6f33823c568584f9aa5cbeadd51424 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll new file mode 100644 index 0000000..55df5c0 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll.meta new file mode 100644 index 0000000..7b819ca --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.dlss_g.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 334057619639d404c9404b4728d8ce6e +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll new file mode 100644 index 0000000..b28cec0 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll.meta new file mode 100644 index 0000000..59215a1 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.imgui.dll.meta @@ -0,0 +1,52 @@ +fileFormatVersion: 2 +guid: 22ceb1f007652b742aa348858ed7603a +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: x86_64 + DefaultValueInitialized: true + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: x86_64 + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll new file mode 100644 index 0000000..d872bfa Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll.meta new file mode 100644 index 0000000..3551cc7 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.interposer.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: c111f96ddd19e8440908bc89d71d69c1 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.pcl.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.pcl.dll.meta new file mode 100644 index 0000000..d6ddc05 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.pcl.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: aa3cdfd7567ede4499cc98b29a53314c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll new file mode 100644 index 0000000..7620402 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll.meta new file mode 100644 index 0000000..9bbd099 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Plugins/x86_64/sl.reflex.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 261d07c95e83fec4e8274400661cd84c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime.meta new file mode 100644 index 0000000..ac48bfe --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c4925c5b82eb39b4188e1a64b975034e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs new file mode 100644 index 0000000..22936bf --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs @@ -0,0 +1,77 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline Builtin")] + public class Streamline : MonoBehaviour + { + private static CommandBuffer m_cmdBuffer; + public bool StreamlineFeatureAvailable { get; private set; } = false; + private Camera m_camera; + void Awake() + { + m_camera = GetComponent(); + + StreamlineFeatureAvailable = false; + if (StreamlineCore.IsStreamlineEnabled()) + { + StreamlineFeatureAvailable = true; + m_cmdBuffer = new CommandBuffer(); + m_cmdBuffer.name = "StreamlineCMDs"; + } + } + + void OnEnable() + { + if (StreamlineFeatureAvailable) + { + m_camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdBuffer); + m_cmdBuffer.Clear(); + } + } + + void OnDisable() + { + if (StreamlineFeatureAvailable) + { + m_camera.RemoveCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdBuffer); + m_cmdBuffer.Clear(); + } + } + + void OnDestroy() + { + StreamlineCore.m_nativeAllocator.RemoveAllItems(); + } + + void LateUpdate() + { + if (StreamlineFeatureAvailable) + { + StreamlineCore.m_nativeAllocator.RemoveOldItems((uint)Time.frameCount); + + if (GraphicsSettings.defaultRenderPipeline == null) //if builtin + { + m_cmdBuffer.Clear(); +#if !UNITY_EDITOR && UNITY_2019_1_OR_NEWER + // On DX12 up until 2020.2 command lists that are being generated do not get flushed. + // This causes incorrect ordering of plugin side command lists. + // i.e. After submitted lists but before currently being generated lists. + // We can force a flush in non-editor mode by creating a fence but never waiting for it. + // Editor mode does not support GPUFence. + GraphicsFence fence1 = m_cmdBuffer.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations); +#endif + bool jitter = false; + bool firstFrame = false; + StreamlineCore.SetupStreamlineConstants(m_cmdBuffer, m_camera, 0, (uint)Time.frameCount, jitter, Vector4.zero, firstFrame); + } + } + } + + }; +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs.meta new file mode 100644 index 0000000..8a95de2 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/Streamline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7c8c6bc9ae687a45abf374858854166 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineCore.cs new file mode 100644 index 0000000..dec0219 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineCore.cs @@ -0,0 +1,637 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + public class NativeMemoryAllocator + { + public class NativeMemoryItem + { + public IntPtr m_nativePtr = IntPtr.Zero; + public UInt32 m_frameIndex; + + public NativeMemoryItem(UInt32 frameIndex, int size) + { + m_nativePtr = Marshal.AllocHGlobal(size); + m_frameIndex = frameIndex; + } + + public void Free() + { + Marshal.FreeHGlobal(m_nativePtr); + m_nativePtr = IntPtr.Zero; + } + + }; + + public List m_memList = new List(); + public String m_name; + + public NativeMemoryAllocator(String name) + { + m_name = name; + } + + public IntPtr Malloc(UInt32 frameIndex, int size) + { + NativeMemoryItem newItem = new NativeMemoryItem(frameIndex, size); + + m_memList.Add(newItem); + + return newItem.m_nativePtr; + } + + // Remove items older than frameIndex + public void RemoveOldItems(UInt32 frameIndex) + { + //if item.frameTime + 4 < frameIndex, remove it + for (int i = m_memList.Count - 1; i >= 0; i--) + { + if (m_memList[i].m_frameIndex + 4 < frameIndex) + { + m_memList[i].Free(); + m_memList.RemoveAt(i); + } + } + //Debug.Log("NativeAllocator " + m_name + " has " + m_memList.Count + " items"); + } + + public void RemoveAllItems() + { + for (int i = m_memList.Count - 1; i >= 0; i--) + { + m_memList[i].Free(); + m_memList.RemoveAt(i); + } + } + + }; + + public class StreamlineCore + { + public enum PluginEvent + { + //Must match internal enum PluginEvent + + PluginEventSubmitData = 0, + PluginEventSetConstants = 1, + PluginEventSetDLSSGConstants = 2, + PluginEventSetTagData = 3, + PluginEventSetDLSSConstants = 4, + PluginEventEvaluateFeature = 5, + //insert new ones here, before reflex ones + + PluginEvent_SIMULATION_START = 10, + PluginEvent_SIMULATION_END = 11, + PluginEvent_RENDERSUBMIT_START = 12, + PluginEvent_RENDERSUBMIT_END = 13, + PluginEvent_PRESENT_START = 14, + PluginEvent_PRESENT_END = 15, + PluginEvent_INPUT_SAMPLE = 16, + PluginEvent_TRIGGER_FLASH = 17, + + PluginEventCount = 18 + }; + + public enum Feature : uint + { + //! Deep Learning Super Sampling + eFeatureDLSS = 0, + //! Real-Time Denoiser + eFeatureNRD = 1, + //! NVIDIA Image Scaling + eFeatureNIS = 2, + //! Low-Latency + eFeatureReflex = 3, + //! Streamline debug plugin + eFeatureDebug = 5, + //! DLSS Frame Generation + eFeatureDLSS_G = 1000, + + //! Common feature, NOT intended to be used directly + //eFeatureCommon = UINT_MAX + }; + + public enum BufferType : uint + { + //! Depth buffer - IMPORTANT - Must be suitable to use with clipToPrevClip transformation (see Constants below) + eBufferTypeDepth, + //! Object and optional camera motion vectors (see Constants below) + eBufferTypeMVec, + //! Color buffer with all post-processing effects applied but without any UI/HUD elements + eBufferTypeHUDLessColor, + //! Color buffer containing jittered input data for the image scaling pass + eBufferTypeScalingInputColor, + //! Color buffer containing results from the image scaling pass + eBufferTypeScalingOutputColor, + //! Normals + eBufferTypeNormals, + //! Roughness + eBufferTypeRoughness, + //! Albedo + eBufferTypeAlbedo, + //! Specular Albedo + eBufferTypeSpecularAlbedo, + //! Indirect Albedo + eBufferTypeIndirectAlbedo, + //! Specular Mvec + eBufferTypeSpecularMVec, + //! Disocclusion Mask + eBufferTypeDisocclusionMask, + //! Emissive + eBufferTypeEmissive, + //! Exposure + eBufferTypeExposure, + //! Buffer with normal and roughness in alpha channel + eBufferTypeNormalRoughness, + //! Diffuse and camera ray length + eBufferTypeDiffuseHitNoisy, + //! Diffuse denoised + eBufferTypeDiffuseHitDenoised, + //! Specular and reflected ray length + eBufferTypeSpecularHitNoisy, + //! Specular denoised + eBufferTypeSpecularHitDenoised, + //! Shadow noisy + eBufferTypeShadowNoisy, + //! Shadow denoised + eBufferTypeShadowDenoised, + //! AO noisy + eBufferTypeAmbientOcclusionNoisy, + //! AO denoised + eBufferTypeAmbientOcclusionDenoised, + + //! Optional - UI/HUD color and alpha + //! IMPORTANT: Please make sure that alpha channel has enough precision (for example do NOT use formats like R10G10B10A2) + eBufferTypeUIColorAndAlpha, + //! Optional - Shadow pixels hint (set to 1 if a pixel belongs to the shadow area, 0 otherwise) + eBufferTypeShadowHint, + //! Optional - Reflection pixels hint (set to 1 if a pixel belongs to the reflection area, 0 otherwise) + eBufferTypeReflectionHint, + //! Optional - Particle pixels hint (set to 1 if a pixel represents a particle, 0 otherwise) + eBufferTypeParticleHint, + //! Optional - Transparency pixels hint (set to 1 if a pixel belongs to the transparent area, 0 otherwise) + eBufferTypeTransparencyHint, + //! Optional - Animated texture pixels hint (set to 1 if a pixel belongs to the animated texture area, 0 otherwise) + eBufferTypeAnimatedTextureHint, + //! Optional - Bias for current color vs history hint - lerp(history, current, bias) (set to 1 to completely reject history) + eBufferTypeBiasCurrentColorHint, + //! Optional - Ray-tracing distance (camera ray length) + eBufferTypeRaytracingDistance, + //! Optional - Motion vectors for reflections + eBufferTypeReflectionMotionVectors, + //! Optional - Position, in same space as eBufferTypeNormals + eBufferTypePosition, + //! Optional - Indicates (via non-zero value) which pixels have motion/depth values that do not match the final color content at that pixel (e.g. overlaid, opaque Picture-in-Picture) + eBufferTypeInvalidDepthMotionHint, + + //! Alpha + eBufferTypeAlpha, + //! Color buffer containing only opaque geometry + eBufferTypeOpaqueColor, + //! Optional - Reduce reliance on history instead using current frame hint (0 if a pixel is not at all reactive and default composition should be used, 1 if fully reactive) + eBufferTypeReactiveMaskHint, + //! Optional - Pixel lock adjustment hint (set to 1 if pixel lock should be completely removed, 0 otherwise) + eBufferTypeTransparencyAndCompositionMaskHint + }; + + public enum SLBool : uint + { + eFalse, + eTrue, + eInvalid + }; + + public enum SLResult : uint + { + eOk, + eErrorIO, + eErrorDriverOutOfDate, + eErrorOSOutOfDate, + eErrorOSDisabledHWS, + eErrorDeviceNotCreated, + eErrorNoSupportedAdapter, + eErrorNoPlugins, + eErrorVulkanAPI, + eErrorDXGIAPI, + eErrorD3DAPI, + eErrorNRDAPI, + eErrorNVAPI, + eErrorReflexAPI, + eErrorNGXFailed, + eErrorJSONParsing, + eErrorMissingProxy, + eErrorMissingResourceState, + eErrorInvalidIntegration, + eErrorMissingInputParameter, + eErrorNotInitialized, + eErrorComputeFailed, + eErrorInitNotCalled, + eErrorExceptionHandler, + eErrorInvalidParameter, + eErrorMissingConstants, + eErrorDuplicatedConstants, + eErrorMissingOrInvalidAPI, + eErrorCommonConstantsMissing, + eErrorUnsupportedInterface, + eErrorFeatureMissing, + eErrorFeatureNotSupported, + eErrorFeatureMissingHooks, + eErrorFeatureFailedToLoad, + eErrorFeatureWrongPriority, + eErrorFeatureMissingDependency, + eErrorFeatureManagerInvalidState, + eErrorInvalidState, + }; + + [StructLayout(LayoutKind.Sequential)] + struct Constants + { + public UInt32 id; + public UInt32 frameIndex; + + //! IMPORTANT: All matrices are row major (see float4x4 definition) and + //! must NOT contain temporal AA jitter offset (if any). Any jitter offset + //! should be provided as the additional parameter Constants::jitterOffset (see below) + + //! Specifies matrix transformation from the camera view to the clip space. + public Matrix4x4 cameraViewToClip; + //! Specifies matrix transformation from the clip space to the camera view space. + public Matrix4x4 clipToCameraView; + //! Optional - Specifies matrix transformation describing lens distortion in clip space. + public Matrix4x4 clipToLensClip; + //! Specifies matrix transformation from the current clip to the previous clip space. + //! clipToPrevClip = clipToView * viewToViewPrev * viewToClipPrev + //! Sample code can be found in sl_matrix_helpers.h + public Matrix4x4 clipToPrevClip; + //! Specifies matrix transformation from the previous clip to the current clip space. + //! prevClipToClip = clipToPrevClip.inverse() + public Matrix4x4 prevClipToClip; + + //! Specifies pixel space jitter offset + public Vector2 jitterOffset; + //! Specifies scale factors used to normalize motion vectors (so the values are in [-1,1] range) + public Vector2 mvecScale; + //! Optional - Specifies camera pinhole offset if used. + public Vector2 cameraPinholeOffset; + //! Specifies camera position in world space. + public Vector3 cameraPos; + //! Specifies camera up vector in world space. + public Vector3 cameraUp; + //! Specifies camera right vector in world space. + public Vector3 cameraRight; + //! Specifies camera forward vector in world space. + public Vector3 cameraFwd; + + //! Specifies camera near view plane distance. + public float cameraNear; + //! Specifies camera far view plane distance. + public float cameraFar; + //! Specifies camera field of view in radians. + public float cameraFOV; + //! Specifies camera aspect ratio defined as view space width divided by height. + public float cameraAspectRatio; + //! Specifies which value represents an invalid (un-initialized) value in the motion vectors buffer + //! NOTE: This is only required if `cameraMotionIncluded` is set to false and SL needs to compute it. + public float motionVectorsInvalidValue; + + //! Specifies if depth values are inverted (value closer to the camera is higher) or not. + public SLBool depthInverted; + //! Specifies if camera motion is included in the MVec buffer. + public SLBool cameraMotionIncluded; + //! Specifies if motion vectors are 3D or not. + public SLBool motionVectors3D; + //! Specifies if previous frame has no connection to the current one (i.e. motion vectors are invalid) + public SLBool reset; + //! Specifies if orthographic projection is used or not. + public SLBool orthographicProjection; + //! Specifies if motion vectors are already dilated or not. + public SLBool motionVectorsDilated; + //! Specifies if motion vectors are jittered or not. + public SLBool motionVectorsJittered; + }; + + [StructLayout(LayoutKind.Sequential)] + struct TextureTagData + { + public uint frameIndex; + public uint tag; + public uint id; + public IntPtr nativeTexturePtr; + }; + + [StructLayout(LayoutKind.Sequential)] + struct EvaluateFeatureData + { + public uint frameIndex; + public uint id; + public uint feature; + }; + + + public static NativeMemoryAllocator m_nativeAllocator = new NativeMemoryAllocator("SL"); + + //0=DLSSG, 1=REFLEX + private static Dictionary m_dictFeatureIds = new Dictionary(); + + + + public static bool IsStreamlineEnabled() + { + bool enabled = Streamline_IsStreamlineEnabled() != 0; + + return enabled; + } + + public static bool IsFeatureSupported(Feature feature) + { + bool supported = Streamline_IsFeatureSupported((uint)feature) != 0; + if (!supported) + { + SLResult result = (SLResult)Plugin_GetLastError(); + Debug.LogFormat("Streamline IsFeatureSupported {0} failed {1}", feature.ToString(), result.ToString()); + } + return supported; + } + + // returns -1 if failed + public static int CreateFeature(Feature feature) + { + //If DLSS-G check we don't already have that feature as we can only have one. + if (feature == Feature.eFeatureDLSS_G) + { + if (m_dictFeatureIds.ContainsKey(0)) + { + Debug.LogError("Trying to create >1 DLSS-G feature"); + return -1; + } + else + { + m_dictFeatureIds.Add(0, Feature.eFeatureDLSS_G); + return 0; + } + } + else if (feature == Feature.eFeatureReflex) + { + if (m_dictFeatureIds.ContainsKey(1)) + { + Debug.LogError("Trying to create >1 Reflex feature"); + return -1; + } + else + { + m_dictFeatureIds.Add(1, Feature.eFeatureReflex); + return 1; + } + } + else + { + for (int i=2; i 0 && constants.frameIndex == lastFrameConstantsSet) //Only set constants once per frame + return; + lastFrameConstantsSet = constants.frameIndex; + + int size = Marshal.SizeOf(typeof(StreamlineDLSSCore.DLSSConstants)); + + IntPtr dataPtr = StreamlineCore.m_nativeAllocator.Malloc(constants.frameIndex, size); + Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld + + StreamlineCore.InsertEventCall(cmdBuffer, StreamlineCore.PluginEvent.PluginEventSetDLSSConstants, dataPtr); + } + + public static bool GetOptimalSettings(DLSSMode mode, uint outputWidth, uint outputHeight, out DLSSOptimalSettings settingsDest) + { + // allocate native data to fill + int size = Marshal.SizeOf(typeof(DLSSOptimalSettings)); + IntPtr dataPtr = Marshal.AllocHGlobal(size); + + bool success = Plugin_DLSSGetOptimalSettings((uint)mode, outputWidth, outputHeight, dataPtr) != 0; + + + if (success) + { + settingsDest = (DLSSOptimalSettings)Marshal.PtrToStructure(dataPtr, typeof(DLSSOptimalSettings)); + } + else + { + settingsDest = new DLSSOptimalSettings(); + } + + Marshal.FreeHGlobal(dataPtr); + return success; + } + + //---------------------- + // HDRP calls + + + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int Plugin_DLSSGetOptimalSettings(uint mode, uint outputWidth, uint outputHeight, IntPtr dlssSettingsDest); + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs new file mode 100644 index 0000000..2e1be20 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs @@ -0,0 +1,314 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + public class StreamlineDLSSGCore + { + public static bool DLSSGEnabled { get; set; } = true; + public const bool UseHudlessColor = true; + + public enum DLSSGMode : uint + { + eDLSSGModeOff, + eDLSSGModeOn, + eDLSSGModeCount + }; + + public enum DLSSGFlags : uint + { + eShowOnlyInterpolatedFrame = 1 << 0, + eDynamicResolutionEnabled = 1 << 1, + eRequestVRAMEstimate = 1 << 2, + eRequestRawFrameTime = 1 << 3 + }; + + [StructLayout(LayoutKind.Sequential)] + struct DLSSGConstants + { + public UInt32 id; + public UInt32 frameIndex; + + //! Specifies which mode should be used. + public UInt32 mode; + //! Must be 1 + public UInt32 numFramesToGenerate; + //! Optional - Flags used to enable or disable certain functionality + public UInt32 flags; + //! Optional - Dynamic resolution optimal width (used only if eDynamicResolutionEnabled is set) + public UInt32 dynamicResWidth; + //! Optional - Dynamic resolution optimal height (used only if eDynamicResolutionEnabled is set) + public UInt32 dynamicResHeight; + //! Optional - Expected number of buffers in the swap-chain + public UInt32 numBackBuffers; + //! Optional - Expected width of the input render targets (depth, motion-vector buffers etc) + public UInt32 mvecDepthWidth; + //! Optional - Expected height of the input render targets (depth, motion-vector buffers etc) + public UInt32 mvecDepthHeight; + //! Optional - Expected width of the back buffers in the swap-chain + public UInt32 colorWidth; + //! Optional - Expected height of the back buffers in the swap-chain + public UInt32 colorHeight; + //! Optional - Indicates native format used for the swap-chain back buffers + public UInt32 colorBufferFormat; + //! Optional - Indicates native format used for eMotionVectors + public UInt32 mvecBufferFormat; + //! Optional - Indicates native format used for eDepth + public UInt32 depthBufferFormat; + //! Optional - Indicates native format used for eHUDLessColor + public UInt32 hudLessBufferFormat; + //! Optional - Indicates native format used for eUIColorAndAlpha + public UInt32 uiBufferFormat; + }; + + public class TaggedTextureDimensions + { + public Rect m_currentViewRect = new Rect(0.0f, 0.0f, 0.0f, 0.0f); //view rect within swapchain + public Rect m_currentDrawRect = new Rect(0.0f, 0.0f, 0.0f, 0.0f); //draw rect within view rect + public Vector4 m_srcScaleBias = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + public Vector4 m_dstScaleBias = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + public float m_desktopScale = 1.0f; //I think this is only needed for editor mode + }; + + private static TaggedTextureDimensions m_taggedDimensions = new TaggedTextureDimensions(); + + private static int m_taggedBufferCount = 2; //>2 might be too much + private static RenderTexture[] m_depthTexTagged = new RenderTexture[m_taggedBufferCount]; + private static RenderTexture[] m_mvecsTexTagged = new RenderTexture[m_taggedBufferCount]; + private static RenderTexture[] m_hudlessColorTexTagged = new RenderTexture[m_taggedBufferCount]; + + public static ref TaggedTextureDimensions GetTaggedTextureDimensionsRef() + { + return ref m_taggedDimensions; + } + + public static RenderTexture GetTargetDepthTexture() + { + return m_depthTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + public static RenderTexture GetTargetMVecsTexture() + { + return m_mvecsTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + public static RenderTexture GetTargetHudlessColorTexture() + { + return m_hudlessColorTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + private static uint lastFrameConstantsSet = 0; + + public class RenderTextureDisposal + { + public RenderTexture m_tex; + public int m_time; + public RenderTextureDisposal(RenderTexture tex) + { + m_time = Time.frameCount + 2; //keep textures around for n frames incase SL is still using them. TODO, find out is SL is still using a texture. + m_tex = tex; + } + }; + + public static List m_disposalList = new List(); + + + public static bool UpdateDrawRects(Camera camera) + { + // Check if draw rect has changed and set flag for texture resize + bool changed = false; + + Display currentDisplay = Display.displays[camera.targetDisplay]; + + int sw = currentDisplay.systemWidth; + int sh = currentDisplay.systemHeight; + + Rect drawRect = new Rect(0, sh, sw, -sh); // Y pos&height for YFlip + Rect viewInParentRect = new Rect(0, 0, sw, sh); + + if (viewInParentRect != m_taggedDimensions.m_currentViewRect) + { + m_taggedDimensions.m_currentViewRect = viewInParentRect; + } + + if (drawRect != m_taggedDimensions.m_currentDrawRect) + { + changed = true; + + m_taggedDimensions.m_currentDrawRect = drawRect; + } + + if (changed) //and HDRP + { + HDRPCalculateScaleBias(drawRect,viewInParentRect); + } + return changed; + } + + public static void AddTextureForDisposal(RenderTexture tex) + { + RenderTextureDisposal item = new RenderTextureDisposal(tex); + m_disposalList.Add(item); + } + + //call before get or allocate textures + public static void ProcessDisposals() + { + foreach (RenderTextureDisposal item in m_disposalList) + { + if (item.m_time < Time.frameCount) + { + item.m_tex.Release(); + m_disposalList.Remove(item); + } + } + } + + public static void AllocateTextures(Rect drawRect, Rect viewInParentRect, bool inEditor, float desktopScale, bool useHudlessColor) + { + //TODO, these sizes don't always match the swap-chain color texture size in the Editor. ~1pixel error. ViewInParentRect dimensions are often not exact pixel sizes. + int width = (int)Mathf.Ceil((viewInParentRect.width + viewInParentRect.x) * desktopScale); + int height = (int)Mathf.Ceil((viewInParentRect.height + viewInParentRect.y) * desktopScale); + + for (int i = 0; i < m_taggedBufferCount; i++) + { + if (m_depthTexTagged[i]) + { + AddTextureForDisposal(m_depthTexTagged[i]); + m_depthTexTagged[i] = null; + } + if (m_mvecsTexTagged[i]) + { + AddTextureForDisposal(m_mvecsTexTagged[i]); + m_mvecsTexTagged[i] = null; + } + if (useHudlessColor) + { + if (m_hudlessColorTexTagged[i]) + { + AddTextureForDisposal(m_hudlessColorTexTagged[i]); + m_hudlessColorTexTagged[i] = null; + } + } + } + + for (int i = 0; i < m_taggedBufferCount; i++) + { + if (m_depthTexTagged[i] == null) + { + RenderTextureDescriptor descDepth = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.RFloat, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray }; + m_depthTexTagged[i] = new RenderTexture(descDepth); + m_depthTexTagged[i].name = "r_DLSSGDepthCopy"; + } + + if (m_mvecsTexTagged[i] == null) + { + RenderTextureDescriptor descMVecs = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.RGHalf, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray }; + m_mvecsTexTagged[i] = new RenderTexture(descMVecs); + m_mvecsTexTagged[i].name = "r_DLSSGMotionVectors"; + } + + if (useHudlessColor) + { + if (m_hudlessColorTexTagged[i] == null) + { + RenderTextureDescriptor descMVecs = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.ARGB32, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray, sRGB=true }; + m_hudlessColorTexTagged[i] = new RenderTexture(descMVecs); + m_hudlessColorTexTagged[i].name = "r_DLSSGHudlessColor"; + } + } + } + } + + public static void SetupDLSSGFeatureConstants(CommandBuffer cmdBuffer, Camera camera, uint id, uint frameIndex) + { + if (frameIndex > 0 && frameIndex == lastFrameConstantsSet) //Only set constants once per frame + return; + lastFrameConstantsSet = frameIndex; + + StreamlineDLSSGCore.DLSSGConstants constants = new StreamlineDLSSGCore.DLSSGConstants(); + + constants.id = id; + constants.frameIndex = frameIndex; + constants.mode = (uint) (DLSSGEnabled ? StreamlineDLSSGCore.DLSSGMode.eDLSSGModeOn : StreamlineDLSSGCore.DLSSGMode.eDLSSGModeOff); + constants.numFramesToGenerate = 1; + constants.flags = 0; + + int size = Marshal.SizeOf(typeof(StreamlineDLSSGCore.DLSSGConstants)); + + IntPtr dataPtr = StreamlineCore.m_nativeAllocator.Malloc(frameIndex, size); + Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld + + StreamlineCore.InsertEventCall(cmdBuffer, StreamlineCore.PluginEvent.PluginEventSetDLSSGConstants, dataPtr); + } + + + //---------------------- + // HDRP calls + + public static void HDRPRequestScaleBiasValues(out Vector4 srcScaleBias, out Vector4 dstScaleBias) + { + srcScaleBias = m_taggedDimensions.m_srcScaleBias; + dstScaleBias = m_taggedDimensions.m_dstScaleBias; + } + + public static void HDRPSetupDLSSGFeatureConstants(CommandBuffer cmdBuffer, Camera camera) + { + Debug.LogError("m_id doesnt exist in HDRPSetupDLSSGFeatureConstants"); + //SetupDLSSGFeatureConstants(cmdBuffer, camera, m_id, (uint)Time.frameCount); + } + + public static void HDRPCalculateScaleBias(Rect drawRect, Rect viewInParentRect) + { + // note. The following calculations would be required for enabling DLSSG in editor mode, if implemented. + float scaleX = 1.0f; + float scaleY = 1.0f; + float biasX = 0.0f; + float biasY = 0.0f; + + if (drawRect.x < 0 || drawRect.y > viewInParentRect.height) + { + // draw rect is larger than view rect (Editor mode, if ever implemented) + biasX = -drawRect.x / drawRect.width; + scaleX = drawRect.width / viewInParentRect.width; + biasY = drawRect.y / -drawRect.height; + scaleY = drawRect.height / viewInParentRect.height; + + m_taggedDimensions.m_srcScaleBias = new Vector4(1.0f / scaleX, 1.0f / scaleY, biasX, biasY); + + // viewInParentRect has n pixels at top of swapchain for gui + float swapChainHeight = viewInParentRect.height + viewInParentRect.y; + float destYScale = viewInParentRect.height / swapChainHeight; + float destYBias = viewInParentRect.y / swapChainHeight; + + m_taggedDimensions.m_dstScaleBias = new Vector4(1.0f, destYScale, 0.0f, destYBias); + } + else + { + //draw rect is within the view rect + float swapChainHeight = viewInParentRect.height + viewInParentRect.y; + scaleX = drawRect.width / viewInParentRect.width; + scaleY = drawRect.height / swapChainHeight; + biasX = drawRect.x / viewInParentRect.width; + biasY = (drawRect.y + viewInParentRect.y) / swapChainHeight; + + m_taggedDimensions.m_srcScaleBias = new Vector4(1.0f, 1.0f, 0.0f, 0.0f); + m_taggedDimensions.m_dstScaleBias = new Vector4(scaleX, scaleY, biasX, biasY); + } + + //Debug.Log("drectx=" + drawRect.x + " y=" + drawRect.y + " w=" + drawRect.width + " h=" + drawRect.height); + //Debug.Log("vrectx=" + viewRect.x + " y=" + viewRect.y + " w=" + viewRect.width + " h=" + viewRect.height); + //Debug.Log("scaleBias = scaleX= " + scaleX + " scaleY= " + scaleY + " biasX= " + biasX + " biasY= " + biasY); + } + + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs.meta new file mode 100644 index 0000000..f48a308 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineDLSSGCore.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2400248ea5cb82247b40565a582af890 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs new file mode 100644 index 0000000..c5dfffc --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline HDRP")] + public class StreamlineHDRP : MonoBehaviour + { + public bool StreamlineFeatureAvailable { get; private set; } = false; + + public void HDRPSetStreamlineConstants(CommandBuffer cmdBuffer, Camera camera, bool requiresJitter, Vector4 jitter, bool isFirstFrame, int frameCount) + { + StreamlineCore.SetupStreamlineConstants(cmdBuffer, camera, 0, (uint)frameCount, requiresJitter, jitter, isFirstFrame); + } + + void Awake() + { + StreamlineFeatureAvailable = false; + if (StreamlineCore.IsStreamlineEnabled()) + { + StreamlineFeatureAvailable = true; + } + } + + void OnEnable() + { + } + + void OnDisable() + { + } + + void OnDestroy() + { + StreamlineCore.m_nativeAllocator.RemoveAllItems(); + } + + void LateUpdate() + { + if (StreamlineFeatureAvailable) + { + StreamlineCore.m_nativeAllocator.RemoveOldItems((uint)Time.frameCount); + } + } + + }; +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs.meta new file mode 100644 index 0000000..6a2ba54 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineHDRP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 182def67fadf4fd4aba7f2934fe07b8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs new file mode 100644 index 0000000..c945d6b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ +using System; +using System.Collections; +using System.Runtime.InteropServices; +using UnityEngine; +using UnityEngine.Rendering; +using NVStreamline; + +namespace NVStreamline +{ + public class StreamlineReflexCore : MonoBehaviour + { + public enum NvReflex_LATENCY_MARKER_TYPE : int + { + SIMULATION_START, + SIMULATION_END, + RENDERSUBMIT_START, + RENDERSUBMIT_END, + PRESENT_START, + PRESENT_END, + INPUT_SAMPLE, + TRIGGER_FLASH, + PC_LATENCY_PING + } + + public enum NvReflex_Status : int + { + NvReflex_OK = 0, + NvReflex_ERROR = -1, + NvReflex_LIBRARY_NOT_FOUND = -2, + NvReflex_NO_IMPLEMENTATION = -3, + NvReflex_API_NOT_INITIALIZED = -4, + NvReflex_INVALID_ARGUMENT = -5, + NvReflex_NVIDIA_DEVICE_NOT_FOUND = -6, + NvReflex_END_ENUMERATION = -7, + NvReflex_INVALID_HANDLE = -8, + NvReflex_INCOMPATIBLE_STRUCT_VERSION = -9, + NvReflex_HANDLE_INVALIDATED = -10, + NvReflex_OPENGL_CONTEXT_NOT_CURRENT = -11, + NvReflex_INVALID_POINTER = -14, + NvReflex_NO_GL_EXPERT = -12, + NvReflex_INSTRUMENTATION_DISABLED = -13, + NvReflex_NO_GL_NSIGHT = -15, + NvReflex_EXPECTED_LOGICAL_GPU_HANDLE = -100, + NvReflex_EXPECTED_PHYSICAL_GPU_HANDLE = -101, + NvReflex_EXPECTED_DISPLAY_HANDLE = -102, + NvReflex_INVALID_COMBINATION = -103, + NvReflex_NOT_SUPPORTED = -104, + NvReflex_PORTID_NOT_FOUND = -105, + NvReflex_EXPECTED_UNATTACHED_DISPLAY_HANDLE = -106, + NvReflex_INVALID_PERF_LEVEL = -107, + NvReflex_DEVICE_BUSY = -108, + NvReflex_NV_PERSIST_FILE_NOT_FOUND = -109, + NvReflex_PERSIST_DATA_NOT_FOUND = -110, + NvReflex_EXPECTED_TV_DISPLAY = -111, + NvReflex_EXPECTED_TV_DISPLAY_ON_DCONNECTOR = -112, + NvReflex_NO_ACTIVE_SLI_TOPOLOGY = -113, + NvReflex_SLI_RENDERING_MODE_NOTALLOWED = -114, + NvReflex_EXPECTED_DIGITAL_FLAT_PANEL = -115, + NvReflex_ARGUMENT_EXCEED_MAX_SIZE = -116, + NvReflex_DEVICE_SWITCHING_NOT_ALLOWED = -117, + NvReflex_TESTING_CLOCKS_NOT_SUPPORTED = -118, + NvReflex_UNKNOWN_UNDERSCAN_CONFIG = -119, + NvReflex_TIMEOUT_RECONFIGURING_GPU_TOPO = -120, + NvReflex_DATA_NOT_FOUND = -121, + NvReflex_EXPECTED_ANALOG_DISPLAY = -122, + NvReflex_NO_VIDLINK = -123, + NvReflex_REQUIRES_REBOOT = -124, + NvReflex_INVALID_HYBRID_MODE = -125, + NvReflex_MIXED_TARGET_TYPES = -126, + NvReflex_SYSWOW64_NOT_SUPPORTED = -127, + NvReflex_IMPLICIT_SET_GPU_TOPOLOGY_CHANGE_NOT_ALLOWED = -128, + NvReflex_REQUEST_USER_TO_CLOSE_NON_MIGRATABLE_APPS = -129, + NvReflex_OUT_OF_MEMORY = -130, + NvReflex_WAS_STILL_DRAWING = -131, + NvReflex_FILE_NOT_FOUND = -132, + NvReflex_TOO_MANY_UNIQUE_STATE_OBJECTS = -133, + NvReflex_INVALID_CALL = -134, + NvReflex_D3D10_1_LIBRARY_NOT_FOUND = -135, + NvReflex_FUNCTION_NOT_FOUND = -136, + NvReflex_INVALID_USER_PRIVILEGE = -137, + NvReflex_EXPECTED_NON_PRIMARY_DISPLAY_HANDLE = -138, + NvReflex_EXPECTED_COMPUTE_GPU_HANDLE = -139, + NvReflex_STEREO_NOT_INITIALIZED = -140, + NvReflex_STEREO_REGISTRY_ACCESS_FAILED = -141, + NvReflex_STEREO_REGISTRY_PROFILE_TYPE_NOT_SUPPORTED = -142, + NvReflex_STEREO_REGISTRY_VALUE_NOT_SUPPORTED = -143, + NvReflex_STEREO_NOT_ENABLED = -144, + NvReflex_STEREO_NOT_TURNED_ON = -145, + NvReflex_STEREO_INVALID_DEVICE_INTERFACE = -146, + NvReflex_STEREO_PARAMETER_OUT_OF_RANGE = -147, + NvReflex_STEREO_FRUSTUM_ADJUST_MODE_NOT_SUPPORTED = -148, + NvReflex_TOPO_NOT_POSSIBLE = -149, + NvReflex_MODE_CHANGE_FAILED = -150, + NvReflex_D3D11_LIBRARY_NOT_FOUND = -151, + NvReflex_INVALID_ADDRESS = -152, + NvReflex_STRING_TOO_SMALL = -153, + NvReflex_MATCHING_DEVICE_NOT_FOUND = -154, + NvReflex_DRIVER_RUNNING = -155, + NvReflex_DRIVER_NOTRUNNING = -156, + NvReflex_ERROR_DRIVER_RELOAD_REQUIRED = -157, + NvReflex_SET_NOT_ALLOWED = -158, + NvReflex_ADVANCED_DISPLAY_TOPOLOGY_REQUIRED = -159, + NvReflex_SETTING_NOT_FOUND = -160, + NvReflex_SETTING_SIZE_TOO_LARGE = -161, + NvReflex_TOO_MANY_SETTINGS_IN_PROFILE = -162, + NvReflex_PROFILE_NOT_FOUND = -163, + NvReflex_PROFILE_NAME_IN_USE = -164, + NvReflex_PROFILE_NAME_EMPTY = -165, + NvReflex_EXECUTABLE_NOT_FOUND = -166, + NvReflex_EXECUTABLE_ALREADY_IN_USE = -167, + NvReflex_DATATYPE_MISMATCH = -168, + NvReflex_PROFILE_REMOVED = -169, + NvReflex_UNREGISTERED_RESOURCE = -170, + NvReflex_ID_OUT_OF_RANGE = -171, + NvReflex_DISPLAYCONFIG_VALIDATION_FAILED = -172, + NvReflex_DPMST_CHANGED = -173, + NvReflex_INSUFFICIENT_BUFFER = -174, + NvReflex_ACCESS_DENIED = -175, + NvReflex_MOSAIC_NOT_ACTIVE = -176, + NvReflex_SHARE_RESOURCE_RELOCATED = -177, + NvReflex_REQUEST_USER_TO_DISABLE_DWM = -178, + NvReflex_D3D_DEVICE_LOST = -179, + NvReflex_INVALID_CONFIGURATION = -180, + NvReflex_STEREO_HANDSHAKE_NOT_DONE = -181, + NvReflex_EXECUTABLE_PATH_IS_AMBIGUOUS = -182, + NvReflex_DEFAULT_STEREO_PROFILE_IS_NOT_DEFINED = -183, + NvReflex_DEFAULT_STEREO_PROFILE_DOES_NOT_EXIST = -184, + NvReflex_CLUSTER_ALREADY_EXISTS = -185, + NvReflex_DPMST_DISPLAY_ID_EXPECTED = -186, + NvReflex_INVALID_DISPLAY_ID = -187, + NvReflex_STREAM_IS_OUT_OF_SYNC = -188, + NvReflex_INCOMPATIBLE_AUDIO_DRIVER = -189, + NvReflex_VALUE_ALREADY_SET = -190, + NvReflex_TIMEOUT = -191, + NvReflex_GPU_WORKSTATION_FEATURE_INCOMPLETE = -192, + NvReflex_STEREO_INIT_ACTIVATION_NOT_DONE = -193, + NvReflex_SYNC_NOT_ACTIVE = -194, + NvReflex_SYNC_MASTER_NOT_FOUND = -195, + NvReflex_INVALID_SYNC_TOPOLOGY = -196, + NvReflex_ECID_SIGN_ALGO_UNSUPPORTED = -197, + NvReflex_ECID_KEY_VERIFICATION_FAILED = -198, + NvReflex_FIRMWARE_OUT_OF_DATE = -199, + NvReflex_FIRMWARE_REVISION_NOT_SUPPORTED = -200, + NvReflex_LICENSE_CALLER_AUTHENTICATION_FAILED = -201, + NvReflex_D3D_DEVICE_NOT_REGISTERED = -202, + NvReflex_RESOURCE_NOT_ACQUIRED = -203, + NvReflex_TIMING_NOT_SUPPORTED = -204, + NvReflex_HDCP_ENCRYPTION_FAILED = -205, + NvReflex_PCLK_LIMITATION_FAILED = -206, + NvReflex_NO_CONNECTOR_FOUND = -207, + NvReflex_HDCP_DISABLED = -208, + NvReflex_API_IN_USE = -209, + NvReflex_NVIDIA_DISPLAY_NOT_FOUND = -210, + NvReflex_PRIV_SEC_VIOLATION = -211, + NvReflex_INCORRECT_VENDOR = -212, + NvReflex_DISPLAY_IN_USE = -213, + NvReflex_UNSUPPORTED_CONFIG_NON_HDCP_HMD = -214, + NvReflex_MAX_DISPLAY_LIMIT_REACHED = -215, + NvReflex_INVALID_DIRECT_MODE_DISPLAY = -216, + NvReflex_GPU_IN_DEBUG_MODE = -217, + NvReflex_D3D_CONTEXT_NOT_FOUND = -218, + NvReflex_STEREO_VERSION_MISMATCH = -219, + NvReflex_GPU_NOT_POWERED = -220, + NvReflex_ERROR_DRIVER_RELOAD_IN_PROGRESS = -221, + NvReflex_WAIT_FOR_HW_RESOURCE = -222, + NvReflex_REQUIRE_FURTHER_HDCP_ACTION = -223, + NvReflex_DISPLAY_MUX_TRANSITION_FAILED = -224, + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_FrameReport + { + public ulong frameID; + public ulong inputSampleTime; + public ulong simStartTime; + public ulong simEndTime; + public ulong renderSubmitStartTime; + public ulong renderSubmitEndTime; + public ulong presentStartTime; + public ulong presentEndTime; + public ulong driverStartTime; + public ulong driverEndTime; + public ulong osRenderQueueStartTime; + public ulong osRenderQueueEndTime; + public ulong gpuRenderStartTime; + public ulong gpuRenderEndTime; + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_LATENCY_RESULT_PARAMS + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public NvReflex_FrameReport[] frameReport; + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_GET_SLEEP_STATUS_PARAMS + { + public byte bLowLatencyMode; + } + + public static void TriggerFlash() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + int flashEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.TRIGGER_FLASH); + SetLatencyMarker(flashEventID, (ulong)Time.frameCount); + } + } + + public static void PCLatencyPing() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + int pingEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.PC_LATENCY_PING); + SetLatencyMarker(pingEventID, (ulong)Time.frameCount); + } + } + + //Expects marker from NvReflex_Plugin_GetEventIDForEvent() + public static void SetLatencyMarker(int marker, ulong frameID) + { + NvReflex_Plugin_SetLatencyMarker(marker, frameID); + } + + public static NvReflex_Status IsReflexLowLatencySupported() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + bool success = false; + NvReflex_GET_SLEEP_STATUS_PARAMS sleepParams; + uint driverVersion = 0; + + bool res = NvReflex_Plugin_GetDriverVersion(out driverVersion) != 0; + + if ((res) || (driverVersion < 45500)) + { + return NvReflex_Status.NvReflex_ERROR; + } + + success = NvReflex_Plugin_GetSleepStatus(out sleepParams) != 0; + return success ? NvReflex_Status.NvReflex_OK : NvReflex_Status.NvReflex_ERROR; + } + return NvReflex_Status.NvReflex_API_NOT_INITIALIZED; + } + + public static NvReflex_Status IsAutomaticReflexAnalyzerSupported() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + uint driverVersion = 0; + + bool status = NvReflex_Plugin_GetDriverVersion(out driverVersion) != 0; + + return ((status) && (driverVersion >= 51179)) ? NvReflex_Status.NvReflex_OK : NvReflex_Status.NvReflex_ERROR; + } + return NvReflex_Status.NvReflex_API_NOT_INITIALIZED; + } + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_SetSleepMode(bool lowLatencyMode, uint minimumIntervalUs, bool lowLatencyBoost, bool markersOptimzation); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_Sleep(ulong frameID); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_SetLatencyMarker(int marker, ulong frameID); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetLatency(out NvReflex_LATENCY_RESULT_PARAMS markers); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetSleepStatus(out NvReflex_GET_SLEEP_STATUS_PARAMS sleepStatusParams); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetEventIDForEvent(int inEvent); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern IntPtr NvReflex_Plugin_GetRenderEventAndDataFunc(); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_HasReceivedRenderEvent(); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetDriverVersion(out uint ver); + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs.meta new file mode 100644 index 0000000..a8a4980 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineReflexCore.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1117f316f75cb3b45b0f6717da4ab36c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs new file mode 100644 index 0000000..46344ab --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs @@ -0,0 +1,81 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline Tester")] + public class StreamlineTester : MonoBehaviour + { + bool dlssg_enabled = false; + bool reflex_enabled = false; + + //uint mvecoffset = 0; + + Vector2[] mvectable = { + new Vector2(1.0f,1.0f), + new Vector2(-1.0f,1.0f), + new Vector2(1.0f,-1.0f), + new Vector2(-1.0f,-1.0f), + + new Vector2(3840.0f,2160.0f), + new Vector2(-3840.0f,2160.0f), + new Vector2(3840.0f,-2160.0f), + new Vector2(-3840.0f,-2160.0f), + + new Vector2(1.0f/3840.0f,1.0f/2160.0f), + new Vector2(-1.0f/3840.0f,1.0f/2160.0f), + new Vector2(1.0f/3840.0f,-1.0f/2160.0f), + new Vector2(-1.0f/3840.0f,-1.0f/2160.0f), + }; + + + // Start is called before the first frame update + void Start() + { + dlssg_enabled = StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureDLSS_G); + reflex_enabled = StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureReflex); + } + + // Update is called once per frame + void Update() + { + HandleInput(); + } + + private void HandleInput() + { + if (Input.GetKeyDown(KeyCode.Alpha1)) + { + StreamlineDLSSGCore.DLSSGEnabled = !StreamlineDLSSGCore.DLSSGEnabled; + } + + } + + private void OnGUI() + { + GUILayout.BeginArea(new Rect { x = 10, y = 80, width = 400, height = 320 }, "Streamline Controls", GUI.skin.window); + + GUILayout.Label(string.Format("DLSS-G is {0}", dlssg_enabled ? "supported" : "not supported")); + GUILayout.Label(string.Format("Reflex is {0}", reflex_enabled ? "supported" : "not supported")); + + if (GraphicsSettings.defaultRenderPipeline!=null) + { + GUILayout.Label(string.Format("Current renderpipeline = {0}", GraphicsSettings.defaultRenderPipeline.name)); + } + else + { + GUILayout.Label(string.Format("BuiltIn Pipeline")); + } + + GUILayout.Label(string.Format("[1] DLSSGEnabled is {0}", StreamlineDLSSGCore.DLSSGEnabled ? "True" : "False")); + GUILayout.Label(string.Format("frame is {0}", (uint)Time.frameCount)); + GUILayout.EndArea(); + } + } +} + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs.meta new file mode 100644 index 0000000..479e886 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/StreamlineTester.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13bdb2384d9734f44a26c0c0e2d56f02 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef new file mode 100644 index 0000000..89547d6 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef @@ -0,0 +1,13 @@ +{ + "name": "com.nvidia.streamline.core.Runtime", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta new file mode 100644 index 0000000..f0b26e6 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2ad66e0615e74ce41bad44512e0dc450 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json new file mode 100644 index 0000000..164f700 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json @@ -0,0 +1,16 @@ +{ + "name": "com.nvidia.streamline.core", + "description": "NVIDIA Streamline Core implementation package", + "version": "0.0.1-alpha1", + "unity": "2019.4", + "unityRelease": "1f1", + "displayName": "NVIDIA Streamline Core", + "dependencies": {}, + "keywords": [ + "graphics", + "performance", + "rendering", + "render", + "pipeline" + ] +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json.meta new file mode 100644 index 0000000..7630c7e --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1.dev/package/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 08c2d83d275eb5349802afcd291ec67d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md new file mode 100644 index 0000000..06bb7b4 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog +All notable changes to this package will be documented in this file. + +## [Unreleased] + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md.meta new file mode 100644 index 0000000..1fcbc55 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b51a25b14eb15204b90d1e2803e4e665 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation.meta new file mode 100644 index 0000000..277ecb2 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 463851d0a2c6a61449351e69182542e8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md new file mode 100644 index 0000000..987a86b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md @@ -0,0 +1,63 @@ +# NVIDIA Streamline Core package + +## Supported versions of Unity + +- DX12 is supported on Unity versions 2019.4 and Unity2022.2.17f1 +- DLSS-G is non supported in DX11. +- Vulkan is not currently supported. + +## Integrating into your Unity application + +- Apply Unity2019.4src.patch to Unity2019.4 source or apply Unity2022.2.17f1src.patch to Unity2022.2.17f1 source. +- For versions later than the ones directly supported you will need to manually merge the changes into your editor source. +- Build Editor and Standalone players. For final packaging of a non-development build you will need the NONDEVELOPMENT version of the player. + jam --help WinPlayer in the Editor src folder will list all possible build commands for building players. See Documentation\BuildDocs\docs\BuildingViaJam.md for more information on building. + + +## Integrating into your Unity application + +- Import com.nvidia.streamline.core package +- Import additional streamline packages. eg com.nvidia.streamline.dlssg, com.nvidia.streamline.reflex + +- Builtin project. + Add Streamline component (Streamline.cs) to Main Camera along with Streamline DLSSG Builtin (StreamlineDLSSG.cs) and Streamline Reflex Builtin (StreamlineReflex.cs) components. + +- HDRP project. + The following also applies to the HDRP 14.0.7 patch. + Apply HDRP 7.7.1 patch to a copy of com.unity.render-pipelines.high-definition@7.7.1 (see below) + Add Streamline component (StreamlineHDRP.cs) to Main Camera. + +- Applying patch to HDRP. + 1. Copy com.unity.render-pipelines.high-definition-config@7.7.1 from \Library\PackageCache\ into \Packages + 2. Open a cmd prompt in \Packages. + 3. git apply -p4 --directory=com.unity.render-pipelines.high-definition@7.7.1 --ignore-whitespace \path\to\com.unity.render-pipelines.high-definition@7.7.1.patch + 4. Edit manifest.json and update the HDRP package entry to read "com.unity.render-pipelines.high-definition": "file:./com.unity.render-pipelines.high-definition@7.7.1", + +## Using Streamline with Unity's NVIDIA DLSS Package. + If DLSS is failing copy the nvngx_dlss.dll from the standalone executable folder into the data/plugins/x86_64 folder. If DLSS fails in the Editor, unpack com.nvidia.streamline.core to a folder and edit + Packages/manifest.json to point to the unpacked folder rather than the tgz. Copy nvngx_dlss.dll from the Editor executable folder (where Unity.exe is found) into the unpacked com.nvidia.streamline.core folder. + +## Debugging DLSS-G with development package, com.nvidia.streamline.core.dev + + NOTE. the GUI is only available with DLSS-G enabled currently. + 1. Close the editor. + 2. Edit YouProject/packages/manifest.json and change the "com.nvidia.streamline.core": field from com.nvidia.streamline.core-???.tgz to com.nvidia.streamline.core-???.dev.tgz + 3. In Unity Hub to the right of your project name open the options "..." and "add command line arguments". Add the argument --nvsl-showgui (this is to ensure the sl.imgui.dll is packaged when building your standalone build) + 4. Open your project and check in package manager that com.nvidia.streamline.core is installed from the .dev.tgz package. + 5. Build a standalone build, ensuring the "development build" option is ticked. You may need to build to a clean path so Unity's build process is forced to copy the new dev DLL files. + 5. Run the standalone build from a cmd line with the --nvsl-showgui command argument. + 6. Your app will run with the Streamline on-screen gui. Here you can check depth and motion vector buffers are being used and that constants are set correctly. + Ctrl-Shift-Insert will show the input buffers to DLSS-G. Ctrl-Shift-Help toggles different buffers. More information on ImGUI is here https://github.com/NVIDIAGameWorks/Streamline/blob/main/docs/Debugging%20-%20SL%20ImGUI%20(Realtime%20Data%20Inspection).md + + New command line options: + -nvsl-disable-all Disable all Streamline interposing. Streamline will not be available at all. + -nvsl-noswapchain Disable hooking the standalone swapchain. Streamline scripts will still see Streamline as available, there just won't be any swapchain processing. Useful for debugging. + -nvsl-showconsole Show the Streamline debug window when running editor or standalone. + -nvsl-logtostderr Log Steamline plugin errors to stdout & Unity logs. + -nvsl-showgui Show IMGUI panel onscreen (if using a development build and the development core package) + + Command line options are not available in non-development builds. + + Streamline debug jsons are not copied to the standalone plugin folder, these need to be manually copied if required and are only available for the development package. + + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md.meta new file mode 100644 index 0000000..3f80659 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Documentation/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bdbb7d35a8f7aa441a87419e207fc987 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md new file mode 100644 index 0000000..2e3dc69 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md @@ -0,0 +1,7 @@ +Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved. + +NVIDIA CORPORATION and its licensors retain all intellectual property +and proprietary rights in and to this software, related documentation +and any modifications thereto. Any use, reproduction, disclosure or +distribution of this software and related documentation without an express +license agreement from NVIDIA CORPORATION is strictly prohibited. diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md.meta new file mode 100644 index 0000000..f36cfe5 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6899f9a40e5d1114c9146ac0d8ddd203 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins.meta new file mode 100644 index 0000000..fb4edf9 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7dbb533ef9b1b8745a2bc09d80a142d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64.meta new file mode 100644 index 0000000..d94bc85 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 382460b4efeded84cbef5762a8b6424b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll new file mode 100644 index 0000000..b2930e1 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta new file mode 100644 index 0000000..549a157 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/GfxPluginNVIDIAStreamline.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 98b2974e71a1edc4f886c6e00ab73d79 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll new file mode 100644 index 0000000..32a3cac Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll.meta new file mode 100644 index 0000000..b4aaa9d --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/nvngx_dlssg.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 43b00b1a1adef4d41ac98fdb1d73ba83 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll new file mode 100644 index 0000000..489db35 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll.meta new file mode 100644 index 0000000..884d42b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.common.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: ca6f33823c568584f9aa5cbeadd51424 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll new file mode 100644 index 0000000..ede52e7 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll.meta new file mode 100644 index 0000000..7b819ca --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.dlss_g.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 334057619639d404c9404b4728d8ce6e +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.imgui.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.imgui.dll.meta new file mode 100644 index 0000000..59215a1 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.imgui.dll.meta @@ -0,0 +1,52 @@ +fileFormatVersion: 2 +guid: 22ceb1f007652b742aa348858ed7603a +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: x86_64 + DefaultValueInitialized: true + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: x86_64 + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll new file mode 100644 index 0000000..e32f039 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll.meta new file mode 100644 index 0000000..3551cc7 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.interposer.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: c111f96ddd19e8440908bc89d71d69c1 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll new file mode 100644 index 0000000..c8f1016 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll.meta new file mode 100644 index 0000000..d6ddc05 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.pcl.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: aa3cdfd7567ede4499cc98b29a53314c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll new file mode 100644 index 0000000..8593288 Binary files /dev/null and b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll differ diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll.meta new file mode 100644 index 0000000..9bbd099 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Plugins/x86_64/sl.reflex.dll.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: 261d07c95e83fec4e8274400661cd84c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime.meta new file mode 100644 index 0000000..ac48bfe --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c4925c5b82eb39b4188e1a64b975034e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs new file mode 100644 index 0000000..22936bf --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs @@ -0,0 +1,77 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline Builtin")] + public class Streamline : MonoBehaviour + { + private static CommandBuffer m_cmdBuffer; + public bool StreamlineFeatureAvailable { get; private set; } = false; + private Camera m_camera; + void Awake() + { + m_camera = GetComponent(); + + StreamlineFeatureAvailable = false; + if (StreamlineCore.IsStreamlineEnabled()) + { + StreamlineFeatureAvailable = true; + m_cmdBuffer = new CommandBuffer(); + m_cmdBuffer.name = "StreamlineCMDs"; + } + } + + void OnEnable() + { + if (StreamlineFeatureAvailable) + { + m_camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdBuffer); + m_cmdBuffer.Clear(); + } + } + + void OnDisable() + { + if (StreamlineFeatureAvailable) + { + m_camera.RemoveCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdBuffer); + m_cmdBuffer.Clear(); + } + } + + void OnDestroy() + { + StreamlineCore.m_nativeAllocator.RemoveAllItems(); + } + + void LateUpdate() + { + if (StreamlineFeatureAvailable) + { + StreamlineCore.m_nativeAllocator.RemoveOldItems((uint)Time.frameCount); + + if (GraphicsSettings.defaultRenderPipeline == null) //if builtin + { + m_cmdBuffer.Clear(); +#if !UNITY_EDITOR && UNITY_2019_1_OR_NEWER + // On DX12 up until 2020.2 command lists that are being generated do not get flushed. + // This causes incorrect ordering of plugin side command lists. + // i.e. After submitted lists but before currently being generated lists. + // We can force a flush in non-editor mode by creating a fence but never waiting for it. + // Editor mode does not support GPUFence. + GraphicsFence fence1 = m_cmdBuffer.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations); +#endif + bool jitter = false; + bool firstFrame = false; + StreamlineCore.SetupStreamlineConstants(m_cmdBuffer, m_camera, 0, (uint)Time.frameCount, jitter, Vector4.zero, firstFrame); + } + } + } + + }; +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs.meta new file mode 100644 index 0000000..8a95de2 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/Streamline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7c8c6bc9ae687a45abf374858854166 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineCore.cs new file mode 100644 index 0000000..dec0219 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineCore.cs @@ -0,0 +1,637 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + public class NativeMemoryAllocator + { + public class NativeMemoryItem + { + public IntPtr m_nativePtr = IntPtr.Zero; + public UInt32 m_frameIndex; + + public NativeMemoryItem(UInt32 frameIndex, int size) + { + m_nativePtr = Marshal.AllocHGlobal(size); + m_frameIndex = frameIndex; + } + + public void Free() + { + Marshal.FreeHGlobal(m_nativePtr); + m_nativePtr = IntPtr.Zero; + } + + }; + + public List m_memList = new List(); + public String m_name; + + public NativeMemoryAllocator(String name) + { + m_name = name; + } + + public IntPtr Malloc(UInt32 frameIndex, int size) + { + NativeMemoryItem newItem = new NativeMemoryItem(frameIndex, size); + + m_memList.Add(newItem); + + return newItem.m_nativePtr; + } + + // Remove items older than frameIndex + public void RemoveOldItems(UInt32 frameIndex) + { + //if item.frameTime + 4 < frameIndex, remove it + for (int i = m_memList.Count - 1; i >= 0; i--) + { + if (m_memList[i].m_frameIndex + 4 < frameIndex) + { + m_memList[i].Free(); + m_memList.RemoveAt(i); + } + } + //Debug.Log("NativeAllocator " + m_name + " has " + m_memList.Count + " items"); + } + + public void RemoveAllItems() + { + for (int i = m_memList.Count - 1; i >= 0; i--) + { + m_memList[i].Free(); + m_memList.RemoveAt(i); + } + } + + }; + + public class StreamlineCore + { + public enum PluginEvent + { + //Must match internal enum PluginEvent + + PluginEventSubmitData = 0, + PluginEventSetConstants = 1, + PluginEventSetDLSSGConstants = 2, + PluginEventSetTagData = 3, + PluginEventSetDLSSConstants = 4, + PluginEventEvaluateFeature = 5, + //insert new ones here, before reflex ones + + PluginEvent_SIMULATION_START = 10, + PluginEvent_SIMULATION_END = 11, + PluginEvent_RENDERSUBMIT_START = 12, + PluginEvent_RENDERSUBMIT_END = 13, + PluginEvent_PRESENT_START = 14, + PluginEvent_PRESENT_END = 15, + PluginEvent_INPUT_SAMPLE = 16, + PluginEvent_TRIGGER_FLASH = 17, + + PluginEventCount = 18 + }; + + public enum Feature : uint + { + //! Deep Learning Super Sampling + eFeatureDLSS = 0, + //! Real-Time Denoiser + eFeatureNRD = 1, + //! NVIDIA Image Scaling + eFeatureNIS = 2, + //! Low-Latency + eFeatureReflex = 3, + //! Streamline debug plugin + eFeatureDebug = 5, + //! DLSS Frame Generation + eFeatureDLSS_G = 1000, + + //! Common feature, NOT intended to be used directly + //eFeatureCommon = UINT_MAX + }; + + public enum BufferType : uint + { + //! Depth buffer - IMPORTANT - Must be suitable to use with clipToPrevClip transformation (see Constants below) + eBufferTypeDepth, + //! Object and optional camera motion vectors (see Constants below) + eBufferTypeMVec, + //! Color buffer with all post-processing effects applied but without any UI/HUD elements + eBufferTypeHUDLessColor, + //! Color buffer containing jittered input data for the image scaling pass + eBufferTypeScalingInputColor, + //! Color buffer containing results from the image scaling pass + eBufferTypeScalingOutputColor, + //! Normals + eBufferTypeNormals, + //! Roughness + eBufferTypeRoughness, + //! Albedo + eBufferTypeAlbedo, + //! Specular Albedo + eBufferTypeSpecularAlbedo, + //! Indirect Albedo + eBufferTypeIndirectAlbedo, + //! Specular Mvec + eBufferTypeSpecularMVec, + //! Disocclusion Mask + eBufferTypeDisocclusionMask, + //! Emissive + eBufferTypeEmissive, + //! Exposure + eBufferTypeExposure, + //! Buffer with normal and roughness in alpha channel + eBufferTypeNormalRoughness, + //! Diffuse and camera ray length + eBufferTypeDiffuseHitNoisy, + //! Diffuse denoised + eBufferTypeDiffuseHitDenoised, + //! Specular and reflected ray length + eBufferTypeSpecularHitNoisy, + //! Specular denoised + eBufferTypeSpecularHitDenoised, + //! Shadow noisy + eBufferTypeShadowNoisy, + //! Shadow denoised + eBufferTypeShadowDenoised, + //! AO noisy + eBufferTypeAmbientOcclusionNoisy, + //! AO denoised + eBufferTypeAmbientOcclusionDenoised, + + //! Optional - UI/HUD color and alpha + //! IMPORTANT: Please make sure that alpha channel has enough precision (for example do NOT use formats like R10G10B10A2) + eBufferTypeUIColorAndAlpha, + //! Optional - Shadow pixels hint (set to 1 if a pixel belongs to the shadow area, 0 otherwise) + eBufferTypeShadowHint, + //! Optional - Reflection pixels hint (set to 1 if a pixel belongs to the reflection area, 0 otherwise) + eBufferTypeReflectionHint, + //! Optional - Particle pixels hint (set to 1 if a pixel represents a particle, 0 otherwise) + eBufferTypeParticleHint, + //! Optional - Transparency pixels hint (set to 1 if a pixel belongs to the transparent area, 0 otherwise) + eBufferTypeTransparencyHint, + //! Optional - Animated texture pixels hint (set to 1 if a pixel belongs to the animated texture area, 0 otherwise) + eBufferTypeAnimatedTextureHint, + //! Optional - Bias for current color vs history hint - lerp(history, current, bias) (set to 1 to completely reject history) + eBufferTypeBiasCurrentColorHint, + //! Optional - Ray-tracing distance (camera ray length) + eBufferTypeRaytracingDistance, + //! Optional - Motion vectors for reflections + eBufferTypeReflectionMotionVectors, + //! Optional - Position, in same space as eBufferTypeNormals + eBufferTypePosition, + //! Optional - Indicates (via non-zero value) which pixels have motion/depth values that do not match the final color content at that pixel (e.g. overlaid, opaque Picture-in-Picture) + eBufferTypeInvalidDepthMotionHint, + + //! Alpha + eBufferTypeAlpha, + //! Color buffer containing only opaque geometry + eBufferTypeOpaqueColor, + //! Optional - Reduce reliance on history instead using current frame hint (0 if a pixel is not at all reactive and default composition should be used, 1 if fully reactive) + eBufferTypeReactiveMaskHint, + //! Optional - Pixel lock adjustment hint (set to 1 if pixel lock should be completely removed, 0 otherwise) + eBufferTypeTransparencyAndCompositionMaskHint + }; + + public enum SLBool : uint + { + eFalse, + eTrue, + eInvalid + }; + + public enum SLResult : uint + { + eOk, + eErrorIO, + eErrorDriverOutOfDate, + eErrorOSOutOfDate, + eErrorOSDisabledHWS, + eErrorDeviceNotCreated, + eErrorNoSupportedAdapter, + eErrorNoPlugins, + eErrorVulkanAPI, + eErrorDXGIAPI, + eErrorD3DAPI, + eErrorNRDAPI, + eErrorNVAPI, + eErrorReflexAPI, + eErrorNGXFailed, + eErrorJSONParsing, + eErrorMissingProxy, + eErrorMissingResourceState, + eErrorInvalidIntegration, + eErrorMissingInputParameter, + eErrorNotInitialized, + eErrorComputeFailed, + eErrorInitNotCalled, + eErrorExceptionHandler, + eErrorInvalidParameter, + eErrorMissingConstants, + eErrorDuplicatedConstants, + eErrorMissingOrInvalidAPI, + eErrorCommonConstantsMissing, + eErrorUnsupportedInterface, + eErrorFeatureMissing, + eErrorFeatureNotSupported, + eErrorFeatureMissingHooks, + eErrorFeatureFailedToLoad, + eErrorFeatureWrongPriority, + eErrorFeatureMissingDependency, + eErrorFeatureManagerInvalidState, + eErrorInvalidState, + }; + + [StructLayout(LayoutKind.Sequential)] + struct Constants + { + public UInt32 id; + public UInt32 frameIndex; + + //! IMPORTANT: All matrices are row major (see float4x4 definition) and + //! must NOT contain temporal AA jitter offset (if any). Any jitter offset + //! should be provided as the additional parameter Constants::jitterOffset (see below) + + //! Specifies matrix transformation from the camera view to the clip space. + public Matrix4x4 cameraViewToClip; + //! Specifies matrix transformation from the clip space to the camera view space. + public Matrix4x4 clipToCameraView; + //! Optional - Specifies matrix transformation describing lens distortion in clip space. + public Matrix4x4 clipToLensClip; + //! Specifies matrix transformation from the current clip to the previous clip space. + //! clipToPrevClip = clipToView * viewToViewPrev * viewToClipPrev + //! Sample code can be found in sl_matrix_helpers.h + public Matrix4x4 clipToPrevClip; + //! Specifies matrix transformation from the previous clip to the current clip space. + //! prevClipToClip = clipToPrevClip.inverse() + public Matrix4x4 prevClipToClip; + + //! Specifies pixel space jitter offset + public Vector2 jitterOffset; + //! Specifies scale factors used to normalize motion vectors (so the values are in [-1,1] range) + public Vector2 mvecScale; + //! Optional - Specifies camera pinhole offset if used. + public Vector2 cameraPinholeOffset; + //! Specifies camera position in world space. + public Vector3 cameraPos; + //! Specifies camera up vector in world space. + public Vector3 cameraUp; + //! Specifies camera right vector in world space. + public Vector3 cameraRight; + //! Specifies camera forward vector in world space. + public Vector3 cameraFwd; + + //! Specifies camera near view plane distance. + public float cameraNear; + //! Specifies camera far view plane distance. + public float cameraFar; + //! Specifies camera field of view in radians. + public float cameraFOV; + //! Specifies camera aspect ratio defined as view space width divided by height. + public float cameraAspectRatio; + //! Specifies which value represents an invalid (un-initialized) value in the motion vectors buffer + //! NOTE: This is only required if `cameraMotionIncluded` is set to false and SL needs to compute it. + public float motionVectorsInvalidValue; + + //! Specifies if depth values are inverted (value closer to the camera is higher) or not. + public SLBool depthInverted; + //! Specifies if camera motion is included in the MVec buffer. + public SLBool cameraMotionIncluded; + //! Specifies if motion vectors are 3D or not. + public SLBool motionVectors3D; + //! Specifies if previous frame has no connection to the current one (i.e. motion vectors are invalid) + public SLBool reset; + //! Specifies if orthographic projection is used or not. + public SLBool orthographicProjection; + //! Specifies if motion vectors are already dilated or not. + public SLBool motionVectorsDilated; + //! Specifies if motion vectors are jittered or not. + public SLBool motionVectorsJittered; + }; + + [StructLayout(LayoutKind.Sequential)] + struct TextureTagData + { + public uint frameIndex; + public uint tag; + public uint id; + public IntPtr nativeTexturePtr; + }; + + [StructLayout(LayoutKind.Sequential)] + struct EvaluateFeatureData + { + public uint frameIndex; + public uint id; + public uint feature; + }; + + + public static NativeMemoryAllocator m_nativeAllocator = new NativeMemoryAllocator("SL"); + + //0=DLSSG, 1=REFLEX + private static Dictionary m_dictFeatureIds = new Dictionary(); + + + + public static bool IsStreamlineEnabled() + { + bool enabled = Streamline_IsStreamlineEnabled() != 0; + + return enabled; + } + + public static bool IsFeatureSupported(Feature feature) + { + bool supported = Streamline_IsFeatureSupported((uint)feature) != 0; + if (!supported) + { + SLResult result = (SLResult)Plugin_GetLastError(); + Debug.LogFormat("Streamline IsFeatureSupported {0} failed {1}", feature.ToString(), result.ToString()); + } + return supported; + } + + // returns -1 if failed + public static int CreateFeature(Feature feature) + { + //If DLSS-G check we don't already have that feature as we can only have one. + if (feature == Feature.eFeatureDLSS_G) + { + if (m_dictFeatureIds.ContainsKey(0)) + { + Debug.LogError("Trying to create >1 DLSS-G feature"); + return -1; + } + else + { + m_dictFeatureIds.Add(0, Feature.eFeatureDLSS_G); + return 0; + } + } + else if (feature == Feature.eFeatureReflex) + { + if (m_dictFeatureIds.ContainsKey(1)) + { + Debug.LogError("Trying to create >1 Reflex feature"); + return -1; + } + else + { + m_dictFeatureIds.Add(1, Feature.eFeatureReflex); + return 1; + } + } + else + { + for (int i=2; i 0 && constants.frameIndex == lastFrameConstantsSet) //Only set constants once per frame + return; + lastFrameConstantsSet = constants.frameIndex; + + int size = Marshal.SizeOf(typeof(StreamlineDLSSCore.DLSSConstants)); + + IntPtr dataPtr = StreamlineCore.m_nativeAllocator.Malloc(constants.frameIndex, size); + Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld + + StreamlineCore.InsertEventCall(cmdBuffer, StreamlineCore.PluginEvent.PluginEventSetDLSSConstants, dataPtr); + } + + public static bool GetOptimalSettings(DLSSMode mode, uint outputWidth, uint outputHeight, out DLSSOptimalSettings settingsDest) + { + // allocate native data to fill + int size = Marshal.SizeOf(typeof(DLSSOptimalSettings)); + IntPtr dataPtr = Marshal.AllocHGlobal(size); + + bool success = Plugin_DLSSGetOptimalSettings((uint)mode, outputWidth, outputHeight, dataPtr) != 0; + + + if (success) + { + settingsDest = (DLSSOptimalSettings)Marshal.PtrToStructure(dataPtr, typeof(DLSSOptimalSettings)); + } + else + { + settingsDest = new DLSSOptimalSettings(); + } + + Marshal.FreeHGlobal(dataPtr); + return success; + } + + //---------------------- + // HDRP calls + + + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int Plugin_DLSSGetOptimalSettings(uint mode, uint outputWidth, uint outputHeight, IntPtr dlssSettingsDest); + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs new file mode 100644 index 0000000..2e1be20 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs @@ -0,0 +1,314 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + public class StreamlineDLSSGCore + { + public static bool DLSSGEnabled { get; set; } = true; + public const bool UseHudlessColor = true; + + public enum DLSSGMode : uint + { + eDLSSGModeOff, + eDLSSGModeOn, + eDLSSGModeCount + }; + + public enum DLSSGFlags : uint + { + eShowOnlyInterpolatedFrame = 1 << 0, + eDynamicResolutionEnabled = 1 << 1, + eRequestVRAMEstimate = 1 << 2, + eRequestRawFrameTime = 1 << 3 + }; + + [StructLayout(LayoutKind.Sequential)] + struct DLSSGConstants + { + public UInt32 id; + public UInt32 frameIndex; + + //! Specifies which mode should be used. + public UInt32 mode; + //! Must be 1 + public UInt32 numFramesToGenerate; + //! Optional - Flags used to enable or disable certain functionality + public UInt32 flags; + //! Optional - Dynamic resolution optimal width (used only if eDynamicResolutionEnabled is set) + public UInt32 dynamicResWidth; + //! Optional - Dynamic resolution optimal height (used only if eDynamicResolutionEnabled is set) + public UInt32 dynamicResHeight; + //! Optional - Expected number of buffers in the swap-chain + public UInt32 numBackBuffers; + //! Optional - Expected width of the input render targets (depth, motion-vector buffers etc) + public UInt32 mvecDepthWidth; + //! Optional - Expected height of the input render targets (depth, motion-vector buffers etc) + public UInt32 mvecDepthHeight; + //! Optional - Expected width of the back buffers in the swap-chain + public UInt32 colorWidth; + //! Optional - Expected height of the back buffers in the swap-chain + public UInt32 colorHeight; + //! Optional - Indicates native format used for the swap-chain back buffers + public UInt32 colorBufferFormat; + //! Optional - Indicates native format used for eMotionVectors + public UInt32 mvecBufferFormat; + //! Optional - Indicates native format used for eDepth + public UInt32 depthBufferFormat; + //! Optional - Indicates native format used for eHUDLessColor + public UInt32 hudLessBufferFormat; + //! Optional - Indicates native format used for eUIColorAndAlpha + public UInt32 uiBufferFormat; + }; + + public class TaggedTextureDimensions + { + public Rect m_currentViewRect = new Rect(0.0f, 0.0f, 0.0f, 0.0f); //view rect within swapchain + public Rect m_currentDrawRect = new Rect(0.0f, 0.0f, 0.0f, 0.0f); //draw rect within view rect + public Vector4 m_srcScaleBias = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + public Vector4 m_dstScaleBias = new Vector4(0.0f, 0.0f, 0.0f, 0.0f); + public float m_desktopScale = 1.0f; //I think this is only needed for editor mode + }; + + private static TaggedTextureDimensions m_taggedDimensions = new TaggedTextureDimensions(); + + private static int m_taggedBufferCount = 2; //>2 might be too much + private static RenderTexture[] m_depthTexTagged = new RenderTexture[m_taggedBufferCount]; + private static RenderTexture[] m_mvecsTexTagged = new RenderTexture[m_taggedBufferCount]; + private static RenderTexture[] m_hudlessColorTexTagged = new RenderTexture[m_taggedBufferCount]; + + public static ref TaggedTextureDimensions GetTaggedTextureDimensionsRef() + { + return ref m_taggedDimensions; + } + + public static RenderTexture GetTargetDepthTexture() + { + return m_depthTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + public static RenderTexture GetTargetMVecsTexture() + { + return m_mvecsTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + public static RenderTexture GetTargetHudlessColorTexture() + { + return m_hudlessColorTexTagged[Time.frameCount % m_taggedBufferCount]; + } + + private static uint lastFrameConstantsSet = 0; + + public class RenderTextureDisposal + { + public RenderTexture m_tex; + public int m_time; + public RenderTextureDisposal(RenderTexture tex) + { + m_time = Time.frameCount + 2; //keep textures around for n frames incase SL is still using them. TODO, find out is SL is still using a texture. + m_tex = tex; + } + }; + + public static List m_disposalList = new List(); + + + public static bool UpdateDrawRects(Camera camera) + { + // Check if draw rect has changed and set flag for texture resize + bool changed = false; + + Display currentDisplay = Display.displays[camera.targetDisplay]; + + int sw = currentDisplay.systemWidth; + int sh = currentDisplay.systemHeight; + + Rect drawRect = new Rect(0, sh, sw, -sh); // Y pos&height for YFlip + Rect viewInParentRect = new Rect(0, 0, sw, sh); + + if (viewInParentRect != m_taggedDimensions.m_currentViewRect) + { + m_taggedDimensions.m_currentViewRect = viewInParentRect; + } + + if (drawRect != m_taggedDimensions.m_currentDrawRect) + { + changed = true; + + m_taggedDimensions.m_currentDrawRect = drawRect; + } + + if (changed) //and HDRP + { + HDRPCalculateScaleBias(drawRect,viewInParentRect); + } + return changed; + } + + public static void AddTextureForDisposal(RenderTexture tex) + { + RenderTextureDisposal item = new RenderTextureDisposal(tex); + m_disposalList.Add(item); + } + + //call before get or allocate textures + public static void ProcessDisposals() + { + foreach (RenderTextureDisposal item in m_disposalList) + { + if (item.m_time < Time.frameCount) + { + item.m_tex.Release(); + m_disposalList.Remove(item); + } + } + } + + public static void AllocateTextures(Rect drawRect, Rect viewInParentRect, bool inEditor, float desktopScale, bool useHudlessColor) + { + //TODO, these sizes don't always match the swap-chain color texture size in the Editor. ~1pixel error. ViewInParentRect dimensions are often not exact pixel sizes. + int width = (int)Mathf.Ceil((viewInParentRect.width + viewInParentRect.x) * desktopScale); + int height = (int)Mathf.Ceil((viewInParentRect.height + viewInParentRect.y) * desktopScale); + + for (int i = 0; i < m_taggedBufferCount; i++) + { + if (m_depthTexTagged[i]) + { + AddTextureForDisposal(m_depthTexTagged[i]); + m_depthTexTagged[i] = null; + } + if (m_mvecsTexTagged[i]) + { + AddTextureForDisposal(m_mvecsTexTagged[i]); + m_mvecsTexTagged[i] = null; + } + if (useHudlessColor) + { + if (m_hudlessColorTexTagged[i]) + { + AddTextureForDisposal(m_hudlessColorTexTagged[i]); + m_hudlessColorTexTagged[i] = null; + } + } + } + + for (int i = 0; i < m_taggedBufferCount; i++) + { + if (m_depthTexTagged[i] == null) + { + RenderTextureDescriptor descDepth = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.RFloat, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray }; + m_depthTexTagged[i] = new RenderTexture(descDepth); + m_depthTexTagged[i].name = "r_DLSSGDepthCopy"; + } + + if (m_mvecsTexTagged[i] == null) + { + RenderTextureDescriptor descMVecs = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.RGHalf, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray }; + m_mvecsTexTagged[i] = new RenderTexture(descMVecs); + m_mvecsTexTagged[i].name = "r_DLSSGMotionVectors"; + } + + if (useHudlessColor) + { + if (m_hudlessColorTexTagged[i] == null) + { + RenderTextureDescriptor descMVecs = new RenderTextureDescriptor(width, height) + { colorFormat = RenderTextureFormat.ARGB32, useMipMap = false, autoGenerateMips = false, enableRandomWrite = true, dimension = TextureDimension.Tex2DArray, sRGB=true }; + m_hudlessColorTexTagged[i] = new RenderTexture(descMVecs); + m_hudlessColorTexTagged[i].name = "r_DLSSGHudlessColor"; + } + } + } + } + + public static void SetupDLSSGFeatureConstants(CommandBuffer cmdBuffer, Camera camera, uint id, uint frameIndex) + { + if (frameIndex > 0 && frameIndex == lastFrameConstantsSet) //Only set constants once per frame + return; + lastFrameConstantsSet = frameIndex; + + StreamlineDLSSGCore.DLSSGConstants constants = new StreamlineDLSSGCore.DLSSGConstants(); + + constants.id = id; + constants.frameIndex = frameIndex; + constants.mode = (uint) (DLSSGEnabled ? StreamlineDLSSGCore.DLSSGMode.eDLSSGModeOn : StreamlineDLSSGCore.DLSSGMode.eDLSSGModeOff); + constants.numFramesToGenerate = 1; + constants.flags = 0; + + int size = Marshal.SizeOf(typeof(StreamlineDLSSGCore.DLSSGConstants)); + + IntPtr dataPtr = StreamlineCore.m_nativeAllocator.Malloc(frameIndex, size); + Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld + + StreamlineCore.InsertEventCall(cmdBuffer, StreamlineCore.PluginEvent.PluginEventSetDLSSGConstants, dataPtr); + } + + + //---------------------- + // HDRP calls + + public static void HDRPRequestScaleBiasValues(out Vector4 srcScaleBias, out Vector4 dstScaleBias) + { + srcScaleBias = m_taggedDimensions.m_srcScaleBias; + dstScaleBias = m_taggedDimensions.m_dstScaleBias; + } + + public static void HDRPSetupDLSSGFeatureConstants(CommandBuffer cmdBuffer, Camera camera) + { + Debug.LogError("m_id doesnt exist in HDRPSetupDLSSGFeatureConstants"); + //SetupDLSSGFeatureConstants(cmdBuffer, camera, m_id, (uint)Time.frameCount); + } + + public static void HDRPCalculateScaleBias(Rect drawRect, Rect viewInParentRect) + { + // note. The following calculations would be required for enabling DLSSG in editor mode, if implemented. + float scaleX = 1.0f; + float scaleY = 1.0f; + float biasX = 0.0f; + float biasY = 0.0f; + + if (drawRect.x < 0 || drawRect.y > viewInParentRect.height) + { + // draw rect is larger than view rect (Editor mode, if ever implemented) + biasX = -drawRect.x / drawRect.width; + scaleX = drawRect.width / viewInParentRect.width; + biasY = drawRect.y / -drawRect.height; + scaleY = drawRect.height / viewInParentRect.height; + + m_taggedDimensions.m_srcScaleBias = new Vector4(1.0f / scaleX, 1.0f / scaleY, biasX, biasY); + + // viewInParentRect has n pixels at top of swapchain for gui + float swapChainHeight = viewInParentRect.height + viewInParentRect.y; + float destYScale = viewInParentRect.height / swapChainHeight; + float destYBias = viewInParentRect.y / swapChainHeight; + + m_taggedDimensions.m_dstScaleBias = new Vector4(1.0f, destYScale, 0.0f, destYBias); + } + else + { + //draw rect is within the view rect + float swapChainHeight = viewInParentRect.height + viewInParentRect.y; + scaleX = drawRect.width / viewInParentRect.width; + scaleY = drawRect.height / swapChainHeight; + biasX = drawRect.x / viewInParentRect.width; + biasY = (drawRect.y + viewInParentRect.y) / swapChainHeight; + + m_taggedDimensions.m_srcScaleBias = new Vector4(1.0f, 1.0f, 0.0f, 0.0f); + m_taggedDimensions.m_dstScaleBias = new Vector4(scaleX, scaleY, biasX, biasY); + } + + //Debug.Log("drectx=" + drawRect.x + " y=" + drawRect.y + " w=" + drawRect.width + " h=" + drawRect.height); + //Debug.Log("vrectx=" + viewRect.x + " y=" + viewRect.y + " w=" + viewRect.width + " h=" + viewRect.height); + //Debug.Log("scaleBias = scaleX= " + scaleX + " scaleY= " + scaleY + " biasX= " + biasX + " biasY= " + biasY); + } + + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs.meta new file mode 100644 index 0000000..f48a308 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineDLSSGCore.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2400248ea5cb82247b40565a582af890 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs new file mode 100644 index 0000000..c5dfffc --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline HDRP")] + public class StreamlineHDRP : MonoBehaviour + { + public bool StreamlineFeatureAvailable { get; private set; } = false; + + public void HDRPSetStreamlineConstants(CommandBuffer cmdBuffer, Camera camera, bool requiresJitter, Vector4 jitter, bool isFirstFrame, int frameCount) + { + StreamlineCore.SetupStreamlineConstants(cmdBuffer, camera, 0, (uint)frameCount, requiresJitter, jitter, isFirstFrame); + } + + void Awake() + { + StreamlineFeatureAvailable = false; + if (StreamlineCore.IsStreamlineEnabled()) + { + StreamlineFeatureAvailable = true; + } + } + + void OnEnable() + { + } + + void OnDisable() + { + } + + void OnDestroy() + { + StreamlineCore.m_nativeAllocator.RemoveAllItems(); + } + + void LateUpdate() + { + if (StreamlineFeatureAvailable) + { + StreamlineCore.m_nativeAllocator.RemoveOldItems((uint)Time.frameCount); + } + } + + }; +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs.meta new file mode 100644 index 0000000..6a2ba54 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineHDRP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 182def67fadf4fd4aba7f2934fe07b8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs new file mode 100644 index 0000000..c945d6b --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ +using System; +using System.Collections; +using System.Runtime.InteropServices; +using UnityEngine; +using UnityEngine.Rendering; +using NVStreamline; + +namespace NVStreamline +{ + public class StreamlineReflexCore : MonoBehaviour + { + public enum NvReflex_LATENCY_MARKER_TYPE : int + { + SIMULATION_START, + SIMULATION_END, + RENDERSUBMIT_START, + RENDERSUBMIT_END, + PRESENT_START, + PRESENT_END, + INPUT_SAMPLE, + TRIGGER_FLASH, + PC_LATENCY_PING + } + + public enum NvReflex_Status : int + { + NvReflex_OK = 0, + NvReflex_ERROR = -1, + NvReflex_LIBRARY_NOT_FOUND = -2, + NvReflex_NO_IMPLEMENTATION = -3, + NvReflex_API_NOT_INITIALIZED = -4, + NvReflex_INVALID_ARGUMENT = -5, + NvReflex_NVIDIA_DEVICE_NOT_FOUND = -6, + NvReflex_END_ENUMERATION = -7, + NvReflex_INVALID_HANDLE = -8, + NvReflex_INCOMPATIBLE_STRUCT_VERSION = -9, + NvReflex_HANDLE_INVALIDATED = -10, + NvReflex_OPENGL_CONTEXT_NOT_CURRENT = -11, + NvReflex_INVALID_POINTER = -14, + NvReflex_NO_GL_EXPERT = -12, + NvReflex_INSTRUMENTATION_DISABLED = -13, + NvReflex_NO_GL_NSIGHT = -15, + NvReflex_EXPECTED_LOGICAL_GPU_HANDLE = -100, + NvReflex_EXPECTED_PHYSICAL_GPU_HANDLE = -101, + NvReflex_EXPECTED_DISPLAY_HANDLE = -102, + NvReflex_INVALID_COMBINATION = -103, + NvReflex_NOT_SUPPORTED = -104, + NvReflex_PORTID_NOT_FOUND = -105, + NvReflex_EXPECTED_UNATTACHED_DISPLAY_HANDLE = -106, + NvReflex_INVALID_PERF_LEVEL = -107, + NvReflex_DEVICE_BUSY = -108, + NvReflex_NV_PERSIST_FILE_NOT_FOUND = -109, + NvReflex_PERSIST_DATA_NOT_FOUND = -110, + NvReflex_EXPECTED_TV_DISPLAY = -111, + NvReflex_EXPECTED_TV_DISPLAY_ON_DCONNECTOR = -112, + NvReflex_NO_ACTIVE_SLI_TOPOLOGY = -113, + NvReflex_SLI_RENDERING_MODE_NOTALLOWED = -114, + NvReflex_EXPECTED_DIGITAL_FLAT_PANEL = -115, + NvReflex_ARGUMENT_EXCEED_MAX_SIZE = -116, + NvReflex_DEVICE_SWITCHING_NOT_ALLOWED = -117, + NvReflex_TESTING_CLOCKS_NOT_SUPPORTED = -118, + NvReflex_UNKNOWN_UNDERSCAN_CONFIG = -119, + NvReflex_TIMEOUT_RECONFIGURING_GPU_TOPO = -120, + NvReflex_DATA_NOT_FOUND = -121, + NvReflex_EXPECTED_ANALOG_DISPLAY = -122, + NvReflex_NO_VIDLINK = -123, + NvReflex_REQUIRES_REBOOT = -124, + NvReflex_INVALID_HYBRID_MODE = -125, + NvReflex_MIXED_TARGET_TYPES = -126, + NvReflex_SYSWOW64_NOT_SUPPORTED = -127, + NvReflex_IMPLICIT_SET_GPU_TOPOLOGY_CHANGE_NOT_ALLOWED = -128, + NvReflex_REQUEST_USER_TO_CLOSE_NON_MIGRATABLE_APPS = -129, + NvReflex_OUT_OF_MEMORY = -130, + NvReflex_WAS_STILL_DRAWING = -131, + NvReflex_FILE_NOT_FOUND = -132, + NvReflex_TOO_MANY_UNIQUE_STATE_OBJECTS = -133, + NvReflex_INVALID_CALL = -134, + NvReflex_D3D10_1_LIBRARY_NOT_FOUND = -135, + NvReflex_FUNCTION_NOT_FOUND = -136, + NvReflex_INVALID_USER_PRIVILEGE = -137, + NvReflex_EXPECTED_NON_PRIMARY_DISPLAY_HANDLE = -138, + NvReflex_EXPECTED_COMPUTE_GPU_HANDLE = -139, + NvReflex_STEREO_NOT_INITIALIZED = -140, + NvReflex_STEREO_REGISTRY_ACCESS_FAILED = -141, + NvReflex_STEREO_REGISTRY_PROFILE_TYPE_NOT_SUPPORTED = -142, + NvReflex_STEREO_REGISTRY_VALUE_NOT_SUPPORTED = -143, + NvReflex_STEREO_NOT_ENABLED = -144, + NvReflex_STEREO_NOT_TURNED_ON = -145, + NvReflex_STEREO_INVALID_DEVICE_INTERFACE = -146, + NvReflex_STEREO_PARAMETER_OUT_OF_RANGE = -147, + NvReflex_STEREO_FRUSTUM_ADJUST_MODE_NOT_SUPPORTED = -148, + NvReflex_TOPO_NOT_POSSIBLE = -149, + NvReflex_MODE_CHANGE_FAILED = -150, + NvReflex_D3D11_LIBRARY_NOT_FOUND = -151, + NvReflex_INVALID_ADDRESS = -152, + NvReflex_STRING_TOO_SMALL = -153, + NvReflex_MATCHING_DEVICE_NOT_FOUND = -154, + NvReflex_DRIVER_RUNNING = -155, + NvReflex_DRIVER_NOTRUNNING = -156, + NvReflex_ERROR_DRIVER_RELOAD_REQUIRED = -157, + NvReflex_SET_NOT_ALLOWED = -158, + NvReflex_ADVANCED_DISPLAY_TOPOLOGY_REQUIRED = -159, + NvReflex_SETTING_NOT_FOUND = -160, + NvReflex_SETTING_SIZE_TOO_LARGE = -161, + NvReflex_TOO_MANY_SETTINGS_IN_PROFILE = -162, + NvReflex_PROFILE_NOT_FOUND = -163, + NvReflex_PROFILE_NAME_IN_USE = -164, + NvReflex_PROFILE_NAME_EMPTY = -165, + NvReflex_EXECUTABLE_NOT_FOUND = -166, + NvReflex_EXECUTABLE_ALREADY_IN_USE = -167, + NvReflex_DATATYPE_MISMATCH = -168, + NvReflex_PROFILE_REMOVED = -169, + NvReflex_UNREGISTERED_RESOURCE = -170, + NvReflex_ID_OUT_OF_RANGE = -171, + NvReflex_DISPLAYCONFIG_VALIDATION_FAILED = -172, + NvReflex_DPMST_CHANGED = -173, + NvReflex_INSUFFICIENT_BUFFER = -174, + NvReflex_ACCESS_DENIED = -175, + NvReflex_MOSAIC_NOT_ACTIVE = -176, + NvReflex_SHARE_RESOURCE_RELOCATED = -177, + NvReflex_REQUEST_USER_TO_DISABLE_DWM = -178, + NvReflex_D3D_DEVICE_LOST = -179, + NvReflex_INVALID_CONFIGURATION = -180, + NvReflex_STEREO_HANDSHAKE_NOT_DONE = -181, + NvReflex_EXECUTABLE_PATH_IS_AMBIGUOUS = -182, + NvReflex_DEFAULT_STEREO_PROFILE_IS_NOT_DEFINED = -183, + NvReflex_DEFAULT_STEREO_PROFILE_DOES_NOT_EXIST = -184, + NvReflex_CLUSTER_ALREADY_EXISTS = -185, + NvReflex_DPMST_DISPLAY_ID_EXPECTED = -186, + NvReflex_INVALID_DISPLAY_ID = -187, + NvReflex_STREAM_IS_OUT_OF_SYNC = -188, + NvReflex_INCOMPATIBLE_AUDIO_DRIVER = -189, + NvReflex_VALUE_ALREADY_SET = -190, + NvReflex_TIMEOUT = -191, + NvReflex_GPU_WORKSTATION_FEATURE_INCOMPLETE = -192, + NvReflex_STEREO_INIT_ACTIVATION_NOT_DONE = -193, + NvReflex_SYNC_NOT_ACTIVE = -194, + NvReflex_SYNC_MASTER_NOT_FOUND = -195, + NvReflex_INVALID_SYNC_TOPOLOGY = -196, + NvReflex_ECID_SIGN_ALGO_UNSUPPORTED = -197, + NvReflex_ECID_KEY_VERIFICATION_FAILED = -198, + NvReflex_FIRMWARE_OUT_OF_DATE = -199, + NvReflex_FIRMWARE_REVISION_NOT_SUPPORTED = -200, + NvReflex_LICENSE_CALLER_AUTHENTICATION_FAILED = -201, + NvReflex_D3D_DEVICE_NOT_REGISTERED = -202, + NvReflex_RESOURCE_NOT_ACQUIRED = -203, + NvReflex_TIMING_NOT_SUPPORTED = -204, + NvReflex_HDCP_ENCRYPTION_FAILED = -205, + NvReflex_PCLK_LIMITATION_FAILED = -206, + NvReflex_NO_CONNECTOR_FOUND = -207, + NvReflex_HDCP_DISABLED = -208, + NvReflex_API_IN_USE = -209, + NvReflex_NVIDIA_DISPLAY_NOT_FOUND = -210, + NvReflex_PRIV_SEC_VIOLATION = -211, + NvReflex_INCORRECT_VENDOR = -212, + NvReflex_DISPLAY_IN_USE = -213, + NvReflex_UNSUPPORTED_CONFIG_NON_HDCP_HMD = -214, + NvReflex_MAX_DISPLAY_LIMIT_REACHED = -215, + NvReflex_INVALID_DIRECT_MODE_DISPLAY = -216, + NvReflex_GPU_IN_DEBUG_MODE = -217, + NvReflex_D3D_CONTEXT_NOT_FOUND = -218, + NvReflex_STEREO_VERSION_MISMATCH = -219, + NvReflex_GPU_NOT_POWERED = -220, + NvReflex_ERROR_DRIVER_RELOAD_IN_PROGRESS = -221, + NvReflex_WAIT_FOR_HW_RESOURCE = -222, + NvReflex_REQUIRE_FURTHER_HDCP_ACTION = -223, + NvReflex_DISPLAY_MUX_TRANSITION_FAILED = -224, + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_FrameReport + { + public ulong frameID; + public ulong inputSampleTime; + public ulong simStartTime; + public ulong simEndTime; + public ulong renderSubmitStartTime; + public ulong renderSubmitEndTime; + public ulong presentStartTime; + public ulong presentEndTime; + public ulong driverStartTime; + public ulong driverEndTime; + public ulong osRenderQueueStartTime; + public ulong osRenderQueueEndTime; + public ulong gpuRenderStartTime; + public ulong gpuRenderEndTime; + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_LATENCY_RESULT_PARAMS + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public NvReflex_FrameReport[] frameReport; + } + + [StructLayout(LayoutKind.Sequential)] + public struct NvReflex_GET_SLEEP_STATUS_PARAMS + { + public byte bLowLatencyMode; + } + + public static void TriggerFlash() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + int flashEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.TRIGGER_FLASH); + SetLatencyMarker(flashEventID, (ulong)Time.frameCount); + } + } + + public static void PCLatencyPing() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + int pingEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.PC_LATENCY_PING); + SetLatencyMarker(pingEventID, (ulong)Time.frameCount); + } + } + + //Expects marker from NvReflex_Plugin_GetEventIDForEvent() + public static void SetLatencyMarker(int marker, ulong frameID) + { + NvReflex_Plugin_SetLatencyMarker(marker, frameID); + } + + public static NvReflex_Status IsReflexLowLatencySupported() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + bool success = false; + NvReflex_GET_SLEEP_STATUS_PARAMS sleepParams; + uint driverVersion = 0; + + bool res = NvReflex_Plugin_GetDriverVersion(out driverVersion) != 0; + + if ((res) || (driverVersion < 45500)) + { + return NvReflex_Status.NvReflex_ERROR; + } + + success = NvReflex_Plugin_GetSleepStatus(out sleepParams) != 0; + return success ? NvReflex_Status.NvReflex_OK : NvReflex_Status.NvReflex_ERROR; + } + return NvReflex_Status.NvReflex_API_NOT_INITIALIZED; + } + + public static NvReflex_Status IsAutomaticReflexAnalyzerSupported() + { + if (NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + uint driverVersion = 0; + + bool status = NvReflex_Plugin_GetDriverVersion(out driverVersion) != 0; + + return ((status) && (driverVersion >= 51179)) ? NvReflex_Status.NvReflex_OK : NvReflex_Status.NvReflex_ERROR; + } + return NvReflex_Status.NvReflex_API_NOT_INITIALIZED; + } + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_SetSleepMode(bool lowLatencyMode, uint minimumIntervalUs, bool lowLatencyBoost, bool markersOptimzation); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_Sleep(ulong frameID); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_SetLatencyMarker(int marker, ulong frameID); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetLatency(out NvReflex_LATENCY_RESULT_PARAMS markers); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetSleepStatus(out NvReflex_GET_SLEEP_STATUS_PARAMS sleepStatusParams); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetEventIDForEvent(int inEvent); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern IntPtr NvReflex_Plugin_GetRenderEventAndDataFunc(); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_HasReceivedRenderEvent(); + + [DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + public static extern int NvReflex_Plugin_GetDriverVersion(out uint ver); + } +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs.meta new file mode 100644 index 0000000..a8a4980 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineReflexCore.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1117f316f75cb3b45b0f6717da4ab36c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs new file mode 100644 index 0000000..46344ab --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs @@ -0,0 +1,81 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline Tester")] + public class StreamlineTester : MonoBehaviour + { + bool dlssg_enabled = false; + bool reflex_enabled = false; + + //uint mvecoffset = 0; + + Vector2[] mvectable = { + new Vector2(1.0f,1.0f), + new Vector2(-1.0f,1.0f), + new Vector2(1.0f,-1.0f), + new Vector2(-1.0f,-1.0f), + + new Vector2(3840.0f,2160.0f), + new Vector2(-3840.0f,2160.0f), + new Vector2(3840.0f,-2160.0f), + new Vector2(-3840.0f,-2160.0f), + + new Vector2(1.0f/3840.0f,1.0f/2160.0f), + new Vector2(-1.0f/3840.0f,1.0f/2160.0f), + new Vector2(1.0f/3840.0f,-1.0f/2160.0f), + new Vector2(-1.0f/3840.0f,-1.0f/2160.0f), + }; + + + // Start is called before the first frame update + void Start() + { + dlssg_enabled = StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureDLSS_G); + reflex_enabled = StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureReflex); + } + + // Update is called once per frame + void Update() + { + HandleInput(); + } + + private void HandleInput() + { + if (Input.GetKeyDown(KeyCode.Alpha1)) + { + StreamlineDLSSGCore.DLSSGEnabled = !StreamlineDLSSGCore.DLSSGEnabled; + } + + } + + private void OnGUI() + { + GUILayout.BeginArea(new Rect { x = 10, y = 80, width = 400, height = 320 }, "Streamline Controls", GUI.skin.window); + + GUILayout.Label(string.Format("DLSS-G is {0}", dlssg_enabled ? "supported" : "not supported")); + GUILayout.Label(string.Format("Reflex is {0}", reflex_enabled ? "supported" : "not supported")); + + if (GraphicsSettings.defaultRenderPipeline!=null) + { + GUILayout.Label(string.Format("Current renderpipeline = {0}", GraphicsSettings.defaultRenderPipeline.name)); + } + else + { + GUILayout.Label(string.Format("BuiltIn Pipeline")); + } + + GUILayout.Label(string.Format("[1] DLSSGEnabled is {0}", StreamlineDLSSGCore.DLSSGEnabled ? "True" : "False")); + GUILayout.Label(string.Format("frame is {0}", (uint)Time.frameCount)); + GUILayout.EndArea(); + } + } +} + diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs.meta new file mode 100644 index 0000000..479e886 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/StreamlineTester.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13bdb2384d9734f44a26c0c0e2d56f02 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef new file mode 100644 index 0000000..89547d6 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef @@ -0,0 +1,13 @@ +{ + "name": "com.nvidia.streamline.core.Runtime", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta new file mode 100644 index 0000000..f0b26e6 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.core.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2ad66e0615e74ce41bad44512e0dc450 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json new file mode 100644 index 0000000..164f700 --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json @@ -0,0 +1,16 @@ +{ + "name": "com.nvidia.streamline.core", + "description": "NVIDIA Streamline Core implementation package", + "version": "0.0.1-alpha1", + "unity": "2019.4", + "unityRelease": "1f1", + "displayName": "NVIDIA Streamline Core", + "dependencies": {}, + "keywords": [ + "graphics", + "performance", + "rendering", + "render", + "pipeline" + ] +} diff --git a/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json.meta b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json.meta new file mode 100644 index 0000000..7630c7e --- /dev/null +++ b/Packages/com.nvidia.streamline.core-0.0.1-alpha1/package/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 08c2d83d275eb5349802afcd291ec67d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md new file mode 100644 index 0000000..06bb7b4 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog +All notable changes to this package will be documented in this file. + +## [Unreleased] + diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md.meta new file mode 100644 index 0000000..f25587c --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f850f29f3bea48f458e1428f058c3ee0 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation.meta new file mode 100644 index 0000000..ddef559 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a85cd14244f4b3647900975104c8d8a0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md new file mode 100644 index 0000000..97b1d22 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md @@ -0,0 +1,20 @@ +# NVIDIA Streamline DLSS3 Frame Generation package + +## Supported versions of Unity + +- DX11/DX12 is supported on Unity version 2019.4.??? x86_64 builds. +- Vulkan is not currently supported. + +## Integrating into your Unity application + +- Apply Unity2019.4src.patch to Unity2019.4 source, build Editor and Standalone players. + +- Import com.nvidia.streamline.core package +- Import com.nvidia.streamline.dlssg and com.nvidia.streamline.reflex. Reflex is required by DLSS-G + +- Builtin project. + Add Streamline component (Streamline.cs) to Main Camera along with Streamline DLSSG Builtin (StreamlineDLSSG.cs) and Streamline Reflex Builtin (StreamlineReflex.cs) components. + +- HDRP project. + Apply HDRP 7.7.1 patch to a copy of com.unity.render-pipelines.high-definition@7.7.1 + Add Streamline component (StreamlineHDRP.cs) to Main Camera along with Streamline DLSSG HDRP (StreamlineDLSSGHDRP.cs) and Streamline Reflex Builtin/HDRP (StreamlineReflex.cs) components. \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md.meta new file mode 100644 index 0000000..be67ea0 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Documentation/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 93d48415677c00347a444ac3d67cef03 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md new file mode 100644 index 0000000..2e3dc69 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md @@ -0,0 +1,7 @@ +Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved. + +NVIDIA CORPORATION and its licensors retain all intellectual property +and proprietary rights in and to this software, related documentation +and any modifications thereto. Any use, reproduction, disclosure or +distribution of this software and related documentation without an express +license agreement from NVIDIA CORPORATION is strictly prohibited. diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md.meta new file mode 100644 index 0000000..360a14b --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8fc9675c6de914848bf7223df5932b6b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime.meta new file mode 100644 index 0000000..68c7e6a --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e9acb86b221bb974f80abbb98e9156eb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs new file mode 100644 index 0000000..cbc18aa --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs @@ -0,0 +1,247 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline DLSS-G Builtin")] + public class StreamlineDLSSG : MonoBehaviour + { + private CommandBuffer m_cmdCopyDepthAndMVecs; + private CommandBuffer m_cmdCopyHudlessColor; + private Camera m_camera; + private uint m_id; + public bool DLSSGFeatureAvailable { get; private set; } = false; + + +#if false + //Put 5x3Compute shader in test project and drag onto this in editor + public ComputeShader TESTcs5x3 = null; +#endif + private void AttachCamera() + { + m_camera.AddCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdCopyDepthAndMVecs); + m_camera.AddCommandBuffer(CameraEvent.AfterEverything, m_cmdCopyHudlessColor); + ClearCommandLists(); + } + + private void DetachCamera() + { + ClearCommandLists(); + m_camera.RemoveCommandBuffer(CameraEvent.BeforeImageEffectsOpaque, m_cmdCopyDepthAndMVecs); + m_camera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_cmdCopyHudlessColor); + } + + private void CreateCommandLists() + { + m_cmdCopyDepthAndMVecs = new CommandBuffer(); + m_cmdCopyDepthAndMVecs.name = "Streamline DLSSG CopyDepthMVecs"; + + //Command list still required for sending Null tag + m_cmdCopyHudlessColor = new CommandBuffer(); + m_cmdCopyHudlessColor.name = "Streamline DLSSG CopyHudlessColor"; + + } + + private void DestroyCommandLists() + { + + } + + void ClearCommandLists() + { + m_cmdCopyDepthAndMVecs.Clear(); + + m_cmdCopyHudlessColor.Clear(); + +#if !UNITY_EDITOR && UNITY_2019_1_OR_NEWER + // On DX12 up until 2020.2 command lists that are being generated do not get flushed. + // This causes incorrect ordering of plugin side command lists. + // i.e. After submitted lists but before currently being generated lists. + // We can force a flush in non-editor mode by creating a fence but never waiting for it. + // Editor mode does not support GPUFence. + GraphicsFence fence1 = m_cmdCopyDepthAndMVecs.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations); + GraphicsFence fence2 = m_cmdCopyHudlessColor.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations); +#endif + } + + + void SetupTextureBlits() + { + uint frameIndex = (uint)Time.frameCount; + if (StreamlineDLSSGCore.DLSSGEnabled) + { + // Using this scale and bias rather than the draw&view rects as they were only relevant for editor rendering and Unity2019.4 + // doesn't have the same Blit commands as 2021 (src and dest bias/scale) + Vector2 scale = new Vector2(1.0f, -1.0f); + Vector2 offset = new Vector2(0.0f, 1.0f); + + RenderTexture targetDepth = StreamlineDLSSGCore.GetTargetDepthTexture(); + RenderTexture targetMVecs = StreamlineDLSSGCore.GetTargetMVecsTexture(); + RenderTexture targetHudlessColor = StreamlineDLSSGCore.GetTargetHudlessColorTexture(); + + // Copy flipped textures + bool deferred = m_camera.actualRenderingPath == RenderingPath.DeferredShading; + RenderTargetIdentifier srcRtid = new RenderTargetIdentifier(deferred ? BuiltinRenderTextureType.ResolvedDepth : BuiltinRenderTextureType.Depth); + m_cmdCopyDepthAndMVecs.Blit(srcRtid, targetDepth.colorBuffer, scale, offset); + m_cmdCopyDepthAndMVecs.Blit(new RenderTargetIdentifier(BuiltinRenderTextureType.MotionVectors), targetMVecs, scale, offset); + + if (StreamlineDLSSGCore.UseHudlessColor) + { + m_cmdCopyHudlessColor.Blit(new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget), targetHudlessColor, scale, offset); + } +#if false + if (TESTcs5x3) + { + int kernel = TESTcs5x3.FindKernel("Font5x3Draw"); + + int w = (4 * 6 * 32); + int h = (5 * 32); + + Vector4 offsetsh = new Vector4(targetDepth.width / 3, targetDepth.height / 2, 0, 0); + + m_cmdCopyDepthAndMVecs.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputDTexture", targetDepth, 0, RenderTextureSubElement.Color); + m_cmdCopyDepthAndMVecs.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameIndex); + m_cmdCopyDepthAndMVecs.SetComputeIntParam(TESTcs5x3, "_Phase", 0); + m_cmdCopyDepthAndMVecs.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); + m_cmdCopyDepthAndMVecs.DispatchCompute(TESTcs5x3, kernel, w, h, 1); + + m_cmdCopyDepthAndMVecs.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputMTexture", targetMVecs, 0, RenderTextureSubElement.Color); + m_cmdCopyDepthAndMVecs.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameIndex); + m_cmdCopyDepthAndMVecs.SetComputeIntParam(TESTcs5x3, "_Phase", 1); + m_cmdCopyDepthAndMVecs.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); + m_cmdCopyDepthAndMVecs.DispatchCompute(TESTcs5x3, kernel, w, h, 1); + + if (StreamlineDLSSGCore.UseHudlessColor) + { + m_cmdCopyHudlessColor.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputHTexture", targetHudlessColor, 0, RenderTextureSubElement.Color); + m_cmdCopyHudlessColor.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameIndex); + m_cmdCopyHudlessColor.SetComputeIntParam(TESTcs5x3, "_Phase", 2); + m_cmdCopyHudlessColor.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); + m_cmdCopyHudlessColor.DispatchCompute(TESTcs5x3, kernel, w, h, 1); + } + + } +#endif + + } + } + + public void SetupDepthAndMVecTextureTags(CommandBuffer cmd) + { + uint frameIndex = (uint)Time.frameCount; + if (StreamlineDLSSGCore.DLSSGEnabled) + { + RenderTexture targetDepth = StreamlineDLSSGCore.GetTargetDepthTexture(); + RenderTexture targetMVecs = StreamlineDLSSGCore.GetTargetMVecsTexture(); + + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetDepth, StreamlineCore.BufferType.eBufferTypeDepth, 0); + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetMVecs, StreamlineCore.BufferType.eBufferTypeMVec, 0); + } + else + { + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeDepth, 0); + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeMVec, 0); + } + } + + + + public void SetupHudlessColorTextureTags(CommandBuffer cmd) + { + uint frameIndex = (uint)Time.frameCount; + if (StreamlineDLSSGCore.DLSSGEnabled && StreamlineDLSSGCore.UseHudlessColor) + { + RenderTexture targetHudlessColor = StreamlineDLSSGCore.GetTargetHudlessColorTexture(); + + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetHudlessColor, StreamlineCore.BufferType.eBufferTypeHUDLessColor, 0); + //StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeHUDLessColor, 0); + } + else + { + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeHUDLessColor, 0); + } + } + + + void Awake() + { + DLSSGFeatureAvailable = false; + + if (!StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureDLSS_G)) + { + Debug.Log("DLSSG is not supported"); + return; + } + + int id = StreamlineCore.CreateFeature(StreamlineCore.Feature.eFeatureDLSS_G); + if (id != 0) //CreateFeature must return 0 for DLSSG + { + Debug.LogError("DLSSG Awake FAILED to get feature id"); + return; + } + + m_id = (uint)id; + DLSSGFeatureAvailable = true; + m_camera = GetComponent(); + m_camera.depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors; + CreateCommandLists(); + } + + void OnDestroy() + { + if (DLSSGFeatureAvailable && m_id == 0) + { + StreamlineCore.DestroyFeature((int)m_id); + } + } + + void OnEnable() + { + if (DLSSGFeatureAvailable) + { + AttachCamera(); + } + } + + void OnDisable() + { + if (DLSSGFeatureAvailable) + { + DetachCamera(); + } + } + + // Update is called once per frame + void LateUpdate() + { + if (DLSSGFeatureAvailable) + { + StreamlineDLSSGCore.ProcessDisposals(); + + if (StreamlineDLSSGCore.UpdateDrawRects(m_camera)) + { + //reallocate tagged textures + StreamlineDLSSGCore.TaggedTextureDimensions tdd = StreamlineDLSSGCore.GetTaggedTextureDimensionsRef(); + + StreamlineDLSSGCore.AllocateTextures(tdd.m_currentDrawRect, tdd.m_currentViewRect, false, tdd.m_desktopScale, StreamlineDLSSGCore.UseHudlessColor); + } + + if (GraphicsSettings.defaultRenderPipeline == null) //Built in only + { + ClearCommandLists(); + SetupTextureBlits(); + SetupDepthAndMVecTextureTags(m_cmdCopyDepthAndMVecs); + SetupHudlessColorTextureTags(m_cmdCopyHudlessColor); + + StreamlineDLSSGCore.SetupDLSSGFeatureConstants(m_cmdCopyDepthAndMVecs, m_camera, m_id, (uint)Time.frameCount); + } + } + } + } +} diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs.meta new file mode 100644 index 0000000..2959a39 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSG.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a900f711d0eea1e44ba8fc5e6288b726 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs new file mode 100644 index 0000000..e9db2b1 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs @@ -0,0 +1,121 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Rendering; + +using NVStreamline; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline DLSS-G HDRP")] + public class StreamlineDLSSGHDRP : MonoBehaviour + { + private Camera m_camera; + private uint m_id; + public bool DLSSGFeatureAvailable { get; private set; } = false; + +#if false + //Put 5x3Compute shader in test project and drag onto this in editor + public ComputeShader TESTcs5x3 = null; + + public ComputeShader GetFont5x3Shader() + { + return TESTcs5x3; + } +#endif + + public void SetupDepthAndMVecTextureTags(CommandBuffer cmd, int frameCount) + { + uint frameIndex = (uint)frameCount; + if (StreamlineDLSSGCore.DLSSGEnabled) + { + RenderTexture targetDepth = StreamlineDLSSGCore.GetTargetDepthTexture(); + RenderTexture targetMVecs = StreamlineDLSSGCore.GetTargetMVecsTexture(); + + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetDepth, StreamlineCore.BufferType.eBufferTypeDepth, 0); + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetMVecs, StreamlineCore.BufferType.eBufferTypeMVec, 0); + } + else + { + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeDepth, 0); + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeMVec, 0); + } + } + + public void SetupHudlessColorTextureTags(CommandBuffer cmd, int frameCount) + { + uint frameIndex = (uint)frameCount; + if (StreamlineDLSSGCore.DLSSGEnabled && StreamlineDLSSGCore.UseHudlessColor) + { + RenderTexture targetHudlessColor = StreamlineDLSSGCore.GetTargetHudlessColorTexture(); + StreamlineCore.SetTag(cmd, frameIndex, m_id, targetHudlessColor, StreamlineCore.BufferType.eBufferTypeHUDLessColor, 0); + } + else + { + StreamlineCore.SetTag(cmd, frameIndex, m_id, null, StreamlineCore.BufferType.eBufferTypeHUDLessColor, 0); + } + } + + public void HDRPSetupDLSSGFeatureConstants(CommandBuffer cmdBuffer, Camera camera, int frameCount) + { + StreamlineDLSSGCore.SetupDLSSGFeatureConstants(cmdBuffer, camera, m_id, (uint)frameCount); + } + + void Awake() + { + m_camera = GetComponent(); + DLSSGFeatureAvailable = false; + + if (!StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureDLSS_G)) + { + Debug.Log("DLSSG is not supported"); + return; + } + + int id = StreamlineCore.CreateFeature(StreamlineCore.Feature.eFeatureDLSS_G); + if (id != 0) //CreateFeature must return 0 for DLSSG + { + Debug.LogError("DLSSG Awake FAILED to get feature id"); + return; + } + + m_id = (uint)id; + DLSSGFeatureAvailable = true; + } + + void OnDestroy() + { + if (DLSSGFeatureAvailable && m_id == 0) + { + StreamlineCore.DestroyFeature((int)m_id); + } + } + + void OnEnable() + { + } + + void OnDisable() + { + } + + // Update is called once per frame + void LateUpdate() + { + if (DLSSGFeatureAvailable) + { + StreamlineDLSSGCore.ProcessDisposals(); + + if (StreamlineDLSSGCore.UpdateDrawRects(m_camera)) + { + //reallocate tagged textures + StreamlineDLSSGCore.TaggedTextureDimensions tdd = StreamlineDLSSGCore.GetTaggedTextureDimensionsRef(); + + StreamlineDLSSGCore.AllocateTextures(tdd.m_currentDrawRect, tdd.m_currentViewRect, false, tdd.m_desktopScale, true); + } + } + } + } +} diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs.meta new file mode 100644 index 0000000..3756fe3 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/StreamlineDLSSGHDRP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7f43cd7ced34da44a291edb15cbc13c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef new file mode 100644 index 0000000..38d92f9 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef @@ -0,0 +1,15 @@ +{ + "name": "com.nvidia.streamline.dlssg.Runtime", + "references": [ + "com.nvidia.streamline.core.Runtime" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef.meta new file mode 100644 index 0000000..33fa555 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/Runtime/com.nvidia.streamline.dlssg.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6a4210699ac0ab844b9dac2e66ee9813 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json new file mode 100644 index 0000000..d6d8def --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json @@ -0,0 +1,18 @@ +{ + "name": "com.nvidia.streamline.dlssg", + "description": "NVIDIA Streamline DLSS-G implementation package", + "version": "0.0.1-alpha1", + "unity": "2019.4", + "unityRelease": "1f1", + "displayName": "NVIDIA Streamline DLSS-G", + "dependencies": { + "com.nvidia.streamline.core": "0.0.1-alpha1" + }, + "keywords": [ + "graphics", + "performance", + "rendering", + "render", + "pipeline" + ] +} diff --git a/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json.meta b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json.meta new file mode 100644 index 0000000..a36f394 --- /dev/null +++ b/Packages/com.nvidia.streamline.dlssg-0.0.1-alpha1/package/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: da91c11f20128c04b9025df7aa857001 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md new file mode 100644 index 0000000..06bb7b4 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog +All notable changes to this package will be documented in this file. + +## [Unreleased] + diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md.meta new file mode 100644 index 0000000..2d498d9 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 50af5c86cbca54047b05de8426a2724e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation.meta new file mode 100644 index 0000000..02ddbc7 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2787ea1707a6626429908ca662609a00 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md new file mode 100644 index 0000000..17c5162 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md @@ -0,0 +1,22 @@ +# NVIDIA Streamline Reflex package + +## Supported versions of Unity + +- DX11/DX12 is supported on Unity version 2019.4.??? x86_64 builds. +- Vulkan is not currently supported. + +## Integrating into your Unity application +- Apply Unity2019.4src.patch to Unity2019.4 source, build Editor and Standalone players. + +- Import com.nvidia.streamline.core package +- Import com.nvidia.streamline.reflex. + +- Builtin or HDRP project. Add Streamline component (Streamline.cs) to Main Camera along with the Streamline Reflex Builtin/HDRP (StreamlineReflex.cs) component. + +## Unity configuration changes needed for Reflex +- In Project Settings, Player ensure that 'Active Input Handling' is set to 'Both' +- In Project Settings, Input ensure that 'Use Physical Keys' is unchecked. + +## Debugging and Verifying Reflex. +- See https://github.com/NVIDIAGameWorks/Streamline/blob/main/docs/ProgrammingGuideReflex.md#80-nvidia-reflex-qa-checklist +- Ensure NVIDIA Performance Overlay is active (Alt-R) \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md.meta new file mode 100644 index 0000000..906eee7 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Documentation/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9b1f89caa058819449f156842d7210a6 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md new file mode 100644 index 0000000..2e3dc69 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md @@ -0,0 +1,7 @@ +Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved. + +NVIDIA CORPORATION and its licensors retain all intellectual property +and proprietary rights in and to this software, related documentation +and any modifications thereto. Any use, reproduction, disclosure or +distribution of this software and related documentation without an express +license agreement from NVIDIA CORPORATION is strictly prohibited. diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md.meta new file mode 100644 index 0000000..4c8a665 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0a42086d349723d4bb2345cd9218c801 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime.meta new file mode 100644 index 0000000..3070207 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: badfd54375974604a830e463ebc802c6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs new file mode 100644 index 0000000..91a608b --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ +using System; +using System.Collections; +using System.Runtime.InteropServices; +using UnityEngine; +using UnityEngine.Rendering; +using NVStreamline; + +namespace NVStreamline +{ + [AddComponentMenu("NVIDIA/Streamline Reflex Builtin & HDRP")] + public class StreamlineReflex : MonoBehaviour + { + [Tooltip("Is this the first camera to be rendered")] + public bool isFirstCamera = true; + private bool isAttachedBeforeRender = false; + [Tooltip("Is this the last camera to be rendered")] + public bool isLastCamera = true; + private bool isAttachedAfterRender = false; + [Tooltip("Minimum interval in microseconds for frame synchronization. 0 = no frame rate limit")] + public uint intervalUs = 0; + [Tooltip("NVIDIA Reflex Low Latency mode.")] + public bool isLowLatencyMode = true; + [Tooltip("NVIDIA Reflex Low Latency Boost")] + public bool isLowLatencyBoost = false; + [Tooltip("NVIDIA Reflex Low Latency Boost")] + public bool useMarkersToOptimize = false; + private static uint previousIntervalUs = 0; + private static bool previousIsLowLatencyMode = false; + private static bool previousIsLowLatencyBoost = true; + private static bool previousUseMarkersToOptimize = false; + private bool hasSimulationStarted = false; + private CommandBuffer renderSubmitStart_CommandBuffer; + private CommandBuffer renderSubmitEnd_CommandBuffer; + public bool isIgnored = false; // Used by DLSS plugin for downsampled camera. + + private uint m_id; + private bool m_reflexEnabled = false; + + private IEnumerator SleepCoroutine() + { + while (true) + { + yield return (new WaitForEndOfFrame()); + + if (StreamlineReflexCore.NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + if (isLastCamera) + { + if ((previousIsLowLatencyMode != isLowLatencyMode) || (previousIntervalUs != intervalUs) || (previousIsLowLatencyBoost != isLowLatencyBoost) || (previousUseMarkersToOptimize != useMarkersToOptimize)) + { + StreamlineReflexCore.NvReflex_Plugin_SetSleepMode(isLowLatencyMode, intervalUs, isLowLatencyBoost, useMarkersToOptimize); + previousIsLowLatencyMode = isLowLatencyMode; + previousIsLowLatencyBoost = isLowLatencyBoost; + previousIntervalUs = intervalUs; + previousUseMarkersToOptimize = useMarkersToOptimize; + } + if (isLowLatencyMode) + { + GL.Flush(); + StreamlineReflexCore.NvReflex_Plugin_Sleep((ulong)Time.frameCount); + } + } + } + } + } + + private void Awake() + { + if (!StreamlineCore.IsFeatureSupported(StreamlineCore.Feature.eFeatureReflex)) + { + Debug.Log("Reflex is not supported"); + return; + } + + int id = StreamlineCore.CreateFeature(StreamlineCore.Feature.eFeatureReflex); + if (id != 1) //CreateFeature must return 1 for Reflex + { + Debug.Log("Reflex Awake FAILED to get feature id"); + m_reflexEnabled = false; + return; + } + m_id = (uint)id; + m_reflexEnabled = true; + + renderSubmitStart_CommandBuffer = new CommandBuffer(); + renderSubmitStart_CommandBuffer.name = "Reflex RENDERSUBMIT_START"; + renderSubmitEnd_CommandBuffer = new CommandBuffer(); + renderSubmitEnd_CommandBuffer.name = "Reflex RENDERSUBMIT_END"; + } + + void OnDestroy() + { + StreamlineCore.DestroyFeature((int)m_id); + } + + private void OnBeginFrameRendering(ScriptableRenderContext context, Camera[] camera) + { + context.ExecuteCommandBuffer(renderSubmitStart_CommandBuffer); + } + + private void OnEndFrameRendering(ScriptableRenderContext context, Camera[] camera) + { + context.ExecuteCommandBuffer(renderSubmitEnd_CommandBuffer); + context.Submit(); + + } + + private void AfterPresent() + { + if (hasSimulationStarted == false) + { + int simStartEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.SIMULATION_START); + StreamlineReflexCore.SetLatencyMarker(simStartEventID, (ulong)Time.frameCount); + + hasSimulationStarted = true; + } + } + + public void FixedUpdate() + { + if (m_reflexEnabled) + { + if (isFirstCamera && + !isIgnored && + StreamlineReflexCore.NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + AfterPresent(); + } + } + } + + public void Update() + { + if (m_reflexEnabled) + { + if (isFirstCamera && + !isIgnored && + StreamlineReflexCore.NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + + AfterPresent(); + int inputSampleEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.INPUT_SAMPLE); + StreamlineReflexCore.SetLatencyMarker(inputSampleEventID, (ulong)Time.frameCount); + + if (Input.GetKeyUp(KeyCode.F13)) + { + StreamlineReflexCore.PCLatencyPing(); + } + if (Input.GetMouseButtonDown(0)) + { + StreamlineReflexCore.TriggerFlash(); + } + } + } + } + + private void AttachDetachCommandBuffers() + { + if ((renderSubmitStart_CommandBuffer != null) & (renderSubmitEnd_CommandBuffer != null)) + { + Camera camComponent = this.GetComponent(); + bool shouldFirstCameraBeAttached = (isFirstCamera & !isIgnored & enabled); + bool shouldLastCameraBeAttached = (isLastCamera & /*!isIgnored &*/ enabled); + + if (shouldFirstCameraBeAttached != isAttachedBeforeRender) + { + if (shouldFirstCameraBeAttached) + { + // Send renderSubmitStart_CommandBuffer on BeforeDepthTexture, BeforeForwardOpaque and BeforeGBuffer events. This ensures whatever configuration the Legacy pipeline is using + // with regard to 2D/3D and Deferred/Rendering the event will be sent. The plugin filters the SubmitStart event and only processes the first that occurs. + var oldBDCmdBuffers = camComponent.GetCommandBuffers(CameraEvent.BeforeDepthTexture); + var oldBOCmdBuffers = camComponent.GetCommandBuffers(CameraEvent.BeforeForwardOpaque); + var oldBDGmdBuffers = camComponent.GetCommandBuffers(CameraEvent.BeforeGBuffer); + camComponent.RemoveCommandBuffers(CameraEvent.BeforeDepthTexture); + camComponent.RemoveCommandBuffers(CameraEvent.BeforeForwardOpaque); + camComponent.RemoveCommandBuffers(CameraEvent.BeforeGBuffer); + camComponent.AddCommandBuffer(CameraEvent.BeforeDepthTexture, renderSubmitStart_CommandBuffer); + camComponent.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, renderSubmitStart_CommandBuffer); + camComponent.AddCommandBuffer(CameraEvent.BeforeGBuffer, renderSubmitStart_CommandBuffer); + foreach (var cmdBuff in oldBDCmdBuffers) + { + camComponent.AddCommandBuffer(CameraEvent.BeforeDepthTexture, cmdBuff); + } + foreach (var cmdBuff in oldBOCmdBuffers) + { + camComponent.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cmdBuff); + } + foreach (var cmdBuff in oldBDGmdBuffers) + { + camComponent.AddCommandBuffer(CameraEvent.BeforeGBuffer, cmdBuff); + } +#if UNITY_2019_1_OR_NEWER + RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering; +#endif + } + else + { + camComponent.RemoveCommandBuffer(CameraEvent.BeforeDepthTexture, renderSubmitStart_CommandBuffer); + camComponent.RemoveCommandBuffer(CameraEvent.BeforeForwardOpaque, renderSubmitStart_CommandBuffer); + camComponent.RemoveCommandBuffer(CameraEvent.BeforeGBuffer, renderSubmitStart_CommandBuffer); +#if UNITY_2019_1_OR_NEWER + RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering; +#endif + } + isAttachedBeforeRender = shouldFirstCameraBeAttached; + } + + if (shouldLastCameraBeAttached != isAttachedAfterRender) + { + if (shouldLastCameraBeAttached) + { + camComponent.AddCommandBuffer(CameraEvent.AfterEverything, renderSubmitEnd_CommandBuffer); +#if UNITY_2019_1_OR_NEWER + RenderPipelineManager.endFrameRendering += OnEndFrameRendering; +#endif + } + else + { + camComponent.RemoveCommandBuffer(CameraEvent.AfterEverything, renderSubmitEnd_CommandBuffer); +#if UNITY_2019_1_OR_NEWER + RenderPipelineManager.endFrameRendering -= OnEndFrameRendering; +#endif + } + isAttachedAfterRender = shouldLastCameraBeAttached; + } + } + } + + void OnEnable() + { + if (m_reflexEnabled) + { + AttachDetachCommandBuffers(); + StartCoroutine(SleepCoroutine()); + } + } + + void OnDisable() + { + if (m_reflexEnabled) + { + AttachDetachCommandBuffers(); + StopCoroutine(SleepCoroutine()); + } + } + + + private void LateUpdate() + { + if (m_reflexEnabled) + { + AttachDetachCommandBuffers(); + + if (isFirstCamera & !isIgnored) + { + if (hasSimulationStarted && + StreamlineReflexCore.NvReflex_Plugin_HasReceivedRenderEvent() != 0) + { + int simEndEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.SIMULATION_END); + StreamlineReflexCore.SetLatencyMarker(simEndEventID, (ulong)Time.frameCount); + hasSimulationStarted = false; + } + int startEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.RENDERSUBMIT_START); + renderSubmitStart_CommandBuffer.Clear(); + renderSubmitStart_CommandBuffer.IssuePluginEventAndData(StreamlineReflexCore.NvReflex_Plugin_GetRenderEventAndDataFunc(), startEventID, (IntPtr)(ulong)Time.frameCount); + } + if (isLastCamera /*& !isIgnored*/) + { + int endEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.RENDERSUBMIT_END); + renderSubmitEnd_CommandBuffer.Clear(); + renderSubmitEnd_CommandBuffer.IssuePluginEventAndData(StreamlineReflexCore.NvReflex_Plugin_GetRenderEventAndDataFunc(), endEventID, (IntPtr)(ulong)Time.frameCount); + + endEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.PRESENT_START); + renderSubmitEnd_CommandBuffer.IssuePluginEventAndData(StreamlineReflexCore.NvReflex_Plugin_GetRenderEventAndDataFunc(), endEventID, (IntPtr)(ulong)Time.frameCount); + + endEventID = StreamlineReflexCore.NvReflex_Plugin_GetEventIDForEvent((int)StreamlineReflexCore.NvReflex_LATENCY_MARKER_TYPE.PRESENT_END); + renderSubmitEnd_CommandBuffer.IssuePluginEventAndData(StreamlineReflexCore.NvReflex_Plugin_GetRenderEventAndDataFunc(), endEventID, (IntPtr)(ulong)Time.frameCount); + } + } + } + + } +} diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs.meta new file mode 100644 index 0000000..455d7da --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/StreamlineReflex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a262e9e5c501afc418ab22fb9d074317 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef new file mode 100644 index 0000000..66cce63 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef @@ -0,0 +1,15 @@ +{ + "name": "com.nvidia.streamline.reflex.Runtime", + "references": [ + "com.nvidia.streamline.core.Runtime" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef.meta new file mode 100644 index 0000000..445b58a --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/Runtime/com.nvidia.streamline.reflex.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3790c245dfbf991469ecd1fa2a3a316b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json new file mode 100644 index 0000000..4e957fb --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json @@ -0,0 +1,18 @@ +{ + "name": "com.nvidia.streamline.reflex", + "description": "NVIDIA Streamline Reflex implementation package", + "version": "1.8.0-alpha.1", + "unity": "2019.4", + "unityRelease": "1f1", + "displayName": "NVIDIA Streamline Reflex", + "dependencies": { + "com.nvidia.streamline.core": "0.0.1-alpha1" + }, + "keywords": [ + "graphics", + "performance", + "rendering", + "render", + "pipeline" + ] +} diff --git a/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json.meta b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json.meta new file mode 100644 index 0000000..12712d7 --- /dev/null +++ b/Packages/com.nvidia.streamline.reflex-1.8.0-alpha.1/package/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1fa871856738f7d4dbbac185f0c0375a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.render-pipelines.high-definition@14.0.7.patch b/Packages/com.unity.render-pipelines.high-definition@14.0.7.patch new file mode 100644 index 0000000..667bdeb --- /dev/null +++ b/Packages/com.unity.render-pipelines.high-definition@14.0.7.patch @@ -0,0 +1,296 @@ +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Editor/Unity.RenderPipelines.HighDefinition.Editor.asmdef b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Editor/Unity.RenderPipelines.HighDefinition.Editor.asmdef +index c7bbde5..d1c99c9 100644 +--- a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Editor/Unity.RenderPipelines.HighDefinition.Editor.asmdef ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Editor/Unity.RenderPipelines.HighDefinition.Editor.asmdef +@@ -10,7 +10,10 @@ + "Unity.VisualEffectGraph.Editor", + "Unity.PackageManagerDocTools.Editor", + "Unity.Rendering.Denoising.Runtime", +- "Unity.RenderPipelines.HighDefinition.Config.Runtime" ++ "Unity.RenderPipelines.HighDefinition.Config.Runtime", ++ "com.nvidia.streamline.core.Runtime", ++ "com.nvidia.streamline.dlssg.Runtime", ++ "com.nvidia.streamline.reflex.Runtime" + ], + "includePlatforms": [ + "Editor" +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDProfileId.cs b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDProfileId.cs +index f48b1f5..b35411c 100644 +--- a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDProfileId.cs ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDProfileId.cs +@@ -262,5 +262,7 @@ namespace UnityEngine.Rendering.HighDefinition + #if ENABLE_VIRTUALTEXTURES + VTFeedbackDownsample, + #endif ++ StreamlineCopyDepthMVecs, ++ StreamlineCopyHudlessColor, + } + } +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +index 8ef49b2..6623760 100644 +--- a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +@@ -100,6 +100,10 @@ namespace UnityEngine.Rendering.HighDefinition + + var prepassOutput = RenderPrepass(m_RenderGraph, colorBuffer, lightingBuffers.sssBuffer, vtFeedbackBuffer, cullingResults, customPassCullingResults, hdCamera, aovRequest, aovBuffers); + ++ //NVIDIA Streamline ++ DLSSGStage1(m_RenderGraph, hdCamera, in prepassOutput); ++ //NVIDIA Streamline ++ + // Need this during debug render at the end outside of the main loop scope. + // Once render graph move is implemented, we can probably remove the branch and this. + ShadowResult shadowResult = new ShadowResult(); +@@ -358,6 +362,10 @@ namespace UnityEngine.Rendering.HighDefinition + + SetFinalTarget(m_RenderGraph, hdCamera, prepassOutput.resolvedDepthBuffer, backBuffer, target.face); + ++ //NVIDIA Streamline ++ DLSSGStage2(m_RenderGraph, hdCamera); ++ //NVIDIA Streamline ++ + RenderWireOverlay(m_RenderGraph, hdCamera, backBuffer); + + RenderGizmos(m_RenderGraph, hdCamera, GizmoSubset.PostImageEffects); +@@ -2067,5 +2075,60 @@ namespace UnityEngine.Rendering.HighDefinition + cb._OffScreenRendering = enabled ? 1u : 0u; + cb._OffScreenDownsampleFactor = factor; + } ++ ++ //NVIDIA streamline ++ class DLSSGStage1PassData ++ { ++ public HDCamera hdCamera; ++ public TextureHandle depthBuffer; ++ public TextureHandle mvecsBuffer; ++ public int frameCount; ++ } ++ ++ void DLSSGStage1(RenderGraph renderGraph, HDCamera hdCamera, in PrepassOutput prepassOutput) ++ { ++ ++ using (var builder = renderGraph.AddRenderPass("Copy DLSSG Depth/MVecs Textures", out var passData, ProfilingSampler.Get(HDProfileId.StreamlineCopyDepthMVecs))) ++ { ++ passData.hdCamera = hdCamera; ++ // Resolved buffers for MSAA. When MSAA is off, they will be the same reference as the buffers above. ++ passData.depthBuffer = builder.ReadTexture(prepassOutput.resolvedDepthBuffer); ++ passData.mvecsBuffer = builder.ReadTexture(prepassOutput.resolvedMotionVectorsBuffer); ++ passData.frameCount = Time.frameCount; ++ ++ builder.SetRenderFunc( ++ (DLSSGStage1PassData data, RenderGraphContext ctx) => ++ { ++ HDStreamline.DLSSGTagDepthAndMVecs(ctx.cmd, data.hdCamera, data.depthBuffer, data.mvecsBuffer, data.frameCount); //does blits and sets constants ++ HDStreamline.StreamlineSetConstants(ctx.cmd, data.hdCamera,data.frameCount); ++ ++ }); ++ } ++ ++ } ++ ++ class DLSSGStage2PassData ++ { ++ public HDCamera hdCamera; ++ public int frameCount; ++ } ++ ++ void DLSSGStage2(RenderGraph renderGraph, HDCamera hdCamera) ++ { ++ using (var builder = renderGraph.AddRenderPass("Copy DLSSG Hudless Textures", out var passData, ProfilingSampler.Get(HDProfileId.StreamlineCopyHudlessColor))) ++ { ++ passData.hdCamera = hdCamera; ++ passData.frameCount = Time.frameCount; ++ ++ builder.SetRenderFunc( ++ (DLSSGStage2PassData data, RenderGraphContext ctx) => ++ { ++ var colorBuffer = data.hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain); ++ HDStreamline.DLSSTagHudlessColor(ctx.cmd, data.hdCamera, colorBuffer, data.frameCount); ++ }); ++ } ++ ++ } ++ //NVIDIA streamline + } + } +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs +new file mode 100644 +index 0000000..f8a3fed +--- /dev/null ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs +@@ -0,0 +1,141 @@ ++using System; ++using System.Collections.Generic; ++using System.Runtime.CompilerServices; ++using UnityEngine.Assertions; ++using UnityEngine.Experimental.Rendering; ++using UnityEngine.Experimental.Rendering.RenderGraphModule; ++ ++using NVStreamline; ++ ++namespace UnityEngine.Rendering.HighDefinition ++{ ++ class HDStreamline ++ { ++ public static void StreamlineSetConstants(CommandBuffer cmdBuffer, HDCamera hdCamera, int frameCount) ++ { ++ StreamlineHDRP streamline = hdCamera.camera.GetComponent(); ++ ++ if (streamline) ++ { ++ if (streamline.StreamlineFeatureAvailable) ++ { ++ bool requiresJitter = false; // hdCamera.hdCamera.RequiresCameraJitter(); //doesnt seem to exist in this version of hdrp... ++ bool isFirstFrame = false; // hdCamera.isFirstFrame; ++ ++ Vector4 jitter = Vector4.zero; ++ if (hdCamera.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing) ++ { ++ jitter = hdCamera.taaJitter; ++ requiresJitter = true; ++ } ++ // ++ //Pass camera, not HDCamera. ++ streamline.HDRPSetStreamlineConstants(cmdBuffer, hdCamera.camera, requiresJitter, jitter, isFirstFrame, frameCount); ++ } ++ } ++ } ++ ++ public static void DLSSGTagDepthAndMVecs(CommandBuffer cmdBuffer, HDCamera hdCamera, RTHandle depthRTH, RTHandle mvecsRTH, int frameCount) ++ { ++ StreamlineDLSSGHDRP dlssg = hdCamera.camera.GetComponent(); ++ ++ if (dlssg) ++ { ++ if (dlssg.DLSSGFeatureAvailable) ++ { ++ if (StreamlineDLSSGCore.DLSSGEnabled) ++ { ++ ++ ++ RenderTexture depthTarget = StreamlineDLSSGCore.GetTargetDepthTexture(); ++ RenderTexture mvecsTarget = StreamlineDLSSGCore.GetTargetMVecsTexture(); ++ ++ StreamlineDLSSGCore.HDRPRequestScaleBiasValues(out Vector4 srcScaleBias, out Vector4 dstScaleBias); ++ ++ CoreUtils.SetRenderTarget(cmdBuffer, mvecsTarget); ++ HDUtils.BlitQuad(cmdBuffer, mvecsRTH, srcScaleBias, dstScaleBias, 0, true); ++ ++ CoreUtils.SetRenderTarget(cmdBuffer, depthTarget); ++ HDUtils.BlitQuad(cmdBuffer, depthRTH, srcScaleBias, dstScaleBias, 0, false); ++ ++#if false //debug5x3 ++ ComputeShader TESTcs5x3 = dlssg.GetFont5x3Shader(); ++ if (TESTcs5x3 != null) ++ { ++ int kernel = TESTcs5x3.FindKernel("Font5x3Draw"); ++ ++ int w = (4 * 6 * 32); ++ int h = (5 * 32); ++ ++ Vector4 offsetsh = new Vector4(depthTarget.width / 3, depthTarget.height / 2, 0, 0); ++ ++ RenderTexture ffs = depthRTH; ++ ++ cmdBuffer.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputDTexture", depthTarget, 0, RenderTextureSubElement.Color); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameCount); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_Phase", 0); ++ cmdBuffer.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); ++ cmdBuffer.DispatchCompute(TESTcs5x3, kernel, w, h, 1); ++ ++ cmdBuffer.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputMTexture", mvecsTarget, 0, RenderTextureSubElement.Color); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameCount); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_Phase", 1); ++ cmdBuffer.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); ++ cmdBuffer.DispatchCompute(TESTcs5x3, kernel, w, h, 1); ++ } ++#endif ++ } ++ ++ // Don't check for whether DLSSG is enabled or disabled as we always send On/Off and Tags/nullTags ++ dlssg.SetupDepthAndMVecTextureTags(cmdBuffer,frameCount); ++ dlssg.HDRPSetupDLSSGFeatureConstants(cmdBuffer, hdCamera.camera,frameCount); ++ } ++ } ++ ++ } ++ ++ public static void DLSSTagHudlessColor(CommandBuffer cmdBuffer, HDCamera hdCamera, RTHandle hudlessColorRTH, int frameCount) ++ { ++ StreamlineDLSSGHDRP dlssg = hdCamera.camera.GetComponent(); ++ ++ if (dlssg) ++ { ++ if (dlssg.DLSSGFeatureAvailable) ++ { ++ if (StreamlineDLSSGCore.DLSSGEnabled) ++ { ++ StreamlineDLSSGCore.HDRPRequestScaleBiasValues(out Vector4 srcScaleBias, out Vector4 dstScaleBias); ++ ++ RenderTexture hudlessColorTarget = StreamlineDLSSGCore.GetTargetHudlessColorTexture(); ++ ++ CoreUtils.SetRenderTarget(cmdBuffer, hudlessColorTarget); ++ HDUtils.BlitQuad(cmdBuffer, hudlessColorRTH, srcScaleBias, dstScaleBias, 0, true); ++ ++#if false //debug5x3 ++ ComputeShader TESTcs5x3 = dlssg.GetFont5x3Shader(); ++ if (TESTcs5x3 != null) ++ { ++ int kernel = TESTcs5x3.FindKernel("Font5x3Draw"); ++ ++ int w = (4 * 6 * 32); ++ int h = (5 * 32); ++ ++ Vector4 offsetsh = new Vector4(hudlessColorTarget.width / 3, hudlessColorTarget.height / 2, 0, 0); ++ ++ cmdBuffer.SetComputeTextureParam(TESTcs5x3, kernel, "_OutputHTexture", hudlessColorTarget, 0, RenderTextureSubElement.Color); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_InputValue", (int)frameCount); ++ cmdBuffer.SetComputeIntParam(TESTcs5x3, "_Phase", 2); ++ cmdBuffer.SetComputeVectorParam(TESTcs5x3, "_Offset", offsetsh); ++ cmdBuffer.DispatchCompute(TESTcs5x3, kernel, w, h, 1); ++ } ++#endif ++ } ++ // Don't check for whether DLSSG is enabled or disabled as we always send Tags/nullTags ++ dlssg.SetupHudlessColorTextureTags(cmdBuffer, frameCount); ++ } ++ } ++ } ++ ++ } ++ ++} +\ No newline at end of file +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs.meta b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs.meta +new file mode 100644 +index 0000000..1b306b3 +--- /dev/null ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/RenderPipeline/HDStreamline.cs.meta +@@ -0,0 +1,11 @@ ++fileFormatVersion: 2 ++guid: 6a74b4e669d466d4d9866791d0be6269 ++MonoImporter: ++ externalObjects: {} ++ serializedVersion: 2 ++ defaultReferences: [] ++ executionOrder: 0 ++ icon: {instanceID: 0} ++ userData: ++ assetBundleName: ++ assetBundleVariant: +diff --git a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/Unity.RenderPipelines.HighDefinition.Runtime.asmdef b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/Unity.RenderPipelines.HighDefinition.Runtime.asmdef +index 185a101..6d2db5b 100644 +--- a/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/Unity.RenderPipelines.HighDefinition.Runtime.asmdef ++++ b/src/HDRP/com.unity.render-pipelines.high-definition@14.0.7/Runtime/Unity.RenderPipelines.HighDefinition.Runtime.asmdef +@@ -7,7 +7,10 @@ + "Unity.Burst", + "Unity.RenderPipelines.HighDefinition.Config.Runtime", + "Unity.Rendering.Denoising.Runtime", +- "Unity.VisualEffectGraph.Runtime" ++ "Unity.VisualEffectGraph.Runtime", ++ "com.nvidia.streamline.core.Runtime", ++ "com.nvidia.streamline.dlssg.Runtime", ++ "com.nvidia.streamline.reflex.Runtime" + ], + "includePlatforms": [], + "excludePlatforms": [],