add qcom afme

This commit is contained in:
StarBeats 2024-11-22 12:09:31 +08:00
parent f2942dae83
commit cabe73b2c6
45 changed files with 1469 additions and 1736 deletions

2
.gitignore vendored
View File

@ -46,6 +46,8 @@ sysinfo.txt
# Builds
*.apk
*.hap
*.app
*.unitypackage
.vsconfig

8
Assets/Plugins.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: W3gf43v7AX7cTPQxR8YjE1dpIPTV5wZRzpHYu5Fn0KISlXqsRzLtc1A=
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: WXkcvXv4UX1/JuVoVKRpheP6zqwavizmXJNdeXG0oEB4Ijk2wBHOKM0=
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,39 @@
fileFormatVersion: 2
guid: DCkXsnv/B34eOwGENG/puU/aLspZXxc9PezQb5HZ7ZE2dZf9faeP2Qk=
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 1
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings:
CPU: ARM64
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
HMIAndroid: HMIAndroid
second:
enabled: 1
settings:
CPU: ARM64
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: WSsfty/7UH++iuK/tWenHX7H1q9yLZfCPmEk6KR2UPRA8V8V0XNmP4I=
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: DCtMtCn5U3xMS7shR8OwiBEID90HAVK1x74mzYKnSk8WZJSdtVLPTY0=
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:

View File

@ -8183,7 +8183,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &737529738
Transform:
m_ObjectHideFlags: 0
@ -14004,7 +14004,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1317243097}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a432c59e36da65418a040549712b15c, type: 3}
m_Name:
@ -14860,7 +14860,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3547149925401584174}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f43f8f36f48f284dbd4ee65ea93bd08, type: 3}
m_Name:
@ -15689,7 +15689,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1510284357}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c2f491b7d0e609d488f7a7bf05596657, type: 3}
m_Name:
@ -16552,6 +16552,11 @@ Light:
m_ShadowRadius: 0
m_ShadowAngle: 0
m_UseOcclusionCulling: 1
--- !u!1 &1558980086 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 4916034631659228877, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
m_PrefabInstance: {fileID: 2760477044720773439}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1559356782
GameObject:
m_ObjectHideFlags: 0
@ -17445,7 +17450,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1636404061
Transform:
m_ObjectHideFlags: 0
@ -22334,7 +22339,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &2050461559
Transform:
m_ObjectHideFlags: 0
@ -24868,7 +24873,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 141850471471409378, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 141850471471409436, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_Enabled
@ -24899,6 +24904,10 @@ PrefabInstance:
value: 1.3750001
objectReference: {fileID: 0}
- target: {fileID: 499885696063000424, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 804158071037245537, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
@ -24920,7 +24929,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2307673875293584181, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2307673875293584185, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_DefaultControlScheme
@ -24930,6 +24939,14 @@ PrefabInstance:
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2760477044286518991, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2760477044286518991, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_CrosshairCanvas
value:
objectReference: {fileID: 0}
- target: {fileID: 2760477044286518991, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: FlythroughDirector
value:
@ -24946,6 +24963,14 @@ PrefabInstance:
propertyPath: m_IdleTransitionTime
value: 10
objectReference: {fileID: 0}
- target: {fileID: 2760477044887562765, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_StopNaN
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2760477044887562765, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_Dithering
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2760477044887562765, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_Antialiasing
value: 0
@ -25040,7 +25065,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2760477045267651031, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4682428349833130388, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_IsActive
@ -25058,6 +25083,10 @@ PrefabInstance:
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6943526994973159469, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7019485897165914674, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
propertyPath: m_LocalPosition.x
value: 0
@ -25175,12 +25204,16 @@ PrefabInstance:
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_RemovedGameObjects:
- {fileID: 9131961404394414058, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: 7019485897165914674, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
insertIndex: -1
addedObject: {fileID: 867583717}
m_AddedComponents: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 4916034631659228877, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
insertIndex: -1
addedObject: {fileID: 6556307556733515108}
m_SourcePrefab: {fileID: 100100000, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
--- !u!4 &3547149924374491350
Transform:
@ -26485,12 +26518,24 @@ MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2760477044286518991, guid: 8e5bed6b8dcfed240a38affefd9c58f6, type: 3}
m_PrefabInstance: {fileID: 2760477044720773439}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_GameObject: {fileID: 1558980086}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 567bc3eba414c614da47a095c9dde5d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &6556307556733515108
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1558980086}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a62f35552be2a4a4e8e2683b7aea565b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &8509203744807723470
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,45 +1,47 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using X.Rendering.Feature;
[ExecuteAlways]
public class Test : MonoBehaviour
{
private Material material;
private Texture2D oriTexture;
private Texture2D cvtTexture;
int vrs = 0;
public void OnClickVRS()
{
var asset = UniversalRenderPipeline.asset;
if (asset != null)
{
vrs++;
if (vrs > (int)RenderingPlugin.VRSPluginShadingRate.X1_PER_4X4_PIXELS)
{
vrs = 0;
}
asset.VRSRate = (RenderingPlugin.VRSPluginShadingRate)vrs;
Debug.Log("VRS RATE" + asset.VRSRate);
}
}
private void Start()
{
material = GetComponent<MeshRenderer>().sharedMaterial;
oriTexture = material.GetTexture("_MainTex") as Texture2D;
ConvertAlpha();
Debug.Log($"FeatureSupport--\n" +
$"VRS:[{RenderingPlugin.GetFeatureSupport(RenderingPlugin.GraphicsFeature.VRS_DRAW)} " +
$"{RenderingPlugin.GetFeatureSupport(RenderingPlugin.GraphicsFeature.VRS_PRIMITIVE)}" +
$"{RenderingPlugin.GetFeatureSupport(RenderingPlugin.GraphicsFeature.VRS_ATTACHMENT)}" +
$"]" +
$"FG:[ QCOM_AFME: {RenderingPlugin.GetFeatureSupport(RenderingPlugin.GraphicsFeature.QCOM_AFME)}]"
);
}
void ConvertAlpha()
private void OnGUI()
{
cvtTexture = new Texture2D(oriTexture.width, oriTexture.height, TextureFormat.ARGB32, false);
for (int i = 0; i < cvtTexture.width; i++)
if (GUI.Button(new Rect(100,200, 100, 50), "VRS"))
{
for (int j = 0; j < cvtTexture.height; j++)
{
var col = oriTexture.GetPixel(i, j);
//col.r = Mathf.Pow(col.r, 1/2.2f);
//col.g = Mathf.Pow(col.g, 1/2.2f);
//col.b = Mathf.Pow(col.b, 1/2.2f);
cvtTexture.SetPixel(i,j, col);
OnClickVRS();
}
}
cvtTexture.Apply();
}
[ContextMenu("Use Converted")]
private void UseAlpha()
if (GUI.Button(new Rect(100, 300, 100, 50), "FG"))
{
X.Rendering.Feature.FG.UseFG = !X.Rendering.Feature.FG.UseFG;
}
[ContextMenu("Use Original")]
private void UseOriginal()
{
material.SetTexture("_MainTex", oriTexture);
}
}

View File

@ -28,7 +28,7 @@ MonoBehaviour:
m_SupportsHDR: 1
m_HDRColorBufferPrecision: 0
m_MSAA: 1
m_RenderScale: 0.75
m_RenderScale: 1
m_UpscalingFilter: 0
m_FsrOverrideSharpness: 1
m_FsrSharpness: 1
@ -114,5 +114,6 @@ MonoBehaviour:
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
m_ShadowCascades: 0
superResolution: 5
sSRenderScale: 3
superResolution: 0
sSRenderScale: 0
vrsRate: 0

View File

@ -81,7 +81,7 @@ MonoBehaviour:
- {fileID: 1524480044783497712}
- {fileID: 6334271670068977784}
m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222f0f17d10860a28157820480586dae757
m_UseNativeRenderPass: 0
m_UseNativeRenderPass: 1
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
@ -144,7 +144,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a6b8ba513f1b1fe499924f362fdde22d, type: 3}
m_Name: GSR
m_EditorClassIdentifier:
m_Active: 1
m_Active: 0
v1settings:
EnableEdgeDirection: 1
Mode: 1

View File

@ -28,7 +28,7 @@ MonoBehaviour:
m_SupportsHDR: 1
m_HDRColorBufferPrecision: 0
m_MSAA: 1
m_RenderScale: 1
m_RenderScale: 0.5
m_UpscalingFilter: 0
m_FsrOverrideSharpness: 0
m_FsrSharpness: 0.92
@ -106,7 +106,14 @@ MonoBehaviour:
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 0
m_PrefilterSoftShadowsQualityLow: 0
m_PrefilterSoftShadowsQualityMedium: 0
m_PrefilterSoftShadowsQualityHigh: 0
m_PrefilterSoftShadows: 0
m_PrefilterScreenCoord: 1
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
m_ShadowCascades: 0
superResolution: 4
sSRenderScale: 5
vrsRate: 0

View File

@ -28,7 +28,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0b2db86121404754db890f4c8dfe81b2, type: 3}
m_Name: Bloom
m_EditorClassIdentifier:
active: 1
active: 0
skipIterations:
m_OverrideState: 1
m_Value: 0

View File

@ -1,7 +1,7 @@
using Benchmarking;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
using UnityEngine.InputSystem;
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
#endif
namespace StarterAssets

View File

@ -1,5 +1,4 @@
build
.vscode
vsxmake2022
vs2022
.vs

View File

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"defines": ["FOO", "BAR=100"],
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}

View File

@ -0,0 +1,31 @@
[
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI.cpp.o", "RenderAPI.cpp"],
"file": "RenderAPI.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D11.cpp.o", "RenderAPI_D3D11.cpp"],
"file": "RenderAPI_D3D11.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D12.cpp.o", "RenderAPI_D3D12.cpp"],
"file": "RenderAPI_D3D12.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_OpenGLCoreES.cpp.o", "RenderAPI_OpenGLCoreES.cpp"],
"file": "RenderAPI_OpenGLCoreES.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_Vulkan.cpp.o", "RenderAPI_Vulkan.cpp"],
"file": "RenderAPI_Vulkan.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["C:\\Users\\xinyt\\AppData\\Local\\OpenHarmony\\Sdk\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-fPIC", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_VULKAN=1", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderingPlugin.cpp.o", "RenderingPlugin.cpp"],
"file": "RenderingPlugin.cpp"
}]

View File

@ -0,0 +1,29 @@
{
"files.associations": {
"xiosbase": "cpp",
"tuple": "cpp",
"array": "cpp",
"format": "cpp",
"initializer_list": "cpp",
"list": "cpp",
"vector": "cpp",
"xhash": "cpp",
"xstring": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"algorithm": "cpp",
"bitset": "cpp",
"iterator": "cpp",
"xmemory": "cpp",
"__bit_reference": "cpp",
"map": "cpp",
"unordered_map": "cpp"
},
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#1073cf2d",
"editor.lineHighlightBorder": "#9fced11f",
"activityBar.background": "#2C3102",
"titleBar.activeBackground": "#3D4402",
"titleBar.activeForeground": "#F9FDD3"
}
}

View File

@ -16,7 +16,8 @@
// UNITY_WEBGL - WebGL
// UNITY_EMBEDDED_LINUX - EmbeddedLinux OpenGLES
// UNITY_EMBEDDED_LINUX_GL - EmbeddedLinux OpenGLCore
#if _MSC_VER
#if OHOS
#elif _MSC_VER
#define UNITY_WIN 1
#elif defined(__APPLE__)
#if TARGET_OS_TV
@ -39,6 +40,7 @@
// Which graphics device APIs we possibly support?
#if UNITY_METRO
#define SUPPORT_D3D11 1
@ -55,14 +57,11 @@
#else
#define SUPPORT_D3D11 0 // comment this out if you don't have D3D11 header/library files
#define SUPPORT_D3D12 0 // comment this out if you don't have D3D12 header/library files
#define SUPPORT_OPENGL_UNIFIED 0
#define SUPPORT_OPENGL_CORE 0
#endif
#elif UNITY_IOS || UNITY_TVOS || UNITY_ANDROID || UNITY_WEBGL
#ifndef SUPPORT_OPENGL_ES
#define SUPPORT_OPENGL_ES 1
#endif
#ifndef SUPPORT_OPENGL_UNIFIED
#define SUPPORT_OPENGL_UNIFIED SUPPORT_OPENGL_ES
#endif
#ifndef SUPPORT_VULKAN
#define SUPPORT_VULKAN 0
#endif

View File

@ -2,7 +2,7 @@
#include "PlatformBase.h"
#include "Unity/IUnityGraphics.h"
RenderAPI* CreateRenderAPI(UnityGfxRenderer apiType)
RenderAPI* createRenderAPI(UnityGfxRenderer apiType)
{
# if SUPPORT_D3D11
if (apiType == kUnityGfxRendererD3D11)
@ -48,3 +48,8 @@ RenderAPI* CreateRenderAPI(UnityGfxRenderer apiType)
// Unknown or unsupported graphics API
return NULL;
}
bool RenderAPI::getFeatureSupport(GraphicsFeature feature)
{
return support_features[feature];
}

View File

@ -2,10 +2,44 @@
#include "Unity/IUnityGraphics.h"
#include <stddef.h>
#include <array>
struct IUnityInterfaces;
enum GraphicsFeature
{
VRS_DRAW = 0,
VRS_PRIMITIVE,
VRS_ATTACHMENT,
HW_SPATIAL_SR,
HW_AISR,
HW_ADAPTIVE_VRS,
HW_FG_INTERPOLATE,
HW_FG_EXTRAPOLATION,
METAL_FX_SPATIAL_SR,
METAL_FX_TEMPORAL_SR,
VIVO_TEMPORAL_SR,
QCOM_AFME,
MAX_CNT
};
struct SupportFeatureList
{
std::array<bool, GraphicsFeature::MAX_CNT> support_features = {0};
bool& operator[](GraphicsFeature feature)
{
return support_features[(int)feature];
}
};
struct AFMEParam
{
void* src;
void* data;
void* dst;
};
// Super-simple "graphics abstraction". This is nothing like how a proper platform abstraction layer would look like;
// all this does is a base interface for whatever our plugin sample needs. Which is only "draw some triangles"
// and "modify a texture" at this point.
@ -16,48 +50,12 @@ class RenderAPI
public:
virtual ~RenderAPI() { }
// Process general event like initialization, shutdown, device loss/reset etc.
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces) = 0;
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces) = 0;
// Is the API using "reversed" (1.0 at near plane, 0.0 at far plane) depth buffer?
// Reversed Z is used on modern platforms, and improves depth buffer precision.
virtual bool GetUsesReverseZ() = 0;
// Draw some triangle geometry, using some simple rendering state.
// Upon call into our plug-in the render state can be almost completely arbitrary depending
// on what was rendered in Unity before. Here, we turn off culling, blending, depth writes etc.
// and draw the triangles with a given world matrix. The triangle data is
// float3 (position) and byte4 (color) per vertex.
virtual void DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4) = 0;
// Begin modifying texture data. You need to pass texture width/height too, since some graphics APIs
// (e.g. OpenGL ES) do not have a good way to query that from the texture itself...
//
// Returns pointer into the data buffer to write into (or NULL on failure), and pitch in bytes of a single texture row.
virtual void* BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch) = 0;
// End modifying texture data.
virtual void EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr) = 0;
// Begin modifying vertex buffer data.
// Returns pointer into the data buffer to write into (or NULL on failure), and buffer size.
virtual void* BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize) = 0;
// End modifying vertex buffer data.
virtual void EndModifyVertexBuffer(void* bufferHandle) = 0;
// --------------------------------------------------------------------------
// DX12 plugin specific functions
// --------------------------------------------------------------------------
// Draws to a texture that is created by the plugin
virtual void drawToPluginTexture() {}
// Draws to a a unity RenderBuffer which can be set with
// setRenderTextureResource(). When the texture resource is not
// set with setRenderTextureResource() one is created by the plugin
virtual void drawToRenderTexture() {}
virtual bool getUsesReverseZ() = 0;
// Returns the native resource pointer to either unity render buffer or
// to the resource created by the plugin (i.e ID3D12Resource* in case of DX12)
@ -84,9 +82,24 @@ public:
virtual void enableVRS(int vrsEnum) {}
virtual void disableVRS() {}
virtual void enableFGExtrapolation() {}
virtual void preFGExtrapolation() {}
// when renturn true present dst, data may matriaxs or texture
virtual bool doFGExtrapolation(void* src, void* data, void* dst) { return false;}
virtual void postFGExtrapolation() {}
virtual void disableFGExtrapolation() {}
virtual void spatialUpScale(void* src, void* data, void* dst) {}
virtual bool getFeatureSupport(GraphicsFeature feature);
protected:
virtual void initSupportFeature() = 0;
SupportFeatureList support_features;
};
// Create a graphics API implementation instance for the given API type.
RenderAPI* CreateRenderAPI(UnityGfxRenderer apiType);
RenderAPI* createRenderAPI(UnityGfxRenderer apiType);

View File

@ -1,12 +1,13 @@
#include "RenderAPI.h"
#include "PlatformBase.h"
#include <cmath>
// Direct3D 12 implementation of RenderAPI.
#if SUPPORT_D3D12
#include <cmath>
#include <assert.h>
#include <dxgi1_6.h>
#include <initguid.h>

View File

@ -11,6 +11,9 @@
#include "Unity/IUnityGraphicsMetal.h"
#import <Metal/Metal.h>
#import <Foundation/Foundation.h>
#import <MetalFX/MTLFXSpatialScaler.h>
class RenderAPI_Metal : public RenderAPI
{
@ -18,28 +21,16 @@ public:
RenderAPI_Metal();
virtual ~RenderAPI_Metal() { }
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
virtual bool GetUsesReverseZ() { return true; }
virtual bool getUsesReverseZ() { return true; }
virtual void DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4);
virtual void* BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch);
virtual void EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr);
virtual void* BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize);
virtual void EndModifyVertexBuffer(void* bufferHandle);
virtual void initSupportFeature();
virtual void spatialUpScale(void* src, void*data, void* dst);
private:
void CreateResources();
private:
IUnityGraphicsMetal* m_MetalGraphics;
id<MTLBuffer> m_VertexBuffer;
id<MTLBuffer> m_ConstantBuffer;
id<MTLDepthStencilState> m_DepthStencil;
id<MTLRenderPipelineState> m_Pipeline;
id <MTLFXSpatialScaler> mfx_spatial_scaler;
IUnityGraphicsMetal* metal_graphics;
};
@ -49,210 +40,66 @@ RenderAPI* CreateRenderAPI_Metal()
}
static Class MTLVertexDescriptorClass;
static Class MTLRenderPipelineDescriptorClass;
static Class MTLDepthStencilDescriptorClass;
const int kVertexSize = 12 + 4;
// Simple vertex & fragment shader source
static const char kShaderSource[] =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct AppData\n"
"{\n"
" float4x4 worldMatrix;\n"
"};\n"
"struct Vertex\n"
"{\n"
" float3 pos [[attribute(0)]];\n"
" float4 color [[attribute(1)]];\n"
"};\n"
"struct VSOutput\n"
"{\n"
" float4 pos [[position]];\n"
" half4 color;\n"
"};\n"
"struct FSOutput\n"
"{\n"
" half4 frag_data [[color(0)]];\n"
"};\n"
"vertex VSOutput vertexMain(Vertex input [[stage_in]], constant AppData& my_cb [[buffer(0)]])\n"
"{\n"
" VSOutput out = { my_cb.worldMatrix * float4(input.pos.xyz, 1), (half4)input.color };\n"
" return out;\n"
"}\n"
"fragment FSOutput fragmentMain(VSOutput input [[stage_in]])\n"
"{\n"
" FSOutput out = { input.color };\n"
" return out;\n"
"}\n";
void RenderAPI_Metal::CreateResources()
{
id<MTLDevice> metalDevice = m_MetalGraphics->MetalDevice();
NSError* error = nil;
// Create shaders
NSString* srcStr = [[NSString alloc] initWithBytes:kShaderSource length:sizeof(kShaderSource) encoding:NSASCIIStringEncoding];
id<MTLLibrary> shaderLibrary = [metalDevice newLibraryWithSource:srcStr options:nil error:&error];
if(error != nil)
{
NSString* desc = [error localizedDescription];
NSString* reason = [error localizedFailureReason];
::fprintf(stderr, "%s\n%s\n\n", desc ? [desc UTF8String] : "<unknown>", reason ? [reason UTF8String] : "");
}
id<MTLFunction> vertexFunction = [shaderLibrary newFunctionWithName:@"vertexMain"];
id<MTLFunction> fragmentFunction = [shaderLibrary newFunctionWithName:@"fragmentMain"];
// Vertex / Constant buffers
# if UNITY_OSX
MTLResourceOptions bufferOptions = MTLResourceCPUCacheModeDefaultCache | MTLResourceStorageModeManaged;
# else
MTLResourceOptions bufferOptions = MTLResourceOptionCPUCacheModeDefault;
# endif
m_VertexBuffer = [metalDevice newBufferWithLength:1024 options:bufferOptions];
m_VertexBuffer.label = @"PluginVB";
m_ConstantBuffer = [metalDevice newBufferWithLength:16*sizeof(float) options:bufferOptions];
m_ConstantBuffer.label = @"PluginCB";
// Vertex layout
MTLVertexDescriptor* vertexDesc = [MTLVertexDescriptorClass vertexDescriptor];
vertexDesc.attributes[0].format = MTLVertexFormatFloat3;
vertexDesc.attributes[0].offset = 0;
vertexDesc.attributes[0].bufferIndex = 1;
vertexDesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
vertexDesc.attributes[1].offset = 3*sizeof(float);
vertexDesc.attributes[1].bufferIndex = 1;
vertexDesc.layouts[1].stride = kVertexSize;
vertexDesc.layouts[1].stepFunction = MTLVertexStepFunctionPerVertex;
vertexDesc.layouts[1].stepRate = 1;
// Pipeline
MTLRenderPipelineDescriptor* pipeDesc = [[MTLRenderPipelineDescriptorClass alloc] init];
// Let's assume we're rendering into BGRA8Unorm...
pipeDesc.colorAttachments[0].pixelFormat= MTLPixelFormatBGRA8Unorm;
pipeDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
pipeDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
pipeDesc.sampleCount = 1;
pipeDesc.colorAttachments[0].blendingEnabled = NO;
pipeDesc.vertexFunction = vertexFunction;
pipeDesc.fragmentFunction = fragmentFunction;
pipeDesc.vertexDescriptor = vertexDesc;
m_Pipeline = [metalDevice newRenderPipelineStateWithDescriptor:pipeDesc error:&error];
if (error != nil)
{
::fprintf(stderr, "Metal: Error creating pipeline state: %s\n%s\n", [[error localizedDescription] UTF8String], [[error localizedFailureReason] UTF8String]);
error = nil;
}
// Depth/Stencil state
MTLDepthStencilDescriptor* depthDesc = [[MTLDepthStencilDescriptorClass alloc] init];
depthDesc.depthCompareFunction = GetUsesReverseZ() ? MTLCompareFunctionGreaterEqual : MTLCompareFunctionLessEqual;
depthDesc.depthWriteEnabled = false;
m_DepthStencil = [metalDevice newDepthStencilStateWithDescriptor:depthDesc];
}
RenderAPI_Metal::RenderAPI_Metal()
{
}
void RenderAPI_Metal::ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces)
void RenderAPI_Metal::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces)
{
if (type == kUnityGfxDeviceEventInitialize)
{
m_MetalGraphics = interfaces->Get<IUnityGraphicsMetal>();
MTLVertexDescriptorClass = NSClassFromString(@"MTLVertexDescriptor");
MTLRenderPipelineDescriptorClass = NSClassFromString(@"MTLRenderPipelineDescriptor");
MTLDepthStencilDescriptorClass = NSClassFromString(@"MTLDepthStencilDescriptor");
CreateResources();
metal_graphics = interfaces->Get<IUnityGraphicsMetal>();
}
else if (type == kUnityGfxDeviceEventShutdown)
{
//@TODO: release resources
}
}
void RenderAPI_Metal::DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4)
void RenderAPI_Metal::initSupportFeature()
{
// Update vertex and constant buffers
//@TODO: we don't do any synchronization here :)
const int vbSize = triangleCount * 3 * kVertexSize;
const int cbSize = 16 * sizeof(float);
::memcpy(m_VertexBuffer.contents, verticesFloat3Byte4, vbSize);
::memcpy(m_ConstantBuffer.contents, worldMatrix, cbSize);
#if UNITY_OSX
[m_VertexBuffer didModifyRange:NSMakeRange(0, vbSize)];
[m_ConstantBuffer didModifyRange:NSMakeRange(0, cbSize)];
#endif
id<MTLRenderCommandEncoder> cmd = (id<MTLRenderCommandEncoder>)m_MetalGraphics->CurrentCommandEncoder();
// Setup rendering state
[cmd setRenderPipelineState:m_Pipeline];
[cmd setDepthStencilState:m_DepthStencil];
[cmd setCullMode:MTLCullModeNone];
// Bind buffers
[cmd setVertexBuffer:m_VertexBuffer offset:0 atIndex:1];
[cmd setVertexBuffer:m_ConstantBuffer offset:0 atIndex:0];
// Draw
[cmd drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:triangleCount*3];
if (@available(iOS 16.0, *))
{
support_features[GraphicsFeature::METAL_FX_SPATIAL_SR] = true;
support_features[GraphicsFeature::METAL_FX_TEMPORAL_SR] = true;
}
}
void* RenderAPI_Metal::BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch)
void RenderAPI_Metal::spatialUpScale(void* src, void* data, void* dst)
{
const int rowPitch = textureWidth * 4;
// Just allocate a system memory buffer here for simplicity
unsigned char* data = new unsigned char[rowPitch * textureHeight];
*outRowPitch = rowPitch;
return data;
if (@available(iOS 16.0, *))
{
id<MTLTexture> srctex = (__bridge id<MTLTexture>)src;
id<MTLTexture> dsttex = (__bridge id<MTLTexture>)dst;
id<MTLDevice> _device = metal_graphics->MetalDevice();
id<MTLCommandBuffer> cmd = (id<MTLCommandBuffer>)metal_graphics->CurrentCommandBuffer();
cmd.label = @"Upscale Command Buffer";
if (mfx_spatial_scaler == nil)
{
MTLFXSpatialScalerDescriptor* desc = [[MTLFXSpatialScalerDescriptor alloc]init];
desc.inputWidth = [srctex width];
desc.inputHeight = [srctex height];
desc.outputWidth = [dsttex width];
desc.outputHeight = [dsttex height];
desc.colorTextureFormat = [srctex pixelFormat];
desc.outputTextureFormat = [dsttex pixelFormat];
desc.colorProcessingMode = MTLFXSpatialScalerColorProcessingModeLinear;
mfx_spatial_scaler = [desc newSpatialScalerWithDevice:_device];
if (mfx_spatial_scaler == nil)
{
return;
}
}
mfx_spatial_scaler.colorTexture = srctex;
mfx_spatial_scaler.outputTexture = dsttex;
[mfx_spatial_scaler encodeToCommandBuffer:cmd];
[cmd commit];
}
}
void RenderAPI_Metal::EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr)
{
id<MTLTexture> tex = (__bridge id<MTLTexture>)textureHandle;
// Update texture data, and free the memory buffer
[tex replaceRegion:MTLRegionMake3D(0,0,0, textureWidth,textureHeight,1) mipmapLevel:0 withBytes:dataPtr bytesPerRow:rowPitch];
delete[](unsigned char*)dataPtr;
}
void* RenderAPI_Metal::BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize)
{
id<MTLBuffer> buf = (__bridge id<MTLBuffer>)bufferHandle;
*outBufferSize = [buf length];
return [buf contents];
}
void RenderAPI_Metal::EndModifyVertexBuffer(void* bufferHandle)
{
# if UNITY_OSX
id<MTLBuffer> buf = (__bridge id<MTLBuffer>)bufferHandle;
[buf didModifyRange:NSMakeRange(0, buf.length)];
# endif // if UNITY_OSX
}
#endif // #if SUPPORT_METAL

View File

@ -1,210 +1,137 @@
#include "RenderAPI.h"
#include "PlatformBase.h"
#include <stdio.h>
// OpenGL Core profile (desktop) or OpenGL ES (mobile) implementation of RenderAPI.
// Supports several flavors: Core, ES2, ES3
#if SUPPORT_OPENGL_UNIFIED
#include "Unity/IUnityRenderingExtensions.h"
#include <assert.h>
#if UNITY_IOS || UNITY_TVOS
# include <OpenGLES/ES2/gl.h>
#elif UNITY_ANDROID || UNITY_WEBGL
# include <GLES2/gl2.h>
#include <OpenGLES/ES2/gl.h>
#elif UNITY_ANDROID || UNITY_WEBGL || OHOS
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#if OHOS
#include <xengine/xeg_gles_extension.h>
#include "xengine/xeg_gles_spatial_upscale.h"
#include "xengine/xeg_gles_adaptive_vrs.h"
#include "xengine/xeg_gles_neural_upscale.h"
#include <native_buffer/native_buffer.h>
#include <native_window/external_window.h>
#endif
#elif UNITY_OSX
# include <OpenGL/gl3.h>
#include <OpenGL/gl3.h>
#elif UNITY_WIN
// On Windows, use gl3w to initialize and load OpenGL Core functions. In principle any other
// library (like GLEW, GLFW etc.) can be used; here we use gl3w since it's simple and
// straightforward.
# include "gl3w/gl3w.h"
#include "gl3w/gl3w.h"
#elif UNITY_LINUX
# define GL_GLEXT_PROTOTYPES
# include <GL/gl.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#elif UNITY_EMBEDDED_LINUX
# include <GLES2/gl2.h>
#include <GLES2/gl2.h>
#if SUPPORT_OPENGL_CORE
# define GL_GLEXT_PROTOTYPES
# include <GL/gl.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#endif
#elif UNITY_QNX
# include <GLES2/gl2.h>
#include <GLES2/gl2.h>
#else
# error Unknown platform
#error Unknown platform
#endif
#include <string.h>
extern void unityLog(const char *msg);
typedef void(GL_APIENTRYP PFNGLSHADINGRATE)(GLenum rate);
typedef void (GL_APIENTRYP PFNGLQCOMFRAMEEXTRAPOLATION) (GLuint src1, GLuint src2, GLuint output, float scaleFactor);
class RenderAPI_OpenGLCoreES : public RenderAPI
{
public:
RenderAPI_OpenGLCoreES(UnityGfxRenderer apiType);
virtual ~RenderAPI_OpenGLCoreES() { }
RenderAPI_OpenGLCoreES(UnityGfxRenderer api_type);
virtual ~RenderAPI_OpenGLCoreES() {}
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces *interfaces) override;
virtual bool GetUsesReverseZ() { return false; }
virtual bool getUsesReverseZ() override { return false; }
virtual void DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4);
virtual void enableVRS(int vrsEnum) override;
virtual void disableVRS() override;
virtual void* BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch);
virtual void EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr);
virtual void enableFGExtrapolation() override;
virtual void preFGExtrapolation() override;
virtual bool doFGExtrapolation(void *src, void *data, void *dst) override;
virtual void postFGExtrapolation() override;
virtual void disableFGExtrapolation() override;
virtual void* BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize);
virtual void EndModifyVertexBuffer(void* bufferHandle);
virtual void spatialUpScale(void *src, void *data, void *dst) override;
private:
void CreateResources();
virtual void initSupportFeature() override;
UnityGfxRenderer m_api_type;
PFNGLSHADINGRATE gl_shadingrate_fn = nullptr;
PFNGLQCOMFRAMEEXTRAPOLATION gl_extrapolate_qcom_fn;
private:
UnityGfxRenderer m_APIType;
GLuint m_VertexShader;
GLuint m_FragmentShader;
GLuint m_Program;
GLuint m_VertexArray;
GLuint m_VertexBuffer;
int m_UniformWorldMatrix;
int m_UniformProjMatrix;
};
// 重新定义 vrs rate
/*
QCOM_shading_rate
SHADING_RATE_1X1_PIXELS_QCOM 0x96A6
SHADING_RATE_1X2_PIXELS_QCOM 0x96A7
SHADING_RATE_2X1_PIXELS_QCOM 0x96A8
SHADING_RATE_2X2_PIXELS_QCOM 0x96A9
SHADING_RATE_4X2_PIXELS_QCOM 0x96AC
SHADING_RATE_4X4_PIXELS_QCOM 0x96AE
*/
#define SHADING_RATE_1X1_PIXELS_EXT 0x96A6
#define SHADING_RATE_1X2_PIXELS_EXT 0x96A7
#define SHADING_RATE_2X1_PIXELS_EXT 0x96A8
#define SHADING_RATE_2X2_PIXELS_EXT 0x96A9
#define SHADING_RATE_1X4_PIXELS_EXT 0x96AA
#define SHADING_RATE_4X1_PIXELS_EXT 0x96AB
#define SHADING_RATE_4X2_PIXELS_EXT 0x96AC
#define SHADING_RATE_2X4_PIXELS_EXT 0x96AD
#define SHADING_RATE_4X4_PIXELS_EXT 0x96AE
RenderAPI* CreateRenderAPI_OpenGLCoreES(UnityGfxRenderer apiType)
{
return new RenderAPI_OpenGLCoreES(apiType);
}
enum VertexInputs
{
kVertexInputPosition = 0,
kVertexInputColor = 1
// TODO: glGetFragmentShadingRatesEXT 检查支持的项
static GLenum vrs_argment_size_table[] =
{
SHADING_RATE_1X1_PIXELS_EXT,
SHADING_RATE_2X1_PIXELS_EXT,
SHADING_RATE_1X2_PIXELS_EXT,
SHADING_RATE_2X2_PIXELS_EXT,
SHADING_RATE_4X2_PIXELS_EXT,
SHADING_RATE_2X4_PIXELS_EXT,
SHADING_RATE_4X4_PIXELS_EXT,
// SHADING_RATE_1X4_PIXELS_EXT, //(此硬件原生不支持)
// SHADING_RATE_4X1_PIXELS_EXT,// (此硬件原生不支持)
};
// Simple vertex shader source
#define VERTEX_SHADER_SRC(ver, attr, varying) \
ver \
attr " highp vec3 pos;\n" \
attr " lowp vec4 color;\n" \
"\n" \
varying " lowp vec4 ocolor;\n" \
"\n" \
"uniform highp mat4 worldMatrix;\n" \
"uniform highp mat4 projMatrix;\n" \
"\n" \
"void main()\n" \
"{\n" \
" gl_Position = (projMatrix * worldMatrix) * vec4(pos,1);\n" \
" ocolor = color;\n" \
"}\n" \
static const char* kGlesVProgTextGLES2 = VERTEX_SHADER_SRC("\n", "attribute", "varying");
static const char* kGlesVProgTextGLES3 = VERTEX_SHADER_SRC("#version 300 es\n", "in", "out");
#if SUPPORT_OPENGL_CORE
static const char* kGlesVProgTextGLCore = VERTEX_SHADER_SRC("#version 150\n", "in", "out");
#endif
#undef VERTEX_SHADER_SRC
// Simple fragment shader source
#define FRAGMENT_SHADER_SRC(ver, varying, outDecl, outVar) \
ver \
outDecl \
varying " lowp vec4 ocolor;\n" \
"\n" \
"void main()\n" \
"{\n" \
" " outVar " = ocolor;\n" \
"}\n" \
static const char* kGlesFShaderTextGLES2 = FRAGMENT_SHADER_SRC("\n", "varying", "\n", "gl_FragColor");
static const char* kGlesFShaderTextGLES3 = FRAGMENT_SHADER_SRC("#version 300 es\n", "in", "out lowp vec4 fragColor;\n", "fragColor");
#if SUPPORT_OPENGL_CORE
static const char* kGlesFShaderTextGLCore = FRAGMENT_SHADER_SRC("#version 150\n", "in", "out lowp vec4 fragColor;\n", "fragColor");
#endif
#undef FRAGMENT_SHADER_SRC
static GLuint CreateShader(GLenum type, const char* sourceText)
RenderAPI *CreateRenderAPI_OpenGLCoreES(UnityGfxRenderer api_type)
{
GLuint ret = glCreateShader(type);
glShaderSource(ret, 1, &sourceText, NULL);
glCompileShader(ret);
return ret;
return new RenderAPI_OpenGLCoreES(api_type);
}
void RenderAPI_OpenGLCoreES::CreateResources()
{
# if UNITY_WIN && SUPPORT_OPENGL_CORE
if (m_APIType == kUnityGfxRendererOpenGLCore)
gl3wInit();
# endif
// Make sure that there are no GL error flags set before creating resources
while (glGetError() != GL_NO_ERROR) {}
// Create shaders
if (m_APIType == kUnityGfxRendererOpenGLES30)
{
m_VertexShader = CreateShader(GL_VERTEX_SHADER, kGlesVProgTextGLES2);
m_FragmentShader = CreateShader(GL_FRAGMENT_SHADER, kGlesFShaderTextGLES2);
}
else if (m_APIType == kUnityGfxRendererOpenGLES30)
{
m_VertexShader = CreateShader(GL_VERTEX_SHADER, kGlesVProgTextGLES3);
m_FragmentShader = CreateShader(GL_FRAGMENT_SHADER, kGlesFShaderTextGLES3);
}
# if SUPPORT_OPENGL_CORE
else if (m_APIType == kUnityGfxRendererOpenGLCore)
{
m_VertexShader = CreateShader(GL_VERTEX_SHADER, kGlesVProgTextGLCore);
m_FragmentShader = CreateShader(GL_FRAGMENT_SHADER, kGlesFShaderTextGLCore);
}
# endif // if SUPPORT_OPENGL_CORE
// Link shaders into a program and find uniform locations
m_Program = glCreateProgram();
glBindAttribLocation(m_Program, kVertexInputPosition, "pos");
glBindAttribLocation(m_Program, kVertexInputColor, "color");
glAttachShader(m_Program, m_VertexShader);
glAttachShader(m_Program, m_FragmentShader);
# if SUPPORT_OPENGL_CORE
if (m_APIType == kUnityGfxRendererOpenGLCore)
glBindFragDataLocation(m_Program, 0, "fragColor");
# endif // if SUPPORT_OPENGL_CORE
glLinkProgram(m_Program);
GLint status = 0;
glGetProgramiv(m_Program, GL_LINK_STATUS, &status);
assert(status == GL_TRUE);
m_UniformWorldMatrix = glGetUniformLocation(m_Program, "worldMatrix");
m_UniformProjMatrix = glGetUniformLocation(m_Program, "projMatrix");
// Create vertex buffer
glGenBuffers(1, &m_VertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
glBufferData(GL_ARRAY_BUFFER, 1024, NULL, GL_STREAM_DRAW);
assert(glGetError() == GL_NO_ERROR);
}
RenderAPI_OpenGLCoreES::RenderAPI_OpenGLCoreES(UnityGfxRenderer apiType)
: m_APIType(apiType)
RenderAPI_OpenGLCoreES::RenderAPI_OpenGLCoreES(UnityGfxRenderer api_type)
: m_api_type(api_type)
{
}
void RenderAPI_OpenGLCoreES::ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces)
void RenderAPI_OpenGLCoreES::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces *interfaces)
{
if (type == kUnityGfxDeviceEventInitialize)
{
CreateResources();
initSupportFeature();
}
else if (type == kUnityGfxDeviceEventShutdown)
{
@ -212,103 +139,155 @@ void RenderAPI_OpenGLCoreES::ProcessDeviceEvent(UnityGfxDeviceEventType type, IU
}
}
void RenderAPI_OpenGLCoreES::DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4)
void RenderAPI_OpenGLCoreES::initSupportFeature()
{
// Set basic render state
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
#ifdef GL_EXT_fragment_shading_rate
support_features[GraphicsFeature::VRS_DRAW] = true;
gl_shadingrate_fn = glShadingRateEXT;
#endif // GL_EXT_fragment_shading_rate
// Tweak the projection matrix a bit to make it match what identity projection would do in D3D case.
float projectionMatrix[16] = {
1,0,0,0,
0,1,0,0,
0,0,2,0,
0,0,-1,1,
#ifdef GL_EXT_fragment_shading_rate_primitive
support_features[GraphicsFeature::VRS_PRIMITIVE] = true;
#endif // GL_EXT_fragment_shading_rate_primitive
#ifdef GL_EXT_fragment_shading_rate_attachment
support_features[GraphicsFeature::VRS_ATTACHMENT] = true;
#endif // GL_EXT_fragment_shading_rate_attachment
const char *extensions = (const char *)glGetString(GL_EXTENSIONS);
if (strstr(extensions, "GL_EXT_fragment_shading_rate") || strstr(extensions, "GL_QCOM_shading_rate"))
{
support_features[GraphicsFeature::VRS_DRAW] = true;
}
if (strstr(extensions, "GL_EXT_fragment_shading_rate_primitive"))
{
support_features[GraphicsFeature::VRS_PRIMITIVE] = true;
}
if (strstr(extensions, "GL_EXT_fragment_shading_rate_attachment"))
{
support_features[GraphicsFeature::VRS_ATTACHMENT] = true;
}
if (support_features[GraphicsFeature::VRS_DRAW])
{
if (gl_shadingrate_fn == nullptr)
{
gl_shadingrate_fn = (PFNGLSHADINGRATE)((void *)eglGetProcAddress("glShadingRateQCOM"));
if (gl_shadingrate_fn == nullptr)
{
gl_shadingrate_fn = (PFNGLSHADINGRATE)((void *)eglGetProcAddress("glShadingRateEXT"));
if (gl_shadingrate_fn == nullptr)
{
support_features[GraphicsFeature::VRS_DRAW] = false;
}
}
}
}
if (strstr(extensions, "GL_QCOM_frame_extrapolation"))
{
support_features[GraphicsFeature::QCOM_AFME] = true;
gl_extrapolate_qcom_fn = (PFNGLQCOMFRAMEEXTRAPOLATION)eglGetProcAddress("glExtrapolateTex2DQCOM");
}
#if OHOS
extensions = (const char *)HMS_XEG_GetString(XEG_EXTENSIONS);
if (strstr(extensions, XEG_SPATIAL_UPSCALE_EXTENSION_NAME))
{
support_features[GraphicsFeature::HW_SPATIAL_SR] = true;
}
if (strstr(extensions, XEG_NEURAL_UPSCALE_EXTENSION_NAME))
{
support_features[GraphicsFeature::HW_AISR] = true;
}
if (strstr(extensions, XEG_ADAPTIVE_VRS_EXTENSION_NAME))
{
support_features[GraphicsFeature::HW_ADAPTIVE_VRS] = true;
}
#endif
char buf[40];
for (size_t i = 0; i < GraphicsFeature::MAX_CNT; i++)
{
sprintf(buf, "GraphicsFeature: %d \n", support_features[(GraphicsFeature)i]);
unityLog(buf);
}
}
void RenderAPI_OpenGLCoreES::enableVRS(int vrs_enum)
{
gl_shadingrate_fn(vrs_argment_size_table[vrs_enum]);
}
void RenderAPI_OpenGLCoreES::disableVRS()
{
gl_shadingrate_fn(vrs_argment_size_table[0]);
}
void RenderAPI_OpenGLCoreES::enableFGExtrapolation()
{
}
void RenderAPI_OpenGLCoreES::preFGExtrapolation()
{
}
bool RenderAPI_OpenGLCoreES::doFGExtrapolation(void *src, void *data, void *dst)
{
GLuint gl_src0tex = (GLuint)(size_t)(src);
GLuint gl_src1tex = (GLuint)(size_t)(data);
GLuint gl_dsttex = (GLuint)(size_t)(dst);
gl_extrapolate_qcom_fn(gl_src0tex, gl_src1tex, gl_dsttex, 0.5f);
auto err = glGetError();
return err == GL_NO_ERROR;
}
void RenderAPI_OpenGLCoreES::postFGExtrapolation()
{
}
void RenderAPI_OpenGLCoreES::disableFGExtrapolation()
{
}
void RenderAPI_OpenGLCoreES::spatialUpScale(void *src, void *data, void *dst)
{
#if OHOS
struct HWSpatialSRParam
{
float sharpness;
uint32_t render_width;
uint32_t render_height;
};
// Setup shader program to use, and the matrices
glUseProgram(m_Program);
glUniformMatrix4fv(m_UniformWorldMatrix, 1, GL_FALSE, worldMatrix);
glUniformMatrix4fv(m_UniformProjMatrix, 1, GL_FALSE, projectionMatrix);
// Core profile needs VAOs, setup one
# if SUPPORT_OPENGL_CORE
if (m_APIType == kUnityGfxRendererOpenGLCore)
if (data != NULL)
{
glGenVertexArrays(1, &m_VertexArray);
glBindVertexArray(m_VertexArray);
HWSpatialSRParam* param = (HWSpatialSRParam*) data;
float m_sharpness = param->sharpness;
HMS_XEG_SpatialUpscaleParameter(XEG_SPATIAL_UPSCALE_SHARPNESS, &m_sharpness);
// upscaleScissor为超分输入图像的采样区域
int upscaleScissor[4] = {0, 0, static_cast<int>(param->render_width), static_cast<int>(param->render_height)};
HMS_XEG_SpatialUpscaleParameter(XEG_SPATIAL_UPSCALE_SCISSOR, upscaleScissor);
}
# endif // if SUPPORT_OPENGL_CORE
GLuint gl_srctex = (GLuint)(size_t)(src);
// Bind a vertex buffer, and update data in it
const int kVertexSize = 12 + 4;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, kVertexSize * triangleCount * 3, verticesFloat3Byte4);
// TODO: 测试由上层设置
// GLuint gl_dsttex = (GLuint)(size_t)(dst);
// // upscaleFBO为用户自定义创建的framebuffer
// glBindFramebuffer(GL_FRAMEBUFFER, gl_dsttex);
// glViewport(0, 0, upscale_width, upscale_height);
// glScissor(0, 0, upscale_width, upscale_height);
// Setup vertex layout
glEnableVertexAttribArray(kVertexInputPosition);
glVertexAttribPointer(kVertexInputPosition, 3, GL_FLOAT, GL_FALSE, kVertexSize, (char*)NULL + 0);
glEnableVertexAttribArray(kVertexInputColor);
glVertexAttribPointer(kVertexInputColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, kVertexSize, (char*)NULL + 12);
// Draw
glDrawArrays(GL_TRIANGLES, 0, triangleCount * 3);
// Cleanup VAO
# if SUPPORT_OPENGL_CORE
if (m_APIType == kUnityGfxRendererOpenGLCore)
{
glDeleteVertexArrays(1, &m_VertexArray);
}
# endif
}
void* RenderAPI_OpenGLCoreES::BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch)
{
const int rowPitch = textureWidth * 4;
// Just allocate a system memory buffer here for simplicity
unsigned char* data = new unsigned char[rowPitch * textureHeight];
*outRowPitch = rowPitch;
return data;
}
void RenderAPI_OpenGLCoreES::EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr)
{
GLuint gltex = (GLuint)(size_t)(textureHandle);
// Update texture data, and free the memory buffer
glBindTexture(GL_TEXTURE_2D, gltex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, dataPtr);
delete[](unsigned char*)dataPtr;
}
void* RenderAPI_OpenGLCoreES::BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize)
{
# if SUPPORT_OPENGL_ES
return 0;
# else
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)(size_t)bufferHandle);
GLint size = 0;
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
*outBufferSize = size;
void* mapped = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
return mapped;
# endif
}
void RenderAPI_OpenGLCoreES::EndModifyVertexBuffer(void* bufferHandle)
{
# if !SUPPORT_OPENGL_ES
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)(size_t)bufferHandle);
glUnmapBuffer(GL_ARRAY_BUFFER);
# endif
HMS_XEG_RenderSpatialUpscale(gl_srctex);
#endif
}
#endif // #if SUPPORT_OPENGL_UNIFIED

View File

@ -3,10 +3,11 @@
#if SUPPORT_VULKAN
#include <string.h>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
// This plugin does not link to the Vulkan loader, easier to support multiple APIs and systems that don't have Vulkan support
#define VK_NO_PROTOTYPES
@ -42,15 +43,23 @@
apply(vkCreateDevice); \
apply(vkGetPhysicalDeviceFeatures2); \
apply(vkGetPhysicalDeviceProperties2); \
apply(vkEnumerateDeviceExtensionProperties); \
apply(vkGetPhysicalDeviceProperties2KHR); \
apply(vkDestroyPipelineLayout);
#define VULKAN_DEFINE_API_FUNCPTR(func) static PFN_##func func
VULKAN_DEFINE_API_FUNCPTR(vkGetInstanceProcAddr);
UNITY_USED_VULKAN_API_FUNCTIONS(VULKAN_DEFINE_API_FUNCPTR);
#undef VULKAN_DEFINE_API_FUNCPTR
extern void UnityLog(const char* msg);
#if OHOS
#include "xengine/xeg_vulkan_adaptive_vrs.h"
#include "xengine/xeg_vulkan_spatial_upscale.h"
#include "xengine/xeg_vulkan_extension.h"
#endif
extern void unityLog(const char *msg);
enum VRSPluginShadingRate
{
@ -63,35 +72,37 @@ enum VRSPluginShadingRate
X1_PER_4X4_PIXELS,
};
static VkExtent2D vrs_ragment_size_table[] = {
VkExtent2D(1,1),
VkExtent2D(2,1),
VkExtent2D(1,2),
VkExtent2D(2,2),
VkExtent2D(4,2),
VkExtent2D(2,4),
VkExtent2D(4,4),
static VkExtent2D vrs_argment_size_table[] = {
VkExtent2D{1, 1},
VkExtent2D{2, 1},
VkExtent2D{1, 2},
VkExtent2D{2, 2},
VkExtent2D{4, 2},
VkExtent2D{2, 4},
VkExtent2D{4, 4},
};
static VkExtent2D vrs_fragment_size = vrs_ragment_size_table[0];
static VkExtent2D vrs_fragment_size = vrs_argment_size_table[0];
static bool vrs_enable;
static int index = 0;
static int curVrsIndex = 0;
static void LoadVulkanAPI(PFN_vkGetInstanceProcAddr getInstanceProcAddr, VkInstance instance)
{
UnityLog("LoadVulkanAPI called.");
unityLog("LoadVulkanAPI called.");
if (!vkGetInstanceProcAddr && getInstanceProcAddr)
vkGetInstanceProcAddr = getInstanceProcAddr;
if (!vkCreateInstance)
vkCreateInstance = (PFN_vkCreateInstance)vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateInstance");
#define LOAD_VULKAN_FUNC(fn) if (!fn) fn = (PFN_##fn)vkGetInstanceProcAddr(instance, #fn)
#define LOAD_VULKAN_FUNC(fn) \
if (!fn) \
fn = (PFN_##fn)vkGetInstanceProcAddr(instance, #fn)
UNITY_USED_VULKAN_API_FUNCTIONS(LOAD_VULKAN_FUNC);
#undef LOAD_VULKAN_FUNC
}
static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents)
static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
{
// Change this to 'true' to override the clear color with green
const bool allowOverrideClearColor = false;
@ -117,14 +128,14 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBeginRenderPass(VkCommandBuffer comm
}
}
static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance)
{
UnityLog("Hook_vkCreateInstance called.");
unityLog("Hook_vkCreateInstance called.");
if (pCreateInfo->ppEnabledExtensionNames)
{
for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++)
{
UnityLog(pCreateInfo->ppEnabledExtensionNames[i]);
unityLog(pCreateInfo->ppEnabledExtensionNames[i]);
}
}
@ -137,22 +148,23 @@ static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateInstance(const VkInstanceCrea
return result;
}
static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
static VKAPI_ATTR VkResult VKAPI_CALL Hook_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice)
{
if (pCreateInfo->pNext)
{
UnityLog("pCreateInfo->pNext");
unityLog("pCreateInfo->pNext");
}
return vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
}
static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
VkPipelineLayout layout, uint32_t firstSet,
uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets,
uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets,
uint32_t dynamicOffsetCount, const uint32_t *pDynamicOffsets)
{
if (vrs_enable)
{
VkExtent2D fragment_size = vrs_ragment_size_table[index];
VkExtent2D fragment_size = vrs_argment_size_table[curVrsIndex];
VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
// If shading rate from attachment is enabled, we set the combiner, so that the values from the attachment are used
@ -160,7 +172,6 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindDescriptorSets(VkCommandBuffer c
combiner_ops[0] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR;
// Combiner for pipeline (A) and attachment (B), replace the pipeline default value (fragment_size) with the fragment sizes stored in the attachment
combiner_ops[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR;
vkCmdSetFragmentShadingRateKHR(commandBuffer, &fragment_size, combiner_ops);
}
@ -169,9 +180,9 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindDescriptorSets(VkCommandBuffer c
static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
{
//if (vrs_enable)
// if (vrs_enable)
//{
// VkExtent2D fragment_size = vrs_ragment_size_table[index];
// VkExtent2D fragment_size = vrs_argment_size_table[curVrsIndex];
// VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
// // If shading rate from attachment is enabled, we set the combiner, so that the values from the attachment are used
@ -186,11 +197,11 @@ static VKAPI_ATTR void VKAPI_CALL Hook_vkCmdBindPipeline(VkCommandBuffer command
vkCmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
}
static int FindMemoryTypeIndex(VkPhysicalDeviceMemoryProperties const & physicalDeviceMemoryProperties, VkMemoryRequirements const & memoryRequirements, VkMemoryPropertyFlags memoryPropertyFlags)
static int FindMemoryTypeIndex(VkPhysicalDeviceMemoryProperties const &physicalDeviceMemoryProperties, VkMemoryRequirements const &memoryRequirements, VkMemoryPropertyFlags memoryPropertyFlags)
{
uint32_t memoryTypeBits = memoryRequirements.memoryTypeBits;
// Search memtypes to find first index with those properties
// Search memtypes to find first curVrsIndex with those properties
for (uint32_t memoryTypeIndex = 0; memoryTypeIndex < VK_MAX_MEMORY_TYPES; ++memoryTypeIndex)
{
if ((memoryTypeBits & 1) == 1)
@ -205,12 +216,14 @@ static int FindMemoryTypeIndex(VkPhysicalDeviceMemoryProperties const & physical
return -1;
}
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL Hook_vkGetInstanceProcAddr(VkInstance device, const char* funcName)
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL Hook_vkGetInstanceProcAddr(VkInstance device, const char *funcName)
{
if (!funcName)
return NULL;
UnityLog(funcName);
#define INTERCEPT(fn) if (strcmp(funcName, #fn) == 0) return (PFN_vkVoidFunction)&Hook_##fn
unityLog(funcName);
#define INTERCEPT(fn) \
if (strcmp(funcName, #fn) == 0) \
return (PFN_vkVoidFunction) & Hook_##fn
INTERCEPT(vkCreateInstance);
INTERCEPT(vkCreateDevice);
INTERCEPT(vkCmdBindPipeline);
@ -220,19 +233,19 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL Hook_vkGetInstanceProcAddr(VkIns
return (PFN_vkVoidFunction)vkGetInstanceProcAddr(device, funcName);
}
static PFN_vkGetInstanceProcAddr UNITY_INTERFACE_API InterceptVulkanInitialization(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void*)
static PFN_vkGetInstanceProcAddr UNITY_INTERFACE_API InterceptVulkanInitialization(PFN_vkGetInstanceProcAddr getInstanceProcAddr, void *)
{
vkGetInstanceProcAddr = getInstanceProcAddr;
return Hook_vkGetInstanceProcAddr;
}
extern "C" void RenderAPI_Vulkan_OnPluginLoad(IUnityInterfaces* interfaces)
extern "C" void RenderAPI_Vulkan_OnPluginLoad(IUnityInterfaces *interfaces)
{
if (IUnityGraphicsVulkanV2* vulkanInterface = interfaces->Get<IUnityGraphicsVulkanV2>())
if (IUnityGraphicsVulkanV2 *vulkanInterface = interfaces->Get<IUnityGraphicsVulkanV2>())
{
vulkanInterface->AddInterceptInitialization(InterceptVulkanInitialization, NULL, 0);
}
else if (IUnityGraphicsVulkan* vulkanInterface = interfaces->Get<IUnityGraphicsVulkan>())
else if (IUnityGraphicsVulkan *vulkanInterface = interfaces->Get<IUnityGraphicsVulkan>())
{
vulkanInterface->InterceptInitialization(InterceptVulkanInitialization, NULL);
}
@ -242,401 +255,99 @@ struct VulkanBuffer
{
VkBuffer buffer;
VkDeviceMemory deviceMemory;
void* mapped;
void *mapped;
VkDeviceSize sizeInBytes;
VkDeviceSize deviceMemorySize;
VkMemoryPropertyFlags deviceMemoryFlags;
};
static VkPipelineLayout CreateTrianglePipelineLayout(VkDevice device)
{
VkPushConstantRange pushConstantRange;
pushConstantRange.offset = 0;
pushConstantRange.size = 64; // single matrix
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = {};
pipelineLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutCreateInfo.pPushConstantRanges = &pushConstantRange;
pipelineLayoutCreateInfo.pushConstantRangeCount = 1;
VkPipelineLayout pipelineLayout;
return vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, NULL, &pipelineLayout) == VK_SUCCESS ? pipelineLayout : VK_NULL_HANDLE;
}
namespace Shader {
// Source of vertex shader (filename: shader.vert)
/*
#version 310 es
layout(location = 0) in highp vec3 vpos;
layout(location = 1) in highp vec4 vcol;
layout(location = 0) out highp vec4 color;
layout(push_constant) uniform PushConstants { mat4 matrix; };
void main() {
gl_Position = matrix * vec4(vpos, 1.0);
color = vcol;
}
*/
// Source of fragment shader (filename: shader.frag)
/*
#version 310 es
layout(location = 0) out highp vec4 fragColor;
layout(location = 0) in highp vec4 color;
void main() { fragColor = color; }
*/
// compiled to SPIR-V using:
// %VULKAN_SDK%\bin\glslc -mfmt=num shader.frag shader.vert -c
const uint32_t vertexShaderSpirv[] = {
0x07230203,0x00010000,0x000d0007,0x00000024,
0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,
0x00000000,0x0003000e,0x00000000,0x00000001,
0x0009000f,0x00000000,0x00000004,0x6e69616d,
0x00000000,0x0000000a,0x00000016,0x00000020,
0x00000022,0x00030003,0x00000001,0x00000136,
0x000a0004,0x475f4c47,0x4c474f4f,0x70635f45,
0x74735f70,0x5f656c79,0x656e696c,0x7269645f,
0x69746365,0x00006576,0x00080004,0x475f4c47,
0x4c474f4f,0x6e695f45,0x64756c63,0x69645f65,
0x74636572,0x00657669,0x00040005,0x00000004,
0x6e69616d,0x00000000,0x00060005,0x00000008,
0x505f6c67,0x65567265,0x78657472,0x00000000,
0x00060006,0x00000008,0x00000000,0x505f6c67,
0x7469736f,0x006e6f69,0x00070006,0x00000008,
0x00000001,0x505f6c67,0x746e696f,0x657a6953,
0x00000000,0x00030005,0x0000000a,0x00000000,
0x00060005,0x0000000e,0x68737550,0x736e6f43,
0x746e6174,0x00000073,0x00050006,0x0000000e,
0x00000000,0x7274616d,0x00007869,0x00030005,
0x00000010,0x00000000,0x00040005,0x00000016,
0x736f7076,0x00000000,0x00040005,0x00000020,
0x6f6c6f63,0x00000072,0x00040005,0x00000022,
0x6c6f6376,0x00000000,0x00050048,0x00000008,
0x00000000,0x0000000b,0x00000000,0x00050048,
0x00000008,0x00000001,0x0000000b,0x00000001,
0x00030047,0x00000008,0x00000002,0x00040048,
0x0000000e,0x00000000,0x00000005,0x00050048,
0x0000000e,0x00000000,0x00000023,0x00000000,
0x00050048,0x0000000e,0x00000000,0x00000007,
0x00000010,0x00030047,0x0000000e,0x00000002,
0x00040047,0x00000016,0x0000001e,0x00000000,
0x00040047,0x00000020,0x0000001e,0x00000000,
0x00040047,0x00000022,0x0000001e,0x00000001,
0x00020013,0x00000002,0x00030021,0x00000003,
0x00000002,0x00030016,0x00000006,0x00000020,
0x00040017,0x00000007,0x00000006,0x00000004,
0x0004001e,0x00000008,0x00000007,0x00000006,
0x00040020,0x00000009,0x00000003,0x00000008,
0x0004003b,0x00000009,0x0000000a,0x00000003,
0x00040015,0x0000000b,0x00000020,0x00000001,
0x0004002b,0x0000000b,0x0000000c,0x00000000,
0x00040018,0x0000000d,0x00000007,0x00000004,
0x0003001e,0x0000000e,0x0000000d,0x00040020,
0x0000000f,0x00000009,0x0000000e,0x0004003b,
0x0000000f,0x00000010,0x00000009,0x00040020,
0x00000011,0x00000009,0x0000000d,0x00040017,
0x00000014,0x00000006,0x00000003,0x00040020,
0x00000015,0x00000001,0x00000014,0x0004003b,
0x00000015,0x00000016,0x00000001,0x0004002b,
0x00000006,0x00000018,0x3f800000,0x00040020,
0x0000001e,0x00000003,0x00000007,0x0004003b,
0x0000001e,0x00000020,0x00000003,0x00040020,
0x00000021,0x00000001,0x00000007,0x0004003b,
0x00000021,0x00000022,0x00000001,0x00050036,
0x00000002,0x00000004,0x00000000,0x00000003,
0x000200f8,0x00000005,0x00050041,0x00000011,
0x00000012,0x00000010,0x0000000c,0x0004003d,
0x0000000d,0x00000013,0x00000012,0x0004003d,
0x00000014,0x00000017,0x00000016,0x00050051,
0x00000006,0x00000019,0x00000017,0x00000000,
0x00050051,0x00000006,0x0000001a,0x00000017,
0x00000001,0x00050051,0x00000006,0x0000001b,
0x00000017,0x00000002,0x00070050,0x00000007,
0x0000001c,0x00000019,0x0000001a,0x0000001b,
0x00000018,0x00050091,0x00000007,0x0000001d,
0x00000013,0x0000001c,0x00050041,0x0000001e,
0x0000001f,0x0000000a,0x0000000c,0x0003003e,
0x0000001f,0x0000001d,0x0004003d,0x00000007,
0x00000023,0x00000022,0x0003003e,0x00000020,
0x00000023,0x000100fd,0x00010038
};
const uint32_t fragmentShaderSpirv[] = {
0x07230203,0x00010000,0x000d0006,0x0000000d,
0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,
0x00000000,0x0003000e,0x00000000,0x00000001,
0x0007000f,0x00000004,0x00000004,0x6e69616d,
0x00000000,0x00000009,0x0000000b,0x00030010,
0x00000004,0x00000007,0x00030003,0x00000001,
0x00000136,0x000a0004,0x475f4c47,0x4c474f4f,
0x70635f45,0x74735f70,0x5f656c79,0x656e696c,
0x7269645f,0x69746365,0x00006576,0x00080004,
0x475f4c47,0x4c474f4f,0x6e695f45,0x64756c63,
0x69645f65,0x74636572,0x00657669,0x00040005,
0x00000004,0x6e69616d,0x00000000,0x00050005,
0x00000009,0x67617266,0x6f6c6f43,0x00000072,
0x00040005,0x0000000b,0x6f6c6f63,0x00000072,
0x00040047,0x00000009,0x0000001e,0x00000000,
0x00040047,0x0000000b,0x0000001e,0x00000000,
0x00020013,0x00000002,0x00030021,0x00000003,
0x00000002,0x00030016,0x00000006,0x00000020,
0x00040017,0x00000007,0x00000006,0x00000004,
0x00040020,0x00000008,0x00000003,0x00000007,
0x0004003b,0x00000008,0x00000009,0x00000003,
0x00040020,0x0000000a,0x00000001,0x00000007,
0x0004003b,0x0000000a,0x0000000b,0x00000001,
0x00050036,0x00000002,0x00000004,0x00000000,
0x00000003,0x000200f8,0x00000005,0x0004003d,
0x00000007,0x0000000c,0x0000000b,0x0003003e,
0x00000009,0x0000000c,0x000100fd,0x00010038
};
} // namespace Shader
static VkPipeline CreateTrianglePipeline(VkDevice device, VkPipelineLayout pipelineLayout, VkRenderPass renderPass, VkPipelineCache pipelineCache)
{
if (pipelineLayout == VK_NULL_HANDLE)
return VK_NULL_HANDLE;
if (device == VK_NULL_HANDLE)
return VK_NULL_HANDLE;
if (renderPass == VK_NULL_HANDLE)
return VK_NULL_HANDLE;
bool success = true;
VkGraphicsPipelineCreateInfo pipelineCreateInfo = {};
VkPipelineShaderStageCreateInfo shaderStages[2] = {};
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
shaderStages[0].pName = "main";
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
shaderStages[1].pName = "main";
if (success)
{
VkShaderModuleCreateInfo moduleCreateInfo = {};
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.codeSize = sizeof(Shader::vertexShaderSpirv);
moduleCreateInfo.pCode = Shader::vertexShaderSpirv;
success = vkCreateShaderModule(device, &moduleCreateInfo, NULL, &shaderStages[0].module) == VK_SUCCESS;
}
if (success)
{
VkShaderModuleCreateInfo moduleCreateInfo = {};
moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCreateInfo.codeSize = sizeof(Shader::fragmentShaderSpirv);
moduleCreateInfo.pCode = Shader::fragmentShaderSpirv;
success = vkCreateShaderModule(device, &moduleCreateInfo, NULL, &shaderStages[1].module) == VK_SUCCESS;
}
VkPipeline pipeline;
if (success)
{
pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineCreateInfo.layout = pipelineLayout;
pipelineCreateInfo.renderPass = renderPass;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = {};
inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
VkPipelineRasterizationStateCreateInfo rasterizationState = {};
rasterizationState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterizationState.polygonMode = VK_POLYGON_MODE_FILL;
rasterizationState.cullMode = VK_CULL_MODE_NONE;
rasterizationState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
rasterizationState.depthClampEnable = VK_FALSE;
rasterizationState.rasterizerDiscardEnable = VK_FALSE;
rasterizationState.depthBiasEnable = VK_FALSE;
rasterizationState.lineWidth = 1.0f;
VkPipelineColorBlendAttachmentState blendAttachmentState[1] = {};
blendAttachmentState[0].colorWriteMask = 0xf;
blendAttachmentState[0].blendEnable = VK_FALSE;
VkPipelineColorBlendStateCreateInfo colorBlendState = {};
colorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlendState.attachmentCount = 1;
colorBlendState.pAttachments = blendAttachmentState;
VkPipelineViewportStateCreateInfo viewportState = {};
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportState.viewportCount = 1;
viewportState.scissorCount = 1;
const VkDynamicState dynamicStateEnables[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_FRAGMENT_SHADING_RATE_KHR };
VkPipelineDynamicStateCreateInfo dynamicState = {};
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dynamicState.pDynamicStates = dynamicStateEnables;
dynamicState.dynamicStateCount = sizeof(dynamicStateEnables) / sizeof(*dynamicStateEnables);
VkPipelineDepthStencilStateCreateInfo depthStencilState = {};
depthStencilState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
depthStencilState.depthTestEnable = VK_TRUE;
depthStencilState.depthWriteEnable = VK_TRUE;
depthStencilState.depthBoundsTestEnable = VK_FALSE;
depthStencilState.stencilTestEnable = VK_FALSE;
depthStencilState.depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL; // Unity/Vulkan uses reverse Z
depthStencilState.back.failOp = VK_STENCIL_OP_KEEP;
depthStencilState.back.passOp = VK_STENCIL_OP_KEEP;
depthStencilState.back.compareOp = VK_COMPARE_OP_ALWAYS;
depthStencilState.front = depthStencilState.back;
VkPipelineMultisampleStateCreateInfo multisampleState = {};
multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
multisampleState.pSampleMask = NULL;
// Vertex:
// float3 vpos;
// byte4 vcol;
VkVertexInputBindingDescription vertexInputBinding = {};
vertexInputBinding.binding = 0;
vertexInputBinding.stride = 16;
vertexInputBinding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
VkVertexInputAttributeDescription vertexInputAttributes[2];
vertexInputAttributes[0].binding = 0;
vertexInputAttributes[0].location = 0;
vertexInputAttributes[0].format = VK_FORMAT_R32G32B32_SFLOAT;
vertexInputAttributes[0].offset = 0;
vertexInputAttributes[1].binding = 0;
vertexInputAttributes[1].location = 1;
vertexInputAttributes[1].format = VK_FORMAT_R8G8B8A8_UNORM;
vertexInputAttributes[1].offset = 12;
VkPipelineVertexInputStateCreateInfo vertexInputState = {};
vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputState.vertexBindingDescriptionCount = 1;
vertexInputState.pVertexBindingDescriptions = &vertexInputBinding;
vertexInputState.vertexAttributeDescriptionCount = 2;
vertexInputState.pVertexAttributeDescriptions = vertexInputAttributes;
pipelineCreateInfo.stageCount = sizeof(shaderStages) / sizeof(*shaderStages);
pipelineCreateInfo.pStages = shaderStages;
pipelineCreateInfo.pVertexInputState = &vertexInputState;
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
pipelineCreateInfo.pRasterizationState = &rasterizationState;
pipelineCreateInfo.pColorBlendState = &colorBlendState;
pipelineCreateInfo.pMultisampleState = &multisampleState;
pipelineCreateInfo.pViewportState = &viewportState;
pipelineCreateInfo.pDepthStencilState = &depthStencilState;
pipelineCreateInfo.pDynamicState = &dynamicState;
success = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, NULL, &pipeline) == VK_SUCCESS;
}
if (shaderStages[0].module != VK_NULL_HANDLE)
vkDestroyShaderModule(device, shaderStages[0].module, NULL);
if (shaderStages[1].module != VK_NULL_HANDLE)
vkDestroyShaderModule(device, shaderStages[1].module, NULL);
return success ? pipeline : VK_NULL_HANDLE;
}
class RenderAPI_Vulkan : public RenderAPI
{
public:
RenderAPI_Vulkan();
virtual ~RenderAPI_Vulkan() { }
virtual ~RenderAPI_Vulkan() {}
virtual void processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces *interfaces) override;
virtual bool getUsesReverseZ() override { return true; }
virtual void enableVRS(int vrsEnum) override;
virtual void disableVRS() override;
virtual void enableFGExtrapolation() override;
virtual void preFGExtrapolation() override;
virtual bool doFGExtrapolation(void *src, void *data, void *dst) override;
virtual void postFGExtrapolation() override;
virtual void disableFGExtrapolation() override;
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces);
virtual bool GetUsesReverseZ() { return true; }
virtual void DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4);
virtual void* BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch);
virtual void EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr);
virtual void* BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize);
virtual void EndModifyVertexBuffer(void* bufferHandle);
virtual void enableVRS(int vrsEnum);
virtual void disableVRS();
private:
typedef std::vector<VulkanBuffer> VulkanBuffers;
typedef std::map<unsigned long long, VulkanBuffers> DeleteQueue;
private:
bool CreateVulkanBuffer(size_t bytes, VulkanBuffer* buffer, VkBufferUsageFlags usage);
void ImmediateDestroyVulkanBuffer(const VulkanBuffer& buffer);
void SafeDestroy(unsigned long long frameNumber, const VulkanBuffer& buffer);
void GarbageCollect(bool force = false);
bool createVulkanBuffer(size_t bytes, VulkanBuffer *buffer, VkBufferUsageFlags usage);
void immediateDestroyVulkanBuffer(const VulkanBuffer &buffer);
void safeDestroy(unsigned long long frameNumber, const VulkanBuffer &buffer);
void garbageCollect(bool force = false);
virtual void initSupportFeature() override;
private:
IUnityGraphicsVulkan* m_UnityVulkan;
UnityVulkanInstance m_Instance;
VulkanBuffer m_TextureStagingBuffer;
VulkanBuffer m_VertexStagingBuffer;
IUnityGraphicsVulkan *unity_vulkan;
UnityVulkanInstance unity_vk_instance;
std::map<unsigned long long, VulkanBuffers> m_DeleteQueue;
VkPipelineLayout m_TrianglePipelineLayout;
VkPipeline m_TrianglePipeline;
VkRenderPass m_TrianglePipelineRenderPass;
};
RenderAPI* CreateRenderAPI_Vulkan()
RenderAPI *CreateRenderAPI_Vulkan()
{
return new RenderAPI_Vulkan();
}
RenderAPI_Vulkan::RenderAPI_Vulkan()
: m_UnityVulkan(NULL)
, m_TextureStagingBuffer()
, m_VertexStagingBuffer()
, m_TrianglePipelineLayout(VK_NULL_HANDLE)
, m_TrianglePipeline(VK_NULL_HANDLE)
, m_TrianglePipelineRenderPass(VK_NULL_HANDLE)
: unity_vulkan(NULL)
{
}
void RenderAPI_Vulkan::ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces)
void RenderAPI_Vulkan::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces *interfaces)
{
switch (type)
{
case kUnityGfxDeviceEventInitialize:
UnityLog("ProcessDeviceEvent called. kUnityGfxDeviceEventInitialize");
unityLog("ProcessDeviceEvent called. kUnityGfxDeviceEventInitialize");
m_UnityVulkan = interfaces->Get<IUnityGraphicsVulkan>();
m_Instance = m_UnityVulkan->Instance();
unity_vulkan = interfaces->Get<IUnityGraphicsVulkan>();
unity_vk_instance = unity_vulkan->Instance();
// Make sure Vulkan API functions are loaded
LoadVulkanAPI(m_Instance.getInstanceProcAddr, m_Instance.instance);
LoadVulkanAPI(unity_vk_instance.getInstanceProcAddr, unity_vk_instance.instance);
UnityVulkanPluginEventConfig config_1;
config_1.graphicsQueueAccess = kUnityVulkanGraphicsQueueAccess_DontCare;
config_1.renderPassPrecondition = kUnityVulkanRenderPass_EnsureInside;
config_1.flags = kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState;
m_UnityVulkan->ConfigureEvent(1, &config_1);
unity_vulkan->ConfigureEvent(1, &config_1);
// alternative way to intercept API
m_UnityVulkan->InterceptVulkanAPI("vkCmdBeginRenderPass", (PFN_vkVoidFunction)Hook_vkCmdBeginRenderPass);
unity_vulkan->InterceptVulkanAPI("vkCmdBeginRenderPass", (PFN_vkVoidFunction)Hook_vkCmdBeginRenderPass);
initSupportFeature();
break;
case kUnityGfxDeviceEventShutdown:
UnityLog("ProcessDeviceEvent called. kUnityGfxDeviceEventShutdown");
unityLog("ProcessDeviceEvent called. kUnityGfxDeviceEventShutdown");
if (m_Instance.device != VK_NULL_HANDLE)
if (unity_vk_instance.device != VK_NULL_HANDLE)
{
GarbageCollect(true);
if (m_TrianglePipeline != VK_NULL_HANDLE)
{
vkDestroyPipeline(m_Instance.device, m_TrianglePipeline, NULL);
m_TrianglePipeline = VK_NULL_HANDLE;
}
if (m_TrianglePipelineLayout != VK_NULL_HANDLE)
{
vkDestroyPipelineLayout(m_Instance.device, m_TrianglePipelineLayout, NULL);
m_TrianglePipelineLayout = VK_NULL_HANDLE;
}
garbageCollect(true);
}
m_UnityVulkan = NULL;
m_TrianglePipelineRenderPass = VK_NULL_HANDLE;
m_Instance = UnityVulkanInstance();
unity_vulkan = NULL;
unity_vk_instance = UnityVulkanInstance();
break;
default:
break;
}
}
bool RenderAPI_Vulkan::CreateVulkanBuffer(size_t sizeInBytes, VulkanBuffer* buffer, VkBufferUsageFlags usage)
bool RenderAPI_Vulkan::createVulkanBuffer(size_t sizeInBytes, VulkanBuffer *buffer, VkBufferUsageFlags usage)
{
if (sizeInBytes == 0)
return false;
@ -644,7 +355,7 @@ bool RenderAPI_Vulkan::CreateVulkanBuffer(size_t sizeInBytes, VulkanBuffer* buff
VkBufferCreateInfo bufferCreateInfo;
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferCreateInfo.pNext = NULL;
bufferCreateInfo.pQueueFamilyIndices = &m_Instance.queueFamilyIndex;
bufferCreateInfo.pQueueFamilyIndices = &unity_vk_instance.queueFamilyIndex;
bufferCreateInfo.queueFamilyIndexCount = 1;
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
bufferCreateInfo.usage = usage;
@ -653,19 +364,19 @@ bool RenderAPI_Vulkan::CreateVulkanBuffer(size_t sizeInBytes, VulkanBuffer* buff
*buffer = VulkanBuffer();
if (vkCreateBuffer(m_Instance.device, &bufferCreateInfo, NULL, &buffer->buffer) != VK_SUCCESS)
if (vkCreateBuffer(unity_vk_instance.device, &bufferCreateInfo, NULL, &buffer->buffer) != VK_SUCCESS)
return false;
VkPhysicalDeviceMemoryProperties physicalDeviceProperties;
vkGetPhysicalDeviceMemoryProperties(m_Instance.physicalDevice, &physicalDeviceProperties);
vkGetPhysicalDeviceMemoryProperties(unity_vk_instance.physicalDevice, &physicalDeviceProperties);
VkMemoryRequirements memoryRequirements;
vkGetBufferMemoryRequirements(m_Instance.device, buffer->buffer, &memoryRequirements);
vkGetBufferMemoryRequirements(unity_vk_instance.device, buffer->buffer, &memoryRequirements);
const int memoryTypeIndex = FindMemoryTypeIndex(physicalDeviceProperties, memoryRequirements, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
if (memoryTypeIndex < 0)
{
ImmediateDestroyVulkanBuffer(*buffer);
immediateDestroyVulkanBuffer(*buffer);
return false;
}
@ -675,21 +386,21 @@ bool RenderAPI_Vulkan::CreateVulkanBuffer(size_t sizeInBytes, VulkanBuffer* buff
memoryAllocateInfo.memoryTypeIndex = memoryTypeIndex;
memoryAllocateInfo.allocationSize = memoryRequirements.size;
if (vkAllocateMemory(m_Instance.device, &memoryAllocateInfo, NULL, &buffer->deviceMemory) != VK_SUCCESS)
if (vkAllocateMemory(unity_vk_instance.device, &memoryAllocateInfo, NULL, &buffer->deviceMemory) != VK_SUCCESS)
{
ImmediateDestroyVulkanBuffer(*buffer);
immediateDestroyVulkanBuffer(*buffer);
return false;
}
if (vkMapMemory(m_Instance.device, buffer->deviceMemory, 0, VK_WHOLE_SIZE, 0, &buffer->mapped) != VK_SUCCESS)
if (vkMapMemory(unity_vk_instance.device, buffer->deviceMemory, 0, VK_WHOLE_SIZE, 0, &buffer->mapped) != VK_SUCCESS)
{
ImmediateDestroyVulkanBuffer(*buffer);
immediateDestroyVulkanBuffer(*buffer);
return false;
}
if (vkBindBufferMemory(m_Instance.device, buffer->buffer, buffer->deviceMemory, 0) != VK_SUCCESS)
if (vkBindBufferMemory(unity_vk_instance.device, buffer->buffer, buffer->deviceMemory, 0) != VK_SUCCESS)
{
ImmediateDestroyVulkanBuffer(*buffer);
immediateDestroyVulkanBuffer(*buffer);
return false;
}
@ -700,31 +411,29 @@ bool RenderAPI_Vulkan::CreateVulkanBuffer(size_t sizeInBytes, VulkanBuffer* buff
return true;
}
void RenderAPI_Vulkan::ImmediateDestroyVulkanBuffer(const VulkanBuffer& buffer)
void RenderAPI_Vulkan::immediateDestroyVulkanBuffer(const VulkanBuffer &buffer)
{
if (buffer.buffer != VK_NULL_HANDLE)
vkDestroyBuffer(m_Instance.device, buffer.buffer, NULL);
vkDestroyBuffer(unity_vk_instance.device, buffer.buffer, NULL);
if (buffer.mapped && buffer.deviceMemory != VK_NULL_HANDLE)
vkUnmapMemory(m_Instance.device, buffer.deviceMemory);
vkUnmapMemory(unity_vk_instance.device, buffer.deviceMemory);
if (buffer.deviceMemory != VK_NULL_HANDLE)
vkFreeMemory(m_Instance.device, buffer.deviceMemory, NULL);
vkFreeMemory(unity_vk_instance.device, buffer.deviceMemory, NULL);
}
void RenderAPI_Vulkan::SafeDestroy(unsigned long long frameNumber, const VulkanBuffer& buffer)
void RenderAPI_Vulkan::safeDestroy(unsigned long long frameNumber, const VulkanBuffer &buffer)
{
m_DeleteQueue[frameNumber].push_back(buffer);
}
void RenderAPI_Vulkan::GarbageCollect(bool force /*= false*/)
void RenderAPI_Vulkan::garbageCollect(bool force /*= false*/)
{
UnityVulkanRecordingState recordingState;
if (force)
recordingState.safeFrameNumber = ~0ull;
else
if (!m_UnityVulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
else if (!unity_vulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
return;
DeleteQueue::iterator it = m_DeleteQueue.begin();
@ -733,7 +442,7 @@ void RenderAPI_Vulkan::GarbageCollect(bool force /*= false*/)
if (it->first <= recordingState.safeFrameNumber)
{
for (size_t i = 0; i < it->second.size(); ++i)
ImmediateDestroyVulkanBuffer(it->second[i]);
immediateDestroyVulkanBuffer(it->second[i]);
m_DeleteQueue.erase(it++);
}
else
@ -741,13 +450,70 @@ void RenderAPI_Vulkan::GarbageCollect(bool force /*= false*/)
}
}
#if OHOS
void checkXEngine(VkPhysicalDevice physic_device, SupportFeatureList &fl)
{
std::vector<std::string> supported_extensions;
uint32_t property_cnt;
HMS_XEG_EnumerateDeviceExtensionProperties(physic_device, &property_cnt, nullptr);
if (property_cnt > 0)
{
std::vector<XEG_ExtensionProperties> properties(property_cnt);
if (HMS_XEG_EnumerateDeviceExtensionProperties(physic_device, &property_cnt,
&properties.front()) == VK_SUCCESS)
{
for (auto ext : properties)
{
supported_extensions.push_back(ext.extensionName);
}
}
}
if (std::find(supported_extensions.begin(), supported_extensions.end(), XEG_SPATIAL_UPSCALE_EXTENSION_NAME) !=
supported_extensions.end())
{
fl[GraphicsFeature::HW_SPATIAL_SR] = true;
}
if (std::find(supported_extensions.begin(), supported_extensions.end(), XEG_ADAPTIVE_VRS_EXTENSION_NAME) !=
supported_extensions.end())
{
fl[GraphicsFeature::HW_ADAPTIVE_VRS] = true;
}
}
#endif
void RenderAPI_Vulkan::initSupportFeature()
{
auto physic_device = unity_vk_instance.physicalDevice;
uint32_t extension_cnt;
vkEnumerateDeviceExtensionProperties(physic_device, nullptr, &extension_cnt, nullptr);
std::vector<VkExtensionProperties> available_extensions(extension_cnt);
vkEnumerateDeviceExtensionProperties(physic_device, nullptr, &extension_cnt, available_extensions.data());
VkPhysicalDeviceFragmentShadingRateFeaturesKHR vrs_feature{};
vrs_feature.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR;
VkPhysicalDeviceFeatures2 features2{};
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features2.pNext = &vrs_feature;
vkGetPhysicalDeviceFeatures2(physic_device, &features2);
support_features[GraphicsFeature::VRS_DRAW] = vrs_feature.pipelineFragmentShadingRate;
support_features[GraphicsFeature::VRS_PRIMITIVE] = vrs_feature.primitiveFragmentShadingRate;
support_features[GraphicsFeature::VRS_ATTACHMENT] = vrs_feature.attachmentFragmentShadingRate;
#if OHOS
checkXEngine(physic_device, support_features);
#endif
// char buf[40];
// sprintf(buf, "initSupportFeature VRS %d %d %d \n", (int)support_vrs_draw, (int)support_vrs_primitive, (int)support_vrs_attachment);
// unityLog(buf);
}
void RenderAPI_Vulkan::enableVRS(int vrsEnum)
{
char msg[20];
sprintf(msg, "vrs:%d\0", vrsEnum);
UnityLog(msg);
index = vrsEnum;
vrs_fragment_size = vrs_ragment_size_table[vrsEnum];
curVrsIndex = vrsEnum;
vrs_fragment_size = vrs_argment_size_table[vrsEnum];
vrs_enable = true;
}
@ -756,156 +522,34 @@ void RenderAPI_Vulkan::disableVRS()
vrs_enable = false;
}
void RenderAPI_Vulkan::DrawSimpleTriangles(const float worldMatrix[16], int triangleCount, const void* verticesFloat3Byte4)
void RenderAPI_Vulkan::enableFGExtrapolation()
{
// not needed, we already configured the event to be inside a render pass
// m_UnityVulkan->EnsureInsideRenderPass();
UnityVulkanRecordingState recordingState;
if (!m_UnityVulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
return;
// Unity does not destroy render passes, so this is safe regarding ABA-problem
if (recordingState.renderPass != m_TrianglePipelineRenderPass)
{
if (m_TrianglePipelineLayout == VK_NULL_HANDLE)
m_TrianglePipelineLayout = CreateTrianglePipelineLayout(m_Instance.device);
m_TrianglePipeline = CreateTrianglePipeline(m_Instance.device, m_TrianglePipelineLayout, recordingState.renderPass, VK_NULL_HANDLE);
m_TrianglePipelineRenderPass = recordingState.renderPass;
}
VkExtent2D fragment_size = { 2, 2 };
VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
// If shading rate from attachment is enabled, we set the combiner, so that the values from the attachment are used
// Combiner for pipeline (A) and primitive (B) - Not used in this sample
combiner_ops[0] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR;
// Combiner for pipeline (A) and attachment (B), replace the pipeline default value (fragment_size) with the fragment sizes stored in the attachment
combiner_ops[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_KHR;
vkCmdSetFragmentShadingRateKHR(recordingState.commandBuffer, &fragment_size, combiner_ops);
if (m_TrianglePipeline != VK_NULL_HANDLE && m_TrianglePipelineLayout != VK_NULL_HANDLE)
{
VulkanBuffer buffer;
if (!CreateVulkanBuffer(16 * 3 * triangleCount, &buffer, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT))
return;
memcpy(buffer.mapped, verticesFloat3Byte4, static_cast<size_t>(buffer.sizeInBytes));
if (!(buffer.deviceMemoryFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
{
VkMappedMemoryRange range;
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range.pNext = NULL;
range.memory = buffer.deviceMemory;
range.offset = 0;
range.size = buffer.deviceMemorySize;
vkFlushMappedMemoryRanges(m_Instance.device, 1, &range);
}
const VkDeviceSize offset = 0;
vkCmdBindVertexBuffers(recordingState.commandBuffer, 0, 1, &buffer.buffer, &offset);
vkCmdPushConstants(recordingState.commandBuffer, m_TrianglePipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, 64, (const void*)worldMatrix);
vkCmdBindPipeline(recordingState.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_TrianglePipeline);
vkCmdDraw(recordingState.commandBuffer, triangleCount * 3, 1, 0, 0);
SafeDestroy(recordingState.currentFrameNumber, buffer);
}
GarbageCollect();
}
void* RenderAPI_Vulkan::BeginModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int* outRowPitch)
void RenderAPI_Vulkan::preFGExtrapolation()
{
*outRowPitch = textureWidth * 4;
const size_t stagingBufferSizeRequirements = *outRowPitch * textureHeight;
UnityVulkanRecordingState recordingState;
if (!m_UnityVulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
return NULL;
SafeDestroy(recordingState.currentFrameNumber, m_TextureStagingBuffer);
m_TextureStagingBuffer = VulkanBuffer();
if (!CreateVulkanBuffer(stagingBufferSizeRequirements, &m_TextureStagingBuffer, VK_BUFFER_USAGE_TRANSFER_SRC_BIT))
return NULL;
return m_TextureStagingBuffer.mapped;
}
void RenderAPI_Vulkan::EndModifyTexture(void* textureHandle, int textureWidth, int textureHeight, int rowPitch, void* dataPtr)
bool RenderAPI_Vulkan::doFGExtrapolation(void *src, void *data, void *dst)
{
// cannot do resource uploads inside renderpass
m_UnityVulkan->EnsureOutsideRenderPass();
// ???
// unity_vulkan->EnsureOutsideRenderPass();
UnityVulkanImage image;
if (!m_UnityVulkan->AccessTexture(textureHandle, UnityVulkanWholeImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
if (unity_vulkan->AccessTexture(src, UnityVulkanWholeImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, kUnityVulkanResourceAccess_PipelineBarrier, &image))
return;
UnityVulkanRecordingState recordingState;
if (!m_UnityVulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
return;
VkBufferImageCopy region;
region.bufferImageHeight = 0;
region.bufferRowLength = 0;
region.bufferOffset = 0;
region.imageOffset.x = 0;
region.imageOffset.y = 0;
region.imageOffset.z = 0;
region.imageExtent.width = textureWidth;
region.imageExtent.height = textureHeight;
region.imageExtent.depth = 1;
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageSubresource.mipLevel = 0;
vkCmdCopyBufferToImage(recordingState.commandBuffer, m_TextureStagingBuffer.buffer, image.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
}
void* RenderAPI_Vulkan::BeginModifyVertexBuffer(void* bufferHandle, size_t* outBufferSize)
{
UnityVulkanRecordingState recordingState;
if (!m_UnityVulkan->CommandRecordingState(&recordingState, kUnityVulkanGraphicsQueueAccess_DontCare))
return NULL;
UnityVulkanBuffer bufferInfo;
if (!m_UnityVulkan->AccessBuffer(bufferHandle, 0, 0, kUnityVulkanResourceAccess_ObserveOnly, &bufferInfo))
return NULL;
*outBufferSize = bufferInfo.sizeInBytes;
if (!bufferInfo.memory.mapped)
return NULL;
// We don't want to start modifying a resource that might still be used by the GPU,
// so we can use kUnityVulkanResourceAccess_Recreate to recreate it while still keeping the old one alive if it's in use.
UnityVulkanBuffer recreatedBuffer;
if (!m_UnityVulkan->AccessBuffer(bufferHandle, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_HOST_WRITE_BIT, kUnityVulkanResourceAccess_Recreate, &recreatedBuffer))
return NULL;
// We don't care about the previous contents of this vertex buffer so we can return the mapped pointer to the new resource memory
return recreatedBuffer.memory.mapped;
}
void RenderAPI_Vulkan::EndModifyVertexBuffer(void* bufferHandle)
{
// cannot do resource uploads inside renderpass, but we know that the texture modification is done first and that already ends the renderpass
// m_UnityVulkan->EnsureOutsideRenderPass();
UnityVulkanBuffer buffer;
if (!m_UnityVulkan->AccessBuffer(bufferHandle, 0, 0, kUnityVulkanResourceAccess_ObserveOnly, &buffer))
return;
if (!(buffer.memory.flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
{
VkMappedMemoryRange range;
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range.pNext = NULL;
range.memory = buffer.memory.memory;
range.offset = buffer.memory.offset; // size and offset also must be multiple of nonCoherentAtomSize
range.size = buffer.memory.size;
vkFlushMappedMemoryRanges(m_Instance.device, 1, &range);
}
return false;
}
void RenderAPI_Vulkan::postFGExtrapolation()
{
}
void RenderAPI_Vulkan::disableFGExtrapolation()
{
}
#endif // #if SUPPORT_VULKAN

View File

@ -9,62 +9,31 @@
#include <math.h>
#include <vector>
// --------------------------------------------------------------------------
// SetTimeFromUnity, an example function we export which is called by one of the scripts.
static float g_Time;
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API SetTimeFromUnity (float t) { g_Time = t; }
// --------------------------------------------------------------------------
// SetTextureFromUnity, an example function we export which is called by one of the scripts.
static void* g_TextureHandle = NULL;
static int g_TextureWidth = 0;
static int g_TextureHeight = 0;
static void* g_VertexBufferHandle = NULL;
static int g_VertexBufferVertexCount;
struct MeshVertex
{
float pos[3];
float normal[3];
float color[4];
float uv[2];
};
static std::vector<MeshVertex> g_VertexSource;
// --------------------------------------------------------------------------
// UnitySetInterfaces
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType);
static IUnityInterfaces* s_UnityInterfaces = NULL;
static IUnityGraphics* s_Graphics = NULL;
static IUnityLog* s_unityLogPtr = nullptr;
static IUnityInterfaces *s_unity_interfaces = NULL;
static IUnityGraphics *s_graphics = NULL;
static IUnityLog *s_unity_logptr = nullptr;
void UnityLog(const char* msg)
void unityLog(const char *msg)
{
UNITY_LOG(s_unityLogPtr, msg);
UNITY_LOG(s_unity_logptr, msg);
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces *unityInterfaces)
{
s_UnityInterfaces = unityInterfaces;
s_Graphics = s_UnityInterfaces->Get<IUnityGraphics>();
s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
s_unityLogPtr = s_UnityInterfaces->Get<IUnityLog>();
UnityLog("UnityPluginLoad");
s_unity_interfaces = unityInterfaces;
s_graphics = s_unity_interfaces->Get<IUnityGraphics>();
s_graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
s_unity_logptr = s_unity_interfaces->Get<IUnityLog>();
unityLog("UnityPluginLoad");
#if SUPPORT_VULKAN
if (s_Graphics->GetRenderer() == kUnityGfxRendererNull)
if (s_graphics->GetRenderer() == kUnityGfxRendererNull)
{
extern void RenderAPI_Vulkan_OnPluginLoad(IUnityInterfaces*);
extern void RenderAPI_Vulkan_OnPluginLoad(IUnityInterfaces *);
RenderAPI_Vulkan_OnPluginLoad(unityInterfaces);
}
#endif // SUPPORT_VULKAN
@ -75,13 +44,12 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnit
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
{
s_Graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
s_graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
}
#if UNITY_WEBGL
typedef void (UNITY_INTERFACE_API * PluginLoadFunc)(IUnityInterfaces* unityInterfaces);
typedef void (UNITY_INTERFACE_API * PluginUnloadFunc)();
typedef void(UNITY_INTERFACE_API *PluginLoadFunc)(IUnityInterfaces *unityInterfaces);
typedef void(UNITY_INTERFACE_API *PluginUnloadFunc)();
extern "C" void UnityRegisterRenderingPlugin(PluginLoadFunc loadPlugin, PluginUnloadFunc unloadPlugin);
@ -94,165 +62,74 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API RegisterPlugin()
// --------------------------------------------------------------------------
// GraphicsDeviceEvent
static RenderAPI* s_CurrentAPI = NULL;
static UnityGfxRenderer s_DeviceType = kUnityGfxRendererNull;
static RenderAPI *s_current_api = NULL;
static UnityGfxRenderer s_device_type = kUnityGfxRendererNull;
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
{
// Create graphics API implementation upon initialization
if (eventType == kUnityGfxDeviceEventInitialize)
{
assert(s_CurrentAPI == NULL);
s_DeviceType = s_Graphics->GetRenderer();
s_CurrentAPI = CreateRenderAPI(s_DeviceType);
assert(s_current_api == NULL);
s_device_type = s_graphics->GetRenderer();
s_current_api = createRenderAPI(s_device_type);
}
// Let the implementation process the device related events
if (s_CurrentAPI)
if (s_current_api)
{
s_CurrentAPI->ProcessDeviceEvent(eventType, s_UnityInterfaces);
s_current_api->processDeviceEvent(eventType, s_unity_interfaces);
}
// Cleanup graphics API implementation upon shutdown
if (eventType == kUnityGfxDeviceEventShutdown)
{
delete s_CurrentAPI;
s_CurrentAPI = NULL;
s_DeviceType = kUnityGfxRendererNull;
delete s_current_api;
s_current_api = NULL;
s_device_type = kUnityGfxRendererNull;
}
}
// --------------------------------------------------------------------------
// OnRenderEvent
// This will be called for GL.IssuePluginEvent script calls; eventID will
// be the integer passed to IssuePluginEvent. In this example, we just ignore
// that value.
static void ModifyTexturePixels()
{
void* textureHandle = g_TextureHandle;
int width = g_TextureWidth;
int height = g_TextureHeight;
if (!textureHandle)
return;
int textureRowPitch;
void* textureDataPtr = s_CurrentAPI->BeginModifyTexture(textureHandle, width, height, &textureRowPitch);
if (!textureDataPtr)
return;
const float t = g_Time * 4.0f;
unsigned char* dst = (unsigned char*)textureDataPtr;
for (int y = 0; y < height; ++y)
{
unsigned char* ptr = dst;
for (int x = 0; x < width; ++x)
{
// Simple "plasma effect": several combined sine waves
int vv = int(
(127.0f + (127.0f * sinf(x / 7.0f + t))) +
(127.0f + (127.0f * sinf(y / 5.0f - t))) +
(127.0f + (127.0f * sinf((x + y) / 6.0f - t))) +
(127.0f + (127.0f * sinf(sqrtf(float(x*x + y*y)) / 4.0f - t)))
) / 4;
// Write the texture pixel
ptr[0] = vv;
ptr[1] = vv;
ptr[2] = vv;
ptr[3] = vv;
// To next pixel (our pixels are 4 bpp)
ptr += 4;
}
// To next image row
dst += textureRowPitch;
}
s_CurrentAPI->EndModifyTexture(textureHandle, width, height, textureRowPitch, textureDataPtr);
}
static void ModifyVertexBuffer()
{
void* bufferHandle = g_VertexBufferHandle;
int vertexCount = g_VertexBufferVertexCount;
if (!bufferHandle)
return;
size_t bufferSize;
void* bufferDataPtr = s_CurrentAPI->BeginModifyVertexBuffer(bufferHandle, &bufferSize);
if (!bufferDataPtr)
return;
int vertexStride = int(bufferSize / vertexCount);
// Unity should return us a buffer that is the size of `vertexCount * sizeof(MeshVertex)`
// If that's not the case then we should quit to avoid unexpected results.
// This can happen if https://docs.unity3d.com/ScriptReference/Mesh.GetNativeVertexBufferPtr.html returns
// a pointer to a buffer with an unexpected layout.
if (static_cast<unsigned int>(vertexStride) != sizeof(MeshVertex))
return;
const float t = g_Time * 3.0f;
char* bufferPtr = (char*)bufferDataPtr;
// modify vertex Y position with several scrolling sine waves,
// copy the rest of the source data unmodified
for (int i = 0; i < vertexCount; ++i)
{
const MeshVertex& src = g_VertexSource[i];
MeshVertex& dst = *(MeshVertex*)bufferPtr;
dst.pos[0] = src.pos[0];
dst.pos[1] = src.pos[1] + sinf(src.pos[0] * 1.1f + t) * 0.4f + sinf(src.pos[2] * 0.9f - t) * 0.3f;
dst.pos[2] = src.pos[2];
dst.normal[0] = src.normal[0];
dst.normal[1] = src.normal[1];
dst.normal[2] = src.normal[2];
dst.uv[0] = src.uv[0];
dst.uv[1] = src.uv[1];
bufferPtr += vertexStride;
}
s_CurrentAPI->EndModifyVertexBuffer(bufferHandle);
}
static void drawToPluginTexture()
{
s_CurrentAPI->drawToPluginTexture();
}
static void drawToRenderTexture()
{
s_CurrentAPI->drawToRenderTexture();
}
enum NativeRenderingEvent
{
EnableVRS = 1,
DisableVRS,
// EnableFGExtrapolation,
// PreFGExtrapolation,
DoFGExtrapolation,
// PostFGExtrapolation,
// DisableFGExtrapolation,
// SpatialUpScale,
};
static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data)
static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data)
{
// Unknown / unsupported graphics device type? Do nothing
if (s_CurrentAPI == NULL)
if (s_current_api == NULL)
return;
switch ((NativeRenderingEvent)eventID)
{
case NativeRenderingEvent::EnableVRS:
{
s_CurrentAPI->enableVRS(*(int*)data);
s_current_api->enableVRS(*(int *)data);
break;
}
case NativeRenderingEvent::DisableVRS:
{
s_CurrentAPI->disableVRS();
s_current_api->disableVRS();
break;
}
case NativeRenderingEvent::DoFGExtrapolation:
{
AFMEParam* param = (AFMEParam*)data;
s_current_api->doFGExtrapolation(param->src, param->data, param->dst);
break;
}
default:
@ -265,41 +142,49 @@ extern "C" UnityRenderingEventAndData UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
return OnRenderEventAndData;
}
extern "C" UNITY_INTERFACE_EXPORT bool GetFeatureSupport(int feature)
{
if (s_current_api == NULL)
return false;
return s_current_api->getFeatureSupport((GraphicsFeature)feature);
}
// --------------------------------------------------------------------------
// DX12 plugin specific
// --------------------------------------------------------------------------
extern "C" UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API GetRenderTexture()
extern "C" UNITY_INTERFACE_EXPORT void *UNITY_INTERFACE_API GetRenderTexture()
{
return s_CurrentAPI->getRenderTexture();
return s_current_api->getRenderTexture();
}
extern "C" UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetRenderTexture(UnityRenderBuffer rb)
{
s_CurrentAPI->setRenderTextureResource(rb);
s_current_api->setRenderTextureResource(rb);
}
extern "C" UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsSwapChainAvailable()
{
return s_CurrentAPI->isSwapChainAvailable();
return s_current_api->isSwapChainAvailable();
}
extern "C" UNITY_INTERFACE_EXPORT unsigned int UNITY_INTERFACE_API GetPresentFlags()
{
return s_CurrentAPI->getPresentFlags();
return s_current_api->getPresentFlags();
}
extern "C" UNITY_INTERFACE_EXPORT unsigned int UNITY_INTERFACE_API GetSyncInterval()
{
return s_CurrentAPI->getSyncInterval();
return s_current_api->getSyncInterval();
}
extern "C" UNITY_INTERFACE_EXPORT unsigned int UNITY_INTERFACE_API GetBackBufferWidth()
{
return s_CurrentAPI->getBackbufferHeight();
return s_current_api->getBackbufferHeight();
}
extern "C" UNITY_INTERFACE_EXPORT unsigned int UNITY_INTERFACE_API GetBackBufferHeight()
{
return s_CurrentAPI->getBackbufferWidth();
return s_current_api->getBackbufferWidth();
}

View File

@ -15,7 +15,7 @@
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY)
#define UNITY_INTERFACE_API __stdcall
#define UNITY_INTERFACE_EXPORT __declspec(dllexport)
#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(LUMIN)
#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(OHOS) || defined(LUMIN)
#define UNITY_INTERFACE_API
#define UNITY_INTERFACE_EXPORT __attribute__ ((visibility ("default")))
#else

View File

@ -8,7 +8,7 @@
#include "IUnityGraphics.h"
#include "stdint.h"
/*
Low-level Native Plugin Rendering Extensions
============================================

View File

@ -7,7 +7,6 @@ if (is_plat("windows")) then
add_cxflags("/EHsc")
end
option("use_vulkan")
set_showmenu(true)
set_default(false)
@ -18,34 +17,118 @@ option("use_metal")
option("use_gles")
set_default(false)
option_end()
target("NativeRenderPlugin")
target("GfxPluginNativeRender")
add_includedirs("./gl3w")
add_includedirs("./Unity")
add_headerfiles("./*.h")
if is_plat("windows") then
add_includedirs("C:/VulkanSDK/1.3.283.0/Include")
add_headerfiles("./PlatformBase.h")
-- add_linkdirs("C:/VulkanSDK/1.3.283.0/Lib")
add_linkdirs("C:/VulkanSDK/1.3.283.0/Lib")
end
if has_config("use_vulkan") then
set_kind("shared")
add_defines("SUPPORT_VULKAN=1")
-- add_links("vulkan-1")
elseif has_config("use_metal") then
-- add_links("EGL")
if is_plat("windows") then
add_links("vulkan-1")
else
add_links("vulkan")
end
if is_plat("android") then
local target = "aarch64-linux-android31"
add_cxflags("--target=" .. target)
add_asflags("--target=" .. target)
add_ldflags("--target=" .. target)
add_shflags("--target=" .. target)
end
end
if has_config("use_metal") then
set_kind("static")
add_defines("SUPPORT_METAL=1")
add_defines("TARGET_OS_IOS=1")
add_files("./*.mm")
elseif has_config("use_gles") then
add_frameworks("MetalFX.framework")
end
if has_config("use_gles") then
set_kind("shared")
add_defines("SUPPORT_OPENGL_UNIFIED=1")
add_defines("SUPPORT_OPENGL_ES=1")
add_links("GLESv2")
if not is_plat("windows") then
add_links("EGL")
add_links("GLESv3")
end
end
if is_plat("harmonyos") then
add_links("xengine")
add_defines("OHOS=1")
end
add_files("./*.cpp")
target_end()
-- xmake f --ndk=E:/NDK -a arm64-v8a -p android --use_gles=true --use_vulkan=true --vs=2022 -m debug
-- xmake f --toolchain=ohndk -p harmonyos -a aarch64 --use_gles=true --vs=2022 -m debug
toolchain("ohndk")
-- mark as standalone toolchain
set_kind("standalone")
set_bindir("C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/llvm/bin")
-- set toolset
set_toolset("cc", "clang")
set_toolset("cxx", "clang", "clang++")
set_toolset("ld", "clang++", "clang")
set_toolset("sh", "clang++", "clang")
set_toolset("ar", "llvm-ar")
set_toolset("ex", "llvm-ar")
set_toolset("strip", "llvm-strip")
set_toolset("mm", "llvm-mm")
set_toolset("mxx", "clang", "clang++")
set_toolset("as", "llvm-as")
add_defines("MYCLANG")
add_defines("OHOS_STL=c++_shared")
on_check(function (toolchain)
return true
end)
-- on load
on_load(function (toolchain)
-- init cxflags for the target kind: binary
toolchain:add("binary.cxflags", "-fPIE", "-pie")
-- add "-fPIE -pie" to ldflags
toolchain:add("ldflags", "-fPIE")
toolchain:add("ldflags", "-pie")
-- add some builtin flags
toolchain:add("cxflags", "-D__MUSL__")
local target = "aarch64-linux-ohos"
toolchain:add("cxflags", "--target=" .. target)
toolchain:add("asflags", "--target=" .. target)
toolchain:add("ldflags", "--target=" .. target)
toolchain:add("shflags", "--target=" .. target)
local sysroot = "C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot"
toolchain:add("cxflags", "--sysroot=" .. sysroot)
toolchain:add("asflags", "--sysroot=" .. sysroot)
toolchain:add("ldflags", "--sysroot=" .. sysroot)
toolchain:add("shflags", "--sysroot=" .. sysroot)
-- toolchain:add("includedirs", "C:/Program Files/Huawei/DevEco Studio/sdk/default/openharmony/native/sysroot/usr/include")
toolchain:add("includedirs", "C:/Program Files/Huawei/DevEco Studio/sdk/default/hms/native/sysroot/usr/include")
toolchain:add("linkdirs", "C:/Program Files/Huawei/DevEco Studio/sdk/default/hms/native/sysroot/usr/lib/aarch64-linux-ohos")
end)
toolchain_end()

View File

@ -22,6 +22,7 @@ namespace UnityEditor.Rendering.Universal
private SerializedProperty superResolution;
private SerializedProperty ssRenderScale;
private SerializedProperty vrsRate;
/// <inheritdoc/>
public override void OnInspectorGUI()
{
@ -29,6 +30,7 @@ namespace UnityEditor.Rendering.Universal
UniversalRenderPipelineAssetUI.Inspector.Draw(m_SerializedURPAsset, this);
EditorGUILayout.PropertyField(superResolution, new GUIContent("超分"));
EditorGUILayout.PropertyField(ssRenderScale, new GUIContent("超分比例"));
EditorGUILayout.PropertyField(vrsRate, new GUIContent("VRS Rate"));
m_SerializedURPAsset.Apply();
}
@ -37,6 +39,7 @@ namespace UnityEditor.Rendering.Universal
m_SerializedURPAsset = new SerializedUniversalRenderPipelineAsset(serializedObject);
superResolution = serializedObject.FindProperty("superResolution");
ssRenderScale = serializedObject.FindProperty("sSRenderScale");
vrsRate = serializedObject.FindProperty("vrsRate");
CreateRendererReorderableList();
}

View File

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.RenderGraphModule;
using UnityEngine.Profiling;
using X.Rendering.Feature;
namespace UnityEngine.Rendering.Universal.Internal
{
@ -170,7 +172,9 @@ namespace UnityEngine.Rendering.Universal.Internal
}
}
private static void ExecutePass(ScriptableRenderContext context, PassData data, ref RenderingData renderingData, bool yFlip)
static IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf<int>());
private static unsafe void ExecutePass(ScriptableRenderContext context, PassData data, ref RenderingData renderingData, bool yFlip)
{
var cmd = renderingData.commandBuffer;
using (new ProfilingScope(cmd, data.m_ProfilingSampler))
@ -237,8 +241,22 @@ namespace UnityEngine.Rendering.Universal.Internal
}
else
{
var asset = UniversalRenderPipeline.asset;
if(asset.VRSRate != RenderingPlugin.VRSPluginShadingRate.X1_PER_PIXEL)
{
*(int*)p.ToPointer() = (int)asset.VRSRate;
cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.EnableVRS, p);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
}
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filterSettings, ref data.m_RenderStateBlock);
if(asset.VRSRate != RenderingPlugin.VRSPluginShadingRate.X1_PER_PIXEL)
{
cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.DisableVRS, IntPtr.Zero);
}
// Render objects that did not match any shader pass with error shader
RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, filterSettings, SortingCriteria.None);
}
@ -250,6 +268,7 @@ namespace UnityEngine.Rendering.Universal.Internal
}
}
private class PassData
{
internal TextureHandle m_Albedo;

View File

@ -2,6 +2,8 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.Experimental.Rendering;
using X.Rendering.Feature;
using static Unity.Burst.Intrinsics.X86.Avx;
using static UnityEngine.Rendering.Universal.UniversalRenderPipeline.Profiling.Pipeline;
namespace UnityEngine.Rendering.Universal
{
@ -500,7 +502,8 @@ namespace UnityEngine.Rendering.Universal
colorDescriptor.width = cameraData.camera.pixelWidth;
colorDescriptor.height = cameraData.camera.pixelHeight;
colorDescriptor.enableRandomWrite = true;
//colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat;
//colorDescriptor.enableRandomWrite = true; // compute
renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear);
@ -645,6 +648,7 @@ namespace UnityEngine.Rendering.Universal
renderer.EnableSwapBufferMSAA(true);
destination = renderer.GetCameraColorFrontBuffer(cmd);
}
FG.RecordFrame(GetSource(), cmd);
Blitter.BlitCameraTexture(cmd, GetSource(), destination, colorLoadAction, RenderBufferStoreAction.Store, m_Materials.uber, 0);
renderer.ConfigureCameraColorTarget(destination);
Swap(renderer);
@ -673,14 +677,22 @@ namespace UnityEngine.Rendering.Universal
RenderTargetIdentifier cameraTarget = cameraData.targetTexture != null ? new RenderTargetIdentifier(cameraData.targetTexture) : cameraTargetID;
RTHandleStaticHelpers.SetRTHandleStaticWrapper(cameraTarget);
var cameraTargetHandle = RTHandleStaticHelpers.s_RTHandleWrapper;
FG.RecordFrame(GetSource(), cmd);
RenderingUtils.FinalBlit(cmd, ref cameraData, GetSource(), cameraTargetHandle, colorLoadAction, RenderBufferStoreAction.Store, m_Materials.uber, 0);
renderer.ConfigureCameraColorTarget(cameraTargetHandle);
}
}
}
}
internal void Present(CommandBuffer cmd, ref CameraData cameraData, RTHandle rt)
{
RenderTargetIdentifier cameraTargetID = BuiltinRenderTextureType.CameraTarget;
RenderTargetIdentifier cameraTarget = cameraData.targetTexture != null ? new RenderTargetIdentifier(cameraData.targetTexture) : cameraTargetID;
RTHandleStaticHelpers.SetRTHandleStaticWrapper(cameraTarget);
var cameraTargetHandle = RTHandleStaticHelpers.s_RTHandleWrapper;
RenderingUtils.FinalBlit(cmd, ref cameraData, rt, cameraTargetHandle, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, m_Materials.uber, 0);
}
#region Sub-pixel Morphological Anti-aliasing

View File

@ -4,24 +4,39 @@ namespace X.Rendering.Feature
{
public static class RenderingPlugin
{
//#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
// [DllImport("__Internal")]
//#else
// [DllImport("NativeRenderPlugin")]
//#endif
// public static extern void SetTimeFromUnity(float t);
#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
[DllImport("__Internal")]
#else
[DllImport("GfxPluginNativeRender")]
#endif
public static extern void SetTimeFromUnity(float t);
//#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
// [DllImport("__Internal")]
//#else
// [DllImport("NativeRenderPlugin")]
//#endif
// public static extern IntPtr GetRenderEventAndDataFunc();
#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
[DllImport("__Internal")]
#else
[DllImport("GfxPluginNativeRender")]
#endif
public static extern IntPtr GetRenderEventAndDataFunc();
#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
[DllImport("__Internal")]
#else
[DllImport("GfxPluginNativeRender")]
#endif
private static extern bool GetFeatureSupport(int feature);
//#if (PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_BRATWURST || PLATFORM_SWITCH) && !UNITY_EDITOR
// [DllImport("__Internal")]
//#else
// [DllImport("GfxPluginNativeRender")]
//#endif
// public static extern bool DoFGExtrapolation(IntPtr src, IntPtr data, IntPtr dst);
public enum NativeRenderingEvent
{
EnableVRS = 1,
DisableVRS,
DoFGExtrapolation,
}
public enum VRSPluginShadingRate
@ -34,5 +49,28 @@ namespace X.Rendering.Feature
X1_PER_2X4_PIXELS,
X1_PER_4X4_PIXELS,
};
public enum GraphicsFeature
{
VRS_DRAW = 0,
VRS_PRIMITIVE,
VRS_ATTACHMENT,
HW_SPATIAL_SR,
HW_AISR,
HW_ADAPTIVE_VRS,
HW_FG_INTERPOLATE,
HW_FG_EXTRAPOLATION,
METAL_FX_SPATIAL_SR,
METAL_FX_TEMPORAL_SR,
VIVO_TEMPORAL_SR,
QCOM_AFME,
MAX_CNT
};
public static bool GetFeatureSupport(GraphicsFeature feature)
{
return GetFeatureSupport((int)feature);
}
}
}

View File

@ -1,11 +0,0 @@
using UnityEngine;
namespace X.Rendering.Feature
{
/// <summary>
/// only gles32 QCOM_frame_extrapolation
/// </summary>
public class AFME : MonoBehaviour
{
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace X.Rendering.Feature
{
public enum EFrameGeneration
{
AFME,// Adaptive Frame Motion Extrapolation GL_QCOM_frame_extrapolation
HW_INTERPOLATE,// 华为 Graphics Accelerate Kit 内插值
HW_EXTRAPOLATION,// 华为 Graphics Accelerate Kit 外插值
//VGS,// vivo
FSR2,
FSR3,
}
public unsafe class FG
{
static int frameIndex = 0;
static RTHandle[] historys = new RTHandle[2];
static RTHandle presentRt;
static bool presented = false;
public static bool UseFG = true;
public static bool CanDoFG => frameIndex > 0 && frameIndex % 3 == 0 && !presented && UseFG;
[StructLayout(LayoutKind.Sequential)]
struct AFMEParam
{
public IntPtr src;
public IntPtr data;
public IntPtr dst;
}
static IntPtr data = Marshal.AllocHGlobal(sizeof(AFMEParam));
public static bool FrameGenearte(ScriptableRenderContext context, CommandBuffer cmd, out RTHandle dst)
{
#if UNITY_ANDROID && !UNITY_EDITOR
Debug.Log("FrameGenearte" + frameIndex);
dst = presentRt;
var history1 = historys[frameIndex % 2];
var history2 = historys[frameIndex % 2 == 1 ? 0 : 1];
AFMEParam* p = (AFMEParam*)data.ToPointer();
p->src = history1.rt.GetNativeTexturePtr();
p->data = history2.rt.GetNativeTexturePtr();
p->dst = dst.rt.GetNativeTexturePtr();
cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.DoFGExtrapolation, data);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
presented = true;
return true;
#else
dst = null;
return false;
#endif
}
public static void RecordFrame(RTHandle source, CommandBuffer cmd)
{
presented = false;
var index = frameIndex++ % 2;
var desc = source.rt.descriptor;
desc.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm;
desc.depthBufferBits = 0;
RenderingUtils.ReAllocateIfNeeded(ref historys[0], desc);
RenderingUtils.ReAllocateIfNeeded(ref historys[1], desc);
RenderingUtils.ReAllocateIfNeeded(ref presentRt, desc);
var history = historys[index];
cmd.Blit(source, history);
}
}
}

View File

@ -1,6 +1,9 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace X.Rendering.Feature
{
public enum ESuperResolution
@ -15,6 +18,7 @@ namespace X.Rendering.Feature
HW_SPATIAL_SR, // 华为空域超分
HW_AISR, // 华为AI空域超分
METAL_FX_SPATIAL_SR, // 苹果空域超分
VSR, // vivo v-sr
DLSS1,
DLSS2,
DLSS3,
@ -36,6 +40,14 @@ namespace X.Rendering.Feature
Factor05,
}
[StructLayout(LayoutKind.Sequential)]
struct HWSpatialSRParam
{
float sharpness;
Int32 render_width;
Int32 render_height;
};
public interface ISuperResolutionFeature
{
public void SetSR(ESuperResolution resolution);

View File

@ -13,6 +13,11 @@ namespace UnityEngine.Rendering.Universal
public ESuperResolution SuperResolution => superResolution;
public RenderingPlugin.VRSPluginShadingRate VRSRate { get => vrsRate; set => vrsRate = value; }
[SerializeField]
private RenderingPlugin.VRSPluginShadingRate vrsRate;
private void UpdateSSSettings()
{
var renderer = GetRenderer(this.m_DefaultRendererIndex);

View File

@ -348,7 +348,7 @@ namespace UnityEngine.Rendering.Universal
if (m_GlobalSettings == null || UniversalRenderPipelineGlobalSettings.instance == null)
{
m_GlobalSettings = UniversalRenderPipelineGlobalSettings.Ensure();
if(m_GlobalSettings == null) return;
if (m_GlobalSettings == null) return;
}
#endif
@ -446,7 +446,7 @@ namespace UnityEngine.Rendering.Universal
StandardRequest standardRequest = renderRequest as StandardRequest;
SingleCameraRequest singleRequest = renderRequest as SingleCameraRequest;
if(standardRequest != null || singleRequest != null)
if (standardRequest != null || singleRequest != null)
{
RenderTexture destination = standardRequest != null ? standardRequest.destination : singleRequest.destination;
int mipLevel = standardRequest != null ? standardRequest.mipLevel : singleRequest.mipLevel;
@ -473,7 +473,7 @@ namespace UnityEngine.Rendering.Universal
RTDesc.height = Mathf.Max(1, RTDesc.height);
//if mip is 0 and target is Texture2D we can immediately render to the requested destination
if(destination.dimension != TextureDimension.Tex2D || mipLevel != 0)
if (destination.dimension != TextureDimension.Tex2D || mipLevel != 0)
{
temporaryRT = RenderTexture.GetTemporary(RTDesc);
}
@ -516,9 +516,9 @@ namespace UnityEngine.Rendering.Universal
}
if(temporaryRT)
if (temporaryRT)
{
switch(destination.dimension)
switch (destination.dimension)
{
case TextureDimension.Tex2D:
case TextureDimension.Tex2DArray:
@ -635,6 +635,12 @@ namespace UnityEngine.Rendering.Universal
ProfilingSampler sampler = Profiling.TryGetOrAddCameraSampler(camera);
using (new ProfilingScope(cmdScope, sampler)) // Enqueues a "BeginSample" command into the CommandBuffer cmd
{
if (camera.cameraType == CameraType.Game && X.Rendering.Feature.FG.CanDoFG && X.Rendering.Feature.FG.FrameGenearte(context, cmd, out var rt))
{
(renderer as UniversalRenderer).postProcessPass.Present(cmd, ref cameraData, rt);
}
else
{
renderer.Clear(cameraData.renderType);
@ -661,7 +667,7 @@ namespace UnityEngine.Rendering.Universal
// Called and updated only once, as the same camera can be rendered multiple times.
// NOTE: Tracks only the current (this) camera, not shadow views or any other offscreen views.
// NOTE: Shared between both Execute and Render (RG) paths.
if(camera.TryGetComponent<UniversalAdditionalCameraData>(out var additionalCameraData))
if (camera.TryGetComponent<UniversalAdditionalCameraData>(out var additionalCameraData))
additionalCameraData.motionVectorsPersistentData.Update(ref cameraData);
// Update TAA persistent data based on cameraData. Most importantly resize the history render targets.
@ -696,6 +702,8 @@ namespace UnityEngine.Rendering.Universal
// Timing scope inside
renderer.Execute(context, ref renderingData);
}
}
} // When ProfilingSample goes out of scope, an "EndSample" command is enqueued into CommandBuffer cmd
context.ExecuteCommandBuffer(cmd); // Sends to ScriptableRenderContext all the commands enqueued since cmd.Clear, i.e the "EndSample" command
@ -1573,7 +1581,7 @@ namespace UnityEngine.Rendering.Universal
// Fill new history with current frame
// XR Multipass renders a "frame" per eye
if(allocation)
if (allocation)
cameraData.taaSettings.resetHistoryFrames += xrMultipassEnabled ? 2 : 1;
}
else

View File

@ -0,0 +1,16 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"DebugDataKind": 1,
"EnableArmv9SecurityFeatures": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"OptimizeFor": 0
}
}

View File

@ -266,6 +266,7 @@ PlayerSettings:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
@ -288,7 +289,7 @@ PlayerSettings:
applicationIdentifier:
Android: com.DefaultCompany.TJURP
OpenHarmony: com.DefaultCompany.TJURP
Standalone: com.unity.template.urp-sample
Standalone: com.DefaultCompany.TJURP
iPhone: com.unity.template.urp-sample
buildNumber:
Standalone: 0
@ -301,7 +302,7 @@ PlayerSettings:
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
aotOptions:
stripEngineCode: 1
stripEngineCode: 0
iPhoneStrippingLevel: 0
iPhoneScriptCallOptimization: 0
ForceInternetPermission: 0
@ -392,7 +393,7 @@ PlayerSettings:
useCustomGradlePropertiesTemplate: 0
useCustomGradleSettingsTemplate: 0
useCustomProguardFile: 0
AndroidTargetArchitectures: 3
AndroidTargetArchitectures: 2
AndroidTargetDevices: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
@ -747,7 +748,7 @@ PlayerSettings:
- m_BuildTarget: LuminSupport
m_GraphicsJobs: 0
- m_BuildTarget: AndroidPlayer
m_GraphicsJobs: 1
m_GraphicsJobs: 0
- m_BuildTarget: WebGLSupport
m_GraphicsJobs: 0
m_BuildTargetGraphicsJobMode:
@ -763,13 +764,19 @@ PlayerSettings:
m_APIs: 10000000
m_Automatic: 1
- m_BuildTarget: AndroidPlayer
m_APIs: 150000000b000000
m_APIs: 0b00000015000000
m_Automatic: 0
- m_BuildTarget: WebGLSupport
m_APIs: 0b000000
m_Automatic: 0
- m_BuildTarget: WindowsStandaloneSupport
m_APIs: 02000000
m_APIs: 15000000
m_Automatic: 0
- m_BuildTarget: LinuxStandaloneSupport
m_APIs: 15000000
m_Automatic: 0
- m_BuildTarget: MacStandaloneSupport
m_APIs: 10000000
m_Automatic: 0
m_BuildTargetVRSettings: []
m_DefaultShaderChunkSizeInMB: 16
@ -1074,13 +1081,14 @@ PlayerSettings:
platformArchitecture: {}
scriptingBackend:
Android: 1
OpenHarmony: 1
Standalone: 0
il2cppCompilerConfiguration: {}
il2cppCodeGeneration: {}
managedStrippingLevel: {}
incrementalIl2cppBuild: {}
suppressCommonWarnings: 1
allowUnsafeCode: 0
allowUnsafeCode: 1
useDeterministicCompilation: 1
additionalIl2CppArgs:
scriptingRuntimeVersion: 1
@ -1168,7 +1176,7 @@ PlayerSettings:
hmiCpuConfiguration:
openHarmonySplashScreen: {fileID: 0}
openHarmonySplashScreenScale: 0
OpenHarmonyTargetArchitectures: 2
OpenHarmonyTargetArchitectures: 6
openHarmonyClientID:
openHarmonyAppID:
openHarmonyDeviceTypes: 7

View File

@ -58,7 +58,6 @@ QualitySettings:
vgStreamingBufferSize: 512
excludedTargetPlatforms:
- Nintendo Switch
- Standalone
m_TextureMipmapLimitGroupNames: []
m_PerPlatformDefaultQuality:
Android: 0

View File

@ -12,14 +12,14 @@ EditorUserSettings:
value: 5a57555407545f0b5e0f5f764277594914161e2b787977692b714e64e4b2363b
flags: 0
RecentlyUsedSceneGuid-2:
value: 57050d5004060d590f56087046700f4445164c7e7a7824312e7c4e6bb0e1376d
flags: 0
RecentlyUsedSceneGuid-3:
value: 01060c075556080e0956597315775b14104e4179282b25662b2c1c31b7b63068
flags: 0
RecentlyUsedSceneGuid-4:
RecentlyUsedSceneGuid-3:
value: 5b00515154055e035459547042705a44154f1e2c2e2e7f677e7d4567e1b9376d
flags: 0
RecentlyUsedSceneGuid-4:
value: 57050d5004060d590f56087046700f4445164c7e7a7824312e7c4e6bb0e1376d
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0

View File

@ -1,30 +1,6 @@
%YAML 1.1
%TAG !u! tag:yousandi.cn,2023:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 12004, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: 2815
y: 219
width: 1934
height: 971
m_ShowMode: 0
m_Title: Frame Debugger
m_RootView: {fileID: 4}
m_MinSize: {x: 1000, y: 521}
m_MaxSize: {x: 4000, y: 4021}
m_Maximized: 0
--- !u!114 &2
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -38,68 +14,17 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: 0
y: 43
width: 2560
height: 1349
x: 9
y: 52
width: 2542
height: 1331
m_ShowMode: 4
m_Title: Game
m_RootView: {fileID: 11}
m_Title: Console
m_RootView: {fileID: 8}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
m_Maximized: 1
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
m_Name: FrameDebuggerWindow
m_EditorClassIdentifier:
m_Children: []
m_Position:
serializedVersion: 2
x: 0
y: 0
width: 1934
height: 971
m_MinSize: {x: 1000, y: 521}
m_MaxSize: {x: 4000, y: 4021}
m_ActualView: {fileID: 17}
m_Panes:
- {fileID: 17}
m_Selected: 0
m_LastSelected: 0
--- !u!114 &4
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 12010, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 3}
m_Position:
serializedVersion: 2
x: 0
y: 0
width: 1934
height: 971
m_MinSize: {x: 1000, y: 521}
m_MaxSize: {x: 4000, y: 4021}
vertical: 0
controlID: 14
draggingID: 0
--- !u!114 &5
m_Maximized: 0
--- !u!114 &2
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -114,18 +39,18 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1300
x: 1400
y: 0
width: 650
height: 529
width: 701
height: 522
m_MinSize: {x: 102, y: 121}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 23}
m_ActualView: {fileID: 19}
m_Panes:
- {fileID: 23}
- {fileID: 19}
m_Selected: 0
m_LastSelected: 0
--- !u!114 &6
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -138,20 +63,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 10}
- {fileID: 5}
- {fileID: 7}
- {fileID: 2}
m_Position:
serializedVersion: 2
x: 0
y: 770
width: 1950
height: 529
y: 759
width: 2101
height: 522
m_MinSize: {x: 200, y: 50}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 126
controlID: 68
draggingID: 0
--- !u!114 &7
--- !u!114 &4
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -164,20 +89,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 14}
- {fileID: 8}
- {fileID: 11}
- {fileID: 5}
m_Position:
serializedVersion: 2
x: 0
y: 30
width: 2560
height: 1299
width: 2542
height: 1281
m_MinSize: {x: 300, y: 100}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 162
controlID: 171
draggingID: 0
--- !u!114 &8
--- !u!114 &5
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -192,18 +117,18 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1950
x: 2101
y: 0
width: 610
height: 1299
width: 441
height: 1281
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 19}
m_ActualView: {fileID: 15}
m_Panes:
- {fileID: 19}
- {fileID: 15}
m_Selected: 0
m_LastSelected: 0
--- !u!114 &9
--- !u!114 &6
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -220,16 +145,16 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 483
height: 770
width: 516
height: 759
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 20}
m_ActualView: {fileID: 16}
m_Panes:
- {fileID: 20}
- {fileID: 16}
m_Selected: 0
m_LastSelected: 0
--- !u!114 &10
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -246,16 +171,16 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1300
height: 529
width: 1400
height: 522
m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 10001, y: 10021}
m_ActualView: {fileID: 18}
m_ActualView: {fileID: 14}
m_Panes:
- {fileID: 18}
- {fileID: 14}
m_Selected: 0
m_LastSelected: 0
--- !u!114 &11
--- !u!114 &8
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -268,22 +193,22 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 12}
- {fileID: 7}
- {fileID: 13}
- {fileID: 9}
- {fileID: 4}
- {fileID: 10}
m_Position:
serializedVersion: 2
x: 0
y: 0
width: 2560
height: 1349
width: 2542
height: 1331
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1
m_TopViewHeight: 30
m_UseBottomView: 1
m_BottomViewHeight: 20
--- !u!114 &12
--- !u!114 &9
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -300,12 +225,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 2560
width: 2542
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
m_LastLoadedLayoutName:
--- !u!114 &13
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -321,12 +246,12 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 1329
width: 2560
y: 1311
width: 2542
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
--- !u!114 &14
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -339,20 +264,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 15}
- {fileID: 6}
- {fileID: 12}
- {fileID: 3}
m_Position:
serializedVersion: 2
x: 0
y: 0
width: 1950
height: 1299
width: 2101
height: 1281
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 39
controlID: 40
draggingID: 0
--- !u!114 &15
--- !u!114 &12
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -365,20 +290,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Children:
- {fileID: 9}
- {fileID: 16}
- {fileID: 6}
- {fileID: 13}
m_Position:
serializedVersion: 2
x: 0
y: 0
width: 1950
height: 770
width: 2101
height: 759
m_MinSize: {x: 200, y: 50}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 40
controlID: 41
draggingID: 0
--- !u!114 &16
--- !u!114 &13
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -393,76 +318,19 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 483
x: 516
y: 0
width: 1467
height: 770
width: 1585
height: 759
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 22}
m_ActualView: {fileID: 18}
m_Panes:
- {fileID: 21}
- {fileID: 22}
- {fileID: 17}
- {fileID: 18}
m_Selected: 1
m_LastSelected: 0
--- !u!114 &17
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 13202, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_MinSize: {x: 1000, y: 500}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: Frame Debugger
m_Image: {fileID: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 2815
y: 219
width: 1934
height: 950
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
m_SupportedDataModes:
isAutomatic: 1
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
m_SaveData: []
m_OverlaysVisible: 1
m_TreeWidth: 337.92
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 1f000000
m_LastClickedID: 31
m_ExpandedIDs: e4ffffffe5ffffffe9ffffffebffffffecfffffff5fffffff8fffffffdfffffffeffffff00000000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
m_OriginalName:
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: 0
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 0
m_ClientGUIView: {fileID: 0}
m_SearchString:
--- !u!114 &18
--- !u!114 &14
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -482,10 +350,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 843
width: 1299
height: 508
x: 9
y: 841
width: 1399
height: 501
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
@ -507,7 +375,7 @@ MonoBehaviour:
m_SkipHidden: 0
m_SearchArea: 1
m_Folders:
- Packages/com.unity.render-pipelines.universal/Runtime/SuperRendering/SR/Shader
- Assets/Settings/Mobile
m_Globs: []
m_OriginalText:
m_ImportLogFlags: 0
@ -515,16 +383,16 @@ MonoBehaviour:
m_ViewMode: 1
m_StartGridSize: 16
m_LastFolders:
- Packages/com.unity.render-pipelines.universal/Runtime/SuperRendering/SR/Shader
- Assets/Settings/Mobile
m_LastFoldersGridSize: 16
m_LastProjectPath: G:\TJURP
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 456}
m_SelectedIDs: 30530000
m_LastClickedID: 21296
m_ExpandedIDs: 00000000284500005c45000068450000344600008c4600004447000060480000e84a0000104c0000144e0000e84f0000649a010000ca9a3bffffff7f
scrollPos: {x: 0, y: 40}
m_SelectedIDs: a6800000
m_LastClickedID: 32934
m_ExpandedIDs: 00000000f07d0000f27d0000f47d0000f67d0000f87d0000fa7d0000fc7d0000fe7d0000007e0000027e0000047e0000067e0000087e00000a7e000000ca9a3bffffff7f
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -540,7 +408,7 @@ MonoBehaviour:
m_IsRenaming: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 1
m_ClientGUIView: {fileID: 10}
m_ClientGUIView: {fileID: 7}
m_SearchString:
m_CreateAssetUtility:
m_EndAction: {fileID: 0}
@ -552,7 +420,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000cc4400002845000068450000344600008c4600004447000060480000e84a0000104c0000144e0000e84f0000649a0100
m_ExpandedIDs: 00000000f07d0000f27d0000f47d0000f67d0000f87d0000fa7d0000fc7d0000fe7d0000007e0000027e0000047e0000067e0000087e00000a7e0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -579,7 +447,7 @@ MonoBehaviour:
m_ListAreaState:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1
m_HadKeyboardFocusLastEvent: 0
m_ExpandedInstanceIDs: c623000000000000
m_RenameOverlay:
m_UserAcceptedRename: 0
@ -596,7 +464,7 @@ MonoBehaviour:
m_IsRenaming: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 1
m_ClientGUIView: {fileID: 10}
m_ClientGUIView: {fileID: 7}
m_CreateAssetUtility:
m_EndAction: {fileID: 0}
m_InstanceID: 0
@ -608,7 +476,7 @@ MonoBehaviour:
m_GridSize: 16
m_SkipHiddenPackages: 0
m_DirectoriesAreaWidth: 207
--- !u!114 &19
--- !u!114 &15
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -628,10 +496,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1950
y: 73
width: 609
height: 1278
x: 2110
y: 82
width: 440
height: 1260
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
@ -655,7 +523,7 @@ MonoBehaviour:
m_LockTracker:
m_IsLocked: 0
m_PreviewWindow: {fileID: 0}
--- !u!114 &20
--- !u!114 &16
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -675,10 +543,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 73
width: 482
height: 749
x: 9
y: 82
width: 515
height: 738
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
@ -692,9 +560,9 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 48030000
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 8e95fdff
m_ExpandedIDs: 3afaffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -710,7 +578,7 @@ MonoBehaviour:
m_IsRenaming: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 0
m_ClientGUIView: {fileID: 9}
m_ClientGUIView: {fileID: 6}
m_SearchString:
m_ExpandedScenes: []
m_CurrenRootInstanceID: 0
@ -718,7 +586,7 @@ MonoBehaviour:
m_IsLocked: 0
m_CurrentSortingName: TransformSorting
m_WindowGUID: 4c969a2b90040154d917609493e03593
--- !u!114 &21
--- !u!114 &17
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -738,10 +606,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 483
y: 73
width: 1465
height: 749
x: 525
y: 82
width: 1583
height: 738
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
@ -756,8 +624,8 @@ MonoBehaviour:
floating: 0
collapsed: 0
displayed: 1
snapOffset: {x: -166, y: -26}
snapOffsetDelta: {x: -5, y: 0}
snapOffset: {x: -171, y: -26}
snapOffsetDelta: {x: 0, y: 0}
snapCorner: 3
id: Tool Settings
index: 0
@ -1134,14 +1002,14 @@ MonoBehaviour:
m_OverrideSceneCullingMask: 6917529027641081856
m_SceneIsLit: 1
m_SceneLighting: 1
m_2DMode: 0
m_2DMode: 1
m_isRotationLocked: 0
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 0.3252655, y: 6.390328, z: -98.436806}
m_Target: {x: 741.2015, y: 1097.4281, z: 82.08899}
speed: 2
m_Value: {x: 0.3252655, y: 6.390328, z: -98.436806}
m_Value: {x: 741.2015, y: 1097.4281, z: 82.08899}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
@ -1169,17 +1037,17 @@ MonoBehaviour:
m_Size: {x: 0, y: 0}
yGrid:
m_Fade:
m_Target: 1
m_Target: 0
speed: 2
m_Value: 1
m_Value: 0
m_Color: {r: 0.5, g: 0.5, b: 0.5, a: 0.4}
m_Pivot: {x: 0, y: 0, z: 0}
m_Size: {x: 1, y: 1}
zGrid:
m_Fade:
m_Target: 0
m_Target: 1
speed: 2
m_Value: 0
m_Value: 1
m_Color: {r: 0.5, g: 0.5, b: 0.5, a: 0.4}
m_Pivot: {x: 0, y: 0, z: 0}
m_Size: {x: 1, y: 1}
@ -1187,17 +1055,17 @@ MonoBehaviour:
m_GridAxis: 1
m_gridOpacity: 0.5
m_Rotation:
m_Target: {x: 0.10873414, y: -0.42024752, z: 0.050804242, w: 0.89943933}
m_Target: {x: 0, y: 0, z: 0, w: 1}
speed: 2
m_Value: {x: 0.10873396, y: -0.4202468, z: 0.050804157, w: 0.89943784}
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 1.4466168
m_Target: 890.40814
speed: 2
m_Value: 1.4466168
m_Value: 890.40814
m_Ortho:
m_Target: 0
m_Target: 1
speed: 2
m_Value: 0
m_Value: 1
m_CameraSettings:
m_Speed: 1
m_SpeedNormalized: 0.5
@ -1213,14 +1081,14 @@ MonoBehaviour:
m_OcclusionCulling: 0
m_EnableGDRP: 1
m_BackfaceCulling: 0
m_LastSceneViewRotation: {x: -0.015300392, y: 0.033586923, z: -0.0005142884, w: -0.9993189}
m_LastSceneViewRotation: {x: -0.08717229, y: 0.89959055, z: -0.21045254, w: -0.3726226}
m_LastSceneViewOrtho: 0
m_ReplacementShader: {fileID: 0}
m_ReplacementString:
m_SceneVisActive: 1
m_LastLockedObject: {fileID: 0}
m_ViewIsLockedToObject: 0
--- !u!114 &22
--- !u!114 &18
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -1240,10 +1108,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 483
y: 73
width: 1465
height: 749
x: 525
y: 82
width: 1583
height: 738
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
@ -1268,7 +1136,7 @@ MonoBehaviour:
m_UseMipMap: 0
m_VSyncEnabled: 0
m_Gizmos: 0
m_Stats: 0
m_Stats: 1
m_SelectedSizes: 0000000000000000000000000a000000000000000000000000000000000000000000000000000000
m_ZoomArea:
m_HRangeLocked: 0
@ -1296,29 +1164,29 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 21
width: 1465
height: 728
m_Scale: {x: 0.50555557, y: 0.50555557}
m_Translation: {x: 732.5, y: 364}
width: 1583
height: 717
m_Scale: {x: 0.49791667, y: 0.49791667}
m_Translation: {x: 791.5, y: 358.5}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
m_MarginBottom: 0
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -1448.901
x: -1589.6234
y: -720
width: 2897.802
width: 3179.2468
height: 1440
m_MinimalGUI: 1
m_defaultScale: 0.50555557
m_LastWindowPixelSize: {x: 1465, y: 749}
m_defaultScale: 0.49791667
m_LastWindowPixelSize: {x: 1583, y: 738}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 00000001000000000000
m_XRRenderMode: 0
m_RenderTexture: {fileID: 0}
--- !u!114 &23
--- !u!114 &19
MonoBehaviour:
m_ObjectHideFlags: 52
m_CorrespondingSourceObject: {fileID: 0}
@ -1338,10 +1206,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1300
y: 843
width: 648
height: 508
x: 1409
y: 841
width: 699
height: 501
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0