aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2018-03-22 00:05:59 +0100
committerAndreas Grois <andi@grois.info>2018-03-22 00:05:59 +0100
commitfa76d77be61ad3f0b295a87236e74f150597751f (patch)
treedf7aa409cf1d7c1955e8f89c08c771b3289527c7
parentcca3254becdf793b9335a1f21bcda2c0909f4d1a (diff)
Initial commit for better brightness.
Needs more work, uses too many VGPRs. Also, maybe work on a single shared variable?
-rw-r--r--BuddhaTest/Shaders/BuddhaCompute.glsl44
-rw-r--r--BuddhaTest/Shaders/BuddhaFragment.glsl5
-rw-r--r--BuddhaTest/src/BuddhaTest.cpp8
3 files changed, 52 insertions, 5 deletions
diff --git a/BuddhaTest/Shaders/BuddhaCompute.glsl b/BuddhaTest/Shaders/BuddhaCompute.glsl
index caf10ee..f0b7d43 100644
--- a/BuddhaTest/Shaders/BuddhaCompute.glsl
+++ b/BuddhaTest/Shaders/BuddhaCompute.glsl
@@ -7,6 +7,11 @@ layout(std430, binding=2) restrict buffer renderedDataRed
restrict uint counts_SSBO[];
};
+layout(std430, binding=3) restrict buffer brightnessData
+{
+ restrict uvec3 brightness;
+};
+
struct individualData
{
uint phase;
@@ -28,12 +33,20 @@ uniform uvec4 orbitLength;
uniform uint iterationsPerDispatch;
uniform uint totalIterations;
+shared uvec3[gl_WorkGroupSize.x*gl_WorkGroupSize.y*gl_WorkGroupSize.z] brightnesses;
+
void addToColorOfCell(uvec2 cell, uvec3 toAdd)
{
uint firstIndex = 3*(cell.x + cell.y * width);
- atomicAdd(counts_SSBO[firstIndex],toAdd.x);
- atomicAdd(counts_SSBO[firstIndex+1],toAdd.y);
- atomicAdd(counts_SSBO[firstIndex+2],toAdd.z);
+ uvec3 b;
+ b.x = atomicAdd(counts_SSBO[firstIndex],toAdd.x);
+ b.y = atomicAdd(counts_SSBO[firstIndex+1],toAdd.y);
+ b.z = atomicAdd(counts_SSBO[firstIndex+2],toAdd.z);
+ for(int i = 0; i < 3;++i)
+ {
+ if(brightnesses[gl_LocalInvocationIndex][i] < b[i])
+ brightnesses[gl_LocalInvocationIndex][i] = b[i];
+ }
}
uvec2 getCell(vec2 complex)
@@ -194,6 +207,11 @@ vec2 getCurrentOrbitOffset(const uint orbitNumber, const uint totalWorkers, cons
}
void main() {
+ for(int i = 0; i < 3;++i)
+ {
+ brightnesses[gl_LocalInvocationIndex][i] = 0;
+ }
+
//we need to know how many total work groups are running this iteration
const uvec3 totalWorkersPerDimension = gl_WorkGroupSize * gl_NumWorkGroups;
const uint totalWorkers = totalWorkersPerDimension.x*totalWorkersPerDimension.y*totalWorkersPerDimension.z;
@@ -258,4 +276,24 @@ void main() {
}
}
stateArray[uniqueWorkerID] = state;
+
+ barrier();
+ groupMemoryBarrier();
+ if(gl_LocalInvocationIndex == 0)
+ {
+ uvec3 maxbrightness = uvec3(0,0,0);
+ for(int i = 0; i < brightnesses.length(); ++i)
+ {
+ for(int j=0; j< 3; ++j)
+ {
+ if(brightnesses[i][j] > maxbrightness[j])
+ maxbrightness[j] = brightnesses[i][j];
+ }
+
+ }
+ for(int i = 0; i < 3; ++i)
+ {
+ atomicMax(brightness[i],maxbrightness[i]);
+ }
+ }
}
diff --git a/BuddhaTest/Shaders/BuddhaFragment.glsl b/BuddhaTest/Shaders/BuddhaFragment.glsl
index 449aa29..16d25f2 100644
--- a/BuddhaTest/Shaders/BuddhaFragment.glsl
+++ b/BuddhaTest/Shaders/BuddhaFragment.glsl
@@ -8,6 +8,10 @@ layout(std430, binding=2) restrict readonly buffer renderedDataRed
{
restrict readonly uint counts_SSBO[];
};
+layout(std430, binding=3) restrict readonly buffer brightnessData
+{
+ restrict readonly uvec3 brightness;
+};
uniform uint width;
uniform uint height;
@@ -22,7 +26,6 @@ uvec3 getColorAt(vec2 fragCoord)
void main(){
uvec3 totalCount = getColorAt(uv);
- uvec3 brightness = getColorAt(vec2(-0.2390625,0));
vec3 scaled = vec3(totalCount)/max(length(vec3(brightness)),1.0);
color = scaled;
diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp
index 0ae94b0..4de252d 100644
--- a/BuddhaTest/src/BuddhaTest.cpp
+++ b/BuddhaTest/src/BuddhaTest.cpp
@@ -118,7 +118,13 @@ int main(int argc, char * argv[])
glBufferData(GL_SHADER_STORAGE_BUFFER, 4 *3* pixelCount, nullptr, GL_DYNAMIC_COPY);
glClearBufferData(GL_SHADER_STORAGE_BUFFER,GL_R8,GL_RED,GL_UNSIGNED_INT,nullptr);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, drawBuffer);
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
+
+ GLuint brightnessBuffer;
+ glGenBuffers(1,&brightnessBuffer);
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, brightnessBuffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, 16,nullptr, GL_DYNAMIC_COPY);
+ glClearBufferData(GL_SHADER_STORAGE_BUFFER,GL_R8,GL_RED,GL_UNSIGNED_INT,nullptr);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, brightnessBuffer);
//the state buffer is special. While making each entry 8 bytes large and using std430 layout, the data is never read back,
//so we can get away with being more lenient and allowing the compiler to choose layout without much extra work.