优化数组拷贝的性能

This commit is contained in:
ALIENJACK\alien 2024-08-15 10:33:29 +08:00
parent 8f683b0c3c
commit c7445147b4
5 changed files with 20 additions and 18 deletions

@ -1 +1 @@
Subproject commit 8b0f0be28a7697597e9d416fa90a8ba62182bfa4 Subproject commit 1acd8341ce457e66d172834dfb909569db309c33

View File

@ -107,6 +107,8 @@
mapUV.x = lerp(start,end, mapUV.x); mapUV.x = lerp(start,end, mapUV.x);
half4 color = tex2D(_MainTex,mapUV); half4 color = tex2D(_MainTex,mapUV);
float rawIndex = color.b; float rawIndex = color.b;

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Unity.Collections.LowLevel.Unsafe;
namespace VirtualNes.Core namespace VirtualNes.Core
{ {
@ -19,28 +21,26 @@ namespace VirtualNes.Core
memset(array, 0, value, length); memset(array, 0, value, length);
} }
public static void memset(uint[] array, uint value, int length) public unsafe static void memset(byte[] array, int offset, byte value, int length)
{ {
fixed (byte* ptr = array)
{
var offsetptr = ptr + offset;
Unsafe.InitBlock(offsetptr, value, (uint)length);
}
}
public unsafe static void memset(uint[] array, int offset, byte value, int length)
{
fixed (uint* ptr = array)
{
var offsetptr = ptr + offset;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
array[i] = value; offsetptr[i] = value;
} }
} }
public static void memset(byte[] array, int offset, byte value, int length)
{
for (int i = offset; i < length; i++)
{
array[i] = value;
}
}
public static void memset(uint[] array, int offset, uint value, int length)
{
for (int i = offset; i < length; i++)
{
array[i] = value;
}
} }
} }
} }

View File

@ -360,7 +360,7 @@ namespace VirtualNes.Core
loopy_shift = 0; loopy_shift = 0;
if (lpScreen != null) if (lpScreen != null)
MemoryUtility.memset(lpScreen, 0x3F, SCREEN_WIDTH * SCREEN_HEIGHT); MemoryUtility.memset(lpScreen, 0, 0x3F, SCREEN_WIDTH * SCREEN_HEIGHT);
if (lpColormode != null) if (lpColormode != null)
MemoryUtility.memset(lpColormode, 0, SCREEN_HEIGHT); MemoryUtility.memset(lpColormode, 0, SCREEN_HEIGHT);
} }
@ -376,7 +376,7 @@ namespace VirtualNes.Core
if (lpScreen != null) if (lpScreen != null)
{ {
MemoryUtility.memset(lpScreen, 0x3F, SCREEN_WIDTH); MemoryUtility.memset(lpScreen, 0, 0x3F, SCREEN_WIDTH);
} }
if (lpColormode != null) if (lpColormode != null)
{ {

View File

@ -4,7 +4,7 @@
"references": [], "references": [],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],
"allowUnsafeCode": false, "allowUnsafeCode": true,
"overrideReferences": false, "overrideReferences": false,
"precompiledReferences": [], "precompiledReferences": [],
"autoReferenced": false, "autoReferenced": false,