Initial Support for AVX. I need to add a Vsync option for better testing.
This commit is contained in:
GabsPuNs
2026-04-21 23:02:53 -04:00
parent abd269f79d
commit 6519631ba1
8 changed files with 279 additions and 9 deletions

View File

@@ -74,6 +74,10 @@ static LevelRenderer_cull_DataIn g_cullDataIn[4] __attribute__((__aligned__(16))
static LevelRenderer_FindNearestChunk_DataIn g_findNearestChunkDataIn __attribute__((__aligned__(16)));
#endif
#ifdef __AVX__
#include <immintrin.h>
#endif
ResourceLocation LevelRenderer::MOON_LOCATION = ResourceLocation(TN_TERRAIN_MOON);
ResourceLocation LevelRenderer::MOON_PHASES_LOCATION = ResourceLocation(TN_TERRAIN_MOON_PHASES);
ResourceLocation LevelRenderer::SUN_LOCATION = ResourceLocation(TN_TERRAIN_SUN);
@@ -2451,8 +2455,33 @@ bool inline clip(float * __restrict bb, float * __restrict frustum)
const float x0 = bb[0], y0 = bb[1], z0 = bb[2];
const float x1 = bb[3], y1 = bb[4], z1 = bb[5];
#ifdef __AVX__
__m256 vX = _mm256_setr_ps(x0, x1, x0, x1, x0, x1, x0, x1);
__m256 vY = _mm256_setr_ps(y0, y0, y1, y1, y0, y0, y1, y1);
__m256 vZ = _mm256_setr_ps(z0, z0, z0, z0, z1, z1, z1, z1);
__m256 vZero = _mm256_setzero_ps();
#endif
for (int i = 0; i < 6; ++i, frustum += 4)
{
#ifdef __AVX__
__m256 vA = _mm256_set1_ps(frustum[0]);
__m256 vB = _mm256_set1_ps(frustum[1]);
__m256 vC = _mm256_set1_ps(frustum[2]);
__m256 vD = _mm256_set1_ps(frustum[3]);
__m256 dist = _mm256_add_ps(
_mm256_add_ps(_mm256_mul_ps(vA, vX), _mm256_mul_ps(vB, vY)),
_mm256_add_ps(_mm256_mul_ps(vC, vZ), vD)
);
__m256 mask = _mm256_cmp_ps(dist, vZero, _CMP_GT_OQ);
int movemask = _mm256_movemask_ps(mask);
if (movemask == 0)
return false;
#else
const float a = frustum[0], b = frustum[1], c = frustum[2], d = frustum[3];
if (a * x0 + b * y0 + c * z0 + d > 0) continue;
if (a * x1 + b * y0 + c * z0 + d > 0) continue;
@@ -2464,6 +2493,7 @@ bool inline clip(float * __restrict bb, float * __restrict frustum)
if (a * x1 + b * y1 + c * z1 + d > 0) continue;
return false;
#endif
}
return true;