Add D2D1PixelShader APIs to create shaders from constant buffers
このコミットが含まれているのは:
1 親
bba4db7cdb
コミット
07fe9cceee
2ファイル変更
+44
-3
検索条件に一致するファイルはありません
@@ -52,9 +52,7 @@ internal static unsafe class ID2D1EffectExtensions
|
||||
dataSize: (uint)constantBufferSize).Assert();
|
||||
}
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader = shader.CreateFromConstantBuffer(buffer.AsSpan(0, constantBufferSize));
|
||||
T shader = D2D1PixelShader.CreateFromConstantBuffer<T>(buffer);
|
||||
|
||||
ArrayPool<byte>.Shared.Return(buffer);
|
||||
|
||||
|
||||
@@ -461,4 +461,47 @@ public static class D2D1PixelShader
|
||||
|
||||
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <typeparamref name="T"/> value from constant buffer data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader value to create.</typeparam>
|
||||
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> with the constant buffer data.</param>
|
||||
/// <returns>The resulting <typeparamref name="T"/> instance.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown if <paramref name="span"/> is not large enough to contain the constant buffer.</exception>
|
||||
public static T CreateFromConstantBuffer<T>(ReadOnlySpan<byte> span)
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
if (!TryCreateFromConstantBuffer(span, out T shader))
|
||||
{
|
||||
default(ArgumentException).Throw(nameof(span));
|
||||
}
|
||||
|
||||
return shader;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to create a <typeparamref name="T"/> value from constant buffer data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader value to create.</typeparam>
|
||||
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> with the constant buffer data.</param>
|
||||
/// <param name="shader">The resulting <typeparamref name="T"/> value, if successful.</param>
|
||||
/// <returns>Whether or not the <typeparamref name="T"/> value was retrieved successfully.</returns>
|
||||
public static bool TryCreateFromConstantBuffer<T>(ReadOnlySpan<byte> span, out T shader)
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
Unsafe.SkipInit(out shader);
|
||||
|
||||
if (span.Length >= shader.ConstantBufferSize)
|
||||
{
|
||||
shader = shader.CreateFromConstantBuffer(span);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
shader = default;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする