Merge pull request #285 from guzba/master

simd draw bugfix
This commit is contained in:
treeform 2021-09-08 22:34:16 -07:00 committed by GitHub
commit bf322e1d33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 26 deletions

View file

@ -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),

View file

@ -757,24 +757,33 @@ 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):
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()

View file

@ -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

View file

@ -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),