From 5a411e482ebe619a7e85c44584faa5bd71b7ee3b Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 25 Feb 2022 05:33:45 +0000 Subject: [PATCH] Render Pass Streamlining (#1) Co-authored-by: cosmonaut Co-committed-by: cosmonaut --- src/Refresh.cs | 1926 ++++++++++++++++++++++++------------------------ 1 file changed, 946 insertions(+), 980 deletions(-) diff --git a/src/Refresh.cs b/src/Refresh.cs index 312491f..e4cb80d 100644 --- a/src/Refresh.cs +++ b/src/Refresh.cs @@ -30,1024 +30,990 @@ using System.Runtime.InteropServices; namespace RefreshCS { - public static class Refresh - { - private const string nativeLibName = "Refresh"; - - /* Enums */ - - public enum PresentMode - { - Immediate, - Mailbox, - FIFO, - FIFORelaxed - } - - public enum PrimitiveType - { - PointList, - LineList, - LineStrip, - TriangleList, - TriangleStrip - } - - public enum LoadOp - { - Load, - Clear, - DontCare - } - - public enum StoreOp - { - Store, - DontCare - } - - [Flags] - public enum ClearOptionsFlags : uint - { - Color = 1, - Depth = 2, - Stencil = 4, - DepthStencil = Depth | Stencil, - All = Color | Depth | Stencil - } - - public enum IndexElementSize - { - Sixteen, - ThirtyTwo - } - - public enum TextureFormat - { - R8G8B8A8, - R5G6B5, - A1R5G5B5, - B4G4R4A4, - BC1, - BC2, - BC3, - R8G8_SNORM, - R8G8B8A8_SNORM, - A2R10G10B10, - R16G16, - R16G16B16A16, - R8, - R32_SFLOAT, - R32G32_SFLOAT, - R32G32B32A32_SFLOAT, - R16_SFLOAT, - R16G16_SFLOAT, - R16G16B16A16_SFLOAT, - D16, - D32, - D16S8, - D32S8 - } - - [Flags] - public enum TextureUsageFlags : uint - { - Sampler = 1, - ColorTarget = 2, - DepthStencilTarget = 4 - } - - public enum SampleCount - { - One, - Two, - Four, - Eight, - Sixteen, - ThirtyTwo, - SixtyFour - } - - public enum CubeMapFace : uint - { - PositiveX, - NegativeX, - PositiveY, - NegativeY, - PositiveZ, - NegativeZ - } - - [Flags] - public enum BufferUsageFlags : uint - { - Vertex = 1, - Index = 2, - Compute = 4 - } - - public enum VertexElementFormat - { - Single, - Vector2, - Vector3, - Vector4, - Color, - Byte4, - Short2, - Short4, - NormalizedShort2, - NormalizedShort4, - HalfVector2, - HalfVector4 - } - - public enum VertexInputRate - { - Vertex, - Instance - } - - public enum FillMode - { - Fill, - Line, - Point - } - - public enum CullMode - { - None, - Front, - Back, - FrontAndBack - } - - public enum FrontFace - { - CounterClockwise, - Clockwise - } - - public enum CompareOp - { - Never, - Less, - Equal, - LessOrEqual, - Greater, - NotEqual, - GreaterOrEqual, - Always - } - - public enum StencilOp - { - Keep, - Zero, - Replace, - IncrementAndClamp, - DecrementAndClamp, - Invert, - IncrementAndWrap, - DecrementAndWrap - } - - public enum BlendOp - { - Add, - Subtract, - ReverseSubtract, - Min, - Max - } - - public enum LogicOp - { - Clear, - And, - AndReverse, - Copy, - AndInverted, - NoOp, - Xor, - Or, - Nor, - Equivalent, - Invert, - OrReverse, - CopyInverted, - OrInverted, - Nand, - Set - } - - public enum BlendFactor - { - Zero, - One, - SourceColor, - OneMinusSourceColor, - DestinationColor, - OneMinusDestinationColor, - SourceAlpha, - OneMinusSourceAlpha, - DestinationAlpha, - OneMinusDestinationAlpha, - ConstantColor, - OneMinusConstantColor, - ConstantAlpha, - OneMinusConstantAlpha, - SourceAlphaSaturate, - SourceOneColor, - OneMinusSourceOneColor, - SourceOneAlpha, - OneMinusSourceOneAlpha - } - - [Flags] - public enum ColorComponentFlags : uint - { - R = 1, - G = 2, - B = 4, - A = 8, - - RG = R | G, - RB = R | B, - RA = R | A, - GB = G | B, - GA = G | A, - BA = B | A, - - RGB = R | G | B, - RGA = R | G | A, - GBA = G | B | A, - - RGBA = R | G | B | A - } - - public enum ShaderStageType - { - Vertex, - Fragment - } - - public enum Filter - { - Nearest, - Linear, - Cubic - } - - public enum SamplerMipmapMode - { - Nearest, - Linear - } - - public enum SamplerAddressMode - { - Repeat, - MirroredRepeat, - ClampToEdge, - ClampToBorder - } - - public enum BorderColor - { - FloatTransparentBlack, - IntTransparentBlack, - FloatOpaqueBlack, - IntOpaqueBlack, - FloatOpaqueWhite, - IntOpaqueWhite - } - - /* Native Structures */ - - [StructLayout(LayoutKind.Sequential)] - public struct DepthStencilValue - { - public float depth; - public uint stencil; - } - - [StructLayout(LayoutKind.Sequential)] - public struct Rect - { - public int x; - public int y; - public int w; - public int h; - } - - [StructLayout(LayoutKind.Sequential)] - public struct Vec4 - { - public float x; - public float y; - public float z; - public float w; - } - - [StructLayout(LayoutKind.Sequential)] - public struct Viewport - { - public float x; - public float y; - public float w; - public float h; - public float minDepth; - public float maxDepth; - } - - [StructLayout(LayoutKind.Sequential)] - public struct TextureSlice - { - public IntPtr texture; - public Rect rectangle; - public uint depth; - public uint layer; - public uint level; - } - - [StructLayout(LayoutKind.Sequential)] - public struct PresentationParameters - { - public IntPtr deviceWindowHandle; - public PresentMode presentMode; - } - - [StructLayout(LayoutKind.Sequential)] - public struct SamplerStateCreateInfo - { - public Filter minFilter; - public Filter magFilter; - public SamplerMipmapMode mipmapMode; - public SamplerAddressMode addressModeU; - public SamplerAddressMode addressModeV; - public SamplerAddressMode addressModeW; - public float mipLodBias; - public byte anisotropyEnable; - public float maxAnisotropy; - public byte compareEnable; - public CompareOp compareOp; - public float minLod; - public float maxLod; - public BorderColor borderColor; - } - - [StructLayout(LayoutKind.Sequential)] - public struct VertexBinding - { - public uint binding; - public uint stride; - public VertexInputRate inputRate; - } - - [StructLayout(LayoutKind.Sequential)] - public struct VertexAttribute - { - public uint location; - public uint binding; - public VertexElementFormat format; - public uint offset; - } - - [StructLayout(LayoutKind.Sequential)] - public struct VertexInputState - { - public IntPtr vertexBindings; - public uint vertexBindingCount; - public IntPtr vertexAttributes; - public uint vertexAttributeCount; - } - - [StructLayout(LayoutKind.Sequential)] - public struct StencilOpState - { - public StencilOp failOp; - public StencilOp passOp; - public StencilOp depthFailOp; - public CompareOp compareOp; - public uint compareMask; - public uint writeMask; - public uint reference; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ColorTargetBlendState - { - public byte blendEnable; - public BlendFactor sourceColorBlendFactor; - public BlendFactor destinationColorBlendFactor; - public BlendOp colorBlendOp; - public BlendFactor sourceAlphaBlendFactor; - public BlendFactor destinationAlphaBlendFactor; - public BlendOp alphaBlendOp; - public ColorComponentFlags colorWriteMask; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ComputePipelineLayoutCreateInfo - { - public uint bufferBindingCount; - public uint imageBindingCount; - } - - [StructLayout(LayoutKind.Sequential)] - public struct GraphicsPipelineLayoutCreateInfo - { - public uint vertexSamplerBindingCount; - public uint fragmentSamplerBindingCount; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ColorTargetDescription - { - public TextureFormat format; - public SampleCount multisampleCount; - public LoadOp loadOp; - public StoreOp storeOp; - } - - [StructLayout(LayoutKind.Sequential)] - public struct DepthStencilTargetDescription - { - public TextureFormat format; - public LoadOp loadOp; - public StoreOp storeOp; - public LoadOp stencilLoadOp; - public StoreOp stencilStoreOp; - } - - [StructLayout(LayoutKind.Sequential)] - public struct RenderPassCreateInfo - { - public IntPtr colorTargetDescriptions; /* Refresh_ColorTargetDescription */ - public uint colorTargetCount; - public IntPtr depthStencilTargetDescription; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ShaderModuleCreateInfo - { - public UIntPtr codeSize; /* size_t */ - public IntPtr byteCode; - } - - [StructLayout(LayoutKind.Sequential)] - public struct TextureCreateInfo - { - public uint width; - public uint height; - public uint depth; - public byte isCube; - public SampleCount sampleCount; - public uint levelCount; - public TextureFormat format; - public TextureUsageFlags usageFlags; /* Refresh_TextureUsageFlags */ - } - - [StructLayout(LayoutKind.Sequential)] - public struct ShaderStageState - { - public IntPtr shaderModule; - [MarshalAs(UnmanagedType.LPStr)] - public string entryPointName; - public ulong uniformBufferSize; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ViewportState - { - public IntPtr viewports; - public uint viewportCount; - public IntPtr scissors; - public uint scissorCount; - } - - [StructLayout(LayoutKind.Sequential)] - public struct RasterizerState - { - public byte depthClampEnable; - public FillMode fillMode; - public CullMode cullMode; - public FrontFace frontFace; - public byte depthBiasEnable; - public float depthBiasConstantFactor; - public float depthBiasClamp; - public float depthBiasSlopeFactor; - public float lineWidth; - } - - [StructLayout(LayoutKind.Sequential)] - public struct MultisampleState - { - public SampleCount multisampleCount; - public uint sampleMask; - } - - [StructLayout(LayoutKind.Sequential)] - public struct DepthStencilState - { - public byte depthTestEnable; - public byte depthWriteEnable; - public CompareOp compareOp; - public byte depthBoundsTestEnable; - public byte stencilTestEnable; - public StencilOpState frontStencilState; - public StencilOpState backStencilState; - public float minDepthBounds; - public float maxDepthBounds; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct ColorBlendState - { - public byte logicOpEnable; - public LogicOp logicOp; - public IntPtr blendStates; - public uint blendStateCount; - public fixed float blendConstants[4]; - } - - [StructLayout(LayoutKind.Sequential)] - public struct ComputePipelineCreateInfo - { - public ShaderStageState computeShaderState; - public ComputePipelineLayoutCreateInfo pipelineLayoutCreateInfo; - } - - [StructLayout(LayoutKind.Sequential)] - public struct GraphicsPipelineCreateInfo - { - public ShaderStageState vertexShaderState; - public ShaderStageState fragmentShaderState; - public VertexInputState vertexInputState; - public PrimitiveType primitiveType; - public ViewportState viewportState; - public RasterizerState rasterizerState; - public MultisampleState multisampleState; - public DepthStencilState depthStencilState; - public ColorBlendState colorBlendState; - public GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo; - public IntPtr renderPass; - } - - [StructLayout(LayoutKind.Sequential)] - public struct FramebufferCreateInfo - { - public IntPtr renderPass; - public IntPtr pColorTargets; - public uint colorTargetCount; - public IntPtr depthStencilTarget; - public uint width; - public uint height; - } - - /* Logging */ - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void Refresh_LogFunc(IntPtr msg); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_HookLogFunctions( - Refresh_LogFunc info, - Refresh_LogFunc warn, - Refresh_LogFunc error - ); - - /* Init/Quit */ - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateDevice( - in PresentationParameters presentationParameters, - byte debugMode - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_DestroyDevice(IntPtr device); - - /* Drawing */ - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_Clear( - IntPtr device, - IntPtr commandBuffer, - in Rect clearRect, - Refresh.ClearOptionsFlags clearOptions, - IntPtr colors, - uint colorCount, - DepthStencilValue depthStencilValue - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_DrawInstancedPrimitives( - IntPtr device, - IntPtr commandBuffer, - uint baseVertex, - uint startIndex, - uint primitiveCount, - uint instanceCount, - uint vertexParamOffset, - uint fragmentParamOffset - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_DrawIndexedPrimitives( - IntPtr device, - IntPtr commandBuffer, - uint baseVertex, - uint startIndex, - uint primitiveCount, - uint vertexParamOffset, - uint fragmentParamOffset - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_DrawPrimitives( - IntPtr device, - IntPtr commandBuffer, - uint vertexStart, - uint primitiveCount, - uint vertexParamOffset, - uint fragmentParamOffset - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_DispatchCompute( - IntPtr device, - IntPtr commandBuffer, - uint groupCountX, - uint groupCountY, - uint groupCountZ, - uint computeParamOffset - ); - - /* Creates */ - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateRenderPass( - IntPtr device, - in RenderPassCreateInfo renderPassCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateComputePipeline( - IntPtr device, - in ComputePipelineCreateInfo computePipelineCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateGraphicsPipeline( - IntPtr device, - in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateSampler( - IntPtr device, - in SamplerStateCreateInfo samplerStateCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateFramebuffer( - IntPtr device, - in FramebufferCreateInfo framebufferCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateShaderModule( - IntPtr device, - in ShaderModuleCreateInfo shaderModuleCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateTexture( - IntPtr device, - in TextureCreateInfo textureCreateInfo - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateRenderTarget( - IntPtr device, - in TextureSlice textureSlice, - SampleCount multisampleCount - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_CreateBuffer( - IntPtr device, - BufferUsageFlags usageFlags, - uint sizeInBytes - ); - - /* Setters */ - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_SetTextureData( - IntPtr device, - IntPtr commandBuffer, - in TextureSlice textureSlice, - IntPtr data, - uint dataLengthInBytes - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_SetTextureDataYUV( - IntPtr device, - IntPtr commandBuffer, - IntPtr y, - IntPtr u, - IntPtr v, - uint yWidth, - uint yHeight, - uint uvWidth, - uint uvHeight, - IntPtr data, - uint dataLength - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_CopyTextureToTexture( - IntPtr device, - IntPtr commandBuffer, - in TextureSlice sourceTextureSlice, - in TextureSlice destinationTextureSlice, - Filter filter - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_CopyTextureToBuffer( - IntPtr device, - IntPtr commandBuffer, - in TextureSlice textureSlice, - IntPtr buffer - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_GetBufferData( - IntPtr device, - IntPtr buffer, - IntPtr data, - uint dataLengthInBytes - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_SetBufferData( - IntPtr device, - IntPtr commandBuffer, - IntPtr buffer, - uint offsetInBytes, - IntPtr data, - uint dataLengthInBytes - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint Refresh_PushVertexShaderUniforms( - IntPtr device, - IntPtr commandBuffer, - IntPtr data, - uint dataLengthInBytes - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint Refresh_PushFragmentShaderUniforms( - IntPtr device, - IntPtr commandBuffer, - IntPtr data, - uint dataLengthInBytes - ); - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint Refresh_PushComputeShaderUniforms( - IntPtr device, - IntPtr commandBuffer, - IntPtr data, - uint dataLengthInBytes - ); - - /* Disposal */ - - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyTexture( - IntPtr device, + public static class Refresh + { + private const string nativeLibName = "Refresh"; + + /* Enums */ + + public enum PresentMode + { + Immediate, + Mailbox, + FIFO, + FIFORelaxed + } + + public enum PrimitiveType + { + PointList, + LineList, + LineStrip, + TriangleList, + TriangleStrip + } + + public enum LoadOp + { + Load, + Clear, + DontCare + } + + public enum StoreOp + { + Store, + DontCare + } + + [Flags] + public enum ClearOptionsFlags : uint + { + Color = 1, + Depth = 2, + Stencil = 4, + DepthStencil = Depth | Stencil, + All = Color | Depth | Stencil + } + + public enum IndexElementSize + { + Sixteen, + ThirtyTwo + } + + public enum TextureFormat + { + R8G8B8A8, + R5G6B5, + A1R5G5B5, + B4G4R4A4, + BC1, + BC2, + BC3, + R8G8_SNORM, + R8G8B8A8_SNORM, + A2R10G10B10, + R16G16, + R16G16B16A16, + R8, + R32_SFLOAT, + R32G32_SFLOAT, + R32G32B32A32_SFLOAT, + R16_SFLOAT, + R16G16_SFLOAT, + R16G16B16A16_SFLOAT, + D16, + D32, + D16S8, + D32S8 + } + + [Flags] + public enum TextureUsageFlags : uint + { + Sampler = 1, + ColorTarget = 2, + DepthStencilTarget = 4 + } + + public enum SampleCount + { + One, + Two, + Four, + Eight, + Sixteen, + ThirtyTwo, + SixtyFour + } + + public enum CubeMapFace : uint + { + PositiveX, + NegativeX, + PositiveY, + NegativeY, + PositiveZ, + NegativeZ + } + + [Flags] + public enum BufferUsageFlags : uint + { + Vertex = 1, + Index = 2, + Compute = 4 + } + + public enum VertexElementFormat + { + Single, + Vector2, + Vector3, + Vector4, + Color, + Byte4, + Short2, + Short4, + NormalizedShort2, + NormalizedShort4, + HalfVector2, + HalfVector4 + } + + public enum VertexInputRate + { + Vertex, + Instance + } + + public enum FillMode + { + Fill, + Line, + Point + } + + public enum CullMode + { + None, + Front, + Back, + FrontAndBack + } + + public enum FrontFace + { + CounterClockwise, + Clockwise + } + + public enum CompareOp + { + Never, + Less, + Equal, + LessOrEqual, + Greater, + NotEqual, + GreaterOrEqual, + Always + } + + public enum StencilOp + { + Keep, + Zero, + Replace, + IncrementAndClamp, + DecrementAndClamp, + Invert, + IncrementAndWrap, + DecrementAndWrap + } + + public enum BlendOp + { + Add, + Subtract, + ReverseSubtract, + Min, + Max + } + + public enum LogicOp + { + Clear, + And, + AndReverse, + Copy, + AndInverted, + NoOp, + Xor, + Or, + Nor, + Equivalent, + Invert, + OrReverse, + CopyInverted, + OrInverted, + Nand, + Set + } + + public enum BlendFactor + { + Zero, + One, + SourceColor, + OneMinusSourceColor, + DestinationColor, + OneMinusDestinationColor, + SourceAlpha, + OneMinusSourceAlpha, + DestinationAlpha, + OneMinusDestinationAlpha, + ConstantColor, + OneMinusConstantColor, + ConstantAlpha, + OneMinusConstantAlpha, + SourceAlphaSaturate, + SourceOneColor, + OneMinusSourceOneColor, + SourceOneAlpha, + OneMinusSourceOneAlpha + } + + [Flags] + public enum ColorComponentFlags : uint + { + R = 1, + G = 2, + B = 4, + A = 8, + + RG = R | G, + RB = R | B, + RA = R | A, + GB = G | B, + GA = G | A, + BA = B | A, + + RGB = R | G | B, + RGA = R | G | A, + GBA = G | B | A, + + RGBA = R | G | B | A + } + + public enum ShaderStageType + { + Vertex, + Fragment + } + + public enum Filter + { + Nearest, + Linear, + Cubic + } + + public enum SamplerMipmapMode + { + Nearest, + Linear + } + + public enum SamplerAddressMode + { + Repeat, + MirroredRepeat, + ClampToEdge, + ClampToBorder + } + + public enum BorderColor + { + FloatTransparentBlack, + IntTransparentBlack, + FloatOpaqueBlack, + IntOpaqueBlack, + FloatOpaqueWhite, + IntOpaqueWhite + } + + /* Native Structures */ + + [StructLayout(LayoutKind.Sequential)] + public struct DepthStencilValue + { + public float depth; + public uint stencil; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Rect + { + public int x; + public int y; + public int w; + public int h; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Vec4 + { + public float x; + public float y; + public float z; + public float w; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Viewport + { + public float x; + public float y; + public float w; + public float h; + public float minDepth; + public float maxDepth; + } + + [StructLayout(LayoutKind.Sequential)] + public struct TextureSlice + { + public IntPtr texture; + public Rect rectangle; + public uint depth; + public uint layer; + public uint level; + } + + [StructLayout(LayoutKind.Sequential)] + public struct PresentationParameters + { + public IntPtr deviceWindowHandle; + public PresentMode presentMode; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SamplerStateCreateInfo + { + public Filter minFilter; + public Filter magFilter; + public SamplerMipmapMode mipmapMode; + public SamplerAddressMode addressModeU; + public SamplerAddressMode addressModeV; + public SamplerAddressMode addressModeW; + public float mipLodBias; + public byte anisotropyEnable; + public float maxAnisotropy; + public byte compareEnable; + public CompareOp compareOp; + public float minLod; + public float maxLod; + public BorderColor borderColor; + } + + [StructLayout(LayoutKind.Sequential)] + public struct VertexBinding + { + public uint binding; + public uint stride; + public VertexInputRate inputRate; + } + + [StructLayout(LayoutKind.Sequential)] + public struct VertexAttribute + { + public uint location; + public uint binding; + public VertexElementFormat format; + public uint offset; + } + + [StructLayout(LayoutKind.Sequential)] + public struct VertexInputState + { + public IntPtr vertexBindings; + public uint vertexBindingCount; + public IntPtr vertexAttributes; + public uint vertexAttributeCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct StencilOpState + { + public StencilOp failOp; + public StencilOp passOp; + public StencilOp depthFailOp; + public CompareOp compareOp; + public uint compareMask; + public uint writeMask; + public uint reference; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ColorTargetBlendState + { + public byte blendEnable; + public BlendFactor sourceColorBlendFactor; + public BlendFactor destinationColorBlendFactor; + public BlendOp colorBlendOp; + public BlendFactor sourceAlphaBlendFactor; + public BlendFactor destinationAlphaBlendFactor; + public BlendOp alphaBlendOp; + public ColorComponentFlags colorWriteMask; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ComputePipelineLayoutCreateInfo + { + public uint bufferBindingCount; + public uint imageBindingCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct GraphicsPipelineLayoutCreateInfo + { + public uint vertexSamplerBindingCount; + public uint fragmentSamplerBindingCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ShaderModuleCreateInfo + { + public UIntPtr codeSize; /* size_t */ + public IntPtr byteCode; + } + + [StructLayout(LayoutKind.Sequential)] + public struct TextureCreateInfo + { + public uint width; + public uint height; + public uint depth; + public byte isCube; + public SampleCount sampleCount; + public uint levelCount; + public TextureFormat format; + public TextureUsageFlags usageFlags; /* Refresh_TextureUsageFlags */ + } + + [StructLayout(LayoutKind.Sequential)] + public struct ShaderStageState + { + public IntPtr shaderModule; + [MarshalAs(UnmanagedType.LPStr)] + public string entryPointName; + public ulong uniformBufferSize; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ViewportState + { + public IntPtr viewports; + public uint viewportCount; + public IntPtr scissors; + public uint scissorCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct RasterizerState + { + public byte depthClampEnable; + public FillMode fillMode; + public CullMode cullMode; + public FrontFace frontFace; + public byte depthBiasEnable; + public float depthBiasConstantFactor; + public float depthBiasClamp; + public float depthBiasSlopeFactor; + public float lineWidth; + } + + [StructLayout(LayoutKind.Sequential)] + public struct MultisampleState + { + public SampleCount multisampleCount; + public uint sampleMask; + } + + [StructLayout(LayoutKind.Sequential)] + public struct DepthStencilState + { + public byte depthTestEnable; + public byte depthWriteEnable; + public CompareOp compareOp; + public byte depthBoundsTestEnable; + public byte stencilTestEnable; + public StencilOpState frontStencilState; + public StencilOpState backStencilState; + public float minDepthBounds; + public float maxDepthBounds; + } + + [StructLayout(LayoutKind.Sequential)] + public unsafe struct ColorBlendState + { + public byte logicOpEnable; + public LogicOp logicOp; + public IntPtr blendStates; + public uint blendStateCount; + public fixed float blendConstants[4]; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ComputePipelineCreateInfo + { + public ShaderStageState computeShaderState; + public ComputePipelineLayoutCreateInfo pipelineLayoutCreateInfo; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ColorAttachmentDescription + { + public TextureFormat format; + public SampleCount sampleCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct GraphicsPipelineAttachmentInfo + { + public IntPtr colorAttachmentDescriptions; /* Max size 4 */ + public uint colorAttachmentCount; + public byte hasDepthStencilAttachment; + public TextureFormat depthStencilFormat; + } + + [StructLayout(LayoutKind.Sequential)] + public struct GraphicsPipelineCreateInfo + { + public ShaderStageState vertexShaderState; + public ShaderStageState fragmentShaderState; + public VertexInputState vertexInputState; + public PrimitiveType primitiveType; + public ViewportState viewportState; + public RasterizerState rasterizerState; + public MultisampleState multisampleState; + public DepthStencilState depthStencilState; + public ColorBlendState colorBlendState; + public GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo; + public GraphicsPipelineAttachmentInfo attachmentInfo; + } + + public struct ColorAttachmentInfo + { + public IntPtr renderTarget; + public Vec4 clearColor; + public LoadOp loadOp; + public StoreOp storeOp; + } + + public struct DepthStencilAttachmentInfo + { + public IntPtr depthStencilTarget; + public DepthStencilValue depthStencilValue; + public LoadOp loadOp; + public StoreOp storeOp; + public LoadOp stencilLoadOp; + public StoreOp stencilStoreOp; + } + + /* Logging */ + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void Refresh_LogFunc(IntPtr msg); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_HookLogFunctions( + Refresh_LogFunc info, + Refresh_LogFunc warn, + Refresh_LogFunc error + ); + + /* Init/Quit */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateDevice( + in PresentationParameters presentationParameters, + byte debugMode + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_DestroyDevice(IntPtr device); + + /* Drawing */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_Clear( + IntPtr device, IntPtr commandBuffer, - IntPtr texture - ); + in Rect clearRect, + Refresh.ClearOptionsFlags clearOptions, + IntPtr colors, + uint colorCount, + DepthStencilValue depthStencilValue + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroySampler( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_DrawInstancedPrimitives( + IntPtr device, IntPtr commandBuffer, - IntPtr sampler - ); + uint baseVertex, + uint startIndex, + uint primitiveCount, + uint instanceCount, + uint vertexParamOffset, + uint fragmentParamOffset + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyBuffer( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_DrawIndexedPrimitives( + IntPtr device, IntPtr commandBuffer, - IntPtr buffer - ); + uint baseVertex, + uint startIndex, + uint primitiveCount, + uint vertexParamOffset, + uint fragmentParamOffset + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyRenderTarget( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_DrawPrimitives( + IntPtr device, IntPtr commandBuffer, - IntPtr renderTarget - ); + uint vertexStart, + uint primitiveCount, + uint vertexParamOffset, + uint fragmentParamOffset + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyFramebuffer( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_DispatchCompute( + IntPtr device, IntPtr commandBuffer, - IntPtr framebuffer - ); + uint groupCountX, + uint groupCountY, + uint groupCountZ, + uint computeParamOffset + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyShaderModule( - IntPtr device, + /* Creates */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateComputePipeline( + IntPtr device, + in ComputePipelineCreateInfo computePipelineCreateInfo + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateGraphicsPipeline( + IntPtr device, + in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateSampler( + IntPtr device, + in SamplerStateCreateInfo samplerStateCreateInfo + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateShaderModule( + IntPtr device, + in ShaderModuleCreateInfo shaderModuleCreateInfo + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateTexture( + IntPtr device, + in TextureCreateInfo textureCreateInfo + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateRenderTarget( + IntPtr device, + in TextureSlice textureSlice, + SampleCount multisampleCount + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_CreateBuffer( + IntPtr device, + BufferUsageFlags usageFlags, + uint sizeInBytes + ); + + /* Setters */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_SetTextureData( + IntPtr device, IntPtr commandBuffer, - IntPtr shaderModule - ); + in TextureSlice textureSlice, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyRenderPass( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_SetTextureDataYUV( + IntPtr device, IntPtr commandBuffer, - IntPtr renderPass - ); + IntPtr y, + IntPtr u, + IntPtr v, + uint yWidth, + uint yHeight, + uint uvWidth, + uint uvHeight, + IntPtr data, + uint dataLength + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyComputePipeline( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_CopyTextureToTexture( + IntPtr device, IntPtr commandBuffer, - IntPtr computePipeline - ); + in TextureSlice sourceTextureSlice, + in TextureSlice destinationTextureSlice, + Filter filter + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueueDestroyGraphicsPipeline( - IntPtr device, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_CopyTextureToBuffer( + IntPtr device, IntPtr commandBuffer, - IntPtr graphicsPipeline - ); + in TextureSlice textureSlice, + IntPtr buffer + ); - /* Graphics State */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_GetBufferData( + IntPtr device, + IntPtr buffer, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BeginRenderPass( - IntPtr device, - IntPtr commandBuffer, - IntPtr renderPass, - IntPtr framebuffer, - in Rect renderArea, - IntPtr pColorClearValues, - uint colorClearCount, - in DepthStencilValue depthStencilClearValue - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_SetBufferData( + IntPtr device, + IntPtr commandBuffer, + IntPtr buffer, + uint offsetInBytes, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BeginRenderPass( - IntPtr device, - IntPtr commandBuffer, - IntPtr renderPass, - IntPtr framebuffer, - in Rect renderArea, - IntPtr pColorClearValues, - uint colorClearCount, - IntPtr depthStencilClearValue /* NULL */ - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint Refresh_PushVertexShaderUniforms( + IntPtr device, + IntPtr commandBuffer, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_EndRenderPass( - IntPtr device, - IntPtr commandBuffer - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint Refresh_PushFragmentShaderUniforms( + IntPtr device, + IntPtr commandBuffer, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindGraphicsPipeline( - IntPtr device, - IntPtr commandBuffer, - IntPtr graphicsPipeline - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern uint Refresh_PushComputeShaderUniforms( + IntPtr device, + IntPtr commandBuffer, + IntPtr data, + uint dataLengthInBytes + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindVertexBuffers( - IntPtr device, - IntPtr commandBuffer, - uint firstBinding, - uint bindingCount, - IntPtr pBuffers, - IntPtr pOffsets - ); + /* Disposal */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindIndexBuffer( - IntPtr device, - IntPtr commandBuffer, - IntPtr buffer, - uint offset, - IndexElementSize indexElementSize - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyTexture( + IntPtr device, + IntPtr commandBuffer, + IntPtr texture + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindVertexSamplers( - IntPtr device, - IntPtr commandBuffer, - IntPtr pTextures, - IntPtr pSamplers - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroySampler( + IntPtr device, + IntPtr commandBuffer, + IntPtr sampler + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindFragmentSamplers( - IntPtr device, - IntPtr commandBuffer, - IntPtr pTextures, - IntPtr pSamplers - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyBuffer( + IntPtr device, + IntPtr commandBuffer, + IntPtr buffer + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindComputePipeline( - IntPtr device, - IntPtr commandBuffer, - IntPtr computePipeline - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyRenderTarget( + IntPtr device, + IntPtr commandBuffer, + IntPtr renderTarget + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindComputeBuffers( - IntPtr device, - IntPtr commandBuffer, - IntPtr pBuffers - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyShaderModule( + IntPtr device, + IntPtr commandBuffer, + IntPtr shaderModule + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_BindComputeTextures( - IntPtr device, - IntPtr commandBuffer, - IntPtr pTextures - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyComputePipeline( + IntPtr device, + IntPtr commandBuffer, + IntPtr computePipeline + ); - /* Submission/Presentation */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueueDestroyGraphicsPipeline( + IntPtr device, + IntPtr commandBuffer, + IntPtr graphicsPipeline + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_AcquireCommandBuffer( - IntPtr device, - byte isFixed - ); + /* Graphics State */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueuePresent( - IntPtr device, - IntPtr commandBuffer, - in TextureSlice textureSlice, - in Rect destinationRectangle, - Filter filter, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BeginRenderPass( + IntPtr device, + IntPtr commandBuffer, + in Rect renderArea, + IntPtr colorAttachmentInfos, + uint colorAttachmentCount, + IntPtr depthStencilAttachmentInfo /* can be NULL */ + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static unsafe extern void Refresh_BeginRenderPass( + IntPtr device, + IntPtr commandBuffer, + in Rect renderArea, + ColorAttachmentInfo* colorAttachmentInfos, + uint colorAttachmentCount, + DepthStencilAttachmentInfo* depthStencilAttachmentInfo /* can be NULL */ + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_EndRenderPass( + IntPtr device, + IntPtr commandBuffer + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindGraphicsPipeline( + IntPtr device, + IntPtr commandBuffer, + IntPtr graphicsPipeline + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindVertexBuffers( + IntPtr device, + IntPtr commandBuffer, + uint firstBinding, + uint bindingCount, + IntPtr pBuffers, + IntPtr pOffsets + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindIndexBuffer( + IntPtr device, + IntPtr commandBuffer, + IntPtr buffer, + uint offset, + IndexElementSize indexElementSize + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindVertexSamplers( + IntPtr device, + IntPtr commandBuffer, + IntPtr pTextures, + IntPtr pSamplers + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindFragmentSamplers( + IntPtr device, + IntPtr commandBuffer, + IntPtr pTextures, + IntPtr pSamplers + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindComputePipeline( + IntPtr device, + IntPtr commandBuffer, + IntPtr computePipeline + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindComputeBuffers( + IntPtr device, + IntPtr commandBuffer, + IntPtr pBuffers + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_BindComputeTextures( + IntPtr device, + IntPtr commandBuffer, + IntPtr pTextures + ); + + /* Submission/Presentation */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_AcquireCommandBuffer( + IntPtr device, + byte isFixed + ); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueuePresent( + IntPtr device, + IntPtr commandBuffer, + in TextureSlice textureSlice, + in Rect destinationRectangle, + Filter filter, IntPtr windowHandle - ); + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_QueuePresent( - IntPtr device, - IntPtr commandBuffer, - in TextureSlice textureSlice, - IntPtr destinationRectangle, /* null Rect */ - Filter filter, + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_QueuePresent( + IntPtr device, + IntPtr commandBuffer, + in TextureSlice textureSlice, + IntPtr destinationRectangle, /* null Rect */ + Filter filter, IntPtr windowHandle - ); + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_Submit( - IntPtr device, - uint commandBufferCount, - IntPtr pCommandBuffers - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_Submit( + IntPtr device, + uint commandBufferCount, + IntPtr pCommandBuffers + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_Wait( - IntPtr device - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_Wait( + IntPtr device + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Refresh_Image_Load( - [MarshalAs(UnmanagedType.LPStr)] string filename, - out int width, - out int height, - out int numChannels - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr Refresh_Image_Load( + [MarshalAs(UnmanagedType.LPStr)] string filename, + out int width, + out int height, + out int numChannels + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_Image_Free( - IntPtr mem - ); + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_Image_Free( + IntPtr mem + ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void Refresh_Image_SavePNG( - [MarshalAs(UnmanagedType.LPStr)] string filename, - int w, - int h, - IntPtr data - ); - } + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void Refresh_Image_SavePNG( + [MarshalAs(UnmanagedType.LPStr)] string filename, + int w, + int h, + IntPtr data + ); + } }