浏览代码

Renderer: Remove the restriction of tiles to be 64x64

Panagiotis Christopoulos Charitos 9 年之前
父节点
当前提交
baf0b18a3b

+ 0 - 1
sandbox/config.xml

@@ -36,7 +36,6 @@
 	<height>1080</height>
 	<renderingQuality>1</renderingQuality>
 	<lodDistance>20</lodDistance>
-	<samples>1</samples>
 	<tessellation>1</tessellation>
 	<clusterSizeZ>32</clusterSizeZ>
 	<imageReflectionMaxDistance>30</imageReflectionMaxDistance>

+ 15 - 28
shaders/Clusterer.glsl

@@ -10,33 +10,28 @@
 
 #include "shaders/Common.glsl"
 
-// Compute the cluster index using the tile index.
-uint computeClusterIndexUsingTileIdx(
-	float near, float clustererMagic, float zVSpace, uint tileIdx, uint tileCountX, uint tileCountY)
+uint computeClusterK(float near, float clustererMagic, float zVSpace)
 {
-	float fk = sqrt((zVSpace + near) * clustererMagic);
-	uint k = uint(fk);
-
-	return tileIdx + k * (tileCountX * tileCountY);
+	float fz = sqrt((zVSpace + near) * clustererMagic);
+	uint z = uint(fz);
+	return z;
 }
 
-// Compute the cluster index using the a custom gl_FragCoord.xy.
-uint computeClusterIndexUsingCustomFragCoord(
-	float near, float clustererMagic, float zVSpace, uint tileCountX, uint tileCountY, vec2 fragCoord)
+uint computeClusterKSafe(float near, float far, float clustererMagic, float zVSpace)
 {
-	// Compute tile idx
-	uvec2 f = uvec2(fragCoord) >> 6;
-	uint tileIdx = f.y * tileCountX + f.x;
-
-	return computeClusterIndexUsingTileIdx(near, clustererMagic, zVSpace, tileIdx, tileCountX, tileCountY);
+	float z = clamp(zVSpace, -far, -near);
+	float kf = sqrt((z + near) * clustererMagic);
+	return uint(kf);
 }
 
-// Compute the cluster index using the gl_FragCoord.xy.
-uint computeClusterIndexUsingFragCoord(
-	float near, float clustererMagic, float zVSpace, uint tileCountX, uint tileCountY)
+// Compute cluster index
+uint computeClusterIndex(
+	vec2 uv, float near, float clustererMagic, float zVSpace, uint clusterCountX, uint clusterCountY)
 {
-	return computeClusterIndexUsingCustomFragCoord(
-		near, clustererMagic, zVSpace, tileCountX, tileCountY, gl_FragCoord.xy);
+	uvec2 xy = uvec2(uv * vec2(clusterCountX, clusterCountY));
+
+	return computeClusterK(near, clustererMagic, zVSpace) * (clusterCountX * clusterCountY) + xy.y * clusterCountX
+		+ xy.x;
 }
 
 // Compute the Z of the near plane given a cluster idx
@@ -50,12 +45,4 @@ float computeClusterFar(uint k, float near, float clustererMagic)
 	return 1.0 / clustererMagic * pow(float(k + 1u), 2.0) - near;
 }
 
-uint computeClusterKFromZViewSpace(float zViewSpace, float near, float far, float clustererMagic)
-{
-	float z = clamp(zViewSpace, -far, -near);
-	z = -z;
-	float kf = sqrt((z - near) * -clustererMagic);
-	return uint(kf);
-}
-
 #endif

+ 3 - 3
shaders/FsCommonFrag.glsl

@@ -130,12 +130,12 @@ vec3 computeLightColor(vec3 diffCol)
 	}
 
 	// Find the cluster and then the light counts
-	uint clusterIdx = computeClusterIndexUsingCustomFragCoord(u_lightingUniforms.nearFarClustererMagicPad1.x,
+	uint clusterIdx = computeClusterIndex(gl_FragCoord.xy / RENDERER_SIZE,
+		u_lightingUniforms.nearFarClustererMagicPad1.x,
 		u_lightingUniforms.nearFarClustererMagicPad1.z,
 		fragPos.z,
 		u_lightingUniforms.tileCount.x,
-		u_lightingUniforms.tileCount.y,
-		gl_FragCoord.xy * 2.0);
+		u_lightingUniforms.tileCount.y);
 
 	uint idxOffset = u_clusters[clusterIdx];
 

+ 8 - 9
shaders/Is.frag.glsl

@@ -23,7 +23,7 @@ layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_msDepthRt;
 layout(ANKI_TEX_BINDING(1, 0)) uniform sampler2D u_diffDecalTex;
 layout(ANKI_TEX_BINDING(1, 1)) uniform sampler2D u_normalRoughnessDecalTex;
 
-layout(location = 0) in vec2 in_texCoord;
+layout(location = 0) in vec2 in_uv;
 layout(location = 1) flat in int in_instanceId;
 layout(location = 2) in vec2 in_projectionParams;
 
@@ -36,7 +36,7 @@ const float SUBSURFACE_MIN = 0.05;
 // Return frag pos in view space
 vec3 getFragPosVSpace()
 {
-	float depth = texture(u_msDepthRt, in_texCoord, 0.0).r;
+	float depth = texture(u_msDepthRt, in_uv, 0.0).r;
 
 	vec3 fragPos;
 	fragPos.z = u_lightingUniforms.projectionParams.z / (u_lightingUniforms.projectionParams.w + depth);
@@ -142,7 +142,7 @@ void main()
 	float metallic;
 
 	GbufferInfo gbuffer;
-	readGBuffer(u_msRt0, u_msRt1, u_msRt2, in_texCoord, 0.0, gbuffer);
+	readGBuffer(u_msRt0, u_msRt1, u_msRt2, in_uv, 0.0, gbuffer);
 	diffCol = gbuffer.diffuse;
 	specCol = gbuffer.specular;
 	normal = gbuffer.normal;
@@ -152,12 +152,11 @@ void main()
 	emission = gbuffer.emission;
 
 	// Get counts and offsets
-	uint clusterIdx = computeClusterIndexUsingTileIdx(u_lightingUniforms.nearFarClustererMagicPad1.x,
-		u_lightingUniforms.nearFarClustererMagicPad1.z,
-		fragPos.z,
-		in_instanceId,
-		TILE_COUNT_X,
-		TILE_COUNT_Y);
+	uint clusterIdx =
+		computeClusterK(
+			u_lightingUniforms.nearFarClustererMagicPad1.x, u_lightingUniforms.nearFarClustererMagicPad1.z, fragPos.z)
+			* TILE_COUNT
+		+ in_instanceId;
 
 	uint idxOffset = u_clusters[clusterIdx];
 	uint idx;

+ 5 - 5
shaders/Volumetric.frag.glsl

@@ -109,16 +109,16 @@ void main()
 	float farZ = u_lightingUniforms.projectionParams.z / (u_lightingUniforms.projectionParams.w + depth);
 
 	// Compute the max cluster
-	uint maxK = computeClusterKFromZViewSpace(farZ,
-		u_lightingUniforms.nearFarClustererMagicPad1.x,
+	uint maxK = computeClusterKSafe(u_lightingUniforms.nearFarClustererMagicPad1.x,
 		u_lightingUniforms.nearFarClustererMagicPad1.y,
-		u_lightingUniforms.nearFarClustererMagicPad1.z);
+		u_lightingUniforms.nearFarClustererMagicPad1.z,
+		farZ);
 	++maxK;
 
 	vec2 ndc = in_uv * 2.0 - 1.0;
 
-	uint i = uint(gl_FragCoord.x * 4.0) >> 6;
-	uint j = uint(gl_FragCoord.y * 4.0) >> 6;
+	uint i = uint(in_uv.x * CLUSTER_COUNT.x);
+	uint j = uint(in_uv.y * CLUSTER_COUNT.y);
 
 	const float DIST = 1.0 / float(MAX_SAMPLES_PER_CLUSTER);
 	float randFactor = rand(ndc + u_lightingUniforms.rendererSizeTimePad1.z);

+ 1 - 3
src/anki/Config.h.cmake

@@ -93,9 +93,7 @@
 // OpenGL version
 #define ANKI_GL_DESKTOP 1
 #define ANKI_GL_ES 2
-#if ANKI_OS == ANKI_OS_LINUX \
-	|| ANKI_OS == ANKI_OS_MACOS \
-	|| ANKI_OS == ANKI_OS_WINDOWS
+#if ANKI_OS == ANKI_OS_LINUX || ANKI_OS == ANKI_OS_MACOS || ANKI_OS == ANKI_OS_WINDOWS
 #	define ANKI_GL ANKI_GL_DESKTOP
 #	define ANKI_GL_STR "ANKI_GL_DESKTOP"
 #else

+ 2 - 1
src/anki/core/Config.cpp

@@ -60,8 +60,9 @@ Config::Config()
 	newOption("height", 768);
 	newOption("renderingQuality", 1.0); // Applies only to MainRenderer
 	newOption("lodDistance", 10.0); // Distance that used to calculate the LOD
-	newOption("samples", 1);
 	newOption("tessellation", true);
+	newOption("clusterSizeX", 32);
+	newOption("clusterSizeY", 26);
 	newOption("clusterSizeZ", 32);
 	newOption("imageReflectionMaxDistance", 30.0);
 

+ 16 - 13
src/anki/renderer/Is.cpp

@@ -77,14 +77,17 @@ Error Is::initInternal(const ConfigSet& config)
 	m_rtMipCount = computeMaxMipmapCount2d(m_r->getWidth(), m_r->getHeight(), 32);
 	ANKI_ASSERT(m_rtMipCount);
 
-	U clusterCount = m_r->getTileCountXY().x() * m_r->getTileCountXY().y() * config.getNumber("clusterSizeZ");
-	m_clusterCount = clusterCount;
-	m_maxLightIds *= clusterCount;
+	m_clusterCounts[0] = config.getNumber("clusterSizeX");
+	m_clusterCounts[1] = config.getNumber("clusterSizeY");
+	m_clusterCounts[2] = config.getNumber("clusterSizeZ");
+	m_clusterCount = m_clusterCounts[0] * m_clusterCounts[1] * m_clusterCounts[2];
+
+	m_maxLightIds *= m_clusterCount;
 
 	m_lightBin = getAllocator().newInstance<LightBin>(getAllocator(),
-		m_r->getTileCountXY().x(),
-		m_r->getTileCountXY().y(),
-		config.getNumber("clusterSizeZ"),
+		m_clusterCounts[0],
+		m_clusterCounts[1],
+		m_clusterCounts[2],
 		&m_r->getThreadPool(),
 		&getGrManager());
 
@@ -102,9 +105,9 @@ Error Is::initInternal(const ConfigSet& config)
 				"#define POISSON %u\n"
 				"#define INDIRECT_ENABLED %u\n"
 				"#define IR_MIPMAP_COUNT %u\n",
-		m_r->getTileCountXY().x(),
-		m_r->getTileCountXY().y(),
-		clusterCount,
+		m_clusterCounts[0],
+		m_clusterCounts[1],
+		m_clusterCount,
 		m_r->getWidth(),
 		m_r->getHeight(),
 		m_maxLightIds,
@@ -194,7 +197,7 @@ void Is::run(RenderingContext& ctx)
 	cmdb->bindStorageBuffer(0, 0, ctx.m_is.m_clustersToken);
 	cmdb->bindStorageBuffer(0, 1, ctx.m_is.m_lightIndicesToken);
 
-	cmdb->drawArrays(PrimitiveTopology::TRIANGLE_STRIP, 4, m_r->getTileCount());
+	cmdb->drawArrays(PrimitiveTopology::TRIANGLE_STRIP, 4, m_clusterCount);
 	cmdb->endRenderPass();
 }
 
@@ -214,7 +217,7 @@ void Is::updateCommonBlock(RenderingContext& ctx)
 
 	blk->m_rendererSizeTimePad1 = Vec4(m_r->getWidth(), m_r->getHeight(), HighRezTimer::getCurrentTime(), 0.0);
 
-	blk->m_tileCount = UVec4(m_r->getTileCountXY(), m_lightBin->getClusterer().getClusterCountZ(), m_r->getTileCount());
+	blk->m_tileCount = UVec4(m_clusterCounts[0], m_clusterCounts[1], m_clusterCounts[2], m_clusterCount);
 }
 
 void Is::setPreRunBarriers(RenderingContext& ctx)
@@ -252,8 +255,8 @@ Error Is::getOrCreateProgram(ShaderVariantBit variantMask, RenderingContext& ctx
 			"#define DECALS_ENABLED %u\n"
 			"#define POINT_LIGHTS_SHADOWS_ENABLED %u\n"
 			"#define SPOT_LIGHTS_SHADOWS_ENABLED %u\n",
-			m_r->getTileCountXY().x(),
-			m_r->getTileCountXY().y(),
+			m_clusterCounts[0],
+			m_clusterCounts[1],
 			m_clusterCount,
 			m_r->getWidth(),
 			m_r->getHeight(),

+ 2 - 0
src/anki/renderer/Is.h

@@ -56,6 +56,8 @@ private:
 	/// The IS render target
 	TexturePtr m_rt;
 	U8 m_rtMipCount = 0;
+
+	Array<U32, 3> m_clusterCounts = {{0, 0, 0}};
 	U32 m_clusterCount = 0;
 
 	/// The IS FBO

+ 2 - 6
src/anki/renderer/MainRenderer.cpp

@@ -57,8 +57,6 @@ Error MainRenderer::create(ThreadPool* threadpool,
 	ConfigSet config2 = config;
 	m_renderingQuality = config.getNumber("renderingQuality");
 	UVec2 size(m_renderingQuality * F32(m_width), m_renderingQuality * F32(m_height));
-	size.x() = getAlignedRoundDown(TILE_SIZE, size.x() / 2) * 2;
-	size.y() = getAlignedRoundDown(TILE_SIZE, size.y() / 2) * 2;
 
 	config2.set("width", size.x());
 	config2.set("height", size.y());
@@ -71,11 +69,9 @@ Error MainRenderer::create(ThreadPool* threadpool,
 	// Set the default preprocessor string
 	m_materialShaderSource.sprintf(m_alloc,
 		"#define ANKI_RENDERER_WIDTH %u\n"
-		"#define ANKI_RENDERER_HEIGHT %u\n"
-		"#define TILE_SIZE %u\n",
+		"#define ANKI_RENDERER_HEIGHT %u\n",
 		m_r->getWidth(),
-		m_r->getHeight(),
-		TILE_SIZE);
+		m_r->getHeight());
 
 	// Init other
 	if(!m_rDrawToDefaultFb)

+ 2 - 2
src/anki/renderer/Ms.cpp

@@ -19,7 +19,7 @@ Ms::~Ms()
 {
 }
 
-Error Ms::createRt(U32 samples)
+Error Ms::createRt()
 {
 	m_r->createRenderTarget(m_r->getWidth(),
 		m_r->getHeight(),
@@ -96,7 +96,7 @@ Error Ms::init(const ConfigSet& initializer)
 
 Error Ms::initInternal(const ConfigSet& initializer)
 {
-	ANKI_CHECK(createRt(initializer.getNumber("samples")));
+	ANKI_CHECK(createRt());
 	return ErrorCode::NONE;
 }
 

+ 1 - 1
src/anki/renderer/Ms.h

@@ -46,7 +46,7 @@ private:
 	ANKI_USE_RESULT Error initInternal(const ConfigSet& initializer);
 
 	/// Create a G buffer FBO
-	ANKI_USE_RESULT Error createRt(U32 samples);
+	ANKI_USE_RESULT Error createRt();
 };
 /// @}
 

+ 0 - 23
src/anki/renderer/Renderer.cpp

@@ -92,43 +92,20 @@ Error Renderer::initInternal(const ConfigSet& config)
 	// Set from the config
 	m_width = config.getNumber("width");
 	m_height = config.getNumber("height");
-	ANKI_ASSERT(isAligned(TILE_SIZE, m_width) && isAligned(TILE_SIZE, m_height));
 	ANKI_LOGI("Initializing offscreen renderer. Size %ux%u", m_width, m_height);
 
 	m_lodDistance = config.getNumber("lodDistance");
 	m_frameCount = 0;
-	m_samples = config.getNumber("samples");
-	m_tileCountXY.x() = m_width / TILE_SIZE;
-	m_tileCountXY.y() = m_height / TILE_SIZE;
-	m_tileCount = m_tileCountXY.x() * m_tileCountXY.y();
 
 	m_tessellation = config.getNumber("tessellation");
 
 	// A few sanity checks
-	if(m_samples != 1 && m_samples != 4 && m_samples != 8 && m_samples != 16 && m_samples != 32)
-	{
-		ANKI_LOGE("Incorrect samples");
-		return ErrorCode::USER_DATA;
-	}
-
 	if(m_width < 10 || m_height < 10)
 	{
 		ANKI_LOGE("Incorrect sizes");
 		return ErrorCode::USER_DATA;
 	}
 
-	if(m_width % m_tileCountXY.x() != 0)
-	{
-		ANKI_LOGE("Width is not multiple of tile width");
-		return ErrorCode::USER_DATA;
-	}
-
-	if(m_height % m_tileCountXY.y() != 0)
-	{
-		ANKI_LOGE("Height is not multiple of tile height");
-		return ErrorCode::USER_DATA;
-	}
-
 	// quad setup
 	ANKI_CHECK(m_resources->loadResource("shaders/Quad.vert.glsl", m_drawQuadVert));
 

+ 0 - 18
src/anki/renderer/Renderer.h

@@ -252,26 +252,11 @@ anki_internal:
 		return m_sceneDrawer;
 	}
 
-	U getSamples() const
-	{
-		return m_samples;
-	}
-
 	Bool getTessellationEnabled() const
 	{
 		return m_tessellation;
 	}
 
-	U getTileCount() const
-	{
-		return m_tileCount;
-	}
-
-	const UVec2& getTileCountXY() const
-	{
-		return m_tileCountXY;
-	}
-
 	const ShaderPtr& getDrawQuadVertexShader() const
 	{
 		return m_drawQuadVert->getGrShader();
@@ -398,10 +383,7 @@ private:
 	U32 m_height;
 
 	F32 m_lodDistance; ///< Distance that used to calculate the LOD
-	U8 m_samples; ///< Number of sample in multisampling
 	Bool8 m_tessellation;
-	U32 m_tileCount;
-	UVec2 m_tileCountXY;
 
 	ShaderResourcePtr m_drawQuadVert;