diff --git a/src/Audio/AudioDevice.cs b/src/Audio/AudioDevice.cs index 16a5c492..4c3a76d6 100644 --- a/src/Audio/AudioDevice.cs +++ b/src/Audio/AudioDevice.cs @@ -107,13 +107,13 @@ namespace MoonWorks.Audio IntPtr chainPtr; chainPtr = Marshal.AllocHGlobal( - Marshal.SizeOf() + sizeof(FAudio.FAudioEffectChain) ); FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr; reverbChain->EffectCount = 1; reverbChain->pEffectDescriptors = Marshal.AllocHGlobal( - Marshal.SizeOf() + sizeof(FAudio.FAudioEffectDescriptor) ); FAudio.FAudioEffectDescriptor* reverbDescriptor = @@ -146,7 +146,7 @@ namespace MoonWorks.Audio // Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC IntPtr reverbParamsPtr = Marshal.AllocHGlobal( - Marshal.SizeOf() + sizeof(FAudio.FAudioFXReverbParameters) ); FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr; @@ -176,7 +176,7 @@ namespace MoonWorks.Audio ReverbVoice, 0, reverbParamsPtr, - (uint) Marshal.SizeOf(), + (uint) sizeof(FAudio.FAudioFXReverbParameters), 0 ); Marshal.FreeHGlobal(reverbParamsPtr); @@ -187,7 +187,7 @@ namespace MoonWorks.Audio { SendCount = 2, pSends = Marshal.AllocHGlobal( - 2 * Marshal.SizeOf() + 2 * sizeof(FAudio.FAudioSendDescriptor) ) }; FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends; diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 5afbb57b..bc444456 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -511,7 +511,7 @@ namespace MoonWorks.Graphics Device.Handle, Handle, (IntPtr) ptr, - (uint) (uniforms.Length * Marshal.SizeOf()) + (uint) (uniforms.Length * sizeof(T)) ); } } @@ -530,7 +530,7 @@ namespace MoonWorks.Graphics Device.Handle, Handle, (IntPtr) ptr, - (uint) (uniforms.Length * Marshal.SizeOf()) + (uint) (uniforms.Length * sizeof(T)) ); } } @@ -549,7 +549,7 @@ namespace MoonWorks.Graphics Device.Handle, Handle, (IntPtr) ptr, - (uint) (uniforms.Length * Marshal.SizeOf()) + (uint) (uniforms.Length * sizeof(T)) ); } } @@ -745,7 +745,7 @@ namespace MoonWorks.Graphics uint numElements ) where T : unmanaged { - var elementSize = Marshal.SizeOf(); + var elementSize = sizeof(T); fixed (T* ptr = &data[0]) { @@ -762,19 +762,19 @@ namespace MoonWorks.Graphics } } - public void SetBufferData( + public unsafe void SetBufferData( Buffer buffer, IntPtr dataPtr, uint bufferOffsetInElements, uint numElements - ) { + ) where T : unmanaged { Refresh.Refresh_SetBufferData( Device.Handle, Handle, buffer.Handle, - (uint) Marshal.SizeOf() * bufferOffsetInElements, + (uint) sizeof(T) * bufferOffsetInElements, dataPtr, - (uint) Marshal.SizeOf() * numElements + (uint) sizeof(T) * numElements ); } @@ -794,7 +794,7 @@ namespace MoonWorks.Graphics /// An array of data to copy into the texture. public unsafe void SetTextureData(in TextureSlice textureSlice, T[] data) where T : unmanaged { - var size = Marshal.SizeOf(); + var size = sizeof(T); fixed (T* ptr = &data[0]) { diff --git a/src/Graphics/Font/Packer.cs b/src/Graphics/Font/Packer.cs index 65ff964d..8f0fe665 100644 --- a/src/Graphics/Font/Packer.cs +++ b/src/Graphics/Font/Packer.cs @@ -25,8 +25,8 @@ namespace MoonWorks.Graphics.Font { fixed (FontRange *pFontRanges = &fontRanges[0]) { - var nativeSize = fontRanges.Length * Marshal.SizeOf(); - void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) Marshal.SizeOf()); + var nativeSize = fontRanges.Length * sizeof(Wellspring.FontRange); + void* fontRangeMemory = NativeMemory.Alloc((nuint) fontRanges.Length, (nuint) sizeof(Wellspring.FontRange)); System.Buffer.MemoryCopy(pFontRanges, fontRangeMemory, nativeSize, nativeSize); var result = Wellspring.Wellspring_PackFontRanges(Handle, (IntPtr) fontRangeMemory, (uint) fontRanges.Length); diff --git a/src/Graphics/RefreshStructs.cs b/src/Graphics/RefreshStructs.cs index d0cfc5e7..518db0a0 100644 --- a/src/Graphics/RefreshStructs.cs +++ b/src/Graphics/RefreshStructs.cs @@ -128,13 +128,13 @@ namespace MoonWorks.Graphics public VertexInputRate InputRate; // Shortcut for the common case of having a single vertex binding. - public static VertexBinding Create() + public unsafe static VertexBinding Create() where T : unmanaged { return new VertexBinding { Binding = 0, InputRate = VertexInputRate.Vertex, - Stride = (uint) Marshal.SizeOf() + Stride = (uint) sizeof(T) }; } } diff --git a/src/Graphics/Resources/Buffer.cs b/src/Graphics/Resources/Buffer.cs index ee90e856..bd737dbd 100644 --- a/src/Graphics/Resources/Buffer.cs +++ b/src/Graphics/Resources/Buffer.cs @@ -24,16 +24,16 @@ namespace MoonWorks.Graphics /// Specifies how the buffer will be used. /// How many elements of type T the buffer will contain. /// - public static Buffer Create( + public unsafe static Buffer Create( GraphicsDevice device, BufferUsageFlags usageFlags, uint elementCount - ) + ) where T : unmanaged { return new Buffer( device, usageFlags, - (uint) Marshal.SizeOf() * elementCount + (uint) sizeof(T) * elementCount ); } diff --git a/src/Graphics/State/ComputeShaderInfo.cs b/src/Graphics/State/ComputeShaderInfo.cs index 7787de21..ef831783 100644 --- a/src/Graphics/State/ComputeShaderInfo.cs +++ b/src/Graphics/State/ComputeShaderInfo.cs @@ -13,18 +13,18 @@ namespace MoonWorks.Graphics public uint BufferBindingCount; public uint ImageBindingCount; - public static ComputeShaderInfo Create( + public unsafe static ComputeShaderInfo Create( ShaderModule shaderModule, string entryPointName, uint bufferBindingCount, uint imageBindingCount - ) + ) where T : unmanaged { return new ComputeShaderInfo { ShaderModule = shaderModule, EntryPointName = entryPointName, - UniformBufferSize = (uint) Marshal.SizeOf(), + UniformBufferSize = (uint) sizeof(T), BufferBindingCount = bufferBindingCount, ImageBindingCount = imageBindingCount }; diff --git a/src/Graphics/State/GraphicsShaderInfo.cs b/src/Graphics/State/GraphicsShaderInfo.cs index 069cca1c..b0e84e5b 100644 --- a/src/Graphics/State/GraphicsShaderInfo.cs +++ b/src/Graphics/State/GraphicsShaderInfo.cs @@ -12,7 +12,7 @@ namespace MoonWorks.Graphics public uint UniformBufferSize; public uint SamplerBindingCount; - public static GraphicsShaderInfo Create( + public unsafe static GraphicsShaderInfo Create( ShaderModule shaderModule, string entryPointName, uint samplerBindingCount @@ -22,7 +22,7 @@ namespace MoonWorks.Graphics { ShaderModule = shaderModule, EntryPointName = entryPointName, - UniformBufferSize = (uint) Marshal.SizeOf(), + UniformBufferSize = (uint) sizeof(T), SamplerBindingCount = samplerBindingCount }; }