add dlss3 sdk
This commit is contained in:
parent
816a5c184d
commit
f8df0f0005
@ -0,0 +1,5 @@
|
|||||||
|
# Changelog
|
||||||
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b51a25b14eb15204b90d1e2803e4e665
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 463851d0a2c6a61449351e69182542e8
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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 <Projectpath>\Library\PackageCache\ into <ProjectPath>\Packages
|
||||||
|
2. Open a cmd prompt in <ProjectPath>\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.
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdbb7d35a8f7aa441a87419e207fc987
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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.
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6899f9a40e5d1114c9146ac0d8ddd203
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7dbb533ef9b1b8745a2bc09d80a142d0
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 382460b4efeded84cbef5762a8b6424b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c4925c5b82eb39b4188e1a64b975034e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<Camera>();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7c8c6bc9ae687a45abf374858854166
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<NativeMemoryItem> m_memList = new List<NativeMemoryItem>();
|
||||||
|
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<int, Feature> m_dictFeatureIds = new Dictionary<int, Feature>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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<Int32.MaxValue; i++)
|
||||||
|
{
|
||||||
|
if (!m_dictFeatureIds.ContainsKey(i))
|
||||||
|
{
|
||||||
|
m_dictFeatureIds.Add(i, feature);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns -1 failed, 0 success
|
||||||
|
public static int DestroyFeature(int featureId)
|
||||||
|
{
|
||||||
|
if (m_dictFeatureIds.ContainsKey(featureId))
|
||||||
|
{
|
||||||
|
m_dictFeatureIds.Remove(featureId);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetTagOld(CommandBuffer cmd, uint id, Texture texture, BufferType tag, uint extents)
|
||||||
|
{
|
||||||
|
// This method of setting the tag is incompatible with D3D12, as the plugin interface doesn't have a GetNativeTexturePtr method.
|
||||||
|
if (texture == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint userData = (uint)tag << 16 | id;
|
||||||
|
cmd.IssuePluginCustomTextureUpdateV2(Plugin_GetSetTagEventCallback(), texture, userData); //TODO, how to send extents through (have a regular event call first that sends through the extents)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetTag(CommandBuffer cmd, uint frameIndex, uint id, Texture texture, BufferType tag, uint extents)
|
||||||
|
{
|
||||||
|
TextureTagData tagData = new TextureTagData();
|
||||||
|
|
||||||
|
tagData.frameIndex = frameIndex;
|
||||||
|
tagData.tag = (uint)tag;
|
||||||
|
tagData.id = id;
|
||||||
|
tagData.nativeTexturePtr = texture!=null ? texture.GetNativeTexturePtr() : IntPtr.Zero;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(TextureTagData));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(tagData, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmd, PluginEvent.PluginEventSetTagData, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EvaluateFeature(CommandBuffer cmd, uint frameIndex, uint id, Feature feature)
|
||||||
|
{
|
||||||
|
EvaluateFeatureData evalData = new EvaluateFeatureData();
|
||||||
|
|
||||||
|
evalData.frameIndex = frameIndex;
|
||||||
|
evalData.id = id;
|
||||||
|
evalData.feature = (uint)feature;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(EvaluateFeatureData));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(evalData, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmd, PluginEvent.PluginEventEvaluateFeature, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void InsertEventCall(CommandBuffer cmd, PluginEvent pluginEvent, IntPtr ptr)
|
||||||
|
{
|
||||||
|
#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 = cmd.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations);
|
||||||
|
#endif
|
||||||
|
cmd.IssuePluginEvent(Plugin_GetRenderEventFunc(), 0);
|
||||||
|
cmd.IssuePluginEventAndData(Plugin_GetRenderEventAndDataFunc(), (int)pluginEvent + Plugin_GetBaseEventId(), ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=============================================================
|
||||||
|
public struct SLViewConstants
|
||||||
|
{
|
||||||
|
public Matrix4x4 viewProjMatrix;
|
||||||
|
public Matrix4x4 invViewProjMatrix;
|
||||||
|
public Matrix4x4 nonJitteredViewProjMatrix;
|
||||||
|
public Matrix4x4 prevViewProjMatrix;
|
||||||
|
public Vector3 worldSpaceCameraPos;
|
||||||
|
public Vector3 prevWorldSpaceCameraPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void UpdateViewConstants(ref SLViewConstants viewConstants, Matrix4x4 projMatrix, Matrix4x4 viewMatrix, Vector3 cameraPosition, bool jitterProjectionMatrix, bool updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
bool cameraRelativeRendering = true;
|
||||||
|
// If TAA or DLSS2 is enabled projMatrix will hold a jittered projection matrix. The original,
|
||||||
|
// non-jittered projection matrix can be accessed via nonJitteredProjMatrix.
|
||||||
|
var nonJitteredCameraProj = projMatrix;
|
||||||
|
//var cameraProj = jitterProjectionMatrix
|
||||||
|
// ? GetJitteredProjectionMatrix(nonJitteredCameraProj)
|
||||||
|
// : nonJitteredCameraProj;
|
||||||
|
var cameraProj = nonJitteredCameraProj;
|
||||||
|
|
||||||
|
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
|
||||||
|
// (different Z value ranges etc.)
|
||||||
|
var gpuProj = GL.GetGPUProjectionMatrix(cameraProj, true); // Had to change this from 'false'
|
||||||
|
var gpuView = viewMatrix;
|
||||||
|
var gpuNonJitteredProj = GL.GetGPUProjectionMatrix(nonJitteredCameraProj, true);
|
||||||
|
|
||||||
|
if (cameraRelativeRendering)
|
||||||
|
{
|
||||||
|
// Zero out the translation component.
|
||||||
|
gpuView.SetColumn(3, new Vector4(0, 0, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
var gpuVP = gpuNonJitteredProj * gpuView;
|
||||||
|
|
||||||
|
if (updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
bool isFirstFrame = false;
|
||||||
|
if (isFirstFrame)
|
||||||
|
{
|
||||||
|
viewConstants.prevWorldSpaceCameraPos = cameraPosition;
|
||||||
|
viewConstants.prevViewProjMatrix = gpuVP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewConstants.prevWorldSpaceCameraPos = viewConstants.worldSpaceCameraPos;
|
||||||
|
viewConstants.prevViewProjMatrix = viewConstants.nonJitteredViewProjMatrix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewConstants.viewProjMatrix = gpuProj * gpuView;
|
||||||
|
viewConstants.invViewProjMatrix = viewConstants.viewProjMatrix.inverse;
|
||||||
|
viewConstants.nonJitteredViewProjMatrix = gpuNonJitteredProj * gpuView;
|
||||||
|
viewConstants.worldSpaceCameraPos = cameraPosition;
|
||||||
|
|
||||||
|
if (updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
Vector3 cameraDisplacement = viewConstants.worldSpaceCameraPos - viewConstants.prevWorldSpaceCameraPos;
|
||||||
|
viewConstants.prevWorldSpaceCameraPos -= viewConstants.worldSpaceCameraPos; // Make it relative w.r.t. the curr cam pos
|
||||||
|
viewConstants.prevViewProjMatrix *= Matrix4x4.Translate(cameraDisplacement); // Now prevViewProjMatrix correctly transforms this frame's camera-relative positionWS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateAllViewConstants(Camera camera, bool jitterProjectionMatrix, bool updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
var proj = camera.projectionMatrix;
|
||||||
|
var view = camera.worldToCameraMatrix;
|
||||||
|
var cameraPosition = camera.transform.position;
|
||||||
|
|
||||||
|
UpdateViewConstants(ref mainViewConstants, proj, view, cameraPosition, jitterProjectionMatrix, updatePreviousFrameConstants);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SLViewConstants mainViewConstants = new SLViewConstants();
|
||||||
|
|
||||||
|
public static Matrix4x4 lastViewProj = Matrix4x4.identity;
|
||||||
|
|
||||||
|
public static void SetupStreamlineConstants(CommandBuffer cmdBuffer, Camera camera, uint id, uint frameIndex, bool requiresJitter, Vector4 jitter, bool isFirstFrame)
|
||||||
|
{
|
||||||
|
// TODO: check we're not setting constants per id more than once per frame.
|
||||||
|
StreamlineCore.Constants constants = new StreamlineCore.Constants();
|
||||||
|
|
||||||
|
//Matrix4x4 MVP = P * V * M;
|
||||||
|
|
||||||
|
//taken from HDRP version needs UpdateAllViewConstants
|
||||||
|
UpdateAllViewConstants(camera, false, true);
|
||||||
|
constants.cameraViewToClip = mainViewConstants.viewProjMatrix;
|
||||||
|
constants.clipToCameraView = mainViewConstants.invViewProjMatrix;
|
||||||
|
Matrix4x4 prevVP = mainViewConstants.prevViewProjMatrix;
|
||||||
|
Matrix4x4 IVP = mainViewConstants.nonJitteredViewProjMatrix.inverse;
|
||||||
|
Matrix4x4 yflip = Matrix4x4.identity;
|
||||||
|
yflip.m11 = -1.0f;
|
||||||
|
Matrix4x4 clipToPrevClip = (yflip * prevVP * IVP * yflip);
|
||||||
|
|
||||||
|
Matrix4x4 prevClipToClip = clipToPrevClip.inverse;
|
||||||
|
|
||||||
|
constants.id = id;
|
||||||
|
constants.frameIndex = frameIndex;
|
||||||
|
|
||||||
|
constants.clipToLensClip = Matrix4x4.identity;
|
||||||
|
constants.clipToPrevClip = clipToPrevClip;
|
||||||
|
constants.prevClipToClip = prevClipToClip;
|
||||||
|
|
||||||
|
constants.jitterOffset = new Vector2(-jitter.x, jitter.y);
|
||||||
|
constants.mvecScale = new Vector2(-1.0f, 1.0f);
|
||||||
|
constants.cameraPinholeOffset = Vector2.zero;
|
||||||
|
constants.cameraPos = camera.transform.position;
|
||||||
|
constants.cameraUp = camera.transform.up;
|
||||||
|
constants.cameraRight = camera.transform.right;
|
||||||
|
constants.cameraFwd = camera.transform.forward;
|
||||||
|
|
||||||
|
constants.cameraNear = camera.nearClipPlane;
|
||||||
|
constants.cameraFar = camera.farClipPlane;
|
||||||
|
constants.cameraFOV = camera.fieldOfView;
|
||||||
|
constants.cameraAspectRatio = camera.aspect;
|
||||||
|
constants.motionVectorsInvalidValue = 0.0f;
|
||||||
|
|
||||||
|
constants.depthInverted = SLBool.eTrue;
|
||||||
|
constants.cameraMotionIncluded = SLBool.eTrue;
|
||||||
|
constants.motionVectors3D = SLBool.eFalse;
|
||||||
|
constants.reset = isFirstFrame ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
constants.orthographicProjection = camera.orthographic ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
constants.motionVectorsDilated = SLBool.eFalse;
|
||||||
|
constants.motionVectorsJittered = requiresJitter ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(StreamlineCore.Constants));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmdBuffer, PluginEvent.PluginEventSetConstants, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imports
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static int Streamline_IsStreamlineEnabled();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static int Streamline_IsFeatureSupported(UInt32 feature);
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static void Streamline_GetFeatureConfiguration(UInt32 feature);
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static uint Plugin_GetLastError();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private static extern int Plugin_GetBaseEventId();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetRenderEventAndDataFunc();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetRenderEventFunc();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetSetTagEventCallback();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6ba550591aaab0d49af0e772800e7ae8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,141 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
|
using NVStreamline;
|
||||||
|
|
||||||
|
namespace NVStreamline
|
||||||
|
{
|
||||||
|
public class StreamlineDLSSCore
|
||||||
|
{
|
||||||
|
public static bool DLSSEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
public enum DLSSMode : uint
|
||||||
|
{
|
||||||
|
eOff,
|
||||||
|
eMaxPerformance,
|
||||||
|
eBalanced,
|
||||||
|
eMaxQuality,
|
||||||
|
eUltraPerformance,
|
||||||
|
eUltraQuality,
|
||||||
|
eCount
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DLSSPreset : uint
|
||||||
|
{
|
||||||
|
//! Default behavior, may or may not change after an OTA
|
||||||
|
eDefault,
|
||||||
|
//! Fixed DL models
|
||||||
|
ePresetA,
|
||||||
|
ePresetB,
|
||||||
|
ePresetC,
|
||||||
|
ePresetD,
|
||||||
|
ePresetE,
|
||||||
|
ePresetF,
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DLSSFlags : uint
|
||||||
|
{
|
||||||
|
eShowOnlyInterpolatedFrame = 1 << 0,
|
||||||
|
eDynamicResolutionEnabled = 1 << 1,
|
||||||
|
eRequestVRAMEstimate = 1 << 2,
|
||||||
|
eRequestRawFrameTime = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct DLSSConstants
|
||||||
|
{
|
||||||
|
public UInt32 id;
|
||||||
|
public UInt32 frameIndex;
|
||||||
|
|
||||||
|
//! Specifies which mode should be used
|
||||||
|
public UInt32 mode;
|
||||||
|
//! Specifies output (final) target width
|
||||||
|
public UInt32 outputWidth;
|
||||||
|
//! Specifies output (final) target height
|
||||||
|
public UInt32 outputHeight;
|
||||||
|
//! Specifies sharpening level in range [0,1]
|
||||||
|
public float sharpness;
|
||||||
|
//! Specifies pre-exposure value
|
||||||
|
public float preExposure;
|
||||||
|
//! Specifies exposure scale value
|
||||||
|
public float exposureScale;
|
||||||
|
//! Specifies if tagged color buffers are full HDR or not (DLSS in HDR pipeline or not)
|
||||||
|
public UInt32 colorBuffersHDR;
|
||||||
|
//! Specifies if indicator on screen should invert axis
|
||||||
|
public UInt32 indicatorInvertAxisX;
|
||||||
|
//! Specifies if indicator on screen should invert axis
|
||||||
|
public UInt32 indicatorInvertAxisY;
|
||||||
|
//! Presets
|
||||||
|
public UInt32 dlaaPreset;
|
||||||
|
public UInt32 qualityPreset;
|
||||||
|
public UInt32 balancedPreset;
|
||||||
|
public UInt32 performancePreset;
|
||||||
|
public UInt32 ultraPerformancePreset;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct DLSSOptimalSettings
|
||||||
|
{
|
||||||
|
public uint optimalRenderWidth;
|
||||||
|
public uint optimalRenderHeight;
|
||||||
|
public float optimalSharpness;
|
||||||
|
public uint renderWidthMin;
|
||||||
|
public uint renderHeightMin;
|
||||||
|
public uint renderWidthMax;
|
||||||
|
public uint renderHeightMax;
|
||||||
|
};
|
||||||
|
|
||||||
|
private static uint lastFrameConstantsSet = 0;
|
||||||
|
|
||||||
|
public static void SetupDLSSFeatureConstants(CommandBuffer cmdBuffer, ref DLSSConstants constants)
|
||||||
|
{
|
||||||
|
if (constants.frameIndex > 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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<RenderTextureDisposal> m_disposalList = new List<RenderTextureDisposal>();
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2400248ea5cb82247b40565a582af890
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 182def67fadf4fd4aba7f2934fe07b8b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1117f316f75cb3b45b0f6717da4ab36c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 13bdb2384d9734f44a26c0c0e2d56f02
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "com.nvidia.streamline.core.Runtime",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": true,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2ad66e0615e74ce41bad44512e0dc450
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08c2d83d275eb5349802afcd291ec67d
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
# Changelog
|
||||||
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b51a25b14eb15204b90d1e2803e4e665
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 463851d0a2c6a61449351e69182542e8
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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 <Projectpath>\Library\PackageCache\ into <ProjectPath>\Packages
|
||||||
|
2. Open a cmd prompt in <ProjectPath>\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.
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdbb7d35a8f7aa441a87419e207fc987
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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.
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6899f9a40e5d1114c9146ac0d8ddd203
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7dbb533ef9b1b8745a2bc09d80a142d0
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 382460b4efeded84cbef5762a8b6424b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
Binary file not shown.
@ -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:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c4925c5b82eb39b4188e1a64b975034e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<Camera>();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7c8c6bc9ae687a45abf374858854166
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<NativeMemoryItem> m_memList = new List<NativeMemoryItem>();
|
||||||
|
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<int, Feature> m_dictFeatureIds = new Dictionary<int, Feature>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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<Int32.MaxValue; i++)
|
||||||
|
{
|
||||||
|
if (!m_dictFeatureIds.ContainsKey(i))
|
||||||
|
{
|
||||||
|
m_dictFeatureIds.Add(i, feature);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns -1 failed, 0 success
|
||||||
|
public static int DestroyFeature(int featureId)
|
||||||
|
{
|
||||||
|
if (m_dictFeatureIds.ContainsKey(featureId))
|
||||||
|
{
|
||||||
|
m_dictFeatureIds.Remove(featureId);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetTagOld(CommandBuffer cmd, uint id, Texture texture, BufferType tag, uint extents)
|
||||||
|
{
|
||||||
|
// This method of setting the tag is incompatible with D3D12, as the plugin interface doesn't have a GetNativeTexturePtr method.
|
||||||
|
if (texture == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint userData = (uint)tag << 16 | id;
|
||||||
|
cmd.IssuePluginCustomTextureUpdateV2(Plugin_GetSetTagEventCallback(), texture, userData); //TODO, how to send extents through (have a regular event call first that sends through the extents)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetTag(CommandBuffer cmd, uint frameIndex, uint id, Texture texture, BufferType tag, uint extents)
|
||||||
|
{
|
||||||
|
TextureTagData tagData = new TextureTagData();
|
||||||
|
|
||||||
|
tagData.frameIndex = frameIndex;
|
||||||
|
tagData.tag = (uint)tag;
|
||||||
|
tagData.id = id;
|
||||||
|
tagData.nativeTexturePtr = texture!=null ? texture.GetNativeTexturePtr() : IntPtr.Zero;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(TextureTagData));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(tagData, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmd, PluginEvent.PluginEventSetTagData, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void EvaluateFeature(CommandBuffer cmd, uint frameIndex, uint id, Feature feature)
|
||||||
|
{
|
||||||
|
EvaluateFeatureData evalData = new EvaluateFeatureData();
|
||||||
|
|
||||||
|
evalData.frameIndex = frameIndex;
|
||||||
|
evalData.id = id;
|
||||||
|
evalData.feature = (uint)feature;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(EvaluateFeatureData));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(evalData, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmd, PluginEvent.PluginEventEvaluateFeature, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void InsertEventCall(CommandBuffer cmd, PluginEvent pluginEvent, IntPtr ptr)
|
||||||
|
{
|
||||||
|
#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 = cmd.CreateGraphicsFence(GraphicsFenceType.AsyncQueueSynchronisation, SynchronisationStageFlags.AllGPUOperations);
|
||||||
|
#endif
|
||||||
|
cmd.IssuePluginEvent(Plugin_GetRenderEventFunc(), 0);
|
||||||
|
cmd.IssuePluginEventAndData(Plugin_GetRenderEventAndDataFunc(), (int)pluginEvent + Plugin_GetBaseEventId(), ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=============================================================
|
||||||
|
public struct SLViewConstants
|
||||||
|
{
|
||||||
|
public Matrix4x4 viewProjMatrix;
|
||||||
|
public Matrix4x4 invViewProjMatrix;
|
||||||
|
public Matrix4x4 nonJitteredViewProjMatrix;
|
||||||
|
public Matrix4x4 prevViewProjMatrix;
|
||||||
|
public Vector3 worldSpaceCameraPos;
|
||||||
|
public Vector3 prevWorldSpaceCameraPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void UpdateViewConstants(ref SLViewConstants viewConstants, Matrix4x4 projMatrix, Matrix4x4 viewMatrix, Vector3 cameraPosition, bool jitterProjectionMatrix, bool updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
bool cameraRelativeRendering = true;
|
||||||
|
// If TAA or DLSS2 is enabled projMatrix will hold a jittered projection matrix. The original,
|
||||||
|
// non-jittered projection matrix can be accessed via nonJitteredProjMatrix.
|
||||||
|
var nonJitteredCameraProj = projMatrix;
|
||||||
|
//var cameraProj = jitterProjectionMatrix
|
||||||
|
// ? GetJitteredProjectionMatrix(nonJitteredCameraProj)
|
||||||
|
// : nonJitteredCameraProj;
|
||||||
|
var cameraProj = nonJitteredCameraProj;
|
||||||
|
|
||||||
|
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
|
||||||
|
// (different Z value ranges etc.)
|
||||||
|
var gpuProj = GL.GetGPUProjectionMatrix(cameraProj, true); // Had to change this from 'false'
|
||||||
|
var gpuView = viewMatrix;
|
||||||
|
var gpuNonJitteredProj = GL.GetGPUProjectionMatrix(nonJitteredCameraProj, true);
|
||||||
|
|
||||||
|
if (cameraRelativeRendering)
|
||||||
|
{
|
||||||
|
// Zero out the translation component.
|
||||||
|
gpuView.SetColumn(3, new Vector4(0, 0, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
var gpuVP = gpuNonJitteredProj * gpuView;
|
||||||
|
|
||||||
|
if (updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
bool isFirstFrame = false;
|
||||||
|
if (isFirstFrame)
|
||||||
|
{
|
||||||
|
viewConstants.prevWorldSpaceCameraPos = cameraPosition;
|
||||||
|
viewConstants.prevViewProjMatrix = gpuVP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewConstants.prevWorldSpaceCameraPos = viewConstants.worldSpaceCameraPos;
|
||||||
|
viewConstants.prevViewProjMatrix = viewConstants.nonJitteredViewProjMatrix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewConstants.viewProjMatrix = gpuProj * gpuView;
|
||||||
|
viewConstants.invViewProjMatrix = viewConstants.viewProjMatrix.inverse;
|
||||||
|
viewConstants.nonJitteredViewProjMatrix = gpuNonJitteredProj * gpuView;
|
||||||
|
viewConstants.worldSpaceCameraPos = cameraPosition;
|
||||||
|
|
||||||
|
if (updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
Vector3 cameraDisplacement = viewConstants.worldSpaceCameraPos - viewConstants.prevWorldSpaceCameraPos;
|
||||||
|
viewConstants.prevWorldSpaceCameraPos -= viewConstants.worldSpaceCameraPos; // Make it relative w.r.t. the curr cam pos
|
||||||
|
viewConstants.prevViewProjMatrix *= Matrix4x4.Translate(cameraDisplacement); // Now prevViewProjMatrix correctly transforms this frame's camera-relative positionWS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateAllViewConstants(Camera camera, bool jitterProjectionMatrix, bool updatePreviousFrameConstants)
|
||||||
|
{
|
||||||
|
var proj = camera.projectionMatrix;
|
||||||
|
var view = camera.worldToCameraMatrix;
|
||||||
|
var cameraPosition = camera.transform.position;
|
||||||
|
|
||||||
|
UpdateViewConstants(ref mainViewConstants, proj, view, cameraPosition, jitterProjectionMatrix, updatePreviousFrameConstants);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SLViewConstants mainViewConstants = new SLViewConstants();
|
||||||
|
|
||||||
|
public static Matrix4x4 lastViewProj = Matrix4x4.identity;
|
||||||
|
|
||||||
|
public static void SetupStreamlineConstants(CommandBuffer cmdBuffer, Camera camera, uint id, uint frameIndex, bool requiresJitter, Vector4 jitter, bool isFirstFrame)
|
||||||
|
{
|
||||||
|
// TODO: check we're not setting constants per id more than once per frame.
|
||||||
|
StreamlineCore.Constants constants = new StreamlineCore.Constants();
|
||||||
|
|
||||||
|
//Matrix4x4 MVP = P * V * M;
|
||||||
|
|
||||||
|
//taken from HDRP version needs UpdateAllViewConstants
|
||||||
|
UpdateAllViewConstants(camera, false, true);
|
||||||
|
constants.cameraViewToClip = mainViewConstants.viewProjMatrix;
|
||||||
|
constants.clipToCameraView = mainViewConstants.invViewProjMatrix;
|
||||||
|
Matrix4x4 prevVP = mainViewConstants.prevViewProjMatrix;
|
||||||
|
Matrix4x4 IVP = mainViewConstants.nonJitteredViewProjMatrix.inverse;
|
||||||
|
Matrix4x4 yflip = Matrix4x4.identity;
|
||||||
|
yflip.m11 = -1.0f;
|
||||||
|
Matrix4x4 clipToPrevClip = (yflip * prevVP * IVP * yflip);
|
||||||
|
|
||||||
|
Matrix4x4 prevClipToClip = clipToPrevClip.inverse;
|
||||||
|
|
||||||
|
constants.id = id;
|
||||||
|
constants.frameIndex = frameIndex;
|
||||||
|
|
||||||
|
constants.clipToLensClip = Matrix4x4.identity;
|
||||||
|
constants.clipToPrevClip = clipToPrevClip;
|
||||||
|
constants.prevClipToClip = prevClipToClip;
|
||||||
|
|
||||||
|
constants.jitterOffset = new Vector2(-jitter.x, jitter.y);
|
||||||
|
constants.mvecScale = new Vector2(-1.0f, 1.0f);
|
||||||
|
constants.cameraPinholeOffset = Vector2.zero;
|
||||||
|
constants.cameraPos = camera.transform.position;
|
||||||
|
constants.cameraUp = camera.transform.up;
|
||||||
|
constants.cameraRight = camera.transform.right;
|
||||||
|
constants.cameraFwd = camera.transform.forward;
|
||||||
|
|
||||||
|
constants.cameraNear = camera.nearClipPlane;
|
||||||
|
constants.cameraFar = camera.farClipPlane;
|
||||||
|
constants.cameraFOV = camera.fieldOfView;
|
||||||
|
constants.cameraAspectRatio = camera.aspect;
|
||||||
|
constants.motionVectorsInvalidValue = 0.0f;
|
||||||
|
|
||||||
|
constants.depthInverted = SLBool.eTrue;
|
||||||
|
constants.cameraMotionIncluded = SLBool.eTrue;
|
||||||
|
constants.motionVectors3D = SLBool.eFalse;
|
||||||
|
constants.reset = isFirstFrame ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
constants.orthographicProjection = camera.orthographic ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
constants.motionVectorsDilated = SLBool.eFalse;
|
||||||
|
constants.motionVectorsJittered = requiresJitter ? SLBool.eTrue : SLBool.eFalse;
|
||||||
|
|
||||||
|
int size = Marshal.SizeOf(typeof(StreamlineCore.Constants));
|
||||||
|
|
||||||
|
IntPtr dataPtr = m_nativeAllocator.Malloc(frameIndex, size);
|
||||||
|
|
||||||
|
Marshal.StructureToPtr(constants, dataPtr, false); //fDeleteOld
|
||||||
|
|
||||||
|
InsertEventCall(cmdBuffer, PluginEvent.PluginEventSetConstants, dataPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imports
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static int Streamline_IsStreamlineEnabled();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static int Streamline_IsFeatureSupported(UInt32 feature);
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static void Streamline_GetFeatureConfiguration(UInt32 feature);
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static uint Plugin_GetLastError();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private static extern int Plugin_GetBaseEventId();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetRenderEventAndDataFunc();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetRenderEventFunc();
|
||||||
|
|
||||||
|
[DllImport("GfxPluginNVIDIAStreamline", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
||||||
|
private extern static IntPtr Plugin_GetSetTagEventCallback();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6ba550591aaab0d49af0e772800e7ae8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,141 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
|
using NVStreamline;
|
||||||
|
|
||||||
|
namespace NVStreamline
|
||||||
|
{
|
||||||
|
public class StreamlineDLSSCore
|
||||||
|
{
|
||||||
|
public static bool DLSSEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
public enum DLSSMode : uint
|
||||||
|
{
|
||||||
|
eOff,
|
||||||
|
eMaxPerformance,
|
||||||
|
eBalanced,
|
||||||
|
eMaxQuality,
|
||||||
|
eUltraPerformance,
|
||||||
|
eUltraQuality,
|
||||||
|
eCount
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DLSSPreset : uint
|
||||||
|
{
|
||||||
|
//! Default behavior, may or may not change after an OTA
|
||||||
|
eDefault,
|
||||||
|
//! Fixed DL models
|
||||||
|
ePresetA,
|
||||||
|
ePresetB,
|
||||||
|
ePresetC,
|
||||||
|
ePresetD,
|
||||||
|
ePresetE,
|
||||||
|
ePresetF,
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DLSSFlags : uint
|
||||||
|
{
|
||||||
|
eShowOnlyInterpolatedFrame = 1 << 0,
|
||||||
|
eDynamicResolutionEnabled = 1 << 1,
|
||||||
|
eRequestVRAMEstimate = 1 << 2,
|
||||||
|
eRequestRawFrameTime = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct DLSSConstants
|
||||||
|
{
|
||||||
|
public UInt32 id;
|
||||||
|
public UInt32 frameIndex;
|
||||||
|
|
||||||
|
//! Specifies which mode should be used
|
||||||
|
public UInt32 mode;
|
||||||
|
//! Specifies output (final) target width
|
||||||
|
public UInt32 outputWidth;
|
||||||
|
//! Specifies output (final) target height
|
||||||
|
public UInt32 outputHeight;
|
||||||
|
//! Specifies sharpening level in range [0,1]
|
||||||
|
public float sharpness;
|
||||||
|
//! Specifies pre-exposure value
|
||||||
|
public float preExposure;
|
||||||
|
//! Specifies exposure scale value
|
||||||
|
public float exposureScale;
|
||||||
|
//! Specifies if tagged color buffers are full HDR or not (DLSS in HDR pipeline or not)
|
||||||
|
public UInt32 colorBuffersHDR;
|
||||||
|
//! Specifies if indicator on screen should invert axis
|
||||||
|
public UInt32 indicatorInvertAxisX;
|
||||||
|
//! Specifies if indicator on screen should invert axis
|
||||||
|
public UInt32 indicatorInvertAxisY;
|
||||||
|
//! Presets
|
||||||
|
public UInt32 dlaaPreset;
|
||||||
|
public UInt32 qualityPreset;
|
||||||
|
public UInt32 balancedPreset;
|
||||||
|
public UInt32 performancePreset;
|
||||||
|
public UInt32 ultraPerformancePreset;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct DLSSOptimalSettings
|
||||||
|
{
|
||||||
|
public uint optimalRenderWidth;
|
||||||
|
public uint optimalRenderHeight;
|
||||||
|
public float optimalSharpness;
|
||||||
|
public uint renderWidthMin;
|
||||||
|
public uint renderHeightMin;
|
||||||
|
public uint renderWidthMax;
|
||||||
|
public uint renderHeightMax;
|
||||||
|
};
|
||||||
|
|
||||||
|
private static uint lastFrameConstantsSet = 0;
|
||||||
|
|
||||||
|
public static void SetupDLSSFeatureConstants(CommandBuffer cmdBuffer, ref DLSSConstants constants)
|
||||||
|
{
|
||||||
|
if (constants.frameIndex > 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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<RenderTextureDisposal> m_disposalList = new List<RenderTextureDisposal>();
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2400248ea5cb82247b40565a582af890
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 182def67fadf4fd4aba7f2934fe07b8b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1117f316f75cb3b45b0f6717da4ab36c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 13bdb2384d9734f44a26c0c0e2d56f02
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "com.nvidia.streamline.core.Runtime",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": true,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2ad66e0615e74ce41bad44512e0dc450
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08c2d83d275eb5349802afcd291ec67d
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
# Changelog
|
||||||
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f850f29f3bea48f458e1428f058c3ee0
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a85cd14244f4b3647900975104c8d8a0
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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.
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 93d48415677c00347a444ac3d67cef03
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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.
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8fc9675c6de914848bf7223df5932b6b
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e9acb86b221bb974f80abbb98e9156eb
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<Camera>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a900f711d0eea1e44ba8fc5e6288b726
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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<Camera>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7f43cd7ced34da44a291edb15cbc13c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6a4210699ac0ab844b9dac2e66ee9813
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da91c11f20128c04b9025df7aa857001
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user