Add Quad Overdraw debug view mode

This commit is contained in:
Wojtek Figat
2021-10-07 14:59:06 +02:00
parent 949766e3a0
commit 1af5ec8492
22 changed files with 473 additions and 5 deletions

View File

@@ -0,0 +1,48 @@
// [Quad Overdraw implementation based on https://blog.selfshadow.com/2012/11/12/counting-quads/ by Stephen Hill]
#ifndef __QUAD_OVERDRAW__
#define __QUAD_OVERDRAW__
RWTexture2D<uint> lockUAV : register(u0);
RWTexture2D<uint> overdrawUAV : register(u1);
RWTexture2D<uint> liveCountUAV : register(u2);
void DoQuadOverdraw(float4 svPos, uint primId)
{
uint2 quad = svPos.xy * 0.5;
uint prevID;
uint unlockedID = 0xffffffff;
bool processed = false;
int lockCount = 0;
int pixelCount = 0;
for (int i = 0; i < 64; i++)
{
if (!processed)
InterlockedCompareExchange(lockUAV[quad], unlockedID, primId, prevID);
[branch]
if (prevID == unlockedID)
{
if (++lockCount == 4)
{
// Retrieve live pixel count (minus 1) in quad
InterlockedAnd(liveCountUAV[quad], 0, pixelCount);
// Unlock for other quads
InterlockedExchange(lockUAV[quad], unlockedID, prevID);
}
processed = true;
}
if (prevID == primId && !processed)
{
InterlockedAdd(liveCountUAV[quad], 1);
processed = true;
}
}
if (lockCount)
{
InterlockedAdd(overdrawUAV[quad], 1);
}
}
#endif

View File

@@ -0,0 +1,34 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#include "./Flax/Common.hlsl"
// [Quad Overdraw implementation based on https://blog.selfshadow.com/2012/11/12/counting-quads/ by Stephen Hill]
Texture2D<uint> overdrawSRV : register(t0);
float4 ToColour(uint v)
{
const uint nbColours = 10;
const float4 colours[nbColours] =
{
float4(0, 0, 0, 255),
float4(2, 147, 25, 255),
float4(0, 255, 149, 255),
float4(0, 255, 253, 255),
float4(142, 250, 0, 255),
float4(225, 251, 0, 255),
float4(225, 147, 0, 255),
float4(225, 38, 0, 255),
float4(148, 17, 0, 255),
float4(255, 255, 255, 255)
};
return colours[min(v, nbColours - 1)] / 255.0;
}
META_PS(true, FEATURE_LEVEL_ES2)
float4 PS(float4 svPos : SV_POSITION) : SV_Target
{
uint2 quad = svPos.xy * 0.5;
uint overdraw = overdrawSRV[quad];
return ToColour(overdraw);
}