优化数组拷贝的性能

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);
half4 color = tex2D(_MainTex,mapUV);
float rawIndex = color.b;

View File

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

View File

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

View File

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