change sizeof calls to Marshal.SizeOf in interop situations
parent
debb76f62a
commit
b9f2d50730
|
@ -118,13 +118,13 @@ namespace MoonWorks.Audio
|
||||||
|
|
||||||
IntPtr chainPtr;
|
IntPtr chainPtr;
|
||||||
chainPtr = Marshal.AllocHGlobal(
|
chainPtr = Marshal.AllocHGlobal(
|
||||||
sizeof(FAudio.FAudioEffectChain)
|
Marshal.SizeOf<FAudio.FAudioEffectChain>()
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
||||||
reverbChain->EffectCount = 1;
|
reverbChain->EffectCount = 1;
|
||||||
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
||||||
sizeof(FAudio.FAudioEffectDescriptor)
|
Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
||||||
|
@ -157,7 +157,7 @@ namespace MoonWorks.Audio
|
||||||
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
||||||
|
|
||||||
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
||||||
sizeof(FAudio.FAudioFXReverbParameters)
|
Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
|
||||||
);
|
);
|
||||||
|
|
||||||
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
||||||
|
@ -187,7 +187,7 @@ namespace MoonWorks.Audio
|
||||||
ReverbVoice,
|
ReverbVoice,
|
||||||
0,
|
0,
|
||||||
reverbParamsPtr,
|
reverbParamsPtr,
|
||||||
(uint) sizeof(FAudio.FAudioFXReverbParameters),
|
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
Marshal.FreeHGlobal(reverbParamsPtr);
|
Marshal.FreeHGlobal(reverbParamsPtr);
|
||||||
|
@ -198,7 +198,7 @@ namespace MoonWorks.Audio
|
||||||
{
|
{
|
||||||
SendCount = 2,
|
SendCount = 2,
|
||||||
pSends = Marshal.AllocHGlobal(
|
pSends = Marshal.AllocHGlobal(
|
||||||
2 * sizeof(FAudio.FAudioSendDescriptor)
|
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -846,6 +847,10 @@ namespace MoonWorks.Graphics
|
||||||
in BufferBinding bufferBinding,
|
in BufferBinding bufferBinding,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
var bufferPtrs = stackalloc IntPtr[1];
|
var bufferPtrs = stackalloc IntPtr[1];
|
||||||
var offsets = stackalloc ulong[1];
|
var offsets = stackalloc ulong[1];
|
||||||
|
|
||||||
|
@ -873,6 +878,10 @@ namespace MoonWorks.Graphics
|
||||||
in BufferBinding bufferBindingTwo,
|
in BufferBinding bufferBindingTwo,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
var bufferPtrs = stackalloc IntPtr[2];
|
var bufferPtrs = stackalloc IntPtr[2];
|
||||||
var offsets = stackalloc ulong[2];
|
var offsets = stackalloc ulong[2];
|
||||||
|
|
||||||
|
@ -905,6 +914,10 @@ namespace MoonWorks.Graphics
|
||||||
in BufferBinding bufferBindingThree,
|
in BufferBinding bufferBindingThree,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
var bufferPtrs = stackalloc IntPtr[3];
|
var bufferPtrs = stackalloc IntPtr[3];
|
||||||
var offsets = stackalloc ulong[3];
|
var offsets = stackalloc ulong[3];
|
||||||
|
|
||||||
|
@ -941,6 +954,10 @@ namespace MoonWorks.Graphics
|
||||||
in BufferBinding bufferBindingFour,
|
in BufferBinding bufferBindingFour,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
var bufferPtrs = stackalloc IntPtr[4];
|
var bufferPtrs = stackalloc IntPtr[4];
|
||||||
var offsets = stackalloc ulong[4];
|
var offsets = stackalloc ulong[4];
|
||||||
|
|
||||||
|
@ -973,6 +990,10 @@ namespace MoonWorks.Graphics
|
||||||
in Span<BufferBinding> bufferBindings,
|
in Span<BufferBinding> bufferBindings,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
var bufferPtrs = stackalloc IntPtr[bufferBindings.Length];
|
var bufferPtrs = stackalloc IntPtr[bufferBindings.Length];
|
||||||
var offsets = stackalloc ulong[bufferBindings.Length];
|
var offsets = stackalloc ulong[bufferBindings.Length];
|
||||||
|
|
||||||
|
@ -1406,7 +1427,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1433,7 +1454,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1461,7 +1482,7 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(IntPtr) uniformsPtr,
|
(IntPtr) uniformsPtr,
|
||||||
(uint) sizeof(T)
|
(uint) Marshal.SizeOf<T>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1622,6 +1643,13 @@ namespace MoonWorks.Graphics
|
||||||
public Texture AcquireSwapchainTexture(
|
public Texture AcquireSwapchainTexture(
|
||||||
Window window
|
Window window
|
||||||
) {
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
if (!window.Claimed)
|
||||||
|
{
|
||||||
|
throw new System.InvalidOperationException("Cannot acquire swapchain texture, window has not been claimed!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
var texturePtr = Refresh.Refresh_AcquireSwapchainTexture(
|
var texturePtr = Refresh.Refresh_AcquireSwapchainTexture(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
|
@ -1720,7 +1748,7 @@ namespace MoonWorks.Graphics
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var elementSize = sizeof(T);
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
|
||||||
fixed (T* ptr = &data[startElement])
|
fixed (T* ptr = &data[startElement])
|
||||||
{
|
{
|
||||||
|
@ -1749,9 +1777,9 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
(uint) sizeof(T) * bufferOffsetInElements,
|
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
|
||||||
dataPtr,
|
dataPtr,
|
||||||
(uint) sizeof(T) * numElements
|
(uint) Marshal.SizeOf<T>() * numElements
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace MoonWorks.Graphics.Font
|
||||||
{
|
{
|
||||||
fixed (FontRange *pFontRanges = &fontRanges[0])
|
fixed (FontRange *pFontRanges = &fontRanges[0])
|
||||||
{
|
{
|
||||||
var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange);
|
var nativeSize = fontRanges.Length * Marshal.SizeOf<Wellspring.FontRange>();
|
||||||
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange));
|
void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf<Wellspring.FontRange>());
|
||||||
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
|
System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize);
|
||||||
|
|
||||||
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);
|
var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length);
|
||||||
|
|
|
@ -134,7 +134,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
Binding = 0,
|
Binding = 0,
|
||||||
InputRate = VertexInputRate.Vertex,
|
InputRate = VertexInputRate.Vertex,
|
||||||
Stride = (uint) sizeof(T)
|
Stride = (uint) Marshal.SizeOf<T>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using RefreshCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
|
@ -32,7 +33,7 @@ namespace MoonWorks.Graphics
|
||||||
return new Buffer(
|
return new Buffer(
|
||||||
device,
|
device,
|
||||||
usageFlags,
|
usageFlags,
|
||||||
(uint) sizeof(T) * elementCount
|
(uint) Marshal.SizeOf<T>() * elementCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
ShaderModule = shaderModule,
|
ShaderModule = shaderModule,
|
||||||
EntryPointName = entryPointName,
|
EntryPointName = entryPointName,
|
||||||
UniformBufferSize = (uint) sizeof(T),
|
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
||||||
BufferBindingCount = bufferBindingCount,
|
BufferBindingCount = bufferBindingCount,
|
||||||
ImageBindingCount = imageBindingCount
|
ImageBindingCount = imageBindingCount
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
ShaderModule = shaderModule,
|
ShaderModule = shaderModule,
|
||||||
EntryPointName = entryPointName,
|
EntryPointName = entryPointName,
|
||||||
UniformBufferSize = (uint) sizeof(T),
|
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
||||||
SamplerBindingCount = samplerBindingCount
|
SamplerBindingCount = samplerBindingCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue