refactor RenderPass structure
parent
4e8653fb1f
commit
eab282cdca
|
@ -1 +1 @@
|
||||||
Subproject commit 2866dd2a7d4ffd4366bd4885e04c68cf4b485b55
|
Subproject commit 60e2c21a7b224dc6aa6a457dbb71d798a4e66241
|
|
@ -8,7 +8,7 @@ public readonly record struct BufferBinding(
|
||||||
GpuBuffer Buffer,
|
GpuBuffer Buffer,
|
||||||
uint Offset
|
uint Offset
|
||||||
) {
|
) {
|
||||||
public SDL_Gpu.BufferBinding ToRefresh()
|
public SDL_Gpu.BufferBinding ToSDL()
|
||||||
{
|
{
|
||||||
return new SDL_Gpu.BufferBinding
|
return new SDL_Gpu.BufferBinding
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -38,8 +38,9 @@ namespace MoonWorks.Graphics
|
||||||
public bool IsDisposed { get; private set; }
|
public bool IsDisposed { get; private set; }
|
||||||
|
|
||||||
private readonly HashSet<GCHandle> resources = new HashSet<GCHandle>();
|
private readonly HashSet<GCHandle> resources = new HashSet<GCHandle>();
|
||||||
private FencePool FencePool;
|
|
||||||
private CommandBufferPool CommandBufferPool;
|
private CommandBufferPool CommandBufferPool;
|
||||||
|
internal RenderPassPool RenderPassPool;
|
||||||
|
private FencePool FencePool;
|
||||||
|
|
||||||
internal unsafe GraphicsDevice(
|
internal unsafe GraphicsDevice(
|
||||||
Span<Backend> preferredBackends,
|
Span<Backend> preferredBackends,
|
||||||
|
@ -149,12 +150,12 @@ namespace MoonWorks.Graphics
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
DepthStencilState = DepthStencilState.Disable,
|
DepthStencilState = DepthStencilState.Disable,
|
||||||
VertexShaderInfo = GraphicsShaderInfo.Create(
|
VertexShaderResourceInfo = GraphicsShaderInfo.Create(
|
||||||
fullscreenVertShader,
|
fullscreenVertShader,
|
||||||
"main",
|
"main",
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
FragmentShaderInfo = GraphicsShaderInfo.Create(
|
FragmentShaderResourceInfo = GraphicsShaderInfo.Create(
|
||||||
videoFragShader,
|
videoFragShader,
|
||||||
"main",
|
"main",
|
||||||
3
|
3
|
||||||
|
@ -177,12 +178,12 @@ namespace MoonWorks.Graphics
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
DepthStencilState = DepthStencilState.Disable,
|
DepthStencilState = DepthStencilState.Disable,
|
||||||
VertexShaderInfo = GraphicsShaderInfo.Create(
|
VertexShaderResourceInfo = GraphicsShaderInfo.Create(
|
||||||
fullscreenVertShader,
|
fullscreenVertShader,
|
||||||
"main",
|
"main",
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
FragmentShaderInfo = GraphicsShaderInfo.Create(
|
FragmentShaderResourceInfo = GraphicsShaderInfo.Create(
|
||||||
blitFragShader,
|
blitFragShader,
|
||||||
"main",
|
"main",
|
||||||
1
|
1
|
||||||
|
|
|
@ -13,16 +13,17 @@ public class RenderPass
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
internal bool active;
|
internal bool active;
|
||||||
|
internal uint colorAttachmentCount;
|
||||||
|
internal SampleCount colorAttachmentSampleCount;
|
||||||
|
internal TextureFormat colorFormatOne;
|
||||||
|
internal TextureFormat colorFormatTwo;
|
||||||
|
internal TextureFormat colorFormatThree;
|
||||||
|
internal TextureFormat colorFormatFour;
|
||||||
|
internal bool hasDepthStencilAttachment;
|
||||||
|
internal SampleCount depthStencilAttachmentSampleCount;
|
||||||
|
internal TextureFormat depthStencilFormat;
|
||||||
|
|
||||||
GraphicsPipeline currentGraphicsPipeline;
|
GraphicsPipeline currentGraphicsPipeline;
|
||||||
uint colorAttachmentCount;
|
|
||||||
SampleCount colorAttachmentSampleCount;
|
|
||||||
TextureFormat colorFormatOne;
|
|
||||||
TextureFormat colorFormatTwo;
|
|
||||||
TextureFormat colorFormatThree;
|
|
||||||
TextureFormat colorFormatFour;
|
|
||||||
bool hasDepthStencilAttachment;
|
|
||||||
SampleCount depthStencilAttachmentSampleCount;
|
|
||||||
TextureFormat depthStencilFormat;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal void SetHandle(nint handle)
|
internal void SetHandle(nint handle)
|
||||||
|
@ -79,7 +80,7 @@ public class RenderPass
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuSetViewport(
|
SDL_Gpu.SDL_GpuSetViewport(
|
||||||
Handle,
|
Handle,
|
||||||
viewport.ToRefresh()
|
viewport.ToSDL()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ public class RenderPass
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuSetScissor(
|
SDL_Gpu.SDL_GpuSetScissor(
|
||||||
Handle,
|
Handle,
|
||||||
scissor.ToRefresh()
|
scissor.ToSDL()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ public class RenderPass
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bufferBinding">Buffer to bind and associated offset.</param>
|
/// <param name="bufferBinding">Buffer to bind and associated offset.</param>
|
||||||
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
||||||
public unsafe void BindVertexBuffers(
|
public unsafe void BindVertexBuffer(
|
||||||
in BufferBinding bufferBinding,
|
in BufferBinding bufferBinding,
|
||||||
uint firstBinding = 0
|
uint firstBinding = 0
|
||||||
) {
|
) {
|
||||||
|
@ -116,137 +117,16 @@ public class RenderPass
|
||||||
AssertGraphicsPipelineBound();
|
AssertGraphicsPipelineBound();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var bindingArray = stackalloc SDL_Gpu.BufferBinding[1];
|
var sdlBufferBinding = bufferBinding.ToSDL();
|
||||||
bindingArray[0] = bufferBinding.ToRefresh();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
||||||
Handle,
|
Handle,
|
||||||
firstBinding,
|
firstBinding,
|
||||||
bindingArray,
|
&sdlBufferBinding,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Binds vertex buffers to be used by subsequent draw calls.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bufferBindingOne">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingTwo">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
|
||||||
public unsafe void BindVertexBuffers(
|
|
||||||
in BufferBinding bufferBindingOne,
|
|
||||||
in BufferBinding bufferBindingTwo,
|
|
||||||
uint firstBinding = 0
|
|
||||||
) {
|
|
||||||
#if DEBUG
|
|
||||||
AssertGraphicsPipelineBound();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var bindingArray = stackalloc SDL_Gpu.BufferBinding[2];
|
|
||||||
bindingArray[0] = bufferBindingOne.ToRefresh();
|
|
||||||
bindingArray[1] = bufferBindingTwo.ToRefresh();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
|
||||||
Handle,
|
|
||||||
firstBinding,
|
|
||||||
bindingArray,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Binds vertex buffers to be used by subsequent draw calls.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bufferBindingOne">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingTwo">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingThree">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
|
||||||
public unsafe void BindVertexBuffers(
|
|
||||||
in BufferBinding bufferBindingOne,
|
|
||||||
in BufferBinding bufferBindingTwo,
|
|
||||||
in BufferBinding bufferBindingThree,
|
|
||||||
uint firstBinding = 0
|
|
||||||
) {
|
|
||||||
#if DEBUG
|
|
||||||
AssertGraphicsPipelineBound();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var bindingArray = stackalloc SDL_Gpu.BufferBinding[3];
|
|
||||||
bindingArray[0] = bufferBindingOne.ToRefresh();
|
|
||||||
bindingArray[1] = bufferBindingTwo.ToRefresh();
|
|
||||||
bindingArray[2] = bufferBindingThree.ToRefresh();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
|
||||||
Handle,
|
|
||||||
firstBinding,
|
|
||||||
bindingArray,
|
|
||||||
3
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Binds vertex buffers to be used by subsequent draw calls.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bufferBindingOne">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingTwo">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingThree">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="bufferBindingFour">Buffer to bind and associated offset.</param>
|
|
||||||
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
|
||||||
public unsafe void BindVertexBuffers(
|
|
||||||
in BufferBinding bufferBindingOne,
|
|
||||||
in BufferBinding bufferBindingTwo,
|
|
||||||
in BufferBinding bufferBindingThree,
|
|
||||||
in BufferBinding bufferBindingFour,
|
|
||||||
uint firstBinding = 0
|
|
||||||
) {
|
|
||||||
#if DEBUG
|
|
||||||
AssertGraphicsPipelineBound();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var bindingArray = stackalloc SDL_Gpu.BufferBinding[4];
|
|
||||||
bindingArray[0] = bufferBindingOne.ToRefresh();
|
|
||||||
bindingArray[1] = bufferBindingTwo.ToRefresh();
|
|
||||||
bindingArray[2] = bufferBindingThree.ToRefresh();
|
|
||||||
bindingArray[3] = bufferBindingFour.ToRefresh();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
|
||||||
Handle,
|
|
||||||
firstBinding,
|
|
||||||
bindingArray,
|
|
||||||
4
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Binds vertex buffers to be used by subsequent draw calls.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bufferBindings">Spawn of buffers to bind and their associated offsets.</param>
|
|
||||||
/// <param name="firstBinding">The index of the first vertex input binding whose state is updated by the command.</param>
|
|
||||||
public unsafe void BindVertexBuffers(
|
|
||||||
in Span<BufferBinding> bufferBindings,
|
|
||||||
uint firstBinding = 0
|
|
||||||
) {
|
|
||||||
#if DEBUG
|
|
||||||
AssertGraphicsPipelineBound();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SDL_Gpu.BufferBinding* bufferBindingsArray = (SDL_Gpu.BufferBinding*) NativeMemory.Alloc((nuint) (Marshal.SizeOf<SDL_Gpu.BufferBinding>() * bufferBindings.Length));
|
|
||||||
|
|
||||||
for (var i = 0; i < bufferBindings.Length; i += 1)
|
|
||||||
{
|
|
||||||
bufferBindingsArray[i] = bufferBindings[i].ToRefresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexBuffers(
|
|
||||||
Handle,
|
|
||||||
firstBinding,
|
|
||||||
bufferBindingsArray,
|
|
||||||
(uint) bufferBindings.Length
|
|
||||||
);
|
|
||||||
|
|
||||||
NativeMemory.Free(bufferBindingsArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Binds an index buffer to be used by subsequent draw calls.
|
/// Binds an index buffer to be used by subsequent draw calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -264,7 +144,7 @@ public class RenderPass
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindIndexBuffer(
|
SDL_Gpu.SDL_GpuBindIndexBuffer(
|
||||||
Handle,
|
Handle,
|
||||||
bufferBinding.ToRefresh(),
|
bufferBinding.ToSDL(),
|
||||||
(SDL_Gpu.IndexElementSize) indexElementSize
|
(SDL_Gpu.IndexElementSize) indexElementSize
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -283,104 +163,280 @@ public class RenderPass
|
||||||
AssertTextureHasSamplerFlag(textureSamplerBinding.Texture);
|
AssertTextureHasSamplerFlag(textureSamplerBinding.Texture);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var bindingArray = stackalloc SDL_Gpu.TextureSamplerBinding[1];
|
var sdlTextureSamplerBinding = textureSamplerBinding.ToSDL();
|
||||||
bindingArray[0] = textureSamplerBinding.ToSDL();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexSamplers(
|
SDL_Gpu.SDL_GpuBindVertexSamplers(
|
||||||
Handle,
|
Handle,
|
||||||
slot,
|
slot,
|
||||||
bindingArray,
|
&sdlTextureSamplerBinding,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void BindVertexSamplers(
|
|
||||||
in Span<TextureSamplerBinding> textureSamplerBindings,
|
|
||||||
uint firstSlot = 0
|
|
||||||
) {
|
|
||||||
#if DEBUG
|
|
||||||
AssertGraphicsPipelineBound();
|
|
||||||
|
|
||||||
for (var i = 0; i < textureSamplerBindings.Length; i += 1)
|
|
||||||
{
|
|
||||||
AssertTextureSamplerBindingNonNull(textureSamplerBindings[i]);
|
|
||||||
AssertTextureHasSamplerFlag(textureSamplerBindings[i].Texture);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SDL_Gpu.TextureSamplerBinding* samplerBindingsArray =
|
|
||||||
(SDL_Gpu.TextureSamplerBinding*) NativeMemory.Alloc(
|
|
||||||
(nuint) (Marshal.SizeOf<SDL_Gpu.TextureSamplerBinding>() * textureSamplerBindings.Length)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (var i = 0; i < textureSamplerBindings.Length; i += 1)
|
|
||||||
{
|
|
||||||
samplerBindingsArray[i] = textureSamplerBindings[i].ToSDL();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexSamplers(
|
|
||||||
Handle,
|
|
||||||
firstSlot,
|
|
||||||
samplerBindingsArray,
|
|
||||||
(uint) textureSamplerBindings.Length
|
|
||||||
);
|
|
||||||
|
|
||||||
NativeMemory.Free(samplerBindingsArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void BindVertexStorageTexture(
|
public unsafe void BindVertexStorageTexture(
|
||||||
in TextureSlice storageTextureSlice,
|
in TextureSlice textureSlice,
|
||||||
uint slot = 0
|
uint slot = 0
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertGraphicsPipelineBound();
|
AssertGraphicsPipelineBound();
|
||||||
AssertTextureNonNull(storageTextureSlice.Texture);
|
AssertTextureNonNull(textureSlice.Texture);
|
||||||
AssertTextureHasGraphicsStorageFlag(storageTextureSlice.Texture);
|
AssertTextureHasGraphicsStorageFlag(textureSlice.Texture);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var sliceArray = stackalloc SDL_Gpu.TextureSlice[1];
|
var sdlTextureSlice = textureSlice.ToSDL();
|
||||||
sliceArray[0] = storageTextureSlice.ToSDL();
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexStorageTextures(
|
SDL_Gpu.SDL_GpuBindVertexStorageTextures(
|
||||||
Handle,
|
Handle,
|
||||||
slot,
|
slot,
|
||||||
sliceArray,
|
&sdlTextureSlice,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void BindVertexStorageTextures(
|
public unsafe void BindVertexStorageBuffer(
|
||||||
in Span<TextureSlice> storageTextureSlices,
|
GpuBuffer buffer,
|
||||||
uint firstSlot = 0
|
uint slot = 0
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
AssertBufferNonNull(buffer);
|
||||||
|
AssertBufferHasGraphicsStorageFlag(buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var bufferHandle = buffer.Handle;
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuBindVertexStorageBuffers(
|
||||||
|
Handle,
|
||||||
|
slot,
|
||||||
|
&bufferHandle,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void BindFragmentSamplers(
|
||||||
|
in TextureSamplerBinding textureSamplerBinding,
|
||||||
|
uint slot = 0
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
AssertTextureSamplerBindingNonNull(textureSamplerBinding);
|
||||||
|
AssertTextureHasSamplerFlag(textureSamplerBinding.Texture);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var sdlTextureSamplerBinding = textureSamplerBinding.ToSDL();
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuBindFragmentSamplers(
|
||||||
|
Handle,
|
||||||
|
slot,
|
||||||
|
&sdlTextureSamplerBinding,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void BindFragmentStorageTexture(
|
||||||
|
in TextureSlice textureSlice,
|
||||||
|
uint slot = 0
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
AssertTextureNonNull(textureSlice.Texture);
|
||||||
|
AssertTextureHasGraphicsStorageFlag(textureSlice.Texture);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var sdlTextureSlice = textureSlice.ToSDL();
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuBindFragmentStorageTextures(
|
||||||
|
Handle,
|
||||||
|
slot,
|
||||||
|
&sdlTextureSlice,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void BindFragmentStorageBuffer(
|
||||||
|
GpuBuffer buffer,
|
||||||
|
uint slot = 0
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
AssertBufferNonNull(buffer);
|
||||||
|
AssertBufferHasGraphicsStorageFlag(buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var bufferHandle = buffer.Handle;
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuBindFragmentStorageBuffers(
|
||||||
|
Handle,
|
||||||
|
slot,
|
||||||
|
&bufferHandle,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void PushVertexUniformData(
|
||||||
|
void* uniformsPtr,
|
||||||
|
uint size,
|
||||||
|
uint slot = 0
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertGraphicsPipelineBound();
|
AssertGraphicsPipelineBound();
|
||||||
|
|
||||||
for (var i = 0; i < storageTextureSlices.Length; i += 1)
|
if (slot >= currentGraphicsPipeline.VertexShaderResourceInfo.UniformBufferCount)
|
||||||
{
|
{
|
||||||
AssertTextureNonNull(storageTextureSlices[i].Texture);
|
throw new System.ArgumentException($"Slot {slot} given, but {currentGraphicsPipeline.VertexShaderResourceInfo.UniformBufferCount} uniform buffers are used on the shader!");
|
||||||
AssertTextureHasGraphicsStorageFlag(storageTextureSlices[i].Texture);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_Gpu.TextureSlice* sliceArray =
|
SDL_Gpu.SDL_GpuPushVertexUniformData(
|
||||||
(SDL_Gpu.TextureSlice*) NativeMemory.Alloc(
|
|
||||||
(nuint) (Marshal.SizeOf<SDL_Gpu.TextureSlice>() * storageTextureSlices.Length)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (var i = 0; i < storageTextureSlices.Length; i += 1)
|
|
||||||
{
|
|
||||||
sliceArray[i] = storageTextureSlices[i].ToSDL();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Gpu.SDL_GpuBindVertexStorageTextures(
|
|
||||||
Handle,
|
Handle,
|
||||||
firstSlot,
|
slot,
|
||||||
sliceArray,
|
(nint) uniformsPtr,
|
||||||
(uint) storageTextureSlices.Length
|
size
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
NativeMemory.Free(sliceArray);
|
public unsafe void PushVertexUniformData<T>(
|
||||||
|
in T uniforms
|
||||||
|
) where T : unmanaged
|
||||||
|
{
|
||||||
|
fixed (T* uniformsPtr = &uniforms)
|
||||||
|
{
|
||||||
|
PushVertexUniformData(uniformsPtr, (uint) Marshal.SizeOf<T>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void PushFragmentUniformData(
|
||||||
|
void* uniformsPtr,
|
||||||
|
uint size,
|
||||||
|
uint slot = 0
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
|
||||||
|
if (slot >= currentGraphicsPipeline.FragmentShaderResourceInfo.UniformBufferCount)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentException($"Slot {slot} given, but {currentGraphicsPipeline.FragmentShaderResourceInfo.UniformBufferCount} uniform buffers are used on the shader!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuPushFragmentUniformData(
|
||||||
|
Handle,
|
||||||
|
slot,
|
||||||
|
(nint) uniformsPtr,
|
||||||
|
size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void PushFragmentUniformData<T>(
|
||||||
|
in T uniforms
|
||||||
|
) where T : unmanaged
|
||||||
|
{
|
||||||
|
fixed (T* uniformsPtr = &uniforms)
|
||||||
|
{
|
||||||
|
PushFragmentUniformData(uniformsPtr, (uint) Marshal.SizeOf<T>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws using a vertex buffer and an index buffer, and an optional instance count.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseVertex">The starting index offset for the vertex buffer.</param>
|
||||||
|
/// <param name="startIndex">The starting index offset for the index buffer.</param>
|
||||||
|
/// <param name="primitiveCount">The number of primitives to draw.</param>
|
||||||
|
/// <param name="instanceCount">The number of instances to draw.</param>
|
||||||
|
public void DrawIndexedPrimitives(
|
||||||
|
uint baseVertex,
|
||||||
|
uint startIndex,
|
||||||
|
uint primitiveCount,
|
||||||
|
uint instanceCount = 1
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuDrawIndexedPrimitives(
|
||||||
|
Handle,
|
||||||
|
baseVertex,
|
||||||
|
startIndex,
|
||||||
|
primitiveCount,
|
||||||
|
instanceCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws using a vertex buffer and an index buffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseVertex">The starting index offset for the vertex buffer.</param>
|
||||||
|
/// <param name="startIndex">The starting index offset for the index buffer.</param>
|
||||||
|
/// <param name="primitiveCount">The number of primitives to draw.</param>
|
||||||
|
public void DrawPrimitives(
|
||||||
|
uint vertexStart,
|
||||||
|
uint primitiveCount
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuDrawPrimitives(
|
||||||
|
Handle,
|
||||||
|
vertexStart,
|
||||||
|
primitiveCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Similar to DrawPrimitives, but parameters are set from a buffer.
|
||||||
|
/// The buffer must have the Indirect usage flag set.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">The draw parameters buffer.</param>
|
||||||
|
/// <param name="offsetInBytes">The offset to start reading from the draw parameters buffer.</param>
|
||||||
|
/// <param name="drawCount">The number of draw parameter sets that should be read from the buffer.</param>
|
||||||
|
/// <param name="stride">The byte stride between sets of draw parameters.</param>
|
||||||
|
public void DrawPrimitivesIndirect(
|
||||||
|
GpuBuffer buffer,
|
||||||
|
uint offsetInBytes,
|
||||||
|
uint drawCount,
|
||||||
|
uint stride
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuDrawPrimitivesIndirect(
|
||||||
|
Handle,
|
||||||
|
buffer.Handle,
|
||||||
|
offsetInBytes,
|
||||||
|
drawCount,
|
||||||
|
stride
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Similar to DrawIndexedPrimitives, but parameters are set from a buffer.
|
||||||
|
/// The buffer must have the Indirect usage flag set.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buffer">The draw parameters buffer.</param>
|
||||||
|
/// <param name="offsetInBytes">The offset to start reading from the draw parameters buffer.</param>
|
||||||
|
/// <param name="drawCount">The number of draw parameter sets that should be read from the buffer.</param>
|
||||||
|
/// <param name="stride">The byte stride between sets of draw parameters.</param>
|
||||||
|
public void DrawIndexedPrimitivesIndirect(
|
||||||
|
GpuBuffer buffer,
|
||||||
|
uint offsetInBytes,
|
||||||
|
uint drawCount,
|
||||||
|
uint stride
|
||||||
|
) {
|
||||||
|
#if DEBUG
|
||||||
|
AssertGraphicsPipelineBound();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_Gpu.SDL_GpuDrawIndexedPrimitivesIndirect(
|
||||||
|
Handle,
|
||||||
|
buffer.Handle,
|
||||||
|
offsetInBytes,
|
||||||
|
drawCount,
|
||||||
|
stride
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -481,5 +537,21 @@ public class RenderPass
|
||||||
throw new System.ArgumentException("The bound Texture's UsageFlags must include TextureUsageFlags.GraphicsStorage!");
|
throw new System.ArgumentException("The bound Texture's UsageFlags must include TextureUsageFlags.GraphicsStorage!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AssertBufferNonNull(GpuBuffer buffer)
|
||||||
|
{
|
||||||
|
if (buffer == null || buffer.Handle == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
throw new System.NullReferenceException("Buffer must not be null!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssertBufferHasGraphicsStorageFlag(GpuBuffer buffer)
|
||||||
|
{
|
||||||
|
if ((buffer.UsageFlags & BufferUsageFlags.GraphicsStorage) == 0)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentException("The bound Buffer's UsageFlags must include BufferUsageFlag.GraphicsStorage!");
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
|
namespace MoonWorks.Graphics
|
||||||
|
{
|
||||||
|
internal class RenderPassPool
|
||||||
|
{
|
||||||
|
private ConcurrentQueue<RenderPass> RenderPasses = new ConcurrentQueue<RenderPass>();
|
||||||
|
|
||||||
|
public RenderPass Obtain()
|
||||||
|
{
|
||||||
|
if (RenderPasses.TryDequeue(out var renderPass))
|
||||||
|
{
|
||||||
|
return renderPass;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new RenderPass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Return(RenderPass renderPass)
|
||||||
|
{
|
||||||
|
RenderPasses.Enqueue(renderPass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,86 +1,88 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// GpuBuffers are generic data containers that can be used by the GPU.
|
||||||
|
/// </summary>
|
||||||
|
public class GpuBuffer : SDL_GpuResource
|
||||||
{
|
{
|
||||||
|
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseBuffer;
|
||||||
|
|
||||||
|
public BufferUsageFlags UsageFlags { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GpuBuffers are generic data containers that can be used by the GPU.
|
/// Size in bytes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GpuBuffer : SDL_GpuResource
|
public uint Size { get; }
|
||||||
|
|
||||||
|
private string name;
|
||||||
|
public string Name
|
||||||
{
|
{
|
||||||
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_QueueDestroyGpuBuffer;
|
get => name;
|
||||||
|
|
||||||
/// <summary>
|
set
|
||||||
/// Size in bytes.
|
|
||||||
/// </summary>
|
|
||||||
public uint Size { get; }
|
|
||||||
|
|
||||||
private string name;
|
|
||||||
public string Name
|
|
||||||
{
|
{
|
||||||
get => name;
|
if (Device.DebugMode)
|
||||||
|
|
||||||
set
|
|
||||||
{
|
{
|
||||||
if (Device.DebugMode)
|
SDL_Gpu.SDL_GpuSetBufferName(
|
||||||
{
|
Device.Handle,
|
||||||
Refresh.Refresh_SetGpuBufferName(
|
Handle,
|
||||||
Device.Handle,
|
value
|
||||||
Handle,
|
);
|
||||||
value
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
name = value;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
name = value;
|
||||||
/// Creates a buffer of appropriate size given a type and element count.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The type that the buffer will contain.</typeparam>
|
|
||||||
/// <param name="device">The GraphicsDevice.</param>
|
|
||||||
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
|
||||||
/// <param name="elementCount">How many elements of type T the buffer will contain.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public unsafe static GpuBuffer Create<T>(
|
|
||||||
GraphicsDevice device,
|
|
||||||
BufferUsageFlags usageFlags,
|
|
||||||
uint elementCount
|
|
||||||
) where T : unmanaged
|
|
||||||
{
|
|
||||||
return new GpuBuffer(
|
|
||||||
device,
|
|
||||||
usageFlags,
|
|
||||||
(uint) Marshal.SizeOf<T>() * elementCount
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a buffer.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
|
||||||
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
|
||||||
/// <param name="sizeInBytes">The length of the array. Cannot be resized.</param>
|
|
||||||
public GpuBuffer(
|
|
||||||
GraphicsDevice device,
|
|
||||||
BufferUsageFlags usageFlags,
|
|
||||||
uint sizeInBytes
|
|
||||||
) : base(device)
|
|
||||||
{
|
|
||||||
Handle = Refresh.Refresh_CreateGpuBuffer(
|
|
||||||
device.Handle,
|
|
||||||
(Refresh.BufferUsageFlags) usageFlags,
|
|
||||||
sizeInBytes
|
|
||||||
);
|
|
||||||
Size = sizeInBytes;
|
|
||||||
name = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator BufferBinding(GpuBuffer b)
|
|
||||||
{
|
|
||||||
return new BufferBinding(b, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a buffer of appropriate size given a type and element count.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type that the buffer will contain.</typeparam>
|
||||||
|
/// <param name="device">The GraphicsDevice.</param>
|
||||||
|
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
||||||
|
/// <param name="elementCount">How many elements of type T the buffer will contain.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public unsafe static GpuBuffer Create<T>(
|
||||||
|
GraphicsDevice device,
|
||||||
|
BufferUsageFlags usageFlags,
|
||||||
|
uint elementCount
|
||||||
|
) where T : unmanaged
|
||||||
|
{
|
||||||
|
return new GpuBuffer(
|
||||||
|
device,
|
||||||
|
usageFlags,
|
||||||
|
(uint) Marshal.SizeOf<T>() * elementCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a buffer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||||
|
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
||||||
|
/// <param name="sizeInBytes">The length of the array. Cannot be resized.</param>
|
||||||
|
public GpuBuffer(
|
||||||
|
GraphicsDevice device,
|
||||||
|
BufferUsageFlags usageFlags,
|
||||||
|
uint sizeInBytes
|
||||||
|
) : base(device)
|
||||||
|
{
|
||||||
|
Handle = SDL_Gpu.SDL_GpuCreateBuffer(
|
||||||
|
device.Handle,
|
||||||
|
(SDL_Gpu.BufferUsageFlags) usageFlags,
|
||||||
|
sizeInBytes
|
||||||
|
);
|
||||||
|
UsageFlags = usageFlags;
|
||||||
|
Size = sizeInBytes;
|
||||||
|
name = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator BufferBinding(GpuBuffer b)
|
||||||
|
{
|
||||||
|
return new BufferBinding(b, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
|
@ -10,10 +10,10 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GraphicsPipeline : SDL_GpuResource
|
public class GraphicsPipeline : SDL_GpuResource
|
||||||
{
|
{
|
||||||
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_QueueDestroyGraphicsPipeline;
|
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseGraphicsPipeline;
|
||||||
|
|
||||||
public GraphicsShaderInfo VertexShaderInfo { get; }
|
public GraphicsPipelineResourceInfo VertexShaderResourceInfo { get; }
|
||||||
public GraphicsShaderInfo FragmentShaderInfo { get; }
|
public GraphicsPipelineResourceInfo FragmentShaderResourceInfo { get; }
|
||||||
public SampleCount SampleCount { get; }
|
public SampleCount SampleCount { get; }
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -25,103 +25,78 @@ namespace MoonWorks.Graphics
|
||||||
in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
|
in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
|
||||||
) : base(device)
|
) : base(device)
|
||||||
{
|
{
|
||||||
DepthStencilState depthStencilState = graphicsPipelineCreateInfo.DepthStencilState;
|
SDL_Gpu.GraphicsPipelineCreateInfo sdlGraphicsPipelineCreateInfo;
|
||||||
GraphicsShaderInfo vertexShaderInfo = graphicsPipelineCreateInfo.VertexShaderInfo;
|
|
||||||
GraphicsShaderInfo fragmentShaderInfo = graphicsPipelineCreateInfo.FragmentShaderInfo;
|
|
||||||
MultisampleState multisampleState = graphicsPipelineCreateInfo.MultisampleState;
|
|
||||||
RasterizerState rasterizerState = graphicsPipelineCreateInfo.RasterizerState;
|
|
||||||
PrimitiveType primitiveType = graphicsPipelineCreateInfo.PrimitiveType;
|
|
||||||
VertexInputState vertexInputState = graphicsPipelineCreateInfo.VertexInputState;
|
|
||||||
GraphicsPipelineAttachmentInfo attachmentInfo = graphicsPipelineCreateInfo.AttachmentInfo;
|
|
||||||
BlendConstants blendConstants = graphicsPipelineCreateInfo.BlendConstants;
|
|
||||||
|
|
||||||
var vertexAttributesHandle = GCHandle.Alloc(
|
var vertexAttributes = (SDL_Gpu.VertexAttribute*) NativeMemory.Alloc(
|
||||||
vertexInputState.VertexAttributes,
|
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length * Marshal.SizeOf<SDL_Gpu.VertexAttribute>())
|
||||||
GCHandleType.Pinned
|
|
||||||
);
|
|
||||||
var vertexBindingsHandle = GCHandle.Alloc(
|
|
||||||
vertexInputState.VertexBindings,
|
|
||||||
GCHandleType.Pinned
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var colorAttachmentDescriptions = stackalloc Refresh.ColorAttachmentDescription[
|
for (var i = 0; i < graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length; i += 1)
|
||||||
(int) attachmentInfo.ColorAttachmentDescriptions.Length
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var i = 0; i < attachmentInfo.ColorAttachmentDescriptions.Length; i += 1)
|
|
||||||
{
|
{
|
||||||
colorAttachmentDescriptions[i].format = (Refresh.TextureFormat) attachmentInfo.ColorAttachmentDescriptions[i].Format;
|
vertexAttributes[i] = graphicsPipelineCreateInfo.VertexInputState.VertexAttributes[i].ToSDL();
|
||||||
colorAttachmentDescriptions[i].blendState = attachmentInfo.ColorAttachmentDescriptions[i].BlendState.ToRefresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh.GraphicsPipelineCreateInfo refreshGraphicsPipelineCreateInfo;
|
var vertexBindings = (SDL_Gpu.VertexBinding*) NativeMemory.Alloc(
|
||||||
|
(nuint) (graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length * Marshal.SizeOf<SDL_Gpu.VertexBinding>())
|
||||||
|
);
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.blendConstants[0] = blendConstants.R;
|
for (var i = 0; i < graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length; i += 1)
|
||||||
refreshGraphicsPipelineCreateInfo.blendConstants[1] = blendConstants.G;
|
{
|
||||||
refreshGraphicsPipelineCreateInfo.blendConstants[2] = blendConstants.B;
|
vertexBindings[i] = graphicsPipelineCreateInfo.VertexInputState.VertexBindings[i].ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.blendConstants[3] = blendConstants.A;
|
}
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh();
|
var colorAttachmentDescriptions = stackalloc SDL_Gpu.ColorAttachmentDescription[
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh();
|
graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.compareMask = depthStencilState.CompareMask;
|
];
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.writeMask = depthStencilState.WriteMask;
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.reference = depthStencilState.Reference;
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp;
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable);
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable);
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable);
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds;
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds;
|
|
||||||
refreshGraphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable);
|
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.vertexShaderInfo.entryPointName = vertexShaderInfo.EntryPointName;
|
for (var i = 0; i < graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length; i += 1)
|
||||||
refreshGraphicsPipelineCreateInfo.vertexShaderInfo.shaderModule = vertexShaderInfo.ShaderModule.Handle;
|
{
|
||||||
refreshGraphicsPipelineCreateInfo.vertexShaderInfo.uniformBufferSize = vertexShaderInfo.UniformBufferSize;
|
colorAttachmentDescriptions[i].Format = (SDL_Gpu.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].Format;
|
||||||
refreshGraphicsPipelineCreateInfo.vertexShaderInfo.samplerBindingCount = vertexShaderInfo.SamplerBindingCount;
|
colorAttachmentDescriptions[i].BlendState = graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[i].BlendState.ToSDL();
|
||||||
|
}
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.fragmentShaderInfo.entryPointName = fragmentShaderInfo.EntryPointName;
|
sdlGraphicsPipelineCreateInfo.VertexShader = graphicsPipelineCreateInfo.VertexShader.Handle;
|
||||||
refreshGraphicsPipelineCreateInfo.fragmentShaderInfo.shaderModule = fragmentShaderInfo.ShaderModule.Handle;
|
sdlGraphicsPipelineCreateInfo.FragmentShader = graphicsPipelineCreateInfo.FragmentShader.Handle;
|
||||||
refreshGraphicsPipelineCreateInfo.fragmentShaderInfo.uniformBufferSize = fragmentShaderInfo.UniformBufferSize;
|
|
||||||
refreshGraphicsPipelineCreateInfo.fragmentShaderInfo.samplerBindingCount = fragmentShaderInfo.SamplerBindingCount;
|
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.multisampleState.multisampleCount = (Refresh.SampleCount) multisampleState.MultisampleCount;
|
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexAttributes = vertexAttributes;
|
||||||
refreshGraphicsPipelineCreateInfo.multisampleState.sampleMask = multisampleState.SampleMask;
|
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexAttributeCount = (uint) graphicsPipelineCreateInfo.VertexInputState.VertexAttributes.Length;
|
||||||
|
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexBindings = vertexBindings;
|
||||||
|
sdlGraphicsPipelineCreateInfo.VertexInputState.VertexBindingCount = (uint) graphicsPipelineCreateInfo.VertexInputState.VertexBindings.Length;
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.cullMode = (Refresh.CullMode) rasterizerState.CullMode;
|
sdlGraphicsPipelineCreateInfo.PrimitiveType = (SDL_Gpu.PrimitiveType) graphicsPipelineCreateInfo.PrimitiveType;
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasClamp = rasterizerState.DepthBiasClamp;
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasConstantFactor = rasterizerState.DepthBiasConstantFactor;
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasEnable = Conversions.BoolToByte(rasterizerState.DepthBiasEnable);
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasSlopeFactor = rasterizerState.DepthBiasSlopeFactor;
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.fillMode = (Refresh.FillMode) rasterizerState.FillMode;
|
|
||||||
refreshGraphicsPipelineCreateInfo.rasterizerState.frontFace = (Refresh.FrontFace) rasterizerState.FrontFace;
|
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject();
|
sdlGraphicsPipelineCreateInfo.RasterizerState = graphicsPipelineCreateInfo.RasterizerState.ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length;
|
sdlGraphicsPipelineCreateInfo.MultisampleState = graphicsPipelineCreateInfo.MultisampleState.ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject();
|
sdlGraphicsPipelineCreateInfo.DepthStencilState = graphicsPipelineCreateInfo.DepthStencilState.ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length;
|
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
|
sdlGraphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentCount = (uint) graphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions.Length;
|
||||||
|
sdlGraphicsPipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions = colorAttachmentDescriptions;
|
||||||
|
sdlGraphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat = (SDL_Gpu.TextureFormat) graphicsPipelineCreateInfo.AttachmentInfo.DepthStencilFormat;
|
||||||
|
sdlGraphicsPipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment = Conversions.BoolToInt(graphicsPipelineCreateInfo.AttachmentInfo.HasDepthStencilAttachment);
|
||||||
|
|
||||||
refreshGraphicsPipelineCreateInfo.attachmentInfo.colorAttachmentCount = (uint) attachmentInfo.ColorAttachmentDescriptions.Length;
|
sdlGraphicsPipelineCreateInfo.VertexResourceInfo = graphicsPipelineCreateInfo.VertexShaderResourceInfo.ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.attachmentInfo.colorAttachmentDescriptions = (IntPtr) colorAttachmentDescriptions;
|
sdlGraphicsPipelineCreateInfo.FragmentResourceInfo = graphicsPipelineCreateInfo.FragmentShaderResourceInfo.ToSDL();
|
||||||
refreshGraphicsPipelineCreateInfo.attachmentInfo.depthStencilFormat = (Refresh.TextureFormat) attachmentInfo.DepthStencilFormat;
|
|
||||||
refreshGraphicsPipelineCreateInfo.attachmentInfo.hasDepthStencilAttachment = Conversions.BoolToByte(attachmentInfo.HasDepthStencilAttachment);
|
|
||||||
|
|
||||||
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, refreshGraphicsPipelineCreateInfo);
|
sdlGraphicsPipelineCreateInfo.BlendConstants[0] = graphicsPipelineCreateInfo.BlendConstants.R;
|
||||||
|
sdlGraphicsPipelineCreateInfo.BlendConstants[1] = graphicsPipelineCreateInfo.BlendConstants.G;
|
||||||
|
sdlGraphicsPipelineCreateInfo.BlendConstants[2] = graphicsPipelineCreateInfo.BlendConstants.B;
|
||||||
|
sdlGraphicsPipelineCreateInfo.BlendConstants[3] = graphicsPipelineCreateInfo.BlendConstants.A;
|
||||||
|
|
||||||
|
Handle = SDL_Gpu.SDL_GpuCreateGraphicsPipeline(device.Handle, sdlGraphicsPipelineCreateInfo);
|
||||||
if (Handle == IntPtr.Zero)
|
if (Handle == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
throw new Exception("Could not create graphics pipeline!");
|
throw new Exception("Could not create graphics pipeline!");
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexAttributesHandle.Free();
|
NativeMemory.Free(vertexAttributes);
|
||||||
vertexBindingsHandle.Free();
|
NativeMemory.Free(vertexBindings);
|
||||||
|
|
||||||
VertexShaderInfo = vertexShaderInfo;
|
VertexShaderResourceInfo = graphicsPipelineCreateInfo.VertexShaderResourceInfo;
|
||||||
FragmentShaderInfo = fragmentShaderInfo;
|
FragmentShaderResourceInfo = graphicsPipelineCreateInfo.FragmentShaderResourceInfo;
|
||||||
SampleCount = multisampleState.MultisampleCount;
|
SampleCount = graphicsPipelineCreateInfo.MultisampleState.MultisampleCount;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AttachmentInfo = attachmentInfo;
|
AttachmentInfo = graphicsPipelineCreateInfo.AttachmentInfo;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
if (Device.DebugMode)
|
if (Device.DebugMode)
|
||||||
{
|
{
|
||||||
Refresh.Refresh_SetTextureName(
|
SDL_Gpu.SDL_GpuSetTextureName(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
value
|
value
|
||||||
|
@ -41,7 +41,7 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this allocates a delegate instance
|
// FIXME: this allocates a delegate instance
|
||||||
protected override Action<IntPtr, IntPtr> ReleaseFunction => Refresh.Refresh_QueueDestroyTexture;
|
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseTexture;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a 2D texture.
|
/// Creates a 2D texture.
|
||||||
|
@ -179,9 +179,9 @@ namespace MoonWorks.Graphics
|
||||||
in TextureCreateInfo textureCreateInfo
|
in TextureCreateInfo textureCreateInfo
|
||||||
) : base(device)
|
) : base(device)
|
||||||
{
|
{
|
||||||
Handle = Refresh.Refresh_CreateTexture(
|
Handle = SDL_Gpu.SDL_GpuCreateTexture(
|
||||||
device.Handle,
|
device.Handle,
|
||||||
textureCreateInfo.ToRefreshTextureCreateInfo()
|
textureCreateInfo.ToSDL()
|
||||||
);
|
);
|
||||||
|
|
||||||
Format = textureCreateInfo.Format;
|
Format = textureCreateInfo.Format;
|
||||||
|
|
|
@ -36,52 +36,52 @@ public enum IndexElementSize
|
||||||
|
|
||||||
public enum TextureFormat
|
public enum TextureFormat
|
||||||
{
|
{
|
||||||
/* Unsigned Normalized Float Color Formats */
|
/* Unsigned Normalized Float Color Formats */
|
||||||
R8G8B8A8,
|
R8G8B8A8,
|
||||||
B8G8R8A8,
|
B8G8R8A8,
|
||||||
R5G6B5,
|
R5G6B5,
|
||||||
A1R5G5B5,
|
A1R5G5B5,
|
||||||
B4G4R4A4,
|
B4G4R4A4,
|
||||||
A2R10G10B10,
|
A2R10G10B10,
|
||||||
A2B10G10R10,
|
A2B10G10R10,
|
||||||
R16G16,
|
R16G16,
|
||||||
R16G16B16A16,
|
R16G16B16A16,
|
||||||
R8,
|
R8,
|
||||||
A8,
|
A8,
|
||||||
/* Compressed Unsigned Normalized Float Color Formats */
|
/* Compressed Unsigned Normalized Float Color Formats */
|
||||||
BC1,
|
BC1,
|
||||||
BC2,
|
BC2,
|
||||||
BC3,
|
BC3,
|
||||||
BC7,
|
BC7,
|
||||||
/* Signed Normalized Float Color Formats */
|
/* Signed Normalized Float Color Formats */
|
||||||
R8G8_SNORM,
|
R8G8_SNORM,
|
||||||
R8G8B8A8_SNORM,
|
R8G8B8A8_SNORM,
|
||||||
/* Signed Float Color Formats */
|
/* Signed Float Color Formats */
|
||||||
R16_SFLOAT,
|
R16_SFLOAT,
|
||||||
R16G16_SFLOAT,
|
R16G16_SFLOAT,
|
||||||
R16G16B16A16_SFLOAT,
|
R16G16B16A16_SFLOAT,
|
||||||
R32_SFLOAT,
|
R32_SFLOAT,
|
||||||
R32G32_SFLOAT,
|
R32G32_SFLOAT,
|
||||||
R32G32B32A32_SFLOAT,
|
R32G32B32A32_SFLOAT,
|
||||||
/* Unsigned Integer Color Formats */
|
/* Unsigned Integer Color Formats */
|
||||||
R8_UINT,
|
R8_UINT,
|
||||||
R8G8_UINT,
|
R8G8_UINT,
|
||||||
R8G8B8A8_UINT,
|
R8G8B8A8_UINT,
|
||||||
R16_UINT,
|
R16_UINT,
|
||||||
R16G16_UINT,
|
R16G16_UINT,
|
||||||
R16G16B16A16_UINT,
|
R16G16B16A16_UINT,
|
||||||
/* SRGB Color Formats */
|
/* SRGB Color Formats */
|
||||||
R8G8B8A8_SRGB,
|
R8G8B8A8_SRGB,
|
||||||
B8G8R8A8_SRGB,
|
B8G8R8A8_SRGB,
|
||||||
/* Compressed SRGB Color Formats */
|
/* Compressed SRGB Color Formats */
|
||||||
BC3_SRGB,
|
BC3_SRGB,
|
||||||
BC7_SRGB,
|
BC7_SRGB,
|
||||||
/* Depth Formats */
|
/* Depth Formats */
|
||||||
D16_UNORM,
|
D16_UNORM,
|
||||||
D24_UNORM,
|
D24_UNORM,
|
||||||
D32_SFLOAT,
|
D32_SFLOAT,
|
||||||
D24_UNORM_S8_UINT,
|
D24_UNORM_S8_UINT,
|
||||||
D32_SFLOAT_S8_UINT
|
D32_SFLOAT_S8_UINT
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
|
@ -251,10 +251,13 @@ public enum BlendFactor
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum ColorComponentFlags
|
public enum ColorComponentFlags
|
||||||
{
|
{
|
||||||
|
None = 0x0,
|
||||||
R = 0x1,
|
R = 0x1,
|
||||||
G = 0x2,
|
G = 0x2,
|
||||||
B = 0x4,
|
B = 0x4,
|
||||||
A = 0x8
|
A = 0x8,
|
||||||
|
RGB = R | G | B,
|
||||||
|
RGBA = R | G| B | A
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Filter
|
public enum Filter
|
||||||
|
@ -366,7 +369,7 @@ public struct Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: can we do an unsafe cast somehow?
|
// FIXME: can we do an unsafe cast somehow?
|
||||||
public SDL_Gpu.Rect ToRefresh()
|
public SDL_Gpu.Rect ToSDL()
|
||||||
{
|
{
|
||||||
return new SDL_Gpu.Rect
|
return new SDL_Gpu.Rect
|
||||||
{
|
{
|
||||||
|
@ -448,6 +451,16 @@ public struct VertexBinding
|
||||||
Stride = (uint) Marshal.SizeOf<T>()
|
Stride = (uint) Marshal.SizeOf<T>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SDL_Gpu.VertexBinding ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.VertexBinding
|
||||||
|
{
|
||||||
|
Binding = Binding,
|
||||||
|
Stride = Stride,
|
||||||
|
InputRate = (SDL_Gpu.VertexInputRate) InputRate
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
@ -457,6 +470,17 @@ public struct VertexAttribute
|
||||||
public uint Binding;
|
public uint Binding;
|
||||||
public VertexElementFormat Format;
|
public VertexElementFormat Format;
|
||||||
public uint Offset;
|
public uint Offset;
|
||||||
|
|
||||||
|
public SDL_Gpu.VertexAttribute ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.VertexAttribute
|
||||||
|
{
|
||||||
|
Location = Location,
|
||||||
|
Binding = Binding,
|
||||||
|
Format = (SDL_Gpu.VertexElementFormat) Format,
|
||||||
|
Offset = Offset
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
@ -797,3 +821,39 @@ public readonly record struct BufferImageCopy(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public readonly record struct GraphicsPipelineResourceInfo(
|
||||||
|
uint SamplerCount,
|
||||||
|
uint StorageBufferCount,
|
||||||
|
uint StorageTextureCount,
|
||||||
|
uint UniformBufferCount
|
||||||
|
) {
|
||||||
|
public SDL_Gpu.GraphicsPipelineResourceInfo ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.GraphicsPipelineResourceInfo
|
||||||
|
{
|
||||||
|
SamplerCount = SamplerCount,
|
||||||
|
StorageBufferCount = StorageBufferCount,
|
||||||
|
StorageTextureCount = StorageTextureCount,
|
||||||
|
UniformBufferCount = UniformBufferCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// All of the information that is used to create a GraphicsPipeline.
|
||||||
|
/// </summary>
|
||||||
|
public struct GraphicsPipelineCreateInfo
|
||||||
|
{
|
||||||
|
public Shader VertexShader;
|
||||||
|
public Shader FragmentShader;
|
||||||
|
public VertexInputState VertexInputState;
|
||||||
|
public PrimitiveType PrimitiveType;
|
||||||
|
public RasterizerState RasterizerState;
|
||||||
|
public MultisampleState MultisampleState;
|
||||||
|
public DepthStencilState DepthStencilState;
|
||||||
|
public GraphicsPipelineAttachmentInfo AttachmentInfo;
|
||||||
|
public GraphicsPipelineResourceInfo VertexShaderResourceInfo;
|
||||||
|
public GraphicsPipelineResourceInfo FragmentShaderResourceInfo;
|
||||||
|
public BlendConstants BlendConstants;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
|
@ -106,18 +106,18 @@ namespace MoonWorks.Graphics
|
||||||
ColorWriteMask = ColorComponentFlags.None
|
ColorWriteMask = ColorComponentFlags.None
|
||||||
};
|
};
|
||||||
|
|
||||||
public Refresh.ColorAttachmentBlendState ToRefresh()
|
public SDL_Gpu.ColorAttachmentBlendState ToSDL()
|
||||||
{
|
{
|
||||||
return new Refresh.ColorAttachmentBlendState
|
return new SDL_Gpu.ColorAttachmentBlendState
|
||||||
{
|
{
|
||||||
blendEnable = Conversions.BoolToByte(BlendEnable),
|
BlendEnable = Conversions.BoolToInt(BlendEnable),
|
||||||
alphaBlendOp = (Refresh.BlendOp) AlphaBlendOp,
|
AlphaBlendOp = (SDL_Gpu.BlendOp) AlphaBlendOp,
|
||||||
colorBlendOp = (Refresh.BlendOp) ColorBlendOp,
|
ColorBlendOp = (SDL_Gpu.BlendOp) ColorBlendOp,
|
||||||
colorWriteMask = (Refresh.ColorComponentFlags) ColorWriteMask,
|
ColorWriteMask = (SDL_Gpu.ColorComponentFlags) ColorWriteMask,
|
||||||
destinationAlphaBlendFactor = (Refresh.BlendFactor) DestinationAlphaBlendFactor,
|
DestinationAlphaBlendFactor = (SDL_Gpu.BlendFactor) DestinationAlphaBlendFactor,
|
||||||
destinationColorBlendFactor = (Refresh.BlendFactor) DestinationColorBlendFactor,
|
DestinationColorBlendFactor = (SDL_Gpu.BlendFactor) DestinationColorBlendFactor,
|
||||||
sourceAlphaBlendFactor = (Refresh.BlendFactor) SourceAlphaBlendFactor,
|
SourceAlphaBlendFactor = (SDL_Gpu.BlendFactor) SourceAlphaBlendFactor,
|
||||||
sourceColorBlendFactor = (Refresh.BlendFactor) SourceColorBlendFactor
|
SourceColorBlendFactor = (SDL_Gpu.BlendFactor) SourceColorBlendFactor
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
namespace MoonWorks.Graphics
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines how data is written to and read from the depth/stencil buffer.
|
/// Determines how data is written to and read from the depth/stencil buffer.
|
||||||
|
@ -90,5 +92,24 @@
|
||||||
DepthBoundsTestEnable = false,
|
DepthBoundsTestEnable = false,
|
||||||
StencilTestEnable = false
|
StencilTestEnable = false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public SDL_Gpu.DepthStencilState ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.DepthStencilState
|
||||||
|
{
|
||||||
|
DepthTestEnable = Conversions.BoolToInt(DepthTestEnable),
|
||||||
|
BackStencilState = BackStencilState.ToSDL(),
|
||||||
|
FrontStencilState = FrontStencilState.ToSDL(),
|
||||||
|
CompareMask = CompareMask,
|
||||||
|
WriteMask = WriteMask,
|
||||||
|
Reference = Reference,
|
||||||
|
CompareOp = (SDL_Gpu.CompareOp) CompareOp,
|
||||||
|
DepthBoundsTestEnable = Conversions.BoolToInt(DepthBoundsTestEnable),
|
||||||
|
DepthWriteEnable = Conversions.BoolToInt(DepthWriteEnable),
|
||||||
|
MinDepthBounds = MinDepthBounds,
|
||||||
|
MaxDepthBounds = MaxDepthBounds,
|
||||||
|
StencilTestEnable = Conversions.BoolToInt(StencilTestEnable)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace MoonWorks.Graphics
|
||||||
) {
|
) {
|
||||||
ColorAttachmentDescriptions = colorAttachmentDescriptions;
|
ColorAttachmentDescriptions = colorAttachmentDescriptions;
|
||||||
HasDepthStencilAttachment = false;
|
HasDepthStencilAttachment = false;
|
||||||
DepthStencilFormat = TextureFormat.D16;
|
DepthStencilFormat = TextureFormat.D16_UNORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphicsPipelineAttachmentInfo(
|
public GraphicsPipelineAttachmentInfo(
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
namespace MoonWorks.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// All of the information that is used to create a GraphicsPipeline.
|
|
||||||
/// </summary>
|
|
||||||
public struct GraphicsPipelineCreateInfo
|
|
||||||
{
|
|
||||||
public DepthStencilState DepthStencilState;
|
|
||||||
public GraphicsShaderInfo VertexShaderInfo;
|
|
||||||
public GraphicsShaderInfo FragmentShaderInfo;
|
|
||||||
public MultisampleState MultisampleState;
|
|
||||||
public RasterizerState RasterizerState;
|
|
||||||
public PrimitiveType PrimitiveType;
|
|
||||||
public VertexInputState VertexInputState;
|
|
||||||
public GraphicsPipelineAttachmentInfo AttachmentInfo;
|
|
||||||
public BlendConstants BlendConstants;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Information that the pipeline needs about a graphics shader.
|
|
||||||
/// </summary>
|
|
||||||
public struct GraphicsShaderInfo
|
|
||||||
{
|
|
||||||
public ShaderModule ShaderModule;
|
|
||||||
public string EntryPointName;
|
|
||||||
public uint UniformBufferSize;
|
|
||||||
public uint SamplerBindingCount;
|
|
||||||
|
|
||||||
public unsafe static GraphicsShaderInfo Create<T>(
|
|
||||||
ShaderModule shaderModule,
|
|
||||||
string entryPointName,
|
|
||||||
uint samplerBindingCount
|
|
||||||
) where T : unmanaged
|
|
||||||
{
|
|
||||||
return new GraphicsShaderInfo
|
|
||||||
{
|
|
||||||
ShaderModule = shaderModule,
|
|
||||||
EntryPointName = entryPointName,
|
|
||||||
UniformBufferSize = (uint) Marshal.SizeOf<T>(),
|
|
||||||
SamplerBindingCount = samplerBindingCount
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GraphicsShaderInfo Create(
|
|
||||||
ShaderModule shaderModule,
|
|
||||||
string entryPointName,
|
|
||||||
uint samplerBindingCount
|
|
||||||
) {
|
|
||||||
return new GraphicsShaderInfo
|
|
||||||
{
|
|
||||||
ShaderModule = shaderModule,
|
|
||||||
EntryPointName = entryPointName,
|
|
||||||
UniformBufferSize = 0,
|
|
||||||
SamplerBindingCount = samplerBindingCount
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,6 @@
|
||||||
namespace MoonWorks.Graphics
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies how many samples should be used in rasterization.
|
/// Specifies how many samples should be used in rasterization.
|
||||||
|
@ -21,5 +23,14 @@
|
||||||
MultisampleCount = sampleCount;
|
MultisampleCount = sampleCount;
|
||||||
SampleMask = sampleMask;
|
SampleMask = sampleMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SDL_Gpu.MultisampleState ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.MultisampleState
|
||||||
|
{
|
||||||
|
MultisampleCount = (SDL_Gpu.SampleCount) MultisampleCount,
|
||||||
|
SampleMask = SampleMask
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,107 +1,122 @@
|
||||||
namespace MoonWorks.Graphics
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
|
namespace MoonWorks.Graphics;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies how the rasterizer should be configured for a graphics pipeline.
|
||||||
|
/// </summary>
|
||||||
|
public struct RasterizerState
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies how the rasterizer should be configured for a graphics pipeline.
|
/// Specifies whether front faces, back faces, none, or both should be culled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct RasterizerState
|
public CullMode CullMode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies maximum depth bias of a fragment. Only applies if depth biasing is enabled.
|
||||||
|
/// </summary>
|
||||||
|
public float DepthBiasClamp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The constant depth value added to each fragment. Only applies if depth biasing is enabled.
|
||||||
|
/// </summary>
|
||||||
|
public float DepthBiasConstantFactor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies whether depth biasing is enabled. Only applies if depth biasing is enabled.
|
||||||
|
/// </summary>
|
||||||
|
public bool DepthBiasEnable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Factor applied to a fragment's slope in depth bias calculations. Only applies if depth biasing is enabled.
|
||||||
|
/// </summary>
|
||||||
|
public float DepthBiasSlopeFactor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies how triangles should be drawn.
|
||||||
|
/// </summary>
|
||||||
|
public FillMode FillMode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies which triangle winding order is designated as front-facing.
|
||||||
|
/// </summary>
|
||||||
|
public FrontFace FrontFace;
|
||||||
|
|
||||||
|
public static readonly RasterizerState CW_CullFront = new RasterizerState
|
||||||
{
|
{
|
||||||
/// <summary>
|
CullMode = CullMode.Front,
|
||||||
/// Specifies whether front faces, back faces, none, or both should be culled.
|
FrontFace = FrontFace.Clockwise,
|
||||||
/// </summary>
|
FillMode = FillMode.Fill,
|
||||||
public CullMode CullMode;
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CW_CullBack = new RasterizerState
|
||||||
/// Specifies maximum depth bias of a fragment. Only applies if depth biasing is enabled.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.Back,
|
||||||
public float DepthBiasClamp;
|
FrontFace = FrontFace.Clockwise,
|
||||||
|
FillMode = FillMode.Fill,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CW_CullNone = new RasterizerState
|
||||||
/// The constant depth value added to each fragment. Only applies if depth biasing is enabled.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.None,
|
||||||
public float DepthBiasConstantFactor;
|
FrontFace = FrontFace.Clockwise,
|
||||||
|
FillMode = FillMode.Fill,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CW_Wireframe = new RasterizerState
|
||||||
/// Specifies whether depth biasing is enabled. Only applies if depth biasing is enabled.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.None,
|
||||||
public bool DepthBiasEnable;
|
FrontFace = FrontFace.Clockwise,
|
||||||
|
FillMode = FillMode.Line,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CCW_CullFront = new RasterizerState
|
||||||
/// Factor applied to a fragment's slope in depth bias calculations. Only applies if depth biasing is enabled.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.Front,
|
||||||
public float DepthBiasSlopeFactor;
|
FrontFace = FrontFace.CounterClockwise,
|
||||||
|
FillMode = FillMode.Fill,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CCW_CullBack = new RasterizerState
|
||||||
/// Specifies how triangles should be drawn.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.Back,
|
||||||
public FillMode FillMode;
|
FrontFace = FrontFace.CounterClockwise,
|
||||||
|
FillMode = FillMode.Fill,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
public static readonly RasterizerState CCW_CullNone = new RasterizerState
|
||||||
/// Specifies which triangle winding order is designated as front-facing.
|
{
|
||||||
/// </summary>
|
CullMode = CullMode.None,
|
||||||
public FrontFace FrontFace;
|
FrontFace = FrontFace.CounterClockwise,
|
||||||
|
FillMode = FillMode.Fill,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
public static readonly RasterizerState CW_CullFront = new RasterizerState
|
public static readonly RasterizerState CCW_Wireframe = new RasterizerState
|
||||||
|
{
|
||||||
|
CullMode = CullMode.None,
|
||||||
|
FrontFace = FrontFace.CounterClockwise,
|
||||||
|
FillMode = FillMode.Line,
|
||||||
|
DepthBiasEnable = false
|
||||||
|
};
|
||||||
|
|
||||||
|
public SDL_Gpu.RasterizerState ToSDL()
|
||||||
|
{
|
||||||
|
return new SDL_Gpu.RasterizerState
|
||||||
{
|
{
|
||||||
CullMode = CullMode.Front,
|
CullMode = (SDL_Gpu.CullMode) CullMode,
|
||||||
FrontFace = FrontFace.Clockwise,
|
DepthBiasClamp = DepthBiasClamp,
|
||||||
FillMode = FillMode.Fill,
|
DepthBiasConstantFactor = DepthBiasConstantFactor,
|
||||||
DepthBiasEnable = false
|
DepthBiasEnable = Conversions.BoolToInt(DepthBiasEnable),
|
||||||
};
|
DepthBiasSlopeFactor = DepthBiasSlopeFactor,
|
||||||
|
FillMode = (SDL_Gpu.FillMode) FillMode,
|
||||||
public static readonly RasterizerState CW_CullBack = new RasterizerState
|
FrontFace = (SDL_Gpu.FrontFace) FrontFace
|
||||||
{
|
|
||||||
CullMode = CullMode.Back,
|
|
||||||
FrontFace = FrontFace.Clockwise,
|
|
||||||
FillMode = FillMode.Fill,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CW_CullNone = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.None,
|
|
||||||
FrontFace = FrontFace.Clockwise,
|
|
||||||
FillMode = FillMode.Fill,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CW_Wireframe = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.None,
|
|
||||||
FrontFace = FrontFace.Clockwise,
|
|
||||||
FillMode = FillMode.Line,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CCW_CullFront = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.Front,
|
|
||||||
FrontFace = FrontFace.CounterClockwise,
|
|
||||||
FillMode = FillMode.Fill,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CCW_CullBack = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.Back,
|
|
||||||
FrontFace = FrontFace.CounterClockwise,
|
|
||||||
FillMode = FillMode.Fill,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CCW_CullNone = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.None,
|
|
||||||
FrontFace = FrontFace.CounterClockwise,
|
|
||||||
FillMode = FillMode.Fill,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
|
||||||
|
|
||||||
public static readonly RasterizerState CCW_Wireframe = new RasterizerState
|
|
||||||
{
|
|
||||||
CullMode = CullMode.None,
|
|
||||||
FrontFace = FrontFace.CounterClockwise,
|
|
||||||
FillMode = FillMode.Line,
|
|
||||||
DepthBiasEnable = false
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
|
@ -17,19 +17,19 @@ namespace MoonWorks.Graphics
|
||||||
public TextureFormat Format;
|
public TextureFormat Format;
|
||||||
public TextureUsageFlags UsageFlags;
|
public TextureUsageFlags UsageFlags;
|
||||||
|
|
||||||
public Refresh.TextureCreateInfo ToRefreshTextureCreateInfo()
|
public SDL_Gpu.TextureCreateInfo ToSDL()
|
||||||
{
|
{
|
||||||
return new Refresh.TextureCreateInfo
|
return new SDL_Gpu.TextureCreateInfo
|
||||||
{
|
{
|
||||||
width = Width,
|
Width = Width,
|
||||||
height = Height,
|
Height = Height,
|
||||||
depth = Depth,
|
Depth = Depth,
|
||||||
isCube = Conversions.BoolToByte(IsCube),
|
IsCube = Conversions.BoolToInt(IsCube),
|
||||||
layerCount = LayerCount,
|
LayerCount = LayerCount,
|
||||||
levelCount = LevelCount,
|
LevelCount = LevelCount,
|
||||||
sampleCount = (Refresh.SampleCount) SampleCount,
|
SampleCount = (SDL_Gpu.SampleCount) SampleCount,
|
||||||
format = (Refresh.TextureFormat) Format,
|
Format = (SDL_Gpu.TextureFormat) Format,
|
||||||
usageFlags = (Refresh.TextureUsageFlags) UsageFlags
|
UsageFlags = (SDL_Gpu.TextureUsageFlags) UsageFlags
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using RefreshCS;
|
using SDL2_gpuCS;
|
||||||
|
|
||||||
namespace MoonWorks.Graphics
|
namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
|
@ -29,17 +29,17 @@ namespace MoonWorks.Graphics
|
||||||
Depth = texture.Depth;
|
Depth = texture.Depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Refresh.TextureRegion ToRefreshTextureRegion()
|
public SDL_Gpu.TextureRegion ToSDL()
|
||||||
{
|
{
|
||||||
return new Refresh.TextureRegion
|
return new SDL_Gpu.TextureRegion
|
||||||
{
|
{
|
||||||
textureSlice = TextureSlice.ToRefreshTextureSlice(),
|
TextureSlice = TextureSlice.ToSDL(),
|
||||||
x = X,
|
X = X,
|
||||||
y = Y,
|
Y = Y,
|
||||||
z = Z,
|
Z = Z,
|
||||||
w = Width,
|
W = Width,
|
||||||
h = Height,
|
H = Height,
|
||||||
d = Depth
|
D = Depth
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue