Skip to content

Commit

Permalink
Merge pull request #105 from reveriejake/master
Browse files Browse the repository at this point in the history
Fix:  'internal error: no storage type for block output' with Unity HLSL
  • Loading branch information
Auburn authored Nov 10, 2022
2 parents 5923df5 + 51700fa commit 95900f7
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions HLSL/FastNoiseLite.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ typedef int fnl_cellular_return_type;
#define FNL_DOMAIN_WARP_BASICGRID 2
typedef int fnl_domain_warp_type;

// Removes [0x80004005 - unknown error] 'internal error: no storage type for block output'
#if UNITY_VERSION
#define FNL_FLATTEN [flatten]
#define FNL_UNROLL [unroll(1)]
#else
#define FNL_FLATTEN
#define FNL_UNROLL
#endif

/**
* Structure containing entire noise system state.
* @note Must only be created using fnlCreateState(optional: seed). To ensure defaults are set.
Expand Down Expand Up @@ -537,7 +546,7 @@ static float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);

static float _fnlGenNoiseSingle2D(fnl_state state, int seed, FNLfloat x, FNLfloat y)
{
switch (state.noise_type)
FNL_FLATTEN switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleSimplex2D(seed, x, y);
Expand All @@ -558,7 +567,7 @@ static float _fnlGenNoiseSingle2D(fnl_state state, int seed, FNLfloat x, FNLfloa

static float _fnlGenNoiseSingle3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
switch (state.noise_type)
FNL_FLATTEN switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleOpenSimplex23D(seed, x, y, z);
Expand Down Expand Up @@ -952,7 +961,7 @@ static float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);

for (int l = 0; ; l++)
FNL_UNROLL for (int l = 0; ; l++)
{
if (a > 0)
{
Expand Down Expand Up @@ -1291,7 +1300,7 @@ static float _fnlSingleCellular2D(fnl_state state, int seed, FNLfloat x, FNLfloa
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;

switch (state.cellular_distance_func)
FNL_FLATTEN switch (state.cellular_distance_func)
{
default:
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
Expand Down Expand Up @@ -1380,7 +1389,7 @@ static float _fnlSingleCellular2D(fnl_state state, int seed, FNLfloat x, FNLfloa
}
}

if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
FNL_FLATTEN if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
Expand Down Expand Up @@ -1767,7 +1776,7 @@ static void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, fl

static void _fnlDoSingleDomainWarp2D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp)
{
switch (state.domain_warp_type)
FNL_FLATTEN switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, xp, yp, false);
Expand All @@ -1783,7 +1792,7 @@ static void _fnlDoSingleDomainWarp2D(fnl_state state, int seed, float amp, float

static void _fnlDoSingleDomainWarp3D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp)
{
switch (state.domain_warp_type)
FNL_FLATTEN switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, xp, yp, zp, false);
Expand Down Expand Up @@ -2251,7 +2260,7 @@ float fnlGetNoise2D(fnl_state state, FNLfloat x, FNLfloat y)
{
_fnlTransformNoiseCoordinate2D(state, x, y);

switch (state.fractal_type)
FNL_FLATTEN switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle2D(state, state.seed, x, y);
Expand All @@ -2269,7 +2278,7 @@ float fnlGetNoise3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
_fnlTransformNoiseCoordinate3D(state, x, y, z);

// Select a noise type
switch (state.fractal_type)
FNL_FLATTEN switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle3D(state, state.seed, x, y, z);
Expand All @@ -2284,7 +2293,7 @@ float fnlGetNoise3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)

void fnlDomainWarp2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
switch (state.fractal_type)
FNL_FLATTEN switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle2D(state, x, y);
Expand All @@ -2300,7 +2309,7 @@ void fnlDomainWarp2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)

void fnlDomainWarp3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
switch (state.fractal_type)
FNL_FLATTEN switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle3D(state, x, y, z);
Expand All @@ -2312,4 +2321,4 @@ void fnlDomainWarp3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout
_fnlDomainWarpFractalIndependent3D(state, x, y, z);
break;
}
}
}

0 comments on commit 95900f7

Please sign in to comment.