spd aspect

This commit is contained in:
StarBeats 2025-06-25 11:11:33 +08:00
parent 3e340fe793
commit 4fa3eca91e
2 changed files with 21 additions and 16 deletions

View File

@ -208,10 +208,10 @@ namespace X.Rendering.Feature
resizeX = Mathf.IsPowerOfTwo(viewportSize.x) ? viewportSize.x : Mathf.NextPowerOfTwo(viewportSize.x); resizeX = Mathf.IsPowerOfTwo(viewportSize.x) ? viewportSize.x : Mathf.NextPowerOfTwo(viewportSize.x);
resizeY = Mathf.IsPowerOfTwo(viewportSize.y) ? viewportSize.y : Mathf.NextPowerOfTwo(viewportSize.y); resizeY = Mathf.IsPowerOfTwo(viewportSize.y) ? viewportSize.y : Mathf.NextPowerOfTwo(viewportSize.y);
if (resizeX > viewportSize.x) //if (resizeX > viewportSize.x)
resizeX /= 2; // resizeX /= 2;
if (resizeY > viewportSize.y) //if (resizeY > viewportSize.y)
resizeY /= 2; // resizeY /= 2;
Vector2Int hardwareTextureSize = new Vector2Int(resizeX, resizeY); Vector2Int hardwareTextureSize = new Vector2Int(resizeX, resizeY);
mipLevelOffsets[0] = Vector2Int.zero; mipLevelOffsets[0] = Vector2Int.zero;
@ -443,10 +443,11 @@ namespace X.Rendering.Feature
}, filterMode: FilterMode.Point, name: depthPyramidNames[hizIndex]); }, filterMode: FilterMode.Point, name: depthPyramidNames[hizIndex]);
depthPyramidTexs[hizIndex] = hizBuffer; depthPyramidTexs[hizIndex] = hizBuffer;
var dispatchX = Mathf.CeilToInt(mip0SizeNOP.x / 64f); var dispatchX = Mathf.CeilToInt(mipOffsetAndSizes[0].z / 64f);
var dispatchY = Mathf.CeilToInt(mip0SizeNOP.y / 64f); var dispatchY = Mathf.CeilToInt(mipOffsetAndSizes[0].w / 64f);
cmd.SetComputeIntParam(settings.Spd, "mips", mipLevelCount); cmd.SetComputeIntParam(settings.Spd, "mips", mipLevelCount);
cmd.SetComputeIntParam(settings.Spd, "numWorkGroups", dispatchX * dispatchY); cmd.SetComputeIntParam(settings.Spd, "numWorkGroups", dispatchX * dispatchY);
cmd.SetComputeVectorParam(settings.Spd, "inputTextureSize", new Vector4(mip0SizeNOP.x, mip0SizeNOP.y, 0, 0));
cmd.SetComputeVectorArrayParam(settings.Spd, "_MipOffsetAndSizeArray", mipOffsetAndSizes); cmd.SetComputeVectorArrayParam(settings.Spd, "_MipOffsetAndSizeArray", mipOffsetAndSizes);

View File

@ -16,6 +16,15 @@
#include "ffx/ffx_common_types.h" #include "ffx/ffx_common_types.h"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
Texture2D<FfxFloat32> _InputDepth;
RWTexture2D<FfxFloat32> _OutDepth;
float4 _MipOffsetAndSizeArray[16];
FfxUInt32 mips;
FfxUInt32x2 inputTextureSize;
FfxUInt32 numWorkGroups;
FFX_GROUPSHARED FfxUInt32 spdCounter;
RWTexture2D<FfxUInt32> rw_internal_global_atomic;
FFX_GROUPSHARED FfxFloat32 spdIntermediate[16][16]; FFX_GROUPSHARED FfxFloat32 spdIntermediate[16][16];
void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value) { void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value) {
@ -52,9 +61,6 @@ FfxFloat16x4 SpdReduce4H(FfxFloat16x4 v0, FfxFloat16x4 v1, FfxFloat16x4 v2, FfxF
return max(max(v0, v1), max(v2, v3)); return max(max(v0, v1), max(v2, v3));
#endif #endif
} }
Texture2D<FfxFloat32> _InputDepth;
RWTexture2D<FfxFloat32> _OutDepth;
float4 _MipOffsetAndSizeArray[16];
FfxFloat32x4 SpdLoad(FfxInt32x2 coordinate, FfxUInt32 slice) FfxFloat32x4 SpdLoad(FfxInt32x2 coordinate, FfxUInt32 slice)
{ {
@ -87,14 +93,12 @@ FfxFloat32x4 SpdLoadSourceImage(FfxInt32x2 coordinate, FfxUInt32 slice)
FfxFloat32x4 SpdLoadSourceImageH(FfxInt32x2 coordinate, FfxUInt32 slice) FfxFloat32x4 SpdLoadSourceImageH(FfxInt32x2 coordinate, FfxUInt32 slice)
{ {
return _InputDepth[coordinate].xxxx; uint4 cur = _MipOffsetAndSizeArray[0];
float2 uv = coordinate / float2(cur.zw);
FfxInt32x2 uv2 = FfxInt32x2(uv * inputTextureSize);
return _InputDepth[uv2].xxxx;
} }
FfxUInt32 mips;
FfxUInt32 numWorkGroups;
FFX_GROUPSHARED FfxUInt32 spdCounter;
RWTexture2D<FfxUInt32> rw_internal_global_atomic;
void IncreaseAtomicCounter(FFX_PARAMETER_IN FfxUInt32 slice, FFX_PARAMETER_INOUT FfxUInt32 counter) void IncreaseAtomicCounter(FFX_PARAMETER_IN FfxUInt32 slice, FFX_PARAMETER_INOUT FfxUInt32 counter)
{ {
InterlockedAdd(rw_internal_global_atomic[FfxInt32x2(0, 0)] , 1, counter); InterlockedAdd(rw_internal_global_atomic[FfxInt32x2(0, 0)] , 1, counter);