Browse Source

Move Ssr to the new format

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
eed928bf9e

+ 0 - 135
shaders/GlobalIlluminationClipmapPopulation.glslp

@@ -1,135 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// Populates a clipmap with the irradiance values of probes.
-
-#pragma anki input const UVec3 WORKGROUP_SIZE
-#pragma anki input const U32 PROBE_COUNT
-#pragma anki mutator HAS_PROBES 0 1
-
-#pragma anki start comp
-
-#include <shaders/glsl_cpp_common/ClusteredShading.h>
-#include <shaders/Functions.glsl>
-
-#define DEBUG_MODE 0 // 0: disabled, 1: draw different shade per dir per level, 2 draw differend shade per cell
-
-layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = WORKGROUP_SIZE.z) in;
-
-struct Clipmap
-{
-	Vec3 m_aabbMin;
-	F32 m_cellSize;
-	Vec3 m_aabbMax;
-	F32 m_padding0;
-	UVec3 m_cellCounts;
-	U32 m_padding2;
-};
-
-layout(set = 0, binding = 0, std140) uniform ubo_
-{
-	Clipmap u_clipmaps[GLOBAL_ILLUMINATION_CLIPMAP_LEVEL_COUNT];
-	Vec3 u_cameraPos;
-	U32 u_padding;
-};
-
-layout(set = 0, binding = 1) uniform writeonly image3D u_clipmapImages[6u * GLOBAL_ILLUMINATION_CLIPMAP_LEVEL_COUNT];
-
-#if HAS_PROBES
-layout(set = 0, binding = 2) buffer ssbo_
-{
-	GlobalIlluminationProbe u_probes[];
-};
-
-layout(set = 0, binding = 3) uniform sampler u_linearAnyClampSampler;
-layout(set = 0, binding = 4) uniform texture3D u_probeIrradianceTextures[6u * PROBE_COUNT];
-#endif
-
-Bool aabbsOverlap(const Clipmap clipmap, const GlobalIlluminationProbe probe)
-{
-	return aabbsOverlap(clipmap.m_aabbMin, clipmap.m_aabbMax, probe.m_aabbMin, probe.m_aabbMax);
-}
-
-// Compute the texture coordinates inside a probe
-Vec3 computeUvwCoordsInsideProbe(const GlobalIlluminationProbe probe, const Vec3 positionInsideTheProbe)
-{
-	const Vec3 probeSize = probe.m_aabbMax - probe.m_aabbMin;
-	const Vec3 uvw = (positionInsideTheProbe - probe.m_aabbMin) / probeSize;
-	return uvw;
-}
-
-void main()
-{
-	// Populate all clipmaps
-	ANKI_UNROLL for(U32 clipmapIdx = 0u; clipmapIdx < GLOBAL_ILLUMINATION_CLIPMAP_LEVEL_COUNT; ++clipmapIdx)
-	{
-		const Clipmap clipmap = u_clipmaps[clipmapIdx];
-
-		// Check bounds
-		if(any(greaterThanEqual(gl_GlobalInvocationID, clipmap.m_cellCounts)))
-		{
-			continue;
-		}
-
-#if HAS_PROBES
-		// For all probes
-		F32 weight = EPSILON;
-		Vec3 accumulatedIrradiance[6u] = Vec3[](Vec3(0.0), Vec3(0.0), Vec3(0.0), Vec3(0.0), Vec3(0.0), Vec3(0.0));
-		ANKI_UNROLL for(U32 probeIdx = 0u; probeIdx < PROBE_COUNT; ++probeIdx)
-		{
-			const GlobalIlluminationProbe probe = u_probes[probeIdx];
-
-			ANKI_FLATTEN if(aabbsOverlap(clipmap, probe))
-			{
-				// Compute the world position of the cell in the clipmap
-				Vec3 cellPosition = Vec3(gl_GlobalInvocationID) * clipmap.m_cellSize;
-				cellPosition += clipmap.m_cellSize / 2.0; // Move to the center of the cell
-				cellPosition += clipmap.m_aabbMin;
-
-				// Compute the UVW coords
-				const Vec3 texCoordsInProbe = computeUvwCoordsInsideProbe(probe, cellPosition);
-
-				// Read the texture
-				ANKI_UNROLL for(U32 dirIdx = 0u; dirIdx < 6u; ++dirIdx)
-				{
-					// Read the color from the probe
-					const U32 inputTexIdx = probeIdx * 6u + dirIdx;
-					const Vec3 inColor = textureLod(
-						u_probeIrradianceTextures[inputTexIdx], u_linearAnyClampSampler, texCoordsInProbe, 0.0)
-											 .rgb;
-
-					accumulatedIrradiance[dirIdx] += inColor;
-				}
-
-				weight += 1.0;
-			}
-		}
-#endif
-
-		// Write the result
-		ANKI_UNROLL for(U32 dirIdx = 0u; dirIdx < 6u; ++dirIdx)
-		{
-			const U32 clipmapImageIdx = clipmapIdx * 6u + dirIdx;
-
-#if DEBUG_MODE == 1
-			const Vec3 dirColor = colorPerCubeFace(dirIdx);
-			const F32 clipmapFactor = F32(GLOBAL_ILLUMINATION_CLIPMAP_LEVEL_COUNT - clipmapIdx)
-									  / F32(GLOBAL_ILLUMINATION_CLIPMAP_LEVEL_COUNT);
-			const Vec3 storedColor = dirColor * clipmapFactor;
-#elif DEBUG_MODE == 2
-			const F32 factor =
-				F32(gl_LocalInvocationIndex) / F32(WORKGROUP_SIZE.x * WORKGROUP_SIZE.y * WORKGROUP_SIZE.z);
-			const Vec3 storedColor = heatmap(factor);
-#elif HAS_PROBES
-			const Vec3 storedColor = accumulatedIrradiance[dirIdx] / weight;
-#else
-			const Vec3 storedColor = Vec3(0.0);
-#endif
-			imageStore(u_clipmapImages[clipmapImageIdx], IVec3(gl_GlobalInvocationID), Vec4(storedColor, 0.0));
-		}
-	}
-}
-
-#pragma anki end

+ 5 - 5
shaders/Ssr.glslp → shaders/Ssr.ankiprog

@@ -11,11 +11,10 @@
 
 
 #pragma anki mutator VARIANT 0 1
 #pragma anki mutator VARIANT 0 1
 
 
-#pragma anki input const UVec2 FB_SIZE
-#pragma anki input const UVec2 WORKGROUP_SIZE
-#pragma anki input const U32 MAX_STEPS
-#pragma anki input const U32 LIGHT_BUFFER_MIP_COUNT
-#pragma anki input const F32 HISTORY_COLOR_BLEND_FACTOR
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 0, UVec2(1));
+ANKI_SPECIALIZATION_CONSTANT_U32(MAX_STEPS, 2, 1);
+ANKI_SPECIALIZATION_CONSTANT_U32(LIGHT_BUFFER_MIP_COUNT, 3, 1);
+ANKI_SPECIALIZATION_CONSTANT_F32(HISTORY_COLOR_BLEND_FACTOR, 4, 0.5);
 
 
 #pragma anki start comp
 #pragma anki start comp
 #include <shaders/Functions.glsl>
 #include <shaders/Functions.glsl>
@@ -23,6 +22,7 @@
 #include <shaders/glsl_cpp_common/Ssr.h>
 #include <shaders/glsl_cpp_common/Ssr.h>
 #include <shaders/Tonemapping.glsl>
 #include <shaders/Tonemapping.glsl>
 
 
+const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
 layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
 layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = 1) in;
 
 
 layout(set = 0, binding = 0) uniform sampler u_trilinearClampSampler;
 layout(set = 0, binding = 0) uniform sampler u_trilinearClampSampler;

+ 15 - 17
src/anki/renderer/Ssr.cpp

@@ -45,24 +45,23 @@ Error Ssr::initInternal(const ConfigSet& cfg)
 	m_rt = m_r->createAndClearRenderTarget(texinit);
 	m_rt = m_r->createAndClearRenderTarget(texinit);
 
 
 	// Create shader
 	// Create shader
-	ANKI_CHECK(getResourceManager().loadResource("shaders/Ssr.glslp", m_prog));
+	ANKI_CHECK(getResourceManager().loadResource("shaders/Ssr.ankiprog", m_prog));
 
 
-	ShaderProgramResourceConstantValueInitList<5> consts(m_prog);
-	consts.add("FB_SIZE", UVec2(width, height));
-	consts.add("WORKGROUP_SIZE", UVec2(m_workgroupSize[0], m_workgroupSize[1]));
-	consts.add("MAX_STEPS", cfg.getNumberU32("r_ssrMaxSteps"));
-	consts.add("LIGHT_BUFFER_MIP_COUNT", U32(m_r->getDownscaleBlur().getMipmapCount()));
-	consts.add("HISTORY_COLOR_BLEND_FACTOR", cfg.getNumberF32("r_ssrHistoryBlendFactor"));
+	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_prog);
+	variantInitInfo.addConstant("FB_SIZE", UVec2(width, height));
+	variantInitInfo.addConstant("MAX_STEPS", cfg.getNumberU32("r_ssrMaxSteps"));
+	variantInitInfo.addConstant("LIGHT_BUFFER_MIP_COUNT", m_r->getDownscaleBlur().getMipmapCount());
+	variantInitInfo.addConstant("HISTORY_COLOR_BLEND_FACTOR", cfg.getNumberF32("r_ssrHistoryBlendFactor"));
+	variantInitInfo.addMutation("VARIANT", 0);
 
 
-	ShaderProgramResourceMutationInitList<1> mutators(m_prog);
-	mutators.add("VARIANT", 0);
-
-	const ShaderProgramResourceVariant* variant;
-	m_prog->getOrCreateVariant(mutators.get(), consts.get(), variant);
+	const ShaderProgramResourceVariant2* variant;
+	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_grProg[0] = variant->getProgram();
 	m_grProg[0] = variant->getProgram();
+	m_workgroupSize[0] = variant->getWorkgroupSizes()[0];
+	m_workgroupSize[1] = variant->getWorkgroupSizes()[1];
 
 
-	mutators[0].m_value = 1;
-	m_prog->getOrCreateVariant(mutators.get(), consts.get(), variant);
+	variantInitInfo.addMutation("VARIANT", 1);
+	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_grProg[1] = variant->getProgram();
 	m_grProg[1] = variant->getProgram();
 
 
 	return Error::NONE;
 	return Error::NONE;
@@ -120,9 +119,8 @@ void Ssr::run(RenderPassWorkContext& rgraphCtx)
 	unis->m_normalMat = Mat3x4(ctx.m_matrices.m_view.getRotationPart());
 	unis->m_normalMat = Mat3x4(ctx.m_matrices.m_view.getRotationPart());
 
 
 	// Dispatch
 	// Dispatch
-	const U32 sizeX = (m_r->getWidth() / SSR_FRACTION + m_workgroupSize[0] - 1) / m_workgroupSize[0];
-	const U32 sizeY = (m_r->getHeight() / SSR_FRACTION + m_workgroupSize[1] - 1) / m_workgroupSize[1];
-	cmdb->dispatchCompute(sizeX / 2, sizeY, 1);
+	dispatchPPCompute(
+		cmdb, m_workgroupSize[0], m_workgroupSize[1], m_r->getWidth() / SSR_FRACTION, m_r->getHeight() / SSR_FRACTION);
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 2 - 2
src/anki/renderer/Ssr.h

@@ -35,12 +35,12 @@ public:
 	}
 	}
 
 
 private:
 private:
-	ShaderProgramResourcePtr m_prog;
+	ShaderProgramResource2Ptr m_prog;
 	Array<ShaderProgramPtr, 2> m_grProg;
 	Array<ShaderProgramPtr, 2> m_grProg;
 
 
 	TexturePtr m_rt;
 	TexturePtr m_rt;
 
 
-	Array<U8, 2> m_workgroupSize = {{16, 16}};
+	Array<U32, 2> m_workgroupSize = {};
 
 
 	class
 	class
 	{
 	{