SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Refactor Asset Loading
This commit is contained in:
9 files changed
+102
-162
No files matched your search
+27
-28
@@ -4,41 +4,40 @@ using System.Resources;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Util
|
||||
namespace ADOFAIRenderer.Util;
|
||||
|
||||
internal static class BundleLoader
|
||||
{
|
||||
internal static class BundleLoader
|
||||
private static readonly string BundlePlatform;
|
||||
private static readonly Assembly? ExecutingAssembly;
|
||||
|
||||
static BundleLoader()
|
||||
{
|
||||
private static readonly string BundlePlatform;
|
||||
private static readonly Assembly? ExecutingAssembly;
|
||||
|
||||
static BundleLoader()
|
||||
BundlePlatform = Application.platform switch
|
||||
{
|
||||
BundlePlatform = Application.platform switch
|
||||
{
|
||||
RuntimePlatform.WindowsPlayer => "Win64",
|
||||
RuntimePlatform.OSXPlayer => "OSX",
|
||||
_ => "Linux"
|
||||
};
|
||||
ExecutingAssembly = Assembly.GetExecutingAssembly();
|
||||
}
|
||||
RuntimePlatform.WindowsPlayer => "Win64",
|
||||
RuntimePlatform.OSXPlayer => "OSX",
|
||||
_ => "Linux"
|
||||
};
|
||||
ExecutingAssembly = Assembly.GetExecutingAssembly();
|
||||
}
|
||||
|
||||
public static AssetBundle GetBundle(string resourcePath)
|
||||
public static AssetBundle GetBundle(string resourcePath)
|
||||
{
|
||||
if (ExecutingAssembly != null)
|
||||
{
|
||||
if (ExecutingAssembly != null)
|
||||
var bundlePath = $"ADOFAIRenderer.Bundle.{BundlePlatform}.{resourcePath}";
|
||||
using var resourceStream = ExecutingAssembly.GetManifestResourceStream(bundlePath);
|
||||
if (resourceStream != null)
|
||||
{
|
||||
var bundlePath = $"ADOFAIRenderer.Bundle.{BundlePlatform}.{resourcePath}";
|
||||
using var resourceStream = ExecutingAssembly.GetManifestResourceStream(bundlePath);
|
||||
if (resourceStream != null)
|
||||
{
|
||||
return AssetBundle.LoadFromStream(resourceStream);
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error($"Could not find bundle resource in DLL.\n{bundlePath}");
|
||||
throw new MissingManifestResourceException("Could not find bundle resource in DLL.");
|
||||
return AssetBundle.LoadFromStream(resourceStream);
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error("Executing assembly has not been set properly.");
|
||||
throw new InvalidOperationException("ExecutingAssembly has not been set.");
|
||||
|
||||
Melon<RenderMod>.Logger.Error($"Could not find bundle resource in DLL.\n{bundlePath}");
|
||||
throw new MissingManifestResourceException("Could not find bundle resource in DLL.");
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error("Executing assembly has not been set properly.");
|
||||
throw new InvalidOperationException("ExecutingAssembly has not been set.");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using ADOFAIRenderer.UI;
|
||||
using ADOFAIRenderer.Util.FFmpeg;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
@@ -77,7 +78,7 @@ namespace ADOFAIRenderer.Util
|
||||
try
|
||||
{
|
||||
_decoder = new FFmpegNativeDecoder(videoPath);
|
||||
_computeShader = RenderMod.ColorConversionShader;
|
||||
_computeShader = ModAssets.ColorConversionShader;
|
||||
|
||||
var w = _decoder.Width;
|
||||
var h = _decoder.Height;
|
||||
|
||||
+10
-9
@@ -3,6 +3,7 @@ using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ADOFAIRenderer.Core;
|
||||
using ADOFAIRenderer.UI;
|
||||
using FFmpeg.AutoGen;
|
||||
using MelonLoader;
|
||||
using Unity.Collections;
|
||||
@@ -71,7 +72,7 @@ namespace ADOFAIRenderer.Util
|
||||
}
|
||||
|
||||
// Check if GPU color conversion is enabled
|
||||
bool useGPUConversion = RenderMod.ColorConversionShader;
|
||||
bool useGPUConversion = ModAssets.ColorConversionShader;
|
||||
AVPixelFormat expectedFmt = AVPixelFormat.AV_PIX_FMT_RGBA;
|
||||
|
||||
if (useGPUConversion)
|
||||
@@ -87,31 +88,31 @@ namespace ADOFAIRenderer.Util
|
||||
var bufferSize = texture.width * texture.height * 4; // RGBA = 4 channel
|
||||
state.Setup(currentFrame, bufferSize, useGPUConversion, expectedFmt, texture.width, texture.height);
|
||||
|
||||
if (useGPUConversion && state.GPUBuffer != null && RenderMod.ColorConversionShader)
|
||||
if (useGPUConversion && state.GPUBuffer != null && ModAssets.ColorConversionShader)
|
||||
{
|
||||
int kernelIndex = -1;
|
||||
if (expectedFmt == AVPixelFormat.AV_PIX_FMT_NV12)
|
||||
{
|
||||
kernelIndex = RenderMod.ColorConversionShader.FindKernel("CSMain_NV12");
|
||||
kernelIndex = ModAssets.ColorConversionShader.FindKernel("CSMain_NV12");
|
||||
}
|
||||
else if (expectedFmt == AVPixelFormat.AV_PIX_FMT_YUV420P)
|
||||
{
|
||||
kernelIndex = RenderMod.ColorConversionShader.FindKernel("CSMain_YUV420P");
|
||||
kernelIndex = ModAssets.ColorConversionShader.FindKernel("CSMain_YUV420P");
|
||||
}
|
||||
|
||||
if (kernelIndex >= 0)
|
||||
{
|
||||
RenderMod.ColorConversionShader.SetTexture(kernelIndex, SourceTexture, texture);
|
||||
RenderMod.ColorConversionShader.SetBuffer(kernelIndex, DestinationBuffer, state.GPUBuffer);
|
||||
RenderMod.ColorConversionShader.SetInt(Width, texture.width);
|
||||
RenderMod.ColorConversionShader.SetInt(Height, texture.height);
|
||||
ModAssets.ColorConversionShader.SetTexture(kernelIndex, SourceTexture, texture);
|
||||
ModAssets.ColorConversionShader.SetBuffer(kernelIndex, DestinationBuffer, state.GPUBuffer);
|
||||
ModAssets.ColorConversionShader.SetInt(Width, texture.width);
|
||||
ModAssets.ColorConversionShader.SetInt(Height, texture.height);
|
||||
|
||||
var threadGroupsX = expectedFmt == AVPixelFormat.AV_PIX_FMT_NV12
|
||||
? (texture.width + 31) / 32
|
||||
: (texture.width + 63) / 64;
|
||||
var threadGroupsY = (texture.height + 15) / 16;
|
||||
|
||||
RenderMod.ColorConversionShader.Dispatch(kernelIndex, threadGroupsX, threadGroupsY, 1);
|
||||
ModAssets.ColorConversionShader.Dispatch(kernelIndex, threadGroupsX, threadGroupsY, 1);
|
||||
|
||||
AsyncGPUReadback.Request(
|
||||
state.GPUBuffer,
|
||||
|
||||
Reference in new issue
Block a user