Exemple #1
0
        public void Create(IMgSwapchainCollection swapchains, IMgRenderPass pass, IMgImageView depthStencilView, uint width, uint height)
        {
            Debug.Assert(mGraphicsConfiguration.Partition != null);

            // Create frame buffers for every swap chain image
            var frameBuffers = new IMgFramebuffer[swapchains.Buffers.Length];

            for (uint i = 0; i < frameBuffers.Length; i++)
            {
                var frameBufferCreateInfo = new MgFramebufferCreateInfo
                {
                    RenderPass  = pass,
                    Attachments = new[]
                    {
                        swapchains.Buffers[i].View,
                        // Depth/Stencil attachment is the same for all frame buffers
                        depthStencilView,
                    },
                    Width  = width,
                    Height = height,
                    Layers = 1,
                };

                var err = mGraphicsConfiguration.Partition.Device.CreateFramebuffer(frameBufferCreateInfo, null, out frameBuffers[i]);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
            }

            mFramebuffers = frameBuffers;
        }
Exemple #2
0
        void CreateRenderpass(MgGraphicsDeviceCreateInfo createInfo)
        {
            var attachments = new []
            {
                // Color attachment[0]
                new MgAttachmentDescription {
                    Format = createInfo.Color,
                    // TODO : multisampling
                    Samples        = MgSampleCountFlagBits.COUNT_1_BIT,
                    LoadOp         = MgAttachmentLoadOp.CLEAR,
                    StoreOp        = MgAttachmentStoreOp.STORE,
                    StencilLoadOp  = MgAttachmentLoadOp.DONT_CARE,
                    StencilStoreOp = MgAttachmentStoreOp.DONT_CARE,
                    InitialLayout  = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL,
                    FinalLayout    = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL,
                },
                // Depth attachment[1]
                new MgAttachmentDescription {
                    Format = createInfo.DepthStencil,
                    // TODO : multisampling
                    Samples = MgSampleCountFlagBits.COUNT_1_BIT,
                    LoadOp  = MgAttachmentLoadOp.CLEAR,
                    StoreOp = MgAttachmentStoreOp.STORE,

                    // TODO : activate stencil if needed
                    StencilLoadOp  = MgAttachmentLoadOp.DONT_CARE,
                    StencilStoreOp = MgAttachmentStoreOp.DONT_CARE,

                    InitialLayout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
                    FinalLayout   = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
                }
            };

            var colorReference = new MgAttachmentReference
            {
                Attachment = 0,
                Layout     = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL,
            };

            var depthReference = new MgAttachmentReference {
                Attachment = 1,
                Layout     = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
            };

            var subpass = new MgSubpassDescription
            {
                PipelineBindPoint      = MgPipelineBindPoint.GRAPHICS,
                Flags                  = 0,
                InputAttachments       = null,
                ColorAttachments       = new [] { colorReference },
                ResolveAttachments     = null,
                DepthStencilAttachment = depthReference,
                PreserveAttachments    = null,
            };

            var renderPassInfo = new MgRenderPassCreateInfo {
                Attachments  = attachments,
                Subpasses    = new [] { subpass },
                Dependencies = null,
            };

            Result err;

            IMgRenderPass renderPass;

            err = mGraphicsConfiguration.Partition.Device.CreateRenderPass(renderPassInfo, null, out renderPass);
            Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
            mRenderpass = renderPass;
        }
Exemple #3
0
 void ReleaseUnmanagedResources()
 {
     mRenderpass       = null;
     mDepthStencilView = null;
     mFramebuffers.Clear();
 }
Exemple #4
0
 public void GetRenderAreaGranularity(IMgRenderPass renderPass, out MgExtent2D pGranularity)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public Result CreateRenderPass(MgRenderPassCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgRenderPass pRenderPass)
 {
     pRenderPass = new AmtRenderPass(pCreateInfo);
     return(Result.SUCCESS);
 }
Exemple #6
0
 public Result CreateRenderPass(MgRenderPassCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgRenderPass pRenderPass)
 {
     throw new NotImplementedException();
 }
Exemple #7
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();
        }
Exemple #8
0
        public EffectVariant Initialize(
            IMgDevice device,
            IMgPipelineLayout layout,
            IMgRenderPass renderPass,
            PerVertexInputPipelineState vertexInput,
            EffectVariantOptions options
            )
        {
            using (var vertFs = mPath.OpenVertexShader())
                using (var fragFs = mPath.OpenFragmentShader())
                {
                    var vsCreateInfo = new MgShaderModuleCreateInfo
                    {
                        Code     = vertFs,
                        CodeSize = new UIntPtr((ulong)vertFs.Length),
                    };
                    device.CreateShaderModule(vsCreateInfo, null, out IMgShaderModule vsModule);

                    var fsCreateInfo = new MgShaderModuleCreateInfo
                    {
                        Code     = fragFs,
                        CodeSize = new UIntPtr((ulong)fragFs.Length),
                    };
                    device.CreateShaderModule(fsCreateInfo, null, out IMgShaderModule fsModule);

                    var createInfo = new MgGraphicsPipelineCreateInfo
                    {
                        Stages = new MgPipelineShaderStageCreateInfo[]
                        {
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.VERTEX_BIT,
                                Module = vsModule,
                                Name   = "vertFunc",
                            },
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.FRAGMENT_BIT,
                                Module = fsModule,
                                Name   = "fragFunc",
                            },
                        },

                        ColorBlendState = new MgPipelineColorBlendStateCreateInfo
                        {
                            Attachments = new[]
                            {
                                new MgPipelineColorBlendAttachmentState
                                {
                                    ColorWriteMask = MgColorComponentFlagBits.ALL_BITS,
                                    BlendEnable    = false,
                                }
                            },
                        },
                        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,
                            }
                        },
                        InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                        {
                            Topology = options.Topology,
                        },
                        Layout           = layout,
                        MultisampleState = new MgPipelineMultisampleStateCreateInfo
                        {
                            RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT,
                            SampleMask           = null,
                        },
                        RasterizationState = new MgPipelineRasterizationStateCreateInfo
                        {
                            PolygonMode             = MgPolygonMode.FILL,
                            FrontFace               = options.FrontFace,
                            CullMode                = options.CullMode,
                            DepthClampEnable        = false,
                            RasterizerDiscardEnable = false,
                            DepthBiasEnable         = false,
                            LineWidth               = 1.0f,
                        },
                        RenderPass       = renderPass,
                        VertexInputState = vertexInput.VertexInputState,
                        ViewportState    = null,
                    };

                    var err = device.CreateGraphicsPipelines(null,
                                                             new[] { createInfo }, null, out IMgPipeline[] pPipelines);

                    Debug.Assert(err == Result.SUCCESS);

                    vsModule.DestroyShaderModule(device, null);
                    fsModule.DestroyShaderModule(device, null);

                    return(new EffectVariant
                    {
                        Key = new EffectVariantKey
                        {
                            Definition = vertexInput.VertexMask,
                            Options = EffectVariantEncoder.Encode(options),
                        },
                        Pipeline = pPipelines[0],
                    });
                }
        }