|
|
@@ -0,0 +1,94 @@
|
|
|
+// Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
|
|
|
+// All rights reserved.
|
|
|
+// Code licensed under the BSD License.
|
|
|
+// http://www.anki3d.org/LICENSE
|
|
|
+
|
|
|
+// Used in stat collection in the RenderableDrawer.
|
|
|
+// It's simple drawcall that draws a very small quad to the screen. Only one thread of the fragment shader will read the multi-draw counts and write
|
|
|
+// the number of drawcalls in a buffer.
|
|
|
+
|
|
|
+#pragma anki mutator CLEAR_COUNTER_BUFFER 0 1
|
|
|
+#pragma anki mutator COLOR_ATTACHMENT_COUNT 0 1 4
|
|
|
+
|
|
|
+#include <AnKi/Shaders/Common.hlsl>
|
|
|
+
|
|
|
+#pragma anki start vert
|
|
|
+
|
|
|
+struct VertOut
|
|
|
+{
|
|
|
+ Vec4 m_position : SV_POSITION;
|
|
|
+};
|
|
|
+
|
|
|
+VertOut main(U32 vertId : SV_VERTEXID)
|
|
|
+{
|
|
|
+ Vec2 uv = Vec2(vertId & 1u, ((vertId + 1u) / 3u) & 1u);
|
|
|
+
|
|
|
+ // Limit the UV to just cover at least a 2x2 pixels if we assume that the viewport size is something like 64x64. 2x2 pixels will be enough for the
|
|
|
+ // fragment shader to run
|
|
|
+ uv *= 2.0f / 64.0f;
|
|
|
+
|
|
|
+ VertOut output;
|
|
|
+ output.m_position = Vec4(uv * 2.0 - 1.0, 0.0, 1.0);
|
|
|
+
|
|
|
+ return output;
|
|
|
+}
|
|
|
+#pragma anki end
|
|
|
+
|
|
|
+#pragma anki start frag
|
|
|
+
|
|
|
+[[vk::binding(0)]] RWStructuredBuffer<U32> g_visibleObjectCount;
|
|
|
+#if CLEAR_COUNTER_BUFFER == 0
|
|
|
+[[vk::binding(1)]] RWStructuredBuffer<U32> g_fragThreadCount;
|
|
|
+[[vk::binding(2)]] StructuredBuffer<U32> g_mdiDrawCounts;
|
|
|
+#endif
|
|
|
+
|
|
|
+#if COLOR_ATTACHMENT_COUNT > 0
|
|
|
+struct FragOut
|
|
|
+{
|
|
|
+ Vec4 m_color0 : SV_TARGET0;
|
|
|
+# if COLOR_ATTACHMENT_COUNT == 4
|
|
|
+ Vec4 m_color1 : SV_TARGET1;
|
|
|
+ Vec4 m_color2 : SV_TARGET2;
|
|
|
+ Vec2 m_color3 : SV_TARGET3;
|
|
|
+# endif
|
|
|
+};
|
|
|
+#endif
|
|
|
+
|
|
|
+#if COLOR_ATTACHMENT_COUNT > 0
|
|
|
+FragOut
|
|
|
+#else
|
|
|
+void
|
|
|
+#endif
|
|
|
+main()
|
|
|
+{
|
|
|
+#if CLEAR_COUNTER_BUFFER == 1
|
|
|
+ g_visibleObjectCount[0] = 0;
|
|
|
+#else
|
|
|
+ U32 threadIdx;
|
|
|
+ InterlockedAdd(g_fragThreadCount[0], 1, threadIdx);
|
|
|
+
|
|
|
+ if(threadIdx == 0)
|
|
|
+ {
|
|
|
+ U32 bucketCount, unused;
|
|
|
+ g_mdiDrawCounts.GetDimensions(bucketCount, unused);
|
|
|
+
|
|
|
+ U32 visiblesCount = 0;
|
|
|
+ for(U32 i = 0; i < bucketCount; ++i)
|
|
|
+ {
|
|
|
+ visiblesCount += g_mdiDrawCounts[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(visiblesCount > 0)
|
|
|
+ {
|
|
|
+ InterlockedAdd(g_visibleObjectCount[0], visiblesCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ discard;
|
|
|
+
|
|
|
+#if COLOR_ATTACHMENT_COUNT > 0
|
|
|
+ return (FragOut)0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+#pragma anki end
|