Skip to content

Commit

Permalink
Optimize UpdateShaderVariablesXRCB
Browse files Browse the repository at this point in the history
  • Loading branch information
DiFFoZ committed Jun 24, 2024
1 parent df790b1 commit 0adc6c5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
10 changes: 10 additions & 0 deletions LethalPerformance/LethalPerformance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
<PackageReference Include="UnityEngine.Modules" Version="2022.3.9" Publicize="True" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="LethalCompany.GameLibs.Steam" Version="*-*" Publicize="True" IncludeAssets="compile" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="..\CHANGELOG.md" />
<None Remove="Publish\**" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Unity\Assets\LethalPerformance\*.cs">
<Link>Unity\%(Filename)%(Extension)</Link>
</Compile>

<None Remove="Unity\.gitinclude" />
</ItemGroup>

<Target Name="CopyPublishFiles" AfterTargets="AfterBuild">
<ItemGroup>
Expand Down
12 changes: 8 additions & 4 deletions LethalPerformance/LethalPerformancePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
using HarmonyLib;
using Unity.Burst;
using Unity.Burst.LowLevel;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Netcode;
using UnityEngine;

namespace LethalPerformance;

Expand All @@ -20,16 +24,16 @@ public class LethalPerformancePlugin : BaseUnityPlugin

private Harmony? m_Harmony;

private void Awake()
private unsafe void Awake()
{
Instance = this;
Logger = base.Logger;
WorkingDirectory = new FileInfo(Info.Location).DirectoryName;

/*m_Harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
m_Harmony.PatchAll(typeof(LethalPerformancePlugin).Assembly);*/

LoadGameBurstLib();

m_Harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
m_Harmony.PatchAll(typeof(LethalPerformancePlugin).Assembly);
}

private void LoadGameBurstLib()
Expand Down
22 changes: 22 additions & 0 deletions LethalPerformance/Patches/Patch_HDCamera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using HarmonyLib;
using Unity.Burst;
using UnityEngine.Rendering.HighDefinition;

namespace LethalPerformance.Patches;
[HarmonyPatch(typeof(HDCamera), nameof(HDCamera.UpdateShaderVariablesXRCB))]
internal static unsafe class Patch_HDCamera
{
public static readonly Testing.TestDelegate s_TestDelegate = BurstCompiler.CompileFunctionPointer<Testing.TestDelegate>(Testing.Test).Invoke;

[HarmonyPrefix]
public static unsafe bool Prefix(HDCamera __instance, ref ShaderVariablesXR cb)
{
fixed (void* p = &cb, views = __instance.m_XRViewConstants)
{
s_TestDelegate((Testing.ReadableViewConstants*)views, __instance.viewCount, (Testing.ReadableShaderVariablesXR*)p);

cb = *(ShaderVariablesXR*)p;
return false;
}
}
}
Empty file.

0 comments on commit 0adc6c5

Please sign in to comment.