From b61d8868d3e3b66be3ba892804f4a99514cec66a Mon Sep 17 00:00:00 2001 From: martinfouilleul Date: Sun, 2 Jul 2023 12:26:54 +0200 Subject: [PATCH] [wip, win32, canvas] wip trying to fix multiple shapes --- examples/polygon/main.c | 5 +--- src/gl_canvas.c | 9 +++---- src/glsl_shaders/backprop.glsl | 43 ++++++++++++++++++++++++++-------- src/glsl_shaders/merge.glsl | 1 - src/glsl_shaders/raster.glsl | 4 ++-- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/examples/polygon/main.c b/examples/polygon/main.c index 7912cca..f3ea8d7 100644 --- a/examples/polygon/main.c +++ b/examples/polygon/main.c @@ -16,8 +16,6 @@ #include"milepost.h" -#define LOG_SUBSYSTEM "Main" - int main() { mp_init(); @@ -111,7 +109,6 @@ int main() mg_set_color_rgba(1, 0, 0, 1); mg_fill(); -/* mg_move_to(200, 100); mg_line_to(410, 100); mg_line_to(410, 200); @@ -119,7 +116,7 @@ int main() mg_close_path(); mg_set_color_rgba(0, 1, 0, 1); mg_fill(); - +/* mg_move_to(400, 400); mg_quadratic_to(600, 601, 800, 400); mg_close_path(); diff --git a/src/gl_canvas.c b/src/gl_canvas.c index bb0c597..f47cd60 100644 --- a/src/gl_canvas.c +++ b/src/gl_canvas.c @@ -273,16 +273,13 @@ void mg_gl_render_batch(mg_gl_canvas_backend* backend, glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); //NOTE: backprop pass -/* glUseProgram(backend->backprop); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, backend->tileQueueBuffer); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, backend->pathQueueBuffer); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, backend->tileQueueBuffer); - glUniform2i(0, nTilesX, nTilesY); - - glDispatchCompute(nTilesY, 1, 1); + glDispatchCompute(pathCount, 1, 1); glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); -*/ //NOTE: merge pass glUseProgram(backend->merge); diff --git a/src/glsl_shaders/backprop.glsl b/src/glsl_shaders/backprop.glsl index 46e5c46..6cb4741 100644 --- a/src/glsl_shaders/backprop.glsl +++ b/src/glsl_shaders/backprop.glsl @@ -1,26 +1,49 @@ -layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; +layout(local_size_x = 16, local_size_y = 1, local_size_z = 1) in; precision mediump float; layout(std430) buffer; -layout(binding = 0) restrict buffer tileQueueBufferSSBO +layout(binding = 0) restrict readonly buffer pathQueueBufferSSBO +{ + mg_gl_path_queue elements[]; +} pathQueueBuffer; + +layout(binding = 1) restrict buffer tileQueueBufferSSBO { mg_gl_tile_queue elements[]; } tileQueueBuffer; -layout(location = 0) uniform ivec2 nTiles; +shared int nextRowIndex; void main() { - int rowIndex = int(gl_WorkGroupID.x); + int pathIndex = int(gl_WorkGroupID.x); + int localID = int(gl_LocalInvocationID.x); - int sum = 0; - for(int x = nTiles.x-1; x >= 0; x--) + if(localID == 0) { - int tileIndex = rowIndex * nTiles.x + x; - int offset = tileQueueBuffer.elements[tileIndex].windingOffset; - tileQueueBuffer.elements[tileIndex].windingOffset = sum; - sum += offset; + nextRowIndex = 0; + } + barrier(); + + int rowIndex = 0; + mg_gl_path_queue pathQueue = pathQueueBuffer.elements[pathIndex]; + int tileQueueBase = pathQueue.tileQueues; + int rowSize = pathQueue.area.z; + int rowCount = pathQueue.area.w; + + rowIndex = atomicAdd(nextRowIndex, 1); + while(rowIndex < rowCount) + { + int sum = 0; + for(int x = rowSize-1; x >= 0; x--) + { + int tileIndex = tileQueueBase + rowIndex * rowSize.x + x; + int offset = tileQueueBuffer.elements[tileIndex].windingOffset; + tileQueueBuffer.elements[tileIndex].windingOffset = sum; + sum += offset; + } + rowIndex = atomicAdd(nextRowIndex, 1); } } diff --git a/src/glsl_shaders/merge.glsl b/src/glsl_shaders/merge.glsl index 67de3e1..ea1fdda 100644 --- a/src/glsl_shaders/merge.glsl +++ b/src/glsl_shaders/merge.glsl @@ -45,7 +45,6 @@ void main() int tileIndex = tileCoord.y * nTiles.x + tileCoord.x; screenTilesBuffer.elements[tileIndex] = -1; - int lastOpIndex = -1; for(int pathIndex = 0; pathIndex < pathCount; pathIndex++) diff --git a/src/glsl_shaders/raster.glsl b/src/glsl_shaders/raster.glsl index 3a31cf7..d6f5bb0 100644 --- a/src/glsl_shaders/raster.glsl +++ b/src/glsl_shaders/raster.glsl @@ -150,8 +150,8 @@ void main() while(opIndex >= 0) { - //imageStore(outTexture, ivec2(sampleCoord), vec4(0, 1, 0, 1)); - //return; +// imageStore(outTexture, ivec2(sampleCoord), vec4(0, 1, 1, 1)); +// return; mg_gl_tile_op op = tileOpBuffer.elements[opIndex]; opIndex = op.next;