public void CmdBindPipeline(MgPipelineBindPoint pipelineBindPoint, IMgPipeline pipeline) { var bPipeline = (VkPipeline)pipeline; Debug.Assert(bPipeline != null); Interops.vkCmdBindPipeline(this.Handle, (VkPipelineBindPoint)pipelineBindPoint, bPipeline.Handle); }
public Result CreateGraphicsPipelines(IMgPipelineCache pipelineCache, MgGraphicsPipelineCreateInfo[] pCreateInfos, IMgAllocationCallbacks allocator, out IMgPipeline[] pPipelines) { var noOfPipelines = pCreateInfos.Length; var output = new IMgPipeline[pCreateInfos.Length]; for (var i = 0; i < noOfPipelines; i += 1) { output[i] = new MockGraphicsPipeline(); } pPipelines = output; return(Result.SUCCESS); }
public void CmdBindPipeline(MgPipelineBindPoint pipelineBindPoint, IMgPipeline pipeline) { if (pipeline == null) { throw new ArgumentNullException(nameof(pipeline)); } if (pipelineBindPoint == MgPipelineBindPoint.COMPUTE) { mCommandEncoder.Compute.BindPipeline(pipeline); } else { mCommandEncoder.Graphics.BindPipeline(pipeline); } }
public void BindPipeline(IMgPipeline pipeline) { if (pipeline == null) { throw new ArgumentNullException(nameof(pipeline)); } mCurrentPipeline = (AmtComputePipeline)pipeline; var nextIndex = mBag.Pipelines.Push(mCurrentPipeline); mInstructions.Add(new AmtEncodingInstruction { Category = AmtEncoderCategory.Compute, Index = nextIndex, Operation = CmdBindPipeline, }); }
public Result CreateGraphicsPipelines(IMgPipelineCache pipelineCache, MgGraphicsPipelineCreateInfo[] pCreateInfos, IMgAllocationCallbacks allocator, out IMgPipeline[] pPipelines) { var noOfPipelines = pCreateInfos.Length; pPipelines = new IMgPipeline[noOfPipelines]; for (var i = 0; i < noOfPipelines; i += 1) { var createInfo = pCreateInfos[i]; var bLayout = (IGLPipelineLayout)createInfo.Layout; var programId = 0; IGLShaderModuleInspector inspector = null; var blocks = inspector.Inspect(programId); var arrayMapper = new GLInternalCacheArrayMapper(bLayout, blocks); var cache = new GLInternalCache(bLayout, blocks, arrayMapper); } return(Result.SUCCESS); }
void preparePipelines() { Debug.Assert(mManager.Configuration != null); var device = mManager.Configuration.Device; using (var vertFs = System.IO.File.OpenRead("Shaders/texture1.vert.spv")) using (var fragFs = System.IO.File.OpenRead("Shaders/texture1.frag.spv")) { // Load shaders IMgShaderModule vertSM; { var vsCreateInfo = new MgShaderModuleCreateInfo { Code = vertFs, CodeSize = new UIntPtr((ulong)vertFs.Length), }; // shaderStages[0] = loadShader(getAssetPath() + "shaders/texture/texture.vert.spv", IMg_SHADER_STAGE_VERTEX_BIT); var localErr = device.CreateShaderModule(vsCreateInfo, null, out vertSM); Debug.Assert(localErr == Result.SUCCESS); } IMgShaderModule fragSM; { var fsCreateInfo = new MgShaderModuleCreateInfo { Code = fragFs, CodeSize = new UIntPtr((ulong)fragFs.Length), }; //shaderStages[1] = loadShader(getAssetPath() + "shaders/texture/texture.frag.spv", IMg_SHADER_STAGE_FRAGMENT_BIT); var localErr = device.CreateShaderModule(fsCreateInfo, null, out fragSM); Debug.Assert(localErr == Result.SUCCESS); } var pipelineCreateInfo = new MgGraphicsPipelineCreateInfo { Stages = new MgPipelineShaderStageCreateInfo[] { new MgPipelineShaderStageCreateInfo { Module = vertSM, Stage = MgShaderStageFlagBits.VERTEX_BIT, Name = "vertFunc", }, new MgPipelineShaderStageCreateInfo { Module = fragSM, Stage = MgShaderStageFlagBits.FRAGMENT_BIT, Name = "fragFunc", } }, Layout = mPipelineLayout, RenderPass = mManager.Graphics.Renderpass, VertexInputState = vertices.inputState, InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo { Topology = MgPrimitiveTopology.TRIANGLE_LIST, PrimitiveRestartEnable = false, }, RasterizationState = new MgPipelineRasterizationStateCreateInfo { PolygonMode = MgPolygonMode.FILL, CullMode = MgCullModeFlagBits.NONE, FrontFace = MgFrontFace.COUNTER_CLOCKWISE, }, ColorBlendState = new MgPipelineColorBlendStateCreateInfo { Attachments = new MgPipelineColorBlendAttachmentState[] { new MgPipelineColorBlendAttachmentState { ColorWriteMask = MgColorComponentFlagBits.R_BIT | MgColorComponentFlagBits.G_BIT | MgColorComponentFlagBits.B_BIT | MgColorComponentFlagBits.A_BIT, BlendEnable = false, }, } }, MultisampleState = new MgPipelineMultisampleStateCreateInfo { RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT, }, // pipelineCreateInfo.pViewportState = &viewportState; // MgPipelineViewportStateCreateInfo viewportState = // IMgTools::initializers::pipelineViewportStateCreateInfo(1, 1, 0); //ViewportState = new MgPipelineViewportStateCreateInfo //{ // Scissors = new [] // { // mManager.Graphics.Scissor, // }, // Viewports = new [] // { // mManager.Graphics.CurrentViewport, // } //}, DepthStencilState = new MgPipelineDepthStencilStateCreateInfo { DepthTestEnable = true, DepthWriteEnable = true, DepthCompareOp = MgCompareOp.LESS_OR_EQUAL, DepthBoundsTestEnable = false, Back = new MgStencilOpState { FailOp = MgStencilOp.KEEP, PassOp = MgStencilOp.KEEP, CompareOp = MgCompareOp.ALWAYS, }, StencilTestEnable = false, Front = new MgStencilOpState { FailOp = MgStencilOp.KEEP, PassOp = MgStencilOp.KEEP, CompareOp = MgCompareOp.ALWAYS, }, }, DynamicState = new MgPipelineDynamicStateCreateInfo { DynamicStates = new[] { MgDynamicState.VIEWPORT, MgDynamicState.SCISSOR }, } }; IMgPipeline[] pipelines; var err = device.CreateGraphicsPipelines(null, new[] { pipelineCreateInfo }, null, out pipelines); Debug.Assert(err == Result.SUCCESS); mSolidPipeline = pipelines[0]; } }
public void Preamble() { // PRIVATE IMPLEMENTATION UNIT TESTING mContainer = new Container(); mContainer.Register <IMgQueue, GLCmdQueue>(Reuse.Singleton); mContainer.Register <IGLCmdStateRenderer, GLCmdStateRenderer>(Reuse.Singleton); mContainer.Register <IGLCmdBlendEntrypoint, MockGLCmdBlendEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdStencilEntrypoint, MockGLCmdStencilEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdRasterizationEntrypoint, MockGLCmdRasterizationEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdDepthEntrypoint, MockGLCmdDepthEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdScissorsEntrypoint, MockGLCmdScissorsEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdDrawEntrypoint, MockGLCmdDrawEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdClearEntrypoint, MockGLCmdClearEntrypoint>(Reuse.Singleton); mContainer.Register <IGLErrorHandler, MockGLErrorHandler>(Reuse.Singleton); mContainer.Register <IGLNextCmdShaderProgramCache, GLNextCmdShaderProgramCache>(Reuse.Singleton); mContainer.Register <IGLCmdShaderProgramEntrypoint, MockGLCmdShaderProgramEntrypoint>(Reuse.Singleton); mContainer.Register <IGLBlitOperationEntrypoint, MockGLBlitOperationEntrypoint>(Reuse.Singleton); mContainer.Register <IGLSemaphoreEntrypoint, MockGLSemaphoreEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdImageEntrypoint, MockGLCmdImageEntrypoint>(Reuse.Singleton); mContainer.Register <IGLCmdBlitEncoder, GLCmdBlitEncoder>(Reuse.Singleton); mContainer.Register <GLCmdBlitBag>(Reuse.Singleton); mContainer.Register <IGLCmdComputeEncoder, GLCmdComputeEncoder>(Reuse.Singleton); mContainer.Register <IGLCmdGraphicsEncoder, GLCmdGraphicsEncoder>(Reuse.Singleton); mContainer.Register <GLCmdGraphicsBag>(Reuse.Singleton); mContainer.Register <IGLCmdVBOEntrypoint, MockGLCmdVBOEntrypoint>(Reuse.Singleton); mContainer.Register <IGLDescriptorSetBinder, GLNextDescriptorSetBinder>(Reuse.Singleton); mContainer.Register <IGLCmdEncoderContextSorter, GLCmdIncrementalContextSorter>(Reuse.Singleton); mContainer.Register <GLCmdCommandEncoder>(Reuse.Singleton); mContainer.Register <GLInternalCache>(Reuse.Singleton); mContainer.Register <IMgPipeline, GLGraphicsPipeline>(Reuse.Singleton); mContainer.Register <IGLGraphicsPipelineCompiler, MockGLGraphicsPipelineCompiler>(Reuse.Singleton); mContainer.Register <IGLGraphicsPipelineEntrypoint, MockGLGraphicsPipelineEntrypoint>(Reuse.Singleton); queue = mContainer.Resolve <IMgQueue>(); var cmdEncoder = mContainer.Resolve <GLCmdCommandEncoder>(); cmdBuf = new Magnesium.OpenGL.Internals.GLCmdCommandBuffer(true, cmdEncoder); framebuffer = new Magnesium.OpenGL.Internals.GLFramebuffer(); renderpass = new GLRenderPass(new MgAttachmentDescription[] { }); vertexBuffer = new MockGLBuffer { BufferId = 1, Usage = MgBufferUsageFlagBits.VERTEX_BUFFER_BIT, }; indexBuffer = new MockGLBuffer { BufferId = 2, Usage = MgBufferUsageFlagBits.INDEX_BUFFER_BIT, }; var layout = new MockGLPipelineLayout { }; mContainer.RegisterInstance <IGLPipelineLayout>(layout, Reuse.Singleton); var blockEntries = new GLUniformBlockEntry[] { }; var arrayMapper = new Magnesium.OpenGL.Internals.GLInternalCacheArrayMapper(layout, blockEntries); mContainer.RegisterInstance <GLInternalCacheArrayMapper>(arrayMapper, Reuse.Singleton); var entrypoint = mContainer.Resolve <IGLGraphicsPipelineEntrypoint>(); var internalCache = mContainer.Resolve <GLInternalCache>(); var info = new MgGraphicsPipelineCreateInfo { VertexInputState = new MgPipelineVertexInputStateCreateInfo { VertexAttributeDescriptions = new[] { new MgVertexInputAttributeDescription { Binding = 0, Location = 0, Format = MgFormat.R8G8B8A8_SNORM, } }, VertexBindingDescriptions = new[] { new MgVertexInputBindingDescription { Binding = 0, InputRate = MgVertexInputRate.VERTEX, Stride = 32, } } }, RasterizationState = new MgPipelineRasterizationStateCreateInfo { PolygonMode = MgPolygonMode.FILL, }, InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo { Topology = MgPrimitiveTopology.TRIANGLE_LIST, } }; pipeline = new Magnesium.OpenGL.Internals.GLGraphicsPipeline(entrypoint, 1, info, internalCache, layout); var stateRenderer = mContainer.Resolve <IGLCmdStateRenderer>(); stateRenderer.Initialize(); }
public void BindPipeline(IMgPipeline pipeline) { throw new NotImplementedException(); }
public void CmdBindPipeline(MgPipelineBindPoint pipelineBindPoint, IMgPipeline pipeline) { throw new NotImplementedException(); }
void PreparePipelines() { using (var vertFs = mTrianglePath.OpenVertexShader()) using (var fragFs = mTrianglePath.OpenFragmentShader()) { IMgShaderModule vsModule; { var vsCreateInfo = new MgShaderModuleCreateInfo { Code = vertFs, CodeSize = new UIntPtr((ulong)vertFs.Length), }; mConfiguration.Device.CreateShaderModule(vsCreateInfo, null, out vsModule); } IMgShaderModule fsModule; { var fsCreateInfo = new MgShaderModuleCreateInfo { Code = fragFs, CodeSize = new UIntPtr((ulong)fragFs.Length), }; mConfiguration.Device.CreateShaderModule(fsCreateInfo, null, out fsModule); } var pipelineCreateInfo = new MgGraphicsPipelineCreateInfo { Stages = new [] { new MgPipelineShaderStageCreateInfo { Stage = MgShaderStageFlagBits.VERTEX_BIT, Module = vsModule, Name = "vertFunc", }, new MgPipelineShaderStageCreateInfo { Stage = MgShaderStageFlagBits.FRAGMENT_BIT, Module = fsModule, Name = "fragFunc", }, }, VertexInputState = vertices.inputState, InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo { // GL002 - TRIANGLE STRIP TEST Topology = MgPrimitiveTopology.TRIANGLE_STRIP, }, RasterizationState = new MgPipelineRasterizationStateCreateInfo { PolygonMode = MgPolygonMode.FILL, CullMode = MgCullModeFlagBits.NONE, FrontFace = MgFrontFace.COUNTER_CLOCKWISE, DepthClampEnable = false, RasterizerDiscardEnable = false, DepthBiasEnable = false, LineWidth = 1.0f, }, ColorBlendState = new MgPipelineColorBlendStateCreateInfo { Attachments = new [] { new MgPipelineColorBlendAttachmentState { ColorWriteMask = MgColorComponentFlagBits.R_BIT | MgColorComponentFlagBits.G_BIT | MgColorComponentFlagBits.B_BIT | MgColorComponentFlagBits.A_BIT, BlendEnable = false, } }, }, MultisampleState = new MgPipelineMultisampleStateCreateInfo { RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT, SampleMask = null, }, Layout = mPipelineLayout, RenderPass = mGraphicsDevice.Renderpass, ViewportState = null, DepthStencilState = new MgPipelineDepthStencilStateCreateInfo { DepthTestEnable = true, DepthWriteEnable = true, DepthCompareOp = MgCompareOp.LESS_OR_EQUAL, DepthBoundsTestEnable = false, Back = new MgStencilOpState { FailOp = MgStencilOp.KEEP, PassOp = MgStencilOp.KEEP, CompareOp = MgCompareOp.ALWAYS, }, StencilTestEnable = false, Front = new MgStencilOpState { FailOp = MgStencilOp.KEEP, PassOp = MgStencilOp.KEEP, CompareOp = MgCompareOp.ALWAYS, }, }, DynamicState = new MgPipelineDynamicStateCreateInfo { DynamicStates = new[] { MgDynamicState.VIEWPORT, MgDynamicState.SCISSOR, } }, }; var err = mConfiguration.Device.CreateGraphicsPipelines(null, new[] { pipelineCreateInfo }, null, out IMgPipeline[] pipelines); Debug.Assert(err == Result.SUCCESS); vsModule.DestroyShaderModule(mConfiguration.Device, null); fsModule.DestroyShaderModule(mConfiguration.Device, null); mPipeline = pipelines[0]; } }
void InitializeGraphicsPipeline() { using (var shaderSrc = System.IO.File.OpenRead("Fragment.metal")) using (var fragMemory = new System.IO.MemoryStream()) using (var vertMemory = new System.IO.MemoryStream()) { shaderSrc.CopyTo(fragMemory); // Magnesium uses like open files i.e. open the stream and let it process the data fragMemory.Seek(0, System.IO.SeekOrigin.Begin); // Load the fragment program into the library IMgShaderModule fragmentProgram = null; //IMTLFunction fragmentProgram = defaultLibrary.CreateFunction("lighting_fragment"); MgShaderModuleCreateInfo fragCreateInfo = new MgShaderModuleCreateInfo { Code = fragMemory, CodeSize = new UIntPtr((ulong)fragMemory.Length), }; var err = mConfiguration.Device.CreateShaderModule(fragCreateInfo, null, out fragmentProgram); Debug.Assert(err == Result.SUCCESS); // REWIND AFTER USE shaderSrc.Seek(0, System.IO.SeekOrigin.Begin); shaderSrc.CopyTo(vertMemory); vertMemory.Seek(0, System.IO.SeekOrigin.Begin); // Load the vertex program into the library //IMTLFunction vertexProgram = defaultLibrary.CreateFunction("lighting_vertex"); MgShaderModuleCreateInfo vertCreateInfo = new MgShaderModuleCreateInfo { Code = vertMemory, CodeSize = new UIntPtr((ulong)vertMemory.Length), }; IMgShaderModule vertexProgram = null; err = mConfiguration.Device.CreateShaderModule(vertCreateInfo, null, out vertexProgram); Debug.Assert(err == Result.SUCCESS); IMgPipelineLayout pipelineLayout; MgPipelineLayoutCreateInfo plCreateInfo = new MgPipelineLayoutCreateInfo { SetLayouts = new IMgDescriptorSetLayout[] { mSetLayout, }, }; err = mConfiguration.Device.CreatePipelineLayout(plCreateInfo, null, out pipelineLayout); mPipelineLayout = pipelineLayout; var vertexStride = Marshal.SizeOf <Vector3>(); IMgPipeline[] pipelines; var pCreateInfos = new MgGraphicsPipelineCreateInfo[] { new MgGraphicsPipelineCreateInfo { Stages = new MgPipelineShaderStageCreateInfo[] { new MgPipelineShaderStageCreateInfo { Module = fragmentProgram, Stage = MgShaderStageFlagBits.FRAGMENT_BIT, Name = "lighting_fragment", }, new MgPipelineShaderStageCreateInfo { Module = vertexProgram, Stage = MgShaderStageFlagBits.VERTEX_BIT, Name = "lighting_vertex", }, }, InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo { Topology = MgPrimitiveTopology.TRIANGLE_LIST, }, DepthStencilState = new MgPipelineDepthStencilStateCreateInfo { DepthCompareOp = MgCompareOp.LESS, DepthWriteEnable = true, DepthTestEnable = true, }, MultisampleState = new MgPipelineMultisampleStateCreateInfo { // TODO : METALSample uses 4 bits, have to investigated multisampling in // Vulkan ( => Magnesium) for correct code RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT, }, RasterizationState = new MgPipelineRasterizationStateCreateInfo { FrontFace = MgFrontFace.COUNTER_CLOCKWISE, PolygonMode = MgPolygonMode.FILL, CullMode = MgCullModeFlagBits.BACK_BIT, }, VertexInputState = new MgPipelineVertexInputStateCreateInfo { VertexBindingDescriptions = new MgVertexInputBindingDescription[] { new MgVertexInputBindingDescription { Binding = 0, InputRate = MgVertexInputRate.VERTEX, Stride = (uint)(2 * vertexStride), }, }, VertexAttributeDescriptions = new MgVertexInputAttributeDescription[] { new MgVertexInputAttributeDescription { Binding = 0, Location = 0, Format = MgFormat.R32G32B32_SFLOAT, Offset = 0, }, new MgVertexInputAttributeDescription { Binding = 0, Location = 1, Format = MgFormat.R32G32B32_SFLOAT, Offset = (uint)vertexStride, }, }, }, ViewportState = new MgPipelineViewportStateCreateInfo { Viewports = new MgViewport[] { mGraphicsDevice.CurrentViewport, }, Scissors = new MgRect2D[] { mGraphicsDevice.Scissor, } }, //DynamicState = new MgPipelineDynamicStateCreateInfo //{ // DynamicStates = new MgDynamicState[] // { // MgDynamicState.VIEWPORT, // MgDynamicState.SCISSOR, // } //}, RenderPass = mGraphicsDevice.Renderpass, Layout = pipelineLayout, }, }; err = mConfiguration.Device.CreateGraphicsPipelines( null, pCreateInfos, null, out pipelines); Debug.Assert(err == Result.SUCCESS); fragmentProgram.DestroyShaderModule(mConfiguration.Device, null); vertexProgram.DestroyShaderModule(mConfiguration.Device, null); mPipelineState = pipelines[0]; } GenerateRenderingCommandBuffers(); }