add some missing API functions

main
cosmonaut 2021-01-15 19:08:16 -08:00
parent 799c4a0627
commit add8c8ed40
5 changed files with 256 additions and 5 deletions

@ -1 +1 @@
Subproject commit 2e3871a03d99e413f84748e40bdb6c03df2ecd1c Subproject commit fbed91bfd6f09ae7864193ae620363547382f2fc

View File

@ -37,5 +37,22 @@ namespace Campari
); );
} }
} }
// NOTE: You want to wait on the device before calling this
public unsafe void GetData<T>(
T[] data,
uint dataLengthInBytes
) where T : unmanaged
{
fixed (T* ptr = &data[0])
{
Refresh.Refresh_GetBufferData(
Device.Handle,
Handle,
(IntPtr)ptr,
dataLengthInBytes
);
}
}
} }
} }

View File

@ -62,6 +62,65 @@ namespace Campari
} }
public void BindComputePipeline(
ComputePipeline computePipeline
) {
Refresh.Refresh_BindComputePipeline(
Device.Handle,
Handle,
computePipeline.Handle
);
}
public unsafe uint PushComputeShaderParams<T>(
params T[] uniforms
) where T : unmanaged
{
fixed (T* ptr = &uniforms[0])
{
return Refresh.Refresh_PushComputeShaderParams(
Device.Handle,
Handle,
(IntPtr) ptr,
(uint) uniforms.Length
);
}
}
public unsafe void BindComputeBuffers(
params Buffer[] buffers
) {
var bufferPtrs = stackalloc IntPtr[buffers.Length];
for (var i = 0; i < buffers.Length; i += 1)
{
bufferPtrs[i] = buffers[i].Handle;
}
Refresh.Refresh_BindComputeBuffers(
Device.Handle,
Handle,
(IntPtr) bufferPtrs
);
}
public unsafe void BindComputeTextures(
params Texture[] textures
) {
var texturePtrs = stackalloc IntPtr[textures.Length];
for (var i = 0; i < textures.Length; i += 1)
{
texturePtrs[i] = textures[i].Handle;
}
Refresh.Refresh_BindComputeTextures(
Device.Handle,
Handle,
(IntPtr) texturePtrs
);
}
public void BindGraphicsPipeline( public void BindGraphicsPipeline(
GraphicsPipeline graphicsPipeline GraphicsPipeline graphicsPipeline
) { ) {
@ -142,6 +201,31 @@ namespace Campari
); );
} }
public unsafe void BindVertexSamplers(
Texture[] textures,
Sampler[] samplers
) {
var texturePtrs = stackalloc IntPtr[textures.Length];
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_BindVertexSamplers(
Device.Handle,
Handle,
(IntPtr) texturePtrs,
(IntPtr) samplerPtrs
);
}
public unsafe void BindFragmentSamplers( public unsafe void BindFragmentSamplers(
Texture[] textures, Texture[] textures,
Sampler[] samplers Sampler[] samplers
@ -167,6 +251,63 @@ namespace Campari
); );
} }
public void Clear(
ref Refresh.Rect clearRect,
Refresh.ClearOptionsFlags clearOptions,
ref Refresh.Color[] colors,
float depth,
int stencil
) {
Refresh.Refresh_Clear(
Device.Handle,
Handle,
ref clearRect,
clearOptions,
ref colors,
(uint) colors.Length,
depth,
stencil
);
}
public void DrawInstancedPrimitives(
uint baseVertex,
uint startIndex,
uint primitiveCount,
uint instanceCount,
uint vertexParamOffset,
uint fragmentParamOffset
) {
Refresh.Refresh_DrawInstancedPrimitives(
Device.Handle,
Handle,
baseVertex,
startIndex,
primitiveCount,
instanceCount,
vertexParamOffset,
fragmentParamOffset
);
}
public void DrawIndexedPrimitives(
uint baseVertex,
uint startIndex,
uint primitiveCount,
uint vertexParamOffset,
uint fragmentParamOffset
) {
Refresh.Refresh_DrawIndexedPrimitives(
Device.Handle,
Handle,
baseVertex,
startIndex,
primitiveCount,
vertexParamOffset,
fragmentParamOffset
);
}
public void DrawPrimitives( public void DrawPrimitives(
uint vertexStart, uint vertexStart,
uint primitiveCount, uint primitiveCount,
@ -191,17 +332,66 @@ namespace Campari
); );
} }
public void QueuePresent(ref TextureSlice textureSlice, ref Refresh.Rect rectangle, Refresh.Filter filter) public void QueuePresent(
{ ref TextureSlice textureSlice,
ref Refresh.Rect destinationRectangle,
Refresh.Filter filter
) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice(); var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
Refresh.Refresh_QueuePresent( Refresh.Refresh_QueuePresent(
Device.Handle, Device.Handle,
Handle, Handle,
ref refreshTextureSlice, ref refreshTextureSlice,
ref rectangle, ref destinationRectangle,
filter filter
); );
} }
public void QueuePresent(
ref TextureSlice textureSlice,
Refresh.Filter filter
) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
Refresh.Refresh_QueuePresent(
Device.Handle,
Handle,
ref refreshTextureSlice,
IntPtr.Zero,
filter
);
}
public void CopyTextureToTexture(
ref TextureSlice sourceTextureSlice,
ref TextureSlice destinationTextureSlice,
Refresh.Filter filter
) {
var sourceRefreshTextureSlice = sourceTextureSlice.ToRefreshTextureSlice();
var destRefreshTextureSlice = destinationTextureSlice.ToRefreshTextureSlice();
Refresh.Refresh_CopyTextureToTexture(
Device.Handle,
Handle,
ref sourceRefreshTextureSlice,
ref destRefreshTextureSlice,
filter
);
}
public void CopyTextureToBuffer(
ref TextureSlice textureSlice,
Buffer buffer
) {
var refreshTextureSlice = textureSlice.ToRefreshTextureSlice();
Refresh.Refresh_CopyTextureToBuffer(
Device.Handle,
Handle,
ref refreshTextureSlice,
buffer.Handle
);
}
} }
} }

39
src/ComputePipeline.cs Normal file
View File

@ -0,0 +1,39 @@
using RefreshCS;
using System;
namespace Campari
{
public class ComputePipeline : GraphicsResource
{
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;
public unsafe ComputePipeline(
GraphicsDevice device,
ShaderStageState computeShaderState,
uint bufferBindingCount,
uint imageBindingCount
) : base(device) {
var computePipelineLayoutCreateInfo = new Refresh.ComputePipelineLayoutCreateInfo
{
bufferBindingCount = bufferBindingCount,
imageBindingCount = imageBindingCount
};
var computePipelineCreateInfo = new Refresh.ComputePipelineCreateInfo
{
pipelineLayoutCreateInfo = computePipelineLayoutCreateInfo,
computeShaderState = new Refresh.ShaderStageState
{
entryPointName = computeShaderState.EntryPointName,
shaderModule = computeShaderState.ShaderModule.Handle,
uniformBufferSize = computeShaderState.UniformBufferSize
}
};
Handle = Refresh.Refresh_CreateComputePipeline(
device.Handle,
ref computePipelineCreateInfo
);
}
}
}

View File

@ -10,7 +10,7 @@ namespace Campari
public bool IsDisposed { get; private set; } public bool IsDisposed { get; private set; }
private Queue<CommandBuffer> commandBufferPool; private readonly Queue<CommandBuffer> commandBufferPool;
public GraphicsDevice( public GraphicsDevice(
IntPtr deviceWindowHandle, IntPtr deviceWindowHandle,
@ -73,6 +73,11 @@ namespace Campari
} }
} }
public void Wait()
{
Refresh.Refresh_Wait(Handle);
}
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!IsDisposed) if (!IsDisposed)