فهرست منبع

Re-enabling the multisample resolve

Panagiotis Christopoulos Charitos 12 سال پیش
والد
کامیت
d87b238bd2
9فایلهای تغییر یافته به همراه76 افزوده شده و 45 حذف شده
  1. 1 7
      include/anki/gl/Fbo.h
  2. 2 1
      include/anki/util/Functions.h
  3. 48 0
      src/gl/Fbo.cpp
  4. 7 1
      src/gl/Texture.cpp
  5. 3 0
      src/renderer/Hdr.cpp
  6. 9 34
      src/renderer/Ms.cpp
  7. 2 0
      src/renderer/Renderer.cpp
  8. 2 0
      src/renderer/Ssao.cpp
  9. 2 2
      testapp/Main.cpp

+ 1 - 7
include/anki/gl/Fbo.h

@@ -111,13 +111,7 @@ public:
 	/// Blit another framebuffer to this one
 	void blitFrom(const Fbo& source, const UVec2& srcMin, const UVec2& srcMax, 
 		const UVec2& dstMin, const UVec2& dstMax, 
-		GLbitfield mask, GLenum filter)
-	{
-		source.bind(false, READ_TARGET);
-		bind(false, DRAW_TARGET);
-		glBlitFramebuffer(srcMin.x(), srcMin.y(), srcMax.x(), srcMax.y(), 
-			dstMin.x(), dstMin.y(), dstMax.x(), dstMax.y(), mask, filter);
-	}	
+		GLbitfield mask, GLenum filter);
 
 private:
 	static thread_local const Fbo* currentRead;

+ 2 - 1
include/anki/util/Functions.h

@@ -73,7 +73,8 @@ inline std::string trimString(const std::string& str, const char* what = " ")
 }
 
 /// Check if a number os a power of 2
-inline Bool isPowerOfTwo(U64 x)
+template<typename Int>
+inline Bool isPowerOfTwo(Int x)
 {
 	while(((x % 2) == 0) && x > 1)
 	{

+ 48 - 0
src/gl/Fbo.cpp

@@ -172,4 +172,52 @@ void Fbo::attachTextureInternal(GLenum attachment, const Texture& tex,
 	}
 }
 
+//==============================================================================
+void Fbo::blitFrom(const Fbo& source, const UVec2& srcMin, const UVec2& srcMax, 
+	const UVec2& dstMin, const UVec2& dstMax, 
+	GLbitfield mask, GLenum filter)
+{
+	ANKI_ASSERT(colorAttachmentsCount == source.colorAttachmentsCount 
+		&& "For now only the same FBOs are supported");
+
+	GLenum drawBuffer;
+
+	this->bind(false, DRAW_TARGET);
+	source.bind(false, READ_TARGET);
+
+	U count = colorAttachmentsCount;
+
+	// First blit the color targets of attachments 1 and more
+	if(mask & GL_COLOR_BUFFER_BIT)
+	{
+		Array<GLenum, MAX_COLOR_ATTACHMENTS> drawBuffers;
+
+		while(count-- > 1)
+		{
+			drawBuffer = GL_COLOR_ATTACHMENT0 + count;
+			
+			// Set the array of drawbuffers
+			ANKI_ASSERT(0 == GL_NONE); // Just make sure
+			memset(&drawBuffers[0], GL_NONE, sizeof(drawBuffers));
+			drawBuffers[count] = drawBuffer;
+
+			glReadBuffer(drawBuffer);
+			glDrawBuffers(count + 1, &drawBuffers[0]);
+
+			glBlitFramebuffer(srcMin.x(), srcMin.y(), srcMax.x(), srcMax.y(), 
+				dstMin.x(), dstMin.y(), dstMax.x(), dstMax.y(), 
+				GL_COLOR_BUFFER_BIT, filter);
+		}
+	}
+
+	// Blit the color attachment 0 and depth and stencil
+	drawBuffer = GL_COLOR_ATTACHMENT0;
+	glReadBuffer(drawBuffer);
+	glDrawBuffers(1, &drawBuffer);
+
+	glBlitFramebuffer(srcMin.x(), srcMin.y(), srcMax.x(), srcMax.y(), 
+		dstMin.x(), dstMin.y(), dstMax.x(), dstMax.y(), 
+		mask, filter);
+}
+
 } // end namespace anki

+ 7 - 1
src/gl/Texture.cpp

@@ -1,6 +1,7 @@
 #include "anki/gl/Texture.h"
 #include "anki/gl/GlException.h"
 #include "anki/util/Exception.h"
+#include "anki/util/Functions.h"
 #include "anki/core/Logger.h"
 
 namespace anki {
@@ -421,7 +422,12 @@ void Texture::create(const Initializer& init)
 //==============================================================================
 void Texture::create2dFai(U w, U h, 
 	GLenum internalFormat_, GLenum format_, GLenum type_, U samples_)
-{		
+{
+	// Not very important but keep the resulution of render targets aligned to
+	// 16
+	ANKI_ASSERT(isAligned(16, w));
+	ANKI_ASSERT(isAligned(16, h));
+
 	Initializer init;
 
 	init.width = w;

+ 3 - 0
src/renderer/Hdr.cpp

@@ -33,7 +33,10 @@ void Hdr::initInternal(const RendererInitializer& initializer)
 	const F32 renderingQuality = initializer.get("pps.hdr.renderingQuality");
 
 	width = renderingQuality * (F32)r->getWidth();
+	alignRoundUp(16, width);
 	height = renderingQuality * (F32)r->getHeight();
+	alignRoundUp(16, height);
+
 	exposure = initializer.get("pps.hdr.exposure");
 	blurringDist = initializer.get("pps.hdr.blurringDist");
 	blurringIterationsCount = 

+ 9 - 34
src/renderer/Ms.cpp

@@ -22,25 +22,17 @@ const Texture& Ms::getFai1() const
 //==============================================================================
 void Ms::createFbo(U index, U samples)
 {
+	depthFai[index].create2dFai(r->getWidth(), r->getHeight(),
+		GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT,
+		GL_UNSIGNED_INT, samples);
+
 	if(r->getUseMrt())
 	{
 		fai0[index].create2dFai(r->getWidth(), r->getHeight(), GL_RGBA8,
 			GL_RGBA, GL_UNSIGNED_BYTE, samples);
 		fai1[index].create2dFai(r->getWidth(), r->getHeight(), GL_RGBA8,
 			GL_RGBA, GL_UNSIGNED_BYTE, samples);
-	}
-	else
-	{
-		fai0[index].create2dFai(r->getWidth(), r->getHeight(), GL_RG32UI,
-			GL_RG_INTEGER, GL_UNSIGNED_INT, samples);
-	}
-
-	depthFai[index].create2dFai(r->getWidth(), r->getHeight(),
-		GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT,
-		GL_UNSIGNED_INT, samples);
 
-	if(r->getUseMrt())
-	{
 		fbo[index].create({
 			{&fai0[index], GL_COLOR_ATTACHMENT0}, 
 			{&fai1[index], GL_COLOR_ATTACHMENT1},
@@ -48,6 +40,9 @@ void Ms::createFbo(U index, U samples)
 	}
 	else
 	{
+		fai0[index].create2dFai(r->getWidth(), r->getHeight(), GL_RG32UI,
+			GL_RG_INTEGER, GL_UNSIGNED_INT, samples);
+
 		fbo[index].create({
 			{&fai0[index], GL_COLOR_ATTACHMENT0}, 
 			{&depthFai[index], GL_DEPTH_ATTACHMENT}});
@@ -127,30 +122,10 @@ void Ms::run()
 	// If there is multisampling then resolve to singlesampled
 	if(r->getSamples() > 1)
 	{
-#if 0
-		fbo[0].bind(false, Fbo::FT_READ);
-		glReadBuffer(GL_COLOR_ATTACHMENT1);
-		fbo[1].bind(Fbo::FT_DRAW);
-		static const GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT1};
-		glDrawBuffers(1, drawBuffers);
-
-		glBlitFramebuffer(
-			0, 0, r->getWidth(), r->getHeight(), 
-			0, 0, r->getWidth(), r->getHeight(),
-			GL_COLOR_BUFFER_BIT,
-			GL_NEAREST);
-
-		glReadBuffer(GL_COLOR_ATTACHMENT0);
-		static const GLenum drawBuffers2[] = {GL_COLOR_ATTACHMENT0};
-		glDrawBuffers(1, drawBuffers2);
-
-		glBlitFramebuffer(
-			0, 0, r->getWidth(), r->getHeight(), 
-			0, 0, r->getWidth(), r->getHeight(),
+		fbo[1].blitFrom(fbo[0], UVec2(0U), UVec2(r->getWidth(), r->getHeight()),
+			UVec2(0U), UVec2(r->getWidth(), r->getHeight()),
 			GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
 			GL_NEAREST);
-#endif
-		ANKI_ASSERT(0 && "TODO");
 	}
 
 	// Gen mips

+ 2 - 0
src/renderer/Renderer.cpp

@@ -101,7 +101,9 @@ void Renderer::init(const RendererInitializer& initializer)
 {
 	// set from the initializer
 	width = initializer.get("width");
+	alignRoundUp(16, width);
 	height = initializer.get("height");
+	alignRoundUp(16, height);
 	lodDistance = initializer.get("lodDistance");
 	framesNum = 0;
 	samples = initializer.get("samples");

+ 2 - 0
src/renderer/Ssao.cpp

@@ -89,7 +89,9 @@ void Ssao::initInternal(const RendererInitializer& initializer)
 	const F32 quality = initializer.get("pps.ssao.renderingQuality");
 
 	width = quality * (F32)r->getWidth();
+	alignRoundUp(16, width);
 	height = quality * (F32)r->getHeight();
+	alignRoundUp(16, height);
 
 	//
 	// create FBOs

+ 2 - 2
testapp/Main.cpp

@@ -594,7 +594,7 @@ void initSubsystems(int argc, char* argv[])
 	initializer.get("is.sm.resolution") = 1024;
 	initializer.get("pps.enabled") = true;
 	initializer.get("pps.hdr.enabled") = true;
-	initializer.get("pps.hdr.renderingQuality") = 0.5;
+	initializer.get("pps.hdr.renderingQuality") = 0.6;
 	initializer.get("pps.hdr.blurringDist") = 1.0;
 	initializer.get("pps.hdr.blurringIterationsCount") = 1;
 	initializer.get("pps.hdr.exposure") = 8.0;
@@ -611,7 +611,7 @@ void initSubsystems(int argc, char* argv[])
 	initializer.get("width") = win->getWidth();
 	initializer.get("height") = win->getHeight();
 	initializer.get("lodDistance") = 20.0;
-	initializer.get("samples") = 1;
+	initializer.get("samples") = 16;
 	initializer.get("tessellation") = false;
 	initializer.get("tilesXCount") = 16;
 	initializer.get("tilesYCount") = 16;