From 47544f64c4f85481a0cc39d2f0aa94593e6765a9 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Wed, 8 Sep 2021 19:05:59 -0500 Subject: [PATCH 1/4] run gen_readme --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a47163d..1e9e8d8 100644 --- a/README.md +++ b/README.md @@ -282,16 +282,11 @@ image.fillPath(path, paint) ### Shadow [examples/shadow.nim](examples/shadow.nim) ```nim +let path = newPath() +path.polygon(vec2(100, 100), 70, sides = 8) + let polygonImage = newImage(200, 200) - -let ctx = newContext(polygonImage) -ctx.fillStyle = rgba(255, 255, 255, 255) - -ctx.fillPolygon( - vec2(100, 100), - 70, - sides = 8 -) +polygonImage.fillPath(path, rgba(255, 255, 255, 255)) let shadow = polygonImage.shadow( offset = vec2(2, 2), From 60bcff9bb265b63732b24e68062df3db943a82b4 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Wed, 8 Sep 2021 22:46:49 -0500 Subject: [PATCH 2/4] simd draw bugfix --- src/pixie/images.nim | 35 ++++++++++++++++++++++----------- tests/benchmark_images_draw.nim | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 8ceac10..d36faff 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -757,24 +757,35 @@ proc drawUber( when type(a) is Image: if blendMode.hasSimdBlender(): let blenderSimd = blendMode.blenderSimd() - for _ in countup(x, xMax - 4, 4): + for _ in countup(x, xMax - 16, 16): + # Always take steps of 16 indices since masks will be reading + # 16 bytes even if we only use 4 from the last read. let srcPos = p + dx * x.float32 + dy * y.float32 sx = srcPos.x.int sy = srcPos.y.int - backdrop = mm_loadu_si128(a.data[a.dataIndex(x, y)].addr) when type(b) is Image: - let source = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr) + for q in [0, 4, 8, 12]: + let + backdrop = mm_loadu_si128(a.data[a.dataIndex(x + q, y)].addr) + source = mm_loadu_si128(b.data[b.dataIndex(sx + q, sy)].addr) + mm_storeu_si128( + a.data[a.dataIndex(x + q, y)].addr, + blenderSimd(backdrop, source) + ) else: # b is a Mask - # Need to move 4 mask values into the alpha slots - var source = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr) - source = unpackAlphaValues(source) - - mm_storeu_si128( - a.data[a.dataIndex(x, y)].addr, - blenderSimd(backdrop, source) - ) - x += 4 + var values = mm_loadu_si128(b.data[b.dataIndex(sx, sy)].addr) + for q in [0, 4, 8, 12]: + let + backdrop = mm_loadu_si128(a.data[a.dataIndex(x + q, y)].addr) + source = unpackAlphaValues(values) + mm_storeu_si128( + a.data[a.dataIndex(x + q, y)].addr, + blenderSimd(backdrop, source) + ) + # Shuffle 32 bits off for the next iteration + values = mm_srli_si128(values, 4) + x += 16 else: # is a Mask if blendMode.hasSimdMasker(): let maskerSimd = blendMode.maskerSimd() diff --git a/tests/benchmark_images_draw.nim b/tests/benchmark_images_draw.nim index 3ae2443..34aabd1 100644 --- a/tests/benchmark_images_draw.nim +++ b/tests/benchmark_images_draw.nim @@ -95,7 +95,7 @@ block: timeIt "shadow": b.fill(rgba(0, 0, 0, 255)) - a.draw(b, vec2(25, 25)) + a.draw(b, translate(vec2(25, 25))) let shadow = a.shadow( offset = vec2(0, 0), From 3d424577c9e564568166d80a6b658041d4ec53f8 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Wed, 8 Sep 2021 23:06:17 -0500 Subject: [PATCH 3/4] morepretty --- src/pixie/paths.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 82a6ff7..f01b4e4 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1401,9 +1401,11 @@ proc fillHits( windingRule: WindingRule, blendMode: BlendMode ) = - let blender = blendMode.blender() + let + blender = blendMode.blender() + width = image.width.float32 var filledTo: int - for (prevAt, at, count) in hits.walk(numHits, windingRule, y, image.width.float32): + for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width): let fillStart = prevAt.int fillLen = at.int - fillStart @@ -1449,9 +1451,11 @@ proc fillHits( windingRule: WindingRule, blendMode: BlendMode ) = - let masker = blendMode.masker() + let + masker = blendMode.masker() + width = mask.width.float32 var filledTo: int - for (prevAt, at, count) in hits.walk(numHits, windingRule, y, mask.width.float32): + for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width): let fillStart = prevAt.int fillLen = at.int - fillStart From 9e40bd1c2025da49ff796afd6eaaf1ef74bc7e1e Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Wed, 8 Sep 2021 23:10:02 -0500 Subject: [PATCH 4/4] f --- src/pixie/images.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pixie/images.nim b/src/pixie/images.nim index d36faff..e4e7339 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -758,8 +758,6 @@ proc drawUber( if blendMode.hasSimdBlender(): let blenderSimd = blendMode.blenderSimd() for _ in countup(x, xMax - 16, 16): - # Always take steps of 16 indices since masks will be reading - # 16 bytes even if we only use 4 from the last read. let srcPos = p + dx * x.float32 + dy * y.float32 sx = srcPos.x.int