[win32, gl canvas] bound check intermediate buffers in canvas shaders

This commit is contained in:
martinfouilleul 2023-07-27 12:11:30 +02:00
parent 680deb35b0
commit a35f0b82b2
4 changed files with 208 additions and 168 deletions

View File

@ -62,6 +62,11 @@ int main()
//NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS);
if(mg_surface_is_nil(surface))
{
log_error("Couln't create surface\n");
return(-1);
}
mg_surface_swap_interval(surface, 0);
//TODO: create canvas

View File

@ -106,6 +106,11 @@ void main()
// Additionally if color is opaque and tile is fully inside clip, trim tile list.
int pathOpIndex = atomicAdd(tileOpCountBuffer.elements[0], 1);
if(pathOpIndex >= tileOpBuffer.elements.length())
{
return;
}
tileOpBuffer.elements[pathOpIndex].kind = MG_GL_OP_CLIP_FILL;
tileOpBuffer.elements[pathOpIndex].next = -1;
tileOpBuffer.elements[pathOpIndex].index = pathIndex;
@ -141,6 +146,10 @@ void main()
{
//NOTE: add path start op (with winding offset)
int startOpIndex = atomicAdd(tileOpCountBuffer.elements[0], 1);
if(startOpIndex >= tileOpBuffer.elements.length())
{
return;
}
tileOpBuffer.elements[startOpIndex].kind = MG_GL_OP_START;
tileOpBuffer.elements[startOpIndex].next = -1;
@ -163,6 +172,10 @@ void main()
//NOTE: add path end op
int endOpIndex = atomicAdd(tileOpCountBuffer.elements[0], 1);
if(endOpIndex >= tileOpBuffer.elements.length())
{
return;
}
tileOpBuffer.elements[endOpIndex].kind = MG_GL_OP_END;
tileOpBuffer.elements[endOpIndex].next = -1;

View File

@ -50,6 +50,13 @@ void main()
int tileQueuesIndex = atomicAdd(tileQueueCountBuffer.elements[0], tileCount);
if(tileQueuesIndex + tileCount >= tileQueueBuffer.elements.length())
{
pathQueueBuffer.elements[pathIndex].area = ivec4(0);
pathQueueBuffer.elements[pathIndex].tileQueues = 0;
}
else
{
pathQueueBuffer.elements[pathQueueBufferStart + pathIndex].area = ivec4(firstTile.x, firstTile.y, nTilesX, nTilesY);
pathQueueBuffer.elements[pathQueueBufferStart + pathIndex].tileQueues = tileQueuesIndex;
@ -59,4 +66,5 @@ void main()
tileQueueBuffer.elements[tileQueuesIndex + i].last = -1;
tileQueueBuffer.elements[tileQueuesIndex + i].windingOffset = 0;
}
}
}

View File

@ -105,6 +105,8 @@ void bin_to_tiles(int segIndex)
{
int tileOpIndex = atomicAdd(tileOpCountBuffer.elements[0], 1);
if(tileOpIndex < tileOpBuffer.elements.length())
{
tileOpBuffer.elements[tileOpIndex].kind = MG_GL_OP_SEGMENT;
tileOpBuffer.elements[tileOpIndex].index = segIndex;
tileOpBuffer.elements[tileOpIndex].windingOffsetOrCrossRight = 0;
@ -112,7 +114,8 @@ void bin_to_tiles(int segIndex)
int tileQueueIndex = pathQueue.tileQueues + y*pathArea.z + x;
tileOpBuffer.elements[tileOpIndex].next = atomicExchange(tileQueueBuffer.elements[tileQueueIndex].first, tileOpIndex);
tileOpBuffer.elements[tileOpIndex].next = atomicExchange(tileQueueBuffer.elements[tileQueueIndex].first,
tileOpIndex);
if(tileOpBuffer.elements[tileOpIndex].next == -1)
{
tileQueueBuffer.elements[tileQueueIndex].last = tileOpIndex;
@ -132,12 +135,15 @@ void bin_to_tiles(int segIndex)
}
}
}
}
}
int push_segment(in vec2 p[4], int kind, int pathIndex)
{
int segIndex = atomicAdd(segmentCountBuffer.elements[0], 1);
if(segIndex < segmentBuffer.elements.length())
{
vec2 s, c, e;
switch(kind)
@ -219,7 +225,7 @@ int push_segment(in vec2 p[4], int kind, int pathIndex)
segmentBuffer.elements[segIndex].config = MG_GL_TR;
}
}
}
return(segIndex);
}
@ -229,9 +235,11 @@ int push_segment(in vec2 p[4], int kind, int pathIndex)
void line_setup(vec2 p[4], int pathIndex)
{
int segIndex = push_segment(p, MG_GL_LINE, pathIndex);
if(segIndex < segmentBuffer.elements.length())
{
segmentBuffer.elements[segIndex].hullVertex = p[0];
bin_to_tiles(segIndex);
}
}
vec2 quadratic_blossom(vec2 p[4], float u, float v)
@ -298,6 +306,8 @@ void quadratic_emit(vec2 p[4], int pathIndex)
{
int segIndex = push_segment(p, MG_GL_QUADRATIC, pathIndex);
if(segIndex < segmentBuffer.elements.length())
{
//NOTE: compute implicit equation matrix
float det = p[0].x*(p[1].y-p[2].y) + p[1].x*(p[2].y-p[0].y) + p[2].x*(p[0].y - p[1].y);
@ -319,6 +329,7 @@ void quadratic_emit(vec2 p[4], int pathIndex)
segmentBuffer.elements[segIndex].hullVertex = p[1];
bin_to_tiles(segIndex);
}
}
void quadratic_setup(vec2 p[4], int pathIndex)
@ -654,6 +665,8 @@ void cubic_emit(cubic_info curve, vec2 p[4], float s0, float s1, vec2 sp[4], int
{
int segIndex = push_segment(sp, MG_GL_CUBIC, pathIndex);
if(segIndex < segmentBuffer.elements.length())
{
vec2 v0 = p[0];
vec2 v1 = p[3];
vec2 v2;
@ -719,6 +732,7 @@ void cubic_emit(cubic_info curve, vec2 p[4], float s0, float s1, vec2 sp[4], int
//NOTE: bin to tiles
bin_to_tiles(segIndex);
}
}
void cubic_setup(vec2 p[4], int pathIndex)