Cut 10b Soul Pass #1 fixes: live GPU sparks, 128-slot Bitonic tile sort, monotonic sweep-line, and RD profiler ring fix
This commit is contained in:
parent
ffe777b9d4
commit
326101158e
5 changed files with 135 additions and 52 deletions
|
|
@ -7,8 +7,8 @@ namespace RustToDust.Client;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 4-pass Forward+ Vulkan compute pipeline (<c>PostOpaque</c>) owning:
|
/// 4-pass Forward+ Vulkan compute pipeline (<c>PostOpaque</c>) owning:
|
||||||
/// Pass 0: <c>flow_field_step.glsl</c> (camera-snapped 3m 64x24x64 RGBA16F ping-pong -> <see cref="Texture3Drd"/>)
|
/// Pass 0: <c>flow_field_step.glsl</c> (camera-snapped 3m 64x24x64 RGBA16F ping-pong -> <see cref="Texture3Drd"/>)
|
||||||
/// Pass 1: <c>volumetric_tile_cull.glsl</c> (16x16 half-res tiles + 1-warp 32-element Bitonic sort)
|
/// Pass 1: <c>volumetric_tile_cull.glsl</c> (16x16 half-res tiles + 128-element Bitonic sort)
|
||||||
/// Pass 2: <c>volumetric_raymarch.glsl</c> (sorted sweep-line + Aetheria curl/triNoise + shock cavity + 2 shadow taps)
|
/// Pass 2: <c>volumetric_raymarch.glsl</c> (sorted monotonic sweep-line + Aetheria curl/triNoise + shock cavity + 2 shadow taps)
|
||||||
/// Pass 3: <c>volumetric_composite.glsl</c> (2x2 bilateral depth upsample pre-tonemap)
|
/// Pass 3: <c>volumetric_composite.glsl</c> (2x2 bilateral depth upsample pre-tonemap)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
|
|
@ -84,6 +84,7 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
|
|
||||||
// Lightweight RD timestamp telemetry (populated when ProfilingEnabled == true)
|
// Lightweight RD timestamp telemetry (populated when ProfilingEnabled == true)
|
||||||
public bool ProfilingEnabled { get; set; }
|
public bool ProfilingEnabled { get; set; }
|
||||||
|
private ulong _lastSampledTimestampFrame = ulong.MaxValue;
|
||||||
public double LastFlowGpuMs { get; private set; }
|
public double LastFlowGpuMs { get; private set; }
|
||||||
public double LastCullGpuMs { get; private set; }
|
public double LastCullGpuMs { get; private set; }
|
||||||
public double LastMarchGpuMs { get; private set; }
|
public double LastMarchGpuMs { get; private set; }
|
||||||
|
|
@ -275,8 +276,8 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
Rid prevFlowRid = _flowTexRids[_flowReadIdx];
|
Rid prevFlowRid = _flowTexRids[_flowReadIdx];
|
||||||
Rid nextFlowRid = _flowTexRids[writeIdx];
|
Rid nextFlowRid = _flowTexRids[writeIdx];
|
||||||
|
|
||||||
bool captureThisFrame = ProfilingEnabled && (_frameCounter & 7u) == 0u && _frameCounter >= 32u && rd.GetCapturedTimestampsCount() < 180;
|
bool captureThisFrame = ProfilingEnabled && (_frameCounter & 7u) == 0u && _frameCounter >= 24u && rd.GetCapturedTimestampsCount() < 180;
|
||||||
if (ProfilingEnabled && (_frameCounter & 7u) == 1u && _frameCounter >= 32u)
|
if (ProfilingEnabled)
|
||||||
{
|
{
|
||||||
SamplePreviousFrameTimestamps(rd);
|
SamplePreviousFrameTimestamps(rd);
|
||||||
}
|
}
|
||||||
|
|
@ -373,6 +374,13 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ulong tsFrame = rd.GetCapturedTimestampsFrame();
|
||||||
|
if (tsFrame == _lastSampledTimestampFrame)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_lastSampledTimestampFrame = tsFrame;
|
||||||
|
|
||||||
ulong tFlow = 0, tCull = 0, tMarch = 0, tComp = 0, tEnd = 0;
|
ulong tFlow = 0, tCull = 0, tMarch = 0, tComp = 0, tEnd = 0;
|
||||||
for (uint i = 0; i < count; i++)
|
for (uint i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -387,11 +395,9 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Godot 4.7 Vulkan GetCapturedTimestampGpuTime empirically returns nanoseconds (confirmed vs --gpu-profile; GodotSharp.xml's "microseconds" doc is stale)
|
||||||
if (tFlow > 0 && tEnd >= tFlow)
|
if (tFlow > 0 && tEnd >= tFlow)
|
||||||
{
|
{
|
||||||
// Godot RD timestamps are in nanoseconds -> convert to ms (Wait: docs say microseconds or nanoseconds; let's check magnitude!)
|
|
||||||
// Godot 4 RenderingDevice.GetCapturedTimestampGpuTime returns nanoseconds in Vulkan (Wait: XML says microseconds, let's check both or measure delta!).
|
|
||||||
// Wait: in Godot 4 Vulkan `get_captured_timestamp_gpu_time` actually returns nanoseconds in 4.2+ or microseconds? Let's check in live Vulkan run!
|
|
||||||
if (tCull > tFlow && tMarch > tCull && tComp > tMarch && tEnd >= tComp)
|
if (tCull > tFlow && tMarch > tCull && tComp > tMarch && tEnd >= tComp)
|
||||||
{
|
{
|
||||||
LastFlowGpuMs = (tCull - tFlow) / 1_000_000.0;
|
LastFlowGpuMs = (tCull - tFlow) / 1_000_000.0;
|
||||||
|
|
@ -399,7 +405,7 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
|
||||||
LastMarchGpuMs = (tComp - tMarch) / 1_000_000.0;
|
LastMarchGpuMs = (tComp - tMarch) / 1_000_000.0;
|
||||||
LastCompGpuMs = (tEnd - tComp) / 1_000_000.0;
|
LastCompGpuMs = (tEnd - tComp) / 1_000_000.0;
|
||||||
}
|
}
|
||||||
else if (tEnd >= tFlow)
|
else
|
||||||
{
|
{
|
||||||
LastFlowGpuMs = (tEnd - tFlow) / 1_000_000.0;
|
LastFlowGpuMs = (tEnd - tFlow) / 1_000_000.0;
|
||||||
LastCullGpuMs = 0.0;
|
LastCullGpuMs = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ global uniform vec3 rtd_flow_origin;
|
||||||
global uniform vec3 rtd_flow_inv_extent;
|
global uniform vec3 rtd_flow_inv_extent;
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
ACTIVE = false;
|
ACTIVE = true;
|
||||||
|
TRANSFORM[0].xyz = VELOCITY;
|
||||||
|
TRANSFORM[1].xyz = vec3(0.0, 1.0, 0.0);
|
||||||
|
TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process() {
|
void process() {
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ public partial class Smoke : Node
|
||||||
await VerifyOrbitalDropSequenceAsync();
|
await VerifyOrbitalDropSequenceAsync();
|
||||||
await VerifyCut7bModularOrdnanceAsync();
|
await VerifyCut7bModularOrdnanceAsync();
|
||||||
VerifyForwardPlusAtmosphere();
|
VerifyForwardPlusAtmosphere();
|
||||||
|
await VerifyGpuSparksRenderAsync(isHeadless);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task VerifyHudAndShadersAsync(bool isHeadless)
|
private async Task VerifyHudAndShadersAsync(bool isHeadless)
|
||||||
|
|
@ -2386,6 +2387,74 @@ public partial class Smoke : Node
|
||||||
GD.Print($"SMOKE INFO: Cut 8 Forward+ verified (method={method}, sionZenithT={sionBaked.ZenithTransmittanceMean:F4}, desertZenithT={desertBaked.ZenithTransmittanceMean:F4}, desertHaze=({desertBaked.HazeColor.R:F3},{desertBaked.HazeColor.G:F3},{desertBaked.HazeColor.B:F3}), sionHaze=({sionBaked.HazeColor.R:F3},{sionBaked.HazeColor.G:F3},{sionBaked.HazeColor.B:F3}), grainLayer={atmo.FilmGrainLayer.Layer})");
|
GD.Print($"SMOKE INFO: Cut 8 Forward+ verified (method={method}, sionZenithT={sionBaked.ZenithTransmittanceMean:F4}, desertZenithT={desertBaked.ZenithTransmittanceMean:F4}, desertHaze=({desertBaked.HazeColor.R:F3},{desertBaked.HazeColor.G:F3},{desertBaked.HazeColor.B:F3}), sionHaze=({sionBaked.HazeColor.R:F3},{sionBaked.HazeColor.G:F3},{sionBaked.HazeColor.B:F3}), grainLayer={atmo.FilmGrainLayer.Layer})");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task VerifyGpuSparksRenderAsync(bool isHeadless)
|
||||||
|
{
|
||||||
|
if (isHeadless)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sparkVp = new SubViewport
|
||||||
|
{
|
||||||
|
Size = new Vector2I(128, 128),
|
||||||
|
OwnWorld3D = true,
|
||||||
|
TransparentBg = true,
|
||||||
|
RenderTargetUpdateMode = SubViewport.UpdateMode.Always
|
||||||
|
};
|
||||||
|
var env = new Godot.Environment
|
||||||
|
{
|
||||||
|
BackgroundMode = Godot.Environment.BGMode.Color,
|
||||||
|
BackgroundColor = new Color(0f, 0f, 0f, 0f)
|
||||||
|
};
|
||||||
|
sparkVp.AddChild(new WorldEnvironment { Environment = env });
|
||||||
|
var cam = new Camera3D
|
||||||
|
{
|
||||||
|
Position = new Vector3(0f, 0f, 5.5f),
|
||||||
|
Current = true
|
||||||
|
};
|
||||||
|
sparkVp.AddChild(cam);
|
||||||
|
var sparks = new GpuSparksSystem { Name = "SmokeSparkProbe" };
|
||||||
|
sparkVp.AddChild(sparks);
|
||||||
|
AddChild(sparkVp);
|
||||||
|
cam.LookAt(Vector3.Zero, Vector3.Up);
|
||||||
|
sparks.EnsureInitialized();
|
||||||
|
|
||||||
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
|
||||||
|
var idleImg = sparkVp.GetTexture().GetImage();
|
||||||
|
int idleLit = CountNonZeroAlphaPixels(idleImg, 0.05f);
|
||||||
|
Check(idleLit == 0, $"Expected 0 rendered spark pixels with AmountRatio=0.0f before EmitParticle, got {idleLit}");
|
||||||
|
|
||||||
|
sparks.EmitSparkBurst(Vector3.Zero, Vector3.Up, 128, new Color(4.5f, 2.5f, 0.75f, 1.0f), 8.0f, 0.05f);
|
||||||
|
sparks.EmitMuzzleStarburst(Vector3.Zero, new Color(5.0f, 3.0f, 1.0f, 1.0f), 0.75f, 0.14f);
|
||||||
|
|
||||||
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
|
||||||
|
var activeImg = sparkVp.GetTexture().GetImage();
|
||||||
|
int brightPixels = 0;
|
||||||
|
int w = activeImg.GetWidth();
|
||||||
|
int h = activeImg.GetHeight();
|
||||||
|
for (int y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
Color c = activeImg.GetPixel(x, y);
|
||||||
|
float lum = c.R * 0.2126f + c.G * 0.7152f + c.B * 0.0722f;
|
||||||
|
if (c.A > 0.05f && lum > 0.35f)
|
||||||
|
{
|
||||||
|
brightPixels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GD.Print($"SMOKE INFO: GpuSparksSystem Vulkan render probe idleLit={idleLit} brightPixels={brightPixels}");
|
||||||
|
Check(brightPixels > 25, $"Expected > 25 bright HDR spark pixels after EmitSparkBurst (start() ACTIVE=true), got {brightPixels}");
|
||||||
|
|
||||||
|
sparkVp.QueueFree();
|
||||||
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckFinitePositiveLut(string label, Image img, int expectedW, int expectedH)
|
private void CheckFinitePositiveLut(string label, Image img, int expectedW, int expectedH)
|
||||||
{
|
{
|
||||||
Check(img.GetFormat() == Image.Format.Rgbah, $"Expected {label} format Rgbah, got {img.GetFormat()}");
|
Check(img.GetFormat() == Image.Format.Rgbah, $"Expected {label} format Rgbah, got {img.GetFormat()}");
|
||||||
|
|
|
||||||
|
|
@ -260,9 +260,10 @@ void main() {
|
||||||
vec3 ro = u_frame.camPosTime.xyz;
|
vec3 ro = u_frame.camPosTime.xyz;
|
||||||
float tSceneMax = dMax * invCosView;
|
float tSceneMax = dMax * invCosView;
|
||||||
|
|
||||||
// Exact per-pixel capsule bounds & hit bitmask
|
// Exact per-pixel capsule intersections sorted ascending by t0 for monotonic sweep-line
|
||||||
uint pBounds[MAX_TILE_EMITTERS];
|
uint hitPack[MAX_TILE_EMITTERS];
|
||||||
uint pendingMask = 0u;
|
float hitT1[MAX_TILE_EMITTERS];
|
||||||
|
uint hitCount = 0u;
|
||||||
float tEndMax = 0.0;
|
float tEndMax = 0.0;
|
||||||
|
|
||||||
for (uint k = 0u; k < sTileCount; k++) {
|
for (uint k = 0u; k < sTileCount; k++) {
|
||||||
|
|
@ -272,16 +273,23 @@ void main() {
|
||||||
if (intersectCapsule(ro, rd, em.posRadius.xyz, em.endRadiusTemp.xyz, rBound, t0, t1)) {
|
if (intersectCapsule(ro, rd, em.posRadius.xyz, em.endRadiusTemp.xyz, rBound, t0, t1)) {
|
||||||
t0 = max(0.0, t0);
|
t0 = max(0.0, t0);
|
||||||
t1 = min(tSceneMax, t1);
|
t1 = min(tSceneMax, t1);
|
||||||
if (t1 > t0) {
|
if (t1 > t0 + 1e-3) {
|
||||||
pendingMask |= (1u << k);
|
uint key = (floatBitsToUint(t0) & 0xFFFFFFE0u) | (k & 0x1Fu);
|
||||||
// Conservative 0.5m pad before fp16 pack so distant emitters never clip
|
uint ins = hitCount;
|
||||||
pBounds[k] = packHalf2x16(vec2(max(0.0, t0 - 0.5), t1 + 0.5));
|
while (ins > 0u && hitPack[ins - 1u] > key) {
|
||||||
|
hitPack[ins] = hitPack[ins - 1u];
|
||||||
|
hitT1[ins] = hitT1[ins - 1u];
|
||||||
|
ins--;
|
||||||
|
}
|
||||||
|
hitPack[ins] = key;
|
||||||
|
hitT1[ins] = t1;
|
||||||
|
hitCount++;
|
||||||
tEndMax = max(tEndMax, t1);
|
tEndMax = max(tEndMax, t1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingMask == 0u) {
|
if (hitCount == 0u) {
|
||||||
imageStore(u_halfVol, px, vec4(0.0, 0.0, 0.0, 1.0));
|
imageStore(u_halfVol, px, vec4(0.0, 0.0, 0.0, 1.0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -299,43 +307,40 @@ void main() {
|
||||||
|
|
||||||
vec3 L = vec3(0.0);
|
vec3 L = vec3(0.0);
|
||||||
float T = 1.0;
|
float T = 1.0;
|
||||||
|
uint nextIdx = 0u;
|
||||||
uint activeMask = 0u;
|
uint activeMask = 0u;
|
||||||
float t = 0.0;
|
float t = 0.0;
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
const int MaxSteps = 22;
|
const int MaxSteps = 16;
|
||||||
|
|
||||||
while ((pendingMask != 0u || activeMask != 0u) && t < tEndMax && T >= 0.01 && steps < MaxSteps) {
|
while ((nextIdx < hitCount || activeMask != 0u) && t < tEndMax && T >= 0.015 && steps < MaxSteps) {
|
||||||
// Empty-space jump whenever no emitter is currently active
|
// Empty-space jump directly to nextIdx's t0 whenever no emitter is currently active
|
||||||
if (activeMask == 0u) {
|
if (activeMask == 0u) {
|
||||||
float minNext = tEndMax;
|
float minNext = uintBitsToFloat(hitPack[nextIdx] & 0xFFFFFFE0u);
|
||||||
uint m = pendingMask;
|
float nextT1 = hitT1[nextIdx];
|
||||||
while (m != 0u) {
|
float chord = max(0.0, nextT1 - minNext);
|
||||||
int bit = findLSB(m);
|
|
||||||
m &= m - 1u;
|
|
||||||
float nT = unpackHalf2x16(pBounds[bit]).x;
|
|
||||||
minNext = min(minNext, nT);
|
|
||||||
}
|
|
||||||
float dsLeap = max(0.36, 0.26 + 0.011 * minNext);
|
float dsLeap = max(0.36, 0.26 + 0.011 * minNext);
|
||||||
t = max(t, minNext) + ign * dsLeap;
|
float jitter = ign * min(dsLeap, max(0.05, chord * 0.45));
|
||||||
|
t = min(max(t, minNext) + jitter, tEndMax - 1e-4);
|
||||||
if (t >= tEndMax) {
|
if (t >= tEndMax) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ds = max(0.36, 0.26 + 0.011 * t);
|
float ds = max(0.36, 0.26 + 0.011 * t);
|
||||||
|
float tLo = t - 0.5 * ds;
|
||||||
|
float tHi = t + 0.5 * ds;
|
||||||
|
|
||||||
// Admit emitters whose entry bound has arrived
|
// Monotonic sweep-line admission: advance nextIdx forward, never re-scanning earlier entries
|
||||||
uint pm = pendingMask;
|
while (nextIdx < hitCount) {
|
||||||
while (pm != 0u) {
|
float b0 = uintBitsToFloat(hitPack[nextIdx] & 0xFFFFFFE0u);
|
||||||
int bit = findLSB(pm);
|
if (b0 > tHi) {
|
||||||
pm &= pm - 1u;
|
break;
|
||||||
vec2 b = unpackHalf2x16(pBounds[bit]);
|
|
||||||
if (b.x <= t + 0.5 * ds) {
|
|
||||||
pendingMask &= ~(1u << uint(bit));
|
|
||||||
if (b.y >= t - 0.5 * ds) {
|
|
||||||
activeMask |= (1u << uint(bit));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (hitT1[nextIdx] >= tLo) {
|
||||||
|
activeMask |= (1u << nextIdx);
|
||||||
|
}
|
||||||
|
nextIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retire emitters already exited
|
// Retire emitters already exited
|
||||||
|
|
@ -343,8 +348,7 @@ void main() {
|
||||||
while (amCheck != 0u) {
|
while (amCheck != 0u) {
|
||||||
int bit = findLSB(amCheck);
|
int bit = findLSB(amCheck);
|
||||||
amCheck &= amCheck - 1u;
|
amCheck &= amCheck - 1u;
|
||||||
vec2 b = unpackHalf2x16(pBounds[bit]);
|
if (hitT1[bit] < tLo) {
|
||||||
if (t - 0.5 * ds > b.y) {
|
|
||||||
activeMask &= ~(1u << uint(bit));
|
activeMask &= ~(1u << uint(bit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -366,8 +370,9 @@ void main() {
|
||||||
|
|
||||||
uint am = activeMask;
|
uint am = activeMask;
|
||||||
while (am != 0u) {
|
while (am != 0u) {
|
||||||
int k = findLSB(am);
|
int hitSlot = findLSB(am);
|
||||||
am &= am - 1u;
|
am &= am - 1u;
|
||||||
|
uint k = hitPack[hitSlot] & 0x1Fu;
|
||||||
VolumetricEmitter em = sEmitters[k];
|
VolumetricEmitter em = sEmitters[k];
|
||||||
|
|
||||||
uint flags = floatBitsToUint(em.params.w);
|
uint flags = floatBitsToUint(em.params.w);
|
||||||
|
|
@ -428,9 +433,9 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rhoSum > 0.002) {
|
if (rhoSum > 0.002) {
|
||||||
// 2 tile-local directional sun shadow taps along sunDir (closest 8 tile emitters)
|
// 2 tile-local directional sun shadow taps along sunDir (closest 6 tile emitters)
|
||||||
float tauSun = 0.0;
|
float tauSun = 0.0;
|
||||||
uint shadowCount = min(sTileCount, 8u);
|
uint shadowCount = min(sTileCount, 6u);
|
||||||
for (int st = 0; st < 2; st++) {
|
for (int st = 0; st < 2; st++) {
|
||||||
float sDist = st == 0 ? 1.2 : 3.4;
|
float sDist = st == 0 ? 1.2 : 3.4;
|
||||||
vec3 sPos = worldPos + sunDir * sDist;
|
vec3 sPos = worldPos + sunDir * sDist;
|
||||||
|
|
@ -457,7 +462,7 @@ void main() {
|
||||||
vec3 stepLight = (scatter * sigmaT + emissionSum) * (sigmaT > 1e-4 ? (1.0 - stepTrans) / sigmaT : ds);
|
vec3 stepLight = (scatter * sigmaT + emissionSum) * (sigmaT > 1e-4 ? (1.0 - stepTrans) / sigmaT : ds);
|
||||||
L += T * stepLight;
|
L += T * stepLight;
|
||||||
T *= stepTrans;
|
T *= stepTrans;
|
||||||
if (T < 0.01) {
|
if (T < 0.015) {
|
||||||
T = 0.0;
|
T = 0.0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ layout(set = 0, binding = 3) uniform sampler2D u_depthTex;
|
||||||
shared uint sMinDepthBits;
|
shared uint sMinDepthBits;
|
||||||
shared uint sMaxDepthBits;
|
shared uint sMaxDepthBits;
|
||||||
shared uint sTileCount;
|
shared uint sTileCount;
|
||||||
shared uint sKeys[32];
|
shared uint sKeys[128];
|
||||||
|
|
||||||
float linearizeReverseZ(float rawDepth) {
|
float linearizeReverseZ(float rawDepth) {
|
||||||
if (rawDepth <= 0.0) {
|
if (rawDepth <= 0.0) {
|
||||||
|
|
@ -70,7 +70,7 @@ void main() {
|
||||||
sMaxDepthBits = 0u;
|
sMaxDepthBits = 0u;
|
||||||
sTileCount = 0u;
|
sTileCount = 0u;
|
||||||
}
|
}
|
||||||
if (tid < 32u) {
|
if (tid < 128u) {
|
||||||
sKeys[tid] = 0xFFFFFFFFu;
|
sKeys[tid] = 0xFFFFFFFFu;
|
||||||
}
|
}
|
||||||
memoryBarrierShared();
|
memoryBarrierShared();
|
||||||
|
|
@ -161,7 +161,7 @@ void main() {
|
||||||
float tMinConservative = max(0.0, length(closest) - rBound);
|
float tMinConservative = max(0.0, length(closest) - rBound);
|
||||||
uint packedKey = (floatBitsToUint(tMinConservative) & 0xFFFFFF80u) | (tid & 0x7Fu);
|
uint packedKey = (floatBitsToUint(tMinConservative) & 0xFFFFFF80u) | (tid & 0x7Fu);
|
||||||
uint slot = atomicAdd(sTileCount, 1u);
|
uint slot = atomicAdd(sTileCount, 1u);
|
||||||
if (slot < 32u) {
|
if (slot < 128u) {
|
||||||
sKeys[slot] = packedKey;
|
sKeys[slot] = packedKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,10 +169,10 @@ void main() {
|
||||||
memoryBarrierShared();
|
memoryBarrierShared();
|
||||||
barrier();
|
barrier();
|
||||||
|
|
||||||
// 1-warp 32-element Bitonic sort (barriers kept in uniform workgroup control flow)
|
// 128-element Bitonic sort across 128 threads (7 stages, barriers kept in uniform workgroup control flow)
|
||||||
for (uint k = 2u; k <= 32u; k <<= 1u) {
|
for (uint k = 2u; k <= 128u; k <<= 1u) {
|
||||||
for (uint j = k >> 1u; j > 0u; j >>= 1u) {
|
for (uint j = k >> 1u; j > 0u; j >>= 1u) {
|
||||||
if (tid < 32u) {
|
if (tid < 128u) {
|
||||||
uint ixj = tid ^ j;
|
uint ixj = tid ^ j;
|
||||||
if (ixj > tid) {
|
if (ixj > tid) {
|
||||||
bool ascending = ((tid & k) == 0u);
|
bool ascending = ((tid & k) == 0u);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue