first commit

This commit is contained in:
murdle
2026-03-01 02:38:58 +02:00
commit 19250b9db4
19111 changed files with 4358159 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
#include "stdafx.h"
#include "ImprovedNoise_SPU.h"
double ImprovedNoise_SPU::lerp(double t, double a, double b)
{
return a + t * (b - a);
}
double ImprovedNoise_SPU::grad2(int hash, double x, double z)
{
int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
double u = (1-((h&8)>>3))*x, // INTO 12 GRADIENT DIRECTIONS.
v = h < 4 ? 0 : h == 12 || h == 14 ? x : z;
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
}
double ImprovedNoise_SPU::grad(int hash, double x, double y, double z)
{
int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
double u = h < 8 ? x : y, // INTO 12 GRADIENT DIRECTIONS.
v = h < 4 ? y : h == 12 || h == 14 ? x : z;
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
}
void ImprovedNoise_SPU::add(double* buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow)
{
if (ySize==1)
{
int A = 0, AA = 0, B = 0, BA = 0;
double vv0 = 0, vv2 = 0;
int pp = 0;
double scale = 1.0 / pow;
for (int xx = 0; xx < xSize; xx++)
{
double x = _x + (xx) * xs + xo;
int xf = (int) x;
if (x < xf) xf--;
int X = xf & 255;
x -= xf;
double u = x * x * x * (x * (x * 6 - 15) + 10);
for (int zz = 0; zz < zSize; zz++)
{
double z = _z + (zz) * zs + zo;
int zf = (int) z;
if (z < zf) zf--;
int Z = zf & 255;
z -= zf;
double w = z * z * z * (z * (z * 6 - 15) + 10);
A = p[X] + 0;
AA = p[A] + Z;
B = p[X + 1] + 0;
BA = p[B] + Z;
vv0 = lerp(u, grad2(p[AA], x, z), grad(p[BA], x - 1, 0, z));
vv2 = lerp(u, grad(p[AA + 1], x, 0, z - 1), grad(p[BA + 1], x - 1, 0, z - 1));
double val = lerp(w, vv0, vv2);
buffer[pp++] += val * scale;
}
}
return;
}
int pp = 0;
double scale = 1 / pow;
int yOld = -1;
int A = 0, AA = 0, AB = 0, B = 0, BA = 0, BB = 0;
double vv0 = 0, vv1 = 0, vv2 = 0, vv3 = 0;
for (int xx = 0; xx < xSize; xx++)
{
double x = _x + (xx) * xs + xo;
int xf = (int) x;
if (x < xf) xf--;
int X = xf & 255;
x -= xf;
double u = x * x * x * (x * (x * 6 - 15) + 10);
for (int zz = 0; zz < zSize; zz++)
{
double z = _z + (zz) * zs + zo;
int zf = (int) z;
if (z < zf) zf--;
int Z = zf & 255;
z -= zf;
double w = z * z * z * (z * (z * 6 - 15) + 10);
for (int yy = 0; yy < ySize; yy++)
{
double y = _y + (yy) * ys + yo;
int yf = (int) y;
if (y < yf) yf--;
int Y = yf & 255;
y -= yf;
double v = y * y * y * (y * (y * 6 - 15) + 10);
if (yy == 0 || Y != yOld)
{
yOld = Y;
A = p[X] + Y;
AA = p[A] + Z;
AB = p[A + 1] + Z;
B = p[X + 1] + Y;
BA = p[B] + Z;
BB = p[B + 1] + Z;
vv0 = lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z));
vv1 = lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z));
vv2 = lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1));
vv3 = lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1));
}
double v0 = lerp(v, vv0, vv1);
double v1 = lerp(v, vv2, vv3);
double val = lerp(w, v0, v1);
buffer[pp++] += val * scale;
}
}
}
}

View File

@@ -0,0 +1,20 @@
#pragma once
// #include "Synth.h"
class ImprovedNoise_SPU// : public Synth
{
public:
int p[512];
double scale;
double xo, yo, zo;
double lerp(double t, double a, double b);
double grad2(int hash, double x, double z);
double grad(int hash, double x, double y, double z);
void add(double* buffer, double _x, double _y, double _z, int xSize, int ySize, int zSize, double xs, double ys, double zs, double pow);
};

View File

@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="ContentPackage|PS3">
<Configuration>ContentPackage</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|PS3">
<Configuration>Debug</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|PS3">
<Configuration>Release</Configuration>
<Platform>PS3</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ImprovedNoise_SPU.cpp" />
<ClCompile Include="PerlinNoiseJob.cpp" />
<ClCompile Include="PerlinNoise_SPU.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ImprovedNoise_SPU.h" />
<ClInclude Include="PerlinNoiseJob.h" />
<ClInclude Include="PerlinNoise_SPU.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4CDF5745-FCF3-474D-941B-ABBEA788E8DA}</ProjectGuid>
<ProjectName>PerlinNoise</ProjectName>
<SccProjectName>%24/StoriesPark/Minecraft/MinecraftConsoles-dev/Minecraft.Client/PS3/SPU_Tasks/PerlinNoise</SccProjectName>
<SccAuxPath>https://tfs4jstudios.visualstudio.com/defaultcollection</SccAuxPath>
<SccLocalPath>.</SccLocalPath>
<SccProvider>{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}</SccProvider>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>SPU</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>SPU</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>SPU</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">PS3_Debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">PS3_Debug\</IntDir>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);undefined;$(ExtensionsToDeleteOnClean)</ExtensionsToDeleteOnClean>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'" />
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">false</GenerateManifest>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">PS3_Release\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">PS3_ContentPackage\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">PS3_Release\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">PS3_ContentPackage\</IntDir>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);undefined;$(ExtensionsToDeleteOnClean)</ExtensionsToDeleteOnClean>
<ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">*.obj;*.d;*.map;*.lst;*.pch;$(TargetPath);undefined;$(ExtensionsToDeleteOnClean)</ExtensionsToDeleteOnClean>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|PS3'" />
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'" />
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">false</GenerateManifest>
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">false</GenerateManifest>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">$(ProjectName)</TargetName>
<SpursUsage>SpursInit</SpursUsage>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">$(ProjectName)</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">$(ProjectName)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|PS3'">
<ClCompile>
<AdditionalOptions>-ffunction-sections -fdata-sections -fstack-check %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(SN_PS3_PATH)\spu\include\sn;$(SCE_PS3_ROOT)\target\spu\include;$(SCE_PS3_ROOT)\target\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<PreprocessorDefinitions>SN_TARGET_PS3_SPU;_DEBUG;__GCC__;SPU;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<OptimizationLevel>Level3</OptimizationLevel>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalOptions>-Wl,--gc-sections -g %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>-ldma;-lspurs_jq;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
</Link>
<SpuElfConversion>
<EmbedFormat>JobBin2</EmbedFormat>
<OutputFile>..\ObjFiles\Debug\$(TargetName).ppu$(ObjectExt)</OutputFile>
</SpuElfConversion>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|PS3'">
<ClCompile>
<AdditionalOptions>-ffunction-sections -fdata-sections -fstack-check %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(SN_PS3_PATH)\spu\include\sn;$(SCE_PS3_ROOT)\target\spu\include;$(SCE_PS3_ROOT)\target\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OptimizationLevel>Level3</OptimizationLevel>
<PreprocessorDefinitions>SN_TARGET_PS3_SPU;NDEBUG;__GCC__;SPU;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UnrollLoops>true</UnrollLoops>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalOptions>-Wl,--gc-sections -g %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>-ldma;-lspurs_jq;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
</Link>
<SpuElfConversion>
<EmbedFormat>JobBin2</EmbedFormat>
<OutputFile>..\ObjFiles\Release\$(TargetName).ppu$(ObjectExt)</OutputFile>
</SpuElfConversion>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ContentPackage|PS3'">
<ClCompile>
<AdditionalOptions>-ffunction-sections -fdata-sections -fstack-check %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(SN_PS3_PATH)\spu\include\sn;$(SCE_PS3_ROOT)\target\spu\include;$(SCE_PS3_ROOT)\target\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OptimizationLevel>Level3</OptimizationLevel>
<PreprocessorDefinitions>SN_TARGET_PS3_SPU;NDEBUG;__GCC__;SPU;_CONTENT_PACKAGE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UnrollLoops>true</UnrollLoops>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<Link>
<AdditionalOptions>-Wl,--gc-sections -g %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>-ldma;-lspurs_jq;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
</Link>
<SpuElfConversion>
<EmbedFormat>JobBin2</EmbedFormat>
<OutputFile>..\ObjFiles\ContentPackage\$(TargetName).ppu$(ObjectExt)</OutputFile>
<StripMode>Hard</StripMode>
</SpuElfConversion>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,51 @@
/* SCE CONFIDENTIAL
PlayStation(R)3 Programmer Tool Runtime Library 430.001
* Copyright (C) 2007 Sony Computer Entertainment Inc.
* All Rights Reserved.
*/
/* common headers */
#include <stdint.h>
#include <stdlib.h>
#include <alloca.h>
#include <spu_intrinsics.h>
#include <cell/spurs.h>
#include <cell/dma.h>
#include <cell/spurs/job_queue.h>
#include "PerlinNoiseJob.h"
#include "..\Common\DmaData.h"
#include <vectormath/c/vectormath_aos_v.h>
static const bool sc_verbose = false;
CellSpursJobContext2* g_pSpursJobContext;
void cellSpursJobQueueMain(CellSpursJobContext2 *pContext, CellSpursJob256 *pJob)
{
// CellSpursTaskId idTask = cellSpursGetTaskId();
unsigned int idSpu = cellSpursGetCurrentSpuId();
if(sc_verbose)
spu_print("PerlinNoiseJob [SPU#%u] start\n", idSpu);
g_pSpursJobContext = pContext;
uint32_t eaDataIn = pJob->workArea.userData[0];
// uint32_t eaDataOut =pJob->workArea.userData[1];
PerlinNoise_DataIn dataIn;
DmaData_SPU::getAndWait(&dataIn, eaDataIn, sizeof(PerlinNoise_DataIn));
dataIn.m_perlinData.getRegion( dataIn.m_outputBuffer,
dataIn.x, dataIn.y, dataIn.z,
dataIn.xSize, dataIn.ySize, dataIn.zSize,
dataIn.xScale, dataIn.yScale, dataIn.zScale);
if(sc_verbose)
spu_print("PerlinNoiseJob [SPU#%u] exit\n", idSpu);
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include <vectormath\cpp\vectormath_aos.h>
#include "PerlinNoise_SPU.h"
class PerlinNoise_DataIn
{
public:
#ifndef SN_TARGET_PS3_SPU
void set(PerlinNoise* pNoise, doubleArray& buffer, int x, int y, int z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale)
{
int arraySize = xSize * ySize * zSize;
// make sure it's 16 byte aligned
if(arraySize & 1)
arraySize++;
if (buffer.data == NULL)
buffer = doubleArray(arraySize);
for (unsigned int i = 0; i < buffer.length; i++)
buffer[i] = 0;
m_perlinData.setup(pNoise);
m_outputBuffer = buffer.data;
this->x = x;
this->y = y;
this->z = z;
this->xSize = xSize;
this->ySize = ySize;
this->zSize = zSize;
this->xScale = xScale;
this->yScale = yScale;
this->zScale = zScale;
}
void set(PerlinNoise* pNoise, doubleArray& buffer, int x, int z, int xSize, int zSize, double xScale, double zScale, double pow)
{
set(pNoise, buffer, x, 10, z, xSize, 1, zSize, xScale, 1, zScale);
}
#endif
PerlinNoise_SPU m_perlinData;
double* m_outputBuffer;
int x, y, z;
int xSize, ySize, zSize;
double xScale, yScale, zScale;
};

View File

@@ -0,0 +1,85 @@
#include "PerlinNoise_SPU.h"
#include "..\Common\DmaData.h"
#include <alloca.h>
int64_t lfloor(double v)
{
int64_t i = (int64_t) v;
return v < i ? i - 1 : i;
}
//
// class PPUStoreArray
// {
// static const int sc_cacheSize = 1024;
// double m_localCache[sc_cacheSize];
// double* m_pDataPPU;
// int m_cachePos;
// int m_ppuPos;
//
// public:
// PPUStoreArray(uintptr_t pDataPPU) { m_pDataPPU = (double*)pDataPPU; m_cachePos = 0; m_ppuPos = 0; flush();}
//
// void store(int val)
// {
// m_localCache[m_cachePos] = val;
// m_cachePos++;
// if(m_cachePos >= sc_cacheSize)
// flush();
// }
//
// void flush()
// {
// if(m_cachePos > 0)
// {
// // dma the local cache back to PPU and start again
// // spu_print("DMAing %d bytes from 0x%08x(SPU) to 0x%08x(PPU)\n",(int)( m_cachePos*sizeof(int)), (int)m_localCache, (int)&m_pDataPPU[m_ppuPos]);
// DmaData_SPU::put(m_localCache, (uintptr_t)&m_pDataPPU[m_ppuPos], DmaData_SPU::roundUpDMASize(m_cachePos*sizeof(double)));
// m_ppuPos += m_cachePos;
// m_cachePos = 0;
// }
// for(int i=0;i<sc_cacheSize;i++)
// m_localCache[i] = 0.0;
// }
// int getSize() { return m_ppuPos; }
// };
void PerlinNoise_SPU::getRegion(double* buffer, int x, int y, int z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale)
{
// if (buffer.data == NULL) buffer = doubleArray(xSize * ySize * zSize);
int bufLen = xSize * ySize * zSize;
int bufMemSize = DmaData_SPU::roundUpDMASize(bufLen*sizeof(double));
double* localBuffer = (double*)alloca(bufMemSize);
for (unsigned int i = 0; i < bufLen; i++)
localBuffer[i] = 0;
double pow = 1;
for (int i = 0; i < levels; i++)
{
// value += noiseLevels[i].getValue(x * pow, y * pow, z * pow) / pow;
double xx = x * pow * xScale;
double yy = y * pow * yScale;
double zz = z * pow * zScale;
int64_t xb = lfloor(xx);
int64_t zb = lfloor(zz);
xx -= xb;
zz -= zb;
xb %= 16777216;
zb %= 16777216;
xx += xb;
zz += zb;
noiseLevels[i].add(localBuffer, xx, yy, zz, xSize, ySize, zSize, xScale * pow, yScale * pow, zScale * pow, pow);
pow /= 2;
}
DmaData_SPU::putAndWait(localBuffer,(uintptr_t)buffer, bufMemSize);
}
void PerlinNoise_SPU::getRegion(double* sr, int x, int z, int xSize, int zSize, double xScale, double zScale, double pow)
{
getRegion(sr, x, 10, z, xSize, 1, zSize, xScale, 1, zScale);
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include <vectormath\cpp\vectormath_aos.h>
#include "ImprovedNoise_SPU.h"
#ifndef SN_TARGET_PS3_SPU
#include "PerlinNoise.h"
#endif
class PerlinNoise_SPU//: public Synth
{
private:
static const int MAX_NOISE_LEVELS = 16;
ImprovedNoise_SPU noiseLevels[MAX_NOISE_LEVELS];
int levels;
public:
void getRegion(double* buffer, int x, int y, int z, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale);
void getRegion(double* sr, int x, int z, int xSize, int zSize, double xScale, double zScale, double pow);
#ifndef SN_TARGET_PS3_SPU
void setup(PerlinNoise* pNoise)
{
levels = pNoise->levels;
for(int i=0;i<pNoise->levels;i++)
{
ImprovedNoise_SPU& noiseSPU = noiseLevels[i];
ImprovedNoise* noisePPU = pNoise->noiseLevels[i];
noiseSPU.scale = noisePPU->scale;
noiseSPU.xo = noisePPU->xo;
noiseSPU.yo = noisePPU->yo;
noiseSPU.zo = noisePPU->zo;
memcpy(noiseSPU.p, noisePPU->p, sizeof(noiseSPU.p));
}
}
#endif
};