From b8b10140a95457a00d658e84d4b67b926f467b15 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 24 Feb 2022 21:31:32 -0800 Subject: [PATCH] fix graphics pipeline creation --- src/Graphics/Resources/GraphicsPipeline.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Graphics/Resources/GraphicsPipeline.cs b/src/Graphics/Resources/GraphicsPipeline.cs index 65a3b9a..e293229 100644 --- a/src/Graphics/Resources/GraphicsPipeline.cs +++ b/src/Graphics/Resources/GraphicsPipeline.cs @@ -48,10 +48,6 @@ namespace MoonWorks.Graphics viewportState.Scissors, GCHandleType.Pinned ); - var colorAttachmentDescriptionsHandle = GCHandle.Alloc( - attachmentInfo.colorAttachmentDescriptions, - GCHandleType.Pinned - ); var colorTargetBlendStates = stackalloc Refresh.ColorTargetBlendState[ colorBlendState.ColorTargetBlendStates.Length @@ -62,6 +58,16 @@ namespace MoonWorks.Graphics colorTargetBlendStates[i] = colorBlendState.ColorTargetBlendStates[i].ToRefreshColorTargetBlendState(); } + var colorAttachmentDescriptions = stackalloc Refresh.ColorAttachmentDescription[ + (int) attachmentInfo.colorAttachmentCount + ]; + + for (var i = 0; i < attachmentInfo.colorAttachmentCount; i += 1) + { + colorAttachmentDescriptions[i].format = (Refresh.TextureFormat) attachmentInfo.colorAttachmentDescriptions[i].format; + colorAttachmentDescriptions[i].sampleCount = (Refresh.SampleCount) attachmentInfo.colorAttachmentDescriptions[i].sampleCount; + } + Refresh.GraphicsPipelineCreateInfo refreshGraphicsPipelineCreateInfo; refreshGraphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable); @@ -120,7 +126,7 @@ namespace MoonWorks.Graphics refreshGraphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType; refreshGraphicsPipelineCreateInfo.attachmentInfo.colorAttachmentCount = attachmentInfo.colorAttachmentCount; - refreshGraphicsPipelineCreateInfo.attachmentInfo.colorAttachmentDescriptions = colorAttachmentDescriptionsHandle.AddrOfPinnedObject(); + refreshGraphicsPipelineCreateInfo.attachmentInfo.colorAttachmentDescriptions = (IntPtr) colorAttachmentDescriptions; refreshGraphicsPipelineCreateInfo.attachmentInfo.depthStencilFormat = (Refresh.TextureFormat) attachmentInfo.depthStencilFormat; refreshGraphicsPipelineCreateInfo.attachmentInfo.hasDepthStencilAttachment = Conversions.BoolToByte(attachmentInfo.hasDepthStencilAttachment); @@ -130,7 +136,6 @@ namespace MoonWorks.Graphics vertexBindingsHandle.Free(); viewportHandle.Free(); scissorHandle.Free(); - colorAttachmentDescriptionsHandle.Free(); VertexShaderState = vertexShaderState; FragmentShaderState = fragmentShaderState;