From ccf3ccb9963749ca526ee2287eb63949b26334a1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 19 Nov 2022 04:00:56 +0100 Subject: [PATCH] Fix constant buffer update from D2D1DrawInfoUpdateContextImpl --- ...teContextImpl.ID2D1DrawInfoUpdateContex.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.ID2D1DrawInfoUpdateContex.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.ID2D1DrawInfoUpdateContex.cs index 5a48809b..93a29162 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.ID2D1DrawInfoUpdateContex.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.ID2D1DrawInfoUpdateContex.cs @@ -150,21 +150,17 @@ partial struct D2D1DrawInfoUpdateContextImpl return E.E_INVALIDARG; } - // Reuse the existing buffer if there is one, otherwise allocate a new one - if (@this->constantBuffer is not null) + // If the buffer is empty, just do nothing + if (bufferCount == 0) { - Buffer.MemoryCopy(buffer, @this->constantBuffer, bufferCount, bufferCount); - } - else - { - void* constantBuffer = NativeMemory.Alloc(bufferCount); - - Buffer.MemoryCopy(buffer, constantBuffer, bufferCount, bufferCount); - - @this->constantBuffer = (byte*)constantBuffer; + return S.S_OK; } - return S.S_OK; + // Copy the buffer to the backing store, so the effect can also access it later + Buffer.MemoryCopy(buffer, @this->constantBuffer, bufferCount, bufferCount); + + // Propagate it to the ID2D1DrawInfo object in use as well + return @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(buffer, bufferCount); } } } \ No newline at end of file