reverting to CreateInfo pattern for consistency

main
cosmonaut 2021-01-28 13:50:20 -08:00
parent 9b06225d7d
commit addea0f810
6 changed files with 111 additions and 78 deletions

View File

@ -14,90 +14,106 @@ namespace MoonWorks.Graphics
public unsafe GraphicsPipeline( public unsafe GraphicsPipeline(
GraphicsDevice device, GraphicsDevice device,
ColorBlendState colorBlendState, GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
DepthStencilState depthStencilState,
ShaderStageState vertexShaderState,
ShaderStageState fragmentShaderState,
MultisampleState multisampleState,
GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo,
RasterizerState rasterizerState,
PrimitiveType primitiveType,
VertexInputState vertexInputState,
ViewportState viewportState,
RenderPass renderPass
) : base(device) ) : base(device)
{ {
var vertexAttributesHandle = GCHandle.Alloc(vertexInputState.VertexAttributes, GCHandleType.Pinned); ColorBlendState colorBlendState = graphicsPipelineCreateInfo.ColorBlendState;
var vertexBindingsHandle = GCHandle.Alloc(vertexInputState.VertexBindings, GCHandleType.Pinned); DepthStencilState depthStencilState = graphicsPipelineCreateInfo.DepthStencilState;
var viewportHandle = GCHandle.Alloc(viewportState.Viewports, GCHandleType.Pinned); ShaderStageState vertexShaderState = graphicsPipelineCreateInfo.VertexShaderState;
var scissorHandle = GCHandle.Alloc(viewportState.Scissors, GCHandleType.Pinned); ShaderStageState fragmentShaderState = graphicsPipelineCreateInfo.FragmentShaderState;
MultisampleState multisampleState = graphicsPipelineCreateInfo.MultisampleState;
GraphicsPipelineLayoutInfo pipelineLayoutInfo = graphicsPipelineCreateInfo.PipelineLayoutInfo;
RasterizerState rasterizerState = graphicsPipelineCreateInfo.RasterizerState;
PrimitiveType primitiveType = graphicsPipelineCreateInfo.PrimitiveType;
VertexInputState vertexInputState = graphicsPipelineCreateInfo.VertexInputState;
ViewportState viewportState = graphicsPipelineCreateInfo.ViewportState;
RenderPass renderPass = graphicsPipelineCreateInfo.RenderPass;
var colorTargetBlendStates = stackalloc Refresh.ColorTargetBlendState[colorBlendState.ColorTargetBlendStates.Length]; var vertexAttributesHandle = GCHandle.Alloc(
vertexInputState.VertexAttributes,
GCHandleType.Pinned
);
var vertexBindingsHandle = GCHandle.Alloc(
vertexInputState.VertexBindings,
GCHandleType.Pinned
);
var viewportHandle = GCHandle.Alloc(
viewportState.Viewports,
GCHandleType.Pinned
);
var scissorHandle = GCHandle.Alloc(
viewportState.Scissors,
GCHandleType.Pinned
);
var colorTargetBlendStates = stackalloc Refresh.ColorTargetBlendState[
colorBlendState.ColorTargetBlendStates.Length
];
for (var i = 0; i < colorBlendState.ColorTargetBlendStates.Length; i += 1) for (var i = 0; i < colorBlendState.ColorTargetBlendStates.Length; i += 1)
{ {
colorTargetBlendStates[i] = colorBlendState.ColorTargetBlendStates[i].ToRefreshColorTargetBlendState(); colorTargetBlendStates[i] = colorBlendState.ColorTargetBlendStates[i].ToRefreshColorTargetBlendState();
} }
Refresh.GraphicsPipelineCreateInfo graphicsPipelineCreateInfo; Refresh.GraphicsPipelineCreateInfo refreshGraphicsPipelineCreateInfo;
graphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable); refreshGraphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable);
graphicsPipelineCreateInfo.colorBlendState.logicOp = (Refresh.LogicOp) colorBlendState.LogicOp; refreshGraphicsPipelineCreateInfo.colorBlendState.logicOp = (Refresh.LogicOp) colorBlendState.LogicOp;
graphicsPipelineCreateInfo.colorBlendState.blendStates = (IntPtr) colorTargetBlendStates; refreshGraphicsPipelineCreateInfo.colorBlendState.blendStates = (IntPtr) colorTargetBlendStates;
graphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length; refreshGraphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R; refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G; refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B; refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A; refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A;
graphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh(); refreshGraphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh();
graphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp; refreshGraphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp;
graphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable); refreshGraphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable);
graphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable); refreshGraphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable);
graphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable); refreshGraphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable);
graphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh(); refreshGraphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh();
graphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds; refreshGraphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds;
graphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds; refreshGraphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds;
graphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable); refreshGraphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable);
graphicsPipelineCreateInfo.vertexShaderState.entryPointName = vertexShaderState.EntryPointName; refreshGraphicsPipelineCreateInfo.vertexShaderState.entryPointName = vertexShaderState.EntryPointName;
graphicsPipelineCreateInfo.vertexShaderState.shaderModule = vertexShaderState.ShaderModule.Handle; refreshGraphicsPipelineCreateInfo.vertexShaderState.shaderModule = vertexShaderState.ShaderModule.Handle;
graphicsPipelineCreateInfo.vertexShaderState.uniformBufferSize = vertexShaderState.UniformBufferSize; refreshGraphicsPipelineCreateInfo.vertexShaderState.uniformBufferSize = vertexShaderState.UniformBufferSize;
graphicsPipelineCreateInfo.fragmentShaderState.entryPointName = fragmentShaderState.EntryPointName; refreshGraphicsPipelineCreateInfo.fragmentShaderState.entryPointName = fragmentShaderState.EntryPointName;
graphicsPipelineCreateInfo.fragmentShaderState.shaderModule = fragmentShaderState.ShaderModule.Handle; refreshGraphicsPipelineCreateInfo.fragmentShaderState.shaderModule = fragmentShaderState.ShaderModule.Handle;
graphicsPipelineCreateInfo.fragmentShaderState.uniformBufferSize = fragmentShaderState.UniformBufferSize; refreshGraphicsPipelineCreateInfo.fragmentShaderState.uniformBufferSize = fragmentShaderState.UniformBufferSize;
graphicsPipelineCreateInfo.multisampleState.multisampleCount = (Refresh.SampleCount)multisampleState.MultisampleCount; refreshGraphicsPipelineCreateInfo.multisampleState.multisampleCount = (Refresh.SampleCount)multisampleState.MultisampleCount;
graphicsPipelineCreateInfo.multisampleState.sampleMask = multisampleState.SampleMask; refreshGraphicsPipelineCreateInfo.multisampleState.sampleMask = multisampleState.SampleMask;
graphicsPipelineCreateInfo.pipelineLayoutCreateInfo.vertexSamplerBindingCount = pipelineLayoutCreateInfo.VertexSamplerBindingCount; refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.vertexSamplerBindingCount = pipelineLayoutInfo.VertexSamplerBindingCount;
graphicsPipelineCreateInfo.pipelineLayoutCreateInfo.fragmentSamplerBindingCount = pipelineLayoutCreateInfo.FragmentSamplerBindingCount; refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.fragmentSamplerBindingCount = pipelineLayoutInfo.FragmentSamplerBindingCount;
graphicsPipelineCreateInfo.rasterizerState.cullMode = (Refresh.CullMode)rasterizerState.CullMode; refreshGraphicsPipelineCreateInfo.rasterizerState.cullMode = (Refresh.CullMode)rasterizerState.CullMode;
graphicsPipelineCreateInfo.rasterizerState.depthBiasClamp = rasterizerState.DepthBiasClamp; refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasClamp = rasterizerState.DepthBiasClamp;
graphicsPipelineCreateInfo.rasterizerState.depthBiasConstantFactor = rasterizerState.DepthBiasConstantFactor; refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasConstantFactor = rasterizerState.DepthBiasConstantFactor;
graphicsPipelineCreateInfo.rasterizerState.depthBiasEnable = Conversions.BoolToByte(rasterizerState.DepthBiasEnable); refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasEnable = Conversions.BoolToByte(rasterizerState.DepthBiasEnable);
graphicsPipelineCreateInfo.rasterizerState.depthBiasSlopeFactor = rasterizerState.DepthBiasSlopeFactor; refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasSlopeFactor = rasterizerState.DepthBiasSlopeFactor;
graphicsPipelineCreateInfo.rasterizerState.depthClampEnable = Conversions.BoolToByte(rasterizerState.DepthClampEnable); refreshGraphicsPipelineCreateInfo.rasterizerState.depthClampEnable = Conversions.BoolToByte(rasterizerState.DepthClampEnable);
graphicsPipelineCreateInfo.rasterizerState.fillMode = (Refresh.FillMode)rasterizerState.FillMode; refreshGraphicsPipelineCreateInfo.rasterizerState.fillMode = (Refresh.FillMode)rasterizerState.FillMode;
graphicsPipelineCreateInfo.rasterizerState.frontFace = (Refresh.FrontFace)rasterizerState.FrontFace; refreshGraphicsPipelineCreateInfo.rasterizerState.frontFace = (Refresh.FrontFace)rasterizerState.FrontFace;
graphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth; refreshGraphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth;
graphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject(); refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length; refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length;
graphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject(); refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length; refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length;
graphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject(); refreshGraphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.viewportState.viewportCount = (uint) viewportState.Viewports.Length; refreshGraphicsPipelineCreateInfo.viewportState.viewportCount = (uint) viewportState.Viewports.Length;
graphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject(); refreshGraphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length; refreshGraphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length;
graphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType; refreshGraphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
graphicsPipelineCreateInfo.renderPass = renderPass.Handle; refreshGraphicsPipelineCreateInfo.renderPass = renderPass.Handle;
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, graphicsPipelineCreateInfo); Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, refreshGraphicsPipelineCreateInfo);
vertexAttributesHandle.Free(); vertexAttributesHandle.Free();
vertexBindingsHandle.Free(); vertexBindingsHandle.Free();

View File

@ -9,12 +9,12 @@ namespace MoonWorks.Graphics
public Sampler( public Sampler(
GraphicsDevice device, GraphicsDevice device,
in SamplerState samplerState in SamplerCreateInfo samplerCreateInfo
) : base(device) ) : base(device)
{ {
Handle = Refresh.Refresh_CreateSampler( Handle = Refresh.Refresh_CreateSampler(
device.Handle, device.Handle,
samplerState.ToRefreshSamplerStateCreateInfo() samplerCreateInfo.ToRefreshSamplerStateCreateInfo()
); );
} }
} }

View File

@ -0,0 +1,17 @@
namespace MoonWorks.Graphics
{
public struct GraphicsPipelineCreateInfo
{
public ColorBlendState ColorBlendState;
public DepthStencilState DepthStencilState;
public ShaderStageState VertexShaderState;
public ShaderStageState FragmentShaderState;
public MultisampleState MultisampleState;
public GraphicsPipelineLayoutInfo PipelineLayoutInfo;
public RasterizerState RasterizerState;
public PrimitiveType PrimitiveType;
public VertexInputState VertexInputState;
public ViewportState ViewportState;
public RenderPass RenderPass;
}
}

View File

@ -1,6 +1,6 @@
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
{ {
public struct GraphicsPipelineLayoutCreateInfo public struct GraphicsPipelineLayoutInfo
{ {
public uint VertexSamplerBindingCount; public uint VertexSamplerBindingCount;
public uint FragmentSamplerBindingCount; public uint FragmentSamplerBindingCount;

View File

@ -2,7 +2,7 @@
namespace MoonWorks.Graphics namespace MoonWorks.Graphics
{ {
public struct SamplerState public struct SamplerCreateInfo
{ {
public Filter MinFilter; public Filter MinFilter;
public Filter MagFilter; public Filter MagFilter;
@ -19,7 +19,7 @@ namespace MoonWorks.Graphics
public float MaxLod; public float MaxLod;
public BorderColor BorderColor; public BorderColor BorderColor;
public static readonly SamplerState AnisotropicClamp = new SamplerState public static readonly SamplerCreateInfo AnisotropicClamp = new SamplerCreateInfo
{ {
MinFilter = Filter.Linear, MinFilter = Filter.Linear,
MagFilter = Filter.Linear, MagFilter = Filter.Linear,
@ -35,7 +35,7 @@ namespace MoonWorks.Graphics
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */ MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
}; };
public static readonly SamplerState AnisotropicWrap = new SamplerState public static readonly SamplerCreateInfo AnisotropicWrap = new SamplerCreateInfo
{ {
MinFilter = Filter.Linear, MinFilter = Filter.Linear,
MagFilter = Filter.Linear, MagFilter = Filter.Linear,
@ -51,7 +51,7 @@ namespace MoonWorks.Graphics
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */ MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
}; };
public static readonly SamplerState LinearClamp = new SamplerState public static readonly SamplerCreateInfo LinearClamp = new SamplerCreateInfo
{ {
MinFilter = Filter.Linear, MinFilter = Filter.Linear,
MagFilter = Filter.Linear, MagFilter = Filter.Linear,
@ -66,7 +66,7 @@ namespace MoonWorks.Graphics
MaxLod = 1000 MaxLod = 1000
}; };
public static readonly SamplerState LinearWrap = new SamplerState public static readonly SamplerCreateInfo LinearWrap = new SamplerCreateInfo
{ {
MinFilter = Filter.Linear, MinFilter = Filter.Linear,
MagFilter = Filter.Linear, MagFilter = Filter.Linear,
@ -81,7 +81,7 @@ namespace MoonWorks.Graphics
MaxLod = 1000 MaxLod = 1000
}; };
public static readonly SamplerState PointClamp = new SamplerState public static readonly SamplerCreateInfo PointClamp = new SamplerCreateInfo
{ {
MinFilter = Filter.Nearest, MinFilter = Filter.Nearest,
MagFilter = Filter.Nearest, MagFilter = Filter.Nearest,
@ -96,7 +96,7 @@ namespace MoonWorks.Graphics
MaxLod = 1000 MaxLod = 1000
}; };
public static readonly SamplerState PointWrap = new SamplerState public static readonly SamplerCreateInfo PointWrap = new SamplerCreateInfo
{ {
MinFilter = Filter.Nearest, MinFilter = Filter.Nearest,
MagFilter = Filter.Nearest, MagFilter = Filter.Nearest,

View File

@ -15,10 +15,10 @@ namespace MoonWorks.Graphics
Texture = texture; Texture = texture;
Rectangle = new Rect Rectangle = new Rect
{ {
x = 0, X = 0,
y = 0, Y = 0,
w = (int) texture.Width, W = (int) texture.Width,
h = (int) texture.Height H = (int) texture.Height
}; };
Depth = 0; Depth = 0;
Layer = 0; Layer = 0;