/// <summary> /// defines a barrier ordering memory transactions /// </summary> /// <param name="barriers">Specifies the barriers to insert.</param> public static void MemoryBarrier(MemoryBarrierFlags barriers) { MemoryBarrier((uint)barriers); }
//ARB_shader_image_-load_store /// <summary> /// defines a barrier ordering the memory transactions issued prior to the command relative to those issued after the barrier. /// </summary> /// <param name="barriers">See MemoryBarrierFlags for description of what the flags does.</param> public static void MemoryBarrier(MemoryBarrierFlags barriers) { Delegates.glMemoryBarrier(barriers); }
public void Submit() { //TODO: make this execution task be submitted to the main thread, so construction can happen on a separate thread foreach (CommandEntry c in Commands) { switch (c.Type) { case CommandType.Clear: { GL.Clear((c.ClearColorBuffer ? ClearBufferMask.ColorBufferBit : 0) | (c.ClearDepthBuffer ? ClearBufferMask.DepthBufferBit : 0)); } break; case CommandType.Invalidate: { GraphicsDevice.Framebuffer.Invalidate(); } break; case CommandType.TexUpload: { GL.BindBuffer(BufferTarget.PixelUnpackBuffer, (int)c.Buffer); switch (c.Texture.Target) { case TextureTarget.Texture1D: GL.TextureSubImage1D((int)c.Texture, c.WriteLevel, (int)c.Offset.X, (int)c.Size.X, (OpenTK.Graphics.OpenGL4.PixelFormat)c.Format, (OpenTK.Graphics.OpenGL4.PixelType)c.PixType, IntPtr.Zero); break; case TextureTarget.Texture1DArray: case TextureTarget.Texture2D: case TextureTarget.TextureCubeMap: GL.TextureSubImage2D((int)c.Texture, c.WriteLevel, (int)c.Offset.X, (int)c.Offset.Y, (int)c.Size.X, (int)c.Size.Y, (OpenTK.Graphics.OpenGL4.PixelFormat)c.Format, (OpenTK.Graphics.OpenGL4.PixelType)c.PixType, IntPtr.Zero); break; case TextureTarget.Texture2DArray: case TextureTarget.Texture3D: case TextureTarget.TextureCubeMapArray: GL.TextureSubImage3D((int)c.Texture, c.WriteLevel, (int)c.Offset.X, (int)c.Offset.Y, (int)c.Offset.Z, (int)c.Size.X, (int)c.Size.Y, (int)c.Size.Z, (OpenTK.Graphics.OpenGL4.PixelFormat)c.Format, (OpenTK.Graphics.OpenGL4.PixelType)c.PixType, IntPtr.Zero); break; } c.SyncFence?.PlaceFence(); } break; case CommandType.SwapBuffer: { GraphicsDevice.SwapBuffers(); } break; case CommandType.SetState: { GraphicsDevice.SetRenderState(c.State); } break; case CommandType.Draw: { #if DEBUG GenericMetrics.StartMeasurement(); PerfAPI.BeginDraw(); #endif GL.DrawArraysInstancedBaseInstance((OpenTK.Graphics.OpenGL4.PrimitiveType)c.PrimitiveType, c.First, c.Count, c.InstanceCount, c.BaseInstance); #if DEBUG PerfAPI.EndSample(); GenericMetrics.StopMeasurement(); #endif } break; case CommandType.DrawIndexed: { #if DEBUG GenericMetrics.StartMeasurement(); PerfAPI.BeginDrawIndexed(); #endif GL.DrawElementsInstancedBaseVertexBaseInstance((OpenTK.Graphics.OpenGL4.PrimitiveType)c.PrimitiveType, c.Count, c.IndicesAreShort ? DrawElementsType.UnsignedShort : DrawElementsType.UnsignedInt, (IntPtr)c.IndexOffset, c.InstanceCount, c.First, c.BaseInstance); #if DEBUG PerfAPI.EndSample(); GenericMetrics.StopMeasurement(); #endif } break; case CommandType.MultiDrawIndirect: { #if DEBUG GenericMetrics.StartMeasurement(); PerfAPI.BeginMultiDrawIndirectCount(); #endif GL.BindBuffer(BufferTarget.DrawIndirectBuffer, (int)c.Buffer); GL.BindBuffer((BufferTarget)ArbIndirectParameters.ParameterBufferArb, (int)c.Buffer); GL.MultiDrawArraysIndirectCount((OpenTK.Graphics.OpenGL4.PrimitiveType)c.PrimitiveType, (IntPtr)c.IndirectOffset, (IntPtr)c.DrawCountOffset, c.MaxDrawCount, c.IndirectStride); #if DEBUG PerfAPI.EndSample(); GenericMetrics.StopMeasurement(); #endif } break; case CommandType.MultiDrawIndirectIndexed: { #if DEBUG GenericMetrics.StartMeasurement(); PerfAPI.BeginMultiDrawIndirectIndexedCount(); #endif GL.BindBuffer(BufferTarget.DrawIndirectBuffer, (int)c.Buffer); GL.BindBuffer((BufferTarget)ArbIndirectParameters.ParameterBufferArb, (int)c.Buffer); GL.MultiDrawElementsIndirectCount((OpenTK.Graphics.OpenGL4.PrimitiveType)c.PrimitiveType, c.IndicesAreShort ? All.UnsignedShort : All.UnsignedInt, (IntPtr)c.IndirectOffset, (IntPtr)c.DrawCountOffset, c.MaxDrawCount, c.IndirectStride); #if DEBUG PerfAPI.EndSample(); GenericMetrics.StopMeasurement(); #endif } break; case CommandType.Dispatch: { #if DEBUG PerfAPI.BeginCompute(); #endif GL.DispatchCompute((int)c.Size.X, (int)c.Size.Y, (int)c.Size.Z); #if DEBUG PerfAPI.EndSample(); #endif } break; case CommandType.DispatchIndirect: { #if DEBUG PerfAPI.BeginComputeIndirect(); #endif GL.BindBuffer(BufferTarget.DispatchIndirectBuffer, (int)c.Buffer); GL.DispatchComputeIndirect((IntPtr)c.IndirectOffset); #if DEBUG PerfAPI.EndSample(); #endif } break; case CommandType.Barrier: { MemoryBarrierFlags flags = 0; flags |= (c.BarrierType & BarrierType.ElementArray) != 0 ? MemoryBarrierFlags.ElementArrayBarrierBit : 0; flags |= (c.BarrierType & BarrierType.UniformBuffer) != 0 ? MemoryBarrierFlags.UniformBarrierBit : 0; flags |= (c.BarrierType & BarrierType.TextureFetch) != 0 ? MemoryBarrierFlags.TextureFetchBarrierBit : 0; flags |= (c.BarrierType & BarrierType.ShaderImageAccess) != 0 ? MemoryBarrierFlags.ShaderImageAccessBarrierBit : 0; flags |= (c.BarrierType & BarrierType.Command) != 0 ? MemoryBarrierFlags.CommandBarrierBit : 0; flags |= (c.BarrierType & BarrierType.PixelBuffer) != 0 ? MemoryBarrierFlags.PixelBufferBarrierBit : 0; flags |= (c.BarrierType & BarrierType.TextureUpdate) != 0 ? MemoryBarrierFlags.TextureUpdateBarrierBit : 0; flags |= (c.BarrierType & BarrierType.BufferUpdate) != 0 ? MemoryBarrierFlags.BufferUpdateBarrierBit : 0; flags |= (c.BarrierType & BarrierType.Framebuffer) != 0 ? MemoryBarrierFlags.FramebufferBarrierBit : 0; flags |= (c.BarrierType & BarrierType.StorageBuffer) != 0 ? MemoryBarrierFlags.ShaderStorageBarrierBit : 0; GL.MemoryBarrier(flags); } break; } } }