Skip to content

Commit d5d1d76

Browse files
Fix gradient brushes
1 parent 16a02bd commit d5d1d76

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/ImageSharp.Drawing.WebGPU/Shaders/WgslSource/Shared/transform.wgsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ fn transform_inverse(transform: Transform) -> Transform {
4646
let det = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
4747
let inv_det = 1.0 / det;
4848

49+
// The packed fields represent the matrix:
50+
// [ a d g ]
51+
// [ b e h ]
52+
// [ c f i ]
53+
// so the cofactors must be placed back into that same layout.
4954
return Transform(
50-
inv_det * vec4(e * i - f * h, f * g - d * i, c * h - b * i, a * i - c * g),
51-
inv_det * vec2(b * f - c * e, c * d - a * f),
52-
inv_det * vec3(d * h - e * g, b * g - a * h, a * e - b * d)
55+
inv_det * vec4(e * i - f * h, c * h - b * i, f * g - d * i, a * i - c * g),
56+
inv_det * vec2(d * h - e * g, b * g - a * h),
57+
inv_det * vec3(b * f - c * e, c * d - a * f, a * e - b * d)
5358
);
5459
}
5560

src/ImageSharp.Drawing.WebGPU/WebGPUSceneEncoder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static bool TryEncode(
8080
return true;
8181
}
8282

83-
encodedScene = SupportedSubsetSceneResolver.Resolve(encoding, targetBounds, allocator);
83+
encodedScene = SupportedSubsetSceneResolver.Resolve(ref encoding, targetBounds, allocator);
8484
error = null;
8585
return true;
8686
}
@@ -806,7 +806,7 @@ private static class SupportedSubsetSceneResolver
806806
/// Resolves the mutable encoding into the final packed scene buffers.
807807
/// </summary>
808808
public static WebGPUEncodedScene Resolve(
809-
SupportedSubsetSceneEncoding encoding,
809+
ref SupportedSubsetSceneEncoding encoding,
810810
in Rectangle targetBounds,
811811
MemoryAllocator allocator)
812812
{
@@ -854,7 +854,7 @@ public static WebGPUEncodedScene Resolve(
854854
encoding.InfoWordCount,
855855
sceneDataOwner,
856856
sceneWordCount,
857-
DetachGradientPixels(encoding),
857+
DetachGradientPixels(ref encoding),
858858
encoding.Images,
859859
encoding.GradientRowCount,
860860
layout,
@@ -886,7 +886,7 @@ public static WebGPUEncodedScene Resolve(
886886
/// <summary>
887887
/// Detaches the gradient pixel payload when gradients were emitted for the flush.
888888
/// </summary>
889-
private static IMemoryOwner<uint>? DetachGradientPixels(SupportedSubsetSceneEncoding encoding)
889+
private static IMemoryOwner<uint>? DetachGradientPixels(ref SupportedSubsetSceneEncoding encoding)
890890
{
891891
if (encoding.GradientRowCount == 0)
892892
{

0 commit comments

Comments
 (0)