diff --git a/src/Veldrid/OpenGL/ManagedEntryList/BeginEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/BeginEntry.cs deleted file mode 100644 index b05a968a5..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/BeginEntry.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class BeginEntry : OpenGLCommandEntry - { - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/ClearColorTargetEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/ClearColorTargetEntry.cs deleted file mode 100644 index 09b3dc5a6..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/ClearColorTargetEntry.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class ClearColorTargetEntry : OpenGLCommandEntry - { - public uint Index; - public RgbaFloat ClearColor; - - public ClearColorTargetEntry(uint index, RgbaFloat clearColor) - { - Index = index; - ClearColor = clearColor; - } - - public ClearColorTargetEntry() { } - - public ClearColorTargetEntry Init(uint index, RgbaFloat clearColor) - { - Index = index; - ClearColor = clearColor; - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/ClearDepthTargetEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/ClearDepthTargetEntry.cs deleted file mode 100644 index 9a55e4f6e..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/ClearDepthTargetEntry.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class ClearDepthTargetEntry : OpenGLCommandEntry - { - public float Depth; - - public ClearDepthTargetEntry(float depth) - { - Depth = depth; - } - - public ClearDepthTargetEntry() { } - - public ClearDepthTargetEntry Init(float depth) - { - Depth = depth; - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DispatchEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DispatchEntry.cs deleted file mode 100644 index db9d34e39..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DispatchEntry.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DispatchEntry : OpenGLCommandEntry - { - public uint GroupCountX; - public uint GroupCountY; - public uint GroupCountZ; - - public DispatchEntry() { } - - public DispatchEntry(uint groupCountX, uint groupCountY, uint groupCountZ) - { - GroupCountX = groupCountX; - GroupCountY = groupCountY; - GroupCountZ = groupCountZ; - } - - public DispatchEntry Init(uint groupCountX, uint groupCountY, uint groupCountZ) - { - GroupCountX = groupCountX; - GroupCountY = groupCountY; - GroupCountZ = groupCountZ; - - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DispatchIndirectEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DispatchIndirectEntry.cs deleted file mode 100644 index 8b773e7e5..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DispatchIndirectEntry.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DispatchIndirectEntry : OpenGLCommandEntry - { - public DeviceBuffer IndirectBuffer; - public uint Offset; - - public DispatchIndirectEntry() { } - - public DispatchIndirectEntry(DeviceBuffer indirectBuffer, uint offset) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - } - - public DispatchIndirectEntry Init(DeviceBuffer indirectBuffer, uint offset) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - - return this; - } - - public override void ClearReferences() - { - IndirectBuffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DrawEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DrawEntry.cs deleted file mode 100644 index 3e770d4bc..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DrawEntry.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DrawEntry : OpenGLCommandEntry - { - public uint VertexCount; - public uint InstanceCount; - public uint VertexStart; - public uint InstanceStart; - - public DrawEntry() { } - - public DrawEntry(uint vertexCount, uint instanceCount, uint vertexStart, uint instanceStart) - { - VertexCount = vertexCount; - InstanceCount = instanceCount; - VertexStart = vertexStart; - InstanceStart = instanceStart; - } - - public DrawEntry Init(uint vertexCount, uint instanceCount, uint vertexStart, uint instanceStart) - { - VertexCount = vertexCount; - InstanceCount = instanceCount; - VertexStart = vertexStart; - InstanceStart = instanceStart; - - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedEntry.cs deleted file mode 100644 index 7673145e3..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedEntry.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DrawIndexedEntry : OpenGLCommandEntry - { - public uint IndexCount; - public uint InstanceCount; - public uint IndexStart; - public int VertexOffset; - public uint InstanceStart; - - public DrawIndexedEntry(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart) - { - IndexCount = indexCount; - InstanceCount = instanceCount; - IndexStart = indexStart; - VertexOffset = vertexOffset; - InstanceStart = instanceStart; - } - - public DrawIndexedEntry() { } - - public DrawIndexedEntry Init(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart) - { - IndexCount = indexCount; - InstanceCount = instanceCount; - IndexStart = indexStart; - VertexOffset = vertexOffset; - InstanceStart = instanceStart; - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedIndirectEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedIndirectEntry.cs deleted file mode 100644 index f33ec961a..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndexedIndirectEntry.cs +++ /dev/null @@ -1,35 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DrawIndexedIndirectEntry : OpenGLCommandEntry - { - public DeviceBuffer IndirectBuffer; - public uint Offset; - public uint DrawCount; - public uint Stride; - - public DrawIndexedIndirectEntry() { } - - public DrawIndexedIndirectEntry(DeviceBuffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - DrawCount = drawCount; - Stride = stride; - } - - public DrawIndexedIndirectEntry Init(DeviceBuffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - DrawCount = drawCount; - Stride = stride; - - return this; - } - - public override void ClearReferences() - { - IndirectBuffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndirectEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/DrawIndirectEntry.cs deleted file mode 100644 index 464ec1f71..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/DrawIndirectEntry.cs +++ /dev/null @@ -1,35 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class DrawIndirectEntry : OpenGLCommandEntry - { - public DeviceBuffer IndirectBuffer; - public uint Offset; - public uint DrawCount; - public uint Stride; - - public DrawIndirectEntry() { } - - public DrawIndirectEntry(DeviceBuffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - DrawCount = drawCount; - Stride = stride; - } - - public DrawIndirectEntry Init(DeviceBuffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - IndirectBuffer = indirectBuffer; - Offset = offset; - DrawCount = drawCount; - Stride = stride; - - return this; - } - - public override void ClearReferences() - { - IndirectBuffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/EndEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/EndEntry.cs deleted file mode 100644 index ce5299bfa..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/EndEntry.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class EndEntry : OpenGLCommandEntry - { - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLCommandEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/OpenGLCommandEntry.cs deleted file mode 100644 index 0f1e4b3cc..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLCommandEntry.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal abstract class OpenGLCommandEntry - { - public abstract void ClearReferences(); - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLManagedCommandEntryList.cs b/src/Veldrid/OpenGL/ManagedEntryList/OpenGLManagedCommandEntryList.cs deleted file mode 100644 index 4dd808ca8..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLManagedCommandEntryList.cs +++ /dev/null @@ -1,262 +0,0 @@ -#if OPENGL_MANAGED_COMMAND_ENTRY_LIST -using System; -using System.Collections.Generic; - -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class OpenGLManagedCommandEntryList : OpenGLCommandEntryList - { - private readonly List _commands = new List(); - private readonly StagingMemoryPool _memoryPool = new StagingMemoryPool(); - - public IReadOnlyList Commands => _commands; - - public void Reset() - { - _commands.Clear(); - } - - public void Begin() - { - _commands.Add(new BeginEntry()); - } - - public void ClearColorTarget(uint index, RgbaFloat clearColor) - { - _commands.Add(new ClearColorTargetEntry(index, clearColor)); - } - - public void ClearDepthTarget(float depth) - { - _commands.Add(new ClearDepthTargetEntry(depth)); - } - - public void Draw(uint vertexCount, uint instanceCount, uint vertexStart, uint instanceStart) - { - _commands.Add(new DrawEntry(vertexCount, instanceCount, vertexStart, instanceStart)); - } - - public void DrawIndexed(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart) - { - _commands.Add(new DrawIndexedEntry(indexCount, instanceCount, indexStart, vertexOffset, instanceStart)); - } - - public void DrawIndirect(Buffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - _commands.Add(new DrawIndirectEntry(indirectBuffer, offset, drawCount, stride)); - } - - public void DrawIndexedIndirect(Buffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - _commands.Add(new DrawIndexedIndirectEntry(indirectBuffer, offset, drawCount, stride)); - } - - public void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ) - { - _commands.Add(new DispatchEntry(groupCountX, groupCountY, groupCountZ)); - } - - public void DispatchIndirect(Buffer indirectBuffer, uint offset) - { - _commands.Add(new DispatchIndirectEntry(indirectBuffer, offset)); - } - - public void End() - { - _commands.Add(new EndEntry()); - } - - public void SetFramebuffer(Framebuffer fb) - { - _commands.Add(new SetFramebufferEntry(fb)); - } - - public void SetIndexBuffer(Buffer buffer, IndexFormat format) - { - _commands.Add(new SetIndexBufferEntry(buffer, format)); - } - - public void SetPipeline(Pipeline pipeline) - { - _commands.Add(new SetPipelineEntry(pipeline)); - } - - public void SetGraphicsResourceSet(uint slot, ResourceSet rs) - { - _commands.Add(new SetGraphicsResourceSetEntry(slot, rs)); - } - - public void SetComputeResourceSet(uint slot, ResourceSet rs) - { - _commands.Add(new SetComputeResourceSetEntry(slot, rs)); - } - - public void SetScissorRect(uint index, uint x, uint y, uint width, uint height) - { - _commands.Add(new SetScissorRectEntry(index, x, y, width, height)); - } - - public void SetVertexBuffer(uint index, Buffer vb) - { - _commands.Add(new SetVertexBufferEntry(index, vb)); - } - - public void SetViewport(uint index, ref Viewport viewport) - { - _commands.Add(new SetViewportEntry(index, ref viewport)); - } - - public void UpdateBuffer(Buffer buffer, uint bufferOffsetInBytes, IntPtr source, uint sizeInBytes) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add(new UpdateBufferEntry(buffer, bufferOffsetInBytes, stagingBlock)); - } - - public void UpdateTexture( - Texture texture, - IntPtr source, - uint sizeInBytes, - uint x, - uint y, - uint z, - uint width, - uint height, - uint depth, - uint mipLevel, - uint arrayLayer) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add(new UpdateTextureEntry(texture, stagingBlock, x, y, z, width, height, depth, mipLevel, arrayLayer)); - } - - public void UpdateTextureCube( - Texture textureCube, - IntPtr source, - uint sizeInBytes, - CubeFace face, - uint x, - uint y, - uint width, - uint height, - uint mipLevel, - uint arrayLayer) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add( - new UpdateTextureCubeEntry(textureCube, stagingBlock, face, x, y, width, height, mipLevel, arrayLayer)); - } - - public void ResolveTexture(Texture source, Texture destination) - { - _commands.Add(new ResolveTextureEntry(source, destination)); - - } - - public unsafe void ExecuteAll(OpenGLCommandExecutor executor) - { - foreach (OpenGLCommandEntry entry in _commands) - { - switch (entry) - { - case BeginEntry be: - executor.Begin(); - break; - case ClearColorTargetEntry ccte: - executor.ClearColorTarget(ccte.Index, ccte.ClearColor); - break; - case ClearDepthTargetEntry cdte: - executor.ClearDepthTarget(cdte.Depth); - break; - case DrawEntry de: - executor.Draw(de.VertexCount, de.InstanceCount, de.VertexCount, de.InstanceCount); - break; - case DrawIndexedEntry dIdx: - executor.DrawIndexed(dIdx.IndexCount, dIdx.InstanceCount, dIdx.IndexStart, dIdx.VertexOffset, dIdx.InstanceCount); - break; - case DrawIndirectEntry dInd: - executor.DrawIndirect(dInd.IndirectBuffer, dInd.Offset, dInd.DrawCount, dInd.Stride); - break; - case DrawIndexedIndirectEntry dIdxInd: - executor.DrawIndexedIndirect(dIdxInd.IndirectBuffer, dIdxInd.Offset, dIdxInd.DrawCount, dIdxInd.Stride); - break; - case DispatchEntry dispatch: - executor.Dispatch(dispatch.GroupCountX, dispatch.GroupCountY, dispatch.GroupCountZ); - break; - case DispatchIndirectEntry dispInd: - executor.DispatchIndirect(dispInd.IndirectBuffer, dispInd.Offset); - break; - case EndEntry ee: - executor.End(); - break; - case SetFramebufferEntry sfbe: - executor.SetFramebuffer(sfbe.Framebuffer); - break; - case SetIndexBufferEntry sibe: - executor.SetIndexBuffer(sibe.Buffer, sibe.Format); - break; - case SetPipelineEntry spe: - executor.SetPipeline(spe.Pipeline); - break; - case SetGraphicsResourceSetEntry srse: - executor.SetGraphicsResourceSet(srse.Slot, srse.ResourceSet); - break; - case SetScissorRectEntry ssre: - executor.SetScissorRect(ssre.Index, ssre.X, ssre.Y, ssre.Width, ssre.Height); - break; - case SetVertexBufferEntry svbe: - executor.SetVertexBuffer(svbe.Index, svbe.Buffer); - break; - case SetViewportEntry sve: - executor.SetViewport(sve.Index, ref sve.Viewport); - break; - case UpdateBufferEntry ube: - fixed (byte* dataPtr = &ube.StagingBlock.Array[0]) - { - executor.UpdateBuffer(ube.Buffer, ube.BufferOffsetInBytes, (IntPtr)dataPtr, ube.StagingBlock.SizeInBytes); - } - ube.StagingBlock.Free(); - break; - case UpdateTextureEntry ute: - fixed (byte* dataPtr = &ute.StagingBlock.Array[0]) - { - executor.UpdateTexture( - ute.Texture, - (IntPtr)dataPtr, - ute.X, - ute.Y, - ute.Z, - ute.Width, - ute.Height, - ute.Depth, - ute.MipLevel, - ute.ArrayLayer); - } - ute.StagingBlock.Free(); - break; - case UpdateTextureCubeEntry utce: - fixed (byte* dataPtr = &utce.StagingBlock.Array[0]) - { - executor.UpdateTextureCube( - utce.TextureCube, - (IntPtr)dataPtr, - utce.Face, - utce.X, - utce.Y, - utce.Width, - utce.Height, - utce.MipLevel, - utce.ArrayLayer); - } - utce.StagingBlock.Free(); - break; - case ResolveTextureEntry rte: - executor.ResolveTexture(rte.Source, rte.Destination); - break; - default: - throw new InvalidOperationException("Command type not handled: " + executor.GetType().Name); - } - } - } - } -} -#endif diff --git a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLPooledCommandEntryList.cs b/src/Veldrid/OpenGL/ManagedEntryList/OpenGLPooledCommandEntryList.cs deleted file mode 100644 index 80e363681..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/OpenGLPooledCommandEntryList.cs +++ /dev/null @@ -1,335 +0,0 @@ -#if OPENGL_MANAGED_COMMAND_ENTRY_LIST -using System; -using System.Collections.Generic; - -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class OpenGLPooledCommandEntryList : OpenGLCommandEntryList - { - private readonly List _commands = new List(); - private readonly StagingMemoryPool _memoryPool = new StagingMemoryPool(); - - private readonly EntryPool _beginEntryPool = new EntryPool(); - private readonly EntryPool _clearColorTargetEntryPool = new EntryPool(); - private readonly EntryPool _clearDepthTargetEntryPool = new EntryPool(); - private readonly EntryPool _drawEntryPool = new EntryPool(); - private readonly EntryPool _drawIndexedEntryPool = new EntryPool(); - private readonly EntryPool _dispatchEntryPool = new EntryPool(); - private readonly EntryPool _endEntryPool = new EntryPool(); - private readonly EntryPool _setFramebufferEntryPool = new EntryPool(); - private readonly EntryPool _setIndexBufferEntryPool = new EntryPool(); - private readonly EntryPool _setPipelineEntryPool = new EntryPool(); - private readonly EntryPool _setGraphicsResourceSetEntryPool = new EntryPool(); - private readonly EntryPool _setComputeResourceSetEntryPool = new EntryPool(); - private readonly EntryPool _setScissorRectEntryPool = new EntryPool(); - private readonly EntryPool _setVertexBufferEntryPool = new EntryPool(); - private readonly EntryPool _setViewportEntryPool = new EntryPool(); - private readonly EntryPool _updateBufferEntryPool = new EntryPool(); - private readonly EntryPool _updateTextureEntryPool = new EntryPool(); - private readonly EntryPool _updateTextureCubeEntryPool = new EntryPool(); - private readonly EntryPool _resolveTextureEntryPool = new EntryPool(); - private readonly EntryPool _drawIndirectEntryPool = new EntryPool(); - private readonly EntryPool _drawIndexedIndirectEntryPool = new EntryPool(); - private readonly EntryPool _dispatchIndirectEntryPool = new EntryPool(); - - public IReadOnlyList Commands => _commands; - - public void Reset() - { - _commands.Clear(); - } - - public void Begin() - { - _commands.Add(_beginEntryPool.Rent()); - } - - public void ClearColorTarget(uint index, RgbaFloat clearColor) - { - _commands.Add(_clearColorTargetEntryPool.Rent().Init(index, clearColor)); - } - - public void ClearDepthTarget(float depth) - { - _commands.Add(_clearDepthTargetEntryPool.Rent().Init(depth)); - } - - public void Draw(uint vertexCount, uint instanceCount, uint vertexStart, uint instanceStart) - { - _commands.Add(_drawEntryPool.Rent().Init(vertexCount, instanceCount, vertexStart, instanceStart)); - } - - public void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ) - { - _commands.Add(_dispatchEntryPool.Rent().Init(groupCountX, groupCountY, groupCountZ)); - } - - public void DrawIndexed(uint indexCount, uint instanceCount, uint indexStart, int vertexOffset, uint instanceStart) - { - _commands.Add(_drawIndexedEntryPool.Rent().Init(indexCount, instanceCount, indexStart, vertexOffset, instanceStart)); - } - - public void DrawIndirect(Buffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - _commands.Add(_drawIndirectEntryPool.Rent().Init(indirectBuffer, offset, drawCount, stride)); - } - - public void DrawIndexedIndirect(Buffer indirectBuffer, uint offset, uint drawCount, uint stride) - { - _commands.Add(_drawIndexedIndirectEntryPool.Rent().Init(indirectBuffer, offset, drawCount, stride)); - } - - public void DispatchIndirect(Buffer indirectBuffer, uint offset) - { - _commands.Add(_dispatchIndirectEntryPool.Rent().Init(indirectBuffer, offset)); - } - - public void End() - { - _commands.Add(_endEntryPool.Rent()); - } - - public void SetFramebuffer(Framebuffer fb) - { - _commands.Add(_setFramebufferEntryPool.Rent().Init(fb)); - } - - public void SetIndexBuffer(Buffer buffer, IndexFormat format) - { - _commands.Add(_setIndexBufferEntryPool.Rent().Init(buffer, format)); - } - - public void SetPipeline(Pipeline pipeline) - { - _commands.Add(_setPipelineEntryPool.Rent().Init(pipeline)); - } - - public void SetGraphicsResourceSet(uint slot, ResourceSet rs) - { - _commands.Add(_setGraphicsResourceSetEntryPool.Rent().Init(slot, rs)); - } - - public void SetComputeResourceSet(uint slot, ResourceSet rs) - { - _commands.Add(_setComputeResourceSetEntryPool.Rent().Init(slot, rs)); - } - - public void SetScissorRect(uint index, uint x, uint y, uint width, uint height) - { - _commands.Add(_setScissorRectEntryPool.Rent().Init(index, x, y, width, height)); - } - - public void SetVertexBuffer(uint index, Buffer vb) - { - _commands.Add(_setVertexBufferEntryPool.Rent().Init(index, vb)); - } - - public void SetViewport(uint index, ref Viewport viewport) - { - _commands.Add(_setViewportEntryPool.Rent().Init(index, ref viewport)); - } - - public void UpdateBuffer(Buffer buffer, uint bufferOffsetInBytes, IntPtr source, uint sizeInBytes) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add(_updateBufferEntryPool.Rent().Init(buffer, bufferOffsetInBytes, stagingBlock)); - } - - public void UpdateTexture( - Texture texture, - IntPtr source, - uint sizeInBytes, - uint x, - uint y, - uint z, - uint width, - uint height, - uint depth, - uint mipLevel, - uint arrayLayer) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add(_updateTextureEntryPool.Rent().Init(texture, stagingBlock, x, y, z, width, height, depth, mipLevel, arrayLayer)); - } - - public void UpdateTextureCube( - Texture textureCube, - IntPtr source, - uint sizeInBytes, - CubeFace face, - uint x, - uint y, - uint width, - uint height, - uint mipLevel, - uint arrayLayer) - { - StagingBlock stagingBlock = _memoryPool.Stage(source, sizeInBytes); - _commands.Add(_updateTextureCubeEntryPool.Rent().Init(textureCube, stagingBlock, face, x, y, width, height, mipLevel, arrayLayer)); - } - - public void ResolveTexture(Texture source, Texture destination) - { - _commands.Add(_resolveTextureEntryPool.Rent().Init(source, destination)); - } - - public unsafe void ExecuteAll(OpenGLCommandExecutor executor) - { - foreach (OpenGLCommandEntry entry in _commands) - { - switch (entry) - { - case BeginEntry be: - executor.Begin(); - _beginEntryPool.Return(be); - break; - case ClearColorTargetEntry ccte: - executor.ClearColorTarget(ccte.Index, ccte.ClearColor); - _clearColorTargetEntryPool.Return(ccte); - break; - case ClearDepthTargetEntry cdte: - executor.ClearDepthTarget(cdte.Depth); - _clearDepthTargetEntryPool.Return(cdte); - break; - case DrawEntry de: - executor.Draw(de.VertexCount, de.InstanceCount, de.VertexStart, de.InstanceStart); - _drawEntryPool.Return(de); - break; - case DrawIndexedEntry die: - executor.DrawIndexed(die.IndexCount, die.InstanceCount, die.IndexStart, die.VertexOffset, die.InstanceCount); - _drawIndexedEntryPool.Return(die); - break; - case DrawIndirectEntry dInd: - executor.DrawIndirect(dInd.IndirectBuffer, dInd.Offset, dInd.DrawCount, dInd.Stride); - _drawIndirectEntryPool.Return(dInd); - break; - case DrawIndexedIndirectEntry dIdxInd: - executor.DrawIndexedIndirect(dIdxInd.IndirectBuffer, dIdxInd.Offset, dIdxInd.DrawCount, dIdxInd.Stride); - _drawIndexedIndirectEntryPool.Return(dIdxInd); - break; - case DispatchEntry dispatchEntry: - executor.Dispatch(dispatchEntry.GroupCountX, dispatchEntry.GroupCountY, dispatchEntry.GroupCountZ); - _dispatchEntryPool.Return(dispatchEntry); - break; - case DispatchIndirectEntry dispInd: - executor.DispatchIndirect(dispInd.IndirectBuffer, dispInd.Offset); - _dispatchIndirectEntryPool.Return(dispInd); - break; - case EndEntry ee: - executor.End(); - _endEntryPool.Return(ee); - break; - case SetFramebufferEntry sfbe: - executor.SetFramebuffer(sfbe.Framebuffer); - _setFramebufferEntryPool.Return(sfbe); - break; - case SetIndexBufferEntry sibe: - executor.SetIndexBuffer(sibe.Buffer, sibe.Format); - _setIndexBufferEntryPool.Return(sibe); - break; - case SetPipelineEntry spe: - executor.SetPipeline(spe.Pipeline); - _setPipelineEntryPool.Return(spe); - break; - case SetGraphicsResourceSetEntry sgrse: - executor.SetGraphicsResourceSet(sgrse.Slot, sgrse.ResourceSet); - _setGraphicsResourceSetEntryPool.Return(sgrse); - break; - case SetComputeResourceSetEntry scrse: - executor.SetComputeResourceSet(scrse.Slot, scrse.ResourceSet); - _setComputeResourceSetEntryPool.Return(scrse); - break; - case SetScissorRectEntry ssre: - executor.SetScissorRect(ssre.Index, ssre.X, ssre.Y, ssre.Width, ssre.Height); - _setScissorRectEntryPool.Return(ssre); - break; - case SetVertexBufferEntry svbe: - executor.SetVertexBuffer(svbe.Index, svbe.Buffer); - _setVertexBufferEntryPool.Return(svbe); - break; - case SetViewportEntry sve: - executor.SetViewport(sve.Index, ref sve.Viewport); - _setViewportEntryPool.Return(sve); - break; - case UpdateBufferEntry ube: - fixed (byte* dataPtr = &ube.StagingBlock.Array[0]) - { - executor.UpdateBuffer( - ube.Buffer, - ube.BufferOffsetInBytes, - (IntPtr)dataPtr, - ube.StagingBlock.SizeInBytes); - ube.StagingBlock.Free(); - _updateBufferEntryPool.Return(ube); - } - break; - case UpdateTextureEntry ute: - fixed (byte* dataPtr = &ute.StagingBlock.Array[0]) - { - executor.UpdateTexture( - ute.Texture, - (IntPtr)dataPtr, - ute.X, - ute.Y, - ute.Z, - ute.Width, - ute.Height, - ute.Depth, - ute.MipLevel, - ute.ArrayLayer); - _updateTextureEntryPool.Return(ute); - } - ute.StagingBlock.Free(); - break; - case UpdateTextureCubeEntry utce: - fixed (byte* dataPtr = &utce.StagingBlock.Array[0]) - { - executor.UpdateTextureCube( - utce.TextureCube, - (IntPtr)dataPtr, - utce.Face, - utce.X, - utce.Y, - utce.Width, - utce.Height, - utce.MipLevel, - utce.ArrayLayer); - utce.StagingBlock.Free(); - _updateTextureCubeEntryPool.Return(utce); - } - break; - case ResolveTextureEntry rte: - executor.ResolveTexture(rte.Source, rte.Destination); - _resolveTextureEntryPool.Return(rte); - break; - default: - throw new InvalidOperationException("Command type not handled: " + executor.GetType().Name); - } - } - } - - private class EntryPool where T : OpenGLCommandEntry, new() - { - private readonly Queue _entries = new Queue(); - - public T Rent() - { - if (_entries.Count > 0) - { - return _entries.Dequeue(); - } - else - { - return new T(); - } - } - - public void Return(T entry) - { - entry.ClearReferences(); - _entries.Enqueue(entry); - } - } - } -} -#endif diff --git a/src/Veldrid/OpenGL/ManagedEntryList/ResolveTextureEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/ResolveTextureEntry.cs deleted file mode 100644 index 0d5de51ed..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/ResolveTextureEntry.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class ResolveTextureEntry : OpenGLCommandEntry - { - public Texture Source; - public Texture Destination; - - public ResolveTextureEntry(Texture source, Texture destination) - { - Source = source; - Destination = destination; - } - - public ResolveTextureEntry() { } - - public ResolveTextureEntry Init(Texture source, Texture destination) - { - Source = source; - Destination = destination; - return this; - } - - public override void ClearReferences() - { - Source = null; - Destination = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetComputeResourceSetEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetComputeResourceSetEntry.cs deleted file mode 100644 index 4a050b50b..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetComputeResourceSetEntry.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetComputeResourceSetEntry : OpenGLCommandEntry - { - public uint Slot; - public ResourceSet ResourceSet; - - public SetComputeResourceSetEntry(uint slot, ResourceSet rs) - { - Slot = slot; - ResourceSet = rs; - } - - public SetComputeResourceSetEntry() { } - - public SetComputeResourceSetEntry Init(uint slot, ResourceSet rs) - { - Slot = slot; - ResourceSet = rs; - return this; - } - - public override void ClearReferences() - { - ResourceSet = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetFramebufferEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetFramebufferEntry.cs deleted file mode 100644 index 6c2730a9a..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetFramebufferEntry.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetFramebufferEntry : OpenGLCommandEntry - { - public Framebuffer Framebuffer; - - public SetFramebufferEntry(Framebuffer fb) - { - Framebuffer = fb; - } - - public SetFramebufferEntry() { } - - public SetFramebufferEntry Init(Framebuffer fb) - { - Framebuffer = fb; - return this; - } - - public override void ClearReferences() - { - Framebuffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetGraphicsResourceSetEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetGraphicsResourceSetEntry.cs deleted file mode 100644 index 951c919b3..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetGraphicsResourceSetEntry.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetGraphicsResourceSetEntry : OpenGLCommandEntry - { - public uint Slot; - public ResourceSet ResourceSet; - - public SetGraphicsResourceSetEntry(uint slot, ResourceSet rs) - { - Slot = slot; - ResourceSet = rs; - } - - public SetGraphicsResourceSetEntry() { } - - public SetGraphicsResourceSetEntry Init(uint slot, ResourceSet rs) - { - Slot = slot; - ResourceSet = rs; - return this; - } - - public override void ClearReferences() - { - ResourceSet = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetIndexBufferEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetIndexBufferEntry.cs deleted file mode 100644 index 6b180c939..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetIndexBufferEntry.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetIndexBufferEntry : OpenGLCommandEntry - { - public DeviceBuffer Buffer; - public IndexFormat Format; - - public SetIndexBufferEntry(DeviceBuffer buffer, IndexFormat format) - { - Buffer = buffer; - Format = format; - } - - public SetIndexBufferEntry() { } - - public SetIndexBufferEntry Init(DeviceBuffer buffer, IndexFormat format) - { - Buffer = buffer; - Format = format; - return this; - } - - public override void ClearReferences() - { - Buffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetPipelineEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetPipelineEntry.cs deleted file mode 100644 index 8e32bbd6c..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetPipelineEntry.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetPipelineEntry : OpenGLCommandEntry - { - public Pipeline Pipeline; - - public SetPipelineEntry(Pipeline pipeline) - { - Pipeline = pipeline; - } - - public SetPipelineEntry() { } - - public SetPipelineEntry Init(Pipeline pipeline) - { - Pipeline = pipeline; - return this; - } - - public override void ClearReferences() - { - Pipeline = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetScissorRectEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetScissorRectEntry.cs deleted file mode 100644 index 7628906bc..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetScissorRectEntry.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetScissorRectEntry : OpenGLCommandEntry - { - public uint Index; - public uint X; - public uint Y; - public uint Width; - public uint Height; - - public SetScissorRectEntry(uint index, uint x, uint y, uint width, uint height) - { - Index = index; - X = x; - Y = y; - Width = width; - Height = height; - } - - public SetScissorRectEntry() { } - - public SetScissorRectEntry Init(uint index, uint x, uint y, uint width, uint height) - { - Index = index; - X = x; - Y = y; - Width = width; - Height = height; - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetVertexBufferEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetVertexBufferEntry.cs deleted file mode 100644 index e7a3b9646..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetVertexBufferEntry.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetVertexBufferEntry : OpenGLCommandEntry - { - public uint Index; - public DeviceBuffer Buffer; - - public SetVertexBufferEntry(uint index, DeviceBuffer buffer) - { - Index = index; - Buffer = buffer; - } - - public SetVertexBufferEntry() { } - - public SetVertexBufferEntry Init(uint index, DeviceBuffer buffer) - { - Index = index; - Buffer = buffer; - return this; - } - - public override void ClearReferences() - { - Buffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/SetViewportEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/SetViewportEntry.cs deleted file mode 100644 index fcbf0d8a9..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/SetViewportEntry.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class SetViewportEntry : OpenGLCommandEntry - { - public uint Index; - public Viewport Viewport; - - public SetViewportEntry(uint index, ref Viewport viewport) - { - Index = index; - Viewport = viewport; - } - - public SetViewportEntry() { } - - public SetViewportEntry Init(uint index, ref Viewport viewport) - { - Index = index; - Viewport = viewport; - return this; - } - - public override void ClearReferences() - { - } - } -} diff --git a/src/Veldrid/OpenGL/ManagedEntryList/UpdateBufferEntry.cs b/src/Veldrid/OpenGL/ManagedEntryList/UpdateBufferEntry.cs deleted file mode 100644 index eeec687a5..000000000 --- a/src/Veldrid/OpenGL/ManagedEntryList/UpdateBufferEntry.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Veldrid.OpenGL.ManagedEntryList -{ - internal class UpdateBufferEntry : OpenGLCommandEntry - { - public DeviceBuffer Buffer; - public uint BufferOffsetInBytes; - public StagingBlock StagingBlock; - - public UpdateBufferEntry(DeviceBuffer buffer, uint bufferOffsetInBytes, StagingBlock stagingBlock) - { - Buffer = buffer; - BufferOffsetInBytes = bufferOffsetInBytes; - StagingBlock = stagingBlock; - } - - public UpdateBufferEntry() { } - - public UpdateBufferEntry Init(DeviceBuffer buffer, uint bufferOffsetInBytes, StagingBlock stagingBlock) - { - Buffer = buffer; - BufferOffsetInBytes = bufferOffsetInBytes; - StagingBlock = stagingBlock; - return this; - } - - public override void ClearReferences() - { - Buffer = null; - } - } -} diff --git a/src/Veldrid/OpenGL/NoAllocEntryList/OpenGLNoAllocCommandEntryList.cs b/src/Veldrid/OpenGL/NoAllocEntryList/OpenGLNoAllocCommandEntryList.cs index 1ff2fc499..8515d6cd7 100644 --- a/src/Veldrid/OpenGL/NoAllocEntryList/OpenGLNoAllocCommandEntryList.cs +++ b/src/Veldrid/OpenGL/NoAllocEntryList/OpenGLNoAllocCommandEntryList.cs @@ -623,7 +623,7 @@ private struct EntryStorageBlock : IEquatable { private const int default_storage_block_size = 40000; private readonly byte[] bytes; - private readonly GCHandle gcHandle; + private GCHandle gcHandle; public readonly byte* BasePtr; private uint unusedStart; @@ -683,7 +683,7 @@ internal struct Tracked where T : class { private readonly int index; - public T Get(List list) + public readonly T Get(List list) { return (T)list[index]; } diff --git a/src/Veldrid/OpenGL/OpenGLBuffer.cs b/src/Veldrid/OpenGL/OpenGLBuffer.cs index 5f4362b38..fe28a97fe 100644 --- a/src/Veldrid/OpenGL/OpenGLBuffer.cs +++ b/src/Veldrid/OpenGL/OpenGLBuffer.cs @@ -71,13 +71,14 @@ public void CreateGLResources() if (gd.Extensions.ArbDirectStateAccess) { - uint buffer; - glCreateBuffers(1, &buffer); + uint b; + glCreateBuffers(1, &b); CheckLastError(); - this.buffer = buffer; + + buffer = b; glNamedBufferData( - this.buffer, + buffer, SizeInBytes, null, dynamic ? BufferUsageHint.DynamicDraw : BufferUsageHint.StaticDraw); @@ -104,8 +105,8 @@ public void CreateGLResources() public void DestroyGLResources() { - uint buffer = this.buffer; - glDeleteBuffers(1, ref buffer); + uint b = buffer; + glDeleteBuffers(1, ref b); CheckLastError(); } } diff --git a/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs b/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs index d12a2755c..b80e0c0a7 100644 --- a/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs +++ b/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs @@ -580,11 +580,10 @@ public void UpdateBuffer(DeviceBuffer buffer, uint bufferOffsetInBytes, IntPtr d } else { - var bufferTarget = BufferTarget.CopyWriteBuffer; - glBindBuffer(bufferTarget, glBuffer.Buffer); + glBindBuffer(BufferTarget.CopyWriteBuffer, glBuffer.Buffer); CheckLastError(); glBufferSubData( - bufferTarget, + BufferTarget.CopyWriteBuffer, (IntPtr)bufferOffsetInBytes, sizeInBytes, dataPtr.ToPointer()); @@ -625,7 +624,7 @@ public void UpdateTexture( // Compressed textures can specify regions that are larger than the dimensions. // We should only pass up to the dimensions to OpenGL, though. - Util.GetMipDimensions(glTex, mipLevel, out uint mipWidth, out uint mipHeight, out uint mipDepth); + Util.GetMipDimensions(glTex, mipLevel, out uint mipWidth, out uint mipHeight, out uint _); width = Math.Min(width, mipWidth); height = Math.Min(height, mipHeight); @@ -1705,7 +1704,7 @@ private void copyRoundabout( textureSamplerManager.SetTextureTransient(dstTarget, dstGLTexture.Texture); CheckLastError(); - Util.GetMipDimensions(srcGLTexture, srcMipLevel, out uint mipWidth, out uint mipHeight, out uint mipDepth); + Util.GetMipDimensions(srcGLTexture, srcMipLevel, out uint mipWidth, out uint mipHeight, out uint _); uint fullRowPitch = FormatHelpers.GetRowPitch(mipWidth, srcGLTexture.Format); uint fullDepthPitch = FormatHelpers.GetDepthPitch( fullRowPitch, diff --git a/src/Veldrid/OpenGL/OpenGLCommandList.cs b/src/Veldrid/OpenGL/OpenGLCommandList.cs index 245027399..c79ad5576 100644 --- a/src/Veldrid/OpenGL/OpenGLCommandList.cs +++ b/src/Veldrid/OpenGL/OpenGLCommandList.cs @@ -185,7 +185,7 @@ private IOpenGLCommandEntryList getFreeCommandList() { if (availableLists.Count > 0) { - var ret = availableLists[availableLists.Count - 1]; + var ret = availableLists[^1]; availableLists.RemoveAt(availableLists.Count - 1); return ret; } diff --git a/src/Veldrid/OpenGL/OpenGLExtensions.cs b/src/Veldrid/OpenGL/OpenGLExtensions.cs index 8666440d8..b9608bc09 100644 --- a/src/Veldrid/OpenGL/OpenGLExtensions.cs +++ b/src/Veldrid/OpenGL/OpenGLExtensions.cs @@ -52,7 +52,7 @@ internal OpenGLExtensions(HashSet extensions, GraphicsBackend backend, i ArbDirectStateAccess = IsExtensionSupported("GL_ARB_direct_state_access"); ArbMultiBind = IsExtensionSupported("GL_ARB_multi_bind"); ArbTextureView = GLVersion(4, 3) || IsExtensionSupported("GL_ARB_texture_view") // OpenGL 4.3 - || IsExtensionSupported("GL_OES_texture_view"); + || IsExtensionSupported("GL_OES_texture_view"); CopyImage = IsExtensionSupported("GL_ARB_copy_image") || GLESVersion(3, 2) || IsExtensionSupported("GL_OES_copy_image") diff --git a/src/Veldrid/OpenGL/OpenGLFramebuffer.cs b/src/Veldrid/OpenGL/OpenGLFramebuffer.cs index bdfe73437..f3542ba3d 100644 --- a/src/Veldrid/OpenGL/OpenGLFramebuffer.cs +++ b/src/Veldrid/OpenGL/OpenGLFramebuffer.cs @@ -110,16 +110,13 @@ public void CreateGLResources() CheckLastError(); } - uint depthTextureID = 0; - var depthTarget = TextureTarget.Texture2D; - if (DepthTarget != null) { var glDepthTex = Util.AssertSubtype(DepthTarget.Value.Target); glDepthTex.EnsureResourcesCreated(); - depthTarget = glDepthTex.TextureTarget; - depthTextureID = glDepthTex.Texture; + var depthTarget = glDepthTex.TextureTarget; + uint depthTextureID = glDepthTex.Texture; gd.TextureSamplerManager.SetTextureTransient(depthTarget, glDepthTex.Texture); CheckLastError(); @@ -163,8 +160,9 @@ public void DestroyGLResources() if (!disposed) { disposed = true; - uint framebuffer = this.framebuffer; - glDeleteFramebuffers(1, ref framebuffer); + + uint f = framebuffer; + glDeleteFramebuffers(1, ref f); CheckLastError(); } } diff --git a/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs b/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs index 9b945c0a6..fdfef713e 100644 --- a/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs +++ b/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -89,7 +90,6 @@ private readonly Dictionary makeCurrent; - private Func getCurrentContext; private Action deleteContext; private Action swapBuffers; private Action setSyncToVBlank; @@ -101,8 +101,8 @@ private readonly Dictionary workItems; @@ -167,10 +167,10 @@ public override bool WaitForFences(Fence[] fences, bool waitAll, ulong nanosecon bool result; if (waitAll) - result = WaitHandle.WaitAll(events, msTimeout); + result = WaitHandle.WaitAll(events.Cast().ToArray(), msTimeout); else { - int index = WaitHandle.WaitAny(events, msTimeout); + int index = WaitHandle.WaitAny(events.Cast().ToArray(), msTimeout); result = index != WaitHandle.WaitTimeout; } @@ -327,7 +327,6 @@ private void init( syncToVBlank = options.SyncToVerticalBlank; glContext = platformInfo.OpenGLContextHandle; makeCurrent = platformInfo.MakeCurrent; - getCurrentContext = platformInfo.GetCurrentContext; deleteContext = platformInfo.DeleteContext; swapBuffers = platformInfo.SwapBuffers; setSyncToVBlank = platformInfo.SetSyncToVerticalBlank; @@ -336,7 +335,7 @@ private void init( ShadingLanguageVersion = Util.GetString(glGetString(StringName.ShadingLanguageVersion)); vendorName = Util.GetString(glGetString(StringName.Vendor)); deviceName = Util.GetString(glGetString(StringName.Renderer)); - backendType = Version.StartsWith("OpenGL ES") ? GraphicsBackend.OpenGLES : GraphicsBackend.OpenGL; + backendType = Version.StartsWith("OpenGL ES", StringComparison.Ordinal) ? GraphicsBackend.OpenGLES : GraphicsBackend.OpenGL; LoadAllFunctions(glContext, platformInfo.GetProcAddress, backendType == GraphicsBackend.OpenGLES); @@ -445,34 +444,30 @@ private void init( TextureSamplerManager = new OpenGLTextureSamplerManager(Extensions); commandExecutor = new OpenGLCommandExecutor(this, platformInfo); - int maxColorTextureSamples; + int maxColorTextureSamplesInt; if (backendType == GraphicsBackend.OpenGL) { - glGetIntegerv(GetPName.MaxColorTextureSamples, &maxColorTextureSamples); + glGetIntegerv(GetPName.MaxColorTextureSamples, &maxColorTextureSamplesInt); CheckLastError(); } else { - glGetIntegerv(GetPName.MaxSamples, &maxColorTextureSamples); + glGetIntegerv(GetPName.MaxSamples, &maxColorTextureSamplesInt); CheckLastError(); } - if (maxColorTextureSamples >= 32) - this.maxColorTextureSamples = TextureSampleCount.Count32; - else if (maxColorTextureSamples >= 16) - this.maxColorTextureSamples = TextureSampleCount.Count16; - else if (maxColorTextureSamples >= 8) - this.maxColorTextureSamples = TextureSampleCount.Count8; - else if (maxColorTextureSamples >= 4) - this.maxColorTextureSamples = TextureSampleCount.Count4; - else if (maxColorTextureSamples >= 2) - this.maxColorTextureSamples = TextureSampleCount.Count2; - else - this.maxColorTextureSamples = TextureSampleCount.Count1; + maxColorTextureSamples = maxColorTextureSamplesInt switch + { + >= 32 => TextureSampleCount.Count32, + >= 16 => TextureSampleCount.Count16, + >= 8 => TextureSampleCount.Count8, + >= 4 => TextureSampleCount.Count4, + >= 2 => TextureSampleCount.Count2, + _ => TextureSampleCount.Count1 + }; int maxTexSize; - glGetIntegerv(GetPName.MaxTextureSize, &maxTexSize); CheckLastError(); @@ -492,8 +487,8 @@ private void init( } maxTextureSize = (uint)maxTexSize; - this.maxTexDepth = (uint)maxTexDepth; - this.maxTexArrayLayers = (uint)maxTexArrayLayers; + maxTextureDepth = (uint)maxTexDepth; + maxTextureArrayLayers = (uint)maxTexArrayLayers; mainSwapchain = new OpenGLSwapchain( this, @@ -633,9 +628,9 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) CheckLastError(); uint depthRb = 0; - bool hasDepth = options.SwapchainDepthFormat != null; + PixelFormat? depthFormat = options.SwapchainDepthFormat; - if (hasDepth) + if (depthFormat != null) { glGenRenderbuffers(1, out depthRb); CheckLastError(); @@ -645,7 +640,7 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) glRenderbufferStorage( RenderbufferTarget.Renderbuffer, - (uint)OpenGLFormats.VdToGLSizedInternalFormat(options.SwapchainDepthFormat.Value, true), + (uint)OpenGLFormats.VdToGLSizedInternalFormat(depthFormat.Value, true), (uint)fbWidth, (uint)fbHeight); CheckLastError(); @@ -670,7 +665,7 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) if (!EaglContext.SetCurrentContext(ctx)) throw new VeldridException("Unable to set the thread's current GL context."); }; - Action swapBuffers = () => + Action swapBuffersFunc = () => { glBindRenderbuffer(RenderbufferTarget.Renderbuffer, colorRb); CheckLastError(); @@ -712,7 +707,7 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) out int newHeight); CheckLastError(); - if (hasDepth) + if (depthFormat != null) { Debug.Assert(depthRb != 0); glBindRenderbuffer(RenderbufferTarget.Renderbuffer, depthRb); @@ -720,7 +715,7 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) glRenderbufferStorage( RenderbufferTarget.Renderbuffer, - (uint)OpenGLFormats.VdToGLSizedInternalFormat(options.SwapchainDepthFormat.Value, true), + (uint)OpenGLFormats.VdToGLSizedInternalFormat(depthFormat.Value, true), (uint)newWidth, (uint)newHeight); CheckLastError(); @@ -743,7 +738,7 @@ private void initializeUIView(GraphicsDeviceOptions options, IntPtr uIViewPtr) () => EaglContext.CurrentContext.NativePtr, () => setCurrentContext(IntPtr.Zero), destroyContext, - swapBuffers, + swapBuffersFunc, syncInterval => { }, setSwapchainFramebuffer, resizeSwapchain); @@ -807,19 +802,19 @@ private void initializeANativeWindow( IntPtr context = eglCreateContext(display, bestConfig, IntPtr.Zero, contextAttribs); if (context == IntPtr.Zero) throw new VeldridException("Failed to create an EGLContext: " + eglGetError()); - Action makeCurrent = ctx => + Action makeCurrentFunc = ctx => { if (eglMakeCurrent(display, eglWindowSurface, eglWindowSurface, ctx) == 0) throw new VeldridException($"Failed to make the EGLContext {ctx} current: {eglGetError()}"); }; - makeCurrent(context); + makeCurrentFunc(context); Action clearContext = () => { if (eglMakeCurrent(display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) == 0) throw new VeldridException("Failed to clear the current EGLContext: " + eglGetError()); }; - Action swapBuffers = () => + Action swapBuffersFunc = () => { if (eglSwapBuffers(display, eglWindowSurface) == 0) throw new VeldridException("Failed to swap buffers: " + eglGetError()); }; @@ -840,11 +835,11 @@ private void initializeANativeWindow( var platformInfo = new OpenGLPlatformInfo( context, eglGetProcAddress, - makeCurrent, + makeCurrentFunc, eglGetCurrentContext, clearContext, destroyContext, - swapBuffers, + swapBuffersFunc, setSync); init(options, platformInfo, swapchainDescription.Width, swapchainDescription.Height, true); @@ -975,9 +970,9 @@ private protected override bool GetPixelFormatSupportCore( properties = new PixelFormatProperties( maxTextureSize, type == TextureType.Texture1D ? 1 : maxTextureSize, - type != TextureType.Texture3D ? 1 : maxTexDepth, + type != TextureType.Texture3D ? 1 : maxTextureDepth, uint.MaxValue, - type == TextureType.Texture3D ? 1 : maxTexArrayLayers, + type == TextureType.Texture3D ? 1 : maxTextureArrayLayers, sampleCounts); return true; } @@ -1280,7 +1275,7 @@ private void executeWorkItem(ExecutionThreadWorkItem workItem) case WorkItemType.SetSyncToVerticalBlank: { - bool value = workItem.UInt0 == 1 ? true : false; + bool value = workItem.UInt0 == 1; gd.setSyncToVBlank(value); } break; @@ -1695,6 +1690,8 @@ private struct ExecutionThreadWorkItem public readonly object Object1; public readonly uint UInt0; public readonly uint UInt1; + + // ReSharper disable once NotAccessedField.Local public readonly uint UInt2; public ExecutionThreadWorkItem( diff --git a/src/Veldrid/OpenGL/OpenGLPipeline.cs b/src/Veldrid/OpenGL/OpenGLPipeline.cs index 772f45a42..6f9a1026c 100644 --- a/src/Veldrid/OpenGL/OpenGLPipeline.cs +++ b/src/Veldrid/OpenGL/OpenGLPipeline.cs @@ -200,7 +200,6 @@ private void processResourceSetLayouts(ResourceLayout[] layouts) { int resourceLayoutCount = layouts.Length; setInfos = new SetBindingsInfo[resourceLayoutCount]; - int lastTextureLocation = -1; int relativeTextureIndex = -1; int relativeImageIndex = -1; uint storageBlockIndex = 0; // Tracks OpenGL ES storage buffers. @@ -239,7 +238,6 @@ private void processResourceSetLayouts(ResourceLayout[] layouts) int location = getUniformLocation(resource.Name); relativeTextureIndex += 1; textureBindings[i] = new OpenGLTextureBindingSlotInfo { RelativeIndex = relativeTextureIndex, UniformLocation = location }; - lastTextureLocation = location; samplerTrackedRelativeTextureIndices.Add(relativeTextureIndex); } else if (resource.Kind == ResourceKind.TextureReadWrite) diff --git a/src/Veldrid/OpenGL/OpenGLSampler.cs b/src/Veldrid/OpenGL/OpenGLSampler.cs index de38b6717..85c02e3b5 100644 --- a/src/Veldrid/OpenGL/OpenGLSampler.cs +++ b/src/Veldrid/OpenGL/OpenGLSampler.cs @@ -63,8 +63,8 @@ public void EnsureResourcesCreated() if (gd.Extensions.KhrDebug) { - SetObjectLabel(ObjectLabelIdentifier.Sampler, noMipmapState.Sampler, string.Format("{0}_WithoutMipmapping", name)); - SetObjectLabel(ObjectLabelIdentifier.Sampler, mipmapState.Sampler, string.Format("{0}_WithMipmapping", name)); + SetObjectLabel(ObjectLabelIdentifier.Sampler, noMipmapState.Sampler, $"{name}_WithoutMipmapping"); + SetObjectLabel(ObjectLabelIdentifier.Sampler, mipmapState.Sampler, $"{name}_WithMipmapping"); } } } diff --git a/src/Veldrid/OpenGL/OpenGLShader.cs b/src/Veldrid/OpenGL/OpenGLShader.cs index 42e09ba74..496b52f8f 100644 --- a/src/Veldrid/OpenGL/OpenGLShader.cs +++ b/src/Veldrid/OpenGL/OpenGLShader.cs @@ -34,18 +34,19 @@ public override string Name public OpenGLShader(OpenGLGraphicsDevice gd, ShaderStages stage, StagingBlock stagingBlock, string entryPoint) : base(stage, entryPoint) { + this.gd = gd; + this.stagingBlock = stagingBlock; + shaderType = OpenGLFormats.VdToGLShaderType(stage); + #if VALIDATE_USAGE if (stage == ShaderStages.Compute && !gd.Extensions.ComputeShaders) { - if (this.gd.BackendType == GraphicsBackend.OpenGLES) + if (gd.BackendType == GraphicsBackend.OpenGLES) throw new VeldridException("Compute shaders require OpenGL ES 3.1."); throw new VeldridException("Compute shaders require OpenGL 4.3 or ARB_compute_shader."); } #endif - this.gd = gd; - shaderType = OpenGLFormats.VdToGLShaderType(stage); - this.stagingBlock = stagingBlock; } #region Disposal @@ -118,9 +119,7 @@ private void createGLResources() glGetShaderInfoLog(Shader, (uint)infoLogLength, &returnedInfoLength, infoLog); CheckLastError(); - string message = infoLog != null - ? Encoding.UTF8.GetString(infoLog, (int)returnedInfoLength) - : ""; + string message = Encoding.UTF8.GetString(infoLog, (int)returnedInfoLength); throw new VeldridException($"Unable to compile shader code for shader [{name}] of type {shaderType}: {message}"); } diff --git a/src/Veldrid/OpenGL/OpenGLSwapchainFramebuffer.cs b/src/Veldrid/OpenGL/OpenGLSwapchainFramebuffer.cs index a6b0b3bbc..ad6f585d5 100644 --- a/src/Veldrid/OpenGL/OpenGLSwapchainFramebuffer.cs +++ b/src/Veldrid/OpenGL/OpenGLSwapchainFramebuffer.cs @@ -11,17 +11,15 @@ internal class OpenGLSwapchainFramebuffer : Framebuffer public override bool IsDisposed => disposed; public override IReadOnlyList ColorTargets => colorTargets; - public override FramebufferAttachment? DepthTarget => depthTarget; + public override FramebufferAttachment? DepthTarget { get; } public bool DisableSrgbConversion { get; } public override string Name { get; set; } - private readonly PixelFormat? depthFormat; private readonly OpenGLPlaceholderTexture colorTexture; private readonly OpenGLPlaceholderTexture depthTexture; private readonly FramebufferAttachment[] colorTargets; - private readonly FramebufferAttachment? depthTarget; private bool disposed; internal OpenGLSwapchainFramebuffer( @@ -30,10 +28,9 @@ internal OpenGLSwapchainFramebuffer( PixelFormat? depthFormat, bool disableSrgbConversion) { - this.depthFormat = depthFormat; // This is wrong, but it's not really used. - var depthDesc = this.depthFormat != null - ? new OutputAttachmentDescription(this.depthFormat.Value) + var depthDesc = depthFormat != null + ? new OutputAttachmentDescription(depthFormat.Value) : (OutputAttachmentDescription?)null; OutputDescription = new OutputDescription( depthDesc, @@ -47,7 +44,7 @@ internal OpenGLSwapchainFramebuffer( TextureSampleCount.Count1); colorTargets = new[] { new FramebufferAttachment(colorTexture, 0) }; - if (this.depthFormat != null) + if (depthFormat != null) { depthTexture = new OpenGLPlaceholderTexture( width, @@ -55,7 +52,7 @@ internal OpenGLSwapchainFramebuffer( depthFormat.Value, TextureUsage.DepthStencil, TextureSampleCount.Count1); - depthTarget = new FramebufferAttachment(depthTexture, 0); + DepthTarget = new FramebufferAttachment(depthTexture, 0); } OutputDescription = OutputDescription.CreateFromFramebuffer(this); diff --git a/src/Veldrid/OpenGL/OpenGLTexture.cs b/src/Veldrid/OpenGL/OpenGLTexture.cs index 983997333..491e118da 100644 --- a/src/Veldrid/OpenGL/OpenGLTexture.cs +++ b/src/Veldrid/OpenGL/OpenGLTexture.cs @@ -281,10 +281,10 @@ private void createGLResources() if (dsa) { - uint texture; - glCreateTextures(TextureTarget, 1, &texture); + uint t; + glCreateTextures(TextureTarget, 1, &t); CheckLastError(); - this.texture = texture; + texture = t; } else { diff --git a/src/Veldrid/OpenGL/OpenGLTextureSamplerManager.cs b/src/Veldrid/OpenGL/OpenGLTextureSamplerManager.cs index 1d642e8ea..99cc3d84d 100644 --- a/src/Veldrid/OpenGL/OpenGLTextureSamplerManager.cs +++ b/src/Veldrid/OpenGL/OpenGLTextureSamplerManager.cs @@ -11,7 +11,6 @@ namespace Veldrid.OpenGL internal unsafe class OpenGLTextureSamplerManager { private readonly bool dsaAvailable; - private readonly int maxTextureUnits; private readonly uint lastTextureUnit; private readonly OpenGLTextureView[] textureUnitTextures; private readonly BoundSamplerStateInfo[] textureUnitSamplers; @@ -20,14 +19,15 @@ internal unsafe class OpenGLTextureSamplerManager public OpenGLTextureSamplerManager(OpenGLExtensions extensions) { dsaAvailable = extensions.ArbDirectStateAccess; - int maxTextureUnits; - glGetIntegerv(GetPName.MaxCombinedTextureImageUnits, &maxTextureUnits); + + int maxTexUnits; + glGetIntegerv(GetPName.MaxCombinedTextureImageUnits, &maxTexUnits); CheckLastError(); - this.maxTextureUnits = Math.Max(maxTextureUnits, 8); // OpenGL spec indicates that implementations must support at least 8. - textureUnitTextures = new OpenGLTextureView[this.maxTextureUnits]; - textureUnitSamplers = new BoundSamplerStateInfo[this.maxTextureUnits]; + maxTexUnits = Math.Max(maxTexUnits, 8); // OpenGL spec indicates that implementations must support at least 8. - lastTextureUnit = (uint)(this.maxTextureUnits - 1); + textureUnitTextures = new OpenGLTextureView[maxTexUnits]; + textureUnitSamplers = new BoundSamplerStateInfo[maxTexUnits]; + lastTextureUnit = (uint)(maxTexUnits - 1); } public void SetTexture(uint textureUnit, OpenGLTextureView textureView) diff --git a/src/Veldrid/OpenGL/OpenGLTextureView.cs b/src/Veldrid/OpenGL/OpenGLTextureView.cs index 0cd7d4760..8626bc92e 100644 --- a/src/Veldrid/OpenGL/OpenGLTextureView.cs +++ b/src/Veldrid/OpenGL/OpenGLTextureView.cs @@ -280,30 +280,15 @@ private void createGLResources() if (originalTarget == TextureTarget.Texture1D) TextureTarget = TextureTarget.Texture1D; else if (originalTarget == TextureTarget.Texture1DArray) - { - if (ArrayLayers > 1) - TextureTarget = TextureTarget.Texture1DArray; - else - TextureTarget = TextureTarget.Texture1D; - } + TextureTarget = ArrayLayers > 1 ? TextureTarget.Texture1DArray : TextureTarget.Texture1D; else if (originalTarget == TextureTarget.Texture2D) TextureTarget = TextureTarget.Texture2D; else if (originalTarget == TextureTarget.Texture2DArray) - { - if (ArrayLayers > 1) - TextureTarget = TextureTarget.Texture2DArray; - else - TextureTarget = TextureTarget.Texture2D; - } + TextureTarget = ArrayLayers > 1 ? TextureTarget.Texture2DArray : TextureTarget.Texture2D; else if (originalTarget == TextureTarget.Texture2DMultisample) TextureTarget = TextureTarget.Texture2DMultisample; else if (originalTarget == TextureTarget.Texture2DMultisampleArray) - { - if (ArrayLayers > 1) - TextureTarget = TextureTarget.Texture2DMultisampleArray; - else - TextureTarget = TextureTarget.Texture2DMultisample; - } + TextureTarget = ArrayLayers > 1 ? TextureTarget.Texture2DMultisampleArray : TextureTarget.Texture2DMultisample; else if (originalTarget == TextureTarget.Texture3D) TextureTarget = TextureTarget.Texture3D; else if (originalTarget == TextureTarget.TextureCubeMap) diff --git a/src/Veldrid/OpenGL/OpenGLUtil.cs b/src/Veldrid/OpenGL/OpenGLUtil.cs index 2e6cae2cd..71024c302 100644 --- a/src/Veldrid/OpenGL/OpenGLUtil.cs +++ b/src/Veldrid/OpenGL/OpenGLUtil.cs @@ -32,10 +32,10 @@ internal static unsafe void SetObjectLabel(ObjectLabelIdentifier identifier, uin if (maxLabelLength == null) { - int maxLabelLength = -1; - glGetIntegerv(GetPName.MaxLabelLength, &maxLabelLength); + int localMaxLabelLength = -1; + glGetIntegerv(GetPName.MaxLabelLength, &localMaxLabelLength); CheckLastError(); - OpenGLUtil.maxLabelLength = maxLabelLength; + maxLabelLength = localMaxLabelLength; } if (byteCount >= maxLabelLength)