From 627aa610fc93398ac51129096ce8fb30731af341 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sun, 11 Mar 2018 21:27:11 +0100 Subject: Split buffer in three, one per color (as OpenGL guarantees that one can at least have 8 SSBOs), to allow three times larger images. Also make it possible to ignore maximum buffer size reported by the driver. The maximum buffer size limitation is rather strict on radeonsi, so I decided to split the buffer in three, effectively increasing the maximum image size by a factor of three. While doing so I realized that at least on radeonsi the reported maximum buffer size seems to be off. For this reason I added a new command line switch, that allows to ignore the maximum buffer size check. For those curious: radeonsi reports a maximum buffer size of 128 MB, but I had no problems when using three buffers of 1098 MB each. --- BuddhaTest/src/BuddhaTest.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'BuddhaTest/src/BuddhaTest.cpp') diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp index 1709853..5d03ad4 100644 --- a/BuddhaTest/src/BuddhaTest.cpp +++ b/BuddhaTest/src/BuddhaTest.cpp @@ -58,7 +58,7 @@ int main(int argc, char * argv[]) //we have a context. Let's check if input is sane. //calcualte buffer size, and make sure it's allowed by the driver. - const unsigned int pixelCount{(settings.imageWidth * bufferHeight)*3}; //*3 -> RGB + const unsigned int pixelCount{(settings.imageWidth * bufferHeight)}; if(!settings.CheckValidity()) { glfwTerminate(); @@ -109,15 +109,18 @@ int main(int argc, char * argv[]) glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); - GLuint drawBuffer; - glGenBuffers(1, &drawBuffer); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer); + GLuint drawBuffer[3]; + glGenBuffers(3, drawBuffer); + for(int i=0; i < 3; ++i) { - glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * pixelCount, nullptr, GL_DYNAMIC_COPY); - glClearBufferData(GL_SHADER_STORAGE_BUFFER,GL_R8,GL_RED,GL_UNSIGNED_INT,nullptr); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer[i]); + { + glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * pixelCount, nullptr, GL_DYNAMIC_COPY); + glClearBufferData(GL_SHADER_STORAGE_BUFFER,GL_R8,GL_RED,GL_UNSIGNED_INT,nullptr); + } + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2+i, drawBuffer[i]); } - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, drawBuffer); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); uint32_t iterationCount{0}; glUseProgram(ComputeShader); @@ -188,17 +191,25 @@ int main(int argc, char * argv[]) if(!settings.pngFilename.empty()) { glMemoryBarrier(GL_ALL_BARRIER_BITS); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer); + std::vector> readBackBuffers(3,std::vector(pixelCount)); + for(int i = 0; i < 3; ++i) + { + glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer[i]); + glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0,4 * pixelCount,readBackBuffers[i].data()); + } + + //too lazy to change WriteOutputPng... + std::vector combinedBuffer(3*pixelCount); + for(int i=0;i<3*pixelCount;++i) { - std::vector readBackBuffer(pixelCount); - glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,0,4 * pixelCount,readBackBuffer.data()); - Helpers::WriteOutputPNG(settings.pngFilename,readBackBuffer,settings.imageWidth,bufferHeight, settings.pngGamma, settings.pngColorScale); + combinedBuffer[i] = readBackBuffers[i%3][i/3]; } + Helpers::WriteOutputPNG(settings.pngFilename,combinedBuffer,settings.imageWidth,bufferHeight, settings.pngGamma, settings.pngColorScale); } //a bit of cleanup glDeleteBuffers(1,&vertexbuffer); - glDeleteBuffers(1,&drawBuffer); + glDeleteBuffers(3,drawBuffer); glfwTerminate(); return 0; -- cgit v1.2.3