general fixes

main
cosmonaut 2021-01-14 19:14:56 -08:00
parent f92309c614
commit 798dada35a
11 changed files with 72 additions and 71 deletions

@ -1 +1 @@
Subproject commit 377d53f7a9645758a5702d86fa9059c4d8bd1835 Subproject commit 3379b95e449904b30d66d8bc17e4da83fc60c1be

View File

@ -39,6 +39,29 @@ namespace Campari
clearColorHandle.Free(); clearColorHandle.Free();
} }
public void BeginRenderPass(
RenderPass renderPass,
Framebuffer framebuffer,
ref Refresh.Rect renderArea,
Refresh.Color[] clearColors
) {
var clearColorHandle = GCHandle.Alloc(clearColors, GCHandleType.Pinned);
Refresh.Refresh_BeginRenderPass(
Device.Handle,
Handle,
renderPass.Handle,
framebuffer.Handle,
ref renderArea,
clearColorHandle.AddrOfPinnedObject(),
(uint) clearColors.Length,
IntPtr.Zero
);
clearColorHandle.Free();
}
public void BindGraphicsPipeline( public void BindGraphicsPipeline(
GraphicsPipeline graphicsPipeline GraphicsPipeline graphicsPipeline
) { ) {
@ -50,7 +73,7 @@ namespace Campari
} }
public unsafe uint PushVertexShaderParams<T>( public unsafe uint PushVertexShaderParams<T>(
T[] uniforms params T[] uniforms
) where T : unmanaged ) where T : unmanaged
{ {
fixed (T* ptr = &uniforms[0]) fixed (T* ptr = &uniforms[0])
@ -65,7 +88,7 @@ namespace Campari
} }
public unsafe uint PushFragmentShaderParams<T>( public unsafe uint PushFragmentShaderParams<T>(
T[] uniforms params T[] uniforms
) where T : unmanaged ) where T : unmanaged
{ {
fixed (T* ptr = &uniforms[0]) fixed (T* ptr = &uniforms[0])
@ -79,13 +102,18 @@ namespace Campari
} }
} }
public void BindVertexBuffers( public unsafe void BindVertexBuffers(
uint firstBinding, uint firstBinding,
uint bindingCount, uint bindingCount,
Buffer[] buffers, Buffer[] buffers,
UInt64[] offsets UInt64[] offsets
) { ) {
var bufferHandle = GCHandle.Alloc(buffers, GCHandleType.Pinned); var bufferPtrs = stackalloc IntPtr[buffers.Length];
for (var i = 0; i < buffers.Length; i += 1)
{
bufferPtrs[i] = buffers[i].Handle;
}
var offsetHandle = GCHandle.Alloc(offsets, GCHandleType.Pinned); var offsetHandle = GCHandle.Alloc(offsets, GCHandleType.Pinned);
Refresh.Refresh_BindVertexBuffers( Refresh.Refresh_BindVertexBuffers(
@ -93,11 +121,10 @@ namespace Campari
Handle, Handle,
firstBinding, firstBinding,
bindingCount, bindingCount,
bufferHandle.AddrOfPinnedObject(), (IntPtr) bufferPtrs,
offsetHandle.AddrOfPinnedObject() offsetHandle.AddrOfPinnedObject()
); );
bufferHandle.Free();
offsetHandle.Free(); offsetHandle.Free();
} }
@ -115,22 +142,29 @@ namespace Campari
); );
} }
public void BindFragmentSamplers( public unsafe void BindFragmentSamplers(
Texture[] textures, Texture[] textures,
Sampler[] samplers Sampler[] samplers
) { ) {
var textureHandle = GCHandle.Alloc(textures, GCHandleType.Pinned); var texturePtrs = stackalloc IntPtr[textures.Length];
var samplerHandle = GCHandle.Alloc(samplers, GCHandleType.Pinned); var samplerPtrs = stackalloc IntPtr[samplers.Length];
for (var i = 0; i < textures.Length; i += 1)
{
texturePtrs[i] = textures[i].Handle;
}
for (var i = 0; i < samplers.Length; i += 1)
{
samplerPtrs[i] = samplers[i].Handle;
}
Refresh.Refresh_BindFragmentSamplers( Refresh.Refresh_BindFragmentSamplers(
Device.Handle, Device.Handle,
Handle, Handle,
textureHandle.AddrOfPinnedObject(), (IntPtr) texturePtrs,
samplerHandle.AddrOfPinnedObject() (IntPtr) samplerPtrs
); );
textureHandle.Free();
samplerHandle.Free();
} }
public void DrawPrimitives( public void DrawPrimitives(

View File

@ -12,8 +12,8 @@ namespace Campari
RefreshDevice device, RefreshDevice device,
ColorBlendState colorBlendState, ColorBlendState colorBlendState,
DepthStencilState depthStencilState, DepthStencilState depthStencilState,
ShaderStageState fragmentShaderState,
ShaderStageState vertexShaderState, ShaderStageState vertexShaderState,
ShaderStageState fragmentShaderState,
MultisampleState multisampleState, MultisampleState multisampleState,
GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo, GraphicsPipelineLayoutCreateInfo pipelineLayoutCreateInfo,
RasterizerState rasterizerState, RasterizerState rasterizerState,
@ -34,7 +34,7 @@ namespace Campari
graphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable); graphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable);
graphicsPipelineCreateInfo.colorBlendState.logicOp = colorBlendState.LogicOp; graphicsPipelineCreateInfo.colorBlendState.logicOp = colorBlendState.LogicOp;
graphicsPipelineCreateInfo.colorBlendState.blendStates = blendStateHandle.AddrOfPinnedObject(); graphicsPipelineCreateInfo.colorBlendState.blendStates = blendStateHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.colorBlendState.blendStateCount = colorBlendState.BlendStateCount; graphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R; graphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G; graphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G;
graphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B; graphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B;
@ -75,14 +75,14 @@ namespace Campari
graphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth; graphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth;
graphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject(); graphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = vertexInputState.VertexAttributeCount; graphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length;
graphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject(); graphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = vertexInputState.VertexBindingCount; graphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length;
graphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject(); graphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.viewportState.viewportCount = viewportState.ViewportCount; graphicsPipelineCreateInfo.viewportState.viewportCount = (uint) viewportState.Viewports.Length;
graphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject(); graphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject();
graphicsPipelineCreateInfo.viewportState.scissorCount = viewportState.ScissorCount; graphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length;
graphicsPipelineCreateInfo.primitiveType = primitiveType; graphicsPipelineCreateInfo.primitiveType = primitiveType;
graphicsPipelineCreateInfo.renderPass = renderPass.Handle; graphicsPipelineCreateInfo.renderPass = renderPass.Handle;

View File

@ -18,7 +18,7 @@ namespace Campari
) { ) {
Handle = Refresh.Refresh_CreateDevice( Handle = Refresh.Refresh_CreateDevice(
ref presentationParameters, ref presentationParameters,
(byte) (debugMode ? 1 : 0) Conversions.BoolToByte(debugMode)
); );
} }
@ -29,17 +29,20 @@ namespace Campari
return new CommandBuffer(this, commandBufferHandle); return new CommandBuffer(this, commandBufferHandle);
} }
public void Submit(CommandBuffer[] commandBuffers) public unsafe void Submit(params CommandBuffer[] commandBuffers)
{ {
var commandBufferHandle = GCHandle.Alloc(commandBuffers, GCHandleType.Pinned); var commandBufferPtrs = stackalloc IntPtr[commandBuffers.Length];
for (var i = 0; i < commandBuffers.Length; i += 1)
{
commandBufferPtrs[i] = commandBuffers[i].Handle;
}
Refresh.Refresh_Submit( Refresh.Refresh_Submit(
Handle, Handle,
(uint) commandBuffers.Length, (uint) commandBuffers.Length,
commandBufferHandle.AddrOfPinnedObject() (IntPtr) commandBufferPtrs
); );
commandBufferHandle.Free();
} }
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)

View File

@ -7,7 +7,6 @@ namespace Campari
public bool LogicOpEnable; public bool LogicOpEnable;
public Refresh.LogicOp LogicOp; public Refresh.LogicOp LogicOp;
public BlendConstants BlendConstants; public BlendConstants BlendConstants;
public uint BlendStateCount;
public Refresh.ColorTargetBlendState[] ColorTargetBlendStates; public Refresh.ColorTargetBlendState[] ColorTargetBlendStates;
} }
} }

View File

@ -1,10 +1,10 @@
using RefreshCS;
namespace Campari namespace Campari
{ {
public struct VertexInputState public struct VertexInputState
{ {
public VertexBinding[] VertexBindings; public Refresh.VertexBinding[] VertexBindings;
public uint VertexBindingCount; public Refresh.VertexAttribute[] VertexAttributes;
public VertexAttribute[] VertexAttributes;
public uint VertexAttributeCount;
} }
} }

View File

@ -4,9 +4,7 @@ namespace Campari
{ {
public struct ViewportState public struct ViewportState
{ {
public Viewport[] Viewports; public Refresh.Viewport[] Viewports;
public uint ViewportCount;
public Refresh.Rect[] Scissors; public Refresh.Rect[] Scissors;
public uint ScissorCount;
} }
} }

View File

@ -6,8 +6,8 @@ namespace Campari
{ {
public class Texture : GraphicsResource public class Texture : GraphicsResource
{ {
public uint Height { get; }
public uint Width { get; } public uint Width { get; }
public uint Height { get; }
public Refresh.ColorFormat Format { get; } public Refresh.ColorFormat Format { get; }
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture; protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
@ -47,6 +47,8 @@ namespace Campari
); );
Format = textureCreateInfo.format; Format = textureCreateInfo.format;
Width = textureCreateInfo.width;
Height = textureCreateInfo.height;
} }
public void SetData(IntPtr data, uint dataLengthInBytes) public void SetData(IntPtr data, uint dataLengthInBytes)

View File

@ -1,12 +0,0 @@
using RefreshCS;
namespace Campari
{
public struct VertexAttribute
{
public uint Binding;
public uint Location;
public Refresh.VertexElementFormat Format;
public uint Offset;
}
}

View File

@ -1,11 +0,0 @@
using RefreshCS;
namespace Campari
{
public struct VertexBinding
{
public uint Binding;
public Refresh.VertexInputRate VertexInputRate;
public uint Stride;
}
}

View File

@ -1,12 +0,0 @@
namespace Campari
{
public struct Viewport
{
public float X;
public float Y;
public float W;
public float H;
public float MinDepth;
public float MaxDepth;
}
}