Add property getter/setter for shader constant buffer

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:29 +02:00
1 親 8b48c6f729
コミット 74b7df089a
2ファイル変更
+80 -4

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

+13 -4
ファイルの表示
@@ -117,15 +117,24 @@ public class EndToEndTests
<Inputs>
<Input name='Source'/>
</Inputs>
<Property name='Buffer' type='blob'>
<Property name='DisplayName' type='string' value='Buffer'/>
</Property>
</Effect>";
fixed (char* p = xml)
fixed (char* pXml = xml)
fixed (char* pPropertyName = "Buffer")
{
D2D1_PROPERTY_BINDING d2D1PropertyBinding;
d2D1PropertyBinding.propertyName = (ushort*)pPropertyName;
d2D1PropertyBinding.getFunction = (delegate* unmanaged<IUnknown*, byte*, uint, uint*, HRESULT>)(delegate* unmanaged<IUnknown*, byte*, uint, uint*, int>)&PixelShaderEffect.GetConstantBuffer;
d2D1PropertyBinding.setFunction = (delegate* unmanaged<IUnknown*, byte*, uint, HRESULT>)(delegate* unmanaged<IUnknown*, byte*, uint, int>)&PixelShaderEffect.SetConstantBuffer;
d2D1Factory2.Get()->RegisterEffectFromString(
classId: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(typeof(InvertShader).GUID)),
propertyXml: (ushort*)p,
bindings: null,
bindingsCount: 0,
propertyXml: (ushort*)pXml,
bindings: &d2D1PropertyBinding,
bindingsCount: 1,
effectFactory: (delegate* unmanaged<IUnknown**, HRESULT>)(delegate* unmanaged<IUnknown**, int>)&PixelShaderEffect.Factory).Assert();
}
+67
ファイルの表示
@@ -50,6 +50,16 @@ internal unsafe partial struct PixelShaderEffect
/// </summary>
private PixelShaderTransform* pixelShaderTransform;
/// <summary>
/// The constant buffer data, if set.
/// </summary>
private byte* constantBuffer;
/// <summary>
/// The size of <see cref="constantBuffer"/>, if set.
/// </summary>
private int constantBufferSize;
/// <summary>
/// Creates and initializes a new <see cref="PixelShaderEffect"/> instance.
/// </summary>
@@ -61,6 +71,8 @@ internal unsafe partial struct PixelShaderEffect
@this->lpVtbl = Vtbl;
@this->referenceCount = 1;
@this->pixelShaderTransform = null;
@this->constantBuffer = null;
@this->constantBufferSize = 0;
return @this;
}
@@ -83,6 +95,49 @@ internal unsafe partial struct PixelShaderEffect
return S.S_OK;
}
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
[UnmanagedCallersOnly]
public static int GetConstantBuffer(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
{
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
if (@this->constantBufferSize == 0)
{
*actualSize = 0;
}
else
{
int bytesToCopy = Math.Min((int)dataSize, @this->constantBufferSize);
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, bytesToCopy);
*actualSize = (uint)bytesToCopy;
}
return S.S_OK;
}
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
[UnmanagedCallersOnly]
public static int SetConstantBuffer(IUnknown* effect, byte* data, uint dataSize)
{
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
if (@this->constantBuffer is not null)
{
NativeMemory.Free(@this->constantBuffer);
}
void* buffer = NativeMemory.Alloc(dataSize);
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
@this->constantBuffer = (byte*)buffer;
@this->constantBufferSize = (int)dataSize;
return S.S_OK;
}
/// <inheritdoc cref="ID2D1EffectImpl.QueryInterface"/>
[UnmanagedCallersOnly]
private static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject)
@@ -124,6 +179,11 @@ internal unsafe partial struct PixelShaderEffect
{
((IUnknown*)@this->pixelShaderTransform)->Release();
if (@this->constantBuffer is not null)
{
NativeMemory.Free(@this->constantBuffer);
}
NativeMemory.Free(@this);
}
@@ -158,6 +218,13 @@ internal unsafe partial struct PixelShaderEffect
[UnmanagedCallersOnly]
private static int PrepareForRender(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType)
{
if (@this->constantBuffer is not null)
{
return @this->pixelShaderTransform->D2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: @this->constantBuffer,
bufferCount: (uint)@this->constantBufferSize);
}
return S.S_OK;
}