Add tests to update 1D resource textures, bug fixes

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-15 15:01:20 +02:00
1 親 bc90c87837
コミット edfed9359b
2ファイル変更
+84 -2

検索条件に一致するファイルはありません

@@ -377,7 +377,7 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
// Either both extents are available, or none is, and the other values must not be null
if (minimumExtents is null && maximimumExtents is not null ||
minimumExtents is not null && maximimumExtents is null ||
strides is null ||
(dimensions > 1 && strides is null) ||
data is null)
{
return E.E_POINTER;
@@ -506,7 +506,7 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
}
}
return E.E_NOTIMPL;
return S.S_OK;
}
/// <summary>
+82
ファイルの表示
@@ -2,6 +2,7 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Helpers;
using ComputeSharp.Tests.Helpers;
@@ -363,4 +364,85 @@ public partial class D2D1ResourceTextureManagerTests
return this.source[x, y, z];
}
}
[TestMethod]
[DataRow(128, 0, 26)]
[DataRow(128, 0, 67)]
[DataRow(128, 0, 128)]
[DataRow(128, 32, 64)]
[DataRow(1024, 311, 489)]
[DataRow(1024, 907, 117)]
public unsafe void UpdateResourceTexture1D_RCW(int width, int startOffset, int updateLength)
{
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture1DShader>(d2D1Factory2.Get(), null, out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<CopyFromResourceTexture1DShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
CopyFromResourceTexture1DShader shader = new(width);
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
byte[] texture = new byte[width];
D2D1ResourceTextureManager resourceTextureManager = new(
extents: stackalloc[] { (uint)width },
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
channelDepth: D2D1ChannelDepth.One,
filter: D2D1Filter.MinMagMipPoint,
extendModes: stackalloc[] { D2D1ExtendMode.Clamp },
data: texture,
strides: null);
byte[] data = RandomNumberGenerator.GetBytes(updateLength);
resourceTextureManager.Update(
minimumExtents: stackalloc uint[] { (uint)startOffset },
maximimumExtents: stackalloc uint[] { (uint)(startOffset + updateLength) },
strides: ReadOnlySpan<uint>.Empty,
data: data);
data.CopyTo(texture.AsSpan(startOffset));
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0);
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)width, 1);
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
byte[] resultingBytes = new byte[width];
int i = 0;
foreach (Bgra32 pixel in new ReadOnlySpan<Bgra32>(d2D1MappedRect.bits, width))
{
resultingBytes[i++] = pixel.B;
}
Assert.IsTrue(texture.AsSpan().SequenceEqual(resultingBytes));
}
[D2DInputCount(0)]
[D2DRequiresScenePosition]
[AutoConstructor]
private partial struct CopyFromResourceTexture1DShader : ID2D1PixelShader
{
private int width;
[D2DResourceTextureIndex(0)]
private D2D1ResourceTexture1D<float> source;
public float4 Execute()
{
int2 xy = (int2)D2D.GetScenePosition().XY;
return this.source[(int)((uint)xy.X % (uint)this.width)];
}
}
}