Esempio n. 1
0
        public unsafe PipelineBase(VulkanGraphicsDevice gd, Device device)
        {
            Gd     = gd;
            Device = device;

            var pipelineCacheCreateInfo = new PipelineCacheCreateInfo()
            {
                SType = StructureType.PipelineCacheCreateInfo
            };

            gd.Api.CreatePipelineCache(device, pipelineCacheCreateInfo, null, out _pipelineCache).ThrowOnError();

            _descriptorSetUpdater = new DescriptorSetUpdater(gd, this);

            _transformFeedbackBuffers = new BufferState[Constants.MaxTransformFeedbackBuffers];
            _vertexBuffers            = new BufferState[Constants.MaxVertexBuffers + 1];

            const int EmptyVbSize = 16;

            using var emptyVb = gd.BufferManager.Create(gd, EmptyVbSize);
            emptyVb.SetData(0, new byte[EmptyVbSize]);
            _vertexBuffers[0]         = new BufferState(emptyVb.GetBuffer(), 0, EmptyVbSize, 0UL);
            _needsVertexBuffersRebind = true;

            RenderScaleBuffer = gd.BufferManager.Create(gd, SupportBuffer.RequiredSize);

            _newState.Initialize();
            _newState.LineWidth = 1f;
        }
Esempio n. 2
0
        public void CreateBackgroundComputePipeline()
        {
            PipelineState pipeline = new PipelineState();

            pipeline.Initialize();

            pipeline.Stages[0]      = _shaders[0].GetInfo();
            pipeline.StagesCount    = 1;
            pipeline.PipelineLayout = PipelineLayout;

            pipeline.CreateComputePipeline(_gd, _device, this, (_gd.Pipeline as PipelineBase).PipelineCache);
            pipeline.Dispose();
        }
Esempio n. 3
0
        public unsafe PipelineBase(VulkanRenderer gd, Device device)
        {
            Gd     = gd;
            Device = device;

            var pipelineCacheCreateInfo = new PipelineCacheCreateInfo()
            {
                SType = StructureType.PipelineCacheCreateInfo
            };

            gd.Api.CreatePipelineCache(device, pipelineCacheCreateInfo, null, out PipelineCache).ThrowOnError();

            _descriptorSetUpdater = new DescriptorSetUpdater(gd, this);

            _transformFeedbackBuffers = new BufferState[Constants.MaxTransformFeedbackBuffers];
            _vertexBuffers            = new BufferState[Constants.MaxVertexBuffers + 1];

            const int EmptyVbSize = 16;

            using var emptyVb = gd.BufferManager.Create(gd, EmptyVbSize);
            emptyVb.SetData(0, new byte[EmptyVbSize]);
            _vertexBuffers[0]         = new BufferState(emptyVb.GetBuffer(), 0, EmptyVbSize, 0UL);
            _needsVertexBuffersRebind = true;

            ClearScissor = new Rectangle <int>(0, 0, 0xffff, 0xffff);

            var defaultScale = new Vector4 <float> {
                X = 1f, Y = 0f, Z = 0f, W = 0f
            };

            new Span <Vector4 <float> >(_renderScale).Fill(defaultScale);

            _newState.Initialize();
            _newState.LineWidth    = 1f;
            _newState.SamplesCount = 1;
        }
Esempio n. 4
0
        public static PipelineState ToVulkanPipelineState(this ProgramPipelineState state, VulkanRenderer gd)
        {
            PipelineState pipeline = new PipelineState();

            pipeline.Initialize();

            // It is assumed that Dynamic State is enabled when this conversion is used.

            pipeline.BlendConstantA = state.BlendDescriptors[0].BlendConstant.Alpha;
            pipeline.BlendConstantB = state.BlendDescriptors[0].BlendConstant.Blue;
            pipeline.BlendConstantG = state.BlendDescriptors[0].BlendConstant.Green;
            pipeline.BlendConstantR = state.BlendDescriptors[0].BlendConstant.Red;

            pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : CullModeFlags.CullModeNone;

            pipeline.DepthBoundsTestEnable = false; // Not implemented.

            pipeline.DepthClampEnable = state.DepthClampEnable;

            pipeline.DepthTestEnable  = state.DepthTest.TestEnable;
            pipeline.DepthWriteEnable = state.DepthTest.WriteEnable;
            pipeline.DepthCompareOp   = state.DepthTest.Func.Convert();

            pipeline.FrontFace = state.FrontFace.Convert();

            pipeline.HasDepthStencil = state.DepthStencilEnable;
            pipeline.LineWidth       = state.LineWidth;
            pipeline.LogicOpEnable   = state.LogicOpEnable;
            pipeline.LogicOp         = state.LogicOp.Convert();

            pipeline.MinDepthBounds = 0f; // Not implemented.
            pipeline.MaxDepthBounds = 0f; // Not implemented.

            pipeline.PatchControlPoints      = state.PatchControlPoints;
            pipeline.PolygonMode             = Silk.NET.Vulkan.PolygonMode.Fill; // Not implemented.
            pipeline.PrimitiveRestartEnable  = state.PrimitiveRestartEnable;
            pipeline.RasterizerDiscardEnable = state.RasterizerDiscard;
            pipeline.SamplesCount            = (uint)state.SamplesCount;

            if (gd.Capabilities.SupportsMultiView)
            {
                pipeline.ScissorsCount  = Constants.MaxViewports;
                pipeline.ViewportsCount = Constants.MaxViewports;
            }
            else
            {
                pipeline.ScissorsCount  = 1;
                pipeline.ViewportsCount = 1;
            }

            pipeline.DepthBiasEnable = state.BiasEnable != 0;

            // Stencil masks and ref are dynamic, so are 0 in the Vulkan pipeline.

            pipeline.StencilFrontFailOp      = state.StencilTest.FrontSFail.Convert();
            pipeline.StencilFrontPassOp      = state.StencilTest.FrontDpPass.Convert();
            pipeline.StencilFrontDepthFailOp = state.StencilTest.FrontDpFail.Convert();
            pipeline.StencilFrontCompareOp   = state.StencilTest.FrontFunc.Convert();
            pipeline.StencilFrontCompareMask = 0;
            pipeline.StencilFrontWriteMask   = 0;
            pipeline.StencilFrontReference   = 0;

            pipeline.StencilBackFailOp      = state.StencilTest.BackSFail.Convert();
            pipeline.StencilBackPassOp      = state.StencilTest.BackDpPass.Convert();
            pipeline.StencilBackDepthFailOp = state.StencilTest.BackDpFail.Convert();
            pipeline.StencilBackCompareOp   = state.StencilTest.BackFunc.Convert();
            pipeline.StencilBackCompareMask = 0;
            pipeline.StencilBackWriteMask   = 0;
            pipeline.StencilBackReference   = 0;

            pipeline.StencilTestEnable = state.StencilTest.TestEnable;

            pipeline.Topology = state.Topology.Convert();

            int vaCount = Math.Min(Constants.MaxVertexAttributes, state.VertexAttribCount);

            for (int i = 0; i < vaCount; i++)
            {
                var attribute   = state.VertexAttribs[i];
                var bufferIndex = attribute.IsZero ? 0 : attribute.BufferIndex + 1;

                pipeline.Internal.VertexAttributeDescriptions[i] = new VertexInputAttributeDescription(
                    (uint)i,
                    (uint)bufferIndex,
                    gd.FormatCapabilities.ConvertToVertexVkFormat(attribute.Format),
                    (uint)attribute.Offset);
            }

            int descriptorIndex = 1;

            pipeline.Internal.VertexBindingDescriptions[0] = new VertexInputBindingDescription(0, 0, VertexInputRate.Vertex);

            int vbCount = Math.Min(Constants.MaxVertexBuffers, state.VertexBufferCount);

            for (int i = 0; i < vbCount; i++)
            {
                var vertexBuffer = state.VertexBuffers[i];

                if (vertexBuffer.Enable)
                {
                    var inputRate = vertexBuffer.Divisor != 0 ? VertexInputRate.Instance : VertexInputRate.Vertex;

                    // TODO: Support divisor > 1
                    pipeline.Internal.VertexBindingDescriptions[descriptorIndex++] = new VertexInputBindingDescription(
                        (uint)i + 1,
                        (uint)vertexBuffer.Stride,
                        inputRate);
                }
            }

            pipeline.VertexBindingDescriptionsCount = (uint)descriptorIndex;

            // NOTE: Viewports, Scissors are dynamic.

            for (int i = 0; i < 8; i++)
            {
                var blend = state.BlendDescriptors[i];

                pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState(
                    blend.Enable,
                    blend.ColorSrcFactor.Convert(),
                    blend.ColorDstFactor.Convert(),
                    blend.ColorOp.Convert(),
                    blend.AlphaSrcFactor.Convert(),
                    blend.AlphaDstFactor.Convert(),
                    blend.AlphaOp.Convert(),
                    (ColorComponentFlags)state.ColorWriteMask[i]);
            }

            int maxAttachmentIndex = 0;

            for (int i = 0; i < 8; i++)
            {
                if (state.AttachmentEnable[i])
                {
                    pipeline.Internal.AttachmentFormats[maxAttachmentIndex++] = gd.FormatCapabilities.ConvertToVkFormat(state.AttachmentFormats[i]);
                }
            }

            if (state.DepthStencilEnable)
            {
                pipeline.Internal.AttachmentFormats[maxAttachmentIndex++] = gd.FormatCapabilities.ConvertToVkFormat(state.DepthStencilFormat);
            }

            pipeline.ColorBlendAttachmentStateCount   = 8;
            pipeline.VertexAttributeDescriptionsCount = (uint)Math.Min(Constants.MaxVertexAttributes, state.VertexAttribCount);

            return(pipeline);
        }